blob: c91c76e2dd9ebfaab4103f7403a0fffb6ebe24f9 [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
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530913int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
914 const char *ip, const char *mask)
915{
916 char buf[200];
917
918 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
919 ifname, ip, mask);
920 return system(buf) == 0;
921}
922
923
924int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
925{
926 char buf[200];
927
928 if (!is_ip_addr(gw)) {
929 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
930 return -1;
931 }
932
933 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
934 if (!dut->no_ip_addr_set && system(buf) != 0) {
935 snprintf(buf, sizeof(buf), "ip ro re default via %s",
936 gw);
937 if (system(buf) != 0)
938 return 0;
939 }
940
941 return 1;
942}
943
944
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200945static int cmd_sta_set_ip_config(struct sigma_dut *dut,
946 struct sigma_conn *conn,
947 struct sigma_cmd *cmd)
948{
949 const char *intf = get_param(cmd, "Interface");
950 const char *ifname;
951 char buf[200];
952 const char *val, *ip, *mask, *gw;
953 int type = 1;
954
955 if (intf == NULL)
956 return -1;
957
958 if (strcmp(intf, get_main_ifname()) == 0)
959 ifname = get_station_ifname();
960 else
961 ifname = intf;
962
963 if (if_nametoindex(ifname) == 0) {
964 send_resp(dut, conn, SIGMA_ERROR,
965 "ErrorCode,Unknown interface");
966 return 0;
967 }
968
969 val = get_param(cmd, "Type");
970 if (val) {
971 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530972 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200973 send_resp(dut, conn, SIGMA_ERROR,
974 "ErrorCode,Unsupported address type");
975 return 0;
976 }
977 }
978
979 dut->last_set_ip_config_ipv6 = 0;
980
981 val = get_param(cmd, "dhcp");
982 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
983 static_ip_file(0, NULL, NULL, NULL);
984#ifdef __linux__
985 if (type == 2) {
986 dut->last_set_ip_config_ipv6 = 1;
987 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
988 "stateless address autoconfiguration");
989#ifdef ANDROID
990 /*
991 * This sleep is required as the assignment in case of
992 * Android is taking time and is done by the kernel.
993 * The subsequent ping for IPv6 is impacting HS20 test
994 * case.
995 */
996 sleep(2);
997 add_ipv6_rule(dut, intf);
998#endif /* ANDROID */
999 /* Assume this happens by default */
1000 return 1;
1001 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301002 if (type != 3) {
1003 kill_dhcp_client(dut, ifname);
1004 if (start_dhcp_client(dut, ifname) < 0)
1005 return -2;
1006 } else {
1007 sigma_dut_print(dut, DUT_MSG_DEBUG,
1008 "Using FILS HLP DHCPv4 Rapid Commit");
1009 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001010
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001011 return 1;
1012#endif /* __linux__ */
1013 return -2;
1014 }
1015
1016 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301017 if (!ip) {
1018 send_resp(dut, conn, SIGMA_INVALID,
1019 "ErrorCode,Missing IP address");
1020 return 0;
1021 }
1022
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301024 if (!mask) {
1025 send_resp(dut, conn, SIGMA_INVALID,
1026 "ErrorCode,Missing subnet mask");
1027 return 0;
1028 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001029
1030 if (type == 2) {
1031 int net = atoi(mask);
1032
1033 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1034 return -1;
1035
1036 if (dut->no_ip_addr_set) {
1037 snprintf(buf, sizeof(buf),
1038 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1039 ifname);
1040 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1041 if (system(buf) != 0) {
1042 sigma_dut_print(dut, DUT_MSG_DEBUG,
1043 "Failed to disable IPv6 address before association");
1044 }
1045 } else {
1046 snprintf(buf, sizeof(buf),
1047 "ip -6 addr del %s/%s dev %s",
1048 ip, mask, ifname);
1049 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1050 if (system(buf) != 0) {
1051 /*
1052 * This command may fail if the address being
1053 * deleted does not exist. Inaction here is
1054 * intentional.
1055 */
1056 }
1057
1058 snprintf(buf, sizeof(buf),
1059 "ip -6 addr add %s/%s dev %s",
1060 ip, mask, ifname);
1061 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1062 if (system(buf) != 0) {
1063 send_resp(dut, conn, SIGMA_ERROR,
1064 "ErrorCode,Failed to set IPv6 address");
1065 return 0;
1066 }
1067 }
1068
1069 dut->last_set_ip_config_ipv6 = 1;
1070 static_ip_file(6, ip, mask, NULL);
1071 return 1;
1072 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301073 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001074 return -1;
1075 }
1076
1077 kill_dhcp_client(dut, ifname);
1078
1079 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301080 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001081 send_resp(dut, conn, SIGMA_ERROR,
1082 "ErrorCode,Failed to set IP address");
1083 return 0;
1084 }
1085 }
1086
1087 gw = get_param(cmd, "defaultGateway");
1088 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301089 if (set_ipv4_gw(dut, gw) < 1) {
1090 send_resp(dut, conn, SIGMA_ERROR,
1091 "ErrorCode,Failed to set default gateway");
1092 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001093 }
1094 }
1095
1096 val = get_param(cmd, "primary-dns");
1097 if (val) {
1098 /* TODO */
1099 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1100 "setting", val);
1101 }
1102
1103 val = get_param(cmd, "secondary-dns");
1104 if (val) {
1105 /* TODO */
1106 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1107 "setting", val);
1108 }
1109
1110 static_ip_file(4, ip, mask, gw);
1111
1112 return 1;
1113}
1114
1115
1116static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1117 struct sigma_cmd *cmd)
1118{
1119 /* const char *intf = get_param(cmd, "Interface"); */
1120 /* TODO: could report more details here */
1121 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1122 return 0;
1123}
1124
1125
1126static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1127 struct sigma_conn *conn,
1128 struct sigma_cmd *cmd)
1129{
1130 /* const char *intf = get_param(cmd, "Interface"); */
1131 char addr[20], resp[50];
1132
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301133 if (dut->dev_role == DEVROLE_STA_CFON)
1134 return sta_cfon_get_mac_address(dut, conn, cmd);
1135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001136 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1137 < 0)
1138 return -2;
1139
1140 snprintf(resp, sizeof(resp), "mac,%s", addr);
1141 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1142 return 0;
1143}
1144
1145
1146static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1147 struct sigma_cmd *cmd)
1148{
1149 /* const char *intf = get_param(cmd, "Interface"); */
1150 int connected = 0;
1151 char result[32];
1152 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1153 sizeof(result)) < 0) {
1154 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1155 "%s status", get_station_ifname());
1156 return -2;
1157 }
1158
1159 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1160 if (strncmp(result, "COMPLETED", 9) == 0)
1161 connected = 1;
1162
1163 if (connected)
1164 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1165 else
1166 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1167
1168 return 0;
1169}
1170
1171
1172static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1173 struct sigma_conn *conn,
1174 struct sigma_cmd *cmd)
1175{
1176 /* const char *intf = get_param(cmd, "Interface"); */
1177 const char *dst, *timeout;
1178 int wait_time = 90;
1179 char buf[100];
1180 int res;
1181
1182 dst = get_param(cmd, "destination");
1183 if (dst == NULL || !is_ip_addr(dst))
1184 return -1;
1185
1186 timeout = get_param(cmd, "timeout");
1187 if (timeout) {
1188 wait_time = atoi(timeout);
1189 if (wait_time < 1)
1190 wait_time = 1;
1191 }
1192
1193 /* TODO: force renewal of IP lease if DHCP is enabled */
1194
1195 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1196 res = system(buf);
1197 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1198 if (res == 0)
1199 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1200 else if (res == 256)
1201 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1202 else
1203 return -2;
1204
1205 return 0;
1206}
1207
1208
1209static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1210 struct sigma_cmd *cmd)
1211{
1212 /* const char *intf = get_param(cmd, "Interface"); */
1213 char bssid[20], resp[50];
1214
1215 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1216 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001217 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001218
1219 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1220 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1221 return 0;
1222}
1223
1224
1225#ifdef __SAMSUNG__
1226static int add_use_network(const char *ifname)
1227{
1228 char buf[100];
1229
1230 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1231 wpa_command(ifname, buf);
1232 return 0;
1233}
1234#endif /* __SAMSUNG__ */
1235
1236
1237static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1238 const char *ifname, struct sigma_cmd *cmd)
1239{
1240 const char *ssid = get_param(cmd, "ssid");
1241 int id;
1242 const char *val;
1243
1244 if (ssid == NULL)
1245 return -1;
1246
1247 start_sta_mode(dut);
1248
1249#ifdef __SAMSUNG__
1250 add_use_network(ifname);
1251#endif /* __SAMSUNG__ */
1252
1253 id = add_network(ifname);
1254 if (id < 0)
1255 return -2;
1256 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1257
1258 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1259 return -2;
1260
1261 dut->infra_network_id = id;
1262 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1263
1264 val = get_param(cmd, "program");
1265 if (!val)
1266 val = get_param(cmd, "prog");
1267 if (val && strcasecmp(val, "hs2") == 0) {
1268 char buf[100];
1269 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1270 wpa_command(ifname, buf);
1271
1272 val = get_param(cmd, "prefer");
1273 if (val && atoi(val) > 0)
1274 set_network(ifname, id, "priority", "1");
1275 }
1276
1277 return id;
1278}
1279
1280
1281static int cmd_sta_set_encryption(struct sigma_dut *dut,
1282 struct sigma_conn *conn,
1283 struct sigma_cmd *cmd)
1284{
1285 const char *intf = get_param(cmd, "Interface");
1286 const char *ssid = get_param(cmd, "ssid");
1287 const char *type = get_param(cmd, "encpType");
1288 const char *ifname;
1289 char buf[200];
1290 int id;
1291
1292 if (intf == NULL || ssid == NULL)
1293 return -1;
1294
1295 if (strcmp(intf, get_main_ifname()) == 0)
1296 ifname = get_station_ifname();
1297 else
1298 ifname = intf;
1299
1300 id = add_network_common(dut, conn, ifname, cmd);
1301 if (id < 0)
1302 return id;
1303
1304 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1305 return -2;
1306
1307 if (type && strcasecmp(type, "wep") == 0) {
1308 const char *val;
1309 int i;
1310
1311 val = get_param(cmd, "activeKey");
1312 if (val) {
1313 int keyid;
1314 keyid = atoi(val);
1315 if (keyid < 1 || keyid > 4)
1316 return -1;
1317 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1318 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1319 return -2;
1320 }
1321
1322 for (i = 0; i < 4; i++) {
1323 snprintf(buf, sizeof(buf), "key%d", i + 1);
1324 val = get_param(cmd, buf);
1325 if (val == NULL)
1326 continue;
1327 snprintf(buf, sizeof(buf), "wep_key%d", i);
1328 if (set_network(ifname, id, buf, val) < 0)
1329 return -2;
1330 }
1331 }
1332
1333 return 1;
1334}
1335
1336
1337static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1338 const char *ifname, struct sigma_cmd *cmd)
1339{
1340 const char *val;
1341 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001342 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001343 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301344 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001345
1346 id = add_network_common(dut, conn, ifname, cmd);
1347 if (id < 0)
1348 return id;
1349
Jouni Malinen47dcc952017-10-09 16:43:24 +03001350 val = get_param(cmd, "Type");
1351 owe = val && strcasecmp(val, "OWE") == 0;
1352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001353 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001354 if (!val && owe)
1355 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001356 if (val == NULL) {
1357 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1358 return 0;
1359 }
1360 if (strcasecmp(val, "wpa") == 0 ||
1361 strcasecmp(val, "wpa-psk") == 0) {
1362 if (set_network(ifname, id, "proto", "WPA") < 0)
1363 return -2;
1364 } else if (strcasecmp(val, "wpa2") == 0 ||
1365 strcasecmp(val, "wpa2-psk") == 0 ||
1366 strcasecmp(val, "wpa2-ft") == 0 ||
1367 strcasecmp(val, "wpa2-sha256") == 0) {
1368 if (set_network(ifname, id, "proto", "WPA2") < 0)
1369 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301370 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1371 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001372 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1373 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001374 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301375 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001376 if (set_network(ifname, id, "proto", "WPA2") < 0)
1377 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001378 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001379 } else {
1380 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1381 return 0;
1382 }
1383
1384 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001385 if (val) {
1386 cipher_set = 1;
1387 if (strcasecmp(val, "tkip") == 0) {
1388 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1389 return -2;
1390 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1391 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1392 return -2;
1393 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1394 if (set_network(ifname, id, "pairwise",
1395 "CCMP TKIP") < 0)
1396 return -2;
1397 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1398 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1399 return -2;
1400 if (set_network(ifname, id, "group", "GCMP") < 0)
1401 return -2;
1402 } else {
1403 send_resp(dut, conn, SIGMA_ERROR,
1404 "errorCode,Unrecognized encpType value");
1405 return 0;
1406 }
1407 }
1408
1409 val = get_param(cmd, "PairwiseCipher");
1410 if (val) {
1411 cipher_set = 1;
1412 /* TODO: Support space separated list */
1413 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1414 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1415 return -2;
1416 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1417 if (set_network(ifname, id, "pairwise",
1418 "CCMP-256") < 0)
1419 return -2;
1420 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1421 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1422 return -2;
1423 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1424 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1425 return -2;
1426 } else {
1427 send_resp(dut, conn, SIGMA_ERROR,
1428 "errorCode,Unrecognized PairwiseCipher value");
1429 return 0;
1430 }
1431 }
1432
Jouni Malinen47dcc952017-10-09 16:43:24 +03001433 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001434 send_resp(dut, conn, SIGMA_ERROR,
1435 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001436 return 0;
1437 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001438
1439 val = get_param(cmd, "GroupCipher");
1440 if (val) {
1441 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1442 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1443 return -2;
1444 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1445 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1446 return -2;
1447 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1448 if (set_network(ifname, id, "group", "GCMP") < 0)
1449 return -2;
1450 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1451 if (set_network(ifname, id, "group", "CCMP") < 0)
1452 return -2;
1453 } else {
1454 send_resp(dut, conn, SIGMA_ERROR,
1455 "errorCode,Unrecognized GroupCipher value");
1456 return 0;
1457 }
1458 }
1459
Jouni Malinen7b239522017-09-14 21:37:18 +03001460 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001461 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001462 const char *cipher;
1463
1464 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1465 cipher = "BIP-GMAC-256";
1466 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1467 cipher = "BIP-CMAC-256";
1468 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1469 cipher = "BIP-GMAC-128";
1470 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1471 cipher = "AES-128-CMAC";
1472 } else {
1473 send_resp(dut, conn, SIGMA_INVALID,
1474 "errorCode,Unsupported GroupMgntCipher");
1475 return 0;
1476 }
1477 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1478 send_resp(dut, conn, SIGMA_INVALID,
1479 "errorCode,Failed to set GroupMgntCipher");
1480 return 0;
1481 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001482 }
1483
1484 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301485
1486 if (dut->program == PROGRAM_OCE) {
1487 dut->sta_pmf = STA_PMF_OPTIONAL;
1488 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1489 return -2;
1490 }
1491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001492 val = get_param(cmd, "PMF");
1493 if (val) {
1494 if (strcasecmp(val, "Required") == 0 ||
1495 strcasecmp(val, "Forced_Required") == 0) {
1496 dut->sta_pmf = STA_PMF_REQUIRED;
1497 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1498 return -2;
1499 } else if (strcasecmp(val, "Optional") == 0) {
1500 dut->sta_pmf = STA_PMF_OPTIONAL;
1501 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1502 return -2;
1503 } else if (strcasecmp(val, "Disabled") == 0 ||
1504 strcasecmp(val, "Forced_Disabled") == 0) {
1505 dut->sta_pmf = STA_PMF_DISABLED;
1506 } else {
1507 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1508 return 0;
1509 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301510 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001511 dut->sta_pmf = STA_PMF_REQUIRED;
1512 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1513 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514 }
1515
1516 return id;
1517}
1518
1519
1520static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1521 struct sigma_cmd *cmd)
1522{
1523 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001524 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001525 const char *pmf = get_param(cmd, "PMF");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001526 const char *ifname, *val, *alg;
1527 int id;
1528
1529 if (intf == NULL)
1530 return -1;
1531
1532 if (strcmp(intf, get_main_ifname()) == 0)
1533 ifname = get_station_ifname();
1534 else
1535 ifname = intf;
1536
1537 id = set_wpa_common(dut, conn, ifname, cmd);
1538 if (id < 0)
1539 return id;
1540
1541 val = get_param(cmd, "keyMgmtType");
1542 alg = get_param(cmd, "micAlg");
1543
Jouni Malinen992a81e2017-08-22 13:57:47 +03001544 if (type && strcasecmp(type, "SAE") == 0) {
1545 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1546 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1547 return -2;
1548 } else {
1549 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1550 return -2;
1551 }
1552 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1553 sigma_dut_print(dut, DUT_MSG_ERROR,
1554 "Failed to clear sae_groups to default");
1555 return -2;
1556 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001557 if (!pmf) {
1558 dut->sta_pmf = STA_PMF_REQUIRED;
1559 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1560 return -2;
1561 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001562 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1563 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1564 if (set_network(ifname, id, "key_mgmt",
1565 "FT-SAE FT-PSK") < 0)
1566 return -2;
1567 } else {
1568 if (set_network(ifname, id, "key_mgmt",
1569 "SAE WPA-PSK") < 0)
1570 return -2;
1571 }
1572 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1573 sigma_dut_print(dut, DUT_MSG_ERROR,
1574 "Failed to clear sae_groups to default");
1575 return -2;
1576 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001577 if (!pmf) {
1578 dut->sta_pmf = STA_PMF_OPTIONAL;
1579 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1580 return -2;
1581 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001582 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001583 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1584 return -2;
1585 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1586 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1587 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301588 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1589 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1590 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001591 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1592 dut->sta_pmf == STA_PMF_REQUIRED) {
1593 if (set_network(ifname, id, "key_mgmt",
1594 "WPA-PSK WPA-PSK-SHA256") < 0)
1595 return -2;
1596 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1597 if (set_network(ifname, id, "key_mgmt",
1598 "WPA-PSK WPA-PSK-SHA256") < 0)
1599 return -2;
1600 } else {
1601 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1602 return -2;
1603 }
1604
1605 val = get_param(cmd, "passPhrase");
1606 if (val == NULL)
1607 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001608 if (type && strcasecmp(type, "SAE") == 0) {
1609 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1610 return -2;
1611 } else {
1612 if (set_network_quoted(ifname, id, "psk", val) < 0)
1613 return -2;
1614 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001615
Jouni Malinen992a81e2017-08-22 13:57:47 +03001616 val = get_param(cmd, "ECGroupID");
1617 if (val) {
1618 char buf[50];
1619
1620 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1621 if (wpa_command(ifname, buf) != 0) {
1622 sigma_dut_print(dut, DUT_MSG_ERROR,
1623 "Failed to clear sae_groups");
1624 return -2;
1625 }
1626 }
1627
Jouni Malinen68143132017-09-02 02:34:08 +03001628 val = get_param(cmd, "InvalidSAEElement");
1629 if (val) {
1630 free(dut->sae_commit_override);
1631 dut->sae_commit_override = strdup(val);
1632 }
1633
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001634 return 1;
1635}
1636
1637
1638static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301639 const char *ifname, int username_identity,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301642 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643 int id;
1644 char buf[200];
1645#ifdef ANDROID
1646 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1647 int length;
1648#endif /* ANDROID */
1649
1650 id = set_wpa_common(dut, conn, ifname, cmd);
1651 if (id < 0)
1652 return id;
1653
1654 val = get_param(cmd, "keyMgmtType");
1655 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301656 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001657
Jouni Malinenad395a22017-09-01 21:13:46 +03001658 if (val && strcasecmp(val, "SuiteB") == 0) {
1659 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1660 0)
1661 return -2;
1662 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001663 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1664 return -2;
1665 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1666 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1667 return -2;
1668 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1669 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1670 return -2;
1671 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1672 dut->sta_pmf == STA_PMF_REQUIRED) {
1673 if (set_network(ifname, id, "key_mgmt",
1674 "WPA-EAP WPA-EAP-SHA256") < 0)
1675 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301676 } else if (akm && atoi(akm) == 14) {
1677 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1678 dut->sta_pmf == STA_PMF_REQUIRED) {
1679 if (set_network(ifname, id, "key_mgmt",
1680 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1681 return -2;
1682 } else {
1683 if (set_network(ifname, id, "key_mgmt",
1684 "WPA-EAP FILS-SHA256") < 0)
1685 return -2;
1686 }
1687
1688 if (set_network(ifname, id, "erp", "1") < 0)
1689 return -2;
1690 } else if (akm && atoi(akm) == 15) {
1691 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1692 dut->sta_pmf == STA_PMF_REQUIRED) {
1693 if (set_network(ifname, id, "key_mgmt",
1694 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1695 return -2;
1696 } else {
1697 if (set_network(ifname, id, "key_mgmt",
1698 "WPA-EAP FILS-SHA384") < 0)
1699 return -2;
1700 }
1701
1702 if (set_network(ifname, id, "erp", "1") < 0)
1703 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1705 if (set_network(ifname, id, "key_mgmt",
1706 "WPA-EAP WPA-EAP-SHA256") < 0)
1707 return -2;
1708 } else {
1709 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1710 return -2;
1711 }
1712
1713 val = get_param(cmd, "trustedRootCA");
1714 if (val) {
1715#ifdef ANDROID
1716 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1717 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1718 kvalue);
1719 if (length > 0) {
1720 sigma_dut_print(dut, DUT_MSG_INFO,
1721 "Use Android keystore [%s]", buf);
1722 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1723 val);
1724 goto ca_cert_selected;
1725 }
1726#endif /* ANDROID */
1727
1728 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1729#ifdef __linux__
1730 if (!file_exists(buf)) {
1731 char msg[300];
1732 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1733 "file (%s) not found", buf);
1734 send_resp(dut, conn, SIGMA_ERROR, msg);
1735 return -3;
1736 }
1737#endif /* __linux__ */
1738#ifdef ANDROID
1739ca_cert_selected:
1740#endif /* ANDROID */
1741 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1742 return -2;
1743 }
1744
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301745 if (username_identity) {
1746 val = get_param(cmd, "username");
1747 if (val) {
1748 if (set_network_quoted(ifname, id, "identity", val) < 0)
1749 return -2;
1750 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001751
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301752 val = get_param(cmd, "password");
1753 if (val) {
1754 if (set_network_quoted(ifname, id, "password", val) < 0)
1755 return -2;
1756 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001757 }
1758
1759 return id;
1760}
1761
1762
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001763static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1764{
1765 const char *val;
1766
1767 if (!cipher)
1768 return 0;
1769
1770 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1771 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1772 else if (strcasecmp(cipher,
1773 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1774 val = "ECDHE-RSA-AES256-GCM-SHA384";
1775 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1776 val = "DHE-RSA-AES256-GCM-SHA384";
1777 else if (strcasecmp(cipher,
1778 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1779 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1780 else
1781 return -1;
1782
1783 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1784 set_network_quoted(ifname, id, "phase1", "");
1785
1786 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1787}
1788
1789
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1791 struct sigma_cmd *cmd)
1792{
1793 const char *intf = get_param(cmd, "Interface");
1794 const char *ifname, *val;
1795 int id;
1796 char buf[200];
1797#ifdef ANDROID
1798 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1799 int length;
1800 int jb_or_newer = 0;
1801 char prop[PROPERTY_VALUE_MAX];
1802#endif /* ANDROID */
1803
1804 if (intf == NULL)
1805 return -1;
1806
1807 if (strcmp(intf, get_main_ifname()) == 0)
1808 ifname = get_station_ifname();
1809 else
1810 ifname = intf;
1811
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301812 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 if (id < 0)
1814 return id;
1815
1816 if (set_network(ifname, id, "eap", "TLS") < 0)
1817 return -2;
1818
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301819 if (!get_param(cmd, "username") &&
1820 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001821 "wifi-user@wifilabs.local") < 0)
1822 return -2;
1823
1824 val = get_param(cmd, "clientCertificate");
1825 if (val == NULL)
1826 return -1;
1827#ifdef ANDROID
1828 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1829 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1830 if (length < 0) {
1831 /*
1832 * JB started reporting keystore type mismatches, so retry with
1833 * the GET_PUBKEY command if the generic GET fails.
1834 */
1835 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1836 buf, kvalue);
1837 }
1838
1839 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1840 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1841 if (strncmp(prop, "4.0", 3) != 0)
1842 jb_or_newer = 1;
1843 } else
1844 jb_or_newer = 1; /* assume newer */
1845
1846 if (jb_or_newer && length > 0) {
1847 sigma_dut_print(dut, DUT_MSG_INFO,
1848 "Use Android keystore [%s]", buf);
1849 if (set_network(ifname, id, "engine", "1") < 0)
1850 return -2;
1851 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1852 return -2;
1853 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1854 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1855 return -2;
1856 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1857 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1858 return -2;
1859 return 1;
1860 } else if (length > 0) {
1861 sigma_dut_print(dut, DUT_MSG_INFO,
1862 "Use Android keystore [%s]", buf);
1863 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1864 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1865 return -2;
1866 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1867 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1868 return -2;
1869 return 1;
1870 }
1871#endif /* ANDROID */
1872
1873 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1874#ifdef __linux__
1875 if (!file_exists(buf)) {
1876 char msg[300];
1877 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1878 "(%s) not found", buf);
1879 send_resp(dut, conn, SIGMA_ERROR, msg);
1880 return -3;
1881 }
1882#endif /* __linux__ */
1883 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1884 return -2;
1885 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1886 return -2;
1887
1888 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1889 return -2;
1890
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001891 val = get_param(cmd, "keyMgmtType");
1892 if (val && strcasecmp(val, "SuiteB") == 0) {
1893 val = get_param(cmd, "CertType");
1894 if (val && strcasecmp(val, "RSA") == 0) {
1895 if (set_network_quoted(ifname, id, "phase1",
1896 "tls_suiteb=1") < 0)
1897 return -2;
1898 } else {
1899 if (set_network_quoted(ifname, id, "openssl_ciphers",
1900 "SUITEB192") < 0)
1901 return -2;
1902 }
1903
1904 val = get_param(cmd, "TLSCipher");
1905 if (set_tls_cipher(ifname, id, val) < 0) {
1906 send_resp(dut, conn, SIGMA_ERROR,
1907 "ErrorCode,Unsupported TLSCipher value");
1908 return -3;
1909 }
1910 }
1911
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001912 return 1;
1913}
1914
1915
1916static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1917 struct sigma_cmd *cmd)
1918{
1919 const char *intf = get_param(cmd, "Interface");
1920 const char *ifname;
1921 int id;
1922
1923 if (intf == NULL)
1924 return -1;
1925
1926 if (strcmp(intf, get_main_ifname()) == 0)
1927 ifname = get_station_ifname();
1928 else
1929 ifname = intf;
1930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301931 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (id < 0)
1933 return id;
1934
1935 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1936 send_resp(dut, conn, SIGMA_ERROR,
1937 "errorCode,Failed to set TTLS method");
1938 return 0;
1939 }
1940
1941 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1942 send_resp(dut, conn, SIGMA_ERROR,
1943 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1944 return 0;
1945 }
1946
1947 return 1;
1948}
1949
1950
1951static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1952 struct sigma_cmd *cmd)
1953{
1954 const char *intf = get_param(cmd, "Interface");
1955 const char *ifname;
1956 int id;
1957
1958 if (intf == NULL)
1959 return -1;
1960
1961 if (strcmp(intf, get_main_ifname()) == 0)
1962 ifname = get_station_ifname();
1963 else
1964 ifname = intf;
1965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001967 if (id < 0)
1968 return id;
1969
1970 if (set_network(ifname, id, "eap", "SIM") < 0)
1971 return -2;
1972
1973 return 1;
1974}
1975
1976
1977static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1978 struct sigma_cmd *cmd)
1979{
1980 const char *intf = get_param(cmd, "Interface");
1981 const char *ifname, *val;
1982 int id;
1983 char buf[100];
1984
1985 if (intf == NULL)
1986 return -1;
1987
1988 if (strcmp(intf, get_main_ifname()) == 0)
1989 ifname = get_station_ifname();
1990 else
1991 ifname = intf;
1992
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301993 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001994 if (id < 0)
1995 return id;
1996
1997 if (set_network(ifname, id, "eap", "PEAP") < 0)
1998 return -2;
1999
2000 val = get_param(cmd, "innerEAP");
2001 if (val) {
2002 if (strcasecmp(val, "MSCHAPv2") == 0) {
2003 if (set_network_quoted(ifname, id, "phase2",
2004 "auth=MSCHAPV2") < 0)
2005 return -2;
2006 } else if (strcasecmp(val, "GTC") == 0) {
2007 if (set_network_quoted(ifname, id, "phase2",
2008 "auth=GTC") < 0)
2009 return -2;
2010 } else
2011 return -1;
2012 }
2013
2014 val = get_param(cmd, "peapVersion");
2015 if (val) {
2016 int ver = atoi(val);
2017 if (ver < 0 || ver > 1)
2018 return -1;
2019 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2020 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2021 return -2;
2022 }
2023
2024 return 1;
2025}
2026
2027
2028static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2029 struct sigma_cmd *cmd)
2030{
2031 const char *intf = get_param(cmd, "Interface");
2032 const char *ifname, *val;
2033 int id;
2034 char buf[100];
2035
2036 if (intf == NULL)
2037 return -1;
2038
2039 if (strcmp(intf, get_main_ifname()) == 0)
2040 ifname = get_station_ifname();
2041 else
2042 ifname = intf;
2043
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302044 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002045 if (id < 0)
2046 return id;
2047
2048 if (set_network(ifname, id, "eap", "FAST") < 0)
2049 return -2;
2050
2051 val = get_param(cmd, "innerEAP");
2052 if (val) {
2053 if (strcasecmp(val, "MSCHAPV2") == 0) {
2054 if (set_network_quoted(ifname, id, "phase2",
2055 "auth=MSCHAPV2") < 0)
2056 return -2;
2057 } else if (strcasecmp(val, "GTC") == 0) {
2058 if (set_network_quoted(ifname, id, "phase2",
2059 "auth=GTC") < 0)
2060 return -2;
2061 } else
2062 return -1;
2063 }
2064
2065 val = get_param(cmd, "validateServer");
2066 if (val) {
2067 /* TODO */
2068 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2069 "validateServer=%s", val);
2070 }
2071
2072 val = get_param(cmd, "pacFile");
2073 if (val) {
2074 snprintf(buf, sizeof(buf), "blob://%s", val);
2075 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2076 return -2;
2077 }
2078
2079 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2080 0)
2081 return -2;
2082
2083 return 1;
2084}
2085
2086
2087static int cmd_sta_set_eapaka(struct sigma_dut *dut, 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 cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2114 struct sigma_conn *conn,
2115 struct sigma_cmd *cmd)
2116{
2117 const char *intf = get_param(cmd, "Interface");
2118 const char *ifname;
2119 int id;
2120
2121 if (intf == NULL)
2122 return -1;
2123
2124 if (strcmp(intf, get_main_ifname()) == 0)
2125 ifname = get_station_ifname();
2126 else
2127 ifname = intf;
2128
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302129 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 if (id < 0)
2131 return id;
2132
2133 if (set_network(ifname, id, "eap", "AKA'") < 0)
2134 return -2;
2135
2136 return 1;
2137}
2138
2139
2140static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2141 struct sigma_cmd *cmd)
2142{
2143 const char *intf = get_param(cmd, "Interface");
2144 const char *ifname;
2145 int id;
2146
2147 if (strcmp(intf, get_main_ifname()) == 0)
2148 ifname = get_station_ifname();
2149 else
2150 ifname = intf;
2151
2152 id = add_network_common(dut, conn, ifname, cmd);
2153 if (id < 0)
2154 return id;
2155
2156 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2157 return -2;
2158
2159 return 1;
2160}
2161
2162
Jouni Malinen47dcc952017-10-09 16:43:24 +03002163static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2164 struct sigma_cmd *cmd)
2165{
2166 const char *intf = get_param(cmd, "Interface");
2167 const char *ifname, *val;
2168 int id;
2169
2170 if (intf == NULL)
2171 return -1;
2172
2173 if (strcmp(intf, get_main_ifname()) == 0)
2174 ifname = get_station_ifname();
2175 else
2176 ifname = intf;
2177
2178 id = set_wpa_common(dut, conn, ifname, cmd);
2179 if (id < 0)
2180 return id;
2181
2182 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2183 return -2;
2184
2185 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002186 if (val && strcmp(val, "0") == 0) {
2187 if (wpa_command(ifname,
2188 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2189 sigma_dut_print(dut, DUT_MSG_ERROR,
2190 "Failed to set OWE DH Param element override");
2191 return -2;
2192 }
2193 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002194 sigma_dut_print(dut, DUT_MSG_ERROR,
2195 "Failed to clear owe_group");
2196 return -2;
2197 }
2198
2199 return 1;
2200}
2201
2202
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002203static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2204 struct sigma_cmd *cmd)
2205{
2206 const char *type = get_param(cmd, "Type");
2207
2208 if (type == NULL) {
2209 send_resp(dut, conn, SIGMA_ERROR,
2210 "ErrorCode,Missing Type argument");
2211 return 0;
2212 }
2213
2214 if (strcasecmp(type, "OPEN") == 0)
2215 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002216 if (strcasecmp(type, "OWE") == 0)
2217 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002218 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002219 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002220 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 return cmd_sta_set_psk(dut, conn, cmd);
2222 if (strcasecmp(type, "EAPTLS") == 0)
2223 return cmd_sta_set_eaptls(dut, conn, cmd);
2224 if (strcasecmp(type, "EAPTTLS") == 0)
2225 return cmd_sta_set_eapttls(dut, conn, cmd);
2226 if (strcasecmp(type, "EAPPEAP") == 0)
2227 return cmd_sta_set_peap(dut, conn, cmd);
2228 if (strcasecmp(type, "EAPSIM") == 0)
2229 return cmd_sta_set_eapsim(dut, conn, cmd);
2230 if (strcasecmp(type, "EAPFAST") == 0)
2231 return cmd_sta_set_eapfast(dut, conn, cmd);
2232 if (strcasecmp(type, "EAPAKA") == 0)
2233 return cmd_sta_set_eapaka(dut, conn, cmd);
2234 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2235 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002236 if (strcasecmp(type, "wep") == 0)
2237 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002238
2239 send_resp(dut, conn, SIGMA_ERROR,
2240 "ErrorCode,Unsupported Type value");
2241 return 0;
2242}
2243
2244
2245int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2246{
2247#ifdef __linux__
2248 /* special handling for ath6kl */
2249 char path[128], fname[128], *pos;
2250 ssize_t res;
2251 FILE *f;
2252
2253 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2254 res = readlink(path, path, sizeof(path));
2255 if (res < 0)
2256 return 0; /* not ath6kl */
2257
2258 if (res >= (int) sizeof(path))
2259 res = sizeof(path) - 1;
2260 path[res] = '\0';
2261 pos = strrchr(path, '/');
2262 if (pos == NULL)
2263 pos = path;
2264 else
2265 pos++;
2266 snprintf(fname, sizeof(fname),
2267 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2268 "create_qos", pos);
2269 if (!file_exists(fname))
2270 return 0; /* not ath6kl */
2271
2272 if (uapsd) {
2273 f = fopen(fname, "w");
2274 if (f == NULL)
2275 return -1;
2276
2277 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2278 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2279 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2280 "20000 0\n");
2281 fclose(f);
2282 } else {
2283 snprintf(fname, sizeof(fname),
2284 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2285 "delete_qos", pos);
2286
2287 f = fopen(fname, "w");
2288 if (f == NULL)
2289 return -1;
2290
2291 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2292 fprintf(f, "2 4\n");
2293 fclose(f);
2294 }
2295#endif /* __linux__ */
2296
2297 return 0;
2298}
2299
2300
2301static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2302 struct sigma_cmd *cmd)
2303{
2304 const char *intf = get_param(cmd, "Interface");
2305 /* const char *ssid = get_param(cmd, "ssid"); */
2306 const char *val;
2307 int max_sp_len = 4;
2308 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2309 char buf[100];
2310 int ret1, ret2;
2311
2312 val = get_param(cmd, "maxSPLength");
2313 if (val) {
2314 max_sp_len = atoi(val);
2315 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2316 max_sp_len != 4)
2317 return -1;
2318 }
2319
2320 val = get_param(cmd, "acBE");
2321 if (val)
2322 ac_be = atoi(val);
2323
2324 val = get_param(cmd, "acBK");
2325 if (val)
2326 ac_bk = atoi(val);
2327
2328 val = get_param(cmd, "acVI");
2329 if (val)
2330 ac_vi = atoi(val);
2331
2332 val = get_param(cmd, "acVO");
2333 if (val)
2334 ac_vo = atoi(val);
2335
2336 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2337
2338 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2339 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2340 ret1 = wpa_command(intf, buf);
2341
2342 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2343 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2344 ret2 = wpa_command(intf, buf);
2345
2346 if (ret1 && ret2) {
2347 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2348 "UAPSD parameters.");
2349 return -2;
2350 }
2351
2352 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2353 send_resp(dut, conn, SIGMA_ERROR,
2354 "ErrorCode,Failed to set ath6kl QoS parameters");
2355 return 0;
2356 }
2357
2358 return 1;
2359}
2360
2361
2362static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2363 struct sigma_cmd *cmd)
2364{
2365 char buf[1000];
2366 const char *intf = get_param(cmd, "Interface");
2367 const char *grp = get_param(cmd, "Group");
2368 const char *act = get_param(cmd, "Action");
2369 const char *tid = get_param(cmd, "Tid");
2370 const char *dir = get_param(cmd, "Direction");
2371 const char *psb = get_param(cmd, "Psb");
2372 const char *up = get_param(cmd, "Up");
2373 const char *fixed = get_param(cmd, "Fixed");
2374 const char *size = get_param(cmd, "Size");
2375 const char *msize = get_param(cmd, "Maxsize");
2376 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2377 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2378 const char *inact = get_param(cmd, "Inactivity");
2379 const char *sus = get_param(cmd, "Suspension");
2380 const char *mindr = get_param(cmd, "Mindatarate");
2381 const char *meandr = get_param(cmd, "Meandatarate");
2382 const char *peakdr = get_param(cmd, "Peakdatarate");
2383 const char *phyrate = get_param(cmd, "Phyrate");
2384 const char *burstsize = get_param(cmd, "Burstsize");
2385 const char *sba = get_param(cmd, "Sba");
2386 int direction;
2387 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002388 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002389 int fixed_int;
2390 int psb_ts;
2391
2392 if (intf == NULL || grp == NULL || act == NULL )
2393 return -1;
2394
2395 if (strcasecmp(act, "addts") == 0) {
2396 if (tid == NULL || dir == NULL || psb == NULL ||
2397 up == NULL || fixed == NULL || size == NULL)
2398 return -1;
2399
2400 /*
2401 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2402 * possible values, but WMM-AC and V-E test scripts use "UP,
2403 * "DOWN", and "BIDI".
2404 */
2405 if (strcasecmp(dir, "uplink") == 0 ||
2406 strcasecmp(dir, "up") == 0) {
2407 direction = 0;
2408 } else if (strcasecmp(dir, "downlink") == 0 ||
2409 strcasecmp(dir, "down") == 0) {
2410 direction = 1;
2411 } else if (strcasecmp(dir, "bidi") == 0) {
2412 direction = 2;
2413 } else {
2414 sigma_dut_print(dut, DUT_MSG_ERROR,
2415 "Direction %s not supported", dir);
2416 return -1;
2417 }
2418
2419 if (strcasecmp(psb, "legacy") == 0) {
2420 psb_ts = 0;
2421 } else if (strcasecmp(psb, "uapsd") == 0) {
2422 psb_ts = 1;
2423 } else {
2424 sigma_dut_print(dut, DUT_MSG_ERROR,
2425 "PSB %s not supported", psb);
2426 return -1;
2427 }
2428
2429 if (atoi(tid) < 0 || atoi(tid) > 7) {
2430 sigma_dut_print(dut, DUT_MSG_ERROR,
2431 "TID %s not supported", tid);
2432 return -1;
2433 }
2434
2435 if (strcasecmp(fixed, "true") == 0) {
2436 fixed_int = 1;
2437 } else {
2438 fixed_int = 0;
2439 }
2440
Peng Xu93319622017-10-04 17:58:16 -07002441 if (sba)
2442 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002443
2444 dut->dialog_token++;
2445 handle = 7000 + dut->dialog_token;
2446
2447 /*
2448 * size: convert to hex
2449 * maxsi: convert to hex
2450 * mindr: convert to hex
2451 * meandr: convert to hex
2452 * peakdr: convert to hex
2453 * burstsize: convert to hex
2454 * phyrate: convert to hex
2455 * sba: convert to hex with modification
2456 * minsi: convert to integer
2457 * sus: convert to integer
2458 * inact: convert to integer
2459 * maxsi: convert to integer
2460 */
2461
2462 /*
2463 * The Nominal MSDU Size field is 2 octets long and contains an
2464 * unsigned integer that specifies the nominal size, in octets,
2465 * of MSDUs belonging to the traffic under this traffic
2466 * specification and is defined in Figure 16. If the Fixed
2467 * subfield is set to 1, then the size of the MSDU is fixed and
2468 * is indicated by the Size Subfield. If the Fixed subfield is
2469 * set to 0, then the size of the MSDU might not be fixed and
2470 * the Size indicates the nominal MSDU size.
2471 *
2472 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2473 * and specifies the excess allocation of time (and bandwidth)
2474 * over and above the stated rates required to transport an MSDU
2475 * belonging to the traffic in this TSPEC. This field is
2476 * represented as an unsigned binary number with an implicit
2477 * binary point after the leftmost 3 bits. For example, an SBA
2478 * of 1.75 is represented as 0x3800. This field is included to
2479 * account for retransmissions. As such, the value of this field
2480 * must be greater than unity.
2481 */
2482
2483 snprintf(buf, sizeof(buf),
2484 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2485 " 0x%X 0x%X 0x%X"
2486 " 0x%X 0x%X 0x%X"
2487 " 0x%X %d %d %d %d"
2488 " %d %d",
2489 intf, handle, tid, direction, psb_ts, up,
2490 (unsigned int) ((fixed_int << 15) | atoi(size)),
2491 msize ? atoi(msize) : 0,
2492 mindr ? atoi(mindr) : 0,
2493 meandr ? atoi(meandr) : 0,
2494 peakdr ? atoi(peakdr) : 0,
2495 burstsize ? atoi(burstsize) : 0,
2496 phyrate ? atoi(phyrate) : 0,
2497 sba ? ((unsigned int) (((int) sba_fv << 13) |
2498 (int)((sba_fv - (int) sba_fv) *
2499 8192))) : 0,
2500 minsi ? atoi(minsi) : 0,
2501 sus ? atoi(sus) : 0,
2502 0, 0,
2503 inact ? atoi(inact) : 0,
2504 maxsi ? atoi(maxsi) : 0);
2505
2506 if (system(buf) != 0) {
2507 sigma_dut_print(dut, DUT_MSG_ERROR,
2508 "iwpriv addtspec request failed");
2509 send_resp(dut, conn, SIGMA_ERROR,
2510 "errorCode,Failed to execute addTspec command");
2511 return 0;
2512 }
2513
2514 sigma_dut_print(dut, DUT_MSG_INFO,
2515 "iwpriv addtspec request send");
2516
2517 /* Mapping handle to a TID */
2518 dut->tid_to_handle[atoi(tid)] = handle;
2519 } else if (strcasecmp(act, "delts") == 0) {
2520 if (tid == NULL)
2521 return -1;
2522
2523 if (atoi(tid) < 0 || atoi(tid) > 7) {
2524 sigma_dut_print(dut, DUT_MSG_ERROR,
2525 "TID %s not supported", tid);
2526 send_resp(dut, conn, SIGMA_ERROR,
2527 "errorCode,Unsupported TID");
2528 return 0;
2529 }
2530
2531 handle = dut->tid_to_handle[atoi(tid)];
2532
2533 if (handle < 7000 || handle > 7255) {
2534 /* Invalid handle ie no mapping for that TID */
2535 sigma_dut_print(dut, DUT_MSG_ERROR,
2536 "handle-> %d not found", handle);
2537 }
2538
2539 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2540 intf, handle);
2541
2542 if (system(buf) != 0) {
2543 sigma_dut_print(dut, DUT_MSG_ERROR,
2544 "iwpriv deltspec request failed");
2545 send_resp(dut, conn, SIGMA_ERROR,
2546 "errorCode,Failed to execute delTspec command");
2547 return 0;
2548 }
2549
2550 sigma_dut_print(dut, DUT_MSG_INFO,
2551 "iwpriv deltspec request send");
2552
2553 dut->tid_to_handle[atoi(tid)] = 0;
2554 } else {
2555 sigma_dut_print(dut, DUT_MSG_ERROR,
2556 "Action type %s not supported", act);
2557 send_resp(dut, conn, SIGMA_ERROR,
2558 "errorCode,Unsupported Action");
2559 return 0;
2560 }
2561
2562 return 1;
2563}
2564
2565
vamsi krishna52e16f92017-08-29 12:37:34 +05302566static int find_network(struct sigma_dut *dut, const char *ssid)
2567{
2568 char list[4096];
2569 char *pos;
2570
2571 sigma_dut_print(dut, DUT_MSG_DEBUG,
2572 "Search for profile based on SSID: '%s'", ssid);
2573 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2574 list, sizeof(list)) < 0)
2575 return -1;
2576 pos = strstr(list, ssid);
2577 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2578 return -1;
2579
2580 while (pos > list && pos[-1] != '\n')
2581 pos--;
2582 dut->infra_network_id = atoi(pos);
2583 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2584 return 0;
2585}
2586
2587
Sunil Dutt44595082018-02-12 19:41:45 +05302588#ifdef NL80211_SUPPORT
2589static int sta_config_rsnie(struct sigma_dut *dut, int val)
2590{
2591 struct nl_msg *msg;
2592 int ret;
2593 struct nlattr *params;
2594 int ifindex;
2595
2596 ifindex = if_nametoindex("wlan0");
2597 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2598 NL80211_CMD_VENDOR)) ||
2599 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2600 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2601 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2602 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2603 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2604 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2605 sigma_dut_print(dut, DUT_MSG_ERROR,
2606 "%s: err in adding vendor_cmd and vendor_data",
2607 __func__);
2608 nlmsg_free(msg);
2609 return -1;
2610 }
2611 nla_nest_end(msg, params);
2612
2613 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2614 if (ret) {
2615 sigma_dut_print(dut, DUT_MSG_ERROR,
2616 "%s: err in send_and_recv_msgs, ret=%d",
2617 __func__, ret);
2618 return ret;
2619 }
2620
2621 return 0;
2622}
2623#endif /* NL80211_SUPPORT */
2624
2625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002626static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2627 struct sigma_cmd *cmd)
2628{
2629 /* const char *intf = get_param(cmd, "Interface"); */
2630 const char *ssid = get_param(cmd, "ssid");
2631 const char *wps_param = get_param(cmd, "WPS");
2632 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002633 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002634 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002635 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002636
2637 if (ssid == NULL)
2638 return -1;
2639
Jouni Malinen3c367e82017-06-23 17:01:47 +03002640 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302641#ifdef NL80211_SUPPORT
2642 if (get_driver_type() == DRIVER_WCN) {
2643 sta_config_rsnie(dut, 1);
2644 dut->config_rsnie = 1;
2645 }
2646#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002647 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2648 dut->rsne_override);
2649 if (wpa_command(get_station_ifname(), buf) < 0) {
2650 send_resp(dut, conn, SIGMA_ERROR,
2651 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2652 return 0;
2653 }
2654 }
2655
Jouni Malinen68143132017-09-02 02:34:08 +03002656 if (dut->sae_commit_override) {
2657 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2658 dut->sae_commit_override);
2659 if (wpa_command(get_station_ifname(), buf) < 0) {
2660 send_resp(dut, conn, SIGMA_ERROR,
2661 "ErrorCode,Failed to set SAE commit override");
2662 return 0;
2663 }
2664 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302665#ifdef ANDROID
2666 if (dut->fils_hlp)
2667 process_fils_hlp(dut);
2668#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002670 if (wps_param &&
2671 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2672 wps = 1;
2673
2674 if (wps) {
2675 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2676 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2677 "parameters not yet set");
2678 return 0;
2679 }
2680 if (dut->wps_method == WFA_CS_WPS_PBC) {
2681 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2682 return -2;
2683 } else {
2684 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2685 dut->wps_pin);
2686 if (wpa_command(get_station_ifname(), buf) < 0)
2687 return -2;
2688 }
2689 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302690 if (strcmp(ssid, dut->infra_ssid) == 0) {
2691 sigma_dut_print(dut, DUT_MSG_DEBUG,
2692 "sta_associate for the most recently added network");
2693 } else if (find_network(dut, ssid) < 0) {
2694 sigma_dut_print(dut, DUT_MSG_DEBUG,
2695 "sta_associate for a previously stored network profile");
2696 send_resp(dut, conn, SIGMA_ERROR,
2697 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002698 return 0;
2699 }
2700
2701 if (bssid &&
2702 set_network(get_station_ifname(), dut->infra_network_id,
2703 "bssid", bssid) < 0) {
2704 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2705 "Invalid bssid argument");
2706 return 0;
2707 }
2708
Jouni Malinen46a19b62017-06-23 14:31:27 +03002709 extra[0] = '\0';
2710 if (chan)
2711 snprintf(extra, sizeof(extra), " freq=%u",
2712 channel_to_freq(atoi(chan)));
2713 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2714 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002715 if (wpa_command(get_station_ifname(), buf) < 0) {
2716 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2717 "network id %d on %s",
2718 dut->infra_network_id,
2719 get_station_ifname());
2720 return -2;
2721 }
2722 }
2723
2724 return 1;
2725}
2726
2727
2728static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2729{
2730 char buf[500], cmd[200];
2731 int res;
2732
2733 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2734 * default path */
2735 res = snprintf(cmd, sizeof(cmd),
2736 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2737 file_exists("./hs20-osu-client") ?
2738 "./hs20-osu-client" : "hs20-osu-client",
2739 sigma_wpas_ctrl,
2740 dut->summary_log ? "-s " : "",
2741 dut->summary_log ? dut->summary_log : "");
2742 if (res < 0 || res >= (int) sizeof(cmd))
2743 return -1;
2744
2745 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2746 if (res < 0 || res >= (int) sizeof(buf))
2747 return -1;
2748 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2749
2750 if (system(buf) != 0) {
2751 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2752 return -1;
2753 }
2754 sigma_dut_print(dut, DUT_MSG_DEBUG,
2755 "Completed hs20-osu-client operation");
2756
2757 return 0;
2758}
2759
2760
2761static int download_ppsmo(struct sigma_dut *dut,
2762 struct sigma_conn *conn,
2763 const char *intf,
2764 struct sigma_cmd *cmd)
2765{
2766 const char *name, *path, *val;
2767 char url[500], buf[600], fbuf[100];
2768 char *fqdn = NULL;
2769
2770 name = get_param(cmd, "FileName");
2771 path = get_param(cmd, "FilePath");
2772 if (name == NULL || path == NULL)
2773 return -1;
2774
2775 if (strcasecmp(path, "VendorSpecific") == 0) {
2776 snprintf(url, sizeof(url), "PPS/%s", name);
2777 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2778 "from the device (%s)", url);
2779 if (!file_exists(url)) {
2780 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2781 "PPS MO file does not exist");
2782 return 0;
2783 }
2784 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2785 if (system(buf) != 0) {
2786 send_resp(dut, conn, SIGMA_ERROR,
2787 "errorCode,Failed to copy PPS MO");
2788 return 0;
2789 }
2790 } else if (strncasecmp(path, "http:", 5) != 0 &&
2791 strncasecmp(path, "https:", 6) != 0) {
2792 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2793 "Unsupported FilePath value");
2794 return 0;
2795 } else {
2796 snprintf(url, sizeof(url), "%s/%s", path, name);
2797 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2798 url);
2799 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2800 remove("pps-tnds.xml");
2801 if (system(buf) != 0) {
2802 send_resp(dut, conn, SIGMA_ERROR,
2803 "errorCode,Failed to download PPS MO");
2804 return 0;
2805 }
2806 }
2807
2808 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2809 send_resp(dut, conn, SIGMA_ERROR,
2810 "errorCode,Failed to parse downloaded PPSMO");
2811 return 0;
2812 }
2813 unlink("pps-tnds.xml");
2814
2815 val = get_param(cmd, "managementTreeURI");
2816 if (val) {
2817 const char *pos, *end;
2818 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2819 val);
2820 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2821 send_resp(dut, conn, SIGMA_ERROR,
2822 "errorCode,Invalid managementTreeURI prefix");
2823 return 0;
2824 }
2825 pos = val + 8;
2826 end = strchr(pos, '/');
2827 if (end == NULL ||
2828 strcmp(end, "/PerProviderSubscription") != 0) {
2829 send_resp(dut, conn, SIGMA_ERROR,
2830 "errorCode,Invalid managementTreeURI postfix");
2831 return 0;
2832 }
2833 if (end - pos >= (int) sizeof(fbuf)) {
2834 send_resp(dut, conn, SIGMA_ERROR,
2835 "errorCode,Too long FQDN in managementTreeURI");
2836 return 0;
2837 }
2838 memcpy(fbuf, pos, end - pos);
2839 fbuf[end - pos] = '\0';
2840 fqdn = fbuf;
2841 sigma_dut_print(dut, DUT_MSG_INFO,
2842 "FQDN from managementTreeURI: %s", fqdn);
2843 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2844 FILE *f = fopen("pps-fqdn", "r");
2845 if (f) {
2846 if (fgets(fbuf, sizeof(fbuf), f)) {
2847 fbuf[sizeof(fbuf) - 1] = '\0';
2848 fqdn = fbuf;
2849 sigma_dut_print(dut, DUT_MSG_DEBUG,
2850 "Use FQDN %s", fqdn);
2851 }
2852 fclose(f);
2853 }
2854 }
2855
2856 if (fqdn == NULL) {
2857 send_resp(dut, conn, SIGMA_ERROR,
2858 "errorCode,No FQDN specified");
2859 return 0;
2860 }
2861
2862 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2863 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2864 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2865
2866 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2867 if (rename("pps.xml", buf) < 0) {
2868 send_resp(dut, conn, SIGMA_ERROR,
2869 "errorCode,Could not move PPS MO");
2870 return 0;
2871 }
2872
2873 if (strcasecmp(path, "VendorSpecific") == 0) {
2874 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2875 fqdn);
2876 if (system(buf)) {
2877 send_resp(dut, conn, SIGMA_ERROR,
2878 "errorCode,Failed to copy OSU CA cert");
2879 return 0;
2880 }
2881
2882 snprintf(buf, sizeof(buf),
2883 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2884 fqdn);
2885 if (system(buf)) {
2886 send_resp(dut, conn, SIGMA_ERROR,
2887 "errorCode,Failed to copy AAA CA cert");
2888 return 0;
2889 }
2890 } else {
2891 snprintf(buf, sizeof(buf),
2892 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2893 fqdn, fqdn);
2894 if (run_hs20_osu(dut, buf) < 0) {
2895 send_resp(dut, conn, SIGMA_ERROR,
2896 "errorCode,Failed to download OSU CA cert");
2897 return 0;
2898 }
2899
2900 snprintf(buf, sizeof(buf),
2901 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2902 fqdn, fqdn);
2903 if (run_hs20_osu(dut, buf) < 0) {
2904 sigma_dut_print(dut, DUT_MSG_INFO,
2905 "Failed to download AAA CA cert");
2906 }
2907 }
2908
2909 if (file_exists("next-client-cert.pem")) {
2910 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2911 if (rename("next-client-cert.pem", buf) < 0) {
2912 send_resp(dut, conn, SIGMA_ERROR,
2913 "errorCode,Could not move client certificate");
2914 return 0;
2915 }
2916 }
2917
2918 if (file_exists("next-client-key.pem")) {
2919 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2920 if (rename("next-client-key.pem", buf) < 0) {
2921 send_resp(dut, conn, SIGMA_ERROR,
2922 "errorCode,Could not move client key");
2923 return 0;
2924 }
2925 }
2926
2927 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2928 if (run_hs20_osu(dut, buf) < 0) {
2929 send_resp(dut, conn, SIGMA_ERROR,
2930 "errorCode,Failed to configure credential from "
2931 "PPSMO");
2932 return 0;
2933 }
2934
2935 return 1;
2936}
2937
2938
2939static int download_cert(struct sigma_dut *dut,
2940 struct sigma_conn *conn,
2941 const char *intf,
2942 struct sigma_cmd *cmd)
2943{
2944 const char *name, *path;
2945 char url[500], buf[600];
2946
2947 name = get_param(cmd, "FileName");
2948 path = get_param(cmd, "FilePath");
2949 if (name == NULL || path == NULL)
2950 return -1;
2951
2952 if (strcasecmp(path, "VendorSpecific") == 0) {
2953 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2954 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2955 "certificate from the device (%s)", url);
2956 if (!file_exists(url)) {
2957 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2958 "certificate file does not exist");
2959 return 0;
2960 }
2961 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2962 if (system(buf) != 0) {
2963 send_resp(dut, conn, SIGMA_ERROR,
2964 "errorCode,Failed to copy client "
2965 "certificate");
2966 return 0;
2967 }
2968
2969 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2970 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2971 "private key from the device (%s)", url);
2972 if (!file_exists(url)) {
2973 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2974 "private key file does not exist");
2975 return 0;
2976 }
2977 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2978 if (system(buf) != 0) {
2979 send_resp(dut, conn, SIGMA_ERROR,
2980 "errorCode,Failed to copy client key");
2981 return 0;
2982 }
2983 } else if (strncasecmp(path, "http:", 5) != 0 &&
2984 strncasecmp(path, "https:", 6) != 0) {
2985 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2986 "Unsupported FilePath value");
2987 return 0;
2988 } else {
2989 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2990 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2991 "certificate/key from %s", url);
2992 snprintf(buf, sizeof(buf),
2993 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2994 if (system(buf) != 0) {
2995 send_resp(dut, conn, SIGMA_ERROR,
2996 "errorCode,Failed to download client "
2997 "certificate");
2998 return 0;
2999 }
3000
3001 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3002 {
3003 send_resp(dut, conn, SIGMA_ERROR,
3004 "errorCode,Failed to copy client key");
3005 return 0;
3006 }
3007 }
3008
3009 return 1;
3010}
3011
3012
3013static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3014 struct sigma_conn *conn,
3015 const char *intf,
3016 struct sigma_cmd *cmd)
3017{
3018 const char *val;
3019
3020 val = get_param(cmd, "FileType");
3021 if (val && strcasecmp(val, "PPSMO") == 0)
3022 return download_ppsmo(dut, conn, intf, cmd);
3023 if (val && strcasecmp(val, "CERT") == 0)
3024 return download_cert(dut, conn, intf, cmd);
3025 if (val) {
3026 send_resp(dut, conn, SIGMA_ERROR,
3027 "ErrorCode,Unsupported FileType");
3028 return 0;
3029 }
3030
3031 return 1;
3032}
3033
3034
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303035static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3036 struct sigma_conn *conn,
3037 const char *intf,
3038 struct sigma_cmd *cmd)
3039{
3040 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303041 char buf[1000];
3042 char text[20];
3043 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303044
3045 val = get_param(cmd, "OCESupport");
3046 if (val && strcasecmp(val, "Disable") == 0) {
3047 if (wpa_command(intf, "SET oce 0") < 0) {
3048 send_resp(dut, conn, SIGMA_ERROR,
3049 "ErrorCode,Failed to disable OCE");
3050 return 0;
3051 }
3052 } else if (val && strcasecmp(val, "Enable") == 0) {
3053 if (wpa_command(intf, "SET oce 1") < 0) {
3054 send_resp(dut, conn, SIGMA_ERROR,
3055 "ErrorCode,Failed to enable OCE");
3056 return 0;
3057 }
3058 }
3059
vamsi krishnaa2799492017-12-05 14:28:01 +05303060 val = get_param(cmd, "FILScap");
3061 if (val && (atoi(val) == 1)) {
3062 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3063 send_resp(dut, conn, SIGMA_ERROR,
3064 "ErrorCode,Failed to enable FILS");
3065 return 0;
3066 }
3067 } else if (val && (atoi(val) == 0)) {
3068 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3069 send_resp(dut, conn, SIGMA_ERROR,
3070 "ErrorCode,Failed to disable FILS");
3071 return 0;
3072 }
3073 }
3074
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303075 val = get_param(cmd, "FILSHLP");
3076 if (val && strcasecmp(val, "Enable") == 0) {
3077 if (get_wpa_status(get_station_ifname(), "address", text,
3078 sizeof(text)) < 0)
3079 return -2;
3080 hwaddr_aton(text, addr);
3081 snprintf(buf, sizeof(buf),
3082 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3083 "080045100140000040004011399e00000000ffffffff00440043"
3084 "012cb30001010600fd4f46410000000000000000000000000000"
3085 "000000000000"
3086 "%02x%02x%02x%02x%02x%02x"
3087 "0000000000000000000000000000000000000000000000000000"
3088 "0000000000000000000000000000000000000000000000000000"
3089 "0000000000000000000000000000000000000000000000000000"
3090 "0000000000000000000000000000000000000000000000000000"
3091 "0000000000000000000000000000000000000000000000000000"
3092 "0000000000000000000000000000000000000000000000000000"
3093 "0000000000000000000000000000000000000000000000000000"
3094 "0000000000000000000000000000000000000000638253633501"
3095 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3096 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3097 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3098 if (wpa_command(intf, buf)) {
3099 send_resp(dut, conn, SIGMA_ERROR,
3100 "ErrorCode,Failed to add HLP");
3101 return 0;
3102 }
3103 dut->fils_hlp = 1;
3104 }
3105
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303106 return 1;
3107}
3108
3109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3111 const char *val)
3112{
3113 int counter = 0;
3114 char token[50];
3115 char *result;
3116 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303117 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003118
Peng Xub8fc5cc2017-05-10 17:27:28 -07003119 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003120 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303121 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003122 while (result) {
3123 if (strcmp(result, "disable") == 0) {
3124 snprintf(buf, sizeof(buf),
3125 "iwpriv %s noackpolicy %d 1 0",
3126 intf, counter);
3127 } else {
3128 snprintf(buf, sizeof(buf),
3129 "iwpriv %s noackpolicy %d 1 1",
3130 intf, counter);
3131 }
3132 if (system(buf) != 0) {
3133 sigma_dut_print(dut, DUT_MSG_ERROR,
3134 "iwpriv noackpolicy failed");
3135 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303136 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003137 counter++;
3138 }
3139}
3140
3141
3142static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3143 const char *val)
3144{
3145 char buf[100];
3146
3147 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3148 if (system(buf) != 0) {
3149 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3150 }
3151}
3152
3153
3154static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3155 const char *val)
3156{
3157 char buf[100];
3158
3159 if (strcasecmp(val, "off") == 0) {
3160 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3161 if (system(buf) != 0) {
3162 sigma_dut_print(dut, DUT_MSG_ERROR,
3163 "Failed to turn off WMM");
3164 }
3165 }
3166}
3167
3168
3169static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3170 const char *val)
3171{
3172 char buf[100];
3173 int sgi20;
3174
3175 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3176
3177 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3178 if (system(buf) != 0)
3179 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3180}
3181
3182
3183static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3184 const char *val)
3185{
3186 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303187 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003188
3189 /* Disable Tx Beam forming when using a fixed rate */
3190 ath_disable_txbf(dut, intf);
3191
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303192 v = atoi(val);
3193 if (v < 0 || v > 32) {
3194 sigma_dut_print(dut, DUT_MSG_ERROR,
3195 "Invalid Fixed MCS rate: %d", v);
3196 return;
3197 }
3198 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003199
3200 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3201 intf, rate_code);
3202 if (system(buf) != 0) {
3203 sigma_dut_print(dut, DUT_MSG_ERROR,
3204 "iwpriv set11NRates failed");
3205 }
3206
3207 /* Channel width gets messed up, fix this */
3208 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3209 if (system(buf) != 0)
3210 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3211}
3212
3213
3214static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3215 const char *val)
3216{
3217 char buf[60];
3218
3219 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3220 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3221 else
3222 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3223
3224 if (system(buf) != 0)
3225 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3226}
3227
3228
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003229static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3230 int ampdu)
3231{
3232 char buf[60];
3233
3234 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3235 if (system(buf) != 0) {
3236 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3237 return -1;
3238 }
3239
3240 return 0;
3241}
3242
3243
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003244static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3245 const char *val)
3246{
3247 char buf[60];
3248
3249 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3250 if (system(buf) != 0) {
3251 sigma_dut_print(dut, DUT_MSG_ERROR,
3252 "iwpriv tx_stbc failed");
3253 }
3254
3255 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3256 if (system(buf) != 0) {
3257 sigma_dut_print(dut, DUT_MSG_ERROR,
3258 "iwpriv rx_stbc failed");
3259 }
3260}
3261
3262
3263static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3264 const char *val)
3265{
3266 char buf[60];
3267
Peng Xucc317ed2017-05-18 16:44:37 -07003268 if (strcmp(val, "160") == 0) {
3269 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3270 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003271 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3272 } else if (strcmp(val, "40") == 0) {
3273 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3274 } else if (strcmp(val, "20") == 0) {
3275 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3276 } else if (strcasecmp(val, "Auto") == 0) {
3277 buf[0] = '\0';
3278 } else {
3279 sigma_dut_print(dut, DUT_MSG_ERROR,
3280 "WIDTH/CTS_WIDTH value not supported");
3281 return -1;
3282 }
3283
3284 if (buf[0] != '\0' && system(buf) != 0) {
3285 sigma_dut_print(dut, DUT_MSG_ERROR,
3286 "Failed to set WIDTH/CTS_WIDTH");
3287 return -1;
3288 }
3289
3290 return 0;
3291}
3292
3293
3294int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3295 const char *intf, const char *val)
3296{
3297 char buf[60];
3298
3299 if (strcasecmp(val, "Auto") == 0) {
3300 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3301 dut->chwidth = 0;
3302 } else if (strcasecmp(val, "20") == 0) {
3303 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3304 dut->chwidth = 0;
3305 } else if (strcasecmp(val, "40") == 0) {
3306 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3307 dut->chwidth = 1;
3308 } else if (strcasecmp(val, "80") == 0) {
3309 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3310 dut->chwidth = 2;
3311 } else if (strcasecmp(val, "160") == 0) {
3312 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3313 dut->chwidth = 3;
3314 } else {
3315 send_resp(dut, conn, SIGMA_ERROR,
3316 "ErrorCode,WIDTH not supported");
3317 return -1;
3318 }
3319
3320 if (system(buf) != 0) {
3321 sigma_dut_print(dut, DUT_MSG_ERROR,
3322 "iwpriv chwidth failed");
3323 }
3324
3325 return 0;
3326}
3327
3328
3329static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3330 const char *val)
3331{
3332 char buf[60];
3333
3334 if (strcmp(val, "1SS") == 0) {
3335 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
3336 } else if (strcmp(val, "2SS") == 0) {
3337 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
3338 } else {
3339 sigma_dut_print(dut, DUT_MSG_ERROR,
3340 "SP_STREAM value not supported");
3341 return -1;
3342 }
3343
3344 if (system(buf) != 0) {
3345 sigma_dut_print(dut, DUT_MSG_ERROR,
3346 "Failed to set SP_STREAM");
3347 return -1;
3348 }
3349
3350 return 0;
3351}
3352
3353
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303354static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3355 const char *val)
3356{
3357 char buf[60];
3358
3359 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3360 if (system(buf) != 0)
3361 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3362
3363 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3364 if (system(buf) != 0)
3365 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3366}
3367
3368
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303369static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3370 struct sigma_conn *conn,
3371 const char *intf, int capa)
3372{
3373 char buf[32];
3374
3375 if (capa > 0 && capa < 4) {
3376 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3377 if (wpa_command(intf, buf) < 0) {
3378 send_resp(dut, conn, SIGMA_ERROR,
3379 "ErrorCode, Failed to set cellular data capability");
3380 return 0;
3381 }
3382 return 1;
3383 }
3384
3385 sigma_dut_print(dut, DUT_MSG_ERROR,
3386 "Invalid Cellular data capability: %d", capa);
3387 send_resp(dut, conn, SIGMA_INVALID,
3388 "ErrorCode,Invalid cellular data capability");
3389 return 0;
3390}
3391
3392
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303393static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3394 const char *intf, const char *val)
3395{
3396 if (strcasecmp(val, "Disable") == 0) {
3397 if (wpa_command(intf, "SET roaming 0") < 0) {
3398 send_resp(dut, conn, SIGMA_ERROR,
3399 "ErrorCode,Failed to disable roaming");
3400 return 0;
3401 }
3402 return 1;
3403 }
3404
3405 if (strcasecmp(val, "Enable") == 0) {
3406 if (wpa_command(intf, "SET roaming 1") < 0) {
3407 send_resp(dut, conn, SIGMA_ERROR,
3408 "ErrorCode,Failed to enable roaming");
3409 return 0;
3410 }
3411 return 1;
3412 }
3413
3414 sigma_dut_print(dut, DUT_MSG_ERROR,
3415 "Invalid value provided for roaming: %s", val);
3416 send_resp(dut, conn, SIGMA_INVALID,
3417 "ErrorCode,Unknown value provided for Roaming");
3418 return 0;
3419}
3420
3421
Ashwini Patila75de5a2017-04-13 16:35:05 +05303422static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3423 struct sigma_conn *conn,
3424 const char *intf, const char *val)
3425{
3426 if (strcasecmp(val, "Disable") == 0) {
3427 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3428 send_resp(dut, conn, SIGMA_ERROR,
3429 "ErrorCode,Failed to disable Assoc_disallow");
3430 return 0;
3431 }
3432 return 1;
3433 }
3434
3435 if (strcasecmp(val, "Enable") == 0) {
3436 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3437 send_resp(dut, conn, SIGMA_ERROR,
3438 "ErrorCode,Failed to enable Assoc_disallow");
3439 return 0;
3440 }
3441 return 1;
3442 }
3443
3444 sigma_dut_print(dut, DUT_MSG_ERROR,
3445 "Invalid value provided for Assoc_disallow: %s", val);
3446 send_resp(dut, conn, SIGMA_INVALID,
3447 "ErrorCode,Unknown value provided for Assoc_disallow");
3448 return 0;
3449}
3450
3451
Ashwini Patilc63161e2017-04-13 16:30:23 +05303452static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3453 const char *intf, const char *val)
3454{
3455 if (strcasecmp(val, "Reject") == 0) {
3456 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3457 send_resp(dut, conn, SIGMA_ERROR,
3458 "ErrorCode,Failed to Reject BTM Request");
3459 return 0;
3460 }
3461 return 1;
3462 }
3463
3464 if (strcasecmp(val, "Accept") == 0) {
3465 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3466 send_resp(dut, conn, SIGMA_ERROR,
3467 "ErrorCode,Failed to Accept BTM Request");
3468 return 0;
3469 }
3470 return 1;
3471 }
3472
3473 sigma_dut_print(dut, DUT_MSG_ERROR,
3474 "Invalid value provided for BSS_Transition: %s", val);
3475 send_resp(dut, conn, SIGMA_INVALID,
3476 "ErrorCode,Unknown value provided for BSS_Transition");
3477 return 0;
3478}
3479
3480
Ashwini Patil00402582017-04-13 12:29:39 +05303481static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3482 struct sigma_conn *conn,
3483 const char *intf,
3484 struct sigma_cmd *cmd)
3485{
3486 const char *ch, *pref, *op_class, *reason;
3487 char buf[120];
3488 int len, ret;
3489
3490 pref = get_param(cmd, "Ch_Pref");
3491 if (!pref)
3492 return 1;
3493
3494 if (strcasecmp(pref, "clear") == 0) {
3495 free(dut->non_pref_ch_list);
3496 dut->non_pref_ch_list = NULL;
3497 } else {
3498 op_class = get_param(cmd, "Ch_Op_Class");
3499 if (!op_class) {
3500 send_resp(dut, conn, SIGMA_INVALID,
3501 "ErrorCode,Ch_Op_Class not provided");
3502 return 0;
3503 }
3504
3505 ch = get_param(cmd, "Ch_Pref_Num");
3506 if (!ch) {
3507 send_resp(dut, conn, SIGMA_INVALID,
3508 "ErrorCode,Ch_Pref_Num not provided");
3509 return 0;
3510 }
3511
3512 reason = get_param(cmd, "Ch_Reason_Code");
3513 if (!reason) {
3514 send_resp(dut, conn, SIGMA_INVALID,
3515 "ErrorCode,Ch_Reason_Code not provided");
3516 return 0;
3517 }
3518
3519 if (!dut->non_pref_ch_list) {
3520 dut->non_pref_ch_list =
3521 calloc(1, NON_PREF_CH_LIST_SIZE);
3522 if (!dut->non_pref_ch_list) {
3523 send_resp(dut, conn, SIGMA_ERROR,
3524 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3525 return 0;
3526 }
3527 }
3528 len = strlen(dut->non_pref_ch_list);
3529 ret = snprintf(dut->non_pref_ch_list + len,
3530 NON_PREF_CH_LIST_SIZE - len,
3531 " %s:%s:%s:%s", op_class, ch, pref, reason);
3532 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3533 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3534 dut->non_pref_ch_list);
3535 } else {
3536 sigma_dut_print(dut, DUT_MSG_ERROR,
3537 "snprintf failed for non_pref_list, ret = %d",
3538 ret);
3539 send_resp(dut, conn, SIGMA_ERROR,
3540 "ErrorCode,snprintf failed");
3541 free(dut->non_pref_ch_list);
3542 dut->non_pref_ch_list = NULL;
3543 return 0;
3544 }
3545 }
3546
3547 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3548 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3549 if (ret < 0 || ret >= (int) sizeof(buf)) {
3550 sigma_dut_print(dut, DUT_MSG_DEBUG,
3551 "snprintf failed for set non_pref_chan, ret: %d",
3552 ret);
3553 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3554 return 0;
3555 }
3556
3557 if (wpa_command(intf, buf) < 0) {
3558 send_resp(dut, conn, SIGMA_ERROR,
3559 "ErrorCode,Failed to set non-preferred channel list");
3560 return 0;
3561 }
3562
3563 return 1;
3564}
3565
3566
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003567static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3568 struct sigma_conn *conn,
3569 struct sigma_cmd *cmd)
3570{
3571 const char *intf = get_param(cmd, "Interface");
3572 const char *val;
3573
3574 val = get_param(cmd, "Program");
Peng Xue9fa7952017-05-09 15:59:49 -07003575 if (val && strcasecmp(val, "HS2-R2") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003576 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3577 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003578
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003579 if (val && strcasecmp(val, "LOC") == 0)
3580 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003582#ifdef ANDROID_NAN
3583 if (val && strcasecmp(val, "NAN") == 0)
3584 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3585#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003586#ifdef MIRACAST
3587 if (val && (strcasecmp(val, "WFD") == 0 ||
3588 strcasecmp(val, "DisplayR2") == 0))
3589 return miracast_preset_testparameters(dut, conn, cmd);
3590#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003591
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303592 if (val && strcasecmp(val, "MBO") == 0) {
3593 val = get_param(cmd, "Cellular_Data_Cap");
3594 if (val &&
3595 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3596 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303597
3598 val = get_param(cmd, "Ch_Pref");
3599 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3600 return 0;
3601
Ashwini Patilc63161e2017-04-13 16:30:23 +05303602 val = get_param(cmd, "BSS_Transition");
3603 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3604 return 0;
3605
Ashwini Patila75de5a2017-04-13 16:35:05 +05303606 val = get_param(cmd, "Assoc_Disallow");
3607 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3608 return 0;
3609
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303610 val = get_param(cmd, "Roaming");
3611 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3612 return 0;
3613
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303614 return 1;
3615 }
3616
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303617 if (val && strcasecmp(val, "OCE") == 0)
3618 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3619
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620#if 0
3621 val = get_param(cmd, "Supplicant");
3622 if (val && strcasecmp(val, "Default") != 0) {
3623 send_resp(dut, conn, SIGMA_ERROR,
3624 "ErrorCode,Only default(Vendor) supplicant "
3625 "supported");
3626 return 0;
3627 }
3628#endif
3629
3630 val = get_param(cmd, "RTS");
3631 if (val) {
3632 switch (get_driver_type()) {
3633 case DRIVER_ATHEROS:
3634 ath_sta_set_rts(dut, intf, val);
3635 break;
3636 default:
3637#if 0
3638 send_resp(dut, conn, SIGMA_ERROR,
3639 "ErrorCode,Setting RTS not supported");
3640 return 0;
3641#else
3642 sigma_dut_print(dut, DUT_MSG_DEBUG,
3643 "Setting RTS not supported");
3644 break;
3645#endif
3646 }
3647 }
3648
3649#if 0
3650 val = get_param(cmd, "FRGMNT");
3651 if (val) {
3652 /* TODO */
3653 send_resp(dut, conn, SIGMA_ERROR,
3654 "ErrorCode,Setting FRGMNT not supported");
3655 return 0;
3656 }
3657#endif
3658
3659#if 0
3660 val = get_param(cmd, "Preamble");
3661 if (val) {
3662 /* TODO: Long/Short */
3663 send_resp(dut, conn, SIGMA_ERROR,
3664 "ErrorCode,Setting Preamble not supported");
3665 return 0;
3666 }
3667#endif
3668
3669 val = get_param(cmd, "Mode");
3670 if (val) {
3671 if (strcmp(val, "11b") == 0 ||
3672 strcmp(val, "11g") == 0 ||
3673 strcmp(val, "11a") == 0 ||
3674 strcmp(val, "11n") == 0 ||
3675 strcmp(val, "11ng") == 0 ||
3676 strcmp(val, "11nl") == 0 ||
3677 strcmp(val, "11nl(nabg)") == 0 ||
3678 strcmp(val, "AC") == 0 ||
3679 strcmp(val, "11AC") == 0 ||
3680 strcmp(val, "11ac") == 0 ||
3681 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003682 strcmp(val, "11an") == 0 ||
3683 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003684 /* STA supports all modes by default */
3685 } else {
3686 send_resp(dut, conn, SIGMA_ERROR,
3687 "ErrorCode,Setting Mode not supported");
3688 return 0;
3689 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003690
3691 /* Change the mode only in case of testbed for HE program
3692 * and for 11a and 11g modes only. */
3693 if (dut->program == PROGRAM_HE &&
3694 dut->device_type == STA_testbed) {
3695 int phymode;
3696 char buf[60];
3697
3698 if (strcmp(val, "11a") == 0) {
3699 phymode = 1;
3700 } else if (strcmp (val, "11g") == 0) {
3701 phymode = 3;
3702 } else {
3703 sigma_dut_print(dut, DUT_MSG_DEBUG,
3704 "Ignoring mode change for mode: %s",
3705 val);
3706 phymode = -1;
3707 }
3708 if (phymode != -1) {
3709 snprintf(buf, sizeof(buf),
3710 "iwpriv %s setphymode %d",
3711 intf, phymode);
3712 if (system(buf) != 0) {
3713 sigma_dut_print(dut, DUT_MSG_ERROR,
3714 "iwpriv setting of phymode failed");
3715 }
3716 }
3717 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003718 }
3719
3720 val = get_param(cmd, "wmm");
3721 if (val) {
3722 switch (get_driver_type()) {
3723 case DRIVER_ATHEROS:
3724 ath_sta_set_wmm(dut, intf, val);
3725 break;
3726 default:
3727 sigma_dut_print(dut, DUT_MSG_DEBUG,
3728 "Setting wmm not supported");
3729 break;
3730 }
3731 }
3732
3733 val = get_param(cmd, "Powersave");
3734 if (val) {
3735 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3736 if (wpa_command(get_station_ifname(),
3737 "P2P_SET ps 0") < 0)
3738 return -2;
3739 /* Make sure test modes are disabled */
3740 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3741 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3742 } else if (strcmp(val, "1") == 0 ||
3743 strcasecmp(val, "PSPoll") == 0 ||
3744 strcasecmp(val, "on") == 0) {
3745 /* Disable default power save mode */
3746 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3747 /* Enable PS-Poll test mode */
3748 if (wpa_command(get_station_ifname(),
3749 "P2P_SET ps 97") < 0 ||
3750 wpa_command(get_station_ifname(),
3751 "P2P_SET ps 99") < 0)
3752 return -2;
3753 } else if (strcmp(val, "2") == 0 ||
3754 strcasecmp(val, "Fast") == 0) {
3755 /* TODO */
3756 send_resp(dut, conn, SIGMA_ERROR,
3757 "ErrorCode,Powersave=Fast not supported");
3758 return 0;
3759 } else if (strcmp(val, "3") == 0 ||
3760 strcasecmp(val, "PSNonPoll") == 0) {
3761 /* Make sure test modes are disabled */
3762 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3763 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3764
3765 /* Enable default power save mode */
3766 if (wpa_command(get_station_ifname(),
3767 "P2P_SET ps 1") < 0)
3768 return -2;
3769 } else
3770 return -1;
3771 }
3772
3773 val = get_param(cmd, "NoAck");
3774 if (val) {
3775 switch (get_driver_type()) {
3776 case DRIVER_ATHEROS:
3777 ath_sta_set_noack(dut, intf, val);
3778 break;
3779 default:
3780 send_resp(dut, conn, SIGMA_ERROR,
3781 "ErrorCode,Setting NoAck not supported");
3782 return 0;
3783 }
3784 }
3785
3786 val = get_param(cmd, "IgnoreChswitchProhibit");
3787 if (val) {
3788 /* TODO: Enabled/disabled */
3789 if (strcasecmp(val, "Enabled") == 0) {
3790 send_resp(dut, conn, SIGMA_ERROR,
3791 "ErrorCode,Enabling IgnoreChswitchProhibit "
3792 "not supported");
3793 return 0;
3794 }
3795 }
3796
3797 val = get_param(cmd, "TDLS");
3798 if (val) {
3799 if (strcasecmp(val, "Disabled") == 0) {
3800 if (wpa_command(intf, "SET tdls_disabled 1")) {
3801 send_resp(dut, conn, SIGMA_ERROR,
3802 "ErrorCode,Failed to disable TDLS");
3803 return 0;
3804 }
3805 } else if (strcasecmp(val, "Enabled") == 0) {
3806 if (wpa_command(intf, "SET tdls_disabled 0")) {
3807 send_resp(dut, conn, SIGMA_ERROR,
3808 "ErrorCode,Failed to enable TDLS");
3809 return 0;
3810 }
3811 } else {
3812 send_resp(dut, conn, SIGMA_ERROR,
3813 "ErrorCode,Unsupported TDLS value");
3814 return 0;
3815 }
3816 }
3817
3818 val = get_param(cmd, "TDLSmode");
3819 if (val) {
3820 if (strcasecmp(val, "Default") == 0) {
3821 wpa_command(intf, "SET tdls_testing 0");
3822 } else if (strcasecmp(val, "APProhibit") == 0) {
3823 if (wpa_command(intf, "SET tdls_testing 0x400")) {
3824 send_resp(dut, conn, SIGMA_ERROR,
3825 "ErrorCode,Failed to enable ignore "
3826 "APProhibit TDLS mode");
3827 return 0;
3828 }
3829 } else if (strcasecmp(val, "HiLoMac") == 0) {
3830 /* STA should respond with TDLS setup req for a TDLS
3831 * setup req */
3832 if (wpa_command(intf, "SET tdls_testing 0x80")) {
3833 send_resp(dut, conn, SIGMA_ERROR,
3834 "ErrorCode,Failed to enable HiLoMac "
3835 "TDLS mode");
3836 return 0;
3837 }
3838 } else if (strcasecmp(val, "WeakSecurity") == 0) {
3839 /*
3840 * Since all security modes are enabled by default when
3841 * Sigma control is used, there is no need to do
3842 * anything here.
3843 */
3844 } else if (strcasecmp(val, "ExistLink") == 0) {
3845 /*
3846 * Since we allow new TDLS Setup Request even if there
3847 * is an existing link, nothing needs to be done for
3848 * this.
3849 */
3850 } else {
3851 /* TODO:
3852 * ExistLink: STA should send TDLS setup req even if
3853 * direct link already exists
3854 */
3855 send_resp(dut, conn, SIGMA_ERROR,
3856 "ErrorCode,Unsupported TDLSmode value");
3857 return 0;
3858 }
3859 }
3860
3861 val = get_param(cmd, "FakePubKey");
3862 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
3863 send_resp(dut, conn, SIGMA_ERROR,
3864 "ErrorCode,Failed to enable FakePubKey");
3865 return 0;
3866 }
3867
3868 return 1;
3869}
3870
3871
3872static const char * ath_get_radio_name(const char *radio_name)
3873{
3874 if (radio_name == NULL)
3875 return "wifi0";
3876 if (strcmp(radio_name, "wifi1") == 0)
3877 return "wifi1";
3878 if (strcmp(radio_name, "wifi2") == 0)
3879 return "wifi2";
3880 return "wifi0";
3881}
3882
3883
3884static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
3885 const char *val)
3886{
3887 char buf[60];
3888 unsigned int vht_mcsmap = 0;
3889 int txchainmask = 0;
3890 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3891
3892 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3893 if (dut->testbed_flag_txsp == 1) {
3894 vht_mcsmap = 0xfffc;
3895 dut->testbed_flag_txsp = 0;
3896 } else {
3897 vht_mcsmap = 0xfffe;
3898 }
3899 txchainmask = 1;
3900 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3901 if (dut->testbed_flag_txsp == 1) {
3902 vht_mcsmap = 0xfff0;
3903 dut->testbed_flag_txsp = 0;
3904 } else {
3905 vht_mcsmap = 0xfffa;
3906 }
3907 txchainmask = 3;
3908 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3909 if (dut->testbed_flag_txsp == 1) {
3910 vht_mcsmap = 0xffc0;
3911 dut->testbed_flag_txsp = 0;
3912 } else {
3913 vht_mcsmap = 0xffea;
3914 }
3915 txchainmask = 7;
3916 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3917 if (dut->testbed_flag_txsp == 1) {
3918 vht_mcsmap = 0xff00;
3919 dut->testbed_flag_txsp = 0;
3920 } else {
3921 vht_mcsmap = 0xffaa;
3922 }
3923 txchainmask = 15;
3924 } else {
3925 if (dut->testbed_flag_txsp == 1) {
3926 vht_mcsmap = 0xffc0;
3927 dut->testbed_flag_txsp = 0;
3928 } else {
3929 vht_mcsmap = 0xffea;
3930 }
3931 }
3932
3933 if (txchainmask) {
3934 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
3935 basedev, txchainmask);
3936 if (system(buf) != 0) {
3937 sigma_dut_print(dut, DUT_MSG_ERROR,
3938 "iwpriv txchainmask failed");
3939 }
3940 }
3941
3942 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3943 intf, vht_mcsmap);
3944 if (system(buf) != 0) {
3945 sigma_dut_print(dut, DUT_MSG_ERROR,
3946 "iwpriv %s vht_mcsmap 0x%04x failed",
3947 intf, vht_mcsmap);
3948 }
3949}
3950
3951
3952static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
3953 const char *val)
3954{
3955 char buf[60];
3956 unsigned int vht_mcsmap = 0;
3957 int rxchainmask = 0;
3958 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3959
3960 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3961 if (dut->testbed_flag_rxsp == 1) {
3962 vht_mcsmap = 0xfffc;
3963 dut->testbed_flag_rxsp = 0;
3964 } else {
3965 vht_mcsmap = 0xfffe;
3966 }
3967 rxchainmask = 1;
3968 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3969 if (dut->testbed_flag_rxsp == 1) {
3970 vht_mcsmap = 0xfff0;
3971 dut->testbed_flag_rxsp = 0;
3972 } else {
3973 vht_mcsmap = 0xfffa;
3974 }
3975 rxchainmask = 3;
3976 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3977 if (dut->testbed_flag_rxsp == 1) {
3978 vht_mcsmap = 0xffc0;
3979 dut->testbed_flag_rxsp = 0;
3980 } else {
3981 vht_mcsmap = 0xffea;
3982 }
3983 rxchainmask = 7;
3984 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3985 if (dut->testbed_flag_rxsp == 1) {
3986 vht_mcsmap = 0xff00;
3987 dut->testbed_flag_rxsp = 0;
3988 } else {
3989 vht_mcsmap = 0xffaa;
3990 }
3991 rxchainmask = 15;
3992 } else {
3993 if (dut->testbed_flag_rxsp == 1) {
3994 vht_mcsmap = 0xffc0;
3995 dut->testbed_flag_rxsp = 0;
3996 } else {
3997 vht_mcsmap = 0xffea;
3998 }
3999 }
4000
4001 if (rxchainmask) {
4002 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4003 basedev, rxchainmask);
4004 if (system(buf) != 0) {
4005 sigma_dut_print(dut, DUT_MSG_ERROR,
4006 "iwpriv rxchainmask failed");
4007 }
4008 }
4009
4010 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4011 intf, vht_mcsmap);
4012 if (system(buf) != 0) {
4013 sigma_dut_print(dut, DUT_MSG_ERROR,
4014 "iwpriv %s vht_mcsmap 0x%04x",
4015 intf, vht_mcsmap);
4016 }
4017}
4018
4019
4020void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4021{
4022 if (strcasecmp(val, "enable") == 0) {
4023 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4024 != 0) {
4025 sigma_dut_print(dut, DUT_MSG_ERROR,
4026 "Disable BB_VHTSIGB_CRC_CALC failed");
4027 }
4028
4029 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4030 != 0) {
4031 sigma_dut_print(dut, DUT_MSG_ERROR,
4032 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4033 }
4034 } else {
4035 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4036 != 0) {
4037 sigma_dut_print(dut, DUT_MSG_ERROR,
4038 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4039 }
4040
4041 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4042 != 0) {
4043 sigma_dut_print(dut, DUT_MSG_ERROR,
4044 "Enable BB_VHTSIGB_CRC_CALC failed");
4045 }
4046 }
4047}
4048
4049
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004050static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4051 const char *val)
4052{
4053 char buf[60];
4054
4055 if (strcmp(val, "20") == 0) {
4056 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4057 dut->chwidth = 0;
4058 } else if (strcmp(val, "40") == 0) {
4059 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4060 dut->chwidth = 1;
4061 } else if (strcmp(val, "80") == 0) {
4062 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4063 dut->chwidth = 2;
4064 } else if (strcmp(val, "Auto") == 0) {
4065 buf[0] = '\0';
4066 } else {
4067 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4068 val);
4069 return -1;
4070 }
4071
4072 if (buf[0] != '\0' && system(buf) != 0) {
4073 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4074 return -1;
4075 }
4076
4077 return 0;
4078}
4079
4080
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004081static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4082 struct sigma_conn *conn,
4083 struct sigma_cmd *cmd)
4084{
4085 const char *val;
4086 int ampdu = -1;
4087 char buf[30];
4088
4089 val = get_param(cmd, "40_INTOLERANT");
4090 if (val) {
4091 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4092 /* TODO: iwpriv ht40intol through wpa_supplicant */
4093 send_resp(dut, conn, SIGMA_ERROR,
4094 "ErrorCode,40_INTOLERANT not supported");
4095 return 0;
4096 }
4097 }
4098
4099 val = get_param(cmd, "ADDBA_REJECT");
4100 if (val) {
4101 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4102 /* reject any ADDBA with status "decline" */
4103 ampdu = 0;
4104 } else {
4105 /* accept ADDBA */
4106 ampdu = 1;
4107 }
4108 }
4109
4110 val = get_param(cmd, "AMPDU");
4111 if (val) {
4112 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4113 /* enable AMPDU Aggregation */
4114 if (ampdu == 0) {
4115 send_resp(dut, conn, SIGMA_ERROR,
4116 "ErrorCode,Mismatch in "
4117 "addba_reject/ampdu - "
4118 "not supported");
4119 return 0;
4120 }
4121 ampdu = 1;
4122 } else {
4123 /* disable AMPDU Aggregation */
4124 if (ampdu == 1) {
4125 send_resp(dut, conn, SIGMA_ERROR,
4126 "ErrorCode,Mismatch in "
4127 "addba_reject/ampdu - "
4128 "not supported");
4129 return 0;
4130 }
4131 ampdu = 0;
4132 }
4133 }
4134
4135 if (ampdu >= 0) {
4136 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4137 ampdu ? "Enabling" : "Disabling");
4138 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004139 if (wpa_command(intf, buf) < 0 &&
4140 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004141 send_resp(dut, conn, SIGMA_ERROR,
4142 "ErrorCode,set aggr failed");
4143 return 0;
4144 }
4145 }
4146
4147 val = get_param(cmd, "AMSDU");
4148 if (val) {
4149 switch (get_driver_type()) {
4150 case DRIVER_ATHEROS:
4151 ath_sta_set_amsdu(dut, intf, val);
4152 break;
4153 default:
4154 if (strcmp(val, "1") == 0 ||
4155 strcasecmp(val, "Enable") == 0) {
4156 /* Enable AMSDU Aggregation */
4157 send_resp(dut, conn, SIGMA_ERROR,
4158 "ErrorCode,AMSDU aggregation not supported");
4159 return 0;
4160 }
4161 break;
4162 }
4163 }
4164
4165 val = get_param(cmd, "STBC_RX");
4166 if (val) {
4167 switch (get_driver_type()) {
4168 case DRIVER_ATHEROS:
4169 ath_sta_set_stbc(dut, intf, val);
4170 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304171 case DRIVER_WCN:
4172 wcn_sta_set_stbc(dut, intf, val);
4173 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004174 default:
4175 send_resp(dut, conn, SIGMA_ERROR,
4176 "ErrorCode,STBC_RX not supported");
4177 return 0;
4178 }
4179 }
4180
4181 val = get_param(cmd, "WIDTH");
4182 if (val) {
4183 switch (get_driver_type()) {
4184 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004185 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004186 send_resp(dut, conn, SIGMA_ERROR,
4187 "ErrorCode,Failed to set WIDTH");
4188 return 0;
4189 }
4190 break;
4191 case DRIVER_ATHEROS:
4192 if (ath_set_width(dut, conn, intf, val) < 0)
4193 return 0;
4194 break;
4195 default:
4196 sigma_dut_print(dut, DUT_MSG_ERROR,
4197 "Setting WIDTH not supported");
4198 break;
4199 }
4200 }
4201
4202 val = get_param(cmd, "SMPS");
4203 if (val) {
4204 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4205 send_resp(dut, conn, SIGMA_ERROR,
4206 "ErrorCode,SMPS not supported");
4207 return 0;
4208 }
4209
4210 val = get_param(cmd, "TXSP_STREAM");
4211 if (val) {
4212 switch (get_driver_type()) {
4213 case DRIVER_WCN:
4214 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4215 send_resp(dut, conn, SIGMA_ERROR,
4216 "ErrorCode,Failed to set TXSP_STREAM");
4217 return 0;
4218 }
4219 break;
4220 case DRIVER_ATHEROS:
4221 ath_sta_set_txsp_stream(dut, intf, val);
4222 break;
4223 default:
4224 sigma_dut_print(dut, DUT_MSG_ERROR,
4225 "Setting TXSP_STREAM not supported");
4226 break;
4227 }
4228 }
4229
4230 val = get_param(cmd, "RXSP_STREAM");
4231 if (val) {
4232 switch (get_driver_type()) {
4233 case DRIVER_WCN:
4234 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4235 send_resp(dut, conn, SIGMA_ERROR,
4236 "ErrorCode,Failed to set RXSP_STREAM");
4237 return 0;
4238 }
4239 break;
4240 case DRIVER_ATHEROS:
4241 ath_sta_set_rxsp_stream(dut, intf, val);
4242 break;
4243 default:
4244 sigma_dut_print(dut, DUT_MSG_ERROR,
4245 "Setting RXSP_STREAM not supported");
4246 break;
4247 }
4248 }
4249
4250 val = get_param(cmd, "DYN_BW_SGNL");
4251 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004252 switch (get_driver_type()) {
4253 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004254 if (strcasecmp(val, "enable") == 0) {
4255 snprintf(buf, sizeof(buf),
4256 "iwpriv %s cwmenable 1", intf);
4257 if (system(buf) != 0) {
4258 sigma_dut_print(dut, DUT_MSG_ERROR,
4259 "iwpriv cwmenable 1 failed");
4260 return 0;
4261 }
4262 } else if (strcasecmp(val, "disable") == 0) {
4263 snprintf(buf, sizeof(buf),
4264 "iwpriv %s cwmenable 0", intf);
4265 if (system(buf) != 0) {
4266 sigma_dut_print(dut, DUT_MSG_ERROR,
4267 "iwpriv cwmenable 0 failed");
4268 return 0;
4269 }
4270 } else {
4271 sigma_dut_print(dut, DUT_MSG_ERROR,
4272 "Unsupported DYN_BW_SGL");
4273 }
4274
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004275 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4276 if (system(buf) != 0) {
4277 sigma_dut_print(dut, DUT_MSG_ERROR,
4278 "Failed to set cts_cbw in DYN_BW_SGNL");
4279 return 0;
4280 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004281 break;
4282 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004283 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004284 ath_config_dyn_bw_sig(dut, intf, val);
4285 break;
4286 default:
4287 sigma_dut_print(dut, DUT_MSG_ERROR,
4288 "Failed to set DYN_BW_SGNL");
4289 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004291 }
4292
4293 val = get_param(cmd, "RTS_FORCE");
4294 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004295 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004296 if (strcasecmp(val, "Enable") == 0) {
4297 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004298 if (system(buf) != 0) {
4299 sigma_dut_print(dut, DUT_MSG_ERROR,
4300 "Failed to set RTS_FORCE 64");
4301 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004302 snprintf(buf, sizeof(buf),
4303 "wifitool %s beeliner_fw_test 100 1", intf);
4304 if (system(buf) != 0) {
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "wifitool beeliner_fw_test 100 1 failed");
4307 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308 } else if (strcasecmp(val, "Disable") == 0) {
4309 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4310 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004311 if (system(buf) != 0) {
4312 sigma_dut_print(dut, DUT_MSG_ERROR,
4313 "Failed to set RTS_FORCE 2347");
4314 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004315 } else {
4316 send_resp(dut, conn, SIGMA_ERROR,
4317 "ErrorCode,RTS_FORCE value not supported");
4318 return 0;
4319 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004320 }
4321
4322 val = get_param(cmd, "CTS_WIDTH");
4323 if (val) {
4324 switch (get_driver_type()) {
4325 case DRIVER_WCN:
4326 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4327 send_resp(dut, conn, SIGMA_ERROR,
4328 "ErrorCode,Failed to set CTS_WIDTH");
4329 return 0;
4330 }
4331 break;
4332 case DRIVER_ATHEROS:
4333 ath_set_cts_width(dut, intf, val);
4334 break;
4335 default:
4336 sigma_dut_print(dut, DUT_MSG_ERROR,
4337 "Setting CTS_WIDTH not supported");
4338 break;
4339 }
4340 }
4341
4342 val = get_param(cmd, "BW_SGNL");
4343 if (val) {
4344 if (strcasecmp(val, "Enable") == 0) {
4345 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4346 intf);
4347 } else if (strcasecmp(val, "Disable") == 0) {
4348 /* TODO: Disable */
4349 buf[0] = '\0';
4350 } else {
4351 send_resp(dut, conn, SIGMA_ERROR,
4352 "ErrorCode,BW_SGNL value not supported");
4353 return 0;
4354 }
4355
4356 if (buf[0] != '\0' && system(buf) != 0) {
4357 sigma_dut_print(dut, DUT_MSG_ERROR,
4358 "Failed to set BW_SGNL");
4359 }
4360 }
4361
4362 val = get_param(cmd, "Band");
4363 if (val) {
4364 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4365 /* STA supports all bands by default */
4366 } else {
4367 send_resp(dut, conn, SIGMA_ERROR,
4368 "ErrorCode,Unsupported Band");
4369 return 0;
4370 }
4371 }
4372
4373 val = get_param(cmd, "zero_crc");
4374 if (val) {
4375 switch (get_driver_type()) {
4376 case DRIVER_ATHEROS:
4377 ath_set_zero_crc(dut, val);
4378 break;
4379 default:
4380 break;
4381 }
4382 }
4383
4384 return 1;
4385}
4386
4387
4388static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4389 struct sigma_cmd *cmd)
4390{
4391 const char *val;
4392 char buf[100];
4393
4394 val = get_param(cmd, "MSDUSize");
4395 if (val) {
4396 int mtu;
4397
4398 dut->amsdu_size = atoi(val);
4399 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4400 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4401 sigma_dut_print(dut, DUT_MSG_ERROR,
4402 "MSDUSize %d is above max %d or below min %d",
4403 dut->amsdu_size,
4404 IEEE80211_MAX_DATA_LEN_DMG,
4405 IEEE80211_SNAP_LEN_DMG);
4406 dut->amsdu_size = 0;
4407 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4408 }
4409
4410 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4411 sigma_dut_print(dut, DUT_MSG_DEBUG,
4412 "Setting amsdu_size to %d", mtu);
4413 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4414 get_station_ifname(), mtu);
4415
4416 if (system(buf) != 0) {
4417 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4418 buf);
4419 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4420 }
4421 }
4422
4423 val = get_param(cmd, "BAckRcvBuf");
4424 if (val) {
4425 dut->back_rcv_buf = atoi(val);
4426 if (dut->back_rcv_buf == 0) {
4427 sigma_dut_print(dut, DUT_MSG_ERROR,
4428 "Failed to convert %s or value is 0",
4429 val);
4430 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4431 }
4432
4433 sigma_dut_print(dut, DUT_MSG_DEBUG,
4434 "Setting BAckRcvBuf to %s", val);
4435 }
4436
4437 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4438}
4439
4440
4441static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4442 struct sigma_cmd *cmd)
4443{
4444 int net_id;
4445 char *ifname;
4446 const char *val;
4447 char buf[100];
4448
4449 dut->mode = SIGMA_MODE_STATION;
4450 ifname = get_main_ifname();
4451 if (wpa_command(ifname, "PING") != 0) {
4452 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4453 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4454 }
4455
4456 wpa_command(ifname, "FLUSH");
4457 net_id = add_network_common(dut, conn, ifname, cmd);
4458 if (net_id < 0) {
4459 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4460 return net_id;
4461 }
4462
4463 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4464 if (set_network(ifname, net_id, "mode", "2") < 0) {
4465 sigma_dut_print(dut, DUT_MSG_ERROR,
4466 "Failed to set supplicant network mode");
4467 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4468 }
4469
4470 sigma_dut_print(dut, DUT_MSG_DEBUG,
4471 "Supplicant set network with mode 2");
4472
4473 val = get_param(cmd, "Security");
4474 if (val && strcasecmp(val, "OPEN") == 0) {
4475 dut->ap_key_mgmt = AP_OPEN;
4476 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4477 sigma_dut_print(dut, DUT_MSG_ERROR,
4478 "Failed to set supplicant to %s security",
4479 val);
4480 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4481 }
4482 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4483 dut->ap_key_mgmt = AP_WPA2_PSK;
4484 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4485 sigma_dut_print(dut, DUT_MSG_ERROR,
4486 "Failed to set supplicant to %s security",
4487 val);
4488 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4489 }
4490
4491 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4492 sigma_dut_print(dut, DUT_MSG_ERROR,
4493 "Failed to set supplicant to proto RSN");
4494 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4495 }
4496 } else if (val) {
4497 sigma_dut_print(dut, DUT_MSG_ERROR,
4498 "Requested Security %s is not supported on 60GHz",
4499 val);
4500 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4501 }
4502
4503 val = get_param(cmd, "Encrypt");
4504 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4505 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "Failed to set supplicant to pairwise GCMP");
4508 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4509 }
4510 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4511 sigma_dut_print(dut, DUT_MSG_ERROR,
4512 "Failed to set supplicant to group GCMP");
4513 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4514 }
4515 } else if (val) {
4516 sigma_dut_print(dut, DUT_MSG_ERROR,
4517 "Requested Encrypt %s is not supported on 60 GHz",
4518 val);
4519 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4520 }
4521
4522 val = get_param(cmd, "PSK");
4523 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4524 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4525 val);
4526 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4527 }
4528
4529 /* Convert 60G channel to freq */
4530 switch (dut->ap_channel) {
4531 case 1:
4532 val = "58320";
4533 break;
4534 case 2:
4535 val = "60480";
4536 break;
4537 case 3:
4538 val = "62640";
4539 break;
4540 default:
4541 sigma_dut_print(dut, DUT_MSG_ERROR,
4542 "Failed to configure channel %d. Not supported",
4543 dut->ap_channel);
4544 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4545 }
4546
4547 if (set_network(ifname, net_id, "frequency", val) < 0) {
4548 sigma_dut_print(dut, DUT_MSG_ERROR,
4549 "Failed to set supplicant network frequency");
4550 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4551 }
4552
4553 sigma_dut_print(dut, DUT_MSG_DEBUG,
4554 "Supplicant set network with frequency");
4555
4556 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4557 if (wpa_command(ifname, buf) < 0) {
4558 sigma_dut_print(dut, DUT_MSG_INFO,
4559 "Failed to select network id %d on %s",
4560 net_id, ifname);
4561 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4562 }
4563
4564 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4565
4566 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4567}
4568
4569
Lior David67543f52017-01-03 19:04:22 +02004570static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4571{
4572 char buf[128], fname[128];
4573 FILE *f;
4574
4575 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4576 sigma_dut_print(dut, DUT_MSG_ERROR,
4577 "failed to get wil6210 debugfs dir");
4578 return -1;
4579 }
4580
4581 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4582 f = fopen(fname, "w");
4583 if (!f) {
4584 sigma_dut_print(dut, DUT_MSG_ERROR,
4585 "failed to open: %s", fname);
4586 return -1;
4587 }
4588
4589 fprintf(f, "%d\n", abft_len);
4590 fclose(f);
4591
4592 return 0;
4593}
4594
4595
4596static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4597 int abft_len)
4598{
4599 switch (get_driver_type()) {
4600 case DRIVER_WIL6210:
4601 return wil6210_set_abft_len(dut, abft_len);
4602 default:
4603 sigma_dut_print(dut, DUT_MSG_ERROR,
4604 "set abft_len not supported");
4605 return -1;
4606 }
4607}
4608
4609
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004610static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4611 struct sigma_cmd *cmd)
4612{
4613 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004614 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004615
4616 if (dut->dev_role != DEVROLE_PCP) {
4617 send_resp(dut, conn, SIGMA_INVALID,
4618 "ErrorCode,Invalid DevRole");
4619 return 0;
4620 }
4621
4622 val = get_param(cmd, "SSID");
4623 if (val) {
4624 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4625 send_resp(dut, conn, SIGMA_INVALID,
4626 "ErrorCode,Invalid SSID");
4627 return -1;
4628 }
4629
Peng Xub8fc5cc2017-05-10 17:27:28 -07004630 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004631 }
4632
4633 val = get_param(cmd, "CHANNEL");
4634 if (val) {
4635 const char *pos;
4636
4637 dut->ap_channel = atoi(val);
4638 pos = strchr(val, ';');
4639 if (pos) {
4640 pos++;
4641 dut->ap_channel_1 = atoi(pos);
4642 }
4643 }
4644
4645 switch (dut->ap_channel) {
4646 case 1:
4647 case 2:
4648 case 3:
4649 break;
4650 default:
4651 sigma_dut_print(dut, DUT_MSG_ERROR,
4652 "Channel %d is not supported", dut->ap_channel);
4653 send_resp(dut, conn, SIGMA_ERROR,
4654 "Requested channel is not supported");
4655 return -1;
4656 }
4657
4658 val = get_param(cmd, "BCNINT");
4659 if (val)
4660 dut->ap_bcnint = atoi(val);
4661
4662
4663 val = get_param(cmd, "ExtSchIE");
4664 if (val) {
4665 send_resp(dut, conn, SIGMA_ERROR,
4666 "ErrorCode,ExtSchIE is not supported yet");
4667 return -1;
4668 }
4669
4670 val = get_param(cmd, "AllocType");
4671 if (val) {
4672 send_resp(dut, conn, SIGMA_ERROR,
4673 "ErrorCode,AllocType is not supported yet");
4674 return -1;
4675 }
4676
4677 val = get_param(cmd, "PercentBI");
4678 if (val) {
4679 send_resp(dut, conn, SIGMA_ERROR,
4680 "ErrorCode,PercentBI is not supported yet");
4681 return -1;
4682 }
4683
4684 val = get_param(cmd, "CBAPOnly");
4685 if (val) {
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "ErrorCode,CBAPOnly is not supported yet");
4688 return -1;
4689 }
4690
4691 val = get_param(cmd, "AMPDU");
4692 if (val) {
4693 if (strcasecmp(val, "Enable") == 0)
4694 dut->ap_ampdu = 1;
4695 else if (strcasecmp(val, "Disable") == 0)
4696 dut->ap_ampdu = 2;
4697 else {
4698 send_resp(dut, conn, SIGMA_ERROR,
4699 "ErrorCode,AMPDU value is not Enable nor Disabled");
4700 return -1;
4701 }
4702 }
4703
4704 val = get_param(cmd, "AMSDU");
4705 if (val) {
4706 if (strcasecmp(val, "Enable") == 0)
4707 dut->ap_amsdu = 1;
4708 else if (strcasecmp(val, "Disable") == 0)
4709 dut->ap_amsdu = 2;
4710 }
4711
4712 val = get_param(cmd, "NumMSDU");
4713 if (val) {
4714 send_resp(dut, conn, SIGMA_ERROR,
4715 "ErrorCode, NumMSDU is not supported yet");
4716 return -1;
4717 }
4718
4719 val = get_param(cmd, "ABFTLRang");
4720 if (val) {
4721 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004722 "ABFTLRang parameter %s", val);
4723 if (strcmp(val, "Gt1") == 0)
4724 abft_len = 2; /* 2 slots in this case */
4725 }
4726
4727 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4728 send_resp(dut, conn, SIGMA_ERROR,
4729 "ErrorCode, Can't set ABFT length");
4730 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004731 }
4732
4733 if (sta_pcp_start(dut, conn, cmd) < 0) {
4734 send_resp(dut, conn, SIGMA_ERROR,
4735 "ErrorCode, Can't start PCP role");
4736 return -1;
4737 }
4738
4739 return sta_set_60g_common(dut, conn, cmd);
4740}
4741
4742
4743static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
4744 struct sigma_cmd *cmd)
4745{
4746 const char *val = get_param(cmd, "DiscoveryMode");
4747
4748 if (dut->dev_role != DEVROLE_STA) {
4749 send_resp(dut, conn, SIGMA_INVALID,
4750 "ErrorCode,Invalid DevRole");
4751 return 0;
4752 }
4753
4754 if (val) {
4755 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
4756 /* Ignore Discovery mode till Driver expose API. */
4757#if 0
4758 if (strcasecmp(val, "1") == 0) {
4759 send_resp(dut, conn, SIGMA_INVALID,
4760 "ErrorCode,DiscoveryMode 1 not supported");
4761 return 0;
4762 }
4763
4764 if (strcasecmp(val, "0") == 0) {
4765 /* OK */
4766 } else {
4767 send_resp(dut, conn, SIGMA_INVALID,
4768 "ErrorCode,DiscoveryMode not supported");
4769 return 0;
4770 }
4771#endif
4772 }
4773
4774 if (start_sta_mode(dut) != 0)
4775 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4776 return sta_set_60g_common(dut, conn, cmd);
4777}
4778
4779
4780static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
4781 struct sigma_cmd *cmd)
4782{
4783 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02004784 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05304785
Jouni Malinened77e672018-01-10 16:45:13 +02004786 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08004787 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02004788 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05304789 wpa_command(intf, "DISCONNECT");
4790 return 1;
4791 }
4792
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004793 disconnect_station(dut);
4794 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
4795 * due to cached results. */
4796 wpa_command(intf, "SET ignore_old_scan_res 1");
4797 wpa_command(intf, "BSS_FLUSH");
4798 return 1;
4799}
4800
4801
4802static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
4803 struct sigma_cmd *cmd)
4804{
4805 const char *intf = get_param(cmd, "Interface");
4806 const char *bssid = get_param(cmd, "bssid");
4807 const char *val = get_param(cmd, "CHANNEL");
4808 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05304809 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05304810 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004811 int res;
4812 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05304813 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05304814 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004815
4816 if (bssid == NULL) {
4817 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
4818 "argument");
4819 return 0;
4820 }
4821
4822 if (val)
4823 chan = atoi(val);
4824
4825 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
4826 /* The current network may be from sta_associate or
4827 * sta_hs2_associate
4828 */
4829 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
4830 0 ||
4831 set_network(intf, 0, "bssid", bssid) < 0)
4832 return -2;
4833 }
4834
4835 ctrl = open_wpa_mon(intf);
4836 if (ctrl == NULL) {
4837 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
4838 "wpa_supplicant monitor connection");
4839 return -1;
4840 }
4841
Sunil Duttd30ce092018-01-11 23:56:29 +05304842 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
4843 sizeof(result)) < 0 ||
4844 strncmp(result, "COMPLETED", 9) != 0) {
4845 sigma_dut_print(dut, DUT_MSG_DEBUG,
4846 "sta_reassoc: Not connected");
4847 fastreassoc = 0;
4848 }
4849
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05304850 if (dut->rsne_override) {
4851#ifdef NL80211_SUPPORT
4852 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
4853 sta_config_rsnie(dut, 1);
4854 dut->config_rsnie = 1;
4855 }
4856#endif /* NL80211_SUPPORT */
4857 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4858 dut->rsne_override);
4859 if (wpa_command(intf, buf) < 0) {
4860 send_resp(dut, conn, SIGMA_ERROR,
4861 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4862 return 0;
4863 }
4864 }
4865
Sunil Duttd30ce092018-01-11 23:56:29 +05304866 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004867#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05304868 if (chan) {
4869 unsigned int freq;
4870
4871 freq = channel_to_freq(chan);
4872 if (!freq) {
4873 sigma_dut_print(dut, DUT_MSG_ERROR,
4874 "Invalid channel number provided: %d",
4875 chan);
4876 send_resp(dut, conn, SIGMA_INVALID,
4877 "ErrorCode,Invalid channel number");
4878 goto close_mon_conn;
4879 }
4880 res = snprintf(buf, sizeof(buf),
4881 "SCAN TYPE=ONLY freq=%d", freq);
4882 } else {
4883 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
4884 }
4885 if (res < 0 || res >= (int) sizeof(buf)) {
4886 send_resp(dut, conn, SIGMA_ERROR,
4887 "ErrorCode,snprintf failed");
4888 goto close_mon_conn;
4889 }
4890 if (wpa_command(intf, buf) < 0) {
4891 sigma_dut_print(dut, DUT_MSG_INFO,
4892 "Failed to start scan");
4893 send_resp(dut, conn, SIGMA_ERROR,
4894 "ErrorCode,scan failed");
4895 goto close_mon_conn;
4896 }
4897
4898 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
4899 buf, sizeof(buf));
4900 if (res < 0) {
4901 sigma_dut_print(dut, DUT_MSG_INFO,
4902 "Scan did not complete");
4903 send_resp(dut, conn, SIGMA_ERROR,
4904 "ErrorCode,scan did not complete");
4905 goto close_mon_conn;
4906 }
4907
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004908 if (set_network(intf, dut->infra_network_id, "bssid", "any")
4909 < 0) {
4910 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
4911 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05304912 status = -2;
4913 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004914 }
4915 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
4916 bssid, chan);
4917 if (res > 0 && res < (int) sizeof(buf))
4918 res = wpa_command(intf, buf);
4919
4920 if (res < 0 || res >= (int) sizeof(buf)) {
4921 send_resp(dut, conn, SIGMA_ERROR,
4922 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05304923 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004924 }
4925#else /* ANDROID */
4926 sigma_dut_print(dut, DUT_MSG_DEBUG,
4927 "Reassoc using iwpriv - skip chan=%d info",
4928 chan);
4929 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
4930 if (system(buf) != 0) {
4931 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05304932 status = -2;
4933 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004934 }
4935#endif /* ANDROID */
4936 sigma_dut_print(dut, DUT_MSG_INFO,
4937 "sta_reassoc: Run %s successful", buf);
4938 } else if (wpa_command(intf, "REASSOCIATE")) {
4939 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
4940 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05304941 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004942 }
4943
4944 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
4945 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05304946 if (res < 0) {
4947 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
4948 status = -1;
4949 goto close_mon_conn;
4950 }
4951 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004952
Ashwini Patil467efef2017-05-25 12:18:27 +05304953close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004954 wpa_ctrl_detach(ctrl);
4955 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05304956 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004957}
4958
4959
4960static void hs2_clear_credentials(const char *intf)
4961{
4962 wpa_command(intf, "REMOVE_CRED all");
4963}
4964
4965
Lior Davidcc88b562017-01-03 18:52:09 +02004966#ifdef __linux__
4967static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
4968 unsigned int *aid)
4969{
Lior David0fe101e2017-03-09 16:09:50 +02004970 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02004971
Lior David0fe101e2017-03-09 16:09:50 +02004972 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02004973}
4974#endif /* __linux__ */
4975
4976
4977static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
4978 unsigned int *aid)
4979{
4980 switch (get_driver_type()) {
4981#ifdef __linux__
4982 case DRIVER_WIL6210:
4983 return wil6210_get_aid(dut, bssid, aid);
4984#endif /* __linux__ */
4985 default:
4986 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
4987 return -1;
4988 }
4989}
4990
4991
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004992static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
4993 struct sigma_cmd *cmd)
4994{
4995 char buf[MAX_CMD_LEN];
4996 char bss_list[MAX_CMD_LEN];
4997 const char *parameter = get_param(cmd, "Parameter");
4998
4999 if (parameter == NULL)
5000 return -1;
5001
Lior Davidcc88b562017-01-03 18:52:09 +02005002 if (strcasecmp(parameter, "AID") == 0) {
5003 unsigned int aid = 0;
5004 char bssid[20];
5005
5006 if (get_wpa_status(get_station_ifname(), "bssid",
5007 bssid, sizeof(bssid)) < 0) {
5008 sigma_dut_print(dut, DUT_MSG_ERROR,
5009 "could not get bssid");
5010 return -2;
5011 }
5012
5013 if (sta_get_aid_60g(dut, bssid, &aid))
5014 return -2;
5015
5016 snprintf(buf, sizeof(buf), "aid,%d", aid);
5017 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5018 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5019 return 0;
5020 }
5021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005022 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5023 char *bss_line;
5024 char *bss_id = NULL;
5025 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305026 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005027
5028 if (ifname == NULL) {
5029 sigma_dut_print(dut, DUT_MSG_INFO,
5030 "For get DiscoveredDevList need Interface name.");
5031 return -1;
5032 }
5033
5034 /*
5035 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5036 * of BSSIDs in "bssid=<BSSID>\n"
5037 */
5038 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5039 bss_list,
5040 sizeof(bss_list)) < 0) {
5041 sigma_dut_print(dut, DUT_MSG_ERROR,
5042 "Failed to get bss list");
5043 return -1;
5044 }
5045
5046 sigma_dut_print(dut, DUT_MSG_DEBUG,
5047 "bss list for ifname:%s is:%s",
5048 ifname, bss_list);
5049
5050 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305051 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005052 while (bss_line) {
5053 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5054 bss_id) {
5055 int len;
5056
5057 len = snprintf(buf + strlen(buf),
5058 sizeof(buf) - strlen(buf),
5059 ",%s", bss_id);
5060 free(bss_id);
5061 bss_id = NULL;
5062 if (len < 0) {
5063 sigma_dut_print(dut,
5064 DUT_MSG_ERROR,
5065 "Failed to read BSSID");
5066 send_resp(dut, conn, SIGMA_ERROR,
5067 "ErrorCode,Failed to read BSS ID");
5068 return 0;
5069 }
5070
5071 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5072 sigma_dut_print(dut,
5073 DUT_MSG_ERROR,
5074 "Response buf too small for list");
5075 send_resp(dut, conn,
5076 SIGMA_ERROR,
5077 "ErrorCode,Response buf too small for list");
5078 return 0;
5079 }
5080 }
5081
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305082 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005083 }
5084
5085 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5086 buf);
5087 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5088 return 0;
5089 }
5090
5091 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5092 return 0;
5093}
5094
5095
5096static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5097 struct sigma_cmd *cmd)
5098{
5099 const char *program = get_param(cmd, "Program");
5100
5101 if (program == NULL)
5102 return -1;
5103
5104 if (strcasecmp(program, "P2PNFC") == 0)
5105 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5106
5107 if (strcasecmp(program, "60ghz") == 0)
5108 return sta_get_parameter_60g(dut, conn, cmd);
5109
5110#ifdef ANDROID_NAN
5111 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005112 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005113#endif /* ANDROID_NAN */
5114
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005115#ifdef MIRACAST
5116 if (strcasecmp(program, "WFD") == 0 ||
5117 strcasecmp(program, "DisplayR2") == 0)
5118 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5119#endif /* MIRACAST */
5120
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005121 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5122 return 0;
5123}
5124
5125
5126static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5127 const char *type)
5128{
5129 char buf[100];
5130
5131 if (dut->program == PROGRAM_VHT) {
5132 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5133 if (system(buf) != 0) {
5134 sigma_dut_print(dut, DUT_MSG_ERROR,
5135 "iwpriv %s chwidth failed", intf);
5136 }
5137
5138 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5139 if (system(buf) != 0) {
5140 sigma_dut_print(dut, DUT_MSG_ERROR,
5141 "iwpriv %s mode 11ACVHT80 failed",
5142 intf);
5143 }
5144
5145 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5146 if (system(buf) != 0) {
5147 sigma_dut_print(dut, DUT_MSG_ERROR,
5148 "iwpriv %s vhtmcs -1 failed", intf);
5149 }
5150 }
5151
5152 if (dut->program == PROGRAM_HT) {
5153 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5154 if (system(buf) != 0) {
5155 sigma_dut_print(dut, DUT_MSG_ERROR,
5156 "iwpriv %s chwidth failed", intf);
5157 }
5158
5159 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5160 if (system(buf) != 0) {
5161 sigma_dut_print(dut, DUT_MSG_ERROR,
5162 "iwpriv %s mode 11naht40 failed",
5163 intf);
5164 }
5165
5166 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5167 if (system(buf) != 0) {
5168 sigma_dut_print(dut, DUT_MSG_ERROR,
5169 "iwpriv set11NRates failed");
5170 }
5171 }
5172
5173 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5174 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5175 if (system(buf) != 0) {
5176 sigma_dut_print(dut, DUT_MSG_ERROR,
5177 "disabling powersave failed");
5178 }
5179
5180 /* Reset CTS width */
5181 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5182 intf);
5183 if (system(buf) != 0) {
5184 sigma_dut_print(dut, DUT_MSG_ERROR,
5185 "wifitool %s beeliner_fw_test 54 0 failed",
5186 intf);
5187 }
5188
5189 /* Enable Dynamic Bandwidth signalling by default */
5190 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5191 if (system(buf) != 0) {
5192 sigma_dut_print(dut, DUT_MSG_ERROR,
5193 "iwpriv %s cwmenable 1 failed", intf);
5194 }
5195
5196 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5197 if (system(buf) != 0) {
5198 sigma_dut_print(dut, DUT_MSG_ERROR,
5199 "iwpriv rts failed");
5200 }
5201 }
5202
5203 if (type && strcasecmp(type, "Testbed") == 0) {
5204 dut->testbed_flag_txsp = 1;
5205 dut->testbed_flag_rxsp = 1;
5206 /* STA has to set spatial stream to 2 per Appendix H */
5207 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5208 if (system(buf) != 0) {
5209 sigma_dut_print(dut, DUT_MSG_ERROR,
5210 "iwpriv vht_mcsmap failed");
5211 }
5212
5213 /* Disable LDPC per Appendix H */
5214 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5215 if (system(buf) != 0) {
5216 sigma_dut_print(dut, DUT_MSG_ERROR,
5217 "iwpriv %s ldpc 0 failed", intf);
5218 }
5219
5220 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5221 if (system(buf) != 0) {
5222 sigma_dut_print(dut, DUT_MSG_ERROR,
5223 "iwpriv amsdu failed");
5224 }
5225
5226 /* TODO: Disable STBC 2x1 transmit and receive */
5227 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5228 if (system(buf) != 0) {
5229 sigma_dut_print(dut, DUT_MSG_ERROR,
5230 "Disable tx_stbc 0 failed");
5231 }
5232
5233 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5234 if (system(buf) != 0) {
5235 sigma_dut_print(dut, DUT_MSG_ERROR,
5236 "Disable rx_stbc 0 failed");
5237 }
5238
5239 /* STA has to disable Short GI per Appendix H */
5240 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5241 if (system(buf) != 0) {
5242 sigma_dut_print(dut, DUT_MSG_ERROR,
5243 "iwpriv %s shortgi 0 failed", intf);
5244 }
5245 }
5246
5247 if (type && strcasecmp(type, "DUT") == 0) {
5248 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5249 if (system(buf) != 0) {
5250 sigma_dut_print(dut, DUT_MSG_ERROR,
5251 "iwpriv %s nss 3 failed", intf);
5252 }
5253
5254 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5255 if (system(buf) != 0) {
5256 sigma_dut_print(dut, DUT_MSG_ERROR,
5257 "iwpriv %s shortgi 1 failed", intf);
5258 }
5259 }
5260}
5261
5262
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005263#ifdef NL80211_SUPPORT
5264static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5265 enum he_mcs_config mcs)
5266{
5267 struct nl_msg *msg;
5268 int ret = 0;
5269 struct nlattr *params;
5270 int ifindex;
5271
5272 ifindex = if_nametoindex(intf);
5273 if (ifindex == 0) {
5274 sigma_dut_print(dut, DUT_MSG_ERROR,
5275 "%s: Index for interface %s failed",
5276 __func__, intf);
5277 return -1;
5278 }
5279
5280 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5281 NL80211_CMD_VENDOR)) ||
5282 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5283 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5284 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5285 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5286 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5287 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5288 mcs)) {
5289 sigma_dut_print(dut, DUT_MSG_ERROR,
5290 "%s: err in adding vendor_cmd and vendor_data",
5291 __func__);
5292 nlmsg_free(msg);
5293 return -1;
5294 }
5295 nla_nest_end(msg, params);
5296
5297 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5298 if (ret) {
5299 sigma_dut_print(dut, DUT_MSG_ERROR,
5300 "%s: err in send_and_recv_msgs, ret=%d",
5301 __func__, ret);
5302 }
5303 return ret;
5304}
5305#endif /* NL80211_SUPPORT */
5306
5307
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005308static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5309 const char *type)
5310{
5311 char buf[60];
5312
5313 if (dut->program == PROGRAM_HE) {
5314 /* resetting phymode to auto in case of HE program */
5315 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5316 if (system(buf) != 0) {
5317 sigma_dut_print(dut, DUT_MSG_ERROR,
5318 "iwpriv %s setphymode failed", intf);
5319 }
5320
5321 /* remove all network profiles */
5322 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005323
5324 /* Set nss to 1 and MCS 0-7 in case of testbed */
5325 if (type && strcasecmp(type, "Testbed") == 0) {
5326#ifdef NL80211_SUPPORT
5327 int ret;
5328#endif /* NL80211_SUPPORT */
5329
5330 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5331 if (system(buf) != 0) {
5332 sigma_dut_print(dut, DUT_MSG_ERROR,
5333 "iwpriv %s nss failed", intf);
5334 }
5335
5336#ifdef NL80211_SUPPORT
5337 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5338 if (ret) {
5339 sigma_dut_print(dut, DUT_MSG_ERROR,
5340 "Setting of MCS failed, ret:%d",
5341 ret);
5342 }
5343#endif /* NL80211_SUPPORT */
5344 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005345 }
5346}
5347
5348
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005349static int cmd_sta_reset_default(struct sigma_dut *dut,
5350 struct sigma_conn *conn,
5351 struct sigma_cmd *cmd)
5352{
5353 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5354 struct sigma_cmd *cmd);
5355 const char *intf = get_param(cmd, "Interface");
5356 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005357 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305358 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005359
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005360 if (!program)
5361 program = get_param(cmd, "prog");
5362 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005363 dut->device_type = STA_unknown;
5364 type = get_param(cmd, "type");
5365 if (type && strcasecmp(type, "Testbed") == 0)
5366 dut->device_type = STA_testbed;
5367 if (type && strcasecmp(type, "DUT") == 0)
5368 dut->device_type = STA_dut;
5369
5370 if (dut->program == PROGRAM_TDLS) {
5371 /* Clear TDLS testing mode */
5372 wpa_command(intf, "SET tdls_disabled 0");
5373 wpa_command(intf, "SET tdls_testing 0");
5374 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305375 if (get_driver_type() == DRIVER_WCN) {
5376 /* Enable the WCN driver in TDLS Explicit trigger mode
5377 */
5378 wpa_command(intf, "SET tdls_external_control 0");
5379 wpa_command(intf, "SET tdls_trigger_control 0");
5380 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005381 }
5382
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005383#ifdef MIRACAST
5384 if (dut->program == PROGRAM_WFD ||
5385 dut->program == PROGRAM_DISPLAYR2)
5386 miracast_sta_reset_default(dut, conn, cmd);
5387#endif /* MIRACAST */
5388
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005389 switch (get_driver_type()) {
5390 case DRIVER_ATHEROS:
5391 sta_reset_default_ath(dut, intf, type);
5392 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005393 case DRIVER_WCN:
5394 sta_reset_default_wcn(dut, intf, type);
5395 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005396 default:
5397 break;
5398 }
5399
5400#ifdef ANDROID_NAN
5401 if (dut->program == PROGRAM_NAN)
5402 nan_cmd_sta_reset_default(dut, conn, cmd);
5403#endif /* ANDROID_NAN */
5404
5405 if (dut->program == PROGRAM_HS2_R2) {
5406 unlink("SP/wi-fi.org/pps.xml");
5407 if (system("rm -r SP/*") != 0) {
5408 }
5409 unlink("next-client-cert.pem");
5410 unlink("next-client-key.pem");
5411 }
5412
5413 if (dut->program == PROGRAM_60GHZ) {
5414 const char *dev_role = get_param(cmd, "DevRole");
5415
5416 if (!dev_role) {
5417 send_resp(dut, conn, SIGMA_ERROR,
5418 "errorCode,Missing DevRole argument");
5419 return 0;
5420 }
5421
5422 if (strcasecmp(dev_role, "STA") == 0)
5423 dut->dev_role = DEVROLE_STA;
5424 else if (strcasecmp(dev_role, "PCP") == 0)
5425 dut->dev_role = DEVROLE_PCP;
5426 else {
5427 send_resp(dut, conn, SIGMA_ERROR,
5428 "errorCode,Unknown DevRole");
5429 return 0;
5430 }
5431
5432 if (dut->device_type == STA_unknown) {
5433 sigma_dut_print(dut, DUT_MSG_ERROR,
5434 "Device type is not STA testbed or DUT");
5435 send_resp(dut, conn, SIGMA_ERROR,
5436 "errorCode,Unknown device type");
5437 return 0;
5438 }
5439 }
5440
5441 wpa_command(intf, "WPS_ER_STOP");
5442 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305443 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005444 wpa_command(intf, "SET radio_disabled 0");
5445
5446 if (dut->tmp_mac_addr && dut->set_macaddr) {
5447 dut->tmp_mac_addr = 0;
5448 if (system(dut->set_macaddr) != 0) {
5449 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5450 "temporary MAC address");
5451 }
5452 }
5453
5454 set_ps(intf, dut, 0);
5455
5456 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5457 wpa_command(intf, "SET interworking 1");
5458 wpa_command(intf, "SET hs20 1");
5459 }
5460
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08005461 if (dut->program == PROGRAM_HS2_R2 ||
5462 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005463 wpa_command(intf, "SET pmf 1");
5464 } else {
5465 wpa_command(intf, "SET pmf 0");
5466 }
5467
5468 hs2_clear_credentials(intf);
5469 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
5470 wpa_command(intf, "SET access_network_type 15");
5471
5472 static_ip_file(0, NULL, NULL, NULL);
5473 kill_dhcp_client(dut, intf);
5474 clear_ip_addr(dut, intf);
5475
5476 dut->er_oper_performed = 0;
5477 dut->er_oper_bssid[0] = '\0';
5478
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07005479 if (dut->program == PROGRAM_LOC) {
5480 /* Disable Interworking by default */
5481 wpa_command(get_station_ifname(), "SET interworking 0");
5482 }
5483
Ashwini Patil00402582017-04-13 12:29:39 +05305484 if (dut->program == PROGRAM_MBO) {
5485 free(dut->non_pref_ch_list);
5486 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05305487 free(dut->btm_query_cand_list);
5488 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05305489 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05305490 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05305491 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305492 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05305493 }
5494
Jouni Malinen3c367e82017-06-23 17:01:47 +03005495 free(dut->rsne_override);
5496 dut->rsne_override = NULL;
5497
Jouni Malinen68143132017-09-02 02:34:08 +03005498 free(dut->sae_commit_override);
5499 dut->sae_commit_override = NULL;
5500
Jouni Malinend86e5822017-08-29 03:55:32 +03005501 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02005502 free(dut->dpp_peer_uri);
5503 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02005504 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02005505 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03005506
Jouni Malinenfac9cad2017-10-10 18:35:55 +03005507 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
5508
vamsi krishnaa2799492017-12-05 14:28:01 +05305509 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305510 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05305511 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305512 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
5513 dut->fils_hlp = 0;
5514#ifdef ANDROID
5515 hlp_thread_cleanup(dut);
5516#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05305517 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305518
Sunil Dutt076081f2018-02-05 19:45:50 +05305519#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05305520 if (get_driver_type() == DRIVER_WCN &&
5521 dut->config_rsnie == 1) {
5522 dut->config_rsnie = 0;
5523 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05305524 }
5525#endif /* NL80211_SUPPORT */
5526
Sunil Duttfebf8a82018-02-09 18:50:13 +05305527 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
5528 dut->dev_role = DEVROLE_STA_CFON;
5529 return sta_cfon_reset_default(dut, conn, cmd);
5530 }
5531
5532 if (dut->program != PROGRAM_VHT)
5533 return cmd_sta_p2p_reset(dut, conn, cmd);
5534
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08005535 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536}
5537
5538
5539static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
5540 struct sigma_cmd *cmd)
5541{
5542 const char *program = get_param(cmd, "Program");
5543
5544 if (program == NULL)
5545 return -1;
5546#ifdef ANDROID_NAN
5547 if (strcasecmp(program, "NAN") == 0)
5548 return nan_cmd_sta_get_events(dut, conn, cmd);
5549#endif /* ANDROID_NAN */
5550 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5551 return 0;
5552}
5553
5554
5555static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
5556 struct sigma_cmd *cmd)
5557{
5558 const char *program = get_param(cmd, "Prog");
5559
5560 if (program == NULL)
5561 return -1;
5562#ifdef ANDROID_NAN
5563 if (strcasecmp(program, "NAN") == 0)
5564 return nan_cmd_sta_exec_action(dut, conn, cmd);
5565#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005566 if (strcasecmp(program, "Loc") == 0)
5567 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005568 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5569 return 0;
5570}
5571
5572
5573static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
5574 struct sigma_cmd *cmd)
5575{
5576 const char *intf = get_param(cmd, "Interface");
5577 const char *val, *mcs32, *rate;
5578
5579 val = get_param(cmd, "GREENFIELD");
5580 if (val) {
5581 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5582 /* Enable GD */
5583 send_resp(dut, conn, SIGMA_ERROR,
5584 "ErrorCode,GF not supported");
5585 return 0;
5586 }
5587 }
5588
5589 val = get_param(cmd, "SGI20");
5590 if (val) {
5591 switch (get_driver_type()) {
5592 case DRIVER_ATHEROS:
5593 ath_sta_set_sgi(dut, intf, val);
5594 break;
5595 default:
5596 send_resp(dut, conn, SIGMA_ERROR,
5597 "ErrorCode,SGI20 not supported");
5598 return 0;
5599 }
5600 }
5601
5602 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
5603 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
5604 if (mcs32 && rate) {
5605 /* TODO */
5606 send_resp(dut, conn, SIGMA_ERROR,
5607 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
5608 return 0;
5609 } else if (mcs32 && !rate) {
5610 /* TODO */
5611 send_resp(dut, conn, SIGMA_ERROR,
5612 "ErrorCode,MCS32 not supported");
5613 return 0;
5614 } else if (!mcs32 && rate) {
5615 switch (get_driver_type()) {
5616 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005617 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005618 ath_sta_set_11nrates(dut, intf, rate);
5619 break;
5620 default:
5621 send_resp(dut, conn, SIGMA_ERROR,
5622 "ErrorCode,MCS32_FIXEDRATE not supported");
5623 return 0;
5624 }
5625 }
5626
5627 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5628}
5629
5630
5631static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
5632 struct sigma_conn *conn,
5633 struct sigma_cmd *cmd)
5634{
5635 const char *intf = get_param(cmd, "Interface");
5636 const char *val;
5637 char buf[30];
5638 int tkip = -1;
5639 int wep = -1;
5640
5641 val = get_param(cmd, "SGI80");
5642 if (val) {
5643 int sgi80;
5644
5645 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5646 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
5647 if (system(buf) != 0) {
5648 sigma_dut_print(dut, DUT_MSG_ERROR,
5649 "iwpriv shortgi failed");
5650 }
5651 }
5652
5653 val = get_param(cmd, "TxBF");
5654 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5655 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
5656 if (system(buf) != 0) {
5657 sigma_dut_print(dut, DUT_MSG_ERROR,
5658 "iwpriv vhtsubfee failed");
5659 }
5660 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
5661 if (system(buf) != 0) {
5662 sigma_dut_print(dut, DUT_MSG_ERROR,
5663 "iwpriv vhtsubfer failed");
5664 }
5665 }
5666
5667 val = get_param(cmd, "MU_TxBF");
5668 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5669 switch (get_driver_type()) {
5670 case DRIVER_ATHEROS:
5671 ath_sta_set_txsp_stream(dut, intf, "1SS");
5672 ath_sta_set_rxsp_stream(dut, intf, "1SS");
5673 case DRIVER_WCN:
5674 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
5675 send_resp(dut, conn, SIGMA_ERROR,
5676 "ErrorCode,Failed to set RX/TXSP_STREAM");
5677 return 0;
5678 }
5679 default:
5680 sigma_dut_print(dut, DUT_MSG_ERROR,
5681 "Setting SP_STREAM not supported");
5682 break;
5683 }
5684 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
5685 if (system(buf) != 0) {
5686 sigma_dut_print(dut, DUT_MSG_ERROR,
5687 "iwpriv vhtmubfee failed");
5688 }
5689 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
5690 if (system(buf) != 0) {
5691 sigma_dut_print(dut, DUT_MSG_ERROR,
5692 "iwpriv vhtmubfer failed");
5693 }
5694 }
5695
5696 val = get_param(cmd, "LDPC");
5697 if (val) {
5698 int ldpc;
5699
5700 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5701 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
5702 if (system(buf) != 0) {
5703 sigma_dut_print(dut, DUT_MSG_ERROR,
5704 "iwpriv ldpc failed");
5705 }
5706 }
5707
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08005708 val = get_param(cmd, "BCC");
5709 if (val) {
5710 int bcc;
5711
5712 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5713 /* use LDPC iwpriv itself to set bcc coding, bcc coding
5714 * is mutually exclusive to bcc */
5715 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
5716 if (system(buf) != 0) {
5717 sigma_dut_print(dut, DUT_MSG_ERROR,
5718 "Enabling/Disabling of BCC failed");
5719 }
5720 }
5721
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005722 val = get_param(cmd, "opt_md_notif_ie");
5723 if (val) {
5724 char *result = NULL;
5725 char delim[] = ";";
5726 char token[30];
5727 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305728 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005729
Peng Xub8fc5cc2017-05-10 17:27:28 -07005730 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305731 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005732
5733 /* Extract the NSS information */
5734 if (result) {
5735 value = atoi(result);
5736 switch (value) {
5737 case 1:
5738 config_val = 1;
5739 break;
5740 case 2:
5741 config_val = 3;
5742 break;
5743 case 3:
5744 config_val = 7;
5745 break;
5746 case 4:
5747 config_val = 15;
5748 break;
5749 default:
5750 config_val = 3;
5751 break;
5752 }
5753
5754 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
5755 intf, config_val);
5756 if (system(buf) != 0) {
5757 sigma_dut_print(dut, DUT_MSG_ERROR,
5758 "iwpriv rxchainmask failed");
5759 }
5760
5761 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
5762 intf, config_val);
5763 if (system(buf) != 0) {
5764 sigma_dut_print(dut, DUT_MSG_ERROR,
5765 "iwpriv txchainmask failed");
5766 }
5767 }
5768
5769 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305770 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005771 if (result) {
5772 value = atoi(result);
5773 switch (value) {
5774 case 20:
5775 config_val = 0;
5776 break;
5777 case 40:
5778 config_val = 1;
5779 break;
5780 case 80:
5781 config_val = 2;
5782 break;
5783 case 160:
5784 config_val = 3;
5785 break;
5786 default:
5787 config_val = 2;
5788 break;
5789 }
5790
5791 dut->chwidth = config_val;
5792
5793 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5794 intf, config_val);
5795 if (system(buf) != 0) {
5796 sigma_dut_print(dut, DUT_MSG_ERROR,
5797 "iwpriv chwidth failed");
5798 }
5799 }
5800
5801 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
5802 if (system(buf) != 0) {
5803 sigma_dut_print(dut, DUT_MSG_ERROR,
5804 "iwpriv opmode_notify failed");
5805 }
5806 }
5807
5808 val = get_param(cmd, "nss_mcs_cap");
5809 if (val) {
5810 int nss, mcs;
5811 char token[20];
5812 char *result = NULL;
5813 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305814 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005815
Peng Xub8fc5cc2017-05-10 17:27:28 -07005816 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305817 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305818 if (!result) {
5819 sigma_dut_print(dut, DUT_MSG_ERROR,
5820 "VHT NSS not specified");
5821 return 0;
5822 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005823 nss = atoi(result);
5824
5825 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
5826 if (system(buf) != 0) {
5827 sigma_dut_print(dut, DUT_MSG_ERROR,
5828 "iwpriv nss failed");
5829 }
5830
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305831 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005832 if (result == NULL) {
5833 sigma_dut_print(dut, DUT_MSG_ERROR,
5834 "VHTMCS NOT SPECIFIED!");
5835 return 0;
5836 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305837 result = strtok_r(result, "-", &saveptr);
5838 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305839 if (!result) {
5840 sigma_dut_print(dut, DUT_MSG_ERROR,
5841 "VHT MCS not specified");
5842 return 0;
5843 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005844 mcs = atoi(result);
5845
5846 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
5847 if (system(buf) != 0) {
5848 sigma_dut_print(dut, DUT_MSG_ERROR,
5849 "iwpriv mcs failed");
5850 }
5851
5852 switch (nss) {
5853 case 1:
5854 switch (mcs) {
5855 case 7:
5856 vht_mcsmap = 0xfffc;
5857 break;
5858 case 8:
5859 vht_mcsmap = 0xfffd;
5860 break;
5861 case 9:
5862 vht_mcsmap = 0xfffe;
5863 break;
5864 default:
5865 vht_mcsmap = 0xfffe;
5866 break;
5867 }
5868 break;
5869 case 2:
5870 switch (mcs) {
5871 case 7:
5872 vht_mcsmap = 0xfff0;
5873 break;
5874 case 8:
5875 vht_mcsmap = 0xfff5;
5876 break;
5877 case 9:
5878 vht_mcsmap = 0xfffa;
5879 break;
5880 default:
5881 vht_mcsmap = 0xfffa;
5882 break;
5883 }
5884 break;
5885 case 3:
5886 switch (mcs) {
5887 case 7:
5888 vht_mcsmap = 0xffc0;
5889 break;
5890 case 8:
5891 vht_mcsmap = 0xffd5;
5892 break;
5893 case 9:
5894 vht_mcsmap = 0xffea;
5895 break;
5896 default:
5897 vht_mcsmap = 0xffea;
5898 break;
5899 }
5900 break;
5901 default:
5902 vht_mcsmap = 0xffea;
5903 break;
5904 }
5905 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5906 intf, vht_mcsmap);
5907 if (system(buf) != 0) {
5908 sigma_dut_print(dut, DUT_MSG_ERROR,
5909 "iwpriv vht_mcsmap failed");
5910 }
5911 }
5912
5913 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
5914
5915 val = get_param(cmd, "Vht_tkip");
5916 if (val)
5917 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5918
5919 val = get_param(cmd, "Vht_wep");
5920 if (val)
5921 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5922
5923 if (tkip != -1 || wep != -1) {
5924 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
5925 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
5926 intf);
5927 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
5928 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
5929 intf);
5930 } else {
5931 sigma_dut_print(dut, DUT_MSG_ERROR,
5932 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
5933 return 0;
5934 }
5935
5936 if (system(buf) != 0) {
5937 sigma_dut_print(dut, DUT_MSG_ERROR,
5938 "iwpriv htweptkip failed");
5939 }
5940 }
5941
5942 val = get_param(cmd, "txBandwidth");
5943 if (val) {
5944 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08005945 case DRIVER_WCN:
5946 if (wcn_sta_set_width(dut, intf, val) < 0) {
5947 send_resp(dut, conn, SIGMA_ERROR,
5948 "ErrorCode,Failed to set txBandwidth");
5949 return 0;
5950 }
5951 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005952 case DRIVER_ATHEROS:
5953 if (ath_set_width(dut, conn, intf, val) < 0) {
5954 send_resp(dut, conn, SIGMA_ERROR,
5955 "ErrorCode,Failed to set txBandwidth");
5956 return 0;
5957 }
5958 break;
5959 default:
5960 sigma_dut_print(dut, DUT_MSG_ERROR,
5961 "Setting txBandwidth not supported");
5962 break;
5963 }
5964 }
5965
5966 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5967}
5968
5969
5970static int sta_set_wireless_60g(struct sigma_dut *dut,
5971 struct sigma_conn *conn,
5972 struct sigma_cmd *cmd)
5973{
5974 const char *dev_role = get_param(cmd, "DevRole");
5975
5976 if (!dev_role) {
5977 send_resp(dut, conn, SIGMA_INVALID,
5978 "ErrorCode,DevRole not specified");
5979 return 0;
5980 }
5981
5982 if (strcasecmp(dev_role, "PCP") == 0)
5983 return sta_set_60g_pcp(dut, conn, cmd);
5984 if (strcasecmp(dev_role, "STA") == 0)
5985 return sta_set_60g_sta(dut, conn, cmd);
5986 send_resp(dut, conn, SIGMA_INVALID,
5987 "ErrorCode,DevRole not supported");
5988 return 0;
5989}
5990
5991
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305992static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
5993 struct sigma_cmd *cmd)
5994{
5995 int status;
5996 const char *intf = get_param(cmd, "Interface");
5997 const char *val = get_param(cmd, "DevRole");
5998
5999 if (val && strcasecmp(val, "STA-CFON") == 0) {
6000 status = sta_cfon_set_wireless(dut, conn, cmd);
6001 if (status)
6002 return status;
6003 }
6004 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6005}
6006
6007
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006008static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6009 struct sigma_cmd *cmd)
6010{
6011 const char *val;
6012
6013 val = get_param(cmd, "Program");
6014 if (val) {
6015 if (strcasecmp(val, "11n") == 0)
6016 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006017 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006018 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6019 if (strcasecmp(val, "60ghz") == 0)
6020 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306021 if (strcasecmp(val, "OCE") == 0)
6022 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006023 send_resp(dut, conn, SIGMA_ERROR,
6024 "ErrorCode,Program value not supported");
6025 } else {
6026 send_resp(dut, conn, SIGMA_ERROR,
6027 "ErrorCode,Program argument not available");
6028 }
6029
6030 return 0;
6031}
6032
6033
6034static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6035 int tid)
6036{
6037 char buf[100];
6038 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6039
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306040 if (tid < 0 ||
6041 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6042 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6043 return;
6044 }
6045
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046 /*
6047 * Two ways to ensure that addba request with a
6048 * non zero TID could be sent out. EV 117296
6049 */
6050 snprintf(buf, sizeof(buf),
6051 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6052 tid);
6053 if (system(buf) != 0) {
6054 sigma_dut_print(dut, DUT_MSG_ERROR,
6055 "Ping did not send out");
6056 }
6057
6058 snprintf(buf, sizeof(buf),
6059 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6060 intf, VI_QOS_TMP_FILE);
6061 if (system(buf) != 0)
6062 return;
6063
6064 snprintf(buf, sizeof(buf),
6065 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6066 intf, VI_QOS_TMP_FILE);
6067 if (system(buf) != 0)
6068 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6069
6070 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6071 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6072 if (system(buf) != 0) {
6073 sigma_dut_print(dut, DUT_MSG_ERROR,
6074 "VI_QOS_TEMP_FILE generation error failed");
6075 }
6076 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6077 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6078 if (system(buf) != 0) {
6079 sigma_dut_print(dut, DUT_MSG_ERROR,
6080 "VI_QOS_FILE generation failed");
6081 }
6082
6083 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6084 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6085 if (system(buf) != 0) {
6086 sigma_dut_print(dut, DUT_MSG_ERROR,
6087 "VI_QOS_FILE generation failed");
6088 }
6089
6090 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6091 if (system(buf) != 0) {
6092 }
6093}
6094
6095
6096static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6097 struct sigma_cmd *cmd)
6098{
6099 const char *intf = get_param(cmd, "Interface");
6100 const char *val;
6101 int tid = 0;
6102 char buf[100];
6103
6104 val = get_param(cmd, "TID");
6105 if (val) {
6106 tid = atoi(val);
6107 if (tid)
6108 ath_sta_inject_frame(dut, intf, tid);
6109 }
6110
6111 /* Command sequence for ADDBA request on Peregrine based devices */
6112 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6113 if (system(buf) != 0) {
6114 sigma_dut_print(dut, DUT_MSG_ERROR,
6115 "iwpriv setaddbaoper failed");
6116 }
6117
6118 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6119 if (system(buf) != 0) {
6120 sigma_dut_print(dut, DUT_MSG_ERROR,
6121 "wifitool senddelba failed");
6122 }
6123
6124 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6125 if (system(buf) != 0) {
6126 sigma_dut_print(dut, DUT_MSG_ERROR,
6127 "wifitool sendaddba failed");
6128 }
6129
6130 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6131
6132 return 1;
6133}
6134
6135
Lior David9981b512017-01-20 13:16:40 +02006136#ifdef __linux__
6137
6138static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6139 int agg_size)
6140{
6141 char dir[128], buf[128];
6142 FILE *f;
6143 regex_t re;
6144 regmatch_t m[2];
6145 int rc, ret = -1, vring_id, found;
6146
6147 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6148 sigma_dut_print(dut, DUT_MSG_ERROR,
6149 "failed to get wil6210 debugfs dir");
6150 return -1;
6151 }
6152
6153 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6154 f = fopen(buf, "r");
6155 if (!f) {
6156 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6157 return -1;
6158 }
6159
6160 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6161 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6162 goto out;
6163 }
6164
6165 /* find TX VRING for the mac address */
6166 found = 0;
6167 while (fgets(buf, sizeof(buf), f)) {
6168 if (strcasestr(buf, dest_mac)) {
6169 found = 1;
6170 break;
6171 }
6172 }
6173
6174 if (!found) {
6175 sigma_dut_print(dut, DUT_MSG_ERROR,
6176 "no TX VRING for %s", dest_mac);
6177 goto out;
6178 }
6179
6180 /* extract VRING ID, "VRING tx_<id> = {" */
6181 if (!fgets(buf, sizeof(buf), f)) {
6182 sigma_dut_print(dut, DUT_MSG_ERROR,
6183 "no VRING start line for %s", dest_mac);
6184 goto out;
6185 }
6186
6187 rc = regexec(&re, buf, 2, m, 0);
6188 regfree(&re);
6189 if (rc || m[1].rm_so < 0) {
6190 sigma_dut_print(dut, DUT_MSG_ERROR,
6191 "no VRING TX ID for %s", dest_mac);
6192 goto out;
6193 }
6194 buf[m[1].rm_eo] = 0;
6195 vring_id = atoi(&buf[m[1].rm_so]);
6196
6197 /* send the addba command */
6198 fclose(f);
6199 snprintf(buf, sizeof(buf), "%s/back", dir);
6200 f = fopen(buf, "w");
6201 if (!f) {
6202 sigma_dut_print(dut, DUT_MSG_ERROR,
6203 "failed to open: %s", buf);
6204 return -1;
6205 }
6206
6207 fprintf(f, "add %d %d\n", vring_id, agg_size);
6208
6209 ret = 0;
6210
6211out:
6212 fclose(f);
6213
6214 return ret;
6215}
6216
6217
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006218static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6219 struct sigma_cmd *cmd)
6220{
6221 const char *val;
6222 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006223
6224 val = get_param(cmd, "TID");
6225 if (val) {
6226 tid = atoi(val);
6227 if (tid != 0) {
6228 sigma_dut_print(dut, DUT_MSG_ERROR,
6229 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6230 tid);
6231 }
6232 }
6233
6234 val = get_param(cmd, "Dest_mac");
6235 if (!val) {
6236 sigma_dut_print(dut, DUT_MSG_ERROR,
6237 "Currently not supporting addba for 60G without Dest_mac");
6238 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6239 }
6240
Lior David9981b512017-01-20 13:16:40 +02006241 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006242 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006243
6244 return 1;
6245}
6246
Lior David9981b512017-01-20 13:16:40 +02006247#endif /* __linux__ */
6248
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006249
6250static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6251 struct sigma_cmd *cmd)
6252{
6253 switch (get_driver_type()) {
6254 case DRIVER_ATHEROS:
6255 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006256#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 case DRIVER_WIL6210:
6258 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006259#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006260 default:
6261 /*
6262 * There is no driver specific implementation for other drivers.
6263 * Ignore the command and report COMPLETE since the following
6264 * throughput test operation will end up sending ADDBA anyway.
6265 */
6266 return 1;
6267 }
6268}
6269
6270
6271int inject_eth_frame(int s, const void *data, size_t len,
6272 unsigned short ethtype, char *dst, char *src)
6273{
6274 struct iovec iov[4] = {
6275 {
6276 .iov_base = dst,
6277 .iov_len = ETH_ALEN,
6278 },
6279 {
6280 .iov_base = src,
6281 .iov_len = ETH_ALEN,
6282 },
6283 {
6284 .iov_base = &ethtype,
6285 .iov_len = sizeof(unsigned short),
6286 },
6287 {
6288 .iov_base = (void *) data,
6289 .iov_len = len,
6290 }
6291 };
6292 struct msghdr msg = {
6293 .msg_name = NULL,
6294 .msg_namelen = 0,
6295 .msg_iov = iov,
6296 .msg_iovlen = 4,
6297 .msg_control = NULL,
6298 .msg_controllen = 0,
6299 .msg_flags = 0,
6300 };
6301
6302 return sendmsg(s, &msg, 0);
6303}
6304
6305#if defined(__linux__) || defined(__QNXNTO__)
6306
6307int inject_frame(int s, const void *data, size_t len, int encrypt)
6308{
6309#define IEEE80211_RADIOTAP_F_WEP 0x04
6310#define IEEE80211_RADIOTAP_F_FRAG 0x08
6311 unsigned char rtap_hdr[] = {
6312 0x00, 0x00, /* radiotap version */
6313 0x0e, 0x00, /* radiotap length */
6314 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6315 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
6316 0x00, /* padding */
6317 0x00, 0x00, /* RX and TX flags to indicate that */
6318 0x00, 0x00, /* this is the injected frame directly */
6319 };
6320 struct iovec iov[2] = {
6321 {
6322 .iov_base = &rtap_hdr,
6323 .iov_len = sizeof(rtap_hdr),
6324 },
6325 {
6326 .iov_base = (void *) data,
6327 .iov_len = len,
6328 }
6329 };
6330 struct msghdr msg = {
6331 .msg_name = NULL,
6332 .msg_namelen = 0,
6333 .msg_iov = iov,
6334 .msg_iovlen = 2,
6335 .msg_control = NULL,
6336 .msg_controllen = 0,
6337 .msg_flags = 0,
6338 };
6339
6340 if (encrypt)
6341 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
6342
6343 return sendmsg(s, &msg, 0);
6344}
6345
6346
6347int open_monitor(const char *ifname)
6348{
6349#ifdef __QNXNTO__
6350 struct sockaddr_dl ll;
6351 int s;
6352
6353 memset(&ll, 0, sizeof(ll));
6354 ll.sdl_family = AF_LINK;
6355 ll.sdl_index = if_nametoindex(ifname);
6356 if (ll.sdl_index == 0) {
6357 perror("if_nametoindex");
6358 return -1;
6359 }
6360 s = socket(PF_INET, SOCK_RAW, 0);
6361#else /* __QNXNTO__ */
6362 struct sockaddr_ll ll;
6363 int s;
6364
6365 memset(&ll, 0, sizeof(ll));
6366 ll.sll_family = AF_PACKET;
6367 ll.sll_ifindex = if_nametoindex(ifname);
6368 if (ll.sll_ifindex == 0) {
6369 perror("if_nametoindex");
6370 return -1;
6371 }
6372 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
6373#endif /* __QNXNTO__ */
6374 if (s < 0) {
6375 perror("socket[PF_PACKET,SOCK_RAW]");
6376 return -1;
6377 }
6378
6379 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
6380 perror("monitor socket bind");
6381 close(s);
6382 return -1;
6383 }
6384
6385 return s;
6386}
6387
6388
6389static int hex2num(char c)
6390{
6391 if (c >= '0' && c <= '9')
6392 return c - '0';
6393 if (c >= 'a' && c <= 'f')
6394 return c - 'a' + 10;
6395 if (c >= 'A' && c <= 'F')
6396 return c - 'A' + 10;
6397 return -1;
6398}
6399
6400
6401int hwaddr_aton(const char *txt, unsigned char *addr)
6402{
6403 int i;
6404
6405 for (i = 0; i < 6; i++) {
6406 int a, b;
6407
6408 a = hex2num(*txt++);
6409 if (a < 0)
6410 return -1;
6411 b = hex2num(*txt++);
6412 if (b < 0)
6413 return -1;
6414 *addr++ = (a << 4) | b;
6415 if (i < 5 && *txt++ != ':')
6416 return -1;
6417 }
6418
6419 return 0;
6420}
6421
6422#endif /* defined(__linux__) || defined(__QNXNTO__) */
6423
6424enum send_frame_type {
6425 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
6426};
6427enum send_frame_protection {
6428 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6429};
6430
6431
6432static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6433 enum send_frame_type frame,
6434 enum send_frame_protection protected,
6435 const char *dest)
6436{
6437#ifdef __linux__
6438 unsigned char buf[1000], *pos;
6439 int s, res;
6440 char bssid[20], addr[20];
6441 char result[32], ssid[100];
6442 size_t ssid_len;
6443
6444 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6445 sizeof(result)) < 0 ||
6446 strncmp(result, "COMPLETED", 9) != 0) {
6447 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
6448 return 0;
6449 }
6450
6451 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
6452 < 0) {
6453 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6454 "current BSSID");
6455 return 0;
6456 }
6457
6458 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
6459 < 0) {
6460 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6461 "own MAC address");
6462 return 0;
6463 }
6464
6465 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
6466 < 0) {
6467 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6468 "current SSID");
6469 return 0;
6470 }
6471 ssid_len = strlen(ssid);
6472
6473 pos = buf;
6474
6475 /* Frame Control */
6476 switch (frame) {
6477 case DISASSOC:
6478 *pos++ = 0xa0;
6479 break;
6480 case DEAUTH:
6481 *pos++ = 0xc0;
6482 break;
6483 case SAQUERY:
6484 *pos++ = 0xd0;
6485 break;
6486 case AUTH:
6487 *pos++ = 0xb0;
6488 break;
6489 case ASSOCREQ:
6490 *pos++ = 0x00;
6491 break;
6492 case REASSOCREQ:
6493 *pos++ = 0x20;
6494 break;
6495 case DLS_REQ:
6496 *pos++ = 0xd0;
6497 break;
6498 }
6499
6500 if (protected == INCORRECT_KEY)
6501 *pos++ = 0x40; /* Set Protected field to 1 */
6502 else
6503 *pos++ = 0x00;
6504
6505 /* Duration */
6506 *pos++ = 0x00;
6507 *pos++ = 0x00;
6508
6509 /* addr1 = DA (current AP) */
6510 hwaddr_aton(bssid, pos);
6511 pos += 6;
6512 /* addr2 = SA (own address) */
6513 hwaddr_aton(addr, pos);
6514 pos += 6;
6515 /* addr3 = BSSID (current AP) */
6516 hwaddr_aton(bssid, pos);
6517 pos += 6;
6518
6519 /* Seq# (to be filled by driver/mac80211) */
6520 *pos++ = 0x00;
6521 *pos++ = 0x00;
6522
6523 if (protected == INCORRECT_KEY) {
6524 /* CCMP parameters */
6525 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6526 pos += 8;
6527 }
6528
6529 if (protected == INCORRECT_KEY) {
6530 switch (frame) {
6531 case DEAUTH:
6532 /* Reason code (encrypted) */
6533 memcpy(pos, "\xa7\x39", 2);
6534 pos += 2;
6535 break;
6536 case DISASSOC:
6537 /* Reason code (encrypted) */
6538 memcpy(pos, "\xa7\x39", 2);
6539 pos += 2;
6540 break;
6541 case SAQUERY:
6542 /* Category|Action|TransID (encrypted) */
6543 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6544 pos += 4;
6545 break;
6546 default:
6547 return -1;
6548 }
6549
6550 /* CCMP MIC */
6551 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6552 pos += 8;
6553 } else {
6554 switch (frame) {
6555 case DEAUTH:
6556 /* reason code = 8 */
6557 *pos++ = 0x08;
6558 *pos++ = 0x00;
6559 break;
6560 case DISASSOC:
6561 /* reason code = 8 */
6562 *pos++ = 0x08;
6563 *pos++ = 0x00;
6564 break;
6565 case SAQUERY:
6566 /* Category - SA Query */
6567 *pos++ = 0x08;
6568 /* SA query Action - Request */
6569 *pos++ = 0x00;
6570 /* Transaction ID */
6571 *pos++ = 0x12;
6572 *pos++ = 0x34;
6573 break;
6574 case AUTH:
6575 /* Auth Alg (Open) */
6576 *pos++ = 0x00;
6577 *pos++ = 0x00;
6578 /* Seq# */
6579 *pos++ = 0x01;
6580 *pos++ = 0x00;
6581 /* Status code */
6582 *pos++ = 0x00;
6583 *pos++ = 0x00;
6584 break;
6585 case ASSOCREQ:
6586 /* Capability Information */
6587 *pos++ = 0x31;
6588 *pos++ = 0x04;
6589 /* Listen Interval */
6590 *pos++ = 0x0a;
6591 *pos++ = 0x00;
6592 /* SSID */
6593 *pos++ = 0x00;
6594 *pos++ = ssid_len;
6595 memcpy(pos, ssid, ssid_len);
6596 pos += ssid_len;
6597 /* Supported Rates */
6598 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6599 10);
6600 pos += 10;
6601 /* Extended Supported Rates */
6602 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6603 pos += 6;
6604 /* RSN */
6605 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6606 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6607 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6608 pos += 28;
6609 break;
6610 case REASSOCREQ:
6611 /* Capability Information */
6612 *pos++ = 0x31;
6613 *pos++ = 0x04;
6614 /* Listen Interval */
6615 *pos++ = 0x0a;
6616 *pos++ = 0x00;
6617 /* Current AP */
6618 hwaddr_aton(bssid, pos);
6619 pos += 6;
6620 /* SSID */
6621 *pos++ = 0x00;
6622 *pos++ = ssid_len;
6623 memcpy(pos, ssid, ssid_len);
6624 pos += ssid_len;
6625 /* Supported Rates */
6626 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6627 10);
6628 pos += 10;
6629 /* Extended Supported Rates */
6630 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6631 pos += 6;
6632 /* RSN */
6633 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6634 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6635 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6636 pos += 28;
6637 break;
6638 case DLS_REQ:
6639 /* Category - DLS */
6640 *pos++ = 0x02;
6641 /* DLS Action - Request */
6642 *pos++ = 0x00;
6643 /* Destination MACAddress */
6644 if (dest)
6645 hwaddr_aton(dest, pos);
6646 else
6647 memset(pos, 0, 6);
6648 pos += 6;
6649 /* Source MACAddress */
6650 hwaddr_aton(addr, pos);
6651 pos += 6;
6652 /* Capability Information */
6653 *pos++ = 0x10; /* Privacy */
6654 *pos++ = 0x06; /* QoS */
6655 /* DLS Timeout Value */
6656 *pos++ = 0x00;
6657 *pos++ = 0x01;
6658 /* Supported rates */
6659 *pos++ = 0x01;
6660 *pos++ = 0x08;
6661 *pos++ = 0x0c; /* 6 Mbps */
6662 *pos++ = 0x12; /* 9 Mbps */
6663 *pos++ = 0x18; /* 12 Mbps */
6664 *pos++ = 0x24; /* 18 Mbps */
6665 *pos++ = 0x30; /* 24 Mbps */
6666 *pos++ = 0x48; /* 36 Mbps */
6667 *pos++ = 0x60; /* 48 Mbps */
6668 *pos++ = 0x6c; /* 54 Mbps */
6669 /* TODO: Extended Supported Rates */
6670 /* TODO: HT Capabilities */
6671 break;
6672 }
6673 }
6674
6675 s = open_monitor("sigmadut");
6676 if (s < 0) {
6677 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6678 "monitor socket");
6679 return 0;
6680 }
6681
6682 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
6683 if (res < 0) {
6684 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6685 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306686 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687 return 0;
6688 }
6689 if (res < pos - buf) {
6690 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
6691 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306692 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006693 return 0;
6694 }
6695
6696 close(s);
6697
6698 return 1;
6699#else /* __linux__ */
6700 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
6701 "yet supported");
6702 return 0;
6703#endif /* __linux__ */
6704}
6705
6706
6707static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
6708 struct sigma_conn *conn,
6709 struct sigma_cmd *cmd)
6710{
6711 const char *intf = get_param(cmd, "Interface");
6712 const char *sta, *val;
6713 unsigned char addr[ETH_ALEN];
6714 char buf[100];
6715
6716 sta = get_param(cmd, "peer");
6717 if (sta == NULL)
6718 sta = get_param(cmd, "station");
6719 if (sta == NULL) {
6720 send_resp(dut, conn, SIGMA_ERROR,
6721 "ErrorCode,Missing peer address");
6722 return 0;
6723 }
6724 if (hwaddr_aton(sta, addr) < 0) {
6725 send_resp(dut, conn, SIGMA_ERROR,
6726 "ErrorCode,Invalid peer address");
6727 return 0;
6728 }
6729
6730 val = get_param(cmd, "type");
6731 if (val == NULL)
6732 return -1;
6733
6734 if (strcasecmp(val, "DISCOVERY") == 0) {
6735 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
6736 if (wpa_command(intf, buf) < 0) {
6737 send_resp(dut, conn, SIGMA_ERROR,
6738 "ErrorCode,Failed to send TDLS discovery");
6739 return 0;
6740 }
6741 return 1;
6742 }
6743
6744 if (strcasecmp(val, "SETUP") == 0) {
6745 int status = 0, timeout = 0;
6746
6747 val = get_param(cmd, "Status");
6748 if (val)
6749 status = atoi(val);
6750
6751 val = get_param(cmd, "Timeout");
6752 if (val)
6753 timeout = atoi(val);
6754
6755 if (status != 0 && status != 37) {
6756 send_resp(dut, conn, SIGMA_ERROR,
6757 "ErrorCode,Unsupported status value");
6758 return 0;
6759 }
6760
6761 if (timeout != 0 && timeout != 301) {
6762 send_resp(dut, conn, SIGMA_ERROR,
6763 "ErrorCode,Unsupported timeout value");
6764 return 0;
6765 }
6766
6767 if (status && timeout) {
6768 send_resp(dut, conn, SIGMA_ERROR,
6769 "ErrorCode,Unsupported timeout+status "
6770 "combination");
6771 return 0;
6772 }
6773
6774 if (status == 37 &&
6775 wpa_command(intf, "SET tdls_testing 0x200")) {
6776 send_resp(dut, conn, SIGMA_ERROR,
6777 "ErrorCode,Failed to enable "
6778 "decline setup response test mode");
6779 return 0;
6780 }
6781
6782 if (timeout == 301) {
6783 int res;
6784 if (dut->no_tpk_expiration)
6785 res = wpa_command(intf,
6786 "SET tdls_testing 0x108");
6787 else
6788 res = wpa_command(intf,
6789 "SET tdls_testing 0x8");
6790 if (res) {
6791 send_resp(dut, conn, SIGMA_ERROR,
6792 "ErrorCode,Failed to set short TPK "
6793 "lifetime");
6794 return 0;
6795 }
6796 }
6797
6798 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
6799 if (wpa_command(intf, buf) < 0) {
6800 send_resp(dut, conn, SIGMA_ERROR,
6801 "ErrorCode,Failed to send TDLS setup");
6802 return 0;
6803 }
6804 return 1;
6805 }
6806
6807 if (strcasecmp(val, "TEARDOWN") == 0) {
6808 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
6809 if (wpa_command(intf, buf) < 0) {
6810 send_resp(dut, conn, SIGMA_ERROR,
6811 "ErrorCode,Failed to send TDLS teardown");
6812 return 0;
6813 }
6814 return 1;
6815 }
6816
6817 send_resp(dut, conn, SIGMA_ERROR,
6818 "ErrorCode,Unsupported TDLS frame");
6819 return 0;
6820}
6821
6822
6823static int sta_ap_known(const char *ifname, const char *bssid)
6824{
6825 char buf[4096];
6826
6827 snprintf(buf, sizeof(buf), "BSS %s", bssid);
6828 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
6829 return 0;
6830 if (strncmp(buf, "id=", 3) != 0)
6831 return 0;
6832 return 1;
6833}
6834
6835
6836static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
6837 const char *bssid)
6838{
6839 int res;
6840 struct wpa_ctrl *ctrl;
6841 char buf[256];
6842
6843 if (sta_ap_known(ifname, bssid))
6844 return 0;
6845 sigma_dut_print(dut, DUT_MSG_DEBUG,
6846 "AP not in BSS table - start scan");
6847
6848 ctrl = open_wpa_mon(ifname);
6849 if (ctrl == NULL) {
6850 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6851 "wpa_supplicant monitor connection");
6852 return -1;
6853 }
6854
6855 if (wpa_command(ifname, "SCAN") < 0) {
6856 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
6857 wpa_ctrl_detach(ctrl);
6858 wpa_ctrl_close(ctrl);
6859 return -1;
6860 }
6861
6862 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6863 buf, sizeof(buf));
6864
6865 wpa_ctrl_detach(ctrl);
6866 wpa_ctrl_close(ctrl);
6867
6868 if (res < 0) {
6869 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
6870 return -1;
6871 }
6872
6873 if (sta_ap_known(ifname, bssid))
6874 return 0;
6875 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
6876 return -1;
6877}
6878
6879
6880static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
6881 struct sigma_conn *conn,
6882 struct sigma_cmd *cmd,
6883 const char *intf)
6884{
6885 char buf[200];
6886
6887 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
6888 if (system(buf) != 0) {
6889 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
6890 "ndsend");
6891 return 0;
6892 }
6893
6894 return 1;
6895}
6896
6897
6898static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
6899 struct sigma_conn *conn,
6900 struct sigma_cmd *cmd,
6901 const char *intf)
6902{
6903 char buf[200];
6904 const char *ip = get_param(cmd, "SenderIP");
6905
Peng Xu26b356d2017-10-04 17:58:16 -07006906 if (!ip)
6907 return 0;
6908
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006909 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
6910 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6911 if (system(buf) == 0) {
6912 sigma_dut_print(dut, DUT_MSG_INFO,
6913 "Neighbor Solicitation got a response "
6914 "for %s@%s", ip, intf);
6915 }
6916
6917 return 1;
6918}
6919
6920
6921static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
6922 struct sigma_conn *conn,
6923 struct sigma_cmd *cmd,
6924 const char *ifname)
6925{
6926 char buf[200];
6927 const char *ip = get_param(cmd, "SenderIP");
6928
6929 if (ip == NULL) {
6930 send_resp(dut, conn, SIGMA_ERROR,
6931 "ErrorCode,Missing SenderIP parameter");
6932 return 0;
6933 }
6934 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
6935 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6936 if (system(buf) != 0) {
6937 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
6938 "for %s@%s", ip, ifname);
6939 }
6940
6941 return 1;
6942}
6943
6944
6945static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
6946 struct sigma_conn *conn,
6947 struct sigma_cmd *cmd,
6948 const char *ifname)
6949{
6950 char buf[200];
6951 char ip[16];
6952 int s;
Peng Xub3756882017-10-04 14:39:09 -07006953 struct ifreq ifr;
6954 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006955
6956 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07006957 if (s < 0) {
6958 perror("socket");
6959 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006960 }
6961
Peng Xub3756882017-10-04 14:39:09 -07006962 memset(&ifr, 0, sizeof(ifr));
6963 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
6964 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
6965 sigma_dut_print(dut, DUT_MSG_INFO,
6966 "Failed to get %s IP address: %s",
6967 ifname, strerror(errno));
6968 close(s);
6969 return -1;
6970 }
6971 close(s);
6972
6973 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
6974 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
6975
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006976 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
6977 ip);
6978 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6979 if (system(buf) != 0) {
6980 }
6981
6982 return 1;
6983}
6984
6985
6986static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
6987 struct sigma_conn *conn,
6988 struct sigma_cmd *cmd,
6989 const char *ifname)
6990{
6991 char buf[200], addr[20];
6992 char dst[ETH_ALEN], src[ETH_ALEN];
6993 short ethtype = htons(ETH_P_ARP);
6994 char *pos;
6995 int s, res;
6996 const char *val;
6997 struct sockaddr_in taddr;
6998
6999 val = get_param(cmd, "dest");
7000 if (val)
7001 hwaddr_aton(val, (unsigned char *) dst);
7002
7003 val = get_param(cmd, "DestIP");
7004 if (val)
7005 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007006 else
7007 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007008
7009 if (get_wpa_status(get_station_ifname(), "address", addr,
7010 sizeof(addr)) < 0)
7011 return -2;
7012 hwaddr_aton(addr, (unsigned char *) src);
7013
7014 pos = buf;
7015 *pos++ = 0x00;
7016 *pos++ = 0x01;
7017 *pos++ = 0x08;
7018 *pos++ = 0x00;
7019 *pos++ = 0x06;
7020 *pos++ = 0x04;
7021 *pos++ = 0x00;
7022 *pos++ = 0x02;
7023 memcpy(pos, src, ETH_ALEN);
7024 pos += ETH_ALEN;
7025 memcpy(pos, &taddr.sin_addr, 4);
7026 pos += 4;
7027 memcpy(pos, dst, ETH_ALEN);
7028 pos += ETH_ALEN;
7029 memcpy(pos, &taddr.sin_addr, 4);
7030 pos += 4;
7031
7032 s = open_monitor(get_station_ifname());
7033 if (s < 0) {
7034 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7035 "monitor socket");
7036 return 0;
7037 }
7038
7039 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7040 if (res < 0) {
7041 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7042 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307043 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007044 return 0;
7045 }
7046
7047 close(s);
7048
7049 return 1;
7050}
7051
7052
7053static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7054 struct sigma_conn *conn,
7055 struct sigma_cmd *cmd,
7056 const char *intf, const char *dest)
7057{
7058 char buf[100];
7059
7060 if (if_nametoindex("sigmadut") == 0) {
7061 snprintf(buf, sizeof(buf),
7062 "iw dev %s interface add sigmadut type monitor",
7063 get_station_ifname());
7064 if (system(buf) != 0 ||
7065 if_nametoindex("sigmadut") == 0) {
7066 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7067 "monitor interface with '%s'", buf);
7068 return -2;
7069 }
7070 }
7071
7072 if (system("ifconfig sigmadut up") != 0) {
7073 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7074 "monitor interface up");
7075 return -2;
7076 }
7077
7078 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7079}
7080
7081
7082static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7083 struct sigma_conn *conn,
7084 struct sigma_cmd *cmd)
7085{
7086 const char *intf = get_param(cmd, "Interface");
7087 const char *dest = get_param(cmd, "Dest");
7088 const char *type = get_param(cmd, "FrameName");
7089 const char *val;
7090 char buf[200], *pos, *end;
7091 int count, count2;
7092
7093 if (type == NULL)
7094 type = get_param(cmd, "Type");
7095
7096 if (intf == NULL || dest == NULL || type == NULL)
7097 return -1;
7098
7099 if (strcasecmp(type, "NeighAdv") == 0)
7100 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7101
7102 if (strcasecmp(type, "NeighSolicitReq") == 0)
7103 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7104
7105 if (strcasecmp(type, "ARPProbe") == 0)
7106 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7107
7108 if (strcasecmp(type, "ARPAnnounce") == 0)
7109 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7110
7111 if (strcasecmp(type, "ARPReply") == 0)
7112 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7113
7114 if (strcasecmp(type, "DLS-request") == 0 ||
7115 strcasecmp(type, "DLSrequest") == 0)
7116 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7117 dest);
7118
7119 if (strcasecmp(type, "ANQPQuery") != 0 &&
7120 strcasecmp(type, "Query") != 0) {
7121 send_resp(dut, conn, SIGMA_ERROR,
7122 "ErrorCode,Unsupported HS 2.0 send frame type");
7123 return 0;
7124 }
7125
7126 if (sta_scan_ap(dut, intf, dest) < 0) {
7127 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7128 "the requested AP");
7129 return 0;
7130 }
7131
7132 pos = buf;
7133 end = buf + sizeof(buf);
7134 count = 0;
7135 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7136
7137 val = get_param(cmd, "ANQP_CAP_LIST");
7138 if (val && atoi(val)) {
7139 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7140 count++;
7141 }
7142
7143 val = get_param(cmd, "VENUE_NAME");
7144 if (val && atoi(val)) {
7145 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7146 count++;
7147 }
7148
7149 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7150 if (val && atoi(val)) {
7151 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7152 count++;
7153 }
7154
7155 val = get_param(cmd, "ROAMING_CONS");
7156 if (val && atoi(val)) {
7157 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7158 count++;
7159 }
7160
7161 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7162 if (val && atoi(val)) {
7163 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7164 count++;
7165 }
7166
7167 val = get_param(cmd, "NAI_REALM_LIST");
7168 if (val && atoi(val)) {
7169 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7170 count++;
7171 }
7172
7173 val = get_param(cmd, "3GPP_INFO");
7174 if (val && atoi(val)) {
7175 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7176 count++;
7177 }
7178
7179 val = get_param(cmd, "DOMAIN_LIST");
7180 if (val && atoi(val)) {
7181 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7182 count++;
7183 }
7184
7185 if (count && wpa_command(intf, buf)) {
7186 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7187 return 0;
7188 }
7189
7190 pos = buf;
7191 end = buf + sizeof(buf);
7192 count2 = 0;
7193 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7194
7195 val = get_param(cmd, "HS_CAP_LIST");
7196 if (val && atoi(val)) {
7197 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7198 count2++;
7199 }
7200
7201 val = get_param(cmd, "OPER_NAME");
7202 if (val && atoi(val)) {
7203 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7204 count2++;
7205 }
7206
7207 val = get_param(cmd, "WAN_METRICS");
7208 if (!val)
7209 val = get_param(cmd, "WAN_MAT");
7210 if (!val)
7211 val = get_param(cmd, "WAN_MET");
7212 if (val && atoi(val)) {
7213 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7214 count2++;
7215 }
7216
7217 val = get_param(cmd, "CONNECTION_CAPABILITY");
7218 if (val && atoi(val)) {
7219 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7220 count2++;
7221 }
7222
7223 val = get_param(cmd, "OP_CLASS");
7224 if (val && atoi(val)) {
7225 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7226 count2++;
7227 }
7228
7229 val = get_param(cmd, "OSU_PROVIDER_LIST");
7230 if (val && atoi(val)) {
7231 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7232 count2++;
7233 }
7234
7235 if (count && count2) {
7236 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7237 "second query");
7238 sleep(1);
7239 }
7240
7241 if (count2 && wpa_command(intf, buf)) {
7242 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7243 "failed");
7244 return 0;
7245 }
7246
7247 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7248 if (val) {
7249 if (count || count2) {
7250 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7251 "sending out second query");
7252 sleep(1);
7253 }
7254
7255 if (strcmp(val, "1") == 0)
7256 val = "mail.example.com";
7257 snprintf(buf, end - pos,
7258 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7259 dest, val);
7260 if (wpa_command(intf, buf)) {
7261 send_resp(dut, conn, SIGMA_ERROR,
7262 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7263 "failed");
7264 return 0;
7265 }
7266 }
7267
7268 val = get_param(cmd, "ICON_REQUEST");
7269 if (val) {
7270 if (count || count2) {
7271 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7272 "sending out second query");
7273 sleep(1);
7274 }
7275
7276 snprintf(buf, end - pos,
7277 "HS20_ICON_REQUEST %s %s", dest, val);
7278 if (wpa_command(intf, buf)) {
7279 send_resp(dut, conn, SIGMA_ERROR,
7280 "ErrorCode,HS20_ICON_REQUEST failed");
7281 return 0;
7282 }
7283 }
7284
7285 return 1;
7286}
7287
7288
7289static int ath_sta_send_frame_vht(struct sigma_dut *dut,
7290 struct sigma_conn *conn,
7291 struct sigma_cmd *cmd)
7292{
7293 const char *val;
7294 char *ifname;
7295 char buf[100];
7296 int chwidth, nss;
7297
7298 val = get_param(cmd, "framename");
7299 if (!val)
7300 return -1;
7301 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
7302
7303 /* Command sequence to generate Op mode notification */
7304 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
7305 ifname = get_station_ifname();
7306
7307 /* Disable STBC */
7308 snprintf(buf, sizeof(buf),
7309 "iwpriv %s tx_stbc 0", ifname);
7310 if (system(buf) != 0) {
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "iwpriv tx_stbc 0 failed!");
7313 }
7314
7315 /* Extract Channel width */
7316 val = get_param(cmd, "Channel_width");
7317 if (val) {
7318 switch (atoi(val)) {
7319 case 20:
7320 chwidth = 0;
7321 break;
7322 case 40:
7323 chwidth = 1;
7324 break;
7325 case 80:
7326 chwidth = 2;
7327 break;
7328 case 160:
7329 chwidth = 3;
7330 break;
7331 default:
7332 chwidth = 2;
7333 break;
7334 }
7335
7336 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7337 ifname, chwidth);
7338 if (system(buf) != 0) {
7339 sigma_dut_print(dut, DUT_MSG_ERROR,
7340 "iwpriv chwidth failed!");
7341 }
7342 }
7343
7344 /* Extract NSS */
7345 val = get_param(cmd, "NSS");
7346 if (val) {
7347 switch (atoi(val)) {
7348 case 1:
7349 nss = 1;
7350 break;
7351 case 2:
7352 nss = 3;
7353 break;
7354 case 3:
7355 nss = 7;
7356 break;
7357 default:
7358 /* We do not support NSS > 3 */
7359 nss = 3;
7360 break;
7361 }
7362 snprintf(buf, sizeof(buf),
7363 "iwpriv %s rxchainmask %d", ifname, nss);
7364 if (system(buf) != 0) {
7365 sigma_dut_print(dut, DUT_MSG_ERROR,
7366 "iwpriv rxchainmask failed!");
7367 }
7368 }
7369
7370 /* Opmode notify */
7371 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
7372 if (system(buf) != 0) {
7373 sigma_dut_print(dut, DUT_MSG_ERROR,
7374 "iwpriv opmode_notify failed!");
7375 } else {
7376 sigma_dut_print(dut, DUT_MSG_INFO,
7377 "Sent out the notify frame!");
7378 }
7379 }
7380
7381 return 1;
7382}
7383
7384
7385static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
7386 struct sigma_conn *conn,
7387 struct sigma_cmd *cmd)
7388{
7389 switch (get_driver_type()) {
7390 case DRIVER_ATHEROS:
7391 return ath_sta_send_frame_vht(dut, conn, cmd);
7392 default:
7393 send_resp(dut, conn, SIGMA_ERROR,
7394 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
7395 return 0;
7396 }
7397}
7398
7399
Lior David0fe101e2017-03-09 16:09:50 +02007400#ifdef __linux__
7401int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7402 struct sigma_cmd *cmd)
7403{
7404 const char *frame_name = get_param(cmd, "framename");
7405 const char *mac = get_param(cmd, "dest_mac");
7406
7407 if (!frame_name || !mac) {
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "framename and dest_mac must be provided");
7410 return -1;
7411 }
7412
7413 if (strcasecmp(frame_name, "brp") == 0) {
7414 const char *l_rx = get_param(cmd, "L-RX");
7415 int l_rx_i;
7416
7417 if (!l_rx) {
7418 sigma_dut_print(dut, DUT_MSG_ERROR,
7419 "L-RX must be provided");
7420 return -1;
7421 }
7422 l_rx_i = atoi(l_rx);
7423
7424 sigma_dut_print(dut, DUT_MSG_INFO,
7425 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
7426 mac, l_rx);
7427 if (l_rx_i != 16) {
7428 sigma_dut_print(dut, DUT_MSG_ERROR,
7429 "unsupported L-RX: %s", l_rx);
7430 return -1;
7431 }
7432
7433 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
7434 return -1;
7435 } else if (strcasecmp(frame_name, "ssw") == 0) {
7436 sigma_dut_print(dut, DUT_MSG_INFO,
7437 "dev_send_frame: SLS, dest_mac %s", mac);
7438 if (wil6210_send_sls(dut, mac))
7439 return -1;
7440 } else {
7441 sigma_dut_print(dut, DUT_MSG_ERROR,
7442 "unsupported frame type: %s", frame_name);
7443 return -1;
7444 }
7445
7446 return 1;
7447}
7448#endif /* __linux__ */
7449
7450
7451static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
7452 struct sigma_conn *conn,
7453 struct sigma_cmd *cmd)
7454{
7455 switch (get_driver_type()) {
7456#ifdef __linux__
7457 case DRIVER_WIL6210:
7458 return wil6210_send_frame_60g(dut, conn, cmd);
7459#endif /* __linux__ */
7460 default:
7461 send_resp(dut, conn, SIGMA_ERROR,
7462 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7463 return 0;
7464 }
7465}
7466
7467
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307468static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
7469 const char *intf, struct sigma_cmd *cmd)
7470{
7471 const char *val, *addr;
7472 char buf[100];
7473
7474 addr = get_param(cmd, "DestMac");
7475 if (!addr) {
7476 send_resp(dut, conn, SIGMA_INVALID,
7477 "ErrorCode,AP MAC address is missing");
7478 return 0;
7479 }
7480
7481 val = get_param(cmd, "ANQPQuery_ID");
7482 if (!val) {
7483 send_resp(dut, conn, SIGMA_INVALID,
7484 "ErrorCode,Missing ANQPQuery_ID");
7485 return 0;
7486 }
7487
7488 if (strcasecmp(val, "NeighborReportReq") == 0) {
7489 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
7490 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
7491 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
7492 } else {
7493 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
7494 val);
7495 send_resp(dut, conn, SIGMA_INVALID,
7496 "ErrorCode,Invalid ANQPQuery_ID");
7497 return 0;
7498 }
7499
Ashwini Patild174f2c2017-04-13 16:49:46 +05307500 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
7501 * (Address3 = Wildcard BSSID when sent to not-associated AP;
7502 * if associated, AP BSSID).
7503 */
7504 if (wpa_command(intf, "SET gas_address3 1") < 0) {
7505 send_resp(dut, conn, SIGMA_ERROR,
7506 "ErrorCode,Failed to set gas_address3");
7507 return 0;
7508 }
7509
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307510 if (wpa_command(intf, buf) < 0) {
7511 send_resp(dut, conn, SIGMA_ERROR,
7512 "ErrorCode,Failed to send ANQP query");
7513 return 0;
7514 }
7515
7516 return 1;
7517}
7518
7519
7520static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
7521 struct sigma_conn *conn,
7522 const char *intf,
7523 struct sigma_cmd *cmd)
7524{
7525 const char *val = get_param(cmd, "FrameName");
7526
7527 if (val && strcasecmp(val, "ANQPQuery") == 0)
7528 return mbo_send_anqp_query(dut, conn, intf, cmd);
7529
7530 return 2;
7531}
7532
7533
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007534int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7535 struct sigma_cmd *cmd)
7536{
7537 const char *intf = get_param(cmd, "Interface");
7538 const char *val;
7539 enum send_frame_type frame;
7540 enum send_frame_protection protected;
7541 char buf[100];
7542 unsigned char addr[ETH_ALEN];
7543 int res;
7544
7545 val = get_param(cmd, "program");
7546 if (val == NULL)
7547 val = get_param(cmd, "frame");
7548 if (val && strcasecmp(val, "TDLS") == 0)
7549 return cmd_sta_send_frame_tdls(dut, conn, cmd);
7550 if (val && (strcasecmp(val, "HS2") == 0 ||
7551 strcasecmp(val, "HS2-R2") == 0))
7552 return cmd_sta_send_frame_hs2(dut, conn, cmd);
7553 if (val && strcasecmp(val, "VHT") == 0)
7554 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007555 if (val && strcasecmp(val, "LOC") == 0)
7556 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007557 if (val && strcasecmp(val, "60GHz") == 0)
7558 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307559 if (val && strcasecmp(val, "MBO") == 0) {
7560 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
7561 if (res != 2)
7562 return res;
7563 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007564
7565 val = get_param(cmd, "TD_DISC");
7566 if (val) {
7567 if (hwaddr_aton(val, addr) < 0)
7568 return -1;
7569 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
7570 if (wpa_command(intf, buf) < 0) {
7571 send_resp(dut, conn, SIGMA_ERROR,
7572 "ErrorCode,Failed to send TDLS discovery");
7573 return 0;
7574 }
7575 return 1;
7576 }
7577
7578 val = get_param(cmd, "TD_Setup");
7579 if (val) {
7580 if (hwaddr_aton(val, addr) < 0)
7581 return -1;
7582 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
7583 if (wpa_command(intf, buf) < 0) {
7584 send_resp(dut, conn, SIGMA_ERROR,
7585 "ErrorCode,Failed to start TDLS setup");
7586 return 0;
7587 }
7588 return 1;
7589 }
7590
7591 val = get_param(cmd, "TD_TearDown");
7592 if (val) {
7593 if (hwaddr_aton(val, addr) < 0)
7594 return -1;
7595 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
7596 if (wpa_command(intf, buf) < 0) {
7597 send_resp(dut, conn, SIGMA_ERROR,
7598 "ErrorCode,Failed to tear down TDLS link");
7599 return 0;
7600 }
7601 return 1;
7602 }
7603
7604 val = get_param(cmd, "TD_ChannelSwitch");
7605 if (val) {
7606 /* TODO */
7607 send_resp(dut, conn, SIGMA_ERROR,
7608 "ErrorCode,TD_ChannelSwitch not yet supported");
7609 return 0;
7610 }
7611
7612 val = get_param(cmd, "TD_NF");
7613 if (val) {
7614 /* TODO */
7615 send_resp(dut, conn, SIGMA_ERROR,
7616 "ErrorCode,TD_NF not yet supported");
7617 return 0;
7618 }
7619
7620 val = get_param(cmd, "PMFFrameType");
7621 if (val == NULL)
7622 val = get_param(cmd, "FrameName");
7623 if (val == NULL)
7624 val = get_param(cmd, "Type");
7625 if (val == NULL)
7626 return -1;
7627 if (strcasecmp(val, "disassoc") == 0)
7628 frame = DISASSOC;
7629 else if (strcasecmp(val, "deauth") == 0)
7630 frame = DEAUTH;
7631 else if (strcasecmp(val, "saquery") == 0)
7632 frame = SAQUERY;
7633 else if (strcasecmp(val, "auth") == 0)
7634 frame = AUTH;
7635 else if (strcasecmp(val, "assocreq") == 0)
7636 frame = ASSOCREQ;
7637 else if (strcasecmp(val, "reassocreq") == 0)
7638 frame = REASSOCREQ;
7639 else if (strcasecmp(val, "neigreq") == 0) {
7640 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
7641
7642 val = get_param(cmd, "ssid");
7643 if (val == NULL)
7644 return -1;
7645
7646 res = send_neighbor_request(dut, intf, val);
7647 if (res) {
7648 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7649 "Failed to send neighbor report request");
7650 return 0;
7651 }
7652
7653 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307654 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
7655 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007656 sigma_dut_print(dut, DUT_MSG_DEBUG,
7657 "Got Transition Management Query");
7658
Ashwini Patil5acd7382017-04-13 15:55:04 +05307659 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007660 if (res) {
7661 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7662 "Failed to send Transition Management Query");
7663 return 0;
7664 }
7665
7666 return 1;
7667 } else {
7668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7669 "PMFFrameType");
7670 return 0;
7671 }
7672
7673 val = get_param(cmd, "PMFProtected");
7674 if (val == NULL)
7675 val = get_param(cmd, "Protected");
7676 if (val == NULL)
7677 return -1;
7678 if (strcasecmp(val, "Correct-key") == 0 ||
7679 strcasecmp(val, "CorrectKey") == 0)
7680 protected = CORRECT_KEY;
7681 else if (strcasecmp(val, "IncorrectKey") == 0)
7682 protected = INCORRECT_KEY;
7683 else if (strcasecmp(val, "Unprotected") == 0)
7684 protected = UNPROTECTED;
7685 else {
7686 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7687 "PMFProtected");
7688 return 0;
7689 }
7690
7691 if (protected != UNPROTECTED &&
7692 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
7693 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
7694 "PMFProtected for auth/assocreq/reassocreq");
7695 return 0;
7696 }
7697
7698 if (if_nametoindex("sigmadut") == 0) {
7699 snprintf(buf, sizeof(buf),
7700 "iw dev %s interface add sigmadut type monitor",
7701 get_station_ifname());
7702 if (system(buf) != 0 ||
7703 if_nametoindex("sigmadut") == 0) {
7704 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7705 "monitor interface with '%s'", buf);
7706 return -2;
7707 }
7708 }
7709
7710 if (system("ifconfig sigmadut up") != 0) {
7711 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7712 "monitor interface up");
7713 return -2;
7714 }
7715
7716 return sta_inject_frame(dut, conn, frame, protected, NULL);
7717}
7718
7719
7720static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
7721 struct sigma_conn *conn,
7722 struct sigma_cmd *cmd,
7723 const char *ifname)
7724{
7725 char buf[200];
7726 const char *val;
7727
7728 val = get_param(cmd, "ClearARP");
7729 if (val && atoi(val) == 1) {
7730 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
7731 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7732 if (system(buf) != 0) {
7733 send_resp(dut, conn, SIGMA_ERROR,
7734 "errorCode,Failed to clear ARP cache");
7735 return 0;
7736 }
7737 }
7738
7739 return 1;
7740}
7741
7742
7743int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
7744 struct sigma_cmd *cmd)
7745{
7746 const char *intf = get_param(cmd, "Interface");
7747 const char *val;
7748
7749 if (intf == NULL)
7750 return -1;
7751
7752 val = get_param(cmd, "program");
7753 if (val && (strcasecmp(val, "HS2") == 0 ||
7754 strcasecmp(val, "HS2-R2") == 0))
7755 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
7756
7757 return -1;
7758}
7759
7760
7761static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
7762 struct sigma_cmd *cmd)
7763{
7764 const char *intf = get_param(cmd, "Interface");
7765 const char *mac = get_param(cmd, "MAC");
7766
7767 if (intf == NULL || mac == NULL)
7768 return -1;
7769
7770 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
7771 "interface %s to %s", intf, mac);
7772
7773 if (dut->set_macaddr) {
7774 char buf[128];
7775 int res;
7776 if (strcasecmp(mac, "default") == 0) {
7777 res = snprintf(buf, sizeof(buf), "%s",
7778 dut->set_macaddr);
7779 dut->tmp_mac_addr = 0;
7780 } else {
7781 res = snprintf(buf, sizeof(buf), "%s %s",
7782 dut->set_macaddr, mac);
7783 dut->tmp_mac_addr = 1;
7784 }
7785 if (res < 0 || res >= (int) sizeof(buf))
7786 return -1;
7787 if (system(buf) != 0) {
7788 send_resp(dut, conn, SIGMA_ERROR,
7789 "errorCode,Failed to set MAC "
7790 "address");
7791 return 0;
7792 }
7793 return 1;
7794 }
7795
7796 if (strcasecmp(mac, "default") == 0)
7797 return 1;
7798
7799 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7800 "command");
7801 return 0;
7802}
7803
7804
7805static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
7806 struct sigma_conn *conn, const char *intf,
7807 int val)
7808{
7809 char buf[200];
7810 int res;
7811
7812 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
7813 intf, val);
7814 if (res < 0 || res >= (int) sizeof(buf))
7815 return -1;
7816 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7817 if (system(buf) != 0) {
7818 send_resp(dut, conn, SIGMA_ERROR,
7819 "errorCode,Failed to configure offchannel mode");
7820 return 0;
7821 }
7822
7823 return 1;
7824}
7825
7826
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007827static int off_chan_val(enum sec_ch_offset off)
7828{
7829 switch (off) {
7830 case SEC_CH_NO:
7831 return 0;
7832 case SEC_CH_40ABOVE:
7833 return 40;
7834 case SEC_CH_40BELOW:
7835 return -40;
7836 }
7837
7838 return 0;
7839}
7840
7841
7842static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
7843 const char *intf, int off_ch_num,
7844 enum sec_ch_offset sec)
7845{
7846 char buf[200];
7847 int res;
7848
7849 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
7850 intf, off_ch_num);
7851 if (res < 0 || res >= (int) sizeof(buf))
7852 return -1;
7853 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7854 if (system(buf) != 0) {
7855 send_resp(dut, conn, SIGMA_ERROR,
7856 "errorCode,Failed to set offchan");
7857 return 0;
7858 }
7859
7860 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
7861 intf, off_chan_val(sec));
7862 if (res < 0 || res >= (int) sizeof(buf))
7863 return -1;
7864 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7865 if (system(buf) != 0) {
7866 send_resp(dut, conn, SIGMA_ERROR,
7867 "errorCode,Failed to set sec chan offset");
7868 return 0;
7869 }
7870
7871 return 1;
7872}
7873
7874
7875static int tdls_set_offchannel_offset(struct sigma_dut *dut,
7876 struct sigma_conn *conn,
7877 const char *intf, int off_ch_num,
7878 enum sec_ch_offset sec)
7879{
7880 char buf[200];
7881 int res;
7882
7883 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
7884 off_ch_num);
7885 if (res < 0 || res >= (int) sizeof(buf))
7886 return -1;
7887 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7888
7889 if (wpa_command(intf, buf) < 0) {
7890 send_resp(dut, conn, SIGMA_ERROR,
7891 "ErrorCode,Failed to set offchan");
7892 return 0;
7893 }
7894 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
7895 off_chan_val(sec));
7896 if (res < 0 || res >= (int) sizeof(buf))
7897 return -1;
7898
7899 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7900
7901 if (wpa_command(intf, buf) < 0) {
7902 send_resp(dut, conn, SIGMA_ERROR,
7903 "ErrorCode,Failed to set sec chan offset");
7904 return 0;
7905 }
7906
7907 return 1;
7908}
7909
7910
7911static int tdls_set_offchannel_mode(struct sigma_dut *dut,
7912 struct sigma_conn *conn,
7913 const char *intf, int val)
7914{
7915 char buf[200];
7916 int res;
7917
7918 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
7919 val);
7920 if (res < 0 || res >= (int) sizeof(buf))
7921 return -1;
7922 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7923
7924 if (wpa_command(intf, buf) < 0) {
7925 send_resp(dut, conn, SIGMA_ERROR,
7926 "ErrorCode,Failed to configure offchannel mode");
7927 return 0;
7928 }
7929
7930 return 1;
7931}
7932
7933
7934static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
7935 struct sigma_conn *conn,
7936 struct sigma_cmd *cmd)
7937{
7938 const char *val;
7939 enum {
7940 CHSM_NOT_SET,
7941 CHSM_ENABLE,
7942 CHSM_DISABLE,
7943 CHSM_REJREQ,
7944 CHSM_UNSOLRESP
7945 } chsm = CHSM_NOT_SET;
7946 int off_ch_num = -1;
7947 enum sec_ch_offset sec_ch = SEC_CH_NO;
7948 int res;
7949
7950 val = get_param(cmd, "Uapsd");
7951 if (val) {
7952 char buf[100];
7953 if (strcasecmp(val, "Enable") == 0)
7954 snprintf(buf, sizeof(buf), "SET ps 99");
7955 else if (strcasecmp(val, "Disable") == 0)
7956 snprintf(buf, sizeof(buf), "SET ps 98");
7957 else {
7958 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7959 "Unsupported uapsd parameter value");
7960 return 0;
7961 }
7962 if (wpa_command(intf, buf)) {
7963 send_resp(dut, conn, SIGMA_ERROR,
7964 "ErrorCode,Failed to change U-APSD "
7965 "powersave mode");
7966 return 0;
7967 }
7968 }
7969
7970 val = get_param(cmd, "TPKTIMER");
7971 if (val && strcasecmp(val, "DISABLE") == 0) {
7972 if (wpa_command(intf, "SET tdls_testing 0x100")) {
7973 send_resp(dut, conn, SIGMA_ERROR,
7974 "ErrorCode,Failed to enable no TPK "
7975 "expiration test mode");
7976 return 0;
7977 }
7978 dut->no_tpk_expiration = 1;
7979 }
7980
7981 val = get_param(cmd, "ChSwitchMode");
7982 if (val) {
7983 if (strcasecmp(val, "Enable") == 0 ||
7984 strcasecmp(val, "Initiate") == 0)
7985 chsm = CHSM_ENABLE;
7986 else if (strcasecmp(val, "Disable") == 0 ||
7987 strcasecmp(val, "passive") == 0)
7988 chsm = CHSM_DISABLE;
7989 else if (strcasecmp(val, "RejReq") == 0)
7990 chsm = CHSM_REJREQ;
7991 else if (strcasecmp(val, "UnSolResp") == 0)
7992 chsm = CHSM_UNSOLRESP;
7993 else {
7994 send_resp(dut, conn, SIGMA_ERROR,
7995 "ErrorCode,Unknown ChSwitchMode value");
7996 return 0;
7997 }
7998 }
7999
8000 val = get_param(cmd, "OffChNum");
8001 if (val) {
8002 off_ch_num = atoi(val);
8003 if (off_ch_num == 0) {
8004 send_resp(dut, conn, SIGMA_ERROR,
8005 "ErrorCode,Invalid OffChNum");
8006 return 0;
8007 }
8008 }
8009
8010 val = get_param(cmd, "SecChOffset");
8011 if (val) {
8012 if (strcmp(val, "20") == 0)
8013 sec_ch = SEC_CH_NO;
8014 else if (strcasecmp(val, "40above") == 0)
8015 sec_ch = SEC_CH_40ABOVE;
8016 else if (strcasecmp(val, "40below") == 0)
8017 sec_ch = SEC_CH_40BELOW;
8018 else {
8019 send_resp(dut, conn, SIGMA_ERROR,
8020 "ErrorCode,Unknown SecChOffset value");
8021 return 0;
8022 }
8023 }
8024
8025 if (chsm == CHSM_NOT_SET) {
8026 /* no offchannel changes requested */
8027 return 1;
8028 }
8029
8030 if (strcmp(intf, get_main_ifname()) != 0 &&
8031 strcmp(intf, get_station_ifname()) != 0) {
8032 send_resp(dut, conn, SIGMA_ERROR,
8033 "ErrorCode,Unknown interface");
8034 return 0;
8035 }
8036
8037 switch (chsm) {
8038 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008039 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008040 break;
8041 case CHSM_ENABLE:
8042 if (off_ch_num < 0) {
8043 send_resp(dut, conn, SIGMA_ERROR,
8044 "ErrorCode,Missing OffChNum argument");
8045 return 0;
8046 }
8047 if (wifi_chip_type == DRIVER_WCN) {
8048 res = tdls_set_offchannel_offset(dut, conn, intf,
8049 off_ch_num, sec_ch);
8050 } else {
8051 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8052 sec_ch);
8053 }
8054 if (res != 1)
8055 return res;
8056 if (wifi_chip_type == DRIVER_WCN)
8057 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8058 else
8059 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8060 break;
8061 case CHSM_DISABLE:
8062 if (wifi_chip_type == DRIVER_WCN)
8063 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8064 else
8065 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8066 break;
8067 case CHSM_REJREQ:
8068 if (wifi_chip_type == DRIVER_WCN)
8069 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8070 else
8071 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8072 break;
8073 case CHSM_UNSOLRESP:
8074 if (off_ch_num < 0) {
8075 send_resp(dut, conn, SIGMA_ERROR,
8076 "ErrorCode,Missing OffChNum argument");
8077 return 0;
8078 }
8079 if (wifi_chip_type == DRIVER_WCN) {
8080 res = tdls_set_offchannel_offset(dut, conn, intf,
8081 off_ch_num, sec_ch);
8082 } else {
8083 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8084 sec_ch);
8085 }
8086 if (res != 1)
8087 return res;
8088 if (wifi_chip_type == DRIVER_WCN)
8089 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8090 else
8091 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8092 break;
8093 }
8094
8095 return res;
8096}
8097
8098
8099static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8100 struct sigma_conn *conn,
8101 struct sigma_cmd *cmd)
8102{
8103 const char *val;
8104 char *token, *result;
8105
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008106 novap_reset(dut, intf);
8107
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008108 val = get_param(cmd, "nss_mcs_opt");
8109 if (val) {
8110 /* String (nss_operating_mode; mcs_operating_mode) */
8111 int nss, mcs;
8112 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308113 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008114
8115 token = strdup(val);
8116 if (!token)
8117 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308118 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308119 if (!result) {
8120 sigma_dut_print(dut, DUT_MSG_ERROR,
8121 "VHT NSS not specified");
8122 goto failed;
8123 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008124 if (strcasecmp(result, "def") != 0) {
8125 nss = atoi(result);
8126 if (nss == 4)
8127 ath_disable_txbf(dut, intf);
8128 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8129 intf, nss);
8130 if (system(buf) != 0) {
8131 sigma_dut_print(dut, DUT_MSG_ERROR,
8132 "iwpriv nss failed");
8133 goto failed;
8134 }
8135 }
8136
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308137 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308138 if (!result) {
8139 sigma_dut_print(dut, DUT_MSG_ERROR,
8140 "VHT MCS not specified");
8141 goto failed;
8142 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008143 if (strcasecmp(result, "def") == 0) {
8144 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8145 intf);
8146 if (system(buf) != 0) {
8147 sigma_dut_print(dut, DUT_MSG_ERROR,
8148 "iwpriv set11NRates failed");
8149 goto failed;
8150 }
8151
8152 } else {
8153 mcs = atoi(result);
8154 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8155 intf, mcs);
8156 if (system(buf) != 0) {
8157 sigma_dut_print(dut, DUT_MSG_ERROR,
8158 "iwpriv vhtmcs failed");
8159 goto failed;
8160 }
8161 }
8162 /* Channel width gets messed up, fix this */
8163 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8164 intf, dut->chwidth);
8165 if (system(buf) != 0) {
8166 sigma_dut_print(dut, DUT_MSG_ERROR,
8167 "iwpriv chwidth failed");
8168 }
8169 }
8170
8171 return 1;
8172failed:
8173 free(token);
8174 return 0;
8175}
8176
8177
8178static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8179 struct sigma_conn *conn,
8180 struct sigma_cmd *cmd)
8181{
8182 switch (get_driver_type()) {
8183 case DRIVER_ATHEROS:
8184 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8185 default:
8186 send_resp(dut, conn, SIGMA_ERROR,
8187 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8188 return 0;
8189 }
8190}
8191
8192
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008193static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8194 struct sigma_conn *conn,
8195 struct sigma_cmd *cmd)
8196{
8197 const char *val;
8198 char *token = NULL, *result;
8199 char buf[60];
8200
8201 val = get_param(cmd, "nss_mcs_opt");
8202 if (val) {
8203 /* String (nss_operating_mode; mcs_operating_mode) */
8204 int nss, mcs, ratecode;
8205 char *saveptr;
8206
8207 token = strdup(val);
8208 if (!token)
8209 return -2;
8210
8211 result = strtok_r(token, ";", &saveptr);
8212 if (!result) {
8213 sigma_dut_print(dut, DUT_MSG_ERROR,
8214 "HE NSS not specified");
8215 goto failed;
8216 }
8217 nss = 1;
8218 if (strcasecmp(result, "def") != 0)
8219 nss = atoi(result);
8220
8221 result = strtok_r(NULL, ";", &saveptr);
8222 if (!result) {
8223 sigma_dut_print(dut, DUT_MSG_ERROR,
8224 "HE MCS not specified");
8225 goto failed;
8226 }
8227 mcs = 7;
8228 if (strcasecmp(result, "def") != 0)
8229 mcs = atoi(result);
8230
8231 ratecode = 0x400; /* for nss:1 MCS 0 */
8232 if (nss == 2) {
8233 ratecode = 0x420; /* for nss:2 MCS 0 */
8234 } else if (nss > 2) {
8235 sigma_dut_print(dut, DUT_MSG_ERROR,
8236 "HE NSS %d not supported", nss);
8237 goto failed;
8238 }
8239
8240 /* Add the MCS to the ratecode */
8241 if (mcs >= 0 && mcs <= 11) {
8242 ratecode += mcs;
8243 } else {
8244 sigma_dut_print(dut, DUT_MSG_ERROR,
8245 "HE MCS %d not supported", mcs);
8246 goto failed;
8247 }
8248 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8249 intf, ratecode);
8250 if (system(buf) != 0) {
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "iwpriv setting of 11ax rates failed");
8253 goto failed;
8254 }
8255 free(token);
8256 }
8257
8258 val = get_param(cmd, "GI");
8259 if (val) {
8260 if (strcmp(val, "0.8") == 0) {
8261 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8262 } else if (strcmp(val, "1.6") == 0) {
8263 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8264 } else if (strcmp(val, "3.2") == 0) {
8265 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8266 } else {
8267 send_resp(dut, conn, SIGMA_ERROR,
8268 "errorCode,GI value not supported");
8269 return 0;
8270 }
8271 if (system(buf) != 0) {
8272 send_resp(dut, conn, SIGMA_ERROR,
8273 "errorCode,Failed to set shortgi");
8274 return 0;
8275 }
8276 }
8277
8278 return 1;
8279
8280failed:
8281 free(token);
8282 return -2;
8283}
8284
8285
8286static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8287 struct sigma_conn *conn,
8288 struct sigma_cmd *cmd)
8289{
8290 switch (get_driver_type()) {
8291 case DRIVER_WCN:
8292 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
8293 default:
8294 send_resp(dut, conn, SIGMA_ERROR,
8295 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
8296 return 0;
8297 }
8298}
8299
8300
Ashwini Patil5acd7382017-04-13 15:55:04 +05308301static int btm_query_candidate_list(struct sigma_dut *dut,
8302 struct sigma_conn *conn,
8303 struct sigma_cmd *cmd)
8304{
8305 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
8306 int len, ret;
8307 char buf[10];
8308
8309 /*
8310 * Neighbor Report elements format:
8311 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
8312 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
8313 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
8314 */
8315
8316 bssid = get_param(cmd, "Nebor_BSSID");
8317 if (!bssid) {
8318 send_resp(dut, conn, SIGMA_INVALID,
8319 "errorCode,Nebor_BSSID is missing");
8320 return 0;
8321 }
8322
8323 info = get_param(cmd, "Nebor_Bssid_Info");
8324 if (!info) {
8325 sigma_dut_print(dut, DUT_MSG_INFO,
8326 "Using default value for Nebor_Bssid_Info: %s",
8327 DEFAULT_NEIGHBOR_BSSID_INFO);
8328 info = DEFAULT_NEIGHBOR_BSSID_INFO;
8329 }
8330
8331 op_class = get_param(cmd, "Nebor_Op_Class");
8332 if (!op_class) {
8333 send_resp(dut, conn, SIGMA_INVALID,
8334 "errorCode,Nebor_Op_Class is missing");
8335 return 0;
8336 }
8337
8338 ch = get_param(cmd, "Nebor_Op_Ch");
8339 if (!ch) {
8340 send_resp(dut, conn, SIGMA_INVALID,
8341 "errorCode,Nebor_Op_Ch is missing");
8342 return 0;
8343 }
8344
8345 phy_type = get_param(cmd, "Nebor_Phy_Type");
8346 if (!phy_type) {
8347 sigma_dut_print(dut, DUT_MSG_INFO,
8348 "Using default value for Nebor_Phy_Type: %s",
8349 DEFAULT_NEIGHBOR_PHY_TYPE);
8350 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
8351 }
8352
8353 /* Parse optional subelements */
8354 buf[0] = '\0';
8355 pref = get_param(cmd, "Nebor_Pref");
8356 if (pref) {
8357 /* hexdump for preferrence subelement */
8358 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
8359 if (ret < 0 || ret >= (int) sizeof(buf)) {
8360 sigma_dut_print(dut, DUT_MSG_ERROR,
8361 "snprintf failed for optional subelement ret: %d",
8362 ret);
8363 send_resp(dut, conn, SIGMA_ERROR,
8364 "errorCode,snprintf failed for subelement");
8365 return 0;
8366 }
8367 }
8368
8369 if (!dut->btm_query_cand_list) {
8370 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
8371 if (!dut->btm_query_cand_list) {
8372 send_resp(dut, conn, SIGMA_ERROR,
8373 "errorCode,Failed to allocate memory for btm_query_cand_list");
8374 return 0;
8375 }
8376 }
8377
8378 len = strlen(dut->btm_query_cand_list);
8379 ret = snprintf(dut->btm_query_cand_list + len,
8380 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
8381 bssid, info, op_class, ch, phy_type, buf);
8382 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
8383 sigma_dut_print(dut, DUT_MSG_ERROR,
8384 "snprintf failed for neighbor report list ret: %d",
8385 ret);
8386 send_resp(dut, conn, SIGMA_ERROR,
8387 "errorCode,snprintf failed for neighbor report");
8388 free(dut->btm_query_cand_list);
8389 dut->btm_query_cand_list = NULL;
8390 return 0;
8391 }
8392
8393 return 1;
8394}
8395
8396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008397static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8398 struct sigma_cmd *cmd)
8399{
8400 const char *intf = get_param(cmd, "Interface");
8401 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308402 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008403
8404 if (intf == NULL || prog == NULL)
8405 return -1;
8406
Ashwini Patil5acd7382017-04-13 15:55:04 +05308407 /* BSS Transition candidate list for BTM query */
8408 val = get_param(cmd, "Nebor_BSSID");
8409 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
8410 return 0;
8411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008412 if (strcasecmp(prog, "TDLS") == 0)
8413 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
8414
8415 if (strcasecmp(prog, "VHT") == 0)
8416 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
8417
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008418 if (strcasecmp(prog, "HE") == 0)
8419 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
8420
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308421 if (strcasecmp(prog, "MBO") == 0) {
8422 val = get_param(cmd, "Cellular_Data_Cap");
8423 if (val &&
8424 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
8425 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05308426
8427 val = get_param(cmd, "Ch_Pref");
8428 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
8429 return 0;
8430
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308431 return 1;
8432 }
8433
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008434 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
8435 return 0;
8436}
8437
8438
8439static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
8440 struct sigma_cmd *cmd)
8441{
8442 const char *intf = get_param(cmd, "Interface");
8443 const char *mode = get_param(cmd, "Mode");
8444 int res;
8445
8446 if (intf == NULL || mode == NULL)
8447 return -1;
8448
8449 if (strcasecmp(mode, "On") == 0)
8450 res = wpa_command(intf, "SET radio_disabled 0");
8451 else if (strcasecmp(mode, "Off") == 0)
8452 res = wpa_command(intf, "SET radio_disabled 1");
8453 else
8454 return -1;
8455
8456 if (res) {
8457 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8458 "radio mode");
8459 return 0;
8460 }
8461
8462 return 1;
8463}
8464
8465
8466static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
8467 struct sigma_cmd *cmd)
8468{
8469 const char *intf = get_param(cmd, "Interface");
8470 const char *mode = get_param(cmd, "Mode");
8471 int res;
8472
8473 if (intf == NULL || mode == NULL)
8474 return -1;
8475
8476 if (strcasecmp(mode, "On") == 0)
8477 res = set_ps(intf, dut, 1);
8478 else if (strcasecmp(mode, "Off") == 0)
8479 res = set_ps(intf, dut, 0);
8480 else
8481 return -1;
8482
8483 if (res) {
8484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8485 "power save mode");
8486 return 0;
8487 }
8488
8489 return 1;
8490}
8491
8492
8493static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
8494 struct sigma_cmd *cmd)
8495{
8496 const char *intf = get_param(cmd, "Interface");
8497 const char *val, *bssid;
8498 int res;
8499 char *buf;
8500 size_t buf_len;
8501
8502 val = get_param(cmd, "BSSID_FILTER");
8503 if (val == NULL)
8504 return -1;
8505
8506 bssid = get_param(cmd, "BSSID_List");
8507 if (atoi(val) == 0 || bssid == NULL) {
8508 /* Disable BSSID filter */
8509 if (wpa_command(intf, "SET bssid_filter ")) {
8510 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
8511 "to disable BSSID filter");
8512 return 0;
8513 }
8514
8515 return 1;
8516 }
8517
8518 buf_len = 100 + strlen(bssid);
8519 buf = malloc(buf_len);
8520 if (buf == NULL)
8521 return -1;
8522
8523 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
8524 res = wpa_command(intf, buf);
8525 free(buf);
8526 if (res) {
8527 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
8528 "BSSID filter");
8529 return 0;
8530 }
8531
8532 return 1;
8533}
8534
8535
8536static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
8537 struct sigma_cmd *cmd)
8538{
8539 const char *intf = get_param(cmd, "Interface");
8540 const char *val;
8541
8542 /* TODO: ARP */
8543
8544 val = get_param(cmd, "HS2_CACHE_PROFILE");
8545 if (val && strcasecmp(val, "All") == 0)
8546 hs2_clear_credentials(intf);
8547
8548 return 1;
8549}
8550
8551
8552static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
8553 struct sigma_cmd *cmd)
8554{
8555 const char *intf = get_param(cmd, "Interface");
8556 const char *key_type = get_param(cmd, "KeyType");
8557 char buf[100], resp[200];
8558
8559 if (key_type == NULL)
8560 return -1;
8561
8562 if (strcasecmp(key_type, "GTK") == 0) {
8563 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
8564 strncmp(buf, "FAIL", 4) == 0) {
8565 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8566 "not fetch current GTK");
8567 return 0;
8568 }
8569 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
8570 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8571 return 0;
8572 } else {
8573 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8574 "KeyType");
8575 return 0;
8576 }
8577
8578 return 1;
8579}
8580
8581
8582static int hs2_set_policy(struct sigma_dut *dut)
8583{
8584#ifdef ANDROID
8585 system("ip rule del prio 23000");
8586 if (system("ip rule add from all lookup main prio 23000") != 0) {
8587 sigma_dut_print(dut, DUT_MSG_ERROR,
8588 "Failed to run:ip rule add from all lookup main prio");
8589 return -1;
8590 }
8591 if (system("ip route flush cache") != 0) {
8592 sigma_dut_print(dut, DUT_MSG_ERROR,
8593 "Failed to run ip route flush cache");
8594 return -1;
8595 }
8596 return 1;
8597#else /* ANDROID */
8598 return 0;
8599#endif /* ANDROID */
8600}
8601
8602
8603static int cmd_sta_hs2_associate(struct sigma_dut *dut,
8604 struct sigma_conn *conn,
8605 struct sigma_cmd *cmd)
8606{
8607 const char *intf = get_param(cmd, "Interface");
8608 const char *val = get_param(cmd, "Ignore_blacklist");
8609 struct wpa_ctrl *ctrl;
8610 int res;
8611 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
8612 int tries = 0;
8613 int ignore_blacklist = 0;
8614 const char *events[] = {
8615 "CTRL-EVENT-CONNECTED",
8616 "INTERWORKING-BLACKLISTED",
8617 "INTERWORKING-NO-MATCH",
8618 NULL
8619 };
8620
8621 start_sta_mode(dut);
8622
8623 blacklisted[0] = '\0';
8624 if (val && atoi(val))
8625 ignore_blacklist = 1;
8626
8627try_again:
8628 ctrl = open_wpa_mon(intf);
8629 if (ctrl == NULL) {
8630 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8631 "wpa_supplicant monitor connection");
8632 return -2;
8633 }
8634
8635 tries++;
8636 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
8637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
8638 "Interworking connection");
8639 wpa_ctrl_detach(ctrl);
8640 wpa_ctrl_close(ctrl);
8641 return 0;
8642 }
8643
8644 buf[0] = '\0';
8645 while (1) {
8646 char *pos;
8647 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
8648 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
8649 if (!pos)
8650 break;
8651 pos += 25;
8652 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
8653 pos);
8654 if (!blacklisted[0])
8655 memcpy(blacklisted, pos, strlen(pos) + 1);
8656 }
8657
8658 if (ignore_blacklist && blacklisted[0]) {
8659 char *end;
8660 end = strchr(blacklisted, ' ');
8661 if (end)
8662 *end = '\0';
8663 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
8664 blacklisted);
8665 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
8666 blacklisted);
8667 if (wpa_command(intf, buf)) {
8668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
8669 wpa_ctrl_detach(ctrl);
8670 wpa_ctrl_close(ctrl);
8671 return 0;
8672 }
8673 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8674 buf, sizeof(buf));
8675 }
8676
8677 wpa_ctrl_detach(ctrl);
8678 wpa_ctrl_close(ctrl);
8679
8680 if (res < 0) {
8681 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8682 "connect");
8683 return 0;
8684 }
8685
8686 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
8687 strstr(buf, "INTERWORKING-BLACKLISTED")) {
8688 if (tries < 2) {
8689 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
8690 goto try_again;
8691 }
8692 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
8693 "matching credentials found");
8694 return 0;
8695 }
8696
8697 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8698 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8699 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8700 "get current BSSID/SSID");
8701 return 0;
8702 }
8703
8704 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
8705 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8706 hs2_set_policy(dut);
8707 return 0;
8708}
8709
8710
8711static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
8712 struct sigma_conn *conn,
8713 const char *ifname,
8714 struct sigma_cmd *cmd)
8715{
8716 const char *val;
8717 int id;
8718
8719 id = add_cred(ifname);
8720 if (id < 0)
8721 return -2;
8722 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8723
8724 val = get_param(cmd, "prefer");
8725 if (val && atoi(val) > 0)
8726 set_cred(ifname, id, "priority", "1");
8727
8728 val = get_param(cmd, "REALM");
8729 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
8730 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8731 "realm");
8732 return 0;
8733 }
8734
8735 val = get_param(cmd, "HOME_FQDN");
8736 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
8737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8738 "home_fqdn");
8739 return 0;
8740 }
8741
8742 val = get_param(cmd, "Username");
8743 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
8744 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8745 "username");
8746 return 0;
8747 }
8748
8749 val = get_param(cmd, "Password");
8750 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
8751 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8752 "password");
8753 return 0;
8754 }
8755
8756 val = get_param(cmd, "ROOT_CA");
8757 if (val) {
8758 char fname[200];
8759 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8760#ifdef __linux__
8761 if (!file_exists(fname)) {
8762 char msg[300];
8763 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
8764 "file (%s) not found", fname);
8765 send_resp(dut, conn, SIGMA_ERROR, msg);
8766 return 0;
8767 }
8768#endif /* __linux__ */
8769 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
8770 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8771 "not set root CA");
8772 return 0;
8773 }
8774 }
8775
8776 return 1;
8777}
8778
8779
8780static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
8781{
8782 FILE *in, *out;
8783 char buf[500];
8784 int found = 0;
8785
8786 in = fopen("devdetail.xml", "r");
8787 if (in == NULL)
8788 return -1;
8789 out = fopen("devdetail.xml.tmp", "w");
8790 if (out == NULL) {
8791 fclose(in);
8792 return -1;
8793 }
8794
8795 while (fgets(buf, sizeof(buf), in)) {
8796 char *pos = strstr(buf, "<IMSI>");
8797 if (pos) {
8798 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
8799 imsi);
8800 pos += 6;
8801 *pos = '\0';
8802 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
8803 found++;
8804 } else {
8805 fprintf(out, "%s", buf);
8806 }
8807 }
8808
8809 fclose(out);
8810 fclose(in);
8811 if (found)
8812 rename("devdetail.xml.tmp", "devdetail.xml");
8813 else
8814 unlink("devdetail.xml.tmp");
8815
8816 return 0;
8817}
8818
8819
8820static int sta_add_credential_sim(struct sigma_dut *dut,
8821 struct sigma_conn *conn,
8822 const char *ifname, struct sigma_cmd *cmd)
8823{
8824 const char *val, *imsi = NULL;
8825 int id;
8826 char buf[200];
8827 int res;
8828 const char *pos;
8829 size_t mnc_len;
8830 char plmn_mcc[4];
8831 char plmn_mnc[4];
8832
8833 id = add_cred(ifname);
8834 if (id < 0)
8835 return -2;
8836 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8837
8838 val = get_param(cmd, "prefer");
8839 if (val && atoi(val) > 0)
8840 set_cred(ifname, id, "priority", "1");
8841
8842 val = get_param(cmd, "PLMN_MCC");
8843 if (val == NULL) {
8844 send_resp(dut, conn, SIGMA_ERROR,
8845 "errorCode,Missing PLMN_MCC");
8846 return 0;
8847 }
8848 if (strlen(val) != 3) {
8849 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
8850 return 0;
8851 }
8852 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
8853
8854 val = get_param(cmd, "PLMN_MNC");
8855 if (val == NULL) {
8856 send_resp(dut, conn, SIGMA_ERROR,
8857 "errorCode,Missing PLMN_MNC");
8858 return 0;
8859 }
8860 if (strlen(val) != 2 && strlen(val) != 3) {
8861 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
8862 return 0;
8863 }
8864 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
8865
8866 val = get_param(cmd, "IMSI");
8867 if (val == NULL) {
8868 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
8869 "IMSI");
8870 return 0;
8871 }
8872
8873 imsi = pos = val;
8874
8875 if (strncmp(plmn_mcc, pos, 3) != 0) {
8876 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
8877 return 0;
8878 }
8879 pos += 3;
8880
8881 mnc_len = strlen(plmn_mnc);
8882 if (mnc_len < 2) {
8883 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
8884 return 0;
8885 }
8886
8887 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
8888 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
8889 return 0;
8890 }
8891 pos += mnc_len;
8892
8893 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
8894 if (res < 0 || res >= (int) sizeof(buf))
8895 return -1;
8896 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
8897 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8898 "not set IMSI");
8899 return 0;
8900 }
8901
8902 val = get_param(cmd, "Password");
8903 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
8904 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8905 "not set password");
8906 return 0;
8907 }
8908
8909 if (dut->program == PROGRAM_HS2_R2) {
8910 /*
8911 * Set provisioning_sp for the test cases where SIM/USIM
8912 * provisioning is used.
8913 */
8914 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
8915 "wi-fi.org") < 0) {
8916 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8917 "not set provisioning_sp");
8918 return 0;
8919 }
8920
8921 update_devdetail_imsi(dut, imsi);
8922 }
8923
8924 return 1;
8925}
8926
8927
8928static int sta_add_credential_cert(struct sigma_dut *dut,
8929 struct sigma_conn *conn,
8930 const char *ifname,
8931 struct sigma_cmd *cmd)
8932{
8933 const char *val;
8934 int id;
8935
8936 id = add_cred(ifname);
8937 if (id < 0)
8938 return -2;
8939 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8940
8941 val = get_param(cmd, "prefer");
8942 if (val && atoi(val) > 0)
8943 set_cred(ifname, id, "priority", "1");
8944
8945 val = get_param(cmd, "REALM");
8946 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
8947 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8948 "realm");
8949 return 0;
8950 }
8951
8952 val = get_param(cmd, "HOME_FQDN");
8953 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
8954 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8955 "home_fqdn");
8956 return 0;
8957 }
8958
8959 val = get_param(cmd, "Username");
8960 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
8961 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8962 "username");
8963 return 0;
8964 }
8965
8966 val = get_param(cmd, "clientCertificate");
8967 if (val) {
8968 char fname[200];
8969 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8970#ifdef __linux__
8971 if (!file_exists(fname)) {
8972 char msg[300];
8973 snprintf(msg, sizeof(msg),
8974 "ErrorCode,clientCertificate "
8975 "file (%s) not found", fname);
8976 send_resp(dut, conn, SIGMA_ERROR, msg);
8977 return 0;
8978 }
8979#endif /* __linux__ */
8980 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
8981 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8982 "not set client_cert");
8983 return 0;
8984 }
8985 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
8986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8987 "not set private_key");
8988 return 0;
8989 }
8990 }
8991
8992 val = get_param(cmd, "ROOT_CA");
8993 if (val) {
8994 char fname[200];
8995 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8996#ifdef __linux__
8997 if (!file_exists(fname)) {
8998 char msg[300];
8999 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9000 "file (%s) not found", fname);
9001 send_resp(dut, conn, SIGMA_ERROR, msg);
9002 return 0;
9003 }
9004#endif /* __linux__ */
9005 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9006 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9007 "not set root CA");
9008 return 0;
9009 }
9010 }
9011
9012 return 1;
9013}
9014
9015
9016static int cmd_sta_add_credential(struct sigma_dut *dut,
9017 struct sigma_conn *conn,
9018 struct sigma_cmd *cmd)
9019{
9020 const char *intf = get_param(cmd, "Interface");
9021 const char *type;
9022
9023 start_sta_mode(dut);
9024
9025 type = get_param(cmd, "Type");
9026 if (!type)
9027 return -1;
9028
9029 if (strcasecmp(type, "uname_pwd") == 0)
9030 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9031
9032 if (strcasecmp(type, "sim") == 0)
9033 return sta_add_credential_sim(dut, conn, intf, cmd);
9034
9035 if (strcasecmp(type, "cert") == 0)
9036 return sta_add_credential_cert(dut, conn, intf, cmd);
9037
9038 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9039 "type");
9040 return 0;
9041}
9042
9043
9044static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9045 struct sigma_cmd *cmd)
9046{
9047 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309048 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009049 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309050 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009051 int res;
9052
9053 val = get_param(cmd, "HESSID");
9054 if (val) {
9055 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9056 if (res < 0 || res >= (int) sizeof(buf))
9057 return -1;
9058 wpa_command(intf, buf);
9059 }
9060
9061 val = get_param(cmd, "ACCS_NET_TYPE");
9062 if (val) {
9063 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9064 val);
9065 if (res < 0 || res >= (int) sizeof(buf))
9066 return -1;
9067 wpa_command(intf, buf);
9068 }
9069
vamsi krishna89ad8c62017-09-19 12:51:18 +05309070 bssid = get_param(cmd, "Bssid");
9071 ssid = get_param(cmd, "Ssid");
9072
9073 if (ssid) {
9074 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9075 send_resp(dut, conn, SIGMA_ERROR,
9076 "ErrorCode,Too long SSID");
9077 return 0;
9078 }
9079 ascii2hexstr(ssid, ssid_hex);
9080 }
9081
9082 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9083 bssid ? " bssid=": "",
9084 bssid ? bssid : "",
9085 ssid ? " ssid " : "",
9086 ssid ? ssid_hex : "");
9087 if (res < 0 || res >= (int) sizeof(buf))
9088 return -1;
9089
9090 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009091 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9092 "scan");
9093 return 0;
9094 }
9095
9096 return 1;
9097}
9098
9099
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009100static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9101 struct sigma_cmd *cmd)
9102{
9103 const char *intf = get_param(cmd, "Interface");
9104 const char *bssid;
9105 char buf[4096], *pos;
9106 int freq, chan;
9107 char *ssid;
9108 char resp[100];
9109 int res;
9110 struct wpa_ctrl *ctrl;
9111
9112 bssid = get_param(cmd, "BSSID");
9113 if (!bssid) {
9114 send_resp(dut, conn, SIGMA_INVALID,
9115 "errorCode,BSSID argument is missing");
9116 return 0;
9117 }
9118
9119 ctrl = open_wpa_mon(intf);
9120 if (!ctrl) {
9121 sigma_dut_print(dut, DUT_MSG_ERROR,
9122 "Failed to open wpa_supplicant monitor connection");
9123 return -1;
9124 }
9125
9126 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9127 send_resp(dut, conn, SIGMA_ERROR,
9128 "errorCode,Could not start scan");
9129 wpa_ctrl_detach(ctrl);
9130 wpa_ctrl_close(ctrl);
9131 return 0;
9132 }
9133
9134 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9135 buf, sizeof(buf));
9136
9137 wpa_ctrl_detach(ctrl);
9138 wpa_ctrl_close(ctrl);
9139
9140 if (res < 0) {
9141 send_resp(dut, conn, SIGMA_ERROR,
9142 "errorCode,Scan did not complete");
9143 return 0;
9144 }
9145
9146 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9147 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9148 strncmp(buf, "id=", 3) != 0) {
9149 send_resp(dut, conn, SIGMA_ERROR,
9150 "errorCode,Specified BSSID not found");
9151 return 0;
9152 }
9153
9154 pos = strstr(buf, "\nfreq=");
9155 if (!pos) {
9156 send_resp(dut, conn, SIGMA_ERROR,
9157 "errorCode,Channel not found");
9158 return 0;
9159 }
9160 freq = atoi(pos + 6);
9161 chan = freq_to_channel(freq);
9162
9163 pos = strstr(buf, "\nssid=");
9164 if (!pos) {
9165 send_resp(dut, conn, SIGMA_ERROR,
9166 "errorCode,SSID not found");
9167 return 0;
9168 }
9169 ssid = pos + 6;
9170 pos = strchr(ssid, '\n');
9171 if (pos)
9172 *pos = '\0';
9173 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9174 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9175 return 0;
9176}
9177
9178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009179static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9180 struct sigma_cmd *cmd)
9181{
9182#ifdef __linux__
9183 struct timeval tv;
9184 struct tm tm;
9185 time_t t;
9186 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309187 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009188
9189 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9190
9191 memset(&tm, 0, sizeof(tm));
9192 val = get_param(cmd, "seconds");
9193 if (val)
9194 tm.tm_sec = atoi(val);
9195 val = get_param(cmd, "minutes");
9196 if (val)
9197 tm.tm_min = atoi(val);
9198 val = get_param(cmd, "hours");
9199 if (val)
9200 tm.tm_hour = atoi(val);
9201 val = get_param(cmd, "date");
9202 if (val)
9203 tm.tm_mday = atoi(val);
9204 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309205 if (val) {
9206 v = atoi(val);
9207 if (v < 1 || v > 12) {
9208 send_resp(dut, conn, SIGMA_INVALID,
9209 "errorCode,Invalid month");
9210 return 0;
9211 }
9212 tm.tm_mon = v - 1;
9213 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009214 val = get_param(cmd, "year");
9215 if (val) {
9216 int year = atoi(val);
9217#ifdef ANDROID
9218 if (year > 2035)
9219 year = 2035; /* years beyond 2035 not supported */
9220#endif /* ANDROID */
9221 tm.tm_year = year - 1900;
9222 }
9223 t = mktime(&tm);
9224 if (t == (time_t) -1) {
9225 send_resp(dut, conn, SIGMA_ERROR,
9226 "errorCode,Invalid date or time");
9227 return 0;
9228 }
9229
9230 memset(&tv, 0, sizeof(tv));
9231 tv.tv_sec = t;
9232
9233 if (settimeofday(&tv, NULL) < 0) {
9234 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9235 strerror(errno));
9236 send_resp(dut, conn, SIGMA_ERROR,
9237 "errorCode,Failed to set time");
9238 return 0;
9239 }
9240
9241 return 1;
9242#endif /* __linux__ */
9243
9244 return -1;
9245}
9246
9247
9248static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9249 struct sigma_cmd *cmd)
9250{
9251 const char *intf = get_param(cmd, "Interface");
9252 const char *name, *val;
9253 int prod_ess_assoc = 1;
9254 char buf[200], bssid[100], ssid[100];
9255 int res;
9256 struct wpa_ctrl *ctrl;
9257
9258 name = get_param(cmd, "osuFriendlyName");
9259
9260 val = get_param(cmd, "ProdESSAssoc");
9261 if (val)
9262 prod_ess_assoc = atoi(val);
9263
9264 kill_dhcp_client(dut, intf);
9265 if (start_dhcp_client(dut, intf) < 0)
9266 return -2;
9267
9268 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9269 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9270 res = snprintf(buf, sizeof(buf),
9271 "%s %s%s%s signup osu-ca.pem",
9272 prod_ess_assoc ? "" : "-N",
9273 name ? "-O'" : "", name ? name : "",
9274 name ? "'" : "");
9275
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309276 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009277 if (run_hs20_osu(dut, buf) < 0) {
9278 FILE *f;
9279
9280 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9281
9282 f = fopen("hs20-osu-client.res", "r");
9283 if (f) {
9284 char resp[400], res[300], *pos;
9285 if (!fgets(res, sizeof(res), f))
9286 res[0] = '\0';
9287 pos = strchr(res, '\n');
9288 if (pos)
9289 *pos = '\0';
9290 fclose(f);
9291 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
9292 res);
9293 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
9294 if (system(resp) != 0) {
9295 }
9296 snprintf(resp, sizeof(resp),
9297 "SSID,,BSSID,,failureReason,%s", res);
9298 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9299 return 0;
9300 }
9301
9302 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9303 return 0;
9304 }
9305
9306 if (!prod_ess_assoc)
9307 goto report;
9308
9309 ctrl = open_wpa_mon(intf);
9310 if (ctrl == NULL) {
9311 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9312 "wpa_supplicant monitor connection");
9313 return -1;
9314 }
9315
9316 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9317 buf, sizeof(buf));
9318
9319 wpa_ctrl_detach(ctrl);
9320 wpa_ctrl_close(ctrl);
9321
9322 if (res < 0) {
9323 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
9324 "network after OSU");
9325 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9326 return 0;
9327 }
9328
9329report:
9330 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9331 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9332 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
9333 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9334 return 0;
9335 }
9336
9337 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
9338 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009339 return 0;
9340}
9341
9342
9343static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
9344 struct sigma_cmd *cmd)
9345{
9346 const char *val;
9347 int timeout = 120;
9348
9349 val = get_param(cmd, "PolicyUpdate");
9350 if (val == NULL || atoi(val) == 0)
9351 return 1; /* No operation requested */
9352
9353 val = get_param(cmd, "Timeout");
9354 if (val)
9355 timeout = atoi(val);
9356
9357 if (timeout) {
9358 /* TODO: time out the command and return
9359 * PolicyUpdateStatus,TIMEOUT if needed. */
9360 }
9361
9362 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
9363 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9364 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
9365 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
9366 return 0;
9367 }
9368
9369 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
9370 return 0;
9371}
9372
9373
9374static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
9375 struct sigma_cmd *cmd)
9376{
9377 struct wpa_ctrl *ctrl;
9378 const char *intf = get_param(cmd, "Interface");
9379 const char *bssid = get_param(cmd, "Bssid");
9380 const char *ssid = get_param(cmd, "SSID");
9381 const char *security = get_param(cmd, "Security");
9382 const char *passphrase = get_param(cmd, "Passphrase");
9383 const char *pin = get_param(cmd, "PIN");
9384 char buf[1000];
9385 char ssid_hex[200], passphrase_hex[200];
9386 const char *keymgmt, *cipher;
9387
9388 if (intf == NULL)
9389 intf = get_main_ifname();
9390
9391 if (!bssid) {
9392 send_resp(dut, conn, SIGMA_ERROR,
9393 "ErrorCode,Missing Bssid argument");
9394 return 0;
9395 }
9396
9397 if (!ssid) {
9398 send_resp(dut, conn, SIGMA_ERROR,
9399 "ErrorCode,Missing SSID argument");
9400 return 0;
9401 }
9402
9403 if (!security) {
9404 send_resp(dut, conn, SIGMA_ERROR,
9405 "ErrorCode,Missing Security argument");
9406 return 0;
9407 }
9408
9409 if (!passphrase) {
9410 send_resp(dut, conn, SIGMA_ERROR,
9411 "ErrorCode,Missing Passphrase argument");
9412 return 0;
9413 }
9414
9415 if (!pin) {
9416 send_resp(dut, conn, SIGMA_ERROR,
9417 "ErrorCode,Missing PIN argument");
9418 return 0;
9419 }
9420
vamsi krishna8c9c1562017-05-12 15:51:46 +05309421 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
9422 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009423 send_resp(dut, conn, SIGMA_ERROR,
9424 "ErrorCode,Too long SSID/passphrase");
9425 return 0;
9426 }
9427
9428 ctrl = open_wpa_mon(intf);
9429 if (ctrl == NULL) {
9430 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9431 "wpa_supplicant monitor connection");
9432 return -2;
9433 }
9434
9435 if (strcasecmp(security, "wpa2-psk") == 0) {
9436 keymgmt = "WPA2PSK";
9437 cipher = "CCMP";
9438 } else {
9439 wpa_ctrl_detach(ctrl);
9440 wpa_ctrl_close(ctrl);
9441 send_resp(dut, conn, SIGMA_ERROR,
9442 "ErrorCode,Unsupported Security value");
9443 return 0;
9444 }
9445
9446 ascii2hexstr(ssid, ssid_hex);
9447 ascii2hexstr(passphrase, passphrase_hex);
9448 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
9449 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
9450
9451 if (wpa_command(intf, buf) < 0) {
9452 wpa_ctrl_detach(ctrl);
9453 wpa_ctrl_close(ctrl);
9454 send_resp(dut, conn, SIGMA_ERROR,
9455 "ErrorCode,Failed to start registrar");
9456 return 0;
9457 }
9458
9459 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
9460 dut->er_oper_performed = 1;
9461
9462 return wps_connection_event(dut, conn, ctrl, intf, 0);
9463}
9464
9465
9466static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
9467 struct sigma_conn *conn,
9468 struct sigma_cmd *cmd)
9469{
9470 struct wpa_ctrl *ctrl;
9471 const char *intf = get_param(cmd, "Interface");
9472 const char *bssid = get_param(cmd, "Bssid");
9473 char buf[100];
9474
9475 if (!bssid) {
9476 send_resp(dut, conn, SIGMA_ERROR,
9477 "ErrorCode,Missing Bssid argument");
9478 return 0;
9479 }
9480
9481 ctrl = open_wpa_mon(intf);
9482 if (ctrl == NULL) {
9483 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9484 "wpa_supplicant monitor connection");
9485 return -2;
9486 }
9487
9488 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
9489
9490 if (wpa_command(intf, buf) < 0) {
9491 wpa_ctrl_detach(ctrl);
9492 wpa_ctrl_close(ctrl);
9493 send_resp(dut, conn, SIGMA_ERROR,
9494 "ErrorCode,Failed to start registrar");
9495 return 0;
9496 }
9497
9498 return wps_connection_event(dut, conn, ctrl, intf, 0);
9499}
9500
9501
vamsi krishna9b144002017-09-20 13:28:13 +05309502static int cmd_start_wps_registration(struct sigma_dut *dut,
9503 struct sigma_conn *conn,
9504 struct sigma_cmd *cmd)
9505{
9506 struct wpa_ctrl *ctrl;
9507 const char *intf = get_param(cmd, "Interface");
9508 const char *role, *method;
9509 int res;
9510 char buf[256];
9511 const char *events[] = {
9512 "CTRL-EVENT-CONNECTED",
9513 "WPS-OVERLAP-DETECTED",
9514 "WPS-TIMEOUT",
9515 "WPS-FAIL",
9516 NULL
9517 };
9518
9519 ctrl = open_wpa_mon(intf);
9520 if (!ctrl) {
9521 sigma_dut_print(dut, DUT_MSG_ERROR,
9522 "Failed to open wpa_supplicant monitor connection");
9523 return -2;
9524 }
9525
9526 role = get_param(cmd, "WpsRole");
9527 if (!role) {
9528 send_resp(dut, conn, SIGMA_INVALID,
9529 "ErrorCode,WpsRole not provided");
9530 goto fail;
9531 }
9532
9533 if (strcasecmp(role, "Enrollee") == 0) {
9534 method = get_param(cmd, "WpsConfigMethod");
9535 if (!method) {
9536 send_resp(dut, conn, SIGMA_INVALID,
9537 "ErrorCode,WpsConfigMethod not provided");
9538 goto fail;
9539 }
9540 if (strcasecmp(method, "PBC") == 0) {
9541 if (wpa_command(intf, "WPS_PBC") < 0) {
9542 send_resp(dut, conn, SIGMA_ERROR,
9543 "ErrorCode,Failed to enable PBC");
9544 goto fail;
9545 }
9546 } else {
9547 /* TODO: PIN method */
9548 send_resp(dut, conn, SIGMA_ERROR,
9549 "ErrorCode,Unsupported WpsConfigMethod value");
9550 goto fail;
9551 }
9552 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9553 if (res < 0) {
9554 send_resp(dut, conn, SIGMA_ERROR,
9555 "ErrorCode,WPS connection did not complete");
9556 goto fail;
9557 }
9558 if (strstr(buf, "WPS-TIMEOUT")) {
9559 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
9560 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
9561 send_resp(dut, conn, SIGMA_ERROR,
9562 "ErrorCode,OverlapSession");
9563 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
9564 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
9565 } else {
9566 send_resp(dut, conn, SIGMA_ERROR,
9567 "ErrorCode,WPS operation failed");
9568 }
9569 } else {
9570 /* TODO: Registrar role */
9571 send_resp(dut, conn, SIGMA_ERROR,
9572 "ErrorCode,Unsupported WpsRole value");
9573 }
9574
9575fail:
9576 wpa_ctrl_detach(ctrl);
9577 wpa_ctrl_close(ctrl);
9578 return 0;
9579}
9580
9581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009582static int req_intf(struct sigma_cmd *cmd)
9583{
9584 return get_param(cmd, "interface") == NULL ? -1 : 0;
9585}
9586
9587
9588void sta_register_cmds(void)
9589{
9590 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
9591 cmd_sta_get_ip_config);
9592 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
9593 cmd_sta_set_ip_config);
9594 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
9595 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
9596 cmd_sta_get_mac_address);
9597 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
9598 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
9599 cmd_sta_verify_ip_connection);
9600 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
9601 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
9602 cmd_sta_set_encryption);
9603 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
9604 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
9605 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
9606 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
9607 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
9608 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
9609 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
9610 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
9611 cmd_sta_set_eapakaprime);
9612 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
9613 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
9614 /* TODO: sta_set_ibss */
9615 /* TODO: sta_set_mode */
9616 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
9617 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
9618 /* TODO: sta_up_load */
9619 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
9620 cmd_sta_preset_testparameters);
9621 /* TODO: sta_set_system */
9622 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
9623 /* TODO: sta_set_rifs_test */
9624 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
9625 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
9626 /* TODO: sta_send_coexist_mgmt */
9627 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
9628 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
9629 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
9630 sigma_dut_reg_cmd("sta_reset_default", req_intf,
9631 cmd_sta_reset_default);
9632 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
9633 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
9634 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
9635 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
9636 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
9637 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
9638 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
9639 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
9640 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
9641 cmd_sta_hs2_associate);
9642 sigma_dut_reg_cmd("sta_add_credential", req_intf,
9643 cmd_sta_add_credential);
9644 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009645 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009646 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
9647 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
9648 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
9649 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
9650 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
9651 cmd_sta_wps_connect_pw_token);
9652 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
9653 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
9654 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +05309655 sigma_dut_reg_cmd("start_wps_registration", req_intf,
9656 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009657}