blob: c16e5e46cbf8119e1dafd9ecfe03315f58d77ac2 [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
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004081static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4082 const char *intf, int addbareject)
4083{
4084#ifdef NL80211_SUPPORT
4085 struct nl_msg *msg;
4086 int ret = 0;
4087 struct nlattr *params;
4088 int ifindex;
4089
4090 ifindex = if_nametoindex(intf);
4091 if (ifindex == 0) {
4092 sigma_dut_print(dut, DUT_MSG_ERROR,
4093 "%s: Index for interface %s failed",
4094 __func__, intf);
4095 return -1;
4096 }
4097
4098 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4099 NL80211_CMD_VENDOR)) ||
4100 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4101 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4102 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4103 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4104 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4105 nla_put_u8(msg,
4106 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4107 !addbareject)) {
4108 sigma_dut_print(dut, DUT_MSG_ERROR,
4109 "%s: err in adding vendor_cmd and vendor_data",
4110 __func__);
4111 nlmsg_free(msg);
4112 return -1;
4113 }
4114 nla_nest_end(msg, params);
4115
4116 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4117 if (ret) {
4118 sigma_dut_print(dut, DUT_MSG_ERROR,
4119 "%s: err in send_and_recv_msgs, ret=%d",
4120 __func__, ret);
4121 }
4122 return ret;
4123#else /* NL80211_SUPPORT */
4124 sigma_dut_print(dut, DUT_MSG_ERROR,
4125 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4126 return -1;
4127#endif /* NL80211_SUPPORT */
4128}
4129
4130
4131static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4132 int addbareject)
4133{
4134 int ret;
4135
4136 switch (get_driver_type()) {
4137 case DRIVER_WCN:
4138 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4139 if (ret) {
4140 sigma_dut_print(dut, DUT_MSG_ERROR,
4141 "nlvendor_sta_set_addba_reject failed, ret:%d",
4142 ret);
4143 return ret;
4144 }
4145 break;
4146 default:
4147 sigma_dut_print(dut, DUT_MSG_ERROR,
4148 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4149 ret = -1;
4150 break;
4151 }
4152
4153 return ret;
4154}
4155
4156
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004157static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4158 struct sigma_conn *conn,
4159 struct sigma_cmd *cmd)
4160{
4161 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004162 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004163 char buf[30];
4164
4165 val = get_param(cmd, "40_INTOLERANT");
4166 if (val) {
4167 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4168 /* TODO: iwpriv ht40intol through wpa_supplicant */
4169 send_resp(dut, conn, SIGMA_ERROR,
4170 "ErrorCode,40_INTOLERANT not supported");
4171 return 0;
4172 }
4173 }
4174
4175 val = get_param(cmd, "ADDBA_REJECT");
4176 if (val) {
4177 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4178 /* reject any ADDBA with status "decline" */
4179 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004180 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004181 } else {
4182 /* accept ADDBA */
4183 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004184 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004185 }
4186 }
4187
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004188 if (addbareject >= 0 &&
4189 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4190 send_resp(dut, conn, SIGMA_ERROR,
4191 "ErrorCode,set addba_reject failed");
4192 return 0;
4193 }
4194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004195 val = get_param(cmd, "AMPDU");
4196 if (val) {
4197 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4198 /* enable AMPDU Aggregation */
4199 if (ampdu == 0) {
4200 send_resp(dut, conn, SIGMA_ERROR,
4201 "ErrorCode,Mismatch in "
4202 "addba_reject/ampdu - "
4203 "not supported");
4204 return 0;
4205 }
4206 ampdu = 1;
4207 } else {
4208 /* disable AMPDU Aggregation */
4209 if (ampdu == 1) {
4210 send_resp(dut, conn, SIGMA_ERROR,
4211 "ErrorCode,Mismatch in "
4212 "addba_reject/ampdu - "
4213 "not supported");
4214 return 0;
4215 }
4216 ampdu = 0;
4217 }
4218 }
4219
4220 if (ampdu >= 0) {
4221 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4222 ampdu ? "Enabling" : "Disabling");
4223 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004224 if (wpa_command(intf, buf) < 0 &&
4225 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226 send_resp(dut, conn, SIGMA_ERROR,
4227 "ErrorCode,set aggr failed");
4228 return 0;
4229 }
4230 }
4231
4232 val = get_param(cmd, "AMSDU");
4233 if (val) {
4234 switch (get_driver_type()) {
4235 case DRIVER_ATHEROS:
4236 ath_sta_set_amsdu(dut, intf, val);
4237 break;
4238 default:
4239 if (strcmp(val, "1") == 0 ||
4240 strcasecmp(val, "Enable") == 0) {
4241 /* Enable AMSDU Aggregation */
4242 send_resp(dut, conn, SIGMA_ERROR,
4243 "ErrorCode,AMSDU aggregation not supported");
4244 return 0;
4245 }
4246 break;
4247 }
4248 }
4249
4250 val = get_param(cmd, "STBC_RX");
4251 if (val) {
4252 switch (get_driver_type()) {
4253 case DRIVER_ATHEROS:
4254 ath_sta_set_stbc(dut, intf, val);
4255 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304256 case DRIVER_WCN:
4257 wcn_sta_set_stbc(dut, intf, val);
4258 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259 default:
4260 send_resp(dut, conn, SIGMA_ERROR,
4261 "ErrorCode,STBC_RX not supported");
4262 return 0;
4263 }
4264 }
4265
4266 val = get_param(cmd, "WIDTH");
4267 if (val) {
4268 switch (get_driver_type()) {
4269 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004270 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004271 send_resp(dut, conn, SIGMA_ERROR,
4272 "ErrorCode,Failed to set WIDTH");
4273 return 0;
4274 }
4275 break;
4276 case DRIVER_ATHEROS:
4277 if (ath_set_width(dut, conn, intf, val) < 0)
4278 return 0;
4279 break;
4280 default:
4281 sigma_dut_print(dut, DUT_MSG_ERROR,
4282 "Setting WIDTH not supported");
4283 break;
4284 }
4285 }
4286
4287 val = get_param(cmd, "SMPS");
4288 if (val) {
4289 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4290 send_resp(dut, conn, SIGMA_ERROR,
4291 "ErrorCode,SMPS not supported");
4292 return 0;
4293 }
4294
4295 val = get_param(cmd, "TXSP_STREAM");
4296 if (val) {
4297 switch (get_driver_type()) {
4298 case DRIVER_WCN:
4299 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4300 send_resp(dut, conn, SIGMA_ERROR,
4301 "ErrorCode,Failed to set TXSP_STREAM");
4302 return 0;
4303 }
4304 break;
4305 case DRIVER_ATHEROS:
4306 ath_sta_set_txsp_stream(dut, intf, val);
4307 break;
4308 default:
4309 sigma_dut_print(dut, DUT_MSG_ERROR,
4310 "Setting TXSP_STREAM not supported");
4311 break;
4312 }
4313 }
4314
4315 val = get_param(cmd, "RXSP_STREAM");
4316 if (val) {
4317 switch (get_driver_type()) {
4318 case DRIVER_WCN:
4319 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4320 send_resp(dut, conn, SIGMA_ERROR,
4321 "ErrorCode,Failed to set RXSP_STREAM");
4322 return 0;
4323 }
4324 break;
4325 case DRIVER_ATHEROS:
4326 ath_sta_set_rxsp_stream(dut, intf, val);
4327 break;
4328 default:
4329 sigma_dut_print(dut, DUT_MSG_ERROR,
4330 "Setting RXSP_STREAM not supported");
4331 break;
4332 }
4333 }
4334
4335 val = get_param(cmd, "DYN_BW_SGNL");
4336 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004337 switch (get_driver_type()) {
4338 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004339 if (strcasecmp(val, "enable") == 0) {
4340 snprintf(buf, sizeof(buf),
4341 "iwpriv %s cwmenable 1", intf);
4342 if (system(buf) != 0) {
4343 sigma_dut_print(dut, DUT_MSG_ERROR,
4344 "iwpriv cwmenable 1 failed");
4345 return 0;
4346 }
4347 } else if (strcasecmp(val, "disable") == 0) {
4348 snprintf(buf, sizeof(buf),
4349 "iwpriv %s cwmenable 0", intf);
4350 if (system(buf) != 0) {
4351 sigma_dut_print(dut, DUT_MSG_ERROR,
4352 "iwpriv cwmenable 0 failed");
4353 return 0;
4354 }
4355 } else {
4356 sigma_dut_print(dut, DUT_MSG_ERROR,
4357 "Unsupported DYN_BW_SGL");
4358 }
4359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004360 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4361 if (system(buf) != 0) {
4362 sigma_dut_print(dut, DUT_MSG_ERROR,
4363 "Failed to set cts_cbw in DYN_BW_SGNL");
4364 return 0;
4365 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004366 break;
4367 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004368 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004369 ath_config_dyn_bw_sig(dut, intf, val);
4370 break;
4371 default:
4372 sigma_dut_print(dut, DUT_MSG_ERROR,
4373 "Failed to set DYN_BW_SGNL");
4374 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004375 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004376 }
4377
4378 val = get_param(cmd, "RTS_FORCE");
4379 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004380 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004381 if (strcasecmp(val, "Enable") == 0) {
4382 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004383 if (system(buf) != 0) {
4384 sigma_dut_print(dut, DUT_MSG_ERROR,
4385 "Failed to set RTS_FORCE 64");
4386 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004387 snprintf(buf, sizeof(buf),
4388 "wifitool %s beeliner_fw_test 100 1", intf);
4389 if (system(buf) != 0) {
4390 sigma_dut_print(dut, DUT_MSG_ERROR,
4391 "wifitool beeliner_fw_test 100 1 failed");
4392 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004393 } else if (strcasecmp(val, "Disable") == 0) {
4394 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4395 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004396 if (system(buf) != 0) {
4397 sigma_dut_print(dut, DUT_MSG_ERROR,
4398 "Failed to set RTS_FORCE 2347");
4399 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004400 } else {
4401 send_resp(dut, conn, SIGMA_ERROR,
4402 "ErrorCode,RTS_FORCE value not supported");
4403 return 0;
4404 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405 }
4406
4407 val = get_param(cmd, "CTS_WIDTH");
4408 if (val) {
4409 switch (get_driver_type()) {
4410 case DRIVER_WCN:
4411 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4412 send_resp(dut, conn, SIGMA_ERROR,
4413 "ErrorCode,Failed to set CTS_WIDTH");
4414 return 0;
4415 }
4416 break;
4417 case DRIVER_ATHEROS:
4418 ath_set_cts_width(dut, intf, val);
4419 break;
4420 default:
4421 sigma_dut_print(dut, DUT_MSG_ERROR,
4422 "Setting CTS_WIDTH not supported");
4423 break;
4424 }
4425 }
4426
4427 val = get_param(cmd, "BW_SGNL");
4428 if (val) {
4429 if (strcasecmp(val, "Enable") == 0) {
4430 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4431 intf);
4432 } else if (strcasecmp(val, "Disable") == 0) {
4433 /* TODO: Disable */
4434 buf[0] = '\0';
4435 } else {
4436 send_resp(dut, conn, SIGMA_ERROR,
4437 "ErrorCode,BW_SGNL value not supported");
4438 return 0;
4439 }
4440
4441 if (buf[0] != '\0' && system(buf) != 0) {
4442 sigma_dut_print(dut, DUT_MSG_ERROR,
4443 "Failed to set BW_SGNL");
4444 }
4445 }
4446
4447 val = get_param(cmd, "Band");
4448 if (val) {
4449 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4450 /* STA supports all bands by default */
4451 } else {
4452 send_resp(dut, conn, SIGMA_ERROR,
4453 "ErrorCode,Unsupported Band");
4454 return 0;
4455 }
4456 }
4457
4458 val = get_param(cmd, "zero_crc");
4459 if (val) {
4460 switch (get_driver_type()) {
4461 case DRIVER_ATHEROS:
4462 ath_set_zero_crc(dut, val);
4463 break;
4464 default:
4465 break;
4466 }
4467 }
4468
4469 return 1;
4470}
4471
4472
4473static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4474 struct sigma_cmd *cmd)
4475{
4476 const char *val;
4477 char buf[100];
4478
4479 val = get_param(cmd, "MSDUSize");
4480 if (val) {
4481 int mtu;
4482
4483 dut->amsdu_size = atoi(val);
4484 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4485 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4486 sigma_dut_print(dut, DUT_MSG_ERROR,
4487 "MSDUSize %d is above max %d or below min %d",
4488 dut->amsdu_size,
4489 IEEE80211_MAX_DATA_LEN_DMG,
4490 IEEE80211_SNAP_LEN_DMG);
4491 dut->amsdu_size = 0;
4492 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4493 }
4494
4495 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4496 sigma_dut_print(dut, DUT_MSG_DEBUG,
4497 "Setting amsdu_size to %d", mtu);
4498 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4499 get_station_ifname(), mtu);
4500
4501 if (system(buf) != 0) {
4502 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4503 buf);
4504 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4505 }
4506 }
4507
4508 val = get_param(cmd, "BAckRcvBuf");
4509 if (val) {
4510 dut->back_rcv_buf = atoi(val);
4511 if (dut->back_rcv_buf == 0) {
4512 sigma_dut_print(dut, DUT_MSG_ERROR,
4513 "Failed to convert %s or value is 0",
4514 val);
4515 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4516 }
4517
4518 sigma_dut_print(dut, DUT_MSG_DEBUG,
4519 "Setting BAckRcvBuf to %s", val);
4520 }
4521
4522 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4523}
4524
4525
4526static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4527 struct sigma_cmd *cmd)
4528{
4529 int net_id;
4530 char *ifname;
4531 const char *val;
4532 char buf[100];
4533
4534 dut->mode = SIGMA_MODE_STATION;
4535 ifname = get_main_ifname();
4536 if (wpa_command(ifname, "PING") != 0) {
4537 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4538 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4539 }
4540
4541 wpa_command(ifname, "FLUSH");
4542 net_id = add_network_common(dut, conn, ifname, cmd);
4543 if (net_id < 0) {
4544 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4545 return net_id;
4546 }
4547
4548 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4549 if (set_network(ifname, net_id, "mode", "2") < 0) {
4550 sigma_dut_print(dut, DUT_MSG_ERROR,
4551 "Failed to set supplicant network mode");
4552 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4553 }
4554
4555 sigma_dut_print(dut, DUT_MSG_DEBUG,
4556 "Supplicant set network with mode 2");
4557
4558 val = get_param(cmd, "Security");
4559 if (val && strcasecmp(val, "OPEN") == 0) {
4560 dut->ap_key_mgmt = AP_OPEN;
4561 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4562 sigma_dut_print(dut, DUT_MSG_ERROR,
4563 "Failed to set supplicant to %s security",
4564 val);
4565 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4566 }
4567 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4568 dut->ap_key_mgmt = AP_WPA2_PSK;
4569 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4570 sigma_dut_print(dut, DUT_MSG_ERROR,
4571 "Failed to set supplicant to %s security",
4572 val);
4573 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4574 }
4575
4576 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4577 sigma_dut_print(dut, DUT_MSG_ERROR,
4578 "Failed to set supplicant to proto RSN");
4579 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4580 }
4581 } else if (val) {
4582 sigma_dut_print(dut, DUT_MSG_ERROR,
4583 "Requested Security %s is not supported on 60GHz",
4584 val);
4585 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4586 }
4587
4588 val = get_param(cmd, "Encrypt");
4589 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4590 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4591 sigma_dut_print(dut, DUT_MSG_ERROR,
4592 "Failed to set supplicant to pairwise GCMP");
4593 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4594 }
4595 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4596 sigma_dut_print(dut, DUT_MSG_ERROR,
4597 "Failed to set supplicant to group GCMP");
4598 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4599 }
4600 } else if (val) {
4601 sigma_dut_print(dut, DUT_MSG_ERROR,
4602 "Requested Encrypt %s is not supported on 60 GHz",
4603 val);
4604 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4605 }
4606
4607 val = get_param(cmd, "PSK");
4608 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4609 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4610 val);
4611 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4612 }
4613
4614 /* Convert 60G channel to freq */
4615 switch (dut->ap_channel) {
4616 case 1:
4617 val = "58320";
4618 break;
4619 case 2:
4620 val = "60480";
4621 break;
4622 case 3:
4623 val = "62640";
4624 break;
4625 default:
4626 sigma_dut_print(dut, DUT_MSG_ERROR,
4627 "Failed to configure channel %d. Not supported",
4628 dut->ap_channel);
4629 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4630 }
4631
4632 if (set_network(ifname, net_id, "frequency", val) < 0) {
4633 sigma_dut_print(dut, DUT_MSG_ERROR,
4634 "Failed to set supplicant network frequency");
4635 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4636 }
4637
4638 sigma_dut_print(dut, DUT_MSG_DEBUG,
4639 "Supplicant set network with frequency");
4640
4641 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4642 if (wpa_command(ifname, buf) < 0) {
4643 sigma_dut_print(dut, DUT_MSG_INFO,
4644 "Failed to select network id %d on %s",
4645 net_id, ifname);
4646 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4647 }
4648
4649 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4650
4651 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4652}
4653
4654
Lior David67543f52017-01-03 19:04:22 +02004655static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4656{
4657 char buf[128], fname[128];
4658 FILE *f;
4659
4660 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4661 sigma_dut_print(dut, DUT_MSG_ERROR,
4662 "failed to get wil6210 debugfs dir");
4663 return -1;
4664 }
4665
4666 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4667 f = fopen(fname, "w");
4668 if (!f) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "failed to open: %s", fname);
4671 return -1;
4672 }
4673
4674 fprintf(f, "%d\n", abft_len);
4675 fclose(f);
4676
4677 return 0;
4678}
4679
4680
4681static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4682 int abft_len)
4683{
4684 switch (get_driver_type()) {
4685 case DRIVER_WIL6210:
4686 return wil6210_set_abft_len(dut, abft_len);
4687 default:
4688 sigma_dut_print(dut, DUT_MSG_ERROR,
4689 "set abft_len not supported");
4690 return -1;
4691 }
4692}
4693
4694
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004695static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4696 struct sigma_cmd *cmd)
4697{
4698 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004699 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004700
4701 if (dut->dev_role != DEVROLE_PCP) {
4702 send_resp(dut, conn, SIGMA_INVALID,
4703 "ErrorCode,Invalid DevRole");
4704 return 0;
4705 }
4706
4707 val = get_param(cmd, "SSID");
4708 if (val) {
4709 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4710 send_resp(dut, conn, SIGMA_INVALID,
4711 "ErrorCode,Invalid SSID");
4712 return -1;
4713 }
4714
Peng Xub8fc5cc2017-05-10 17:27:28 -07004715 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004716 }
4717
4718 val = get_param(cmd, "CHANNEL");
4719 if (val) {
4720 const char *pos;
4721
4722 dut->ap_channel = atoi(val);
4723 pos = strchr(val, ';');
4724 if (pos) {
4725 pos++;
4726 dut->ap_channel_1 = atoi(pos);
4727 }
4728 }
4729
4730 switch (dut->ap_channel) {
4731 case 1:
4732 case 2:
4733 case 3:
4734 break;
4735 default:
4736 sigma_dut_print(dut, DUT_MSG_ERROR,
4737 "Channel %d is not supported", dut->ap_channel);
4738 send_resp(dut, conn, SIGMA_ERROR,
4739 "Requested channel is not supported");
4740 return -1;
4741 }
4742
4743 val = get_param(cmd, "BCNINT");
4744 if (val)
4745 dut->ap_bcnint = atoi(val);
4746
4747
4748 val = get_param(cmd, "ExtSchIE");
4749 if (val) {
4750 send_resp(dut, conn, SIGMA_ERROR,
4751 "ErrorCode,ExtSchIE is not supported yet");
4752 return -1;
4753 }
4754
4755 val = get_param(cmd, "AllocType");
4756 if (val) {
4757 send_resp(dut, conn, SIGMA_ERROR,
4758 "ErrorCode,AllocType is not supported yet");
4759 return -1;
4760 }
4761
4762 val = get_param(cmd, "PercentBI");
4763 if (val) {
4764 send_resp(dut, conn, SIGMA_ERROR,
4765 "ErrorCode,PercentBI is not supported yet");
4766 return -1;
4767 }
4768
4769 val = get_param(cmd, "CBAPOnly");
4770 if (val) {
4771 send_resp(dut, conn, SIGMA_ERROR,
4772 "ErrorCode,CBAPOnly is not supported yet");
4773 return -1;
4774 }
4775
4776 val = get_param(cmd, "AMPDU");
4777 if (val) {
4778 if (strcasecmp(val, "Enable") == 0)
4779 dut->ap_ampdu = 1;
4780 else if (strcasecmp(val, "Disable") == 0)
4781 dut->ap_ampdu = 2;
4782 else {
4783 send_resp(dut, conn, SIGMA_ERROR,
4784 "ErrorCode,AMPDU value is not Enable nor Disabled");
4785 return -1;
4786 }
4787 }
4788
4789 val = get_param(cmd, "AMSDU");
4790 if (val) {
4791 if (strcasecmp(val, "Enable") == 0)
4792 dut->ap_amsdu = 1;
4793 else if (strcasecmp(val, "Disable") == 0)
4794 dut->ap_amsdu = 2;
4795 }
4796
4797 val = get_param(cmd, "NumMSDU");
4798 if (val) {
4799 send_resp(dut, conn, SIGMA_ERROR,
4800 "ErrorCode, NumMSDU is not supported yet");
4801 return -1;
4802 }
4803
4804 val = get_param(cmd, "ABFTLRang");
4805 if (val) {
4806 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004807 "ABFTLRang parameter %s", val);
4808 if (strcmp(val, "Gt1") == 0)
4809 abft_len = 2; /* 2 slots in this case */
4810 }
4811
4812 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4813 send_resp(dut, conn, SIGMA_ERROR,
4814 "ErrorCode, Can't set ABFT length");
4815 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004816 }
4817
4818 if (sta_pcp_start(dut, conn, cmd) < 0) {
4819 send_resp(dut, conn, SIGMA_ERROR,
4820 "ErrorCode, Can't start PCP role");
4821 return -1;
4822 }
4823
4824 return sta_set_60g_common(dut, conn, cmd);
4825}
4826
4827
4828static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
4829 struct sigma_cmd *cmd)
4830{
4831 const char *val = get_param(cmd, "DiscoveryMode");
4832
4833 if (dut->dev_role != DEVROLE_STA) {
4834 send_resp(dut, conn, SIGMA_INVALID,
4835 "ErrorCode,Invalid DevRole");
4836 return 0;
4837 }
4838
4839 if (val) {
4840 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
4841 /* Ignore Discovery mode till Driver expose API. */
4842#if 0
4843 if (strcasecmp(val, "1") == 0) {
4844 send_resp(dut, conn, SIGMA_INVALID,
4845 "ErrorCode,DiscoveryMode 1 not supported");
4846 return 0;
4847 }
4848
4849 if (strcasecmp(val, "0") == 0) {
4850 /* OK */
4851 } else {
4852 send_resp(dut, conn, SIGMA_INVALID,
4853 "ErrorCode,DiscoveryMode not supported");
4854 return 0;
4855 }
4856#endif
4857 }
4858
4859 if (start_sta_mode(dut) != 0)
4860 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4861 return sta_set_60g_common(dut, conn, cmd);
4862}
4863
4864
4865static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
4866 struct sigma_cmd *cmd)
4867{
4868 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02004869 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05304870
Jouni Malinened77e672018-01-10 16:45:13 +02004871 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08004872 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02004873 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05304874 wpa_command(intf, "DISCONNECT");
4875 return 1;
4876 }
4877
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004878 disconnect_station(dut);
4879 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
4880 * due to cached results. */
4881 wpa_command(intf, "SET ignore_old_scan_res 1");
4882 wpa_command(intf, "BSS_FLUSH");
4883 return 1;
4884}
4885
4886
4887static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
4888 struct sigma_cmd *cmd)
4889{
4890 const char *intf = get_param(cmd, "Interface");
4891 const char *bssid = get_param(cmd, "bssid");
4892 const char *val = get_param(cmd, "CHANNEL");
4893 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05304894 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05304895 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004896 int res;
4897 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05304898 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05304899 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004900
4901 if (bssid == NULL) {
4902 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
4903 "argument");
4904 return 0;
4905 }
4906
4907 if (val)
4908 chan = atoi(val);
4909
4910 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
4911 /* The current network may be from sta_associate or
4912 * sta_hs2_associate
4913 */
4914 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
4915 0 ||
4916 set_network(intf, 0, "bssid", bssid) < 0)
4917 return -2;
4918 }
4919
4920 ctrl = open_wpa_mon(intf);
4921 if (ctrl == NULL) {
4922 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
4923 "wpa_supplicant monitor connection");
4924 return -1;
4925 }
4926
Sunil Duttd30ce092018-01-11 23:56:29 +05304927 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
4928 sizeof(result)) < 0 ||
4929 strncmp(result, "COMPLETED", 9) != 0) {
4930 sigma_dut_print(dut, DUT_MSG_DEBUG,
4931 "sta_reassoc: Not connected");
4932 fastreassoc = 0;
4933 }
4934
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05304935 if (dut->rsne_override) {
4936#ifdef NL80211_SUPPORT
4937 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
4938 sta_config_rsnie(dut, 1);
4939 dut->config_rsnie = 1;
4940 }
4941#endif /* NL80211_SUPPORT */
4942 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
4943 dut->rsne_override);
4944 if (wpa_command(intf, buf) < 0) {
4945 send_resp(dut, conn, SIGMA_ERROR,
4946 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
4947 return 0;
4948 }
4949 }
4950
Sunil Duttd30ce092018-01-11 23:56:29 +05304951 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004952#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05304953 if (chan) {
4954 unsigned int freq;
4955
4956 freq = channel_to_freq(chan);
4957 if (!freq) {
4958 sigma_dut_print(dut, DUT_MSG_ERROR,
4959 "Invalid channel number provided: %d",
4960 chan);
4961 send_resp(dut, conn, SIGMA_INVALID,
4962 "ErrorCode,Invalid channel number");
4963 goto close_mon_conn;
4964 }
4965 res = snprintf(buf, sizeof(buf),
4966 "SCAN TYPE=ONLY freq=%d", freq);
4967 } else {
4968 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
4969 }
4970 if (res < 0 || res >= (int) sizeof(buf)) {
4971 send_resp(dut, conn, SIGMA_ERROR,
4972 "ErrorCode,snprintf failed");
4973 goto close_mon_conn;
4974 }
4975 if (wpa_command(intf, buf) < 0) {
4976 sigma_dut_print(dut, DUT_MSG_INFO,
4977 "Failed to start scan");
4978 send_resp(dut, conn, SIGMA_ERROR,
4979 "ErrorCode,scan failed");
4980 goto close_mon_conn;
4981 }
4982
4983 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
4984 buf, sizeof(buf));
4985 if (res < 0) {
4986 sigma_dut_print(dut, DUT_MSG_INFO,
4987 "Scan did not complete");
4988 send_resp(dut, conn, SIGMA_ERROR,
4989 "ErrorCode,scan did not complete");
4990 goto close_mon_conn;
4991 }
4992
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004993 if (set_network(intf, dut->infra_network_id, "bssid", "any")
4994 < 0) {
4995 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
4996 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05304997 status = -2;
4998 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004999 }
5000 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5001 bssid, chan);
5002 if (res > 0 && res < (int) sizeof(buf))
5003 res = wpa_command(intf, buf);
5004
5005 if (res < 0 || res >= (int) sizeof(buf)) {
5006 send_resp(dut, conn, SIGMA_ERROR,
5007 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305008 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005009 }
5010#else /* ANDROID */
5011 sigma_dut_print(dut, DUT_MSG_DEBUG,
5012 "Reassoc using iwpriv - skip chan=%d info",
5013 chan);
5014 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5015 if (system(buf) != 0) {
5016 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305017 status = -2;
5018 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005019 }
5020#endif /* ANDROID */
5021 sigma_dut_print(dut, DUT_MSG_INFO,
5022 "sta_reassoc: Run %s successful", buf);
5023 } else if (wpa_command(intf, "REASSOCIATE")) {
5024 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5025 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305026 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005027 }
5028
5029 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5030 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305031 if (res < 0) {
5032 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5033 status = -1;
5034 goto close_mon_conn;
5035 }
5036 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005037
Ashwini Patil467efef2017-05-25 12:18:27 +05305038close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005039 wpa_ctrl_detach(ctrl);
5040 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305041 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005042}
5043
5044
5045static void hs2_clear_credentials(const char *intf)
5046{
5047 wpa_command(intf, "REMOVE_CRED all");
5048}
5049
5050
Lior Davidcc88b562017-01-03 18:52:09 +02005051#ifdef __linux__
5052static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5053 unsigned int *aid)
5054{
Lior David0fe101e2017-03-09 16:09:50 +02005055 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005056
Lior David0fe101e2017-03-09 16:09:50 +02005057 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005058}
5059#endif /* __linux__ */
5060
5061
5062static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5063 unsigned int *aid)
5064{
5065 switch (get_driver_type()) {
5066#ifdef __linux__
5067 case DRIVER_WIL6210:
5068 return wil6210_get_aid(dut, bssid, aid);
5069#endif /* __linux__ */
5070 default:
5071 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5072 return -1;
5073 }
5074}
5075
5076
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005077static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5078 struct sigma_cmd *cmd)
5079{
5080 char buf[MAX_CMD_LEN];
5081 char bss_list[MAX_CMD_LEN];
5082 const char *parameter = get_param(cmd, "Parameter");
5083
5084 if (parameter == NULL)
5085 return -1;
5086
Lior Davidcc88b562017-01-03 18:52:09 +02005087 if (strcasecmp(parameter, "AID") == 0) {
5088 unsigned int aid = 0;
5089 char bssid[20];
5090
5091 if (get_wpa_status(get_station_ifname(), "bssid",
5092 bssid, sizeof(bssid)) < 0) {
5093 sigma_dut_print(dut, DUT_MSG_ERROR,
5094 "could not get bssid");
5095 return -2;
5096 }
5097
5098 if (sta_get_aid_60g(dut, bssid, &aid))
5099 return -2;
5100
5101 snprintf(buf, sizeof(buf), "aid,%d", aid);
5102 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5103 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5104 return 0;
5105 }
5106
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005107 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5108 char *bss_line;
5109 char *bss_id = NULL;
5110 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305111 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005112
5113 if (ifname == NULL) {
5114 sigma_dut_print(dut, DUT_MSG_INFO,
5115 "For get DiscoveredDevList need Interface name.");
5116 return -1;
5117 }
5118
5119 /*
5120 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5121 * of BSSIDs in "bssid=<BSSID>\n"
5122 */
5123 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5124 bss_list,
5125 sizeof(bss_list)) < 0) {
5126 sigma_dut_print(dut, DUT_MSG_ERROR,
5127 "Failed to get bss list");
5128 return -1;
5129 }
5130
5131 sigma_dut_print(dut, DUT_MSG_DEBUG,
5132 "bss list for ifname:%s is:%s",
5133 ifname, bss_list);
5134
5135 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305136 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005137 while (bss_line) {
5138 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5139 bss_id) {
5140 int len;
5141
5142 len = snprintf(buf + strlen(buf),
5143 sizeof(buf) - strlen(buf),
5144 ",%s", bss_id);
5145 free(bss_id);
5146 bss_id = NULL;
5147 if (len < 0) {
5148 sigma_dut_print(dut,
5149 DUT_MSG_ERROR,
5150 "Failed to read BSSID");
5151 send_resp(dut, conn, SIGMA_ERROR,
5152 "ErrorCode,Failed to read BSS ID");
5153 return 0;
5154 }
5155
5156 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5157 sigma_dut_print(dut,
5158 DUT_MSG_ERROR,
5159 "Response buf too small for list");
5160 send_resp(dut, conn,
5161 SIGMA_ERROR,
5162 "ErrorCode,Response buf too small for list");
5163 return 0;
5164 }
5165 }
5166
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305167 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 }
5169
5170 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5171 buf);
5172 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5173 return 0;
5174 }
5175
5176 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5177 return 0;
5178}
5179
5180
5181static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5182 struct sigma_cmd *cmd)
5183{
5184 const char *program = get_param(cmd, "Program");
5185
5186 if (program == NULL)
5187 return -1;
5188
5189 if (strcasecmp(program, "P2PNFC") == 0)
5190 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5191
5192 if (strcasecmp(program, "60ghz") == 0)
5193 return sta_get_parameter_60g(dut, conn, cmd);
5194
5195#ifdef ANDROID_NAN
5196 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005197 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005198#endif /* ANDROID_NAN */
5199
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005200#ifdef MIRACAST
5201 if (strcasecmp(program, "WFD") == 0 ||
5202 strcasecmp(program, "DisplayR2") == 0)
5203 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5204#endif /* MIRACAST */
5205
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005206 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5207 return 0;
5208}
5209
5210
5211static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5212 const char *type)
5213{
5214 char buf[100];
5215
5216 if (dut->program == PROGRAM_VHT) {
5217 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5218 if (system(buf) != 0) {
5219 sigma_dut_print(dut, DUT_MSG_ERROR,
5220 "iwpriv %s chwidth failed", intf);
5221 }
5222
5223 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5224 if (system(buf) != 0) {
5225 sigma_dut_print(dut, DUT_MSG_ERROR,
5226 "iwpriv %s mode 11ACVHT80 failed",
5227 intf);
5228 }
5229
5230 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5231 if (system(buf) != 0) {
5232 sigma_dut_print(dut, DUT_MSG_ERROR,
5233 "iwpriv %s vhtmcs -1 failed", intf);
5234 }
5235 }
5236
5237 if (dut->program == PROGRAM_HT) {
5238 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5239 if (system(buf) != 0) {
5240 sigma_dut_print(dut, DUT_MSG_ERROR,
5241 "iwpriv %s chwidth failed", intf);
5242 }
5243
5244 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5245 if (system(buf) != 0) {
5246 sigma_dut_print(dut, DUT_MSG_ERROR,
5247 "iwpriv %s mode 11naht40 failed",
5248 intf);
5249 }
5250
5251 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5252 if (system(buf) != 0) {
5253 sigma_dut_print(dut, DUT_MSG_ERROR,
5254 "iwpriv set11NRates failed");
5255 }
5256 }
5257
5258 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5259 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5260 if (system(buf) != 0) {
5261 sigma_dut_print(dut, DUT_MSG_ERROR,
5262 "disabling powersave failed");
5263 }
5264
5265 /* Reset CTS width */
5266 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5267 intf);
5268 if (system(buf) != 0) {
5269 sigma_dut_print(dut, DUT_MSG_ERROR,
5270 "wifitool %s beeliner_fw_test 54 0 failed",
5271 intf);
5272 }
5273
5274 /* Enable Dynamic Bandwidth signalling by default */
5275 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5276 if (system(buf) != 0) {
5277 sigma_dut_print(dut, DUT_MSG_ERROR,
5278 "iwpriv %s cwmenable 1 failed", intf);
5279 }
5280
5281 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5282 if (system(buf) != 0) {
5283 sigma_dut_print(dut, DUT_MSG_ERROR,
5284 "iwpriv rts failed");
5285 }
5286 }
5287
5288 if (type && strcasecmp(type, "Testbed") == 0) {
5289 dut->testbed_flag_txsp = 1;
5290 dut->testbed_flag_rxsp = 1;
5291 /* STA has to set spatial stream to 2 per Appendix H */
5292 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5293 if (system(buf) != 0) {
5294 sigma_dut_print(dut, DUT_MSG_ERROR,
5295 "iwpriv vht_mcsmap failed");
5296 }
5297
5298 /* Disable LDPC per Appendix H */
5299 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5300 if (system(buf) != 0) {
5301 sigma_dut_print(dut, DUT_MSG_ERROR,
5302 "iwpriv %s ldpc 0 failed", intf);
5303 }
5304
5305 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5306 if (system(buf) != 0) {
5307 sigma_dut_print(dut, DUT_MSG_ERROR,
5308 "iwpriv amsdu failed");
5309 }
5310
5311 /* TODO: Disable STBC 2x1 transmit and receive */
5312 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5313 if (system(buf) != 0) {
5314 sigma_dut_print(dut, DUT_MSG_ERROR,
5315 "Disable tx_stbc 0 failed");
5316 }
5317
5318 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5319 if (system(buf) != 0) {
5320 sigma_dut_print(dut, DUT_MSG_ERROR,
5321 "Disable rx_stbc 0 failed");
5322 }
5323
5324 /* STA has to disable Short GI per Appendix H */
5325 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5326 if (system(buf) != 0) {
5327 sigma_dut_print(dut, DUT_MSG_ERROR,
5328 "iwpriv %s shortgi 0 failed", intf);
5329 }
5330 }
5331
5332 if (type && strcasecmp(type, "DUT") == 0) {
5333 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5334 if (system(buf) != 0) {
5335 sigma_dut_print(dut, DUT_MSG_ERROR,
5336 "iwpriv %s nss 3 failed", intf);
5337 }
5338
5339 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5340 if (system(buf) != 0) {
5341 sigma_dut_print(dut, DUT_MSG_ERROR,
5342 "iwpriv %s shortgi 1 failed", intf);
5343 }
5344 }
5345}
5346
5347
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005348#ifdef NL80211_SUPPORT
5349static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5350 enum he_mcs_config mcs)
5351{
5352 struct nl_msg *msg;
5353 int ret = 0;
5354 struct nlattr *params;
5355 int ifindex;
5356
5357 ifindex = if_nametoindex(intf);
5358 if (ifindex == 0) {
5359 sigma_dut_print(dut, DUT_MSG_ERROR,
5360 "%s: Index for interface %s failed",
5361 __func__, intf);
5362 return -1;
5363 }
5364
5365 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5366 NL80211_CMD_VENDOR)) ||
5367 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5368 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5369 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5370 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5371 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5372 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5373 mcs)) {
5374 sigma_dut_print(dut, DUT_MSG_ERROR,
5375 "%s: err in adding vendor_cmd and vendor_data",
5376 __func__);
5377 nlmsg_free(msg);
5378 return -1;
5379 }
5380 nla_nest_end(msg, params);
5381
5382 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5383 if (ret) {
5384 sigma_dut_print(dut, DUT_MSG_ERROR,
5385 "%s: err in send_and_recv_msgs, ret=%d",
5386 __func__, ret);
5387 }
5388 return ret;
5389}
5390#endif /* NL80211_SUPPORT */
5391
5392
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005393static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5394 const char *type)
5395{
5396 char buf[60];
5397
5398 if (dut->program == PROGRAM_HE) {
5399 /* resetting phymode to auto in case of HE program */
5400 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5401 if (system(buf) != 0) {
5402 sigma_dut_print(dut, DUT_MSG_ERROR,
5403 "iwpriv %s setphymode failed", intf);
5404 }
5405
5406 /* remove all network profiles */
5407 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005408
5409 /* Set nss to 1 and MCS 0-7 in case of testbed */
5410 if (type && strcasecmp(type, "Testbed") == 0) {
5411#ifdef NL80211_SUPPORT
5412 int ret;
5413#endif /* NL80211_SUPPORT */
5414
5415 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5416 if (system(buf) != 0) {
5417 sigma_dut_print(dut, DUT_MSG_ERROR,
5418 "iwpriv %s nss failed", intf);
5419 }
5420
5421#ifdef NL80211_SUPPORT
5422 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5423 if (ret) {
5424 sigma_dut_print(dut, DUT_MSG_ERROR,
5425 "Setting of MCS failed, ret:%d",
5426 ret);
5427 }
5428#endif /* NL80211_SUPPORT */
5429 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005430 }
5431}
5432
5433
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005434static int cmd_sta_reset_default(struct sigma_dut *dut,
5435 struct sigma_conn *conn,
5436 struct sigma_cmd *cmd)
5437{
5438 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5439 struct sigma_cmd *cmd);
5440 const char *intf = get_param(cmd, "Interface");
5441 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005442 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305443 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005444
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005445 if (!program)
5446 program = get_param(cmd, "prog");
5447 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005448 dut->device_type = STA_unknown;
5449 type = get_param(cmd, "type");
5450 if (type && strcasecmp(type, "Testbed") == 0)
5451 dut->device_type = STA_testbed;
5452 if (type && strcasecmp(type, "DUT") == 0)
5453 dut->device_type = STA_dut;
5454
5455 if (dut->program == PROGRAM_TDLS) {
5456 /* Clear TDLS testing mode */
5457 wpa_command(intf, "SET tdls_disabled 0");
5458 wpa_command(intf, "SET tdls_testing 0");
5459 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305460 if (get_driver_type() == DRIVER_WCN) {
5461 /* Enable the WCN driver in TDLS Explicit trigger mode
5462 */
5463 wpa_command(intf, "SET tdls_external_control 0");
5464 wpa_command(intf, "SET tdls_trigger_control 0");
5465 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005466 }
5467
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005468#ifdef MIRACAST
5469 if (dut->program == PROGRAM_WFD ||
5470 dut->program == PROGRAM_DISPLAYR2)
5471 miracast_sta_reset_default(dut, conn, cmd);
5472#endif /* MIRACAST */
5473
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005474 switch (get_driver_type()) {
5475 case DRIVER_ATHEROS:
5476 sta_reset_default_ath(dut, intf, type);
5477 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005478 case DRIVER_WCN:
5479 sta_reset_default_wcn(dut, intf, type);
5480 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005481 default:
5482 break;
5483 }
5484
5485#ifdef ANDROID_NAN
5486 if (dut->program == PROGRAM_NAN)
5487 nan_cmd_sta_reset_default(dut, conn, cmd);
5488#endif /* ANDROID_NAN */
5489
5490 if (dut->program == PROGRAM_HS2_R2) {
5491 unlink("SP/wi-fi.org/pps.xml");
5492 if (system("rm -r SP/*") != 0) {
5493 }
5494 unlink("next-client-cert.pem");
5495 unlink("next-client-key.pem");
5496 }
5497
5498 if (dut->program == PROGRAM_60GHZ) {
5499 const char *dev_role = get_param(cmd, "DevRole");
5500
5501 if (!dev_role) {
5502 send_resp(dut, conn, SIGMA_ERROR,
5503 "errorCode,Missing DevRole argument");
5504 return 0;
5505 }
5506
5507 if (strcasecmp(dev_role, "STA") == 0)
5508 dut->dev_role = DEVROLE_STA;
5509 else if (strcasecmp(dev_role, "PCP") == 0)
5510 dut->dev_role = DEVROLE_PCP;
5511 else {
5512 send_resp(dut, conn, SIGMA_ERROR,
5513 "errorCode,Unknown DevRole");
5514 return 0;
5515 }
5516
5517 if (dut->device_type == STA_unknown) {
5518 sigma_dut_print(dut, DUT_MSG_ERROR,
5519 "Device type is not STA testbed or DUT");
5520 send_resp(dut, conn, SIGMA_ERROR,
5521 "errorCode,Unknown device type");
5522 return 0;
5523 }
5524 }
5525
5526 wpa_command(intf, "WPS_ER_STOP");
5527 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305528 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005529 wpa_command(intf, "SET radio_disabled 0");
5530
5531 if (dut->tmp_mac_addr && dut->set_macaddr) {
5532 dut->tmp_mac_addr = 0;
5533 if (system(dut->set_macaddr) != 0) {
5534 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5535 "temporary MAC address");
5536 }
5537 }
5538
5539 set_ps(intf, dut, 0);
5540
5541 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5542 wpa_command(intf, "SET interworking 1");
5543 wpa_command(intf, "SET hs20 1");
5544 }
5545
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08005546 if (dut->program == PROGRAM_HS2_R2 ||
5547 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005548 wpa_command(intf, "SET pmf 1");
5549 } else {
5550 wpa_command(intf, "SET pmf 0");
5551 }
5552
5553 hs2_clear_credentials(intf);
5554 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
5555 wpa_command(intf, "SET access_network_type 15");
5556
5557 static_ip_file(0, NULL, NULL, NULL);
5558 kill_dhcp_client(dut, intf);
5559 clear_ip_addr(dut, intf);
5560
5561 dut->er_oper_performed = 0;
5562 dut->er_oper_bssid[0] = '\0';
5563
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07005564 if (dut->program == PROGRAM_LOC) {
5565 /* Disable Interworking by default */
5566 wpa_command(get_station_ifname(), "SET interworking 0");
5567 }
5568
Ashwini Patil00402582017-04-13 12:29:39 +05305569 if (dut->program == PROGRAM_MBO) {
5570 free(dut->non_pref_ch_list);
5571 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05305572 free(dut->btm_query_cand_list);
5573 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05305574 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05305575 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05305576 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305577 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05305578 }
5579
Jouni Malinen3c367e82017-06-23 17:01:47 +03005580 free(dut->rsne_override);
5581 dut->rsne_override = NULL;
5582
Jouni Malinen68143132017-09-02 02:34:08 +03005583 free(dut->sae_commit_override);
5584 dut->sae_commit_override = NULL;
5585
Jouni Malinend86e5822017-08-29 03:55:32 +03005586 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02005587 free(dut->dpp_peer_uri);
5588 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02005589 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02005590 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03005591
Jouni Malinenfac9cad2017-10-10 18:35:55 +03005592 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
5593
vamsi krishnaa2799492017-12-05 14:28:01 +05305594 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305595 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05305596 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305597 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
5598 dut->fils_hlp = 0;
5599#ifdef ANDROID
5600 hlp_thread_cleanup(dut);
5601#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05305602 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305603
Sunil Dutt076081f2018-02-05 19:45:50 +05305604#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05305605 if (get_driver_type() == DRIVER_WCN &&
5606 dut->config_rsnie == 1) {
5607 dut->config_rsnie = 0;
5608 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05305609 }
5610#endif /* NL80211_SUPPORT */
5611
Sunil Duttfebf8a82018-02-09 18:50:13 +05305612 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
5613 dut->dev_role = DEVROLE_STA_CFON;
5614 return sta_cfon_reset_default(dut, conn, cmd);
5615 }
5616
5617 if (dut->program != PROGRAM_VHT)
5618 return cmd_sta_p2p_reset(dut, conn, cmd);
5619
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08005620 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005621}
5622
5623
5624static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
5625 struct sigma_cmd *cmd)
5626{
5627 const char *program = get_param(cmd, "Program");
5628
5629 if (program == NULL)
5630 return -1;
5631#ifdef ANDROID_NAN
5632 if (strcasecmp(program, "NAN") == 0)
5633 return nan_cmd_sta_get_events(dut, conn, cmd);
5634#endif /* ANDROID_NAN */
5635 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5636 return 0;
5637}
5638
5639
5640static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
5641 struct sigma_cmd *cmd)
5642{
5643 const char *program = get_param(cmd, "Prog");
5644
5645 if (program == NULL)
5646 return -1;
5647#ifdef ANDROID_NAN
5648 if (strcasecmp(program, "NAN") == 0)
5649 return nan_cmd_sta_exec_action(dut, conn, cmd);
5650#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005651 if (strcasecmp(program, "Loc") == 0)
5652 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005653 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5654 return 0;
5655}
5656
5657
5658static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
5659 struct sigma_cmd *cmd)
5660{
5661 const char *intf = get_param(cmd, "Interface");
5662 const char *val, *mcs32, *rate;
5663
5664 val = get_param(cmd, "GREENFIELD");
5665 if (val) {
5666 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5667 /* Enable GD */
5668 send_resp(dut, conn, SIGMA_ERROR,
5669 "ErrorCode,GF not supported");
5670 return 0;
5671 }
5672 }
5673
5674 val = get_param(cmd, "SGI20");
5675 if (val) {
5676 switch (get_driver_type()) {
5677 case DRIVER_ATHEROS:
5678 ath_sta_set_sgi(dut, intf, val);
5679 break;
5680 default:
5681 send_resp(dut, conn, SIGMA_ERROR,
5682 "ErrorCode,SGI20 not supported");
5683 return 0;
5684 }
5685 }
5686
5687 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
5688 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
5689 if (mcs32 && rate) {
5690 /* TODO */
5691 send_resp(dut, conn, SIGMA_ERROR,
5692 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
5693 return 0;
5694 } else if (mcs32 && !rate) {
5695 /* TODO */
5696 send_resp(dut, conn, SIGMA_ERROR,
5697 "ErrorCode,MCS32 not supported");
5698 return 0;
5699 } else if (!mcs32 && rate) {
5700 switch (get_driver_type()) {
5701 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005702 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005703 ath_sta_set_11nrates(dut, intf, rate);
5704 break;
5705 default:
5706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,MCS32_FIXEDRATE not supported");
5708 return 0;
5709 }
5710 }
5711
5712 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5713}
5714
5715
5716static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
5717 struct sigma_conn *conn,
5718 struct sigma_cmd *cmd)
5719{
5720 const char *intf = get_param(cmd, "Interface");
5721 const char *val;
5722 char buf[30];
5723 int tkip = -1;
5724 int wep = -1;
5725
5726 val = get_param(cmd, "SGI80");
5727 if (val) {
5728 int sgi80;
5729
5730 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5731 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
5732 if (system(buf) != 0) {
5733 sigma_dut_print(dut, DUT_MSG_ERROR,
5734 "iwpriv shortgi failed");
5735 }
5736 }
5737
5738 val = get_param(cmd, "TxBF");
5739 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5740 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
5741 if (system(buf) != 0) {
5742 sigma_dut_print(dut, DUT_MSG_ERROR,
5743 "iwpriv vhtsubfee failed");
5744 }
5745 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
5746 if (system(buf) != 0) {
5747 sigma_dut_print(dut, DUT_MSG_ERROR,
5748 "iwpriv vhtsubfer failed");
5749 }
5750 }
5751
5752 val = get_param(cmd, "MU_TxBF");
5753 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5754 switch (get_driver_type()) {
5755 case DRIVER_ATHEROS:
5756 ath_sta_set_txsp_stream(dut, intf, "1SS");
5757 ath_sta_set_rxsp_stream(dut, intf, "1SS");
5758 case DRIVER_WCN:
5759 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
5760 send_resp(dut, conn, SIGMA_ERROR,
5761 "ErrorCode,Failed to set RX/TXSP_STREAM");
5762 return 0;
5763 }
5764 default:
5765 sigma_dut_print(dut, DUT_MSG_ERROR,
5766 "Setting SP_STREAM not supported");
5767 break;
5768 }
5769 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
5770 if (system(buf) != 0) {
5771 sigma_dut_print(dut, DUT_MSG_ERROR,
5772 "iwpriv vhtmubfee failed");
5773 }
5774 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
5775 if (system(buf) != 0) {
5776 sigma_dut_print(dut, DUT_MSG_ERROR,
5777 "iwpriv vhtmubfer failed");
5778 }
5779 }
5780
5781 val = get_param(cmd, "LDPC");
5782 if (val) {
5783 int ldpc;
5784
5785 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5786 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
5787 if (system(buf) != 0) {
5788 sigma_dut_print(dut, DUT_MSG_ERROR,
5789 "iwpriv ldpc failed");
5790 }
5791 }
5792
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08005793 val = get_param(cmd, "BCC");
5794 if (val) {
5795 int bcc;
5796
5797 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5798 /* use LDPC iwpriv itself to set bcc coding, bcc coding
5799 * is mutually exclusive to bcc */
5800 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
5801 if (system(buf) != 0) {
5802 sigma_dut_print(dut, DUT_MSG_ERROR,
5803 "Enabling/Disabling of BCC failed");
5804 }
5805 }
5806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005807 val = get_param(cmd, "opt_md_notif_ie");
5808 if (val) {
5809 char *result = NULL;
5810 char delim[] = ";";
5811 char token[30];
5812 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305813 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814
Peng Xub8fc5cc2017-05-10 17:27:28 -07005815 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305816 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005817
5818 /* Extract the NSS information */
5819 if (result) {
5820 value = atoi(result);
5821 switch (value) {
5822 case 1:
5823 config_val = 1;
5824 break;
5825 case 2:
5826 config_val = 3;
5827 break;
5828 case 3:
5829 config_val = 7;
5830 break;
5831 case 4:
5832 config_val = 15;
5833 break;
5834 default:
5835 config_val = 3;
5836 break;
5837 }
5838
5839 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
5840 intf, config_val);
5841 if (system(buf) != 0) {
5842 sigma_dut_print(dut, DUT_MSG_ERROR,
5843 "iwpriv rxchainmask failed");
5844 }
5845
5846 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
5847 intf, config_val);
5848 if (system(buf) != 0) {
5849 sigma_dut_print(dut, DUT_MSG_ERROR,
5850 "iwpriv txchainmask failed");
5851 }
5852 }
5853
5854 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305855 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005856 if (result) {
5857 value = atoi(result);
5858 switch (value) {
5859 case 20:
5860 config_val = 0;
5861 break;
5862 case 40:
5863 config_val = 1;
5864 break;
5865 case 80:
5866 config_val = 2;
5867 break;
5868 case 160:
5869 config_val = 3;
5870 break;
5871 default:
5872 config_val = 2;
5873 break;
5874 }
5875
5876 dut->chwidth = config_val;
5877
5878 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5879 intf, config_val);
5880 if (system(buf) != 0) {
5881 sigma_dut_print(dut, DUT_MSG_ERROR,
5882 "iwpriv chwidth failed");
5883 }
5884 }
5885
5886 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
5887 if (system(buf) != 0) {
5888 sigma_dut_print(dut, DUT_MSG_ERROR,
5889 "iwpriv opmode_notify failed");
5890 }
5891 }
5892
5893 val = get_param(cmd, "nss_mcs_cap");
5894 if (val) {
5895 int nss, mcs;
5896 char token[20];
5897 char *result = NULL;
5898 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305899 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005900
Peng Xub8fc5cc2017-05-10 17:27:28 -07005901 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305902 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305903 if (!result) {
5904 sigma_dut_print(dut, DUT_MSG_ERROR,
5905 "VHT NSS not specified");
5906 return 0;
5907 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005908 nss = atoi(result);
5909
5910 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
5911 if (system(buf) != 0) {
5912 sigma_dut_print(dut, DUT_MSG_ERROR,
5913 "iwpriv nss failed");
5914 }
5915
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305916 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005917 if (result == NULL) {
5918 sigma_dut_print(dut, DUT_MSG_ERROR,
5919 "VHTMCS NOT SPECIFIED!");
5920 return 0;
5921 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305922 result = strtok_r(result, "-", &saveptr);
5923 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305924 if (!result) {
5925 sigma_dut_print(dut, DUT_MSG_ERROR,
5926 "VHT MCS not specified");
5927 return 0;
5928 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929 mcs = atoi(result);
5930
5931 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
5932 if (system(buf) != 0) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR,
5934 "iwpriv mcs failed");
5935 }
5936
5937 switch (nss) {
5938 case 1:
5939 switch (mcs) {
5940 case 7:
5941 vht_mcsmap = 0xfffc;
5942 break;
5943 case 8:
5944 vht_mcsmap = 0xfffd;
5945 break;
5946 case 9:
5947 vht_mcsmap = 0xfffe;
5948 break;
5949 default:
5950 vht_mcsmap = 0xfffe;
5951 break;
5952 }
5953 break;
5954 case 2:
5955 switch (mcs) {
5956 case 7:
5957 vht_mcsmap = 0xfff0;
5958 break;
5959 case 8:
5960 vht_mcsmap = 0xfff5;
5961 break;
5962 case 9:
5963 vht_mcsmap = 0xfffa;
5964 break;
5965 default:
5966 vht_mcsmap = 0xfffa;
5967 break;
5968 }
5969 break;
5970 case 3:
5971 switch (mcs) {
5972 case 7:
5973 vht_mcsmap = 0xffc0;
5974 break;
5975 case 8:
5976 vht_mcsmap = 0xffd5;
5977 break;
5978 case 9:
5979 vht_mcsmap = 0xffea;
5980 break;
5981 default:
5982 vht_mcsmap = 0xffea;
5983 break;
5984 }
5985 break;
5986 default:
5987 vht_mcsmap = 0xffea;
5988 break;
5989 }
5990 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5991 intf, vht_mcsmap);
5992 if (system(buf) != 0) {
5993 sigma_dut_print(dut, DUT_MSG_ERROR,
5994 "iwpriv vht_mcsmap failed");
5995 }
5996 }
5997
5998 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
5999
6000 val = get_param(cmd, "Vht_tkip");
6001 if (val)
6002 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6003
6004 val = get_param(cmd, "Vht_wep");
6005 if (val)
6006 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6007
6008 if (tkip != -1 || wep != -1) {
6009 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
6010 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
6011 intf);
6012 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
6013 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
6014 intf);
6015 } else {
6016 sigma_dut_print(dut, DUT_MSG_ERROR,
6017 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
6018 return 0;
6019 }
6020
6021 if (system(buf) != 0) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "iwpriv htweptkip failed");
6024 }
6025 }
6026
6027 val = get_param(cmd, "txBandwidth");
6028 if (val) {
6029 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006030 case DRIVER_WCN:
6031 if (wcn_sta_set_width(dut, intf, val) < 0) {
6032 send_resp(dut, conn, SIGMA_ERROR,
6033 "ErrorCode,Failed to set txBandwidth");
6034 return 0;
6035 }
6036 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006037 case DRIVER_ATHEROS:
6038 if (ath_set_width(dut, conn, intf, val) < 0) {
6039 send_resp(dut, conn, SIGMA_ERROR,
6040 "ErrorCode,Failed to set txBandwidth");
6041 return 0;
6042 }
6043 break;
6044 default:
6045 sigma_dut_print(dut, DUT_MSG_ERROR,
6046 "Setting txBandwidth not supported");
6047 break;
6048 }
6049 }
6050
6051 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6052}
6053
6054
6055static int sta_set_wireless_60g(struct sigma_dut *dut,
6056 struct sigma_conn *conn,
6057 struct sigma_cmd *cmd)
6058{
6059 const char *dev_role = get_param(cmd, "DevRole");
6060
6061 if (!dev_role) {
6062 send_resp(dut, conn, SIGMA_INVALID,
6063 "ErrorCode,DevRole not specified");
6064 return 0;
6065 }
6066
6067 if (strcasecmp(dev_role, "PCP") == 0)
6068 return sta_set_60g_pcp(dut, conn, cmd);
6069 if (strcasecmp(dev_role, "STA") == 0)
6070 return sta_set_60g_sta(dut, conn, cmd);
6071 send_resp(dut, conn, SIGMA_INVALID,
6072 "ErrorCode,DevRole not supported");
6073 return 0;
6074}
6075
6076
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306077static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
6078 struct sigma_cmd *cmd)
6079{
6080 int status;
6081 const char *intf = get_param(cmd, "Interface");
6082 const char *val = get_param(cmd, "DevRole");
6083
6084 if (val && strcasecmp(val, "STA-CFON") == 0) {
6085 status = sta_cfon_set_wireless(dut, conn, cmd);
6086 if (status)
6087 return status;
6088 }
6089 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6090}
6091
6092
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6094 struct sigma_cmd *cmd)
6095{
6096 const char *val;
6097
6098 val = get_param(cmd, "Program");
6099 if (val) {
6100 if (strcasecmp(val, "11n") == 0)
6101 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006102 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6104 if (strcasecmp(val, "60ghz") == 0)
6105 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306106 if (strcasecmp(val, "OCE") == 0)
6107 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006108 send_resp(dut, conn, SIGMA_ERROR,
6109 "ErrorCode,Program value not supported");
6110 } else {
6111 send_resp(dut, conn, SIGMA_ERROR,
6112 "ErrorCode,Program argument not available");
6113 }
6114
6115 return 0;
6116}
6117
6118
6119static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6120 int tid)
6121{
6122 char buf[100];
6123 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6124
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306125 if (tid < 0 ||
6126 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6128 return;
6129 }
6130
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006131 /*
6132 * Two ways to ensure that addba request with a
6133 * non zero TID could be sent out. EV 117296
6134 */
6135 snprintf(buf, sizeof(buf),
6136 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6137 tid);
6138 if (system(buf) != 0) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR,
6140 "Ping did not send out");
6141 }
6142
6143 snprintf(buf, sizeof(buf),
6144 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6145 intf, VI_QOS_TMP_FILE);
6146 if (system(buf) != 0)
6147 return;
6148
6149 snprintf(buf, sizeof(buf),
6150 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6151 intf, VI_QOS_TMP_FILE);
6152 if (system(buf) != 0)
6153 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6154
6155 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6156 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6157 if (system(buf) != 0) {
6158 sigma_dut_print(dut, DUT_MSG_ERROR,
6159 "VI_QOS_TEMP_FILE generation error failed");
6160 }
6161 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6162 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6163 if (system(buf) != 0) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "VI_QOS_FILE generation failed");
6166 }
6167
6168 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6169 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6170 if (system(buf) != 0) {
6171 sigma_dut_print(dut, DUT_MSG_ERROR,
6172 "VI_QOS_FILE generation failed");
6173 }
6174
6175 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6176 if (system(buf) != 0) {
6177 }
6178}
6179
6180
6181static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6182 struct sigma_cmd *cmd)
6183{
6184 const char *intf = get_param(cmd, "Interface");
6185 const char *val;
6186 int tid = 0;
6187 char buf[100];
6188
6189 val = get_param(cmd, "TID");
6190 if (val) {
6191 tid = atoi(val);
6192 if (tid)
6193 ath_sta_inject_frame(dut, intf, tid);
6194 }
6195
6196 /* Command sequence for ADDBA request on Peregrine based devices */
6197 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6198 if (system(buf) != 0) {
6199 sigma_dut_print(dut, DUT_MSG_ERROR,
6200 "iwpriv setaddbaoper failed");
6201 }
6202
6203 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6204 if (system(buf) != 0) {
6205 sigma_dut_print(dut, DUT_MSG_ERROR,
6206 "wifitool senddelba failed");
6207 }
6208
6209 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6210 if (system(buf) != 0) {
6211 sigma_dut_print(dut, DUT_MSG_ERROR,
6212 "wifitool sendaddba failed");
6213 }
6214
6215 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6216
6217 return 1;
6218}
6219
6220
Lior David9981b512017-01-20 13:16:40 +02006221#ifdef __linux__
6222
6223static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6224 int agg_size)
6225{
6226 char dir[128], buf[128];
6227 FILE *f;
6228 regex_t re;
6229 regmatch_t m[2];
6230 int rc, ret = -1, vring_id, found;
6231
6232 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6233 sigma_dut_print(dut, DUT_MSG_ERROR,
6234 "failed to get wil6210 debugfs dir");
6235 return -1;
6236 }
6237
6238 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6239 f = fopen(buf, "r");
6240 if (!f) {
6241 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6242 return -1;
6243 }
6244
6245 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6246 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6247 goto out;
6248 }
6249
6250 /* find TX VRING for the mac address */
6251 found = 0;
6252 while (fgets(buf, sizeof(buf), f)) {
6253 if (strcasestr(buf, dest_mac)) {
6254 found = 1;
6255 break;
6256 }
6257 }
6258
6259 if (!found) {
6260 sigma_dut_print(dut, DUT_MSG_ERROR,
6261 "no TX VRING for %s", dest_mac);
6262 goto out;
6263 }
6264
6265 /* extract VRING ID, "VRING tx_<id> = {" */
6266 if (!fgets(buf, sizeof(buf), f)) {
6267 sigma_dut_print(dut, DUT_MSG_ERROR,
6268 "no VRING start line for %s", dest_mac);
6269 goto out;
6270 }
6271
6272 rc = regexec(&re, buf, 2, m, 0);
6273 regfree(&re);
6274 if (rc || m[1].rm_so < 0) {
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "no VRING TX ID for %s", dest_mac);
6277 goto out;
6278 }
6279 buf[m[1].rm_eo] = 0;
6280 vring_id = atoi(&buf[m[1].rm_so]);
6281
6282 /* send the addba command */
6283 fclose(f);
6284 snprintf(buf, sizeof(buf), "%s/back", dir);
6285 f = fopen(buf, "w");
6286 if (!f) {
6287 sigma_dut_print(dut, DUT_MSG_ERROR,
6288 "failed to open: %s", buf);
6289 return -1;
6290 }
6291
6292 fprintf(f, "add %d %d\n", vring_id, agg_size);
6293
6294 ret = 0;
6295
6296out:
6297 fclose(f);
6298
6299 return ret;
6300}
6301
6302
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006303static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6304 struct sigma_cmd *cmd)
6305{
6306 const char *val;
6307 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006308
6309 val = get_param(cmd, "TID");
6310 if (val) {
6311 tid = atoi(val);
6312 if (tid != 0) {
6313 sigma_dut_print(dut, DUT_MSG_ERROR,
6314 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6315 tid);
6316 }
6317 }
6318
6319 val = get_param(cmd, "Dest_mac");
6320 if (!val) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "Currently not supporting addba for 60G without Dest_mac");
6323 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6324 }
6325
Lior David9981b512017-01-20 13:16:40 +02006326 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006327 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006328
6329 return 1;
6330}
6331
Lior David9981b512017-01-20 13:16:40 +02006332#endif /* __linux__ */
6333
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006334
6335static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6336 struct sigma_cmd *cmd)
6337{
6338 switch (get_driver_type()) {
6339 case DRIVER_ATHEROS:
6340 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006341#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006342 case DRIVER_WIL6210:
6343 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006344#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006345 default:
6346 /*
6347 * There is no driver specific implementation for other drivers.
6348 * Ignore the command and report COMPLETE since the following
6349 * throughput test operation will end up sending ADDBA anyway.
6350 */
6351 return 1;
6352 }
6353}
6354
6355
6356int inject_eth_frame(int s, const void *data, size_t len,
6357 unsigned short ethtype, char *dst, char *src)
6358{
6359 struct iovec iov[4] = {
6360 {
6361 .iov_base = dst,
6362 .iov_len = ETH_ALEN,
6363 },
6364 {
6365 .iov_base = src,
6366 .iov_len = ETH_ALEN,
6367 },
6368 {
6369 .iov_base = &ethtype,
6370 .iov_len = sizeof(unsigned short),
6371 },
6372 {
6373 .iov_base = (void *) data,
6374 .iov_len = len,
6375 }
6376 };
6377 struct msghdr msg = {
6378 .msg_name = NULL,
6379 .msg_namelen = 0,
6380 .msg_iov = iov,
6381 .msg_iovlen = 4,
6382 .msg_control = NULL,
6383 .msg_controllen = 0,
6384 .msg_flags = 0,
6385 };
6386
6387 return sendmsg(s, &msg, 0);
6388}
6389
6390#if defined(__linux__) || defined(__QNXNTO__)
6391
6392int inject_frame(int s, const void *data, size_t len, int encrypt)
6393{
6394#define IEEE80211_RADIOTAP_F_WEP 0x04
6395#define IEEE80211_RADIOTAP_F_FRAG 0x08
6396 unsigned char rtap_hdr[] = {
6397 0x00, 0x00, /* radiotap version */
6398 0x0e, 0x00, /* radiotap length */
6399 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6400 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
6401 0x00, /* padding */
6402 0x00, 0x00, /* RX and TX flags to indicate that */
6403 0x00, 0x00, /* this is the injected frame directly */
6404 };
6405 struct iovec iov[2] = {
6406 {
6407 .iov_base = &rtap_hdr,
6408 .iov_len = sizeof(rtap_hdr),
6409 },
6410 {
6411 .iov_base = (void *) data,
6412 .iov_len = len,
6413 }
6414 };
6415 struct msghdr msg = {
6416 .msg_name = NULL,
6417 .msg_namelen = 0,
6418 .msg_iov = iov,
6419 .msg_iovlen = 2,
6420 .msg_control = NULL,
6421 .msg_controllen = 0,
6422 .msg_flags = 0,
6423 };
6424
6425 if (encrypt)
6426 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
6427
6428 return sendmsg(s, &msg, 0);
6429}
6430
6431
6432int open_monitor(const char *ifname)
6433{
6434#ifdef __QNXNTO__
6435 struct sockaddr_dl ll;
6436 int s;
6437
6438 memset(&ll, 0, sizeof(ll));
6439 ll.sdl_family = AF_LINK;
6440 ll.sdl_index = if_nametoindex(ifname);
6441 if (ll.sdl_index == 0) {
6442 perror("if_nametoindex");
6443 return -1;
6444 }
6445 s = socket(PF_INET, SOCK_RAW, 0);
6446#else /* __QNXNTO__ */
6447 struct sockaddr_ll ll;
6448 int s;
6449
6450 memset(&ll, 0, sizeof(ll));
6451 ll.sll_family = AF_PACKET;
6452 ll.sll_ifindex = if_nametoindex(ifname);
6453 if (ll.sll_ifindex == 0) {
6454 perror("if_nametoindex");
6455 return -1;
6456 }
6457 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
6458#endif /* __QNXNTO__ */
6459 if (s < 0) {
6460 perror("socket[PF_PACKET,SOCK_RAW]");
6461 return -1;
6462 }
6463
6464 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
6465 perror("monitor socket bind");
6466 close(s);
6467 return -1;
6468 }
6469
6470 return s;
6471}
6472
6473
6474static int hex2num(char c)
6475{
6476 if (c >= '0' && c <= '9')
6477 return c - '0';
6478 if (c >= 'a' && c <= 'f')
6479 return c - 'a' + 10;
6480 if (c >= 'A' && c <= 'F')
6481 return c - 'A' + 10;
6482 return -1;
6483}
6484
6485
6486int hwaddr_aton(const char *txt, unsigned char *addr)
6487{
6488 int i;
6489
6490 for (i = 0; i < 6; i++) {
6491 int a, b;
6492
6493 a = hex2num(*txt++);
6494 if (a < 0)
6495 return -1;
6496 b = hex2num(*txt++);
6497 if (b < 0)
6498 return -1;
6499 *addr++ = (a << 4) | b;
6500 if (i < 5 && *txt++ != ':')
6501 return -1;
6502 }
6503
6504 return 0;
6505}
6506
6507#endif /* defined(__linux__) || defined(__QNXNTO__) */
6508
6509enum send_frame_type {
6510 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
6511};
6512enum send_frame_protection {
6513 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6514};
6515
6516
6517static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6518 enum send_frame_type frame,
6519 enum send_frame_protection protected,
6520 const char *dest)
6521{
6522#ifdef __linux__
6523 unsigned char buf[1000], *pos;
6524 int s, res;
6525 char bssid[20], addr[20];
6526 char result[32], ssid[100];
6527 size_t ssid_len;
6528
6529 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6530 sizeof(result)) < 0 ||
6531 strncmp(result, "COMPLETED", 9) != 0) {
6532 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
6533 return 0;
6534 }
6535
6536 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
6537 < 0) {
6538 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6539 "current BSSID");
6540 return 0;
6541 }
6542
6543 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
6544 < 0) {
6545 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6546 "own MAC address");
6547 return 0;
6548 }
6549
6550 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
6551 < 0) {
6552 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6553 "current SSID");
6554 return 0;
6555 }
6556 ssid_len = strlen(ssid);
6557
6558 pos = buf;
6559
6560 /* Frame Control */
6561 switch (frame) {
6562 case DISASSOC:
6563 *pos++ = 0xa0;
6564 break;
6565 case DEAUTH:
6566 *pos++ = 0xc0;
6567 break;
6568 case SAQUERY:
6569 *pos++ = 0xd0;
6570 break;
6571 case AUTH:
6572 *pos++ = 0xb0;
6573 break;
6574 case ASSOCREQ:
6575 *pos++ = 0x00;
6576 break;
6577 case REASSOCREQ:
6578 *pos++ = 0x20;
6579 break;
6580 case DLS_REQ:
6581 *pos++ = 0xd0;
6582 break;
6583 }
6584
6585 if (protected == INCORRECT_KEY)
6586 *pos++ = 0x40; /* Set Protected field to 1 */
6587 else
6588 *pos++ = 0x00;
6589
6590 /* Duration */
6591 *pos++ = 0x00;
6592 *pos++ = 0x00;
6593
6594 /* addr1 = DA (current AP) */
6595 hwaddr_aton(bssid, pos);
6596 pos += 6;
6597 /* addr2 = SA (own address) */
6598 hwaddr_aton(addr, pos);
6599 pos += 6;
6600 /* addr3 = BSSID (current AP) */
6601 hwaddr_aton(bssid, pos);
6602 pos += 6;
6603
6604 /* Seq# (to be filled by driver/mac80211) */
6605 *pos++ = 0x00;
6606 *pos++ = 0x00;
6607
6608 if (protected == INCORRECT_KEY) {
6609 /* CCMP parameters */
6610 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6611 pos += 8;
6612 }
6613
6614 if (protected == INCORRECT_KEY) {
6615 switch (frame) {
6616 case DEAUTH:
6617 /* Reason code (encrypted) */
6618 memcpy(pos, "\xa7\x39", 2);
6619 pos += 2;
6620 break;
6621 case DISASSOC:
6622 /* Reason code (encrypted) */
6623 memcpy(pos, "\xa7\x39", 2);
6624 pos += 2;
6625 break;
6626 case SAQUERY:
6627 /* Category|Action|TransID (encrypted) */
6628 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6629 pos += 4;
6630 break;
6631 default:
6632 return -1;
6633 }
6634
6635 /* CCMP MIC */
6636 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6637 pos += 8;
6638 } else {
6639 switch (frame) {
6640 case DEAUTH:
6641 /* reason code = 8 */
6642 *pos++ = 0x08;
6643 *pos++ = 0x00;
6644 break;
6645 case DISASSOC:
6646 /* reason code = 8 */
6647 *pos++ = 0x08;
6648 *pos++ = 0x00;
6649 break;
6650 case SAQUERY:
6651 /* Category - SA Query */
6652 *pos++ = 0x08;
6653 /* SA query Action - Request */
6654 *pos++ = 0x00;
6655 /* Transaction ID */
6656 *pos++ = 0x12;
6657 *pos++ = 0x34;
6658 break;
6659 case AUTH:
6660 /* Auth Alg (Open) */
6661 *pos++ = 0x00;
6662 *pos++ = 0x00;
6663 /* Seq# */
6664 *pos++ = 0x01;
6665 *pos++ = 0x00;
6666 /* Status code */
6667 *pos++ = 0x00;
6668 *pos++ = 0x00;
6669 break;
6670 case ASSOCREQ:
6671 /* Capability Information */
6672 *pos++ = 0x31;
6673 *pos++ = 0x04;
6674 /* Listen Interval */
6675 *pos++ = 0x0a;
6676 *pos++ = 0x00;
6677 /* SSID */
6678 *pos++ = 0x00;
6679 *pos++ = ssid_len;
6680 memcpy(pos, ssid, ssid_len);
6681 pos += ssid_len;
6682 /* Supported Rates */
6683 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6684 10);
6685 pos += 10;
6686 /* Extended Supported Rates */
6687 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6688 pos += 6;
6689 /* RSN */
6690 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6691 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6692 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6693 pos += 28;
6694 break;
6695 case REASSOCREQ:
6696 /* Capability Information */
6697 *pos++ = 0x31;
6698 *pos++ = 0x04;
6699 /* Listen Interval */
6700 *pos++ = 0x0a;
6701 *pos++ = 0x00;
6702 /* Current AP */
6703 hwaddr_aton(bssid, pos);
6704 pos += 6;
6705 /* SSID */
6706 *pos++ = 0x00;
6707 *pos++ = ssid_len;
6708 memcpy(pos, ssid, ssid_len);
6709 pos += ssid_len;
6710 /* Supported Rates */
6711 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6712 10);
6713 pos += 10;
6714 /* Extended Supported Rates */
6715 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6716 pos += 6;
6717 /* RSN */
6718 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6719 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6720 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6721 pos += 28;
6722 break;
6723 case DLS_REQ:
6724 /* Category - DLS */
6725 *pos++ = 0x02;
6726 /* DLS Action - Request */
6727 *pos++ = 0x00;
6728 /* Destination MACAddress */
6729 if (dest)
6730 hwaddr_aton(dest, pos);
6731 else
6732 memset(pos, 0, 6);
6733 pos += 6;
6734 /* Source MACAddress */
6735 hwaddr_aton(addr, pos);
6736 pos += 6;
6737 /* Capability Information */
6738 *pos++ = 0x10; /* Privacy */
6739 *pos++ = 0x06; /* QoS */
6740 /* DLS Timeout Value */
6741 *pos++ = 0x00;
6742 *pos++ = 0x01;
6743 /* Supported rates */
6744 *pos++ = 0x01;
6745 *pos++ = 0x08;
6746 *pos++ = 0x0c; /* 6 Mbps */
6747 *pos++ = 0x12; /* 9 Mbps */
6748 *pos++ = 0x18; /* 12 Mbps */
6749 *pos++ = 0x24; /* 18 Mbps */
6750 *pos++ = 0x30; /* 24 Mbps */
6751 *pos++ = 0x48; /* 36 Mbps */
6752 *pos++ = 0x60; /* 48 Mbps */
6753 *pos++ = 0x6c; /* 54 Mbps */
6754 /* TODO: Extended Supported Rates */
6755 /* TODO: HT Capabilities */
6756 break;
6757 }
6758 }
6759
6760 s = open_monitor("sigmadut");
6761 if (s < 0) {
6762 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6763 "monitor socket");
6764 return 0;
6765 }
6766
6767 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
6768 if (res < 0) {
6769 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6770 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306771 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006772 return 0;
6773 }
6774 if (res < pos - buf) {
6775 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
6776 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306777 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006778 return 0;
6779 }
6780
6781 close(s);
6782
6783 return 1;
6784#else /* __linux__ */
6785 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
6786 "yet supported");
6787 return 0;
6788#endif /* __linux__ */
6789}
6790
6791
6792static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
6793 struct sigma_conn *conn,
6794 struct sigma_cmd *cmd)
6795{
6796 const char *intf = get_param(cmd, "Interface");
6797 const char *sta, *val;
6798 unsigned char addr[ETH_ALEN];
6799 char buf[100];
6800
6801 sta = get_param(cmd, "peer");
6802 if (sta == NULL)
6803 sta = get_param(cmd, "station");
6804 if (sta == NULL) {
6805 send_resp(dut, conn, SIGMA_ERROR,
6806 "ErrorCode,Missing peer address");
6807 return 0;
6808 }
6809 if (hwaddr_aton(sta, addr) < 0) {
6810 send_resp(dut, conn, SIGMA_ERROR,
6811 "ErrorCode,Invalid peer address");
6812 return 0;
6813 }
6814
6815 val = get_param(cmd, "type");
6816 if (val == NULL)
6817 return -1;
6818
6819 if (strcasecmp(val, "DISCOVERY") == 0) {
6820 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
6821 if (wpa_command(intf, buf) < 0) {
6822 send_resp(dut, conn, SIGMA_ERROR,
6823 "ErrorCode,Failed to send TDLS discovery");
6824 return 0;
6825 }
6826 return 1;
6827 }
6828
6829 if (strcasecmp(val, "SETUP") == 0) {
6830 int status = 0, timeout = 0;
6831
6832 val = get_param(cmd, "Status");
6833 if (val)
6834 status = atoi(val);
6835
6836 val = get_param(cmd, "Timeout");
6837 if (val)
6838 timeout = atoi(val);
6839
6840 if (status != 0 && status != 37) {
6841 send_resp(dut, conn, SIGMA_ERROR,
6842 "ErrorCode,Unsupported status value");
6843 return 0;
6844 }
6845
6846 if (timeout != 0 && timeout != 301) {
6847 send_resp(dut, conn, SIGMA_ERROR,
6848 "ErrorCode,Unsupported timeout value");
6849 return 0;
6850 }
6851
6852 if (status && timeout) {
6853 send_resp(dut, conn, SIGMA_ERROR,
6854 "ErrorCode,Unsupported timeout+status "
6855 "combination");
6856 return 0;
6857 }
6858
6859 if (status == 37 &&
6860 wpa_command(intf, "SET tdls_testing 0x200")) {
6861 send_resp(dut, conn, SIGMA_ERROR,
6862 "ErrorCode,Failed to enable "
6863 "decline setup response test mode");
6864 return 0;
6865 }
6866
6867 if (timeout == 301) {
6868 int res;
6869 if (dut->no_tpk_expiration)
6870 res = wpa_command(intf,
6871 "SET tdls_testing 0x108");
6872 else
6873 res = wpa_command(intf,
6874 "SET tdls_testing 0x8");
6875 if (res) {
6876 send_resp(dut, conn, SIGMA_ERROR,
6877 "ErrorCode,Failed to set short TPK "
6878 "lifetime");
6879 return 0;
6880 }
6881 }
6882
6883 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
6884 if (wpa_command(intf, buf) < 0) {
6885 send_resp(dut, conn, SIGMA_ERROR,
6886 "ErrorCode,Failed to send TDLS setup");
6887 return 0;
6888 }
6889 return 1;
6890 }
6891
6892 if (strcasecmp(val, "TEARDOWN") == 0) {
6893 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
6894 if (wpa_command(intf, buf) < 0) {
6895 send_resp(dut, conn, SIGMA_ERROR,
6896 "ErrorCode,Failed to send TDLS teardown");
6897 return 0;
6898 }
6899 return 1;
6900 }
6901
6902 send_resp(dut, conn, SIGMA_ERROR,
6903 "ErrorCode,Unsupported TDLS frame");
6904 return 0;
6905}
6906
6907
6908static int sta_ap_known(const char *ifname, const char *bssid)
6909{
6910 char buf[4096];
6911
6912 snprintf(buf, sizeof(buf), "BSS %s", bssid);
6913 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
6914 return 0;
6915 if (strncmp(buf, "id=", 3) != 0)
6916 return 0;
6917 return 1;
6918}
6919
6920
6921static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
6922 const char *bssid)
6923{
6924 int res;
6925 struct wpa_ctrl *ctrl;
6926 char buf[256];
6927
6928 if (sta_ap_known(ifname, bssid))
6929 return 0;
6930 sigma_dut_print(dut, DUT_MSG_DEBUG,
6931 "AP not in BSS table - start scan");
6932
6933 ctrl = open_wpa_mon(ifname);
6934 if (ctrl == NULL) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6936 "wpa_supplicant monitor connection");
6937 return -1;
6938 }
6939
6940 if (wpa_command(ifname, "SCAN") < 0) {
6941 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
6942 wpa_ctrl_detach(ctrl);
6943 wpa_ctrl_close(ctrl);
6944 return -1;
6945 }
6946
6947 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6948 buf, sizeof(buf));
6949
6950 wpa_ctrl_detach(ctrl);
6951 wpa_ctrl_close(ctrl);
6952
6953 if (res < 0) {
6954 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
6955 return -1;
6956 }
6957
6958 if (sta_ap_known(ifname, bssid))
6959 return 0;
6960 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
6961 return -1;
6962}
6963
6964
6965static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
6966 struct sigma_conn *conn,
6967 struct sigma_cmd *cmd,
6968 const char *intf)
6969{
6970 char buf[200];
6971
6972 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
6973 if (system(buf) != 0) {
6974 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
6975 "ndsend");
6976 return 0;
6977 }
6978
6979 return 1;
6980}
6981
6982
6983static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
6984 struct sigma_conn *conn,
6985 struct sigma_cmd *cmd,
6986 const char *intf)
6987{
6988 char buf[200];
6989 const char *ip = get_param(cmd, "SenderIP");
6990
Peng Xu26b356d2017-10-04 17:58:16 -07006991 if (!ip)
6992 return 0;
6993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006994 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
6995 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6996 if (system(buf) == 0) {
6997 sigma_dut_print(dut, DUT_MSG_INFO,
6998 "Neighbor Solicitation got a response "
6999 "for %s@%s", ip, intf);
7000 }
7001
7002 return 1;
7003}
7004
7005
7006static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
7007 struct sigma_conn *conn,
7008 struct sigma_cmd *cmd,
7009 const char *ifname)
7010{
7011 char buf[200];
7012 const char *ip = get_param(cmd, "SenderIP");
7013
7014 if (ip == NULL) {
7015 send_resp(dut, conn, SIGMA_ERROR,
7016 "ErrorCode,Missing SenderIP parameter");
7017 return 0;
7018 }
7019 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
7020 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7021 if (system(buf) != 0) {
7022 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
7023 "for %s@%s", ip, ifname);
7024 }
7025
7026 return 1;
7027}
7028
7029
7030static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
7031 struct sigma_conn *conn,
7032 struct sigma_cmd *cmd,
7033 const char *ifname)
7034{
7035 char buf[200];
7036 char ip[16];
7037 int s;
Peng Xub3756882017-10-04 14:39:09 -07007038 struct ifreq ifr;
7039 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007040
7041 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07007042 if (s < 0) {
7043 perror("socket");
7044 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007045 }
7046
Peng Xub3756882017-10-04 14:39:09 -07007047 memset(&ifr, 0, sizeof(ifr));
7048 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7049 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
7050 sigma_dut_print(dut, DUT_MSG_INFO,
7051 "Failed to get %s IP address: %s",
7052 ifname, strerror(errno));
7053 close(s);
7054 return -1;
7055 }
7056 close(s);
7057
7058 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
7059 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
7060
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007061 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
7062 ip);
7063 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7064 if (system(buf) != 0) {
7065 }
7066
7067 return 1;
7068}
7069
7070
7071static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
7072 struct sigma_conn *conn,
7073 struct sigma_cmd *cmd,
7074 const char *ifname)
7075{
7076 char buf[200], addr[20];
7077 char dst[ETH_ALEN], src[ETH_ALEN];
7078 short ethtype = htons(ETH_P_ARP);
7079 char *pos;
7080 int s, res;
7081 const char *val;
7082 struct sockaddr_in taddr;
7083
7084 val = get_param(cmd, "dest");
7085 if (val)
7086 hwaddr_aton(val, (unsigned char *) dst);
7087
7088 val = get_param(cmd, "DestIP");
7089 if (val)
7090 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007091 else
7092 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007093
7094 if (get_wpa_status(get_station_ifname(), "address", addr,
7095 sizeof(addr)) < 0)
7096 return -2;
7097 hwaddr_aton(addr, (unsigned char *) src);
7098
7099 pos = buf;
7100 *pos++ = 0x00;
7101 *pos++ = 0x01;
7102 *pos++ = 0x08;
7103 *pos++ = 0x00;
7104 *pos++ = 0x06;
7105 *pos++ = 0x04;
7106 *pos++ = 0x00;
7107 *pos++ = 0x02;
7108 memcpy(pos, src, ETH_ALEN);
7109 pos += ETH_ALEN;
7110 memcpy(pos, &taddr.sin_addr, 4);
7111 pos += 4;
7112 memcpy(pos, dst, ETH_ALEN);
7113 pos += ETH_ALEN;
7114 memcpy(pos, &taddr.sin_addr, 4);
7115 pos += 4;
7116
7117 s = open_monitor(get_station_ifname());
7118 if (s < 0) {
7119 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7120 "monitor socket");
7121 return 0;
7122 }
7123
7124 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7125 if (res < 0) {
7126 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7127 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307128 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007129 return 0;
7130 }
7131
7132 close(s);
7133
7134 return 1;
7135}
7136
7137
7138static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7139 struct sigma_conn *conn,
7140 struct sigma_cmd *cmd,
7141 const char *intf, const char *dest)
7142{
7143 char buf[100];
7144
7145 if (if_nametoindex("sigmadut") == 0) {
7146 snprintf(buf, sizeof(buf),
7147 "iw dev %s interface add sigmadut type monitor",
7148 get_station_ifname());
7149 if (system(buf) != 0 ||
7150 if_nametoindex("sigmadut") == 0) {
7151 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7152 "monitor interface with '%s'", buf);
7153 return -2;
7154 }
7155 }
7156
7157 if (system("ifconfig sigmadut up") != 0) {
7158 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7159 "monitor interface up");
7160 return -2;
7161 }
7162
7163 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7164}
7165
7166
7167static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7168 struct sigma_conn *conn,
7169 struct sigma_cmd *cmd)
7170{
7171 const char *intf = get_param(cmd, "Interface");
7172 const char *dest = get_param(cmd, "Dest");
7173 const char *type = get_param(cmd, "FrameName");
7174 const char *val;
7175 char buf[200], *pos, *end;
7176 int count, count2;
7177
7178 if (type == NULL)
7179 type = get_param(cmd, "Type");
7180
7181 if (intf == NULL || dest == NULL || type == NULL)
7182 return -1;
7183
7184 if (strcasecmp(type, "NeighAdv") == 0)
7185 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7186
7187 if (strcasecmp(type, "NeighSolicitReq") == 0)
7188 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7189
7190 if (strcasecmp(type, "ARPProbe") == 0)
7191 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7192
7193 if (strcasecmp(type, "ARPAnnounce") == 0)
7194 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7195
7196 if (strcasecmp(type, "ARPReply") == 0)
7197 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7198
7199 if (strcasecmp(type, "DLS-request") == 0 ||
7200 strcasecmp(type, "DLSrequest") == 0)
7201 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7202 dest);
7203
7204 if (strcasecmp(type, "ANQPQuery") != 0 &&
7205 strcasecmp(type, "Query") != 0) {
7206 send_resp(dut, conn, SIGMA_ERROR,
7207 "ErrorCode,Unsupported HS 2.0 send frame type");
7208 return 0;
7209 }
7210
7211 if (sta_scan_ap(dut, intf, dest) < 0) {
7212 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7213 "the requested AP");
7214 return 0;
7215 }
7216
7217 pos = buf;
7218 end = buf + sizeof(buf);
7219 count = 0;
7220 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7221
7222 val = get_param(cmd, "ANQP_CAP_LIST");
7223 if (val && atoi(val)) {
7224 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7225 count++;
7226 }
7227
7228 val = get_param(cmd, "VENUE_NAME");
7229 if (val && atoi(val)) {
7230 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7231 count++;
7232 }
7233
7234 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7235 if (val && atoi(val)) {
7236 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7237 count++;
7238 }
7239
7240 val = get_param(cmd, "ROAMING_CONS");
7241 if (val && atoi(val)) {
7242 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7243 count++;
7244 }
7245
7246 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7247 if (val && atoi(val)) {
7248 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7249 count++;
7250 }
7251
7252 val = get_param(cmd, "NAI_REALM_LIST");
7253 if (val && atoi(val)) {
7254 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7255 count++;
7256 }
7257
7258 val = get_param(cmd, "3GPP_INFO");
7259 if (val && atoi(val)) {
7260 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7261 count++;
7262 }
7263
7264 val = get_param(cmd, "DOMAIN_LIST");
7265 if (val && atoi(val)) {
7266 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7267 count++;
7268 }
7269
7270 if (count && wpa_command(intf, buf)) {
7271 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7272 return 0;
7273 }
7274
7275 pos = buf;
7276 end = buf + sizeof(buf);
7277 count2 = 0;
7278 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7279
7280 val = get_param(cmd, "HS_CAP_LIST");
7281 if (val && atoi(val)) {
7282 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7283 count2++;
7284 }
7285
7286 val = get_param(cmd, "OPER_NAME");
7287 if (val && atoi(val)) {
7288 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7289 count2++;
7290 }
7291
7292 val = get_param(cmd, "WAN_METRICS");
7293 if (!val)
7294 val = get_param(cmd, "WAN_MAT");
7295 if (!val)
7296 val = get_param(cmd, "WAN_MET");
7297 if (val && atoi(val)) {
7298 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7299 count2++;
7300 }
7301
7302 val = get_param(cmd, "CONNECTION_CAPABILITY");
7303 if (val && atoi(val)) {
7304 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7305 count2++;
7306 }
7307
7308 val = get_param(cmd, "OP_CLASS");
7309 if (val && atoi(val)) {
7310 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7311 count2++;
7312 }
7313
7314 val = get_param(cmd, "OSU_PROVIDER_LIST");
7315 if (val && atoi(val)) {
7316 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7317 count2++;
7318 }
7319
7320 if (count && count2) {
7321 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7322 "second query");
7323 sleep(1);
7324 }
7325
7326 if (count2 && wpa_command(intf, buf)) {
7327 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7328 "failed");
7329 return 0;
7330 }
7331
7332 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7333 if (val) {
7334 if (count || count2) {
7335 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7336 "sending out second query");
7337 sleep(1);
7338 }
7339
7340 if (strcmp(val, "1") == 0)
7341 val = "mail.example.com";
7342 snprintf(buf, end - pos,
7343 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7344 dest, val);
7345 if (wpa_command(intf, buf)) {
7346 send_resp(dut, conn, SIGMA_ERROR,
7347 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7348 "failed");
7349 return 0;
7350 }
7351 }
7352
7353 val = get_param(cmd, "ICON_REQUEST");
7354 if (val) {
7355 if (count || count2) {
7356 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7357 "sending out second query");
7358 sleep(1);
7359 }
7360
7361 snprintf(buf, end - pos,
7362 "HS20_ICON_REQUEST %s %s", dest, val);
7363 if (wpa_command(intf, buf)) {
7364 send_resp(dut, conn, SIGMA_ERROR,
7365 "ErrorCode,HS20_ICON_REQUEST failed");
7366 return 0;
7367 }
7368 }
7369
7370 return 1;
7371}
7372
7373
7374static int ath_sta_send_frame_vht(struct sigma_dut *dut,
7375 struct sigma_conn *conn,
7376 struct sigma_cmd *cmd)
7377{
7378 const char *val;
7379 char *ifname;
7380 char buf[100];
7381 int chwidth, nss;
7382
7383 val = get_param(cmd, "framename");
7384 if (!val)
7385 return -1;
7386 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
7387
7388 /* Command sequence to generate Op mode notification */
7389 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
7390 ifname = get_station_ifname();
7391
7392 /* Disable STBC */
7393 snprintf(buf, sizeof(buf),
7394 "iwpriv %s tx_stbc 0", ifname);
7395 if (system(buf) != 0) {
7396 sigma_dut_print(dut, DUT_MSG_ERROR,
7397 "iwpriv tx_stbc 0 failed!");
7398 }
7399
7400 /* Extract Channel width */
7401 val = get_param(cmd, "Channel_width");
7402 if (val) {
7403 switch (atoi(val)) {
7404 case 20:
7405 chwidth = 0;
7406 break;
7407 case 40:
7408 chwidth = 1;
7409 break;
7410 case 80:
7411 chwidth = 2;
7412 break;
7413 case 160:
7414 chwidth = 3;
7415 break;
7416 default:
7417 chwidth = 2;
7418 break;
7419 }
7420
7421 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7422 ifname, chwidth);
7423 if (system(buf) != 0) {
7424 sigma_dut_print(dut, DUT_MSG_ERROR,
7425 "iwpriv chwidth failed!");
7426 }
7427 }
7428
7429 /* Extract NSS */
7430 val = get_param(cmd, "NSS");
7431 if (val) {
7432 switch (atoi(val)) {
7433 case 1:
7434 nss = 1;
7435 break;
7436 case 2:
7437 nss = 3;
7438 break;
7439 case 3:
7440 nss = 7;
7441 break;
7442 default:
7443 /* We do not support NSS > 3 */
7444 nss = 3;
7445 break;
7446 }
7447 snprintf(buf, sizeof(buf),
7448 "iwpriv %s rxchainmask %d", ifname, nss);
7449 if (system(buf) != 0) {
7450 sigma_dut_print(dut, DUT_MSG_ERROR,
7451 "iwpriv rxchainmask failed!");
7452 }
7453 }
7454
7455 /* Opmode notify */
7456 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
7457 if (system(buf) != 0) {
7458 sigma_dut_print(dut, DUT_MSG_ERROR,
7459 "iwpriv opmode_notify failed!");
7460 } else {
7461 sigma_dut_print(dut, DUT_MSG_INFO,
7462 "Sent out the notify frame!");
7463 }
7464 }
7465
7466 return 1;
7467}
7468
7469
7470static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
7471 struct sigma_conn *conn,
7472 struct sigma_cmd *cmd)
7473{
7474 switch (get_driver_type()) {
7475 case DRIVER_ATHEROS:
7476 return ath_sta_send_frame_vht(dut, conn, cmd);
7477 default:
7478 send_resp(dut, conn, SIGMA_ERROR,
7479 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
7480 return 0;
7481 }
7482}
7483
7484
Lior David0fe101e2017-03-09 16:09:50 +02007485#ifdef __linux__
7486int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7487 struct sigma_cmd *cmd)
7488{
7489 const char *frame_name = get_param(cmd, "framename");
7490 const char *mac = get_param(cmd, "dest_mac");
7491
7492 if (!frame_name || !mac) {
7493 sigma_dut_print(dut, DUT_MSG_ERROR,
7494 "framename and dest_mac must be provided");
7495 return -1;
7496 }
7497
7498 if (strcasecmp(frame_name, "brp") == 0) {
7499 const char *l_rx = get_param(cmd, "L-RX");
7500 int l_rx_i;
7501
7502 if (!l_rx) {
7503 sigma_dut_print(dut, DUT_MSG_ERROR,
7504 "L-RX must be provided");
7505 return -1;
7506 }
7507 l_rx_i = atoi(l_rx);
7508
7509 sigma_dut_print(dut, DUT_MSG_INFO,
7510 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
7511 mac, l_rx);
7512 if (l_rx_i != 16) {
7513 sigma_dut_print(dut, DUT_MSG_ERROR,
7514 "unsupported L-RX: %s", l_rx);
7515 return -1;
7516 }
7517
7518 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
7519 return -1;
7520 } else if (strcasecmp(frame_name, "ssw") == 0) {
7521 sigma_dut_print(dut, DUT_MSG_INFO,
7522 "dev_send_frame: SLS, dest_mac %s", mac);
7523 if (wil6210_send_sls(dut, mac))
7524 return -1;
7525 } else {
7526 sigma_dut_print(dut, DUT_MSG_ERROR,
7527 "unsupported frame type: %s", frame_name);
7528 return -1;
7529 }
7530
7531 return 1;
7532}
7533#endif /* __linux__ */
7534
7535
7536static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
7537 struct sigma_conn *conn,
7538 struct sigma_cmd *cmd)
7539{
7540 switch (get_driver_type()) {
7541#ifdef __linux__
7542 case DRIVER_WIL6210:
7543 return wil6210_send_frame_60g(dut, conn, cmd);
7544#endif /* __linux__ */
7545 default:
7546 send_resp(dut, conn, SIGMA_ERROR,
7547 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7548 return 0;
7549 }
7550}
7551
7552
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307553static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
7554 const char *intf, struct sigma_cmd *cmd)
7555{
7556 const char *val, *addr;
7557 char buf[100];
7558
7559 addr = get_param(cmd, "DestMac");
7560 if (!addr) {
7561 send_resp(dut, conn, SIGMA_INVALID,
7562 "ErrorCode,AP MAC address is missing");
7563 return 0;
7564 }
7565
7566 val = get_param(cmd, "ANQPQuery_ID");
7567 if (!val) {
7568 send_resp(dut, conn, SIGMA_INVALID,
7569 "ErrorCode,Missing ANQPQuery_ID");
7570 return 0;
7571 }
7572
7573 if (strcasecmp(val, "NeighborReportReq") == 0) {
7574 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
7575 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
7576 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
7577 } else {
7578 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
7579 val);
7580 send_resp(dut, conn, SIGMA_INVALID,
7581 "ErrorCode,Invalid ANQPQuery_ID");
7582 return 0;
7583 }
7584
Ashwini Patild174f2c2017-04-13 16:49:46 +05307585 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
7586 * (Address3 = Wildcard BSSID when sent to not-associated AP;
7587 * if associated, AP BSSID).
7588 */
7589 if (wpa_command(intf, "SET gas_address3 1") < 0) {
7590 send_resp(dut, conn, SIGMA_ERROR,
7591 "ErrorCode,Failed to set gas_address3");
7592 return 0;
7593 }
7594
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307595 if (wpa_command(intf, buf) < 0) {
7596 send_resp(dut, conn, SIGMA_ERROR,
7597 "ErrorCode,Failed to send ANQP query");
7598 return 0;
7599 }
7600
7601 return 1;
7602}
7603
7604
7605static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
7606 struct sigma_conn *conn,
7607 const char *intf,
7608 struct sigma_cmd *cmd)
7609{
7610 const char *val = get_param(cmd, "FrameName");
7611
7612 if (val && strcasecmp(val, "ANQPQuery") == 0)
7613 return mbo_send_anqp_query(dut, conn, intf, cmd);
7614
7615 return 2;
7616}
7617
7618
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007619int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7620 struct sigma_cmd *cmd)
7621{
7622 const char *intf = get_param(cmd, "Interface");
7623 const char *val;
7624 enum send_frame_type frame;
7625 enum send_frame_protection protected;
7626 char buf[100];
7627 unsigned char addr[ETH_ALEN];
7628 int res;
7629
7630 val = get_param(cmd, "program");
7631 if (val == NULL)
7632 val = get_param(cmd, "frame");
7633 if (val && strcasecmp(val, "TDLS") == 0)
7634 return cmd_sta_send_frame_tdls(dut, conn, cmd);
7635 if (val && (strcasecmp(val, "HS2") == 0 ||
7636 strcasecmp(val, "HS2-R2") == 0))
7637 return cmd_sta_send_frame_hs2(dut, conn, cmd);
7638 if (val && strcasecmp(val, "VHT") == 0)
7639 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007640 if (val && strcasecmp(val, "LOC") == 0)
7641 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007642 if (val && strcasecmp(val, "60GHz") == 0)
7643 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307644 if (val && strcasecmp(val, "MBO") == 0) {
7645 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
7646 if (res != 2)
7647 return res;
7648 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007649
7650 val = get_param(cmd, "TD_DISC");
7651 if (val) {
7652 if (hwaddr_aton(val, addr) < 0)
7653 return -1;
7654 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
7655 if (wpa_command(intf, buf) < 0) {
7656 send_resp(dut, conn, SIGMA_ERROR,
7657 "ErrorCode,Failed to send TDLS discovery");
7658 return 0;
7659 }
7660 return 1;
7661 }
7662
7663 val = get_param(cmd, "TD_Setup");
7664 if (val) {
7665 if (hwaddr_aton(val, addr) < 0)
7666 return -1;
7667 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
7668 if (wpa_command(intf, buf) < 0) {
7669 send_resp(dut, conn, SIGMA_ERROR,
7670 "ErrorCode,Failed to start TDLS setup");
7671 return 0;
7672 }
7673 return 1;
7674 }
7675
7676 val = get_param(cmd, "TD_TearDown");
7677 if (val) {
7678 if (hwaddr_aton(val, addr) < 0)
7679 return -1;
7680 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
7681 if (wpa_command(intf, buf) < 0) {
7682 send_resp(dut, conn, SIGMA_ERROR,
7683 "ErrorCode,Failed to tear down TDLS link");
7684 return 0;
7685 }
7686 return 1;
7687 }
7688
7689 val = get_param(cmd, "TD_ChannelSwitch");
7690 if (val) {
7691 /* TODO */
7692 send_resp(dut, conn, SIGMA_ERROR,
7693 "ErrorCode,TD_ChannelSwitch not yet supported");
7694 return 0;
7695 }
7696
7697 val = get_param(cmd, "TD_NF");
7698 if (val) {
7699 /* TODO */
7700 send_resp(dut, conn, SIGMA_ERROR,
7701 "ErrorCode,TD_NF not yet supported");
7702 return 0;
7703 }
7704
7705 val = get_param(cmd, "PMFFrameType");
7706 if (val == NULL)
7707 val = get_param(cmd, "FrameName");
7708 if (val == NULL)
7709 val = get_param(cmd, "Type");
7710 if (val == NULL)
7711 return -1;
7712 if (strcasecmp(val, "disassoc") == 0)
7713 frame = DISASSOC;
7714 else if (strcasecmp(val, "deauth") == 0)
7715 frame = DEAUTH;
7716 else if (strcasecmp(val, "saquery") == 0)
7717 frame = SAQUERY;
7718 else if (strcasecmp(val, "auth") == 0)
7719 frame = AUTH;
7720 else if (strcasecmp(val, "assocreq") == 0)
7721 frame = ASSOCREQ;
7722 else if (strcasecmp(val, "reassocreq") == 0)
7723 frame = REASSOCREQ;
7724 else if (strcasecmp(val, "neigreq") == 0) {
7725 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
7726
7727 val = get_param(cmd, "ssid");
7728 if (val == NULL)
7729 return -1;
7730
7731 res = send_neighbor_request(dut, intf, val);
7732 if (res) {
7733 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7734 "Failed to send neighbor report request");
7735 return 0;
7736 }
7737
7738 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307739 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
7740 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007741 sigma_dut_print(dut, DUT_MSG_DEBUG,
7742 "Got Transition Management Query");
7743
Ashwini Patil5acd7382017-04-13 15:55:04 +05307744 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007745 if (res) {
7746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7747 "Failed to send Transition Management Query");
7748 return 0;
7749 }
7750
7751 return 1;
7752 } else {
7753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7754 "PMFFrameType");
7755 return 0;
7756 }
7757
7758 val = get_param(cmd, "PMFProtected");
7759 if (val == NULL)
7760 val = get_param(cmd, "Protected");
7761 if (val == NULL)
7762 return -1;
7763 if (strcasecmp(val, "Correct-key") == 0 ||
7764 strcasecmp(val, "CorrectKey") == 0)
7765 protected = CORRECT_KEY;
7766 else if (strcasecmp(val, "IncorrectKey") == 0)
7767 protected = INCORRECT_KEY;
7768 else if (strcasecmp(val, "Unprotected") == 0)
7769 protected = UNPROTECTED;
7770 else {
7771 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7772 "PMFProtected");
7773 return 0;
7774 }
7775
7776 if (protected != UNPROTECTED &&
7777 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
7778 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
7779 "PMFProtected for auth/assocreq/reassocreq");
7780 return 0;
7781 }
7782
7783 if (if_nametoindex("sigmadut") == 0) {
7784 snprintf(buf, sizeof(buf),
7785 "iw dev %s interface add sigmadut type monitor",
7786 get_station_ifname());
7787 if (system(buf) != 0 ||
7788 if_nametoindex("sigmadut") == 0) {
7789 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7790 "monitor interface with '%s'", buf);
7791 return -2;
7792 }
7793 }
7794
7795 if (system("ifconfig sigmadut up") != 0) {
7796 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7797 "monitor interface up");
7798 return -2;
7799 }
7800
7801 return sta_inject_frame(dut, conn, frame, protected, NULL);
7802}
7803
7804
7805static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
7806 struct sigma_conn *conn,
7807 struct sigma_cmd *cmd,
7808 const char *ifname)
7809{
7810 char buf[200];
7811 const char *val;
7812
7813 val = get_param(cmd, "ClearARP");
7814 if (val && atoi(val) == 1) {
7815 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
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 clear ARP cache");
7820 return 0;
7821 }
7822 }
7823
7824 return 1;
7825}
7826
7827
7828int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
7829 struct sigma_cmd *cmd)
7830{
7831 const char *intf = get_param(cmd, "Interface");
7832 const char *val;
7833
7834 if (intf == NULL)
7835 return -1;
7836
7837 val = get_param(cmd, "program");
7838 if (val && (strcasecmp(val, "HS2") == 0 ||
7839 strcasecmp(val, "HS2-R2") == 0))
7840 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
7841
7842 return -1;
7843}
7844
7845
7846static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
7847 struct sigma_cmd *cmd)
7848{
7849 const char *intf = get_param(cmd, "Interface");
7850 const char *mac = get_param(cmd, "MAC");
7851
7852 if (intf == NULL || mac == NULL)
7853 return -1;
7854
7855 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
7856 "interface %s to %s", intf, mac);
7857
7858 if (dut->set_macaddr) {
7859 char buf[128];
7860 int res;
7861 if (strcasecmp(mac, "default") == 0) {
7862 res = snprintf(buf, sizeof(buf), "%s",
7863 dut->set_macaddr);
7864 dut->tmp_mac_addr = 0;
7865 } else {
7866 res = snprintf(buf, sizeof(buf), "%s %s",
7867 dut->set_macaddr, mac);
7868 dut->tmp_mac_addr = 1;
7869 }
7870 if (res < 0 || res >= (int) sizeof(buf))
7871 return -1;
7872 if (system(buf) != 0) {
7873 send_resp(dut, conn, SIGMA_ERROR,
7874 "errorCode,Failed to set MAC "
7875 "address");
7876 return 0;
7877 }
7878 return 1;
7879 }
7880
7881 if (strcasecmp(mac, "default") == 0)
7882 return 1;
7883
7884 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7885 "command");
7886 return 0;
7887}
7888
7889
7890static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
7891 struct sigma_conn *conn, const char *intf,
7892 int val)
7893{
7894 char buf[200];
7895 int res;
7896
7897 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
7898 intf, val);
7899 if (res < 0 || res >= (int) sizeof(buf))
7900 return -1;
7901 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7902 if (system(buf) != 0) {
7903 send_resp(dut, conn, SIGMA_ERROR,
7904 "errorCode,Failed to configure offchannel mode");
7905 return 0;
7906 }
7907
7908 return 1;
7909}
7910
7911
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007912static int off_chan_val(enum sec_ch_offset off)
7913{
7914 switch (off) {
7915 case SEC_CH_NO:
7916 return 0;
7917 case SEC_CH_40ABOVE:
7918 return 40;
7919 case SEC_CH_40BELOW:
7920 return -40;
7921 }
7922
7923 return 0;
7924}
7925
7926
7927static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
7928 const char *intf, int off_ch_num,
7929 enum sec_ch_offset sec)
7930{
7931 char buf[200];
7932 int res;
7933
7934 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
7935 intf, off_ch_num);
7936 if (res < 0 || res >= (int) sizeof(buf))
7937 return -1;
7938 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7939 if (system(buf) != 0) {
7940 send_resp(dut, conn, SIGMA_ERROR,
7941 "errorCode,Failed to set offchan");
7942 return 0;
7943 }
7944
7945 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
7946 intf, off_chan_val(sec));
7947 if (res < 0 || res >= (int) sizeof(buf))
7948 return -1;
7949 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7950 if (system(buf) != 0) {
7951 send_resp(dut, conn, SIGMA_ERROR,
7952 "errorCode,Failed to set sec chan offset");
7953 return 0;
7954 }
7955
7956 return 1;
7957}
7958
7959
7960static int tdls_set_offchannel_offset(struct sigma_dut *dut,
7961 struct sigma_conn *conn,
7962 const char *intf, int off_ch_num,
7963 enum sec_ch_offset sec)
7964{
7965 char buf[200];
7966 int res;
7967
7968 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
7969 off_ch_num);
7970 if (res < 0 || res >= (int) sizeof(buf))
7971 return -1;
7972 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7973
7974 if (wpa_command(intf, buf) < 0) {
7975 send_resp(dut, conn, SIGMA_ERROR,
7976 "ErrorCode,Failed to set offchan");
7977 return 0;
7978 }
7979 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
7980 off_chan_val(sec));
7981 if (res < 0 || res >= (int) sizeof(buf))
7982 return -1;
7983
7984 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7985
7986 if (wpa_command(intf, buf) < 0) {
7987 send_resp(dut, conn, SIGMA_ERROR,
7988 "ErrorCode,Failed to set sec chan offset");
7989 return 0;
7990 }
7991
7992 return 1;
7993}
7994
7995
7996static int tdls_set_offchannel_mode(struct sigma_dut *dut,
7997 struct sigma_conn *conn,
7998 const char *intf, int val)
7999{
8000 char buf[200];
8001 int res;
8002
8003 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
8004 val);
8005 if (res < 0 || res >= (int) sizeof(buf))
8006 return -1;
8007 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8008
8009 if (wpa_command(intf, buf) < 0) {
8010 send_resp(dut, conn, SIGMA_ERROR,
8011 "ErrorCode,Failed to configure offchannel mode");
8012 return 0;
8013 }
8014
8015 return 1;
8016}
8017
8018
8019static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
8020 struct sigma_conn *conn,
8021 struct sigma_cmd *cmd)
8022{
8023 const char *val;
8024 enum {
8025 CHSM_NOT_SET,
8026 CHSM_ENABLE,
8027 CHSM_DISABLE,
8028 CHSM_REJREQ,
8029 CHSM_UNSOLRESP
8030 } chsm = CHSM_NOT_SET;
8031 int off_ch_num = -1;
8032 enum sec_ch_offset sec_ch = SEC_CH_NO;
8033 int res;
8034
8035 val = get_param(cmd, "Uapsd");
8036 if (val) {
8037 char buf[100];
8038 if (strcasecmp(val, "Enable") == 0)
8039 snprintf(buf, sizeof(buf), "SET ps 99");
8040 else if (strcasecmp(val, "Disable") == 0)
8041 snprintf(buf, sizeof(buf), "SET ps 98");
8042 else {
8043 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8044 "Unsupported uapsd parameter value");
8045 return 0;
8046 }
8047 if (wpa_command(intf, buf)) {
8048 send_resp(dut, conn, SIGMA_ERROR,
8049 "ErrorCode,Failed to change U-APSD "
8050 "powersave mode");
8051 return 0;
8052 }
8053 }
8054
8055 val = get_param(cmd, "TPKTIMER");
8056 if (val && strcasecmp(val, "DISABLE") == 0) {
8057 if (wpa_command(intf, "SET tdls_testing 0x100")) {
8058 send_resp(dut, conn, SIGMA_ERROR,
8059 "ErrorCode,Failed to enable no TPK "
8060 "expiration test mode");
8061 return 0;
8062 }
8063 dut->no_tpk_expiration = 1;
8064 }
8065
8066 val = get_param(cmd, "ChSwitchMode");
8067 if (val) {
8068 if (strcasecmp(val, "Enable") == 0 ||
8069 strcasecmp(val, "Initiate") == 0)
8070 chsm = CHSM_ENABLE;
8071 else if (strcasecmp(val, "Disable") == 0 ||
8072 strcasecmp(val, "passive") == 0)
8073 chsm = CHSM_DISABLE;
8074 else if (strcasecmp(val, "RejReq") == 0)
8075 chsm = CHSM_REJREQ;
8076 else if (strcasecmp(val, "UnSolResp") == 0)
8077 chsm = CHSM_UNSOLRESP;
8078 else {
8079 send_resp(dut, conn, SIGMA_ERROR,
8080 "ErrorCode,Unknown ChSwitchMode value");
8081 return 0;
8082 }
8083 }
8084
8085 val = get_param(cmd, "OffChNum");
8086 if (val) {
8087 off_ch_num = atoi(val);
8088 if (off_ch_num == 0) {
8089 send_resp(dut, conn, SIGMA_ERROR,
8090 "ErrorCode,Invalid OffChNum");
8091 return 0;
8092 }
8093 }
8094
8095 val = get_param(cmd, "SecChOffset");
8096 if (val) {
8097 if (strcmp(val, "20") == 0)
8098 sec_ch = SEC_CH_NO;
8099 else if (strcasecmp(val, "40above") == 0)
8100 sec_ch = SEC_CH_40ABOVE;
8101 else if (strcasecmp(val, "40below") == 0)
8102 sec_ch = SEC_CH_40BELOW;
8103 else {
8104 send_resp(dut, conn, SIGMA_ERROR,
8105 "ErrorCode,Unknown SecChOffset value");
8106 return 0;
8107 }
8108 }
8109
8110 if (chsm == CHSM_NOT_SET) {
8111 /* no offchannel changes requested */
8112 return 1;
8113 }
8114
8115 if (strcmp(intf, get_main_ifname()) != 0 &&
8116 strcmp(intf, get_station_ifname()) != 0) {
8117 send_resp(dut, conn, SIGMA_ERROR,
8118 "ErrorCode,Unknown interface");
8119 return 0;
8120 }
8121
8122 switch (chsm) {
8123 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008124 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008125 break;
8126 case CHSM_ENABLE:
8127 if (off_ch_num < 0) {
8128 send_resp(dut, conn, SIGMA_ERROR,
8129 "ErrorCode,Missing OffChNum argument");
8130 return 0;
8131 }
8132 if (wifi_chip_type == DRIVER_WCN) {
8133 res = tdls_set_offchannel_offset(dut, conn, intf,
8134 off_ch_num, sec_ch);
8135 } else {
8136 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8137 sec_ch);
8138 }
8139 if (res != 1)
8140 return res;
8141 if (wifi_chip_type == DRIVER_WCN)
8142 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8143 else
8144 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8145 break;
8146 case CHSM_DISABLE:
8147 if (wifi_chip_type == DRIVER_WCN)
8148 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8149 else
8150 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8151 break;
8152 case CHSM_REJREQ:
8153 if (wifi_chip_type == DRIVER_WCN)
8154 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8155 else
8156 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8157 break;
8158 case CHSM_UNSOLRESP:
8159 if (off_ch_num < 0) {
8160 send_resp(dut, conn, SIGMA_ERROR,
8161 "ErrorCode,Missing OffChNum argument");
8162 return 0;
8163 }
8164 if (wifi_chip_type == DRIVER_WCN) {
8165 res = tdls_set_offchannel_offset(dut, conn, intf,
8166 off_ch_num, sec_ch);
8167 } else {
8168 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8169 sec_ch);
8170 }
8171 if (res != 1)
8172 return res;
8173 if (wifi_chip_type == DRIVER_WCN)
8174 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8175 else
8176 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8177 break;
8178 }
8179
8180 return res;
8181}
8182
8183
8184static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8185 struct sigma_conn *conn,
8186 struct sigma_cmd *cmd)
8187{
8188 const char *val;
8189 char *token, *result;
8190
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008191 novap_reset(dut, intf);
8192
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008193 val = get_param(cmd, "nss_mcs_opt");
8194 if (val) {
8195 /* String (nss_operating_mode; mcs_operating_mode) */
8196 int nss, mcs;
8197 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308198 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008199
8200 token = strdup(val);
8201 if (!token)
8202 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308203 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308204 if (!result) {
8205 sigma_dut_print(dut, DUT_MSG_ERROR,
8206 "VHT NSS not specified");
8207 goto failed;
8208 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008209 if (strcasecmp(result, "def") != 0) {
8210 nss = atoi(result);
8211 if (nss == 4)
8212 ath_disable_txbf(dut, intf);
8213 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8214 intf, nss);
8215 if (system(buf) != 0) {
8216 sigma_dut_print(dut, DUT_MSG_ERROR,
8217 "iwpriv nss failed");
8218 goto failed;
8219 }
8220 }
8221
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308222 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308223 if (!result) {
8224 sigma_dut_print(dut, DUT_MSG_ERROR,
8225 "VHT MCS not specified");
8226 goto failed;
8227 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008228 if (strcasecmp(result, "def") == 0) {
8229 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8230 intf);
8231 if (system(buf) != 0) {
8232 sigma_dut_print(dut, DUT_MSG_ERROR,
8233 "iwpriv set11NRates failed");
8234 goto failed;
8235 }
8236
8237 } else {
8238 mcs = atoi(result);
8239 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8240 intf, mcs);
8241 if (system(buf) != 0) {
8242 sigma_dut_print(dut, DUT_MSG_ERROR,
8243 "iwpriv vhtmcs failed");
8244 goto failed;
8245 }
8246 }
8247 /* Channel width gets messed up, fix this */
8248 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8249 intf, dut->chwidth);
8250 if (system(buf) != 0) {
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "iwpriv chwidth failed");
8253 }
8254 }
8255
8256 return 1;
8257failed:
8258 free(token);
8259 return 0;
8260}
8261
8262
8263static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8264 struct sigma_conn *conn,
8265 struct sigma_cmd *cmd)
8266{
8267 switch (get_driver_type()) {
8268 case DRIVER_ATHEROS:
8269 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8270 default:
8271 send_resp(dut, conn, SIGMA_ERROR,
8272 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8273 return 0;
8274 }
8275}
8276
8277
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008278static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8279 struct sigma_conn *conn,
8280 struct sigma_cmd *cmd)
8281{
8282 const char *val;
8283 char *token = NULL, *result;
8284 char buf[60];
8285
8286 val = get_param(cmd, "nss_mcs_opt");
8287 if (val) {
8288 /* String (nss_operating_mode; mcs_operating_mode) */
8289 int nss, mcs, ratecode;
8290 char *saveptr;
8291
8292 token = strdup(val);
8293 if (!token)
8294 return -2;
8295
8296 result = strtok_r(token, ";", &saveptr);
8297 if (!result) {
8298 sigma_dut_print(dut, DUT_MSG_ERROR,
8299 "HE NSS not specified");
8300 goto failed;
8301 }
8302 nss = 1;
8303 if (strcasecmp(result, "def") != 0)
8304 nss = atoi(result);
8305
8306 result = strtok_r(NULL, ";", &saveptr);
8307 if (!result) {
8308 sigma_dut_print(dut, DUT_MSG_ERROR,
8309 "HE MCS not specified");
8310 goto failed;
8311 }
8312 mcs = 7;
8313 if (strcasecmp(result, "def") != 0)
8314 mcs = atoi(result);
8315
8316 ratecode = 0x400; /* for nss:1 MCS 0 */
8317 if (nss == 2) {
8318 ratecode = 0x420; /* for nss:2 MCS 0 */
8319 } else if (nss > 2) {
8320 sigma_dut_print(dut, DUT_MSG_ERROR,
8321 "HE NSS %d not supported", nss);
8322 goto failed;
8323 }
8324
8325 /* Add the MCS to the ratecode */
8326 if (mcs >= 0 && mcs <= 11) {
8327 ratecode += mcs;
8328 } else {
8329 sigma_dut_print(dut, DUT_MSG_ERROR,
8330 "HE MCS %d not supported", mcs);
8331 goto failed;
8332 }
8333 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8334 intf, ratecode);
8335 if (system(buf) != 0) {
8336 sigma_dut_print(dut, DUT_MSG_ERROR,
8337 "iwpriv setting of 11ax rates failed");
8338 goto failed;
8339 }
8340 free(token);
8341 }
8342
8343 val = get_param(cmd, "GI");
8344 if (val) {
8345 if (strcmp(val, "0.8") == 0) {
8346 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8347 } else if (strcmp(val, "1.6") == 0) {
8348 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8349 } else if (strcmp(val, "3.2") == 0) {
8350 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8351 } else {
8352 send_resp(dut, conn, SIGMA_ERROR,
8353 "errorCode,GI value not supported");
8354 return 0;
8355 }
8356 if (system(buf) != 0) {
8357 send_resp(dut, conn, SIGMA_ERROR,
8358 "errorCode,Failed to set shortgi");
8359 return 0;
8360 }
8361 }
8362
8363 return 1;
8364
8365failed:
8366 free(token);
8367 return -2;
8368}
8369
8370
8371static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8372 struct sigma_conn *conn,
8373 struct sigma_cmd *cmd)
8374{
8375 switch (get_driver_type()) {
8376 case DRIVER_WCN:
8377 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
8378 default:
8379 send_resp(dut, conn, SIGMA_ERROR,
8380 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
8381 return 0;
8382 }
8383}
8384
8385
Ashwini Patil5acd7382017-04-13 15:55:04 +05308386static int btm_query_candidate_list(struct sigma_dut *dut,
8387 struct sigma_conn *conn,
8388 struct sigma_cmd *cmd)
8389{
8390 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
8391 int len, ret;
8392 char buf[10];
8393
8394 /*
8395 * Neighbor Report elements format:
8396 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
8397 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
8398 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
8399 */
8400
8401 bssid = get_param(cmd, "Nebor_BSSID");
8402 if (!bssid) {
8403 send_resp(dut, conn, SIGMA_INVALID,
8404 "errorCode,Nebor_BSSID is missing");
8405 return 0;
8406 }
8407
8408 info = get_param(cmd, "Nebor_Bssid_Info");
8409 if (!info) {
8410 sigma_dut_print(dut, DUT_MSG_INFO,
8411 "Using default value for Nebor_Bssid_Info: %s",
8412 DEFAULT_NEIGHBOR_BSSID_INFO);
8413 info = DEFAULT_NEIGHBOR_BSSID_INFO;
8414 }
8415
8416 op_class = get_param(cmd, "Nebor_Op_Class");
8417 if (!op_class) {
8418 send_resp(dut, conn, SIGMA_INVALID,
8419 "errorCode,Nebor_Op_Class is missing");
8420 return 0;
8421 }
8422
8423 ch = get_param(cmd, "Nebor_Op_Ch");
8424 if (!ch) {
8425 send_resp(dut, conn, SIGMA_INVALID,
8426 "errorCode,Nebor_Op_Ch is missing");
8427 return 0;
8428 }
8429
8430 phy_type = get_param(cmd, "Nebor_Phy_Type");
8431 if (!phy_type) {
8432 sigma_dut_print(dut, DUT_MSG_INFO,
8433 "Using default value for Nebor_Phy_Type: %s",
8434 DEFAULT_NEIGHBOR_PHY_TYPE);
8435 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
8436 }
8437
8438 /* Parse optional subelements */
8439 buf[0] = '\0';
8440 pref = get_param(cmd, "Nebor_Pref");
8441 if (pref) {
8442 /* hexdump for preferrence subelement */
8443 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
8444 if (ret < 0 || ret >= (int) sizeof(buf)) {
8445 sigma_dut_print(dut, DUT_MSG_ERROR,
8446 "snprintf failed for optional subelement ret: %d",
8447 ret);
8448 send_resp(dut, conn, SIGMA_ERROR,
8449 "errorCode,snprintf failed for subelement");
8450 return 0;
8451 }
8452 }
8453
8454 if (!dut->btm_query_cand_list) {
8455 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
8456 if (!dut->btm_query_cand_list) {
8457 send_resp(dut, conn, SIGMA_ERROR,
8458 "errorCode,Failed to allocate memory for btm_query_cand_list");
8459 return 0;
8460 }
8461 }
8462
8463 len = strlen(dut->btm_query_cand_list);
8464 ret = snprintf(dut->btm_query_cand_list + len,
8465 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
8466 bssid, info, op_class, ch, phy_type, buf);
8467 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
8468 sigma_dut_print(dut, DUT_MSG_ERROR,
8469 "snprintf failed for neighbor report list ret: %d",
8470 ret);
8471 send_resp(dut, conn, SIGMA_ERROR,
8472 "errorCode,snprintf failed for neighbor report");
8473 free(dut->btm_query_cand_list);
8474 dut->btm_query_cand_list = NULL;
8475 return 0;
8476 }
8477
8478 return 1;
8479}
8480
8481
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008482static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8483 struct sigma_cmd *cmd)
8484{
8485 const char *intf = get_param(cmd, "Interface");
8486 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308487 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008488
8489 if (intf == NULL || prog == NULL)
8490 return -1;
8491
Ashwini Patil5acd7382017-04-13 15:55:04 +05308492 /* BSS Transition candidate list for BTM query */
8493 val = get_param(cmd, "Nebor_BSSID");
8494 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
8495 return 0;
8496
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008497 if (strcasecmp(prog, "TDLS") == 0)
8498 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
8499
8500 if (strcasecmp(prog, "VHT") == 0)
8501 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
8502
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008503 if (strcasecmp(prog, "HE") == 0)
8504 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
8505
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308506 if (strcasecmp(prog, "MBO") == 0) {
8507 val = get_param(cmd, "Cellular_Data_Cap");
8508 if (val &&
8509 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
8510 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05308511
8512 val = get_param(cmd, "Ch_Pref");
8513 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
8514 return 0;
8515
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308516 return 1;
8517 }
8518
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008519 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
8520 return 0;
8521}
8522
8523
8524static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
8525 struct sigma_cmd *cmd)
8526{
8527 const char *intf = get_param(cmd, "Interface");
8528 const char *mode = get_param(cmd, "Mode");
8529 int res;
8530
8531 if (intf == NULL || mode == NULL)
8532 return -1;
8533
8534 if (strcasecmp(mode, "On") == 0)
8535 res = wpa_command(intf, "SET radio_disabled 0");
8536 else if (strcasecmp(mode, "Off") == 0)
8537 res = wpa_command(intf, "SET radio_disabled 1");
8538 else
8539 return -1;
8540
8541 if (res) {
8542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8543 "radio mode");
8544 return 0;
8545 }
8546
8547 return 1;
8548}
8549
8550
8551static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
8552 struct sigma_cmd *cmd)
8553{
8554 const char *intf = get_param(cmd, "Interface");
8555 const char *mode = get_param(cmd, "Mode");
8556 int res;
8557
8558 if (intf == NULL || mode == NULL)
8559 return -1;
8560
8561 if (strcasecmp(mode, "On") == 0)
8562 res = set_ps(intf, dut, 1);
8563 else if (strcasecmp(mode, "Off") == 0)
8564 res = set_ps(intf, dut, 0);
8565 else
8566 return -1;
8567
8568 if (res) {
8569 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8570 "power save mode");
8571 return 0;
8572 }
8573
8574 return 1;
8575}
8576
8577
8578static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
8579 struct sigma_cmd *cmd)
8580{
8581 const char *intf = get_param(cmd, "Interface");
8582 const char *val, *bssid;
8583 int res;
8584 char *buf;
8585 size_t buf_len;
8586
8587 val = get_param(cmd, "BSSID_FILTER");
8588 if (val == NULL)
8589 return -1;
8590
8591 bssid = get_param(cmd, "BSSID_List");
8592 if (atoi(val) == 0 || bssid == NULL) {
8593 /* Disable BSSID filter */
8594 if (wpa_command(intf, "SET bssid_filter ")) {
8595 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
8596 "to disable BSSID filter");
8597 return 0;
8598 }
8599
8600 return 1;
8601 }
8602
8603 buf_len = 100 + strlen(bssid);
8604 buf = malloc(buf_len);
8605 if (buf == NULL)
8606 return -1;
8607
8608 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
8609 res = wpa_command(intf, buf);
8610 free(buf);
8611 if (res) {
8612 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
8613 "BSSID filter");
8614 return 0;
8615 }
8616
8617 return 1;
8618}
8619
8620
8621static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
8622 struct sigma_cmd *cmd)
8623{
8624 const char *intf = get_param(cmd, "Interface");
8625 const char *val;
8626
8627 /* TODO: ARP */
8628
8629 val = get_param(cmd, "HS2_CACHE_PROFILE");
8630 if (val && strcasecmp(val, "All") == 0)
8631 hs2_clear_credentials(intf);
8632
8633 return 1;
8634}
8635
8636
8637static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
8638 struct sigma_cmd *cmd)
8639{
8640 const char *intf = get_param(cmd, "Interface");
8641 const char *key_type = get_param(cmd, "KeyType");
8642 char buf[100], resp[200];
8643
8644 if (key_type == NULL)
8645 return -1;
8646
8647 if (strcasecmp(key_type, "GTK") == 0) {
8648 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
8649 strncmp(buf, "FAIL", 4) == 0) {
8650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8651 "not fetch current GTK");
8652 return 0;
8653 }
8654 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
8655 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8656 return 0;
8657 } else {
8658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8659 "KeyType");
8660 return 0;
8661 }
8662
8663 return 1;
8664}
8665
8666
8667static int hs2_set_policy(struct sigma_dut *dut)
8668{
8669#ifdef ANDROID
8670 system("ip rule del prio 23000");
8671 if (system("ip rule add from all lookup main prio 23000") != 0) {
8672 sigma_dut_print(dut, DUT_MSG_ERROR,
8673 "Failed to run:ip rule add from all lookup main prio");
8674 return -1;
8675 }
8676 if (system("ip route flush cache") != 0) {
8677 sigma_dut_print(dut, DUT_MSG_ERROR,
8678 "Failed to run ip route flush cache");
8679 return -1;
8680 }
8681 return 1;
8682#else /* ANDROID */
8683 return 0;
8684#endif /* ANDROID */
8685}
8686
8687
8688static int cmd_sta_hs2_associate(struct sigma_dut *dut,
8689 struct sigma_conn *conn,
8690 struct sigma_cmd *cmd)
8691{
8692 const char *intf = get_param(cmd, "Interface");
8693 const char *val = get_param(cmd, "Ignore_blacklist");
8694 struct wpa_ctrl *ctrl;
8695 int res;
8696 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
8697 int tries = 0;
8698 int ignore_blacklist = 0;
8699 const char *events[] = {
8700 "CTRL-EVENT-CONNECTED",
8701 "INTERWORKING-BLACKLISTED",
8702 "INTERWORKING-NO-MATCH",
8703 NULL
8704 };
8705
8706 start_sta_mode(dut);
8707
8708 blacklisted[0] = '\0';
8709 if (val && atoi(val))
8710 ignore_blacklist = 1;
8711
8712try_again:
8713 ctrl = open_wpa_mon(intf);
8714 if (ctrl == NULL) {
8715 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8716 "wpa_supplicant monitor connection");
8717 return -2;
8718 }
8719
8720 tries++;
8721 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
8722 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
8723 "Interworking connection");
8724 wpa_ctrl_detach(ctrl);
8725 wpa_ctrl_close(ctrl);
8726 return 0;
8727 }
8728
8729 buf[0] = '\0';
8730 while (1) {
8731 char *pos;
8732 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
8733 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
8734 if (!pos)
8735 break;
8736 pos += 25;
8737 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
8738 pos);
8739 if (!blacklisted[0])
8740 memcpy(blacklisted, pos, strlen(pos) + 1);
8741 }
8742
8743 if (ignore_blacklist && blacklisted[0]) {
8744 char *end;
8745 end = strchr(blacklisted, ' ');
8746 if (end)
8747 *end = '\0';
8748 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
8749 blacklisted);
8750 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
8751 blacklisted);
8752 if (wpa_command(intf, buf)) {
8753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
8754 wpa_ctrl_detach(ctrl);
8755 wpa_ctrl_close(ctrl);
8756 return 0;
8757 }
8758 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8759 buf, sizeof(buf));
8760 }
8761
8762 wpa_ctrl_detach(ctrl);
8763 wpa_ctrl_close(ctrl);
8764
8765 if (res < 0) {
8766 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8767 "connect");
8768 return 0;
8769 }
8770
8771 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
8772 strstr(buf, "INTERWORKING-BLACKLISTED")) {
8773 if (tries < 2) {
8774 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
8775 goto try_again;
8776 }
8777 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
8778 "matching credentials found");
8779 return 0;
8780 }
8781
8782 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8783 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8784 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8785 "get current BSSID/SSID");
8786 return 0;
8787 }
8788
8789 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
8790 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8791 hs2_set_policy(dut);
8792 return 0;
8793}
8794
8795
8796static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
8797 struct sigma_conn *conn,
8798 const char *ifname,
8799 struct sigma_cmd *cmd)
8800{
8801 const char *val;
8802 int id;
8803
8804 id = add_cred(ifname);
8805 if (id < 0)
8806 return -2;
8807 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8808
8809 val = get_param(cmd, "prefer");
8810 if (val && atoi(val) > 0)
8811 set_cred(ifname, id, "priority", "1");
8812
8813 val = get_param(cmd, "REALM");
8814 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
8815 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8816 "realm");
8817 return 0;
8818 }
8819
8820 val = get_param(cmd, "HOME_FQDN");
8821 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
8822 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8823 "home_fqdn");
8824 return 0;
8825 }
8826
8827 val = get_param(cmd, "Username");
8828 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
8829 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8830 "username");
8831 return 0;
8832 }
8833
8834 val = get_param(cmd, "Password");
8835 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
8836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8837 "password");
8838 return 0;
8839 }
8840
8841 val = get_param(cmd, "ROOT_CA");
8842 if (val) {
8843 char fname[200];
8844 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8845#ifdef __linux__
8846 if (!file_exists(fname)) {
8847 char msg[300];
8848 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
8849 "file (%s) not found", fname);
8850 send_resp(dut, conn, SIGMA_ERROR, msg);
8851 return 0;
8852 }
8853#endif /* __linux__ */
8854 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
8855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8856 "not set root CA");
8857 return 0;
8858 }
8859 }
8860
8861 return 1;
8862}
8863
8864
8865static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
8866{
8867 FILE *in, *out;
8868 char buf[500];
8869 int found = 0;
8870
8871 in = fopen("devdetail.xml", "r");
8872 if (in == NULL)
8873 return -1;
8874 out = fopen("devdetail.xml.tmp", "w");
8875 if (out == NULL) {
8876 fclose(in);
8877 return -1;
8878 }
8879
8880 while (fgets(buf, sizeof(buf), in)) {
8881 char *pos = strstr(buf, "<IMSI>");
8882 if (pos) {
8883 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
8884 imsi);
8885 pos += 6;
8886 *pos = '\0';
8887 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
8888 found++;
8889 } else {
8890 fprintf(out, "%s", buf);
8891 }
8892 }
8893
8894 fclose(out);
8895 fclose(in);
8896 if (found)
8897 rename("devdetail.xml.tmp", "devdetail.xml");
8898 else
8899 unlink("devdetail.xml.tmp");
8900
8901 return 0;
8902}
8903
8904
8905static int sta_add_credential_sim(struct sigma_dut *dut,
8906 struct sigma_conn *conn,
8907 const char *ifname, struct sigma_cmd *cmd)
8908{
8909 const char *val, *imsi = NULL;
8910 int id;
8911 char buf[200];
8912 int res;
8913 const char *pos;
8914 size_t mnc_len;
8915 char plmn_mcc[4];
8916 char plmn_mnc[4];
8917
8918 id = add_cred(ifname);
8919 if (id < 0)
8920 return -2;
8921 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8922
8923 val = get_param(cmd, "prefer");
8924 if (val && atoi(val) > 0)
8925 set_cred(ifname, id, "priority", "1");
8926
8927 val = get_param(cmd, "PLMN_MCC");
8928 if (val == NULL) {
8929 send_resp(dut, conn, SIGMA_ERROR,
8930 "errorCode,Missing PLMN_MCC");
8931 return 0;
8932 }
8933 if (strlen(val) != 3) {
8934 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
8935 return 0;
8936 }
8937 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
8938
8939 val = get_param(cmd, "PLMN_MNC");
8940 if (val == NULL) {
8941 send_resp(dut, conn, SIGMA_ERROR,
8942 "errorCode,Missing PLMN_MNC");
8943 return 0;
8944 }
8945 if (strlen(val) != 2 && strlen(val) != 3) {
8946 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
8947 return 0;
8948 }
8949 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
8950
8951 val = get_param(cmd, "IMSI");
8952 if (val == NULL) {
8953 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
8954 "IMSI");
8955 return 0;
8956 }
8957
8958 imsi = pos = val;
8959
8960 if (strncmp(plmn_mcc, pos, 3) != 0) {
8961 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
8962 return 0;
8963 }
8964 pos += 3;
8965
8966 mnc_len = strlen(plmn_mnc);
8967 if (mnc_len < 2) {
8968 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
8969 return 0;
8970 }
8971
8972 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
8973 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
8974 return 0;
8975 }
8976 pos += mnc_len;
8977
8978 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
8979 if (res < 0 || res >= (int) sizeof(buf))
8980 return -1;
8981 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
8982 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8983 "not set IMSI");
8984 return 0;
8985 }
8986
8987 val = get_param(cmd, "Password");
8988 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
8989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8990 "not set password");
8991 return 0;
8992 }
8993
8994 if (dut->program == PROGRAM_HS2_R2) {
8995 /*
8996 * Set provisioning_sp for the test cases where SIM/USIM
8997 * provisioning is used.
8998 */
8999 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
9000 "wi-fi.org") < 0) {
9001 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9002 "not set provisioning_sp");
9003 return 0;
9004 }
9005
9006 update_devdetail_imsi(dut, imsi);
9007 }
9008
9009 return 1;
9010}
9011
9012
9013static int sta_add_credential_cert(struct sigma_dut *dut,
9014 struct sigma_conn *conn,
9015 const char *ifname,
9016 struct sigma_cmd *cmd)
9017{
9018 const char *val;
9019 int id;
9020
9021 id = add_cred(ifname);
9022 if (id < 0)
9023 return -2;
9024 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9025
9026 val = get_param(cmd, "prefer");
9027 if (val && atoi(val) > 0)
9028 set_cred(ifname, id, "priority", "1");
9029
9030 val = get_param(cmd, "REALM");
9031 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9032 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9033 "realm");
9034 return 0;
9035 }
9036
9037 val = get_param(cmd, "HOME_FQDN");
9038 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9039 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9040 "home_fqdn");
9041 return 0;
9042 }
9043
9044 val = get_param(cmd, "Username");
9045 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9046 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9047 "username");
9048 return 0;
9049 }
9050
9051 val = get_param(cmd, "clientCertificate");
9052 if (val) {
9053 char fname[200];
9054 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9055#ifdef __linux__
9056 if (!file_exists(fname)) {
9057 char msg[300];
9058 snprintf(msg, sizeof(msg),
9059 "ErrorCode,clientCertificate "
9060 "file (%s) not found", fname);
9061 send_resp(dut, conn, SIGMA_ERROR, msg);
9062 return 0;
9063 }
9064#endif /* __linux__ */
9065 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
9066 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9067 "not set client_cert");
9068 return 0;
9069 }
9070 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
9071 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9072 "not set private_key");
9073 return 0;
9074 }
9075 }
9076
9077 val = get_param(cmd, "ROOT_CA");
9078 if (val) {
9079 char fname[200];
9080 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9081#ifdef __linux__
9082 if (!file_exists(fname)) {
9083 char msg[300];
9084 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9085 "file (%s) not found", fname);
9086 send_resp(dut, conn, SIGMA_ERROR, msg);
9087 return 0;
9088 }
9089#endif /* __linux__ */
9090 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9091 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9092 "not set root CA");
9093 return 0;
9094 }
9095 }
9096
9097 return 1;
9098}
9099
9100
9101static int cmd_sta_add_credential(struct sigma_dut *dut,
9102 struct sigma_conn *conn,
9103 struct sigma_cmd *cmd)
9104{
9105 const char *intf = get_param(cmd, "Interface");
9106 const char *type;
9107
9108 start_sta_mode(dut);
9109
9110 type = get_param(cmd, "Type");
9111 if (!type)
9112 return -1;
9113
9114 if (strcasecmp(type, "uname_pwd") == 0)
9115 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9116
9117 if (strcasecmp(type, "sim") == 0)
9118 return sta_add_credential_sim(dut, conn, intf, cmd);
9119
9120 if (strcasecmp(type, "cert") == 0)
9121 return sta_add_credential_cert(dut, conn, intf, cmd);
9122
9123 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9124 "type");
9125 return 0;
9126}
9127
9128
9129static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9130 struct sigma_cmd *cmd)
9131{
9132 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309133 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009134 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309135 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009136 int res;
9137
9138 val = get_param(cmd, "HESSID");
9139 if (val) {
9140 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9141 if (res < 0 || res >= (int) sizeof(buf))
9142 return -1;
9143 wpa_command(intf, buf);
9144 }
9145
9146 val = get_param(cmd, "ACCS_NET_TYPE");
9147 if (val) {
9148 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9149 val);
9150 if (res < 0 || res >= (int) sizeof(buf))
9151 return -1;
9152 wpa_command(intf, buf);
9153 }
9154
vamsi krishna89ad8c62017-09-19 12:51:18 +05309155 bssid = get_param(cmd, "Bssid");
9156 ssid = get_param(cmd, "Ssid");
9157
9158 if (ssid) {
9159 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9160 send_resp(dut, conn, SIGMA_ERROR,
9161 "ErrorCode,Too long SSID");
9162 return 0;
9163 }
9164 ascii2hexstr(ssid, ssid_hex);
9165 }
9166
9167 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9168 bssid ? " bssid=": "",
9169 bssid ? bssid : "",
9170 ssid ? " ssid " : "",
9171 ssid ? ssid_hex : "");
9172 if (res < 0 || res >= (int) sizeof(buf))
9173 return -1;
9174
9175 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009176 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9177 "scan");
9178 return 0;
9179 }
9180
9181 return 1;
9182}
9183
9184
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009185static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9186 struct sigma_cmd *cmd)
9187{
9188 const char *intf = get_param(cmd, "Interface");
9189 const char *bssid;
9190 char buf[4096], *pos;
9191 int freq, chan;
9192 char *ssid;
9193 char resp[100];
9194 int res;
9195 struct wpa_ctrl *ctrl;
9196
9197 bssid = get_param(cmd, "BSSID");
9198 if (!bssid) {
9199 send_resp(dut, conn, SIGMA_INVALID,
9200 "errorCode,BSSID argument is missing");
9201 return 0;
9202 }
9203
9204 ctrl = open_wpa_mon(intf);
9205 if (!ctrl) {
9206 sigma_dut_print(dut, DUT_MSG_ERROR,
9207 "Failed to open wpa_supplicant monitor connection");
9208 return -1;
9209 }
9210
9211 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9212 send_resp(dut, conn, SIGMA_ERROR,
9213 "errorCode,Could not start scan");
9214 wpa_ctrl_detach(ctrl);
9215 wpa_ctrl_close(ctrl);
9216 return 0;
9217 }
9218
9219 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9220 buf, sizeof(buf));
9221
9222 wpa_ctrl_detach(ctrl);
9223 wpa_ctrl_close(ctrl);
9224
9225 if (res < 0) {
9226 send_resp(dut, conn, SIGMA_ERROR,
9227 "errorCode,Scan did not complete");
9228 return 0;
9229 }
9230
9231 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9232 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9233 strncmp(buf, "id=", 3) != 0) {
9234 send_resp(dut, conn, SIGMA_ERROR,
9235 "errorCode,Specified BSSID not found");
9236 return 0;
9237 }
9238
9239 pos = strstr(buf, "\nfreq=");
9240 if (!pos) {
9241 send_resp(dut, conn, SIGMA_ERROR,
9242 "errorCode,Channel not found");
9243 return 0;
9244 }
9245 freq = atoi(pos + 6);
9246 chan = freq_to_channel(freq);
9247
9248 pos = strstr(buf, "\nssid=");
9249 if (!pos) {
9250 send_resp(dut, conn, SIGMA_ERROR,
9251 "errorCode,SSID not found");
9252 return 0;
9253 }
9254 ssid = pos + 6;
9255 pos = strchr(ssid, '\n');
9256 if (pos)
9257 *pos = '\0';
9258 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9259 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9260 return 0;
9261}
9262
9263
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009264static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9265 struct sigma_cmd *cmd)
9266{
9267#ifdef __linux__
9268 struct timeval tv;
9269 struct tm tm;
9270 time_t t;
9271 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309272 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009273
9274 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9275
9276 memset(&tm, 0, sizeof(tm));
9277 val = get_param(cmd, "seconds");
9278 if (val)
9279 tm.tm_sec = atoi(val);
9280 val = get_param(cmd, "minutes");
9281 if (val)
9282 tm.tm_min = atoi(val);
9283 val = get_param(cmd, "hours");
9284 if (val)
9285 tm.tm_hour = atoi(val);
9286 val = get_param(cmd, "date");
9287 if (val)
9288 tm.tm_mday = atoi(val);
9289 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309290 if (val) {
9291 v = atoi(val);
9292 if (v < 1 || v > 12) {
9293 send_resp(dut, conn, SIGMA_INVALID,
9294 "errorCode,Invalid month");
9295 return 0;
9296 }
9297 tm.tm_mon = v - 1;
9298 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009299 val = get_param(cmd, "year");
9300 if (val) {
9301 int year = atoi(val);
9302#ifdef ANDROID
9303 if (year > 2035)
9304 year = 2035; /* years beyond 2035 not supported */
9305#endif /* ANDROID */
9306 tm.tm_year = year - 1900;
9307 }
9308 t = mktime(&tm);
9309 if (t == (time_t) -1) {
9310 send_resp(dut, conn, SIGMA_ERROR,
9311 "errorCode,Invalid date or time");
9312 return 0;
9313 }
9314
9315 memset(&tv, 0, sizeof(tv));
9316 tv.tv_sec = t;
9317
9318 if (settimeofday(&tv, NULL) < 0) {
9319 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9320 strerror(errno));
9321 send_resp(dut, conn, SIGMA_ERROR,
9322 "errorCode,Failed to set time");
9323 return 0;
9324 }
9325
9326 return 1;
9327#endif /* __linux__ */
9328
9329 return -1;
9330}
9331
9332
9333static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9334 struct sigma_cmd *cmd)
9335{
9336 const char *intf = get_param(cmd, "Interface");
9337 const char *name, *val;
9338 int prod_ess_assoc = 1;
9339 char buf[200], bssid[100], ssid[100];
9340 int res;
9341 struct wpa_ctrl *ctrl;
9342
9343 name = get_param(cmd, "osuFriendlyName");
9344
9345 val = get_param(cmd, "ProdESSAssoc");
9346 if (val)
9347 prod_ess_assoc = atoi(val);
9348
9349 kill_dhcp_client(dut, intf);
9350 if (start_dhcp_client(dut, intf) < 0)
9351 return -2;
9352
9353 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9354 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9355 res = snprintf(buf, sizeof(buf),
9356 "%s %s%s%s signup osu-ca.pem",
9357 prod_ess_assoc ? "" : "-N",
9358 name ? "-O'" : "", name ? name : "",
9359 name ? "'" : "");
9360
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309361 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009362 if (run_hs20_osu(dut, buf) < 0) {
9363 FILE *f;
9364
9365 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9366
9367 f = fopen("hs20-osu-client.res", "r");
9368 if (f) {
9369 char resp[400], res[300], *pos;
9370 if (!fgets(res, sizeof(res), f))
9371 res[0] = '\0';
9372 pos = strchr(res, '\n');
9373 if (pos)
9374 *pos = '\0';
9375 fclose(f);
9376 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
9377 res);
9378 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
9379 if (system(resp) != 0) {
9380 }
9381 snprintf(resp, sizeof(resp),
9382 "SSID,,BSSID,,failureReason,%s", res);
9383 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9384 return 0;
9385 }
9386
9387 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9388 return 0;
9389 }
9390
9391 if (!prod_ess_assoc)
9392 goto report;
9393
9394 ctrl = open_wpa_mon(intf);
9395 if (ctrl == NULL) {
9396 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9397 "wpa_supplicant monitor connection");
9398 return -1;
9399 }
9400
9401 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9402 buf, sizeof(buf));
9403
9404 wpa_ctrl_detach(ctrl);
9405 wpa_ctrl_close(ctrl);
9406
9407 if (res < 0) {
9408 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
9409 "network after OSU");
9410 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9411 return 0;
9412 }
9413
9414report:
9415 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9416 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9417 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
9418 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9419 return 0;
9420 }
9421
9422 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
9423 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009424 return 0;
9425}
9426
9427
9428static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
9429 struct sigma_cmd *cmd)
9430{
9431 const char *val;
9432 int timeout = 120;
9433
9434 val = get_param(cmd, "PolicyUpdate");
9435 if (val == NULL || atoi(val) == 0)
9436 return 1; /* No operation requested */
9437
9438 val = get_param(cmd, "Timeout");
9439 if (val)
9440 timeout = atoi(val);
9441
9442 if (timeout) {
9443 /* TODO: time out the command and return
9444 * PolicyUpdateStatus,TIMEOUT if needed. */
9445 }
9446
9447 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
9448 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9449 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
9450 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
9451 return 0;
9452 }
9453
9454 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
9455 return 0;
9456}
9457
9458
9459static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
9460 struct sigma_cmd *cmd)
9461{
9462 struct wpa_ctrl *ctrl;
9463 const char *intf = get_param(cmd, "Interface");
9464 const char *bssid = get_param(cmd, "Bssid");
9465 const char *ssid = get_param(cmd, "SSID");
9466 const char *security = get_param(cmd, "Security");
9467 const char *passphrase = get_param(cmd, "Passphrase");
9468 const char *pin = get_param(cmd, "PIN");
9469 char buf[1000];
9470 char ssid_hex[200], passphrase_hex[200];
9471 const char *keymgmt, *cipher;
9472
9473 if (intf == NULL)
9474 intf = get_main_ifname();
9475
9476 if (!bssid) {
9477 send_resp(dut, conn, SIGMA_ERROR,
9478 "ErrorCode,Missing Bssid argument");
9479 return 0;
9480 }
9481
9482 if (!ssid) {
9483 send_resp(dut, conn, SIGMA_ERROR,
9484 "ErrorCode,Missing SSID argument");
9485 return 0;
9486 }
9487
9488 if (!security) {
9489 send_resp(dut, conn, SIGMA_ERROR,
9490 "ErrorCode,Missing Security argument");
9491 return 0;
9492 }
9493
9494 if (!passphrase) {
9495 send_resp(dut, conn, SIGMA_ERROR,
9496 "ErrorCode,Missing Passphrase argument");
9497 return 0;
9498 }
9499
9500 if (!pin) {
9501 send_resp(dut, conn, SIGMA_ERROR,
9502 "ErrorCode,Missing PIN argument");
9503 return 0;
9504 }
9505
vamsi krishna8c9c1562017-05-12 15:51:46 +05309506 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
9507 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009508 send_resp(dut, conn, SIGMA_ERROR,
9509 "ErrorCode,Too long SSID/passphrase");
9510 return 0;
9511 }
9512
9513 ctrl = open_wpa_mon(intf);
9514 if (ctrl == NULL) {
9515 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9516 "wpa_supplicant monitor connection");
9517 return -2;
9518 }
9519
9520 if (strcasecmp(security, "wpa2-psk") == 0) {
9521 keymgmt = "WPA2PSK";
9522 cipher = "CCMP";
9523 } else {
9524 wpa_ctrl_detach(ctrl);
9525 wpa_ctrl_close(ctrl);
9526 send_resp(dut, conn, SIGMA_ERROR,
9527 "ErrorCode,Unsupported Security value");
9528 return 0;
9529 }
9530
9531 ascii2hexstr(ssid, ssid_hex);
9532 ascii2hexstr(passphrase, passphrase_hex);
9533 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
9534 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
9535
9536 if (wpa_command(intf, buf) < 0) {
9537 wpa_ctrl_detach(ctrl);
9538 wpa_ctrl_close(ctrl);
9539 send_resp(dut, conn, SIGMA_ERROR,
9540 "ErrorCode,Failed to start registrar");
9541 return 0;
9542 }
9543
9544 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
9545 dut->er_oper_performed = 1;
9546
9547 return wps_connection_event(dut, conn, ctrl, intf, 0);
9548}
9549
9550
9551static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
9552 struct sigma_conn *conn,
9553 struct sigma_cmd *cmd)
9554{
9555 struct wpa_ctrl *ctrl;
9556 const char *intf = get_param(cmd, "Interface");
9557 const char *bssid = get_param(cmd, "Bssid");
9558 char buf[100];
9559
9560 if (!bssid) {
9561 send_resp(dut, conn, SIGMA_ERROR,
9562 "ErrorCode,Missing Bssid argument");
9563 return 0;
9564 }
9565
9566 ctrl = open_wpa_mon(intf);
9567 if (ctrl == NULL) {
9568 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9569 "wpa_supplicant monitor connection");
9570 return -2;
9571 }
9572
9573 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
9574
9575 if (wpa_command(intf, buf) < 0) {
9576 wpa_ctrl_detach(ctrl);
9577 wpa_ctrl_close(ctrl);
9578 send_resp(dut, conn, SIGMA_ERROR,
9579 "ErrorCode,Failed to start registrar");
9580 return 0;
9581 }
9582
9583 return wps_connection_event(dut, conn, ctrl, intf, 0);
9584}
9585
9586
vamsi krishna9b144002017-09-20 13:28:13 +05309587static int cmd_start_wps_registration(struct sigma_dut *dut,
9588 struct sigma_conn *conn,
9589 struct sigma_cmd *cmd)
9590{
9591 struct wpa_ctrl *ctrl;
9592 const char *intf = get_param(cmd, "Interface");
9593 const char *role, *method;
9594 int res;
9595 char buf[256];
9596 const char *events[] = {
9597 "CTRL-EVENT-CONNECTED",
9598 "WPS-OVERLAP-DETECTED",
9599 "WPS-TIMEOUT",
9600 "WPS-FAIL",
9601 NULL
9602 };
9603
9604 ctrl = open_wpa_mon(intf);
9605 if (!ctrl) {
9606 sigma_dut_print(dut, DUT_MSG_ERROR,
9607 "Failed to open wpa_supplicant monitor connection");
9608 return -2;
9609 }
9610
9611 role = get_param(cmd, "WpsRole");
9612 if (!role) {
9613 send_resp(dut, conn, SIGMA_INVALID,
9614 "ErrorCode,WpsRole not provided");
9615 goto fail;
9616 }
9617
9618 if (strcasecmp(role, "Enrollee") == 0) {
9619 method = get_param(cmd, "WpsConfigMethod");
9620 if (!method) {
9621 send_resp(dut, conn, SIGMA_INVALID,
9622 "ErrorCode,WpsConfigMethod not provided");
9623 goto fail;
9624 }
9625 if (strcasecmp(method, "PBC") == 0) {
9626 if (wpa_command(intf, "WPS_PBC") < 0) {
9627 send_resp(dut, conn, SIGMA_ERROR,
9628 "ErrorCode,Failed to enable PBC");
9629 goto fail;
9630 }
9631 } else {
9632 /* TODO: PIN method */
9633 send_resp(dut, conn, SIGMA_ERROR,
9634 "ErrorCode,Unsupported WpsConfigMethod value");
9635 goto fail;
9636 }
9637 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9638 if (res < 0) {
9639 send_resp(dut, conn, SIGMA_ERROR,
9640 "ErrorCode,WPS connection did not complete");
9641 goto fail;
9642 }
9643 if (strstr(buf, "WPS-TIMEOUT")) {
9644 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
9645 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
9646 send_resp(dut, conn, SIGMA_ERROR,
9647 "ErrorCode,OverlapSession");
9648 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
9649 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
9650 } else {
9651 send_resp(dut, conn, SIGMA_ERROR,
9652 "ErrorCode,WPS operation failed");
9653 }
9654 } else {
9655 /* TODO: Registrar role */
9656 send_resp(dut, conn, SIGMA_ERROR,
9657 "ErrorCode,Unsupported WpsRole value");
9658 }
9659
9660fail:
9661 wpa_ctrl_detach(ctrl);
9662 wpa_ctrl_close(ctrl);
9663 return 0;
9664}
9665
9666
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009667static int req_intf(struct sigma_cmd *cmd)
9668{
9669 return get_param(cmd, "interface") == NULL ? -1 : 0;
9670}
9671
9672
9673void sta_register_cmds(void)
9674{
9675 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
9676 cmd_sta_get_ip_config);
9677 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
9678 cmd_sta_set_ip_config);
9679 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
9680 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
9681 cmd_sta_get_mac_address);
9682 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
9683 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
9684 cmd_sta_verify_ip_connection);
9685 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
9686 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
9687 cmd_sta_set_encryption);
9688 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
9689 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
9690 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
9691 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
9692 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
9693 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
9694 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
9695 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
9696 cmd_sta_set_eapakaprime);
9697 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
9698 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
9699 /* TODO: sta_set_ibss */
9700 /* TODO: sta_set_mode */
9701 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
9702 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
9703 /* TODO: sta_up_load */
9704 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
9705 cmd_sta_preset_testparameters);
9706 /* TODO: sta_set_system */
9707 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
9708 /* TODO: sta_set_rifs_test */
9709 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
9710 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
9711 /* TODO: sta_send_coexist_mgmt */
9712 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
9713 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
9714 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
9715 sigma_dut_reg_cmd("sta_reset_default", req_intf,
9716 cmd_sta_reset_default);
9717 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
9718 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
9719 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
9720 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
9721 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
9722 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
9723 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
9724 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
9725 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
9726 cmd_sta_hs2_associate);
9727 sigma_dut_reg_cmd("sta_add_credential", req_intf,
9728 cmd_sta_add_credential);
9729 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009730 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009731 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
9732 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
9733 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
9734 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
9735 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
9736 cmd_sta_wps_connect_pw_token);
9737 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
9738 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
9739 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +05309740 sigma_dut_reg_cmd("start_wps_registration", req_intf,
9741 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009742}