blob: a1bbe1aede31837527b86e1da6a30dfb8404fbcc [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>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020015#include <regex.h>
16#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020017#include <sys/time.h>
18#include <netpacket/packet.h>
19#include <linux/if_ether.h>
20#ifdef ANDROID
21#include <cutils/properties.h>
22#include <android/log.h>
23#include "keystore_get.h"
24#else /* ANDROID */
25#include <ifaddrs.h>
26#endif /* ANDROID */
27#include <netdb.h>
28#endif /* __linux__ */
29#ifdef __QNXNTO__
30#include <net/if_dl.h>
31#endif /* __QNXNTO__ */
32#include "wpa_ctrl.h"
33#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070034#include "miracast.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020035
36/* Temporary files for sta_send_addba */
37#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
38#define VI_QOS_FILE "/tmp/vi-qos.txt"
39#define VI_QOS_REFFILE "/etc/vi-qos.txt"
40
41/*
42 * MTU for Ethernet need to take into account 8-byte SNAP header
43 * to be added when encapsulating Ethernet frame into 802.11
44 */
45#ifndef IEEE80211_MAX_DATA_LEN_DMG
46#define IEEE80211_MAX_DATA_LEN_DMG 7920
47#endif
48#ifndef IEEE80211_SNAP_LEN_DMG
49#define IEEE80211_SNAP_LEN_DMG 8
50#endif
51
Ashwini Patil00402582017-04-13 12:29:39 +053052#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053053#define NEIGHBOR_REPORT_SIZE 1000
54#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
55#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053056
Jouni Malinencd4e3c32015-10-29 12:39:56 +020057extern char *sigma_wpas_ctrl;
58extern char *sigma_cert_path;
59extern enum driver_type wifi_chip_type;
60extern char *sigma_radio_ifname[];
61
Lior David0fe101e2017-03-09 16:09:50 +020062#ifdef __linux__
63#define WIL_WMI_MAX_PAYLOAD 248
64#define WIL_WMI_BF_TRIG_CMDID 0x83a
65
66struct wil_wmi_header {
67 uint8_t mid;
68 uint8_t reserved;
69 uint16_t cmd;
70 uint32_t ts;
71} __attribute__((packed));
72
73enum wil_wmi_bf_trig_type {
74 WIL_WMI_SLS,
75 WIL_WMI_BRP_RX,
76 WIL_WMI_BRP_TX,
77};
78
79struct wil_wmi_bf_trig_cmd {
80 /* enum wil_wmi_bf_trig_type */
81 uint32_t bf_type;
82 /* cid when type == WMI_BRP_RX */
83 uint32_t sta_id;
84 uint32_t reserved;
85 /* mac address when type = WIL_WMI_SLS */
86 uint8_t dest_mac[6];
87} __attribute__((packed));
88#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020089
90#ifdef ANDROID
91
92static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
93
94#define ANDROID_KEYSTORE_GET 'g'
95#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
96
97static int android_keystore_get(char cmd, const char *key, unsigned char *val)
98{
Jouni Malinencd4e3c32015-10-29 12:39:56 +020099 /* Android 4.3 changed keystore design, so need to use keystore_get() */
100#ifndef KEYSTORE_MESSAGE_SIZE
101#define KEYSTORE_MESSAGE_SIZE 65535
102#endif /* KEYSTORE_MESSAGE_SIZE */
103
104 ssize_t len;
105 uint8_t *value = NULL;
106
107 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
108 "keystore command '%c' key '%s' --> keystore_get",
109 cmd, key);
110
111 len = keystore_get(key, strlen(key), &value);
112 if (len < 0) {
113 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
114 "keystore_get() failed");
115 return -1;
116 }
117
118 if (len > KEYSTORE_MESSAGE_SIZE)
119 len = KEYSTORE_MESSAGE_SIZE;
120 memcpy(val, value, len);
121 free(value);
122 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200123}
124#endif /* ANDROID */
125
126
127int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
128{
129#ifdef __linux__
130 char buf[100];
131
132 if (wifi_chip_type == DRIVER_WCN) {
133 if (enabled) {
134 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530135 if (system(buf) != 0)
136 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200137 } else {
138 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530139 if (system(buf) != 0)
140 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200141 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530142 if (system(buf) != 0)
143 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200144 }
145
146 return 0;
147 }
148
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530149set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200150 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
151 intf, enabled ? "on" : "off");
152 if (system(buf) != 0) {
153 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
154 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530155 if (system(buf) != 0) {
156 sigma_dut_print(dut, DUT_MSG_ERROR,
157 "Failed to set power save %s",
158 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200159 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530160 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200161 }
162
163 return 0;
164#else /* __linux__ */
165 return -1;
166#endif /* __linux__ */
167}
168
169
Lior Davidcc88b562017-01-03 18:52:09 +0200170#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200171
Lior Davidcc88b562017-01-03 18:52:09 +0200172static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
173 size_t len)
174{
175 DIR *dir, *wil_dir;
176 struct dirent *entry;
177 int ret = -1;
178 const char *root_path = "/sys/kernel/debug/ieee80211";
179
180 dir = opendir(root_path);
181 if (!dir)
182 return -2;
183
184 while ((entry = readdir(dir))) {
185 if (strcmp(entry->d_name, ".") == 0 ||
186 strcmp(entry->d_name, "..") == 0)
187 continue;
188
189 if (snprintf(path, len, "%s/%s/wil6210",
190 root_path, entry->d_name) >= (int) len) {
191 ret = -3;
192 break;
193 }
194
195 wil_dir = opendir(path);
196 if (wil_dir) {
197 closedir(wil_dir);
198 ret = 0;
199 break;
200 }
201 }
202
203 closedir(dir);
204 return ret;
205}
Lior David0fe101e2017-03-09 16:09:50 +0200206
207
208static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
209 void *payload, uint16_t length)
210{
211 struct {
212 struct wil_wmi_header hdr;
213 char payload[WIL_WMI_MAX_PAYLOAD];
214 } __attribute__((packed)) cmd;
215 char buf[128], fname[128];
216 size_t towrite, written;
217 FILE *f;
218
219 if (length > WIL_WMI_MAX_PAYLOAD) {
220 sigma_dut_print(dut, DUT_MSG_ERROR,
221 "payload too large(%u, max %u)",
222 length, WIL_WMI_MAX_PAYLOAD);
223 return -1;
224 }
225
226 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
227 cmd.hdr.cmd = command;
228 memcpy(cmd.payload, payload, length);
229
230 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
231 sigma_dut_print(dut, DUT_MSG_ERROR,
232 "failed to get wil6210 debugfs dir");
233 return -1;
234 }
235
236 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
237 f = fopen(fname, "wb");
238 if (!f) {
239 sigma_dut_print(dut, DUT_MSG_ERROR,
240 "failed to open: %s", fname);
241 return -1;
242 }
243
244 towrite = sizeof(cmd.hdr) + length;
245 written = fwrite(&cmd, 1, towrite, f);
246 fclose(f);
247 if (written != towrite) {
248 sigma_dut_print(dut, DUT_MSG_ERROR,
249 "failed to send wmi %u", command);
250 return -1;
251 }
252
253 return 0;
254}
255
256
257static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
258 const char *pattern, unsigned int *field)
259{
260 char buf[128], fname[128];
261 FILE *f;
262 regex_t re;
263 regmatch_t m[2];
264 int rc, ret = -1;
265
266 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "failed to get wil6210 debugfs dir");
269 return -1;
270 }
271
272 snprintf(fname, sizeof(fname), "%s/stations", buf);
273 f = fopen(fname, "r");
274 if (!f) {
275 sigma_dut_print(dut, DUT_MSG_ERROR,
276 "failed to open: %s", fname);
277 return -1;
278 }
279
280 if (regcomp(&re, pattern, REG_EXTENDED)) {
281 sigma_dut_print(dut, DUT_MSG_ERROR,
282 "regcomp failed: %s", pattern);
283 goto out;
284 }
285
286 /*
287 * find the entry for the mac address
288 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
289 */
290 while (fgets(buf, sizeof(buf), f)) {
291 if (strcasestr(buf, bssid)) {
292 /* extract the field (CID/AID/state) */
293 rc = regexec(&re, buf, 2, m, 0);
294 if (!rc && (m[1].rm_so >= 0)) {
295 buf[m[1].rm_eo] = 0;
296 *field = atoi(&buf[m[1].rm_so]);
297 ret = 0;
298 break;
299 }
300 }
301 }
302
303 regfree(&re);
304 if (ret)
305 sigma_dut_print(dut, DUT_MSG_ERROR,
306 "could not extract field");
307
308out:
309 fclose(f);
310
311 return ret;
312}
313
314
315static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
316 unsigned int *cid)
317{
318 const char *pattern = "\\[([0-9]+)\\]";
319
320 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
321}
322
323
324static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
325 int l_rx)
326{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700327 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200328 unsigned int cid;
329
Rakesh Sunki556237d2017-03-30 14:49:31 -0700330 memset(&cmd, 0, sizeof(cmd));
331
Lior David0fe101e2017-03-09 16:09:50 +0200332 if (wil6210_get_cid(dut, mac, &cid))
333 return -1;
334
335 cmd.bf_type = WIL_WMI_BRP_RX;
336 cmd.sta_id = cid;
337 /* training length (l_rx) is ignored, FW always uses length 16 */
338 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
339 &cmd, sizeof(cmd));
340}
341
342
343static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
344{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700345 struct wil_wmi_bf_trig_cmd cmd;
346
347 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200348
349 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
350 return -1;
351
352 cmd.bf_type = WIL_WMI_SLS;
353 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
354 &cmd, sizeof(cmd));
355}
356
Lior Davidcc88b562017-01-03 18:52:09 +0200357#endif /* __linux__ */
358
359
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200360static void static_ip_file(int proto, const char *addr, const char *mask,
361 const char *gw)
362{
363 if (proto) {
364 FILE *f = fopen("static-ip", "w");
365 if (f) {
366 fprintf(f, "%d %s %s %s\n", proto, addr,
367 mask ? mask : "N/A",
368 gw ? gw : "N/A");
369 fclose(f);
370 }
371 } else {
372 unlink("static-ip");
373 }
374}
375
376
377static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
378 const char *ssid)
379{
380#ifdef __linux__
381 char buf[100];
382
383 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
384 intf, ssid);
385 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
386
387 if (system(buf) != 0) {
388 sigma_dut_print(dut, DUT_MSG_ERROR,
389 "iwpriv neighbor request failed");
390 return -1;
391 }
392
393 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
394
395 return 0;
396#else /* __linux__ */
397 return -1;
398#endif /* __linux__ */
399}
400
401
402static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530403 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200404{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530405 const char *val;
406 int reason_code = 0;
407 char buf[1024];
408
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200409 /*
410 * In the earlier builds we used WNM_QUERY and in later
411 * builds used WNM_BSS_QUERY.
412 */
413
Ashwini Patil5acd7382017-04-13 15:55:04 +0530414 val = get_param(cmd, "BTMQuery_Reason_Code");
415 if (val)
416 reason_code = atoi(val);
417
418 val = get_param(cmd, "Cand_List");
419 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
420 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
421 dut->btm_query_cand_list);
422 free(dut->btm_query_cand_list);
423 dut->btm_query_cand_list = NULL;
424 } else {
425 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
426 }
427
428 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200429 sigma_dut_print(dut, DUT_MSG_ERROR,
430 "transition management query failed");
431 return -1;
432 }
433
434 sigma_dut_print(dut, DUT_MSG_DEBUG,
435 "transition management query sent");
436
437 return 0;
438}
439
440
441int is_ip_addr(const char *str)
442{
443 const char *pos = str;
444 struct in_addr addr;
445
446 while (*pos) {
447 if (*pos != '.' && (*pos < '0' || *pos > '9'))
448 return 0;
449 pos++;
450 }
451
452 return inet_aton(str, &addr);
453}
454
455
456int is_ipv6_addr(const char *str)
457{
458 struct sockaddr_in6 addr;
459
460 return inet_pton(AF_INET6, str, &(addr.sin6_addr));
461}
462
463
464int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
465 size_t buf_len)
466{
467 char tmp[256], *pos, *pos2;
468 FILE *f;
469 char ip[16], mask[15], dns[16], sec_dns[16];
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530470 const char *str_ps;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200471 int is_dhcp = 0;
472 int s;
473#ifdef ANDROID
474 char prop[PROPERTY_VALUE_MAX];
475#endif /* ANDROID */
476
477 ip[0] = '\0';
478 mask[0] = '\0';
479 dns[0] = '\0';
480 sec_dns[0] = '\0';
481
482 s = socket(PF_INET, SOCK_DGRAM, 0);
483 if (s >= 0) {
484 struct ifreq ifr;
485 struct sockaddr_in saddr;
486
487 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700488 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200489 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
490 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
491 "%s IP address: %s",
492 ifname, strerror(errno));
493 } else {
494 memcpy(&saddr, &ifr.ifr_addr,
495 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700496 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200497 }
498
499 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
500 memcpy(&saddr, &ifr.ifr_addr,
501 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700502 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200503 }
504 close(s);
505 }
506
507#ifdef ANDROID
508 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
509 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
510 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
511 if (property_get(tmp, prop, NULL) != 0 &&
512 strcmp(prop, "ok") == 0) {
513 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
514 ifname);
515 if (property_get(tmp, prop, NULL) != 0 &&
516 strcmp(ip, prop) == 0)
517 is_dhcp = 1;
518 }
519 }
520
521 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700522 if (property_get(tmp, prop, NULL) != 0)
523 strlcpy(dns, prop, sizeof(dns));
524 else if (property_get("net.dns1", prop, NULL) != 0)
525 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200526
527 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700528 if (property_get(tmp, prop, NULL) != 0)
529 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200530#else /* ANDROID */
531#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530532 if (get_driver_type() == DRIVER_OPENWRT)
533 str_ps = "ps -w";
534 else
535 str_ps = "ps ax";
536 snprintf(tmp, sizeof(tmp),
537 "%s | grep dhclient | grep -v grep | grep -q %s",
538 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200539 if (system(tmp) == 0)
540 is_dhcp = 1;
541 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530542 snprintf(tmp, sizeof(tmp),
543 "%s | grep udhcpc | grep -v grep | grep -q %s",
544 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200545 if (system(tmp) == 0)
546 is_dhcp = 1;
547 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530548 snprintf(tmp, sizeof(tmp),
549 "%s | grep dhcpcd | grep -v grep | grep -q %s",
550 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200551 if (system(tmp) == 0)
552 is_dhcp = 1;
553 }
554 }
555#endif /* __linux__ */
556
557 f = fopen("/etc/resolv.conf", "r");
558 if (f) {
559 while (fgets(tmp, sizeof(tmp), f)) {
560 if (strncmp(tmp, "nameserver", 10) != 0)
561 continue;
562 pos = tmp + 10;
563 while (*pos == ' ' || *pos == '\t')
564 pos++;
565 pos2 = pos;
566 while (*pos2) {
567 if (*pos2 == '\n' || *pos2 == '\r') {
568 *pos2 = '\0';
569 break;
570 }
571 pos2++;
572 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700573 if (!dns[0])
574 strlcpy(dns, pos, sizeof(dns));
575 else if (!sec_dns[0])
576 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200577 }
578 fclose(f);
579 }
580#endif /* ANDROID */
581
582 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
583 is_dhcp, ip, mask, dns);
584 buf[buf_len - 1] = '\0';
585
586 return 0;
587}
588
589
590
591
592int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
593 size_t buf_len)
594{
595#ifdef __linux__
596#ifdef ANDROID
597 char cmd[200], result[1000], *pos, *end;
598 FILE *f;
599 size_t len;
600
601 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
602 f = popen(cmd, "r");
603 if (f == NULL)
604 return -1;
605 len = fread(result, 1, sizeof(result) - 1, f);
606 pclose(f);
607 if (len == 0)
608 return -1;
609 result[len] = '\0';
610 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
611
612 pos = strstr(result, "inet6 ");
613 if (pos == NULL)
614 return -1;
615 pos += 6;
616 end = strchr(pos, ' ');
617 if (end)
618 *end = '\0';
619 end = strchr(pos, '/');
620 if (end)
621 *end = '\0';
622 snprintf(buf, buf_len, "ip,%s", pos);
623 buf[buf_len - 1] = '\0';
624 return 0;
625#else /* ANDROID */
626 struct ifaddrs *ifaddr, *ifa;
627 int res, found = 0;
628 char host[NI_MAXHOST];
629
630 if (getifaddrs(&ifaddr) < 0) {
631 perror("getifaddrs");
632 return -1;
633 }
634
635 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
636 if (strcasecmp(ifname, ifa->ifa_name) != 0)
637 continue;
638 if (ifa->ifa_addr == NULL ||
639 ifa->ifa_addr->sa_family != AF_INET6)
640 continue;
641
642 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
643 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
644 if (res != 0) {
645 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
646 gai_strerror(res));
647 continue;
648 }
649 if (strncmp(host, "fe80::", 6) == 0)
650 continue; /* skip link-local */
651
652 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
653 found = 1;
654 break;
655 }
656
657 freeifaddrs(ifaddr);
658
659 if (found) {
660 char *pos;
661 pos = strchr(host, '%');
662 if (pos)
663 *pos = '\0';
664 snprintf(buf, buf_len, "ip,%s", host);
665 buf[buf_len - 1] = '\0';
666 return 0;
667 }
668
669#endif /* ANDROID */
670#endif /* __linux__ */
671 return -1;
672}
673
674
675static int cmd_sta_get_ip_config(struct sigma_dut *dut,
676 struct sigma_conn *conn,
677 struct sigma_cmd *cmd)
678{
679 const char *intf = get_param(cmd, "Interface");
680 const char *ifname;
681 char buf[200];
682 const char *val;
683 int type = 1;
684
685 if (intf == NULL)
686 return -1;
687
688 if (strcmp(intf, get_main_ifname()) == 0)
689 ifname = get_station_ifname();
690 else
691 ifname = intf;
692
693 /*
694 * UCC may assume the IP address to be available immediately after
695 * association without trying to run sta_get_ip_config multiple times.
696 * Sigma CAPI does not specify this command as a block command that
697 * would wait for the address to become available, but to pass tests
698 * more reliably, it looks like such a wait may be needed here.
699 */
700 if (wait_ip_addr(dut, ifname, 15) < 0) {
701 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
702 "for sta_get_ip_config");
703 /*
704 * Try to continue anyway since many UCC tests do not really
705 * care about the return value from here..
706 */
707 }
708
709 val = get_param(cmd, "Type");
710 if (val)
711 type = atoi(val);
712 if (type == 2 || dut->last_set_ip_config_ipv6) {
713 int i;
714
715 /*
716 * Since we do not have proper wait for IPv6 addresses, use a
717 * fixed two second delay here as a workaround for UCC script
718 * assuming IPv6 address is available when this command returns.
719 * Some scripts did not use Type,2 properly for IPv6, so include
720 * also the cases where the previous sta_set_ip_config indicated
721 * use of IPv6.
722 */
723 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
724 for (i = 0; i < 10; i++) {
725 sleep(1);
726 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
727 {
728 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
729 send_resp(dut, conn, SIGMA_COMPLETE, buf);
730#ifdef ANDROID
731 sigma_dut_print(dut, DUT_MSG_INFO,
732 "Adding IPv6 rule on Android");
733 add_ipv6_rule(dut, intf);
734#endif /* ANDROID */
735
736 return 0;
737 }
738 }
739 }
740 if (type == 1) {
741 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
742 return -2;
743 } else if (type == 2) {
744 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
745 return -2;
746 } else {
747 send_resp(dut, conn, SIGMA_ERROR,
748 "errorCode,Unsupported address type");
749 return 0;
750 }
751
752 send_resp(dut, conn, SIGMA_COMPLETE, buf);
753 return 0;
754}
755
756
757static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
758{
759#ifdef __linux__
760 char buf[200];
761 char path[128];
762 struct stat s;
763
764#ifdef ANDROID
765 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
766#else /* ANDROID */
767 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
768#endif /* ANDROID */
769 if (stat(path, &s) == 0) {
770 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
771 sigma_dut_print(dut, DUT_MSG_INFO,
772 "Kill previous DHCP client: %s", buf);
773 if (system(buf) != 0)
774 sigma_dut_print(dut, DUT_MSG_INFO,
775 "Failed to kill DHCP client");
776 unlink(path);
777 sleep(1);
778 } else {
779 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
780
781 if (stat(path, &s) == 0) {
782 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
783 sigma_dut_print(dut, DUT_MSG_INFO,
784 "Kill previous DHCP client: %s", buf);
785 if (system(buf) != 0)
786 sigma_dut_print(dut, DUT_MSG_INFO,
787 "Failed to kill DHCP client");
788 unlink(path);
789 sleep(1);
790 }
791 }
792#endif /* __linux__ */
793}
794
795
796static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
797{
798#ifdef __linux__
799 char buf[200];
800
801#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530802 if (access("/system/bin/dhcpcd", F_OK) != -1) {
803 snprintf(buf, sizeof(buf),
804 "/system/bin/dhcpcd -b %s", ifname);
805 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
806 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
807 } else {
808 sigma_dut_print(dut, DUT_MSG_ERROR,
809 "DHCP client program missing");
810 return 0;
811 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200812#else /* ANDROID */
813 snprintf(buf, sizeof(buf),
814 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
815 ifname, ifname);
816#endif /* ANDROID */
817 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
818 if (system(buf) != 0) {
819 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
820 if (system(buf) != 0) {
821 sigma_dut_print(dut, DUT_MSG_INFO,
822 "Failed to start DHCP client");
823#ifndef ANDROID
824 return -1;
825#endif /* ANDROID */
826 }
827 }
828#endif /* __linux__ */
829
830 return 0;
831}
832
833
834static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
835{
836#ifdef __linux__
837 char buf[200];
838
839 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
840 if (system(buf) != 0) {
841 sigma_dut_print(dut, DUT_MSG_INFO,
842 "Failed to clear IP addresses");
843 return -1;
844 }
845#endif /* __linux__ */
846
847 return 0;
848}
849
850
851#ifdef ANDROID
852static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
853{
854 char cmd[200], *result, *pos;
855 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530856 int tableid;
857 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200858
859 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
860 ifname);
861 fp = popen(cmd, "r");
862 if (fp == NULL)
863 return -1;
864
865 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530866 if (result == NULL) {
867 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200868 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530869 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200870
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530871 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200872 fclose(fp);
873
874 if (len == 0) {
875 free(result);
876 return -1;
877 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530878 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200879
880 pos = strstr(result, "table ");
881 if (pos == NULL) {
882 free(result);
883 return -1;
884 }
885
886 pos += strlen("table ");
887 tableid = atoi(pos);
888 if (tableid != 0) {
889 if (system("ip -6 rule del prio 22000") != 0) {
890 /* ignore any error */
891 }
892 snprintf(cmd, sizeof(cmd),
893 "ip -6 rule add from all lookup %d prio 22000",
894 tableid);
895 if (system(cmd) != 0) {
896 sigma_dut_print(dut, DUT_MSG_INFO,
897 "Failed to run %s", cmd);
898 free(result);
899 return -1;
900 }
901 } else {
902 sigma_dut_print(dut, DUT_MSG_INFO,
903 "No Valid Table Id found %s", pos);
904 free(result);
905 return -1;
906 }
907 free(result);
908
909 return 0;
910}
911#endif /* ANDROID */
912
913
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530914int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
915 const char *ip, const char *mask)
916{
917 char buf[200];
918
919 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
920 ifname, ip, mask);
921 return system(buf) == 0;
922}
923
924
925int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
926{
927 char buf[200];
928
929 if (!is_ip_addr(gw)) {
930 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
931 return -1;
932 }
933
934 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
935 if (!dut->no_ip_addr_set && system(buf) != 0) {
936 snprintf(buf, sizeof(buf), "ip ro re default via %s",
937 gw);
938 if (system(buf) != 0)
939 return 0;
940 }
941
942 return 1;
943}
944
945
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200946static int cmd_sta_set_ip_config(struct sigma_dut *dut,
947 struct sigma_conn *conn,
948 struct sigma_cmd *cmd)
949{
950 const char *intf = get_param(cmd, "Interface");
951 const char *ifname;
952 char buf[200];
953 const char *val, *ip, *mask, *gw;
954 int type = 1;
955
956 if (intf == NULL)
957 return -1;
958
959 if (strcmp(intf, get_main_ifname()) == 0)
960 ifname = get_station_ifname();
961 else
962 ifname = intf;
963
964 if (if_nametoindex(ifname) == 0) {
965 send_resp(dut, conn, SIGMA_ERROR,
966 "ErrorCode,Unknown interface");
967 return 0;
968 }
969
970 val = get_param(cmd, "Type");
971 if (val) {
972 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530973 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200974 send_resp(dut, conn, SIGMA_ERROR,
975 "ErrorCode,Unsupported address type");
976 return 0;
977 }
978 }
979
980 dut->last_set_ip_config_ipv6 = 0;
981
982 val = get_param(cmd, "dhcp");
983 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
984 static_ip_file(0, NULL, NULL, NULL);
985#ifdef __linux__
986 if (type == 2) {
987 dut->last_set_ip_config_ipv6 = 1;
988 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
989 "stateless address autoconfiguration");
990#ifdef ANDROID
991 /*
992 * This sleep is required as the assignment in case of
993 * Android is taking time and is done by the kernel.
994 * The subsequent ping for IPv6 is impacting HS20 test
995 * case.
996 */
997 sleep(2);
998 add_ipv6_rule(dut, intf);
999#endif /* ANDROID */
1000 /* Assume this happens by default */
1001 return 1;
1002 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301003 if (type != 3) {
1004 kill_dhcp_client(dut, ifname);
1005 if (start_dhcp_client(dut, ifname) < 0)
1006 return -2;
1007 } else {
1008 sigma_dut_print(dut, DUT_MSG_DEBUG,
1009 "Using FILS HLP DHCPv4 Rapid Commit");
1010 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001012 return 1;
1013#endif /* __linux__ */
1014 return -2;
1015 }
1016
1017 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301018 if (!ip) {
1019 send_resp(dut, conn, SIGMA_INVALID,
1020 "ErrorCode,Missing IP address");
1021 return 0;
1022 }
1023
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001024 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301025 if (!mask) {
1026 send_resp(dut, conn, SIGMA_INVALID,
1027 "ErrorCode,Missing subnet mask");
1028 return 0;
1029 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001030
1031 if (type == 2) {
1032 int net = atoi(mask);
1033
1034 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1035 return -1;
1036
1037 if (dut->no_ip_addr_set) {
1038 snprintf(buf, sizeof(buf),
1039 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1040 ifname);
1041 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1042 if (system(buf) != 0) {
1043 sigma_dut_print(dut, DUT_MSG_DEBUG,
1044 "Failed to disable IPv6 address before association");
1045 }
1046 } else {
1047 snprintf(buf, sizeof(buf),
1048 "ip -6 addr del %s/%s dev %s",
1049 ip, mask, ifname);
1050 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1051 if (system(buf) != 0) {
1052 /*
1053 * This command may fail if the address being
1054 * deleted does not exist. Inaction here is
1055 * intentional.
1056 */
1057 }
1058
1059 snprintf(buf, sizeof(buf),
1060 "ip -6 addr add %s/%s dev %s",
1061 ip, mask, ifname);
1062 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1063 if (system(buf) != 0) {
1064 send_resp(dut, conn, SIGMA_ERROR,
1065 "ErrorCode,Failed to set IPv6 address");
1066 return 0;
1067 }
1068 }
1069
1070 dut->last_set_ip_config_ipv6 = 1;
1071 static_ip_file(6, ip, mask, NULL);
1072 return 1;
1073 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301074 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001075 return -1;
1076 }
1077
1078 kill_dhcp_client(dut, ifname);
1079
1080 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301081 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001082 send_resp(dut, conn, SIGMA_ERROR,
1083 "ErrorCode,Failed to set IP address");
1084 return 0;
1085 }
1086 }
1087
1088 gw = get_param(cmd, "defaultGateway");
1089 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301090 if (set_ipv4_gw(dut, gw) < 1) {
1091 send_resp(dut, conn, SIGMA_ERROR,
1092 "ErrorCode,Failed to set default gateway");
1093 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001094 }
1095 }
1096
1097 val = get_param(cmd, "primary-dns");
1098 if (val) {
1099 /* TODO */
1100 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1101 "setting", val);
1102 }
1103
1104 val = get_param(cmd, "secondary-dns");
1105 if (val) {
1106 /* TODO */
1107 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1108 "setting", val);
1109 }
1110
1111 static_ip_file(4, ip, mask, gw);
1112
1113 return 1;
1114}
1115
1116
1117static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1118 struct sigma_cmd *cmd)
1119{
1120 /* const char *intf = get_param(cmd, "Interface"); */
1121 /* TODO: could report more details here */
1122 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1123 return 0;
1124}
1125
1126
1127static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1128 struct sigma_conn *conn,
1129 struct sigma_cmd *cmd)
1130{
1131 /* const char *intf = get_param(cmd, "Interface"); */
1132 char addr[20], resp[50];
1133
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301134 if (dut->dev_role == DEVROLE_STA_CFON)
1135 return sta_cfon_get_mac_address(dut, conn, cmd);
1136
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001137 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1138 < 0)
1139 return -2;
1140
1141 snprintf(resp, sizeof(resp), "mac,%s", addr);
1142 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1143 return 0;
1144}
1145
1146
1147static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1148 struct sigma_cmd *cmd)
1149{
1150 /* const char *intf = get_param(cmd, "Interface"); */
1151 int connected = 0;
1152 char result[32];
1153 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1154 sizeof(result)) < 0) {
1155 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1156 "%s status", get_station_ifname());
1157 return -2;
1158 }
1159
1160 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1161 if (strncmp(result, "COMPLETED", 9) == 0)
1162 connected = 1;
1163
1164 if (connected)
1165 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1166 else
1167 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1168
1169 return 0;
1170}
1171
1172
1173static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1174 struct sigma_conn *conn,
1175 struct sigma_cmd *cmd)
1176{
1177 /* const char *intf = get_param(cmd, "Interface"); */
1178 const char *dst, *timeout;
1179 int wait_time = 90;
1180 char buf[100];
1181 int res;
1182
1183 dst = get_param(cmd, "destination");
1184 if (dst == NULL || !is_ip_addr(dst))
1185 return -1;
1186
1187 timeout = get_param(cmd, "timeout");
1188 if (timeout) {
1189 wait_time = atoi(timeout);
1190 if (wait_time < 1)
1191 wait_time = 1;
1192 }
1193
1194 /* TODO: force renewal of IP lease if DHCP is enabled */
1195
1196 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1197 res = system(buf);
1198 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1199 if (res == 0)
1200 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1201 else if (res == 256)
1202 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1203 else
1204 return -2;
1205
1206 return 0;
1207}
1208
1209
1210static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1211 struct sigma_cmd *cmd)
1212{
1213 /* const char *intf = get_param(cmd, "Interface"); */
1214 char bssid[20], resp[50];
1215
1216 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1217 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001218 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001219
1220 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1221 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1222 return 0;
1223}
1224
1225
1226#ifdef __SAMSUNG__
1227static int add_use_network(const char *ifname)
1228{
1229 char buf[100];
1230
1231 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1232 wpa_command(ifname, buf);
1233 return 0;
1234}
1235#endif /* __SAMSUNG__ */
1236
1237
1238static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1239 const char *ifname, struct sigma_cmd *cmd)
1240{
1241 const char *ssid = get_param(cmd, "ssid");
1242 int id;
1243 const char *val;
1244
1245 if (ssid == NULL)
1246 return -1;
1247
1248 start_sta_mode(dut);
1249
1250#ifdef __SAMSUNG__
1251 add_use_network(ifname);
1252#endif /* __SAMSUNG__ */
1253
1254 id = add_network(ifname);
1255 if (id < 0)
1256 return -2;
1257 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1258
1259 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1260 return -2;
1261
1262 dut->infra_network_id = id;
1263 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1264
1265 val = get_param(cmd, "program");
1266 if (!val)
1267 val = get_param(cmd, "prog");
1268 if (val && strcasecmp(val, "hs2") == 0) {
1269 char buf[100];
1270 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1271 wpa_command(ifname, buf);
1272
1273 val = get_param(cmd, "prefer");
1274 if (val && atoi(val) > 0)
1275 set_network(ifname, id, "priority", "1");
1276 }
1277
1278 return id;
1279}
1280
1281
1282static int cmd_sta_set_encryption(struct sigma_dut *dut,
1283 struct sigma_conn *conn,
1284 struct sigma_cmd *cmd)
1285{
1286 const char *intf = get_param(cmd, "Interface");
1287 const char *ssid = get_param(cmd, "ssid");
1288 const char *type = get_param(cmd, "encpType");
1289 const char *ifname;
1290 char buf[200];
1291 int id;
1292
1293 if (intf == NULL || ssid == NULL)
1294 return -1;
1295
1296 if (strcmp(intf, get_main_ifname()) == 0)
1297 ifname = get_station_ifname();
1298 else
1299 ifname = intf;
1300
1301 id = add_network_common(dut, conn, ifname, cmd);
1302 if (id < 0)
1303 return id;
1304
1305 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1306 return -2;
1307
1308 if (type && strcasecmp(type, "wep") == 0) {
1309 const char *val;
1310 int i;
1311
1312 val = get_param(cmd, "activeKey");
1313 if (val) {
1314 int keyid;
1315 keyid = atoi(val);
1316 if (keyid < 1 || keyid > 4)
1317 return -1;
1318 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1319 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1320 return -2;
1321 }
1322
1323 for (i = 0; i < 4; i++) {
1324 snprintf(buf, sizeof(buf), "key%d", i + 1);
1325 val = get_param(cmd, buf);
1326 if (val == NULL)
1327 continue;
1328 snprintf(buf, sizeof(buf), "wep_key%d", i);
1329 if (set_network(ifname, id, buf, val) < 0)
1330 return -2;
1331 }
1332 }
1333
1334 return 1;
1335}
1336
1337
1338static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1339 const char *ifname, struct sigma_cmd *cmd)
1340{
1341 const char *val;
1342 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001343 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001344 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301345 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001346
1347 id = add_network_common(dut, conn, ifname, cmd);
1348 if (id < 0)
1349 return id;
1350
Jouni Malinen47dcc952017-10-09 16:43:24 +03001351 val = get_param(cmd, "Type");
1352 owe = val && strcasecmp(val, "OWE") == 0;
1353
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001354 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001355 if (!val && owe)
1356 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001357 if (val == NULL) {
1358 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1359 return 0;
1360 }
1361 if (strcasecmp(val, "wpa") == 0 ||
1362 strcasecmp(val, "wpa-psk") == 0) {
1363 if (set_network(ifname, id, "proto", "WPA") < 0)
1364 return -2;
1365 } else if (strcasecmp(val, "wpa2") == 0 ||
1366 strcasecmp(val, "wpa2-psk") == 0 ||
1367 strcasecmp(val, "wpa2-ft") == 0 ||
1368 strcasecmp(val, "wpa2-sha256") == 0) {
1369 if (set_network(ifname, id, "proto", "WPA2") < 0)
1370 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301371 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1372 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1374 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001375 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301376 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001377 if (set_network(ifname, id, "proto", "WPA2") < 0)
1378 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001379 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001380 } else {
1381 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1382 return 0;
1383 }
1384
1385 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001386 if (val) {
1387 cipher_set = 1;
1388 if (strcasecmp(val, "tkip") == 0) {
1389 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1390 return -2;
1391 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1392 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1393 return -2;
1394 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1395 if (set_network(ifname, id, "pairwise",
1396 "CCMP TKIP") < 0)
1397 return -2;
1398 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1399 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1400 return -2;
1401 if (set_network(ifname, id, "group", "GCMP") < 0)
1402 return -2;
1403 } else {
1404 send_resp(dut, conn, SIGMA_ERROR,
1405 "errorCode,Unrecognized encpType value");
1406 return 0;
1407 }
1408 }
1409
1410 val = get_param(cmd, "PairwiseCipher");
1411 if (val) {
1412 cipher_set = 1;
1413 /* TODO: Support space separated list */
1414 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1415 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1416 return -2;
1417 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1418 if (set_network(ifname, id, "pairwise",
1419 "CCMP-256") < 0)
1420 return -2;
1421 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1422 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1423 return -2;
1424 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1425 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1426 return -2;
1427 } else {
1428 send_resp(dut, conn, SIGMA_ERROR,
1429 "errorCode,Unrecognized PairwiseCipher value");
1430 return 0;
1431 }
1432 }
1433
Jouni Malinen47dcc952017-10-09 16:43:24 +03001434 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001435 send_resp(dut, conn, SIGMA_ERROR,
1436 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001437 return 0;
1438 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001439
1440 val = get_param(cmd, "GroupCipher");
1441 if (val) {
1442 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1443 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1444 return -2;
1445 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1446 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1447 return -2;
1448 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1449 if (set_network(ifname, id, "group", "GCMP") < 0)
1450 return -2;
1451 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1452 if (set_network(ifname, id, "group", "CCMP") < 0)
1453 return -2;
1454 } else {
1455 send_resp(dut, conn, SIGMA_ERROR,
1456 "errorCode,Unrecognized GroupCipher value");
1457 return 0;
1458 }
1459 }
1460
Jouni Malinen7b239522017-09-14 21:37:18 +03001461 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001462 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001463 const char *cipher;
1464
1465 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1466 cipher = "BIP-GMAC-256";
1467 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1468 cipher = "BIP-CMAC-256";
1469 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1470 cipher = "BIP-GMAC-128";
1471 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1472 cipher = "AES-128-CMAC";
1473 } else {
1474 send_resp(dut, conn, SIGMA_INVALID,
1475 "errorCode,Unsupported GroupMgntCipher");
1476 return 0;
1477 }
1478 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1479 send_resp(dut, conn, SIGMA_INVALID,
1480 "errorCode,Failed to set GroupMgntCipher");
1481 return 0;
1482 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001483 }
1484
1485 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301486
1487 if (dut->program == PROGRAM_OCE) {
1488 dut->sta_pmf = STA_PMF_OPTIONAL;
1489 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1490 return -2;
1491 }
1492
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001493 val = get_param(cmd, "PMF");
1494 if (val) {
1495 if (strcasecmp(val, "Required") == 0 ||
1496 strcasecmp(val, "Forced_Required") == 0) {
1497 dut->sta_pmf = STA_PMF_REQUIRED;
1498 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1499 return -2;
1500 } else if (strcasecmp(val, "Optional") == 0) {
1501 dut->sta_pmf = STA_PMF_OPTIONAL;
1502 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1503 return -2;
1504 } else if (strcasecmp(val, "Disabled") == 0 ||
1505 strcasecmp(val, "Forced_Disabled") == 0) {
1506 dut->sta_pmf = STA_PMF_DISABLED;
1507 } else {
1508 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1509 return 0;
1510 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301511 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001512 dut->sta_pmf = STA_PMF_REQUIRED;
1513 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1514 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001515 }
1516
1517 return id;
1518}
1519
1520
1521static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1522 struct sigma_cmd *cmd)
1523{
1524 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001525 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001526 const char *pmf = get_param(cmd, "PMF");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001527 const char *ifname, *val, *alg;
1528 int id;
1529
1530 if (intf == NULL)
1531 return -1;
1532
1533 if (strcmp(intf, get_main_ifname()) == 0)
1534 ifname = get_station_ifname();
1535 else
1536 ifname = intf;
1537
1538 id = set_wpa_common(dut, conn, ifname, cmd);
1539 if (id < 0)
1540 return id;
1541
1542 val = get_param(cmd, "keyMgmtType");
1543 alg = get_param(cmd, "micAlg");
1544
Jouni Malinen992a81e2017-08-22 13:57:47 +03001545 if (type && strcasecmp(type, "SAE") == 0) {
1546 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1547 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1548 return -2;
1549 } else {
1550 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1551 return -2;
1552 }
1553 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1554 sigma_dut_print(dut, DUT_MSG_ERROR,
1555 "Failed to clear sae_groups to default");
1556 return -2;
1557 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001558 if (!pmf) {
1559 dut->sta_pmf = STA_PMF_REQUIRED;
1560 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1561 return -2;
1562 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001563 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1564 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1565 if (set_network(ifname, id, "key_mgmt",
1566 "FT-SAE FT-PSK") < 0)
1567 return -2;
1568 } else {
1569 if (set_network(ifname, id, "key_mgmt",
1570 "SAE WPA-PSK") < 0)
1571 return -2;
1572 }
1573 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1574 sigma_dut_print(dut, DUT_MSG_ERROR,
1575 "Failed to clear sae_groups to default");
1576 return -2;
1577 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001578 if (!pmf) {
1579 dut->sta_pmf = STA_PMF_OPTIONAL;
1580 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1581 return -2;
1582 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001583 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001584 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1585 return -2;
1586 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1587 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1588 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301589 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1590 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1591 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001592 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1593 dut->sta_pmf == STA_PMF_REQUIRED) {
1594 if (set_network(ifname, id, "key_mgmt",
1595 "WPA-PSK WPA-PSK-SHA256") < 0)
1596 return -2;
1597 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1598 if (set_network(ifname, id, "key_mgmt",
1599 "WPA-PSK WPA-PSK-SHA256") < 0)
1600 return -2;
1601 } else {
1602 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1603 return -2;
1604 }
1605
1606 val = get_param(cmd, "passPhrase");
1607 if (val == NULL)
1608 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001609 if (type && strcasecmp(type, "SAE") == 0) {
1610 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1611 return -2;
1612 } else {
1613 if (set_network_quoted(ifname, id, "psk", val) < 0)
1614 return -2;
1615 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001616
Jouni Malinen992a81e2017-08-22 13:57:47 +03001617 val = get_param(cmd, "ECGroupID");
1618 if (val) {
1619 char buf[50];
1620
1621 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1622 if (wpa_command(ifname, buf) != 0) {
1623 sigma_dut_print(dut, DUT_MSG_ERROR,
1624 "Failed to clear sae_groups");
1625 return -2;
1626 }
1627 }
1628
Jouni Malinen68143132017-09-02 02:34:08 +03001629 val = get_param(cmd, "InvalidSAEElement");
1630 if (val) {
1631 free(dut->sae_commit_override);
1632 dut->sae_commit_override = strdup(val);
1633 }
1634
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001635 return 1;
1636}
1637
1638
1639static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301640 const char *ifname, int username_identity,
1641 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001642{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301643 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001644 int id;
1645 char buf[200];
1646#ifdef ANDROID
1647 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1648 int length;
1649#endif /* ANDROID */
1650
1651 id = set_wpa_common(dut, conn, ifname, cmd);
1652 if (id < 0)
1653 return id;
1654
1655 val = get_param(cmd, "keyMgmtType");
1656 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301657 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001658
Jouni Malinenad395a22017-09-01 21:13:46 +03001659 if (val && strcasecmp(val, "SuiteB") == 0) {
1660 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1661 0)
1662 return -2;
1663 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001664 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1665 return -2;
1666 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1667 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1668 return -2;
1669 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1670 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1671 return -2;
1672 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1673 dut->sta_pmf == STA_PMF_REQUIRED) {
1674 if (set_network(ifname, id, "key_mgmt",
1675 "WPA-EAP WPA-EAP-SHA256") < 0)
1676 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301677 } else if (akm && atoi(akm) == 14) {
1678 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1679 dut->sta_pmf == STA_PMF_REQUIRED) {
1680 if (set_network(ifname, id, "key_mgmt",
1681 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1682 return -2;
1683 } else {
1684 if (set_network(ifname, id, "key_mgmt",
1685 "WPA-EAP FILS-SHA256") < 0)
1686 return -2;
1687 }
1688
1689 if (set_network(ifname, id, "erp", "1") < 0)
1690 return -2;
1691 } else if (akm && atoi(akm) == 15) {
1692 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1693 dut->sta_pmf == STA_PMF_REQUIRED) {
1694 if (set_network(ifname, id, "key_mgmt",
1695 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1696 return -2;
1697 } else {
1698 if (set_network(ifname, id, "key_mgmt",
1699 "WPA-EAP FILS-SHA384") < 0)
1700 return -2;
1701 }
1702
1703 if (set_network(ifname, id, "erp", "1") < 0)
1704 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001705 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1706 if (set_network(ifname, id, "key_mgmt",
1707 "WPA-EAP WPA-EAP-SHA256") < 0)
1708 return -2;
1709 } else {
1710 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1711 return -2;
1712 }
1713
1714 val = get_param(cmd, "trustedRootCA");
1715 if (val) {
1716#ifdef ANDROID
1717 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1718 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1719 kvalue);
1720 if (length > 0) {
1721 sigma_dut_print(dut, DUT_MSG_INFO,
1722 "Use Android keystore [%s]", buf);
1723 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1724 val);
1725 goto ca_cert_selected;
1726 }
1727#endif /* ANDROID */
1728
1729 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1730#ifdef __linux__
1731 if (!file_exists(buf)) {
1732 char msg[300];
1733 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1734 "file (%s) not found", buf);
1735 send_resp(dut, conn, SIGMA_ERROR, msg);
1736 return -3;
1737 }
1738#endif /* __linux__ */
1739#ifdef ANDROID
1740ca_cert_selected:
1741#endif /* ANDROID */
1742 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1743 return -2;
1744 }
1745
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301746 if (username_identity) {
1747 val = get_param(cmd, "username");
1748 if (val) {
1749 if (set_network_quoted(ifname, id, "identity", val) < 0)
1750 return -2;
1751 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001752
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301753 val = get_param(cmd, "password");
1754 if (val) {
1755 if (set_network_quoted(ifname, id, "password", val) < 0)
1756 return -2;
1757 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001758 }
1759
1760 return id;
1761}
1762
1763
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001764static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1765{
1766 const char *val;
1767
1768 if (!cipher)
1769 return 0;
1770
1771 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1772 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1773 else if (strcasecmp(cipher,
1774 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1775 val = "ECDHE-RSA-AES256-GCM-SHA384";
1776 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1777 val = "DHE-RSA-AES256-GCM-SHA384";
1778 else if (strcasecmp(cipher,
1779 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1780 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1781 else
1782 return -1;
1783
1784 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1785 set_network_quoted(ifname, id, "phase1", "");
1786
1787 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1788}
1789
1790
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001791static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1792 struct sigma_cmd *cmd)
1793{
1794 const char *intf = get_param(cmd, "Interface");
1795 const char *ifname, *val;
1796 int id;
1797 char buf[200];
1798#ifdef ANDROID
1799 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1800 int length;
1801 int jb_or_newer = 0;
1802 char prop[PROPERTY_VALUE_MAX];
1803#endif /* ANDROID */
1804
1805 if (intf == NULL)
1806 return -1;
1807
1808 if (strcmp(intf, get_main_ifname()) == 0)
1809 ifname = get_station_ifname();
1810 else
1811 ifname = intf;
1812
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301813 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001814 if (id < 0)
1815 return id;
1816
1817 if (set_network(ifname, id, "eap", "TLS") < 0)
1818 return -2;
1819
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301820 if (!get_param(cmd, "username") &&
1821 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001822 "wifi-user@wifilabs.local") < 0)
1823 return -2;
1824
1825 val = get_param(cmd, "clientCertificate");
1826 if (val == NULL)
1827 return -1;
1828#ifdef ANDROID
1829 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1830 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1831 if (length < 0) {
1832 /*
1833 * JB started reporting keystore type mismatches, so retry with
1834 * the GET_PUBKEY command if the generic GET fails.
1835 */
1836 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1837 buf, kvalue);
1838 }
1839
1840 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1841 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1842 if (strncmp(prop, "4.0", 3) != 0)
1843 jb_or_newer = 1;
1844 } else
1845 jb_or_newer = 1; /* assume newer */
1846
1847 if (jb_or_newer && length > 0) {
1848 sigma_dut_print(dut, DUT_MSG_INFO,
1849 "Use Android keystore [%s]", buf);
1850 if (set_network(ifname, id, "engine", "1") < 0)
1851 return -2;
1852 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1853 return -2;
1854 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1855 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1856 return -2;
1857 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1858 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1859 return -2;
1860 return 1;
1861 } else if (length > 0) {
1862 sigma_dut_print(dut, DUT_MSG_INFO,
1863 "Use Android keystore [%s]", buf);
1864 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1865 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1866 return -2;
1867 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1868 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1869 return -2;
1870 return 1;
1871 }
1872#endif /* ANDROID */
1873
1874 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1875#ifdef __linux__
1876 if (!file_exists(buf)) {
1877 char msg[300];
1878 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1879 "(%s) not found", buf);
1880 send_resp(dut, conn, SIGMA_ERROR, msg);
1881 return -3;
1882 }
1883#endif /* __linux__ */
1884 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1885 return -2;
1886 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1887 return -2;
1888
1889 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1890 return -2;
1891
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001892 val = get_param(cmd, "keyMgmtType");
1893 if (val && strcasecmp(val, "SuiteB") == 0) {
1894 val = get_param(cmd, "CertType");
1895 if (val && strcasecmp(val, "RSA") == 0) {
1896 if (set_network_quoted(ifname, id, "phase1",
1897 "tls_suiteb=1") < 0)
1898 return -2;
1899 } else {
1900 if (set_network_quoted(ifname, id, "openssl_ciphers",
1901 "SUITEB192") < 0)
1902 return -2;
1903 }
1904
1905 val = get_param(cmd, "TLSCipher");
1906 if (set_tls_cipher(ifname, id, val) < 0) {
1907 send_resp(dut, conn, SIGMA_ERROR,
1908 "ErrorCode,Unsupported TLSCipher value");
1909 return -3;
1910 }
1911 }
1912
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001913 return 1;
1914}
1915
1916
1917static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1918 struct sigma_cmd *cmd)
1919{
1920 const char *intf = get_param(cmd, "Interface");
1921 const char *ifname;
1922 int id;
1923
1924 if (intf == NULL)
1925 return -1;
1926
1927 if (strcmp(intf, get_main_ifname()) == 0)
1928 ifname = get_station_ifname();
1929 else
1930 ifname = intf;
1931
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301932 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001933 if (id < 0)
1934 return id;
1935
1936 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1937 send_resp(dut, conn, SIGMA_ERROR,
1938 "errorCode,Failed to set TTLS method");
1939 return 0;
1940 }
1941
1942 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1943 send_resp(dut, conn, SIGMA_ERROR,
1944 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1945 return 0;
1946 }
1947
1948 return 1;
1949}
1950
1951
1952static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1953 struct sigma_cmd *cmd)
1954{
1955 const char *intf = get_param(cmd, "Interface");
1956 const char *ifname;
1957 int id;
1958
1959 if (intf == NULL)
1960 return -1;
1961
1962 if (strcmp(intf, get_main_ifname()) == 0)
1963 ifname = get_station_ifname();
1964 else
1965 ifname = intf;
1966
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301967 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001968 if (id < 0)
1969 return id;
1970
1971 if (set_network(ifname, id, "eap", "SIM") < 0)
1972 return -2;
1973
1974 return 1;
1975}
1976
1977
1978static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1979 struct sigma_cmd *cmd)
1980{
1981 const char *intf = get_param(cmd, "Interface");
1982 const char *ifname, *val;
1983 int id;
1984 char buf[100];
1985
1986 if (intf == NULL)
1987 return -1;
1988
1989 if (strcmp(intf, get_main_ifname()) == 0)
1990 ifname = get_station_ifname();
1991 else
1992 ifname = intf;
1993
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301994 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001995 if (id < 0)
1996 return id;
1997
1998 if (set_network(ifname, id, "eap", "PEAP") < 0)
1999 return -2;
2000
2001 val = get_param(cmd, "innerEAP");
2002 if (val) {
2003 if (strcasecmp(val, "MSCHAPv2") == 0) {
2004 if (set_network_quoted(ifname, id, "phase2",
2005 "auth=MSCHAPV2") < 0)
2006 return -2;
2007 } else if (strcasecmp(val, "GTC") == 0) {
2008 if (set_network_quoted(ifname, id, "phase2",
2009 "auth=GTC") < 0)
2010 return -2;
2011 } else
2012 return -1;
2013 }
2014
2015 val = get_param(cmd, "peapVersion");
2016 if (val) {
2017 int ver = atoi(val);
2018 if (ver < 0 || ver > 1)
2019 return -1;
2020 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2021 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2022 return -2;
2023 }
2024
2025 return 1;
2026}
2027
2028
2029static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2030 struct sigma_cmd *cmd)
2031{
2032 const char *intf = get_param(cmd, "Interface");
2033 const char *ifname, *val;
2034 int id;
2035 char buf[100];
2036
2037 if (intf == NULL)
2038 return -1;
2039
2040 if (strcmp(intf, get_main_ifname()) == 0)
2041 ifname = get_station_ifname();
2042 else
2043 ifname = intf;
2044
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302045 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002046 if (id < 0)
2047 return id;
2048
2049 if (set_network(ifname, id, "eap", "FAST") < 0)
2050 return -2;
2051
2052 val = get_param(cmd, "innerEAP");
2053 if (val) {
2054 if (strcasecmp(val, "MSCHAPV2") == 0) {
2055 if (set_network_quoted(ifname, id, "phase2",
2056 "auth=MSCHAPV2") < 0)
2057 return -2;
2058 } else if (strcasecmp(val, "GTC") == 0) {
2059 if (set_network_quoted(ifname, id, "phase2",
2060 "auth=GTC") < 0)
2061 return -2;
2062 } else
2063 return -1;
2064 }
2065
2066 val = get_param(cmd, "validateServer");
2067 if (val) {
2068 /* TODO */
2069 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2070 "validateServer=%s", val);
2071 }
2072
2073 val = get_param(cmd, "pacFile");
2074 if (val) {
2075 snprintf(buf, sizeof(buf), "blob://%s", val);
2076 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2077 return -2;
2078 }
2079
2080 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2081 0)
2082 return -2;
2083
2084 return 1;
2085}
2086
2087
2088static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2089 struct sigma_cmd *cmd)
2090{
2091 const char *intf = get_param(cmd, "Interface");
2092 const char *ifname;
2093 int id;
2094
2095 if (intf == NULL)
2096 return -1;
2097
2098 if (strcmp(intf, get_main_ifname()) == 0)
2099 ifname = get_station_ifname();
2100 else
2101 ifname = intf;
2102
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302103 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002104 if (id < 0)
2105 return id;
2106
2107 if (set_network(ifname, id, "eap", "AKA") < 0)
2108 return -2;
2109
2110 return 1;
2111}
2112
2113
2114static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2115 struct sigma_conn *conn,
2116 struct sigma_cmd *cmd)
2117{
2118 const char *intf = get_param(cmd, "Interface");
2119 const char *ifname;
2120 int id;
2121
2122 if (intf == NULL)
2123 return -1;
2124
2125 if (strcmp(intf, get_main_ifname()) == 0)
2126 ifname = get_station_ifname();
2127 else
2128 ifname = intf;
2129
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302130 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002131 if (id < 0)
2132 return id;
2133
2134 if (set_network(ifname, id, "eap", "AKA'") < 0)
2135 return -2;
2136
2137 return 1;
2138}
2139
2140
2141static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2142 struct sigma_cmd *cmd)
2143{
2144 const char *intf = get_param(cmd, "Interface");
2145 const char *ifname;
2146 int id;
2147
2148 if (strcmp(intf, get_main_ifname()) == 0)
2149 ifname = get_station_ifname();
2150 else
2151 ifname = intf;
2152
2153 id = add_network_common(dut, conn, ifname, cmd);
2154 if (id < 0)
2155 return id;
2156
2157 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2158 return -2;
2159
2160 return 1;
2161}
2162
2163
Jouni Malinen47dcc952017-10-09 16:43:24 +03002164static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2165 struct sigma_cmd *cmd)
2166{
2167 const char *intf = get_param(cmd, "Interface");
2168 const char *ifname, *val;
2169 int id;
2170
2171 if (intf == NULL)
2172 return -1;
2173
2174 if (strcmp(intf, get_main_ifname()) == 0)
2175 ifname = get_station_ifname();
2176 else
2177 ifname = intf;
2178
2179 id = set_wpa_common(dut, conn, ifname, cmd);
2180 if (id < 0)
2181 return id;
2182
2183 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2184 return -2;
2185
2186 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002187 if (val && strcmp(val, "0") == 0) {
2188 if (wpa_command(ifname,
2189 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2190 sigma_dut_print(dut, DUT_MSG_ERROR,
2191 "Failed to set OWE DH Param element override");
2192 return -2;
2193 }
2194 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002195 sigma_dut_print(dut, DUT_MSG_ERROR,
2196 "Failed to clear owe_group");
2197 return -2;
2198 }
2199
2200 return 1;
2201}
2202
2203
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002204static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2205 struct sigma_cmd *cmd)
2206{
2207 const char *type = get_param(cmd, "Type");
2208
2209 if (type == NULL) {
2210 send_resp(dut, conn, SIGMA_ERROR,
2211 "ErrorCode,Missing Type argument");
2212 return 0;
2213 }
2214
2215 if (strcasecmp(type, "OPEN") == 0)
2216 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002217 if (strcasecmp(type, "OWE") == 0)
2218 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002219 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002220 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002221 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002222 return cmd_sta_set_psk(dut, conn, cmd);
2223 if (strcasecmp(type, "EAPTLS") == 0)
2224 return cmd_sta_set_eaptls(dut, conn, cmd);
2225 if (strcasecmp(type, "EAPTTLS") == 0)
2226 return cmd_sta_set_eapttls(dut, conn, cmd);
2227 if (strcasecmp(type, "EAPPEAP") == 0)
2228 return cmd_sta_set_peap(dut, conn, cmd);
2229 if (strcasecmp(type, "EAPSIM") == 0)
2230 return cmd_sta_set_eapsim(dut, conn, cmd);
2231 if (strcasecmp(type, "EAPFAST") == 0)
2232 return cmd_sta_set_eapfast(dut, conn, cmd);
2233 if (strcasecmp(type, "EAPAKA") == 0)
2234 return cmd_sta_set_eapaka(dut, conn, cmd);
2235 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2236 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002237 if (strcasecmp(type, "wep") == 0)
2238 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002239
2240 send_resp(dut, conn, SIGMA_ERROR,
2241 "ErrorCode,Unsupported Type value");
2242 return 0;
2243}
2244
2245
2246int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2247{
2248#ifdef __linux__
2249 /* special handling for ath6kl */
2250 char path[128], fname[128], *pos;
2251 ssize_t res;
2252 FILE *f;
2253
2254 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2255 res = readlink(path, path, sizeof(path));
2256 if (res < 0)
2257 return 0; /* not ath6kl */
2258
2259 if (res >= (int) sizeof(path))
2260 res = sizeof(path) - 1;
2261 path[res] = '\0';
2262 pos = strrchr(path, '/');
2263 if (pos == NULL)
2264 pos = path;
2265 else
2266 pos++;
2267 snprintf(fname, sizeof(fname),
2268 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2269 "create_qos", pos);
2270 if (!file_exists(fname))
2271 return 0; /* not ath6kl */
2272
2273 if (uapsd) {
2274 f = fopen(fname, "w");
2275 if (f == NULL)
2276 return -1;
2277
2278 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2279 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2280 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2281 "20000 0\n");
2282 fclose(f);
2283 } else {
2284 snprintf(fname, sizeof(fname),
2285 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2286 "delete_qos", pos);
2287
2288 f = fopen(fname, "w");
2289 if (f == NULL)
2290 return -1;
2291
2292 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2293 fprintf(f, "2 4\n");
2294 fclose(f);
2295 }
2296#endif /* __linux__ */
2297
2298 return 0;
2299}
2300
2301
2302static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2303 struct sigma_cmd *cmd)
2304{
2305 const char *intf = get_param(cmd, "Interface");
2306 /* const char *ssid = get_param(cmd, "ssid"); */
2307 const char *val;
2308 int max_sp_len = 4;
2309 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2310 char buf[100];
2311 int ret1, ret2;
2312
2313 val = get_param(cmd, "maxSPLength");
2314 if (val) {
2315 max_sp_len = atoi(val);
2316 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2317 max_sp_len != 4)
2318 return -1;
2319 }
2320
2321 val = get_param(cmd, "acBE");
2322 if (val)
2323 ac_be = atoi(val);
2324
2325 val = get_param(cmd, "acBK");
2326 if (val)
2327 ac_bk = atoi(val);
2328
2329 val = get_param(cmd, "acVI");
2330 if (val)
2331 ac_vi = atoi(val);
2332
2333 val = get_param(cmd, "acVO");
2334 if (val)
2335 ac_vo = atoi(val);
2336
2337 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2338
2339 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2340 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2341 ret1 = wpa_command(intf, buf);
2342
2343 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2344 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2345 ret2 = wpa_command(intf, buf);
2346
2347 if (ret1 && ret2) {
2348 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2349 "UAPSD parameters.");
2350 return -2;
2351 }
2352
2353 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2354 send_resp(dut, conn, SIGMA_ERROR,
2355 "ErrorCode,Failed to set ath6kl QoS parameters");
2356 return 0;
2357 }
2358
2359 return 1;
2360}
2361
2362
2363static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2364 struct sigma_cmd *cmd)
2365{
2366 char buf[1000];
2367 const char *intf = get_param(cmd, "Interface");
2368 const char *grp = get_param(cmd, "Group");
2369 const char *act = get_param(cmd, "Action");
2370 const char *tid = get_param(cmd, "Tid");
2371 const char *dir = get_param(cmd, "Direction");
2372 const char *psb = get_param(cmd, "Psb");
2373 const char *up = get_param(cmd, "Up");
2374 const char *fixed = get_param(cmd, "Fixed");
2375 const char *size = get_param(cmd, "Size");
2376 const char *msize = get_param(cmd, "Maxsize");
2377 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2378 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2379 const char *inact = get_param(cmd, "Inactivity");
2380 const char *sus = get_param(cmd, "Suspension");
2381 const char *mindr = get_param(cmd, "Mindatarate");
2382 const char *meandr = get_param(cmd, "Meandatarate");
2383 const char *peakdr = get_param(cmd, "Peakdatarate");
2384 const char *phyrate = get_param(cmd, "Phyrate");
2385 const char *burstsize = get_param(cmd, "Burstsize");
2386 const char *sba = get_param(cmd, "Sba");
2387 int direction;
2388 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002389 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002390 int fixed_int;
2391 int psb_ts;
2392
2393 if (intf == NULL || grp == NULL || act == NULL )
2394 return -1;
2395
2396 if (strcasecmp(act, "addts") == 0) {
2397 if (tid == NULL || dir == NULL || psb == NULL ||
2398 up == NULL || fixed == NULL || size == NULL)
2399 return -1;
2400
2401 /*
2402 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2403 * possible values, but WMM-AC and V-E test scripts use "UP,
2404 * "DOWN", and "BIDI".
2405 */
2406 if (strcasecmp(dir, "uplink") == 0 ||
2407 strcasecmp(dir, "up") == 0) {
2408 direction = 0;
2409 } else if (strcasecmp(dir, "downlink") == 0 ||
2410 strcasecmp(dir, "down") == 0) {
2411 direction = 1;
2412 } else if (strcasecmp(dir, "bidi") == 0) {
2413 direction = 2;
2414 } else {
2415 sigma_dut_print(dut, DUT_MSG_ERROR,
2416 "Direction %s not supported", dir);
2417 return -1;
2418 }
2419
2420 if (strcasecmp(psb, "legacy") == 0) {
2421 psb_ts = 0;
2422 } else if (strcasecmp(psb, "uapsd") == 0) {
2423 psb_ts = 1;
2424 } else {
2425 sigma_dut_print(dut, DUT_MSG_ERROR,
2426 "PSB %s not supported", psb);
2427 return -1;
2428 }
2429
2430 if (atoi(tid) < 0 || atoi(tid) > 7) {
2431 sigma_dut_print(dut, DUT_MSG_ERROR,
2432 "TID %s not supported", tid);
2433 return -1;
2434 }
2435
2436 if (strcasecmp(fixed, "true") == 0) {
2437 fixed_int = 1;
2438 } else {
2439 fixed_int = 0;
2440 }
2441
Peng Xu93319622017-10-04 17:58:16 -07002442 if (sba)
2443 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444
2445 dut->dialog_token++;
2446 handle = 7000 + dut->dialog_token;
2447
2448 /*
2449 * size: convert to hex
2450 * maxsi: convert to hex
2451 * mindr: convert to hex
2452 * meandr: convert to hex
2453 * peakdr: convert to hex
2454 * burstsize: convert to hex
2455 * phyrate: convert to hex
2456 * sba: convert to hex with modification
2457 * minsi: convert to integer
2458 * sus: convert to integer
2459 * inact: convert to integer
2460 * maxsi: convert to integer
2461 */
2462
2463 /*
2464 * The Nominal MSDU Size field is 2 octets long and contains an
2465 * unsigned integer that specifies the nominal size, in octets,
2466 * of MSDUs belonging to the traffic under this traffic
2467 * specification and is defined in Figure 16. If the Fixed
2468 * subfield is set to 1, then the size of the MSDU is fixed and
2469 * is indicated by the Size Subfield. If the Fixed subfield is
2470 * set to 0, then the size of the MSDU might not be fixed and
2471 * the Size indicates the nominal MSDU size.
2472 *
2473 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2474 * and specifies the excess allocation of time (and bandwidth)
2475 * over and above the stated rates required to transport an MSDU
2476 * belonging to the traffic in this TSPEC. This field is
2477 * represented as an unsigned binary number with an implicit
2478 * binary point after the leftmost 3 bits. For example, an SBA
2479 * of 1.75 is represented as 0x3800. This field is included to
2480 * account for retransmissions. As such, the value of this field
2481 * must be greater than unity.
2482 */
2483
2484 snprintf(buf, sizeof(buf),
2485 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2486 " 0x%X 0x%X 0x%X"
2487 " 0x%X 0x%X 0x%X"
2488 " 0x%X %d %d %d %d"
2489 " %d %d",
2490 intf, handle, tid, direction, psb_ts, up,
2491 (unsigned int) ((fixed_int << 15) | atoi(size)),
2492 msize ? atoi(msize) : 0,
2493 mindr ? atoi(mindr) : 0,
2494 meandr ? atoi(meandr) : 0,
2495 peakdr ? atoi(peakdr) : 0,
2496 burstsize ? atoi(burstsize) : 0,
2497 phyrate ? atoi(phyrate) : 0,
2498 sba ? ((unsigned int) (((int) sba_fv << 13) |
2499 (int)((sba_fv - (int) sba_fv) *
2500 8192))) : 0,
2501 minsi ? atoi(minsi) : 0,
2502 sus ? atoi(sus) : 0,
2503 0, 0,
2504 inact ? atoi(inact) : 0,
2505 maxsi ? atoi(maxsi) : 0);
2506
2507 if (system(buf) != 0) {
2508 sigma_dut_print(dut, DUT_MSG_ERROR,
2509 "iwpriv addtspec request failed");
2510 send_resp(dut, conn, SIGMA_ERROR,
2511 "errorCode,Failed to execute addTspec command");
2512 return 0;
2513 }
2514
2515 sigma_dut_print(dut, DUT_MSG_INFO,
2516 "iwpriv addtspec request send");
2517
2518 /* Mapping handle to a TID */
2519 dut->tid_to_handle[atoi(tid)] = handle;
2520 } else if (strcasecmp(act, "delts") == 0) {
2521 if (tid == NULL)
2522 return -1;
2523
2524 if (atoi(tid) < 0 || atoi(tid) > 7) {
2525 sigma_dut_print(dut, DUT_MSG_ERROR,
2526 "TID %s not supported", tid);
2527 send_resp(dut, conn, SIGMA_ERROR,
2528 "errorCode,Unsupported TID");
2529 return 0;
2530 }
2531
2532 handle = dut->tid_to_handle[atoi(tid)];
2533
2534 if (handle < 7000 || handle > 7255) {
2535 /* Invalid handle ie no mapping for that TID */
2536 sigma_dut_print(dut, DUT_MSG_ERROR,
2537 "handle-> %d not found", handle);
2538 }
2539
2540 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2541 intf, handle);
2542
2543 if (system(buf) != 0) {
2544 sigma_dut_print(dut, DUT_MSG_ERROR,
2545 "iwpriv deltspec request failed");
2546 send_resp(dut, conn, SIGMA_ERROR,
2547 "errorCode,Failed to execute delTspec command");
2548 return 0;
2549 }
2550
2551 sigma_dut_print(dut, DUT_MSG_INFO,
2552 "iwpriv deltspec request send");
2553
2554 dut->tid_to_handle[atoi(tid)] = 0;
2555 } else {
2556 sigma_dut_print(dut, DUT_MSG_ERROR,
2557 "Action type %s not supported", act);
2558 send_resp(dut, conn, SIGMA_ERROR,
2559 "errorCode,Unsupported Action");
2560 return 0;
2561 }
2562
2563 return 1;
2564}
2565
2566
vamsi krishna52e16f92017-08-29 12:37:34 +05302567static int find_network(struct sigma_dut *dut, const char *ssid)
2568{
2569 char list[4096];
2570 char *pos;
2571
2572 sigma_dut_print(dut, DUT_MSG_DEBUG,
2573 "Search for profile based on SSID: '%s'", ssid);
2574 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2575 list, sizeof(list)) < 0)
2576 return -1;
2577 pos = strstr(list, ssid);
2578 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2579 return -1;
2580
2581 while (pos > list && pos[-1] != '\n')
2582 pos--;
2583 dut->infra_network_id = atoi(pos);
2584 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2585 return 0;
2586}
2587
2588
Sunil Dutt44595082018-02-12 19:41:45 +05302589#ifdef NL80211_SUPPORT
2590static int sta_config_rsnie(struct sigma_dut *dut, int val)
2591{
2592 struct nl_msg *msg;
2593 int ret;
2594 struct nlattr *params;
2595 int ifindex;
2596
2597 ifindex = if_nametoindex("wlan0");
2598 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2599 NL80211_CMD_VENDOR)) ||
2600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2601 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2602 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2603 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2604 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2605 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2606 sigma_dut_print(dut, DUT_MSG_ERROR,
2607 "%s: err in adding vendor_cmd and vendor_data",
2608 __func__);
2609 nlmsg_free(msg);
2610 return -1;
2611 }
2612 nla_nest_end(msg, params);
2613
2614 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2615 if (ret) {
2616 sigma_dut_print(dut, DUT_MSG_ERROR,
2617 "%s: err in send_and_recv_msgs, ret=%d",
2618 __func__, ret);
2619 return ret;
2620 }
2621
2622 return 0;
2623}
2624#endif /* NL80211_SUPPORT */
2625
2626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002627static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2628 struct sigma_cmd *cmd)
2629{
2630 /* const char *intf = get_param(cmd, "Interface"); */
2631 const char *ssid = get_param(cmd, "ssid");
2632 const char *wps_param = get_param(cmd, "WPS");
2633 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002634 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002635 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002636 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002637
2638 if (ssid == NULL)
2639 return -1;
2640
Jouni Malinen3c367e82017-06-23 17:01:47 +03002641 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302642#ifdef NL80211_SUPPORT
2643 if (get_driver_type() == DRIVER_WCN) {
2644 sta_config_rsnie(dut, 1);
2645 dut->config_rsnie = 1;
2646 }
2647#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002648 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2649 dut->rsne_override);
2650 if (wpa_command(get_station_ifname(), buf) < 0) {
2651 send_resp(dut, conn, SIGMA_ERROR,
2652 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2653 return 0;
2654 }
2655 }
2656
Jouni Malinen68143132017-09-02 02:34:08 +03002657 if (dut->sae_commit_override) {
2658 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2659 dut->sae_commit_override);
2660 if (wpa_command(get_station_ifname(), buf) < 0) {
2661 send_resp(dut, conn, SIGMA_ERROR,
2662 "ErrorCode,Failed to set SAE commit override");
2663 return 0;
2664 }
2665 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302666#ifdef ANDROID
2667 if (dut->fils_hlp)
2668 process_fils_hlp(dut);
2669#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002670
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002671 if (wps_param &&
2672 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2673 wps = 1;
2674
2675 if (wps) {
2676 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2677 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2678 "parameters not yet set");
2679 return 0;
2680 }
2681 if (dut->wps_method == WFA_CS_WPS_PBC) {
2682 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2683 return -2;
2684 } else {
2685 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2686 dut->wps_pin);
2687 if (wpa_command(get_station_ifname(), buf) < 0)
2688 return -2;
2689 }
2690 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302691 if (strcmp(ssid, dut->infra_ssid) == 0) {
2692 sigma_dut_print(dut, DUT_MSG_DEBUG,
2693 "sta_associate for the most recently added network");
2694 } else if (find_network(dut, ssid) < 0) {
2695 sigma_dut_print(dut, DUT_MSG_DEBUG,
2696 "sta_associate for a previously stored network profile");
2697 send_resp(dut, conn, SIGMA_ERROR,
2698 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002699 return 0;
2700 }
2701
2702 if (bssid &&
2703 set_network(get_station_ifname(), dut->infra_network_id,
2704 "bssid", bssid) < 0) {
2705 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2706 "Invalid bssid argument");
2707 return 0;
2708 }
2709
Jouni Malinen46a19b62017-06-23 14:31:27 +03002710 extra[0] = '\0';
2711 if (chan)
2712 snprintf(extra, sizeof(extra), " freq=%u",
2713 channel_to_freq(atoi(chan)));
2714 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2715 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002716 if (wpa_command(get_station_ifname(), buf) < 0) {
2717 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2718 "network id %d on %s",
2719 dut->infra_network_id,
2720 get_station_ifname());
2721 return -2;
2722 }
2723 }
2724
2725 return 1;
2726}
2727
2728
2729static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2730{
2731 char buf[500], cmd[200];
2732 int res;
2733
2734 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2735 * default path */
2736 res = snprintf(cmd, sizeof(cmd),
2737 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2738 file_exists("./hs20-osu-client") ?
2739 "./hs20-osu-client" : "hs20-osu-client",
2740 sigma_wpas_ctrl,
2741 dut->summary_log ? "-s " : "",
2742 dut->summary_log ? dut->summary_log : "");
2743 if (res < 0 || res >= (int) sizeof(cmd))
2744 return -1;
2745
2746 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2747 if (res < 0 || res >= (int) sizeof(buf))
2748 return -1;
2749 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2750
2751 if (system(buf) != 0) {
2752 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2753 return -1;
2754 }
2755 sigma_dut_print(dut, DUT_MSG_DEBUG,
2756 "Completed hs20-osu-client operation");
2757
2758 return 0;
2759}
2760
2761
2762static int download_ppsmo(struct sigma_dut *dut,
2763 struct sigma_conn *conn,
2764 const char *intf,
2765 struct sigma_cmd *cmd)
2766{
2767 const char *name, *path, *val;
2768 char url[500], buf[600], fbuf[100];
2769 char *fqdn = NULL;
2770
2771 name = get_param(cmd, "FileName");
2772 path = get_param(cmd, "FilePath");
2773 if (name == NULL || path == NULL)
2774 return -1;
2775
2776 if (strcasecmp(path, "VendorSpecific") == 0) {
2777 snprintf(url, sizeof(url), "PPS/%s", name);
2778 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2779 "from the device (%s)", url);
2780 if (!file_exists(url)) {
2781 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2782 "PPS MO file does not exist");
2783 return 0;
2784 }
2785 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2786 if (system(buf) != 0) {
2787 send_resp(dut, conn, SIGMA_ERROR,
2788 "errorCode,Failed to copy PPS MO");
2789 return 0;
2790 }
2791 } else if (strncasecmp(path, "http:", 5) != 0 &&
2792 strncasecmp(path, "https:", 6) != 0) {
2793 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2794 "Unsupported FilePath value");
2795 return 0;
2796 } else {
2797 snprintf(url, sizeof(url), "%s/%s", path, name);
2798 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2799 url);
2800 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2801 remove("pps-tnds.xml");
2802 if (system(buf) != 0) {
2803 send_resp(dut, conn, SIGMA_ERROR,
2804 "errorCode,Failed to download PPS MO");
2805 return 0;
2806 }
2807 }
2808
2809 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2810 send_resp(dut, conn, SIGMA_ERROR,
2811 "errorCode,Failed to parse downloaded PPSMO");
2812 return 0;
2813 }
2814 unlink("pps-tnds.xml");
2815
2816 val = get_param(cmd, "managementTreeURI");
2817 if (val) {
2818 const char *pos, *end;
2819 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2820 val);
2821 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2822 send_resp(dut, conn, SIGMA_ERROR,
2823 "errorCode,Invalid managementTreeURI prefix");
2824 return 0;
2825 }
2826 pos = val + 8;
2827 end = strchr(pos, '/');
2828 if (end == NULL ||
2829 strcmp(end, "/PerProviderSubscription") != 0) {
2830 send_resp(dut, conn, SIGMA_ERROR,
2831 "errorCode,Invalid managementTreeURI postfix");
2832 return 0;
2833 }
2834 if (end - pos >= (int) sizeof(fbuf)) {
2835 send_resp(dut, conn, SIGMA_ERROR,
2836 "errorCode,Too long FQDN in managementTreeURI");
2837 return 0;
2838 }
2839 memcpy(fbuf, pos, end - pos);
2840 fbuf[end - pos] = '\0';
2841 fqdn = fbuf;
2842 sigma_dut_print(dut, DUT_MSG_INFO,
2843 "FQDN from managementTreeURI: %s", fqdn);
2844 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2845 FILE *f = fopen("pps-fqdn", "r");
2846 if (f) {
2847 if (fgets(fbuf, sizeof(fbuf), f)) {
2848 fbuf[sizeof(fbuf) - 1] = '\0';
2849 fqdn = fbuf;
2850 sigma_dut_print(dut, DUT_MSG_DEBUG,
2851 "Use FQDN %s", fqdn);
2852 }
2853 fclose(f);
2854 }
2855 }
2856
2857 if (fqdn == NULL) {
2858 send_resp(dut, conn, SIGMA_ERROR,
2859 "errorCode,No FQDN specified");
2860 return 0;
2861 }
2862
2863 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2864 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2865 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2866
2867 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2868 if (rename("pps.xml", buf) < 0) {
2869 send_resp(dut, conn, SIGMA_ERROR,
2870 "errorCode,Could not move PPS MO");
2871 return 0;
2872 }
2873
2874 if (strcasecmp(path, "VendorSpecific") == 0) {
2875 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2876 fqdn);
2877 if (system(buf)) {
2878 send_resp(dut, conn, SIGMA_ERROR,
2879 "errorCode,Failed to copy OSU CA cert");
2880 return 0;
2881 }
2882
2883 snprintf(buf, sizeof(buf),
2884 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2885 fqdn);
2886 if (system(buf)) {
2887 send_resp(dut, conn, SIGMA_ERROR,
2888 "errorCode,Failed to copy AAA CA cert");
2889 return 0;
2890 }
2891 } else {
2892 snprintf(buf, sizeof(buf),
2893 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2894 fqdn, fqdn);
2895 if (run_hs20_osu(dut, buf) < 0) {
2896 send_resp(dut, conn, SIGMA_ERROR,
2897 "errorCode,Failed to download OSU CA cert");
2898 return 0;
2899 }
2900
2901 snprintf(buf, sizeof(buf),
2902 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2903 fqdn, fqdn);
2904 if (run_hs20_osu(dut, buf) < 0) {
2905 sigma_dut_print(dut, DUT_MSG_INFO,
2906 "Failed to download AAA CA cert");
2907 }
2908 }
2909
2910 if (file_exists("next-client-cert.pem")) {
2911 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2912 if (rename("next-client-cert.pem", buf) < 0) {
2913 send_resp(dut, conn, SIGMA_ERROR,
2914 "errorCode,Could not move client certificate");
2915 return 0;
2916 }
2917 }
2918
2919 if (file_exists("next-client-key.pem")) {
2920 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2921 if (rename("next-client-key.pem", buf) < 0) {
2922 send_resp(dut, conn, SIGMA_ERROR,
2923 "errorCode,Could not move client key");
2924 return 0;
2925 }
2926 }
2927
2928 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2929 if (run_hs20_osu(dut, buf) < 0) {
2930 send_resp(dut, conn, SIGMA_ERROR,
2931 "errorCode,Failed to configure credential from "
2932 "PPSMO");
2933 return 0;
2934 }
2935
2936 return 1;
2937}
2938
2939
2940static int download_cert(struct sigma_dut *dut,
2941 struct sigma_conn *conn,
2942 const char *intf,
2943 struct sigma_cmd *cmd)
2944{
2945 const char *name, *path;
2946 char url[500], buf[600];
2947
2948 name = get_param(cmd, "FileName");
2949 path = get_param(cmd, "FilePath");
2950 if (name == NULL || path == NULL)
2951 return -1;
2952
2953 if (strcasecmp(path, "VendorSpecific") == 0) {
2954 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2955 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2956 "certificate from the device (%s)", url);
2957 if (!file_exists(url)) {
2958 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2959 "certificate file does not exist");
2960 return 0;
2961 }
2962 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2963 if (system(buf) != 0) {
2964 send_resp(dut, conn, SIGMA_ERROR,
2965 "errorCode,Failed to copy client "
2966 "certificate");
2967 return 0;
2968 }
2969
2970 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2971 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2972 "private key from the device (%s)", url);
2973 if (!file_exists(url)) {
2974 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2975 "private key file does not exist");
2976 return 0;
2977 }
2978 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2979 if (system(buf) != 0) {
2980 send_resp(dut, conn, SIGMA_ERROR,
2981 "errorCode,Failed to copy client key");
2982 return 0;
2983 }
2984 } else if (strncasecmp(path, "http:", 5) != 0 &&
2985 strncasecmp(path, "https:", 6) != 0) {
2986 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2987 "Unsupported FilePath value");
2988 return 0;
2989 } else {
2990 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2991 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2992 "certificate/key from %s", url);
2993 snprintf(buf, sizeof(buf),
2994 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2995 if (system(buf) != 0) {
2996 send_resp(dut, conn, SIGMA_ERROR,
2997 "errorCode,Failed to download client "
2998 "certificate");
2999 return 0;
3000 }
3001
3002 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3003 {
3004 send_resp(dut, conn, SIGMA_ERROR,
3005 "errorCode,Failed to copy client key");
3006 return 0;
3007 }
3008 }
3009
3010 return 1;
3011}
3012
3013
3014static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3015 struct sigma_conn *conn,
3016 const char *intf,
3017 struct sigma_cmd *cmd)
3018{
3019 const char *val;
3020
3021 val = get_param(cmd, "FileType");
3022 if (val && strcasecmp(val, "PPSMO") == 0)
3023 return download_ppsmo(dut, conn, intf, cmd);
3024 if (val && strcasecmp(val, "CERT") == 0)
3025 return download_cert(dut, conn, intf, cmd);
3026 if (val) {
3027 send_resp(dut, conn, SIGMA_ERROR,
3028 "ErrorCode,Unsupported FileType");
3029 return 0;
3030 }
3031
3032 return 1;
3033}
3034
3035
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303036static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3037 struct sigma_conn *conn,
3038 const char *intf,
3039 struct sigma_cmd *cmd)
3040{
3041 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303042 char buf[1000];
3043 char text[20];
3044 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303045
3046 val = get_param(cmd, "OCESupport");
3047 if (val && strcasecmp(val, "Disable") == 0) {
3048 if (wpa_command(intf, "SET oce 0") < 0) {
3049 send_resp(dut, conn, SIGMA_ERROR,
3050 "ErrorCode,Failed to disable OCE");
3051 return 0;
3052 }
3053 } else if (val && strcasecmp(val, "Enable") == 0) {
3054 if (wpa_command(intf, "SET oce 1") < 0) {
3055 send_resp(dut, conn, SIGMA_ERROR,
3056 "ErrorCode,Failed to enable OCE");
3057 return 0;
3058 }
3059 }
3060
vamsi krishnaa2799492017-12-05 14:28:01 +05303061 val = get_param(cmd, "FILScap");
3062 if (val && (atoi(val) == 1)) {
3063 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3064 send_resp(dut, conn, SIGMA_ERROR,
3065 "ErrorCode,Failed to enable FILS");
3066 return 0;
3067 }
3068 } else if (val && (atoi(val) == 0)) {
3069 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3070 send_resp(dut, conn, SIGMA_ERROR,
3071 "ErrorCode,Failed to disable FILS");
3072 return 0;
3073 }
3074 }
3075
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303076 val = get_param(cmd, "FILSHLP");
3077 if (val && strcasecmp(val, "Enable") == 0) {
3078 if (get_wpa_status(get_station_ifname(), "address", text,
3079 sizeof(text)) < 0)
3080 return -2;
3081 hwaddr_aton(text, addr);
3082 snprintf(buf, sizeof(buf),
3083 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3084 "080045100140000040004011399e00000000ffffffff00440043"
3085 "012cb30001010600fd4f46410000000000000000000000000000"
3086 "000000000000"
3087 "%02x%02x%02x%02x%02x%02x"
3088 "0000000000000000000000000000000000000000000000000000"
3089 "0000000000000000000000000000000000000000000000000000"
3090 "0000000000000000000000000000000000000000000000000000"
3091 "0000000000000000000000000000000000000000000000000000"
3092 "0000000000000000000000000000000000000000000000000000"
3093 "0000000000000000000000000000000000000000000000000000"
3094 "0000000000000000000000000000000000000000000000000000"
3095 "0000000000000000000000000000000000000000638253633501"
3096 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3097 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3098 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3099 if (wpa_command(intf, buf)) {
3100 send_resp(dut, conn, SIGMA_ERROR,
3101 "ErrorCode,Failed to add HLP");
3102 return 0;
3103 }
3104 dut->fils_hlp = 1;
3105 }
3106
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303107 return 1;
3108}
3109
3110
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003111static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3112 const char *val)
3113{
3114 int counter = 0;
3115 char token[50];
3116 char *result;
3117 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303118 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003119
Peng Xub8fc5cc2017-05-10 17:27:28 -07003120 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303122 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003123 while (result) {
3124 if (strcmp(result, "disable") == 0) {
3125 snprintf(buf, sizeof(buf),
3126 "iwpriv %s noackpolicy %d 1 0",
3127 intf, counter);
3128 } else {
3129 snprintf(buf, sizeof(buf),
3130 "iwpriv %s noackpolicy %d 1 1",
3131 intf, counter);
3132 }
3133 if (system(buf) != 0) {
3134 sigma_dut_print(dut, DUT_MSG_ERROR,
3135 "iwpriv noackpolicy failed");
3136 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303137 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003138 counter++;
3139 }
3140}
3141
3142
3143static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3144 const char *val)
3145{
3146 char buf[100];
3147
3148 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3149 if (system(buf) != 0) {
3150 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3151 }
3152}
3153
3154
3155static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3156 const char *val)
3157{
3158 char buf[100];
3159
3160 if (strcasecmp(val, "off") == 0) {
3161 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3162 if (system(buf) != 0) {
3163 sigma_dut_print(dut, DUT_MSG_ERROR,
3164 "Failed to turn off WMM");
3165 }
3166 }
3167}
3168
3169
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003170static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3171 const char *val)
3172{
3173#ifdef NL80211_SUPPORT
3174 struct nl_msg *msg;
3175 int ret = 0;
3176 struct nlattr *params;
3177 int ifindex;
3178 int wmmenable = 1;
3179
3180 if (val &&
3181 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3182 wmmenable = 0;
3183
3184 ifindex = if_nametoindex(intf);
3185 if (ifindex == 0) {
3186 sigma_dut_print(dut, DUT_MSG_ERROR,
3187 "%s: Index for interface %s failed",
3188 __func__, intf);
3189 return -1;
3190 }
3191
3192 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3193 NL80211_CMD_VENDOR)) ||
3194 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3195 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3196 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3197 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3198 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3199 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3200 wmmenable)) {
3201 sigma_dut_print(dut, DUT_MSG_ERROR,
3202 "%s: err in adding vendor_cmd and vendor_data",
3203 __func__);
3204 nlmsg_free(msg);
3205 return -1;
3206 }
3207 nla_nest_end(msg, params);
3208
3209 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3210 if (ret) {
3211 sigma_dut_print(dut, DUT_MSG_ERROR,
3212 "%s: err in send_and_recv_msgs, ret=%d",
3213 __func__, ret);
3214 }
3215 return ret;
3216#else /* NL80211_SUPPORT */
3217 sigma_dut_print(dut, DUT_MSG_ERROR,
3218 "WMM cannot be changed without NL80211_SUPPORT defined");
3219 return -1;
3220#endif /* NL80211_SUPPORT */
3221}
3222
3223
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003224static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3225 const char *val)
3226{
3227 char buf[100];
3228 int sgi20;
3229
3230 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3231
3232 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3233 if (system(buf) != 0)
3234 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3235}
3236
3237
3238static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3239 const char *val)
3240{
3241 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303242 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003243
3244 /* Disable Tx Beam forming when using a fixed rate */
3245 ath_disable_txbf(dut, intf);
3246
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303247 v = atoi(val);
3248 if (v < 0 || v > 32) {
3249 sigma_dut_print(dut, DUT_MSG_ERROR,
3250 "Invalid Fixed MCS rate: %d", v);
3251 return;
3252 }
3253 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003254
3255 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3256 intf, rate_code);
3257 if (system(buf) != 0) {
3258 sigma_dut_print(dut, DUT_MSG_ERROR,
3259 "iwpriv set11NRates failed");
3260 }
3261
3262 /* Channel width gets messed up, fix this */
3263 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3264 if (system(buf) != 0)
3265 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3266}
3267
3268
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003269static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3270 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003271{
3272 char buf[60];
3273
3274 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3275 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3276 else
3277 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3278
3279 if (system(buf) != 0)
3280 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3281}
3282
3283
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003284static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3285 int ampdu)
3286{
3287 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003288 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003289
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003290 if (ampdu)
3291 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003292 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3293 if (system(buf) != 0) {
3294 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3295 return -1;
3296 }
3297
3298 return 0;
3299}
3300
3301
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003302static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3303 const char *val)
3304{
3305 char buf[60];
3306
3307 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3308 if (system(buf) != 0) {
3309 sigma_dut_print(dut, DUT_MSG_ERROR,
3310 "iwpriv tx_stbc failed");
3311 }
3312
3313 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3314 if (system(buf) != 0) {
3315 sigma_dut_print(dut, DUT_MSG_ERROR,
3316 "iwpriv rx_stbc failed");
3317 }
3318}
3319
3320
3321static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3322 const char *val)
3323{
3324 char buf[60];
3325
Peng Xucc317ed2017-05-18 16:44:37 -07003326 if (strcmp(val, "160") == 0) {
3327 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3328 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003329 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3330 } else if (strcmp(val, "40") == 0) {
3331 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3332 } else if (strcmp(val, "20") == 0) {
3333 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3334 } else if (strcasecmp(val, "Auto") == 0) {
3335 buf[0] = '\0';
3336 } else {
3337 sigma_dut_print(dut, DUT_MSG_ERROR,
3338 "WIDTH/CTS_WIDTH value not supported");
3339 return -1;
3340 }
3341
3342 if (buf[0] != '\0' && system(buf) != 0) {
3343 sigma_dut_print(dut, DUT_MSG_ERROR,
3344 "Failed to set WIDTH/CTS_WIDTH");
3345 return -1;
3346 }
3347
3348 return 0;
3349}
3350
3351
3352int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3353 const char *intf, const char *val)
3354{
3355 char buf[60];
3356
3357 if (strcasecmp(val, "Auto") == 0) {
3358 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3359 dut->chwidth = 0;
3360 } else if (strcasecmp(val, "20") == 0) {
3361 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3362 dut->chwidth = 0;
3363 } else if (strcasecmp(val, "40") == 0) {
3364 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3365 dut->chwidth = 1;
3366 } else if (strcasecmp(val, "80") == 0) {
3367 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3368 dut->chwidth = 2;
3369 } else if (strcasecmp(val, "160") == 0) {
3370 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3371 dut->chwidth = 3;
3372 } else {
3373 send_resp(dut, conn, SIGMA_ERROR,
3374 "ErrorCode,WIDTH not supported");
3375 return -1;
3376 }
3377
3378 if (system(buf) != 0) {
3379 sigma_dut_print(dut, DUT_MSG_ERROR,
3380 "iwpriv chwidth failed");
3381 }
3382
3383 return 0;
3384}
3385
3386
3387static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3388 const char *val)
3389{
3390 char buf[60];
3391
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003392 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003393 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003394 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003395 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
3396 } else {
3397 sigma_dut_print(dut, DUT_MSG_ERROR,
3398 "SP_STREAM value not supported");
3399 return -1;
3400 }
3401
3402 if (system(buf) != 0) {
3403 sigma_dut_print(dut, DUT_MSG_ERROR,
3404 "Failed to set SP_STREAM");
3405 return -1;
3406 }
3407
3408 return 0;
3409}
3410
3411
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303412static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3413 const char *val)
3414{
3415 char buf[60];
3416
3417 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3418 if (system(buf) != 0)
3419 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3420
3421 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3422 if (system(buf) != 0)
3423 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3424}
3425
3426
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303427static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3428 struct sigma_conn *conn,
3429 const char *intf, int capa)
3430{
3431 char buf[32];
3432
3433 if (capa > 0 && capa < 4) {
3434 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3435 if (wpa_command(intf, buf) < 0) {
3436 send_resp(dut, conn, SIGMA_ERROR,
3437 "ErrorCode, Failed to set cellular data capability");
3438 return 0;
3439 }
3440 return 1;
3441 }
3442
3443 sigma_dut_print(dut, DUT_MSG_ERROR,
3444 "Invalid Cellular data capability: %d", capa);
3445 send_resp(dut, conn, SIGMA_INVALID,
3446 "ErrorCode,Invalid cellular data capability");
3447 return 0;
3448}
3449
3450
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303451static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3452 const char *intf, const char *val)
3453{
3454 if (strcasecmp(val, "Disable") == 0) {
3455 if (wpa_command(intf, "SET roaming 0") < 0) {
3456 send_resp(dut, conn, SIGMA_ERROR,
3457 "ErrorCode,Failed to disable roaming");
3458 return 0;
3459 }
3460 return 1;
3461 }
3462
3463 if (strcasecmp(val, "Enable") == 0) {
3464 if (wpa_command(intf, "SET roaming 1") < 0) {
3465 send_resp(dut, conn, SIGMA_ERROR,
3466 "ErrorCode,Failed to enable roaming");
3467 return 0;
3468 }
3469 return 1;
3470 }
3471
3472 sigma_dut_print(dut, DUT_MSG_ERROR,
3473 "Invalid value provided for roaming: %s", val);
3474 send_resp(dut, conn, SIGMA_INVALID,
3475 "ErrorCode,Unknown value provided for Roaming");
3476 return 0;
3477}
3478
3479
Ashwini Patila75de5a2017-04-13 16:35:05 +05303480static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3481 struct sigma_conn *conn,
3482 const char *intf, const char *val)
3483{
3484 if (strcasecmp(val, "Disable") == 0) {
3485 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3486 send_resp(dut, conn, SIGMA_ERROR,
3487 "ErrorCode,Failed to disable Assoc_disallow");
3488 return 0;
3489 }
3490 return 1;
3491 }
3492
3493 if (strcasecmp(val, "Enable") == 0) {
3494 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3495 send_resp(dut, conn, SIGMA_ERROR,
3496 "ErrorCode,Failed to enable Assoc_disallow");
3497 return 0;
3498 }
3499 return 1;
3500 }
3501
3502 sigma_dut_print(dut, DUT_MSG_ERROR,
3503 "Invalid value provided for Assoc_disallow: %s", val);
3504 send_resp(dut, conn, SIGMA_INVALID,
3505 "ErrorCode,Unknown value provided for Assoc_disallow");
3506 return 0;
3507}
3508
3509
Ashwini Patilc63161e2017-04-13 16:30:23 +05303510static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3511 const char *intf, const char *val)
3512{
3513 if (strcasecmp(val, "Reject") == 0) {
3514 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3515 send_resp(dut, conn, SIGMA_ERROR,
3516 "ErrorCode,Failed to Reject BTM Request");
3517 return 0;
3518 }
3519 return 1;
3520 }
3521
3522 if (strcasecmp(val, "Accept") == 0) {
3523 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3524 send_resp(dut, conn, SIGMA_ERROR,
3525 "ErrorCode,Failed to Accept BTM Request");
3526 return 0;
3527 }
3528 return 1;
3529 }
3530
3531 sigma_dut_print(dut, DUT_MSG_ERROR,
3532 "Invalid value provided for BSS_Transition: %s", val);
3533 send_resp(dut, conn, SIGMA_INVALID,
3534 "ErrorCode,Unknown value provided for BSS_Transition");
3535 return 0;
3536}
3537
3538
Ashwini Patil00402582017-04-13 12:29:39 +05303539static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3540 struct sigma_conn *conn,
3541 const char *intf,
3542 struct sigma_cmd *cmd)
3543{
3544 const char *ch, *pref, *op_class, *reason;
3545 char buf[120];
3546 int len, ret;
3547
3548 pref = get_param(cmd, "Ch_Pref");
3549 if (!pref)
3550 return 1;
3551
3552 if (strcasecmp(pref, "clear") == 0) {
3553 free(dut->non_pref_ch_list);
3554 dut->non_pref_ch_list = NULL;
3555 } else {
3556 op_class = get_param(cmd, "Ch_Op_Class");
3557 if (!op_class) {
3558 send_resp(dut, conn, SIGMA_INVALID,
3559 "ErrorCode,Ch_Op_Class not provided");
3560 return 0;
3561 }
3562
3563 ch = get_param(cmd, "Ch_Pref_Num");
3564 if (!ch) {
3565 send_resp(dut, conn, SIGMA_INVALID,
3566 "ErrorCode,Ch_Pref_Num not provided");
3567 return 0;
3568 }
3569
3570 reason = get_param(cmd, "Ch_Reason_Code");
3571 if (!reason) {
3572 send_resp(dut, conn, SIGMA_INVALID,
3573 "ErrorCode,Ch_Reason_Code not provided");
3574 return 0;
3575 }
3576
3577 if (!dut->non_pref_ch_list) {
3578 dut->non_pref_ch_list =
3579 calloc(1, NON_PREF_CH_LIST_SIZE);
3580 if (!dut->non_pref_ch_list) {
3581 send_resp(dut, conn, SIGMA_ERROR,
3582 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3583 return 0;
3584 }
3585 }
3586 len = strlen(dut->non_pref_ch_list);
3587 ret = snprintf(dut->non_pref_ch_list + len,
3588 NON_PREF_CH_LIST_SIZE - len,
3589 " %s:%s:%s:%s", op_class, ch, pref, reason);
3590 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3591 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3592 dut->non_pref_ch_list);
3593 } else {
3594 sigma_dut_print(dut, DUT_MSG_ERROR,
3595 "snprintf failed for non_pref_list, ret = %d",
3596 ret);
3597 send_resp(dut, conn, SIGMA_ERROR,
3598 "ErrorCode,snprintf failed");
3599 free(dut->non_pref_ch_list);
3600 dut->non_pref_ch_list = NULL;
3601 return 0;
3602 }
3603 }
3604
3605 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3606 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3607 if (ret < 0 || ret >= (int) sizeof(buf)) {
3608 sigma_dut_print(dut, DUT_MSG_DEBUG,
3609 "snprintf failed for set non_pref_chan, ret: %d",
3610 ret);
3611 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3612 return 0;
3613 }
3614
3615 if (wpa_command(intf, buf) < 0) {
3616 send_resp(dut, conn, SIGMA_ERROR,
3617 "ErrorCode,Failed to set non-preferred channel list");
3618 return 0;
3619 }
3620
3621 return 1;
3622}
3623
3624
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003625#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003626
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003627static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3628 enum he_fragmentation_val frag)
3629{
3630 struct nl_msg *msg;
3631 int ret = 0;
3632 struct nlattr *params;
3633 int ifindex;
3634
3635 ifindex = if_nametoindex(intf);
3636 if (ifindex == 0) {
3637 sigma_dut_print(dut, DUT_MSG_ERROR,
3638 "%s: Index for interface %s failed",
3639 __func__, intf);
3640 return -1;
3641 }
3642
3643 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3644 NL80211_CMD_VENDOR)) ||
3645 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3646 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3647 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3648 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3649 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3650 nla_put_u8(msg,
3651 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3652 frag)) {
3653 sigma_dut_print(dut, DUT_MSG_ERROR,
3654 "%s: err in adding vendor_cmd and vendor_data",
3655 __func__);
3656 nlmsg_free(msg);
3657 return -1;
3658 }
3659 nla_nest_end(msg, params);
3660
3661 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3662 if (ret) {
3663 sigma_dut_print(dut, DUT_MSG_ERROR,
3664 "%s: err in send_and_recv_msgs, ret=%d",
3665 __func__, ret);
3666 }
3667 return ret;
3668}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003669
3670
3671static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
3672 int noack, enum qca_wlan_ac_type ac)
3673{
3674 struct nl_msg *msg;
3675 int ret = 0;
3676 struct nlattr *params;
3677 int ifindex;
3678
3679 ifindex = if_nametoindex(intf);
3680 if (ifindex == 0) {
3681 sigma_dut_print(dut, DUT_MSG_ERROR,
3682 "%s: Index for interface %s failed",
3683 __func__, intf);
3684 return -1;
3685 }
3686
3687 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3688 NL80211_CMD_VENDOR)) ||
3689 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3690 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3691 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3692 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3693 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3694 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
3695 noack) ||
3696 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
3697 ac)) {
3698 sigma_dut_print(dut, DUT_MSG_ERROR,
3699 "%s: err in adding vendor_cmd and vendor_data",
3700 __func__);
3701 nlmsg_free(msg);
3702 return -1;
3703 }
3704 nla_nest_end(msg, params);
3705
3706 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3707 if (ret) {
3708 sigma_dut_print(dut, DUT_MSG_ERROR,
3709 "%s: err in send_and_recv_msgs, ret=%d",
3710 __func__, ret);
3711 }
3712 return ret;
3713}
3714
3715
3716static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
3717 const char *val)
3718{
3719 int noack, ret;
3720 char token[100];
3721 char *result;
3722 char *saveptr;
3723 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
3724
3725 strlcpy(token, val, sizeof(token));
3726 token[sizeof(token) - 1] = '\0';
3727 result = strtok_r(token, ":", &saveptr);
3728 while (result) {
3729 noack = strcasecmp(result, "Disable") != 0;
3730 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
3731 if (ret) {
3732 sigma_dut_print(dut, DUT_MSG_ERROR,
3733 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
3734 ac, ret);
3735 }
3736 result = strtok_r(NULL, ":", &saveptr);
3737 ac++;
3738 }
3739}
3740
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003741#endif /* NL80211_SUPPORT */
3742
3743
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003744static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3745 struct sigma_conn *conn,
3746 struct sigma_cmd *cmd)
3747{
3748 const char *intf = get_param(cmd, "Interface");
3749 const char *val;
3750
3751 val = get_param(cmd, "Program");
Peng Xue9fa7952017-05-09 15:59:49 -07003752 if (val && strcasecmp(val, "HS2-R2") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003753 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3754 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003755
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003756 if (val && strcasecmp(val, "LOC") == 0)
3757 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3758
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003759#ifdef ANDROID_NAN
3760 if (val && strcasecmp(val, "NAN") == 0)
3761 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3762#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003763#ifdef MIRACAST
3764 if (val && (strcasecmp(val, "WFD") == 0 ||
3765 strcasecmp(val, "DisplayR2") == 0))
3766 return miracast_preset_testparameters(dut, conn, cmd);
3767#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003768
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303769 if (val && strcasecmp(val, "MBO") == 0) {
3770 val = get_param(cmd, "Cellular_Data_Cap");
3771 if (val &&
3772 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3773 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303774
3775 val = get_param(cmd, "Ch_Pref");
3776 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3777 return 0;
3778
Ashwini Patilc63161e2017-04-13 16:30:23 +05303779 val = get_param(cmd, "BSS_Transition");
3780 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3781 return 0;
3782
Ashwini Patila75de5a2017-04-13 16:35:05 +05303783 val = get_param(cmd, "Assoc_Disallow");
3784 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3785 return 0;
3786
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303787 val = get_param(cmd, "Roaming");
3788 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3789 return 0;
3790
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303791 return 1;
3792 }
3793
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303794 if (val && strcasecmp(val, "OCE") == 0)
3795 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3796
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003797#if 0
3798 val = get_param(cmd, "Supplicant");
3799 if (val && strcasecmp(val, "Default") != 0) {
3800 send_resp(dut, conn, SIGMA_ERROR,
3801 "ErrorCode,Only default(Vendor) supplicant "
3802 "supported");
3803 return 0;
3804 }
3805#endif
3806
3807 val = get_param(cmd, "RTS");
3808 if (val) {
3809 switch (get_driver_type()) {
3810 case DRIVER_ATHEROS:
3811 ath_sta_set_rts(dut, intf, val);
3812 break;
3813 default:
3814#if 0
3815 send_resp(dut, conn, SIGMA_ERROR,
3816 "ErrorCode,Setting RTS not supported");
3817 return 0;
3818#else
3819 sigma_dut_print(dut, DUT_MSG_DEBUG,
3820 "Setting RTS not supported");
3821 break;
3822#endif
3823 }
3824 }
3825
3826#if 0
3827 val = get_param(cmd, "FRGMNT");
3828 if (val) {
3829 /* TODO */
3830 send_resp(dut, conn, SIGMA_ERROR,
3831 "ErrorCode,Setting FRGMNT not supported");
3832 return 0;
3833 }
3834#endif
3835
3836#if 0
3837 val = get_param(cmd, "Preamble");
3838 if (val) {
3839 /* TODO: Long/Short */
3840 send_resp(dut, conn, SIGMA_ERROR,
3841 "ErrorCode,Setting Preamble not supported");
3842 return 0;
3843 }
3844#endif
3845
3846 val = get_param(cmd, "Mode");
3847 if (val) {
3848 if (strcmp(val, "11b") == 0 ||
3849 strcmp(val, "11g") == 0 ||
3850 strcmp(val, "11a") == 0 ||
3851 strcmp(val, "11n") == 0 ||
3852 strcmp(val, "11ng") == 0 ||
3853 strcmp(val, "11nl") == 0 ||
3854 strcmp(val, "11nl(nabg)") == 0 ||
3855 strcmp(val, "AC") == 0 ||
3856 strcmp(val, "11AC") == 0 ||
3857 strcmp(val, "11ac") == 0 ||
3858 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003859 strcmp(val, "11an") == 0 ||
3860 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003861 /* STA supports all modes by default */
3862 } else {
3863 send_resp(dut, conn, SIGMA_ERROR,
3864 "ErrorCode,Setting Mode not supported");
3865 return 0;
3866 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003867
3868 /* Change the mode only in case of testbed for HE program
3869 * and for 11a and 11g modes only. */
3870 if (dut->program == PROGRAM_HE &&
3871 dut->device_type == STA_testbed) {
3872 int phymode;
3873 char buf[60];
3874
3875 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08003876 phymode = 1; /* IEEE80211_MODE_11A */
3877 } else if (strcmp(val, "11g") == 0) {
3878 phymode = 3; /* IEEE80211_MODE_11G */
3879 } else if (strcmp(val, "11b") == 0) {
3880 phymode = 2; /* IEEE80211_MODE_11B */
3881 } else if (strcmp(val, "11n") == 0 ||
3882 strcmp(val, "11nl") == 0 ||
3883 strcmp(val, "11nl(nabg)") == 0) {
3884 phymode = 22; /* IEEE80211_MODE_11AGN */
3885 } else if (strcmp(val, "11ng") == 0) {
3886 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
3887 } else if (strcmp(val, "AC") == 0 ||
3888 strcasecmp(val, "11AC") == 0) {
3889 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
3890 } else if (strcmp(val, "11na") == 0 ||
3891 strcasecmp(val, "11an") == 0) {
3892 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
3893 } else if (strcmp(val, "11ax") == 0) {
3894 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003895 } else {
3896 sigma_dut_print(dut, DUT_MSG_DEBUG,
3897 "Ignoring mode change for mode: %s",
3898 val);
3899 phymode = -1;
3900 }
3901 if (phymode != -1) {
3902 snprintf(buf, sizeof(buf),
3903 "iwpriv %s setphymode %d",
3904 intf, phymode);
3905 if (system(buf) != 0) {
3906 sigma_dut_print(dut, DUT_MSG_ERROR,
3907 "iwpriv setting of phymode failed");
3908 }
3909 }
3910 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003911 }
3912
3913 val = get_param(cmd, "wmm");
3914 if (val) {
3915 switch (get_driver_type()) {
3916 case DRIVER_ATHEROS:
3917 ath_sta_set_wmm(dut, intf, val);
3918 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003919 case DRIVER_WCN:
3920 wcn_sta_set_wmm(dut, intf, val);
3921 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003922 default:
3923 sigma_dut_print(dut, DUT_MSG_DEBUG,
3924 "Setting wmm not supported");
3925 break;
3926 }
3927 }
3928
3929 val = get_param(cmd, "Powersave");
3930 if (val) {
3931 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3932 if (wpa_command(get_station_ifname(),
3933 "P2P_SET ps 0") < 0)
3934 return -2;
3935 /* Make sure test modes are disabled */
3936 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3937 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3938 } else if (strcmp(val, "1") == 0 ||
3939 strcasecmp(val, "PSPoll") == 0 ||
3940 strcasecmp(val, "on") == 0) {
3941 /* Disable default power save mode */
3942 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3943 /* Enable PS-Poll test mode */
3944 if (wpa_command(get_station_ifname(),
3945 "P2P_SET ps 97") < 0 ||
3946 wpa_command(get_station_ifname(),
3947 "P2P_SET ps 99") < 0)
3948 return -2;
3949 } else if (strcmp(val, "2") == 0 ||
3950 strcasecmp(val, "Fast") == 0) {
3951 /* TODO */
3952 send_resp(dut, conn, SIGMA_ERROR,
3953 "ErrorCode,Powersave=Fast not supported");
3954 return 0;
3955 } else if (strcmp(val, "3") == 0 ||
3956 strcasecmp(val, "PSNonPoll") == 0) {
3957 /* Make sure test modes are disabled */
3958 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3959 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3960
3961 /* Enable default power save mode */
3962 if (wpa_command(get_station_ifname(),
3963 "P2P_SET ps 1") < 0)
3964 return -2;
3965 } else
3966 return -1;
3967 }
3968
3969 val = get_param(cmd, "NoAck");
3970 if (val) {
3971 switch (get_driver_type()) {
3972 case DRIVER_ATHEROS:
3973 ath_sta_set_noack(dut, intf, val);
3974 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003975#ifdef NL80211_SUPPORT
3976 case DRIVER_WCN:
3977 wcn_sta_set_noack(dut, intf, val);
3978 break;
3979#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003980 default:
3981 send_resp(dut, conn, SIGMA_ERROR,
3982 "ErrorCode,Setting NoAck not supported");
3983 return 0;
3984 }
3985 }
3986
3987 val = get_param(cmd, "IgnoreChswitchProhibit");
3988 if (val) {
3989 /* TODO: Enabled/disabled */
3990 if (strcasecmp(val, "Enabled") == 0) {
3991 send_resp(dut, conn, SIGMA_ERROR,
3992 "ErrorCode,Enabling IgnoreChswitchProhibit "
3993 "not supported");
3994 return 0;
3995 }
3996 }
3997
3998 val = get_param(cmd, "TDLS");
3999 if (val) {
4000 if (strcasecmp(val, "Disabled") == 0) {
4001 if (wpa_command(intf, "SET tdls_disabled 1")) {
4002 send_resp(dut, conn, SIGMA_ERROR,
4003 "ErrorCode,Failed to disable TDLS");
4004 return 0;
4005 }
4006 } else if (strcasecmp(val, "Enabled") == 0) {
4007 if (wpa_command(intf, "SET tdls_disabled 0")) {
4008 send_resp(dut, conn, SIGMA_ERROR,
4009 "ErrorCode,Failed to enable TDLS");
4010 return 0;
4011 }
4012 } else {
4013 send_resp(dut, conn, SIGMA_ERROR,
4014 "ErrorCode,Unsupported TDLS value");
4015 return 0;
4016 }
4017 }
4018
4019 val = get_param(cmd, "TDLSmode");
4020 if (val) {
4021 if (strcasecmp(val, "Default") == 0) {
4022 wpa_command(intf, "SET tdls_testing 0");
4023 } else if (strcasecmp(val, "APProhibit") == 0) {
4024 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4025 send_resp(dut, conn, SIGMA_ERROR,
4026 "ErrorCode,Failed to enable ignore "
4027 "APProhibit TDLS mode");
4028 return 0;
4029 }
4030 } else if (strcasecmp(val, "HiLoMac") == 0) {
4031 /* STA should respond with TDLS setup req for a TDLS
4032 * setup req */
4033 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4034 send_resp(dut, conn, SIGMA_ERROR,
4035 "ErrorCode,Failed to enable HiLoMac "
4036 "TDLS mode");
4037 return 0;
4038 }
4039 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4040 /*
4041 * Since all security modes are enabled by default when
4042 * Sigma control is used, there is no need to do
4043 * anything here.
4044 */
4045 } else if (strcasecmp(val, "ExistLink") == 0) {
4046 /*
4047 * Since we allow new TDLS Setup Request even if there
4048 * is an existing link, nothing needs to be done for
4049 * this.
4050 */
4051 } else {
4052 /* TODO:
4053 * ExistLink: STA should send TDLS setup req even if
4054 * direct link already exists
4055 */
4056 send_resp(dut, conn, SIGMA_ERROR,
4057 "ErrorCode,Unsupported TDLSmode value");
4058 return 0;
4059 }
4060 }
4061
4062 val = get_param(cmd, "FakePubKey");
4063 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4064 send_resp(dut, conn, SIGMA_ERROR,
4065 "ErrorCode,Failed to enable FakePubKey");
4066 return 0;
4067 }
4068
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004069#ifdef NL80211_SUPPORT
4070 val = get_param(cmd, "FrgmntSupport");
4071 if (val) {
4072 if (strcasecmp(val, "Enable") == 0) {
4073 if (sta_set_he_fragmentation(dut, intf,
4074 HE_FRAG_LEVEL1)) {
4075 send_resp(dut, conn, SIGMA_ERROR,
4076 "ErrorCode,Failed to enable HE Fragmentation");
4077 return 0;
4078 }
4079 } else if (strcasecmp(val, "Disable") == 0) {
4080 if (sta_set_he_fragmentation(dut, intf,
4081 HE_FRAG_DISABLE)) {
4082 send_resp(dut, conn, SIGMA_ERROR,
4083 "ErrorCode,Failed to disable HE Fragmentation");
4084 return 0;
4085 }
4086 }
4087 }
4088#endif /* NL80211_SUPPORT */
4089
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004090 return 1;
4091}
4092
4093
4094static const char * ath_get_radio_name(const char *radio_name)
4095{
4096 if (radio_name == NULL)
4097 return "wifi0";
4098 if (strcmp(radio_name, "wifi1") == 0)
4099 return "wifi1";
4100 if (strcmp(radio_name, "wifi2") == 0)
4101 return "wifi2";
4102 return "wifi0";
4103}
4104
4105
4106static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4107 const char *val)
4108{
4109 char buf[60];
4110 unsigned int vht_mcsmap = 0;
4111 int txchainmask = 0;
4112 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4113
4114 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4115 if (dut->testbed_flag_txsp == 1) {
4116 vht_mcsmap = 0xfffc;
4117 dut->testbed_flag_txsp = 0;
4118 } else {
4119 vht_mcsmap = 0xfffe;
4120 }
4121 txchainmask = 1;
4122 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4123 if (dut->testbed_flag_txsp == 1) {
4124 vht_mcsmap = 0xfff0;
4125 dut->testbed_flag_txsp = 0;
4126 } else {
4127 vht_mcsmap = 0xfffa;
4128 }
4129 txchainmask = 3;
4130 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4131 if (dut->testbed_flag_txsp == 1) {
4132 vht_mcsmap = 0xffc0;
4133 dut->testbed_flag_txsp = 0;
4134 } else {
4135 vht_mcsmap = 0xffea;
4136 }
4137 txchainmask = 7;
4138 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4139 if (dut->testbed_flag_txsp == 1) {
4140 vht_mcsmap = 0xff00;
4141 dut->testbed_flag_txsp = 0;
4142 } else {
4143 vht_mcsmap = 0xffaa;
4144 }
4145 txchainmask = 15;
4146 } else {
4147 if (dut->testbed_flag_txsp == 1) {
4148 vht_mcsmap = 0xffc0;
4149 dut->testbed_flag_txsp = 0;
4150 } else {
4151 vht_mcsmap = 0xffea;
4152 }
4153 }
4154
4155 if (txchainmask) {
4156 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4157 basedev, txchainmask);
4158 if (system(buf) != 0) {
4159 sigma_dut_print(dut, DUT_MSG_ERROR,
4160 "iwpriv txchainmask failed");
4161 }
4162 }
4163
4164 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4165 intf, vht_mcsmap);
4166 if (system(buf) != 0) {
4167 sigma_dut_print(dut, DUT_MSG_ERROR,
4168 "iwpriv %s vht_mcsmap 0x%04x failed",
4169 intf, vht_mcsmap);
4170 }
4171}
4172
4173
4174static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4175 const char *val)
4176{
4177 char buf[60];
4178 unsigned int vht_mcsmap = 0;
4179 int rxchainmask = 0;
4180 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4181
4182 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4183 if (dut->testbed_flag_rxsp == 1) {
4184 vht_mcsmap = 0xfffc;
4185 dut->testbed_flag_rxsp = 0;
4186 } else {
4187 vht_mcsmap = 0xfffe;
4188 }
4189 rxchainmask = 1;
4190 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4191 if (dut->testbed_flag_rxsp == 1) {
4192 vht_mcsmap = 0xfff0;
4193 dut->testbed_flag_rxsp = 0;
4194 } else {
4195 vht_mcsmap = 0xfffa;
4196 }
4197 rxchainmask = 3;
4198 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4199 if (dut->testbed_flag_rxsp == 1) {
4200 vht_mcsmap = 0xffc0;
4201 dut->testbed_flag_rxsp = 0;
4202 } else {
4203 vht_mcsmap = 0xffea;
4204 }
4205 rxchainmask = 7;
4206 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4207 if (dut->testbed_flag_rxsp == 1) {
4208 vht_mcsmap = 0xff00;
4209 dut->testbed_flag_rxsp = 0;
4210 } else {
4211 vht_mcsmap = 0xffaa;
4212 }
4213 rxchainmask = 15;
4214 } else {
4215 if (dut->testbed_flag_rxsp == 1) {
4216 vht_mcsmap = 0xffc0;
4217 dut->testbed_flag_rxsp = 0;
4218 } else {
4219 vht_mcsmap = 0xffea;
4220 }
4221 }
4222
4223 if (rxchainmask) {
4224 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4225 basedev, rxchainmask);
4226 if (system(buf) != 0) {
4227 sigma_dut_print(dut, DUT_MSG_ERROR,
4228 "iwpriv rxchainmask failed");
4229 }
4230 }
4231
4232 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4233 intf, vht_mcsmap);
4234 if (system(buf) != 0) {
4235 sigma_dut_print(dut, DUT_MSG_ERROR,
4236 "iwpriv %s vht_mcsmap 0x%04x",
4237 intf, vht_mcsmap);
4238 }
4239}
4240
4241
4242void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4243{
4244 if (strcasecmp(val, "enable") == 0) {
4245 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4246 != 0) {
4247 sigma_dut_print(dut, DUT_MSG_ERROR,
4248 "Disable BB_VHTSIGB_CRC_CALC failed");
4249 }
4250
4251 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4252 != 0) {
4253 sigma_dut_print(dut, DUT_MSG_ERROR,
4254 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4255 }
4256 } else {
4257 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4258 != 0) {
4259 sigma_dut_print(dut, DUT_MSG_ERROR,
4260 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4261 }
4262
4263 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4264 != 0) {
4265 sigma_dut_print(dut, DUT_MSG_ERROR,
4266 "Enable BB_VHTSIGB_CRC_CALC failed");
4267 }
4268 }
4269}
4270
4271
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004272static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4273 const char *val)
4274{
4275 char buf[60];
4276
4277 if (strcmp(val, "20") == 0) {
4278 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4279 dut->chwidth = 0;
4280 } else if (strcmp(val, "40") == 0) {
4281 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4282 dut->chwidth = 1;
4283 } else if (strcmp(val, "80") == 0) {
4284 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4285 dut->chwidth = 2;
4286 } else if (strcmp(val, "Auto") == 0) {
4287 buf[0] = '\0';
4288 } else {
4289 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4290 val);
4291 return -1;
4292 }
4293
4294 if (buf[0] != '\0' && system(buf) != 0) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4296 return -1;
4297 }
4298
4299 return 0;
4300}
4301
4302
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004303static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4304 const char *intf, int addbareject)
4305{
4306#ifdef NL80211_SUPPORT
4307 struct nl_msg *msg;
4308 int ret = 0;
4309 struct nlattr *params;
4310 int ifindex;
4311
4312 ifindex = if_nametoindex(intf);
4313 if (ifindex == 0) {
4314 sigma_dut_print(dut, DUT_MSG_ERROR,
4315 "%s: Index for interface %s failed",
4316 __func__, intf);
4317 return -1;
4318 }
4319
4320 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4321 NL80211_CMD_VENDOR)) ||
4322 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4323 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4324 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4325 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4326 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4327 nla_put_u8(msg,
4328 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4329 !addbareject)) {
4330 sigma_dut_print(dut, DUT_MSG_ERROR,
4331 "%s: err in adding vendor_cmd and vendor_data",
4332 __func__);
4333 nlmsg_free(msg);
4334 return -1;
4335 }
4336 nla_nest_end(msg, params);
4337
4338 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4339 if (ret) {
4340 sigma_dut_print(dut, DUT_MSG_ERROR,
4341 "%s: err in send_and_recv_msgs, ret=%d",
4342 __func__, ret);
4343 }
4344 return ret;
4345#else /* NL80211_SUPPORT */
4346 sigma_dut_print(dut, DUT_MSG_ERROR,
4347 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4348 return -1;
4349#endif /* NL80211_SUPPORT */
4350}
4351
4352
4353static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4354 int addbareject)
4355{
4356 int ret;
4357
4358 switch (get_driver_type()) {
4359 case DRIVER_WCN:
4360 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4361 if (ret) {
4362 sigma_dut_print(dut, DUT_MSG_ERROR,
4363 "nlvendor_sta_set_addba_reject failed, ret:%d",
4364 ret);
4365 return ret;
4366 }
4367 break;
4368 default:
4369 sigma_dut_print(dut, DUT_MSG_ERROR,
4370 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4371 ret = -1;
4372 break;
4373 }
4374
4375 return ret;
4376}
4377
4378
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004379static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4380 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004381{
4382#ifdef NL80211_SUPPORT
4383 struct nl_msg *msg;
4384 int ret = 0;
4385 struct nlattr *params;
4386 int ifindex;
4387
4388 ifindex = if_nametoindex(intf);
4389 if (ifindex == 0) {
4390 sigma_dut_print(dut, DUT_MSG_ERROR,
4391 "%s: Index for interface %s failed",
4392 __func__, intf);
4393 return -1;
4394 }
4395
4396 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4397 NL80211_CMD_VENDOR)) ||
4398 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4399 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4400 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4401 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4402 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4403 nla_put_u8(msg,
4404 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004405 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004406 sigma_dut_print(dut, DUT_MSG_ERROR,
4407 "%s: err in adding vendor_cmd and vendor_data",
4408 __func__);
4409 nlmsg_free(msg);
4410 return -1;
4411 }
4412 nla_nest_end(msg, params);
4413
4414 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4415 if (ret) {
4416 sigma_dut_print(dut, DUT_MSG_ERROR,
4417 "%s: err in send_and_recv_msgs, ret=%d",
4418 __func__, ret);
4419 }
4420 return ret;
4421#else /* NL80211_SUPPORT */
4422 sigma_dut_print(dut, DUT_MSG_ERROR,
4423 "Disable addba not possible without NL80211_SUPPORT defined");
4424 return -1;
4425#endif /* NL80211_SUPPORT */
4426}
4427
4428
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004429static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4430 struct sigma_conn *conn,
4431 struct sigma_cmd *cmd)
4432{
4433 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004434 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 char buf[30];
4436
4437 val = get_param(cmd, "40_INTOLERANT");
4438 if (val) {
4439 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4440 /* TODO: iwpriv ht40intol through wpa_supplicant */
4441 send_resp(dut, conn, SIGMA_ERROR,
4442 "ErrorCode,40_INTOLERANT not supported");
4443 return 0;
4444 }
4445 }
4446
4447 val = get_param(cmd, "ADDBA_REJECT");
4448 if (val) {
4449 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4450 /* reject any ADDBA with status "decline" */
4451 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004452 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004453 } else {
4454 /* accept ADDBA */
4455 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004456 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004457 }
4458 }
4459
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004460 if (addbareject >= 0 &&
4461 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4462 send_resp(dut, conn, SIGMA_ERROR,
4463 "ErrorCode,set addba_reject failed");
4464 return 0;
4465 }
4466
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004467 val = get_param(cmd, "AMPDU");
4468 if (val) {
4469 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4470 /* enable AMPDU Aggregation */
4471 if (ampdu == 0) {
4472 send_resp(dut, conn, SIGMA_ERROR,
4473 "ErrorCode,Mismatch in "
4474 "addba_reject/ampdu - "
4475 "not supported");
4476 return 0;
4477 }
4478 ampdu = 1;
4479 } else {
4480 /* disable AMPDU Aggregation */
4481 if (ampdu == 1) {
4482 send_resp(dut, conn, SIGMA_ERROR,
4483 "ErrorCode,Mismatch in "
4484 "addba_reject/ampdu - "
4485 "not supported");
4486 return 0;
4487 }
4488 ampdu = 0;
4489 }
4490 }
4491
4492 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004493 int ret;
4494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004495 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4496 ampdu ? "Enabling" : "Disabling");
4497 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004498 if (wpa_command(intf, buf) < 0 &&
4499 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004500 send_resp(dut, conn, SIGMA_ERROR,
4501 "ErrorCode,set aggr failed");
4502 return 0;
4503 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004504
4505 if (ampdu == 0) {
4506 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004507 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004508 if (ret) {
4509 sigma_dut_print(dut, DUT_MSG_ERROR,
4510 "Failed to disable addba, ret:%d",
4511 ret);
4512 }
4513 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004514 }
4515
4516 val = get_param(cmd, "AMSDU");
4517 if (val) {
4518 switch (get_driver_type()) {
4519 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004520 case DRIVER_WCN:
4521 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004522 break;
4523 default:
4524 if (strcmp(val, "1") == 0 ||
4525 strcasecmp(val, "Enable") == 0) {
4526 /* Enable AMSDU Aggregation */
4527 send_resp(dut, conn, SIGMA_ERROR,
4528 "ErrorCode,AMSDU aggregation not supported");
4529 return 0;
4530 }
4531 break;
4532 }
4533 }
4534
4535 val = get_param(cmd, "STBC_RX");
4536 if (val) {
4537 switch (get_driver_type()) {
4538 case DRIVER_ATHEROS:
4539 ath_sta_set_stbc(dut, intf, val);
4540 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304541 case DRIVER_WCN:
4542 wcn_sta_set_stbc(dut, intf, val);
4543 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004544 default:
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,STBC_RX not supported");
4547 return 0;
4548 }
4549 }
4550
4551 val = get_param(cmd, "WIDTH");
4552 if (val) {
4553 switch (get_driver_type()) {
4554 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004555 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004556 send_resp(dut, conn, SIGMA_ERROR,
4557 "ErrorCode,Failed to set WIDTH");
4558 return 0;
4559 }
4560 break;
4561 case DRIVER_ATHEROS:
4562 if (ath_set_width(dut, conn, intf, val) < 0)
4563 return 0;
4564 break;
4565 default:
4566 sigma_dut_print(dut, DUT_MSG_ERROR,
4567 "Setting WIDTH not supported");
4568 break;
4569 }
4570 }
4571
4572 val = get_param(cmd, "SMPS");
4573 if (val) {
4574 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4575 send_resp(dut, conn, SIGMA_ERROR,
4576 "ErrorCode,SMPS not supported");
4577 return 0;
4578 }
4579
4580 val = get_param(cmd, "TXSP_STREAM");
4581 if (val) {
4582 switch (get_driver_type()) {
4583 case DRIVER_WCN:
4584 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4585 send_resp(dut, conn, SIGMA_ERROR,
4586 "ErrorCode,Failed to set TXSP_STREAM");
4587 return 0;
4588 }
4589 break;
4590 case DRIVER_ATHEROS:
4591 ath_sta_set_txsp_stream(dut, intf, val);
4592 break;
4593 default:
4594 sigma_dut_print(dut, DUT_MSG_ERROR,
4595 "Setting TXSP_STREAM not supported");
4596 break;
4597 }
4598 }
4599
4600 val = get_param(cmd, "RXSP_STREAM");
4601 if (val) {
4602 switch (get_driver_type()) {
4603 case DRIVER_WCN:
4604 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4605 send_resp(dut, conn, SIGMA_ERROR,
4606 "ErrorCode,Failed to set RXSP_STREAM");
4607 return 0;
4608 }
4609 break;
4610 case DRIVER_ATHEROS:
4611 ath_sta_set_rxsp_stream(dut, intf, val);
4612 break;
4613 default:
4614 sigma_dut_print(dut, DUT_MSG_ERROR,
4615 "Setting RXSP_STREAM not supported");
4616 break;
4617 }
4618 }
4619
4620 val = get_param(cmd, "DYN_BW_SGNL");
4621 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004622 switch (get_driver_type()) {
4623 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004624 if (strcasecmp(val, "enable") == 0) {
4625 snprintf(buf, sizeof(buf),
4626 "iwpriv %s cwmenable 1", intf);
4627 if (system(buf) != 0) {
4628 sigma_dut_print(dut, DUT_MSG_ERROR,
4629 "iwpriv cwmenable 1 failed");
4630 return 0;
4631 }
4632 } else if (strcasecmp(val, "disable") == 0) {
4633 snprintf(buf, sizeof(buf),
4634 "iwpriv %s cwmenable 0", intf);
4635 if (system(buf) != 0) {
4636 sigma_dut_print(dut, DUT_MSG_ERROR,
4637 "iwpriv cwmenable 0 failed");
4638 return 0;
4639 }
4640 } else {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "Unsupported DYN_BW_SGL");
4643 }
4644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004645 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4646 if (system(buf) != 0) {
4647 sigma_dut_print(dut, DUT_MSG_ERROR,
4648 "Failed to set cts_cbw in DYN_BW_SGNL");
4649 return 0;
4650 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004651 break;
4652 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004653 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004654 ath_config_dyn_bw_sig(dut, intf, val);
4655 break;
4656 default:
4657 sigma_dut_print(dut, DUT_MSG_ERROR,
4658 "Failed to set DYN_BW_SGNL");
4659 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004660 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004661 }
4662
4663 val = get_param(cmd, "RTS_FORCE");
4664 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004665 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004666 if (strcasecmp(val, "Enable") == 0) {
4667 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004668 if (system(buf) != 0) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "Failed to set RTS_FORCE 64");
4671 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004672 snprintf(buf, sizeof(buf),
4673 "wifitool %s beeliner_fw_test 100 1", intf);
4674 if (system(buf) != 0) {
4675 sigma_dut_print(dut, DUT_MSG_ERROR,
4676 "wifitool beeliner_fw_test 100 1 failed");
4677 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004678 } else if (strcasecmp(val, "Disable") == 0) {
4679 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4680 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004681 if (system(buf) != 0) {
4682 sigma_dut_print(dut, DUT_MSG_ERROR,
4683 "Failed to set RTS_FORCE 2347");
4684 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004685 } else {
4686 send_resp(dut, conn, SIGMA_ERROR,
4687 "ErrorCode,RTS_FORCE value not supported");
4688 return 0;
4689 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004690 }
4691
4692 val = get_param(cmd, "CTS_WIDTH");
4693 if (val) {
4694 switch (get_driver_type()) {
4695 case DRIVER_WCN:
4696 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4697 send_resp(dut, conn, SIGMA_ERROR,
4698 "ErrorCode,Failed to set CTS_WIDTH");
4699 return 0;
4700 }
4701 break;
4702 case DRIVER_ATHEROS:
4703 ath_set_cts_width(dut, intf, val);
4704 break;
4705 default:
4706 sigma_dut_print(dut, DUT_MSG_ERROR,
4707 "Setting CTS_WIDTH not supported");
4708 break;
4709 }
4710 }
4711
4712 val = get_param(cmd, "BW_SGNL");
4713 if (val) {
4714 if (strcasecmp(val, "Enable") == 0) {
4715 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4716 intf);
4717 } else if (strcasecmp(val, "Disable") == 0) {
4718 /* TODO: Disable */
4719 buf[0] = '\0';
4720 } else {
4721 send_resp(dut, conn, SIGMA_ERROR,
4722 "ErrorCode,BW_SGNL value not supported");
4723 return 0;
4724 }
4725
4726 if (buf[0] != '\0' && system(buf) != 0) {
4727 sigma_dut_print(dut, DUT_MSG_ERROR,
4728 "Failed to set BW_SGNL");
4729 }
4730 }
4731
4732 val = get_param(cmd, "Band");
4733 if (val) {
4734 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4735 /* STA supports all bands by default */
4736 } else {
4737 send_resp(dut, conn, SIGMA_ERROR,
4738 "ErrorCode,Unsupported Band");
4739 return 0;
4740 }
4741 }
4742
4743 val = get_param(cmd, "zero_crc");
4744 if (val) {
4745 switch (get_driver_type()) {
4746 case DRIVER_ATHEROS:
4747 ath_set_zero_crc(dut, val);
4748 break;
4749 default:
4750 break;
4751 }
4752 }
4753
4754 return 1;
4755}
4756
4757
4758static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4759 struct sigma_cmd *cmd)
4760{
4761 const char *val;
4762 char buf[100];
4763
4764 val = get_param(cmd, "MSDUSize");
4765 if (val) {
4766 int mtu;
4767
4768 dut->amsdu_size = atoi(val);
4769 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4770 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4771 sigma_dut_print(dut, DUT_MSG_ERROR,
4772 "MSDUSize %d is above max %d or below min %d",
4773 dut->amsdu_size,
4774 IEEE80211_MAX_DATA_LEN_DMG,
4775 IEEE80211_SNAP_LEN_DMG);
4776 dut->amsdu_size = 0;
4777 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4778 }
4779
4780 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4781 sigma_dut_print(dut, DUT_MSG_DEBUG,
4782 "Setting amsdu_size to %d", mtu);
4783 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4784 get_station_ifname(), mtu);
4785
4786 if (system(buf) != 0) {
4787 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4788 buf);
4789 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4790 }
4791 }
4792
4793 val = get_param(cmd, "BAckRcvBuf");
4794 if (val) {
4795 dut->back_rcv_buf = atoi(val);
4796 if (dut->back_rcv_buf == 0) {
4797 sigma_dut_print(dut, DUT_MSG_ERROR,
4798 "Failed to convert %s or value is 0",
4799 val);
4800 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4801 }
4802
4803 sigma_dut_print(dut, DUT_MSG_DEBUG,
4804 "Setting BAckRcvBuf to %s", val);
4805 }
4806
4807 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4808}
4809
4810
4811static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4812 struct sigma_cmd *cmd)
4813{
4814 int net_id;
4815 char *ifname;
4816 const char *val;
4817 char buf[100];
4818
4819 dut->mode = SIGMA_MODE_STATION;
4820 ifname = get_main_ifname();
4821 if (wpa_command(ifname, "PING") != 0) {
4822 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4823 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4824 }
4825
4826 wpa_command(ifname, "FLUSH");
4827 net_id = add_network_common(dut, conn, ifname, cmd);
4828 if (net_id < 0) {
4829 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4830 return net_id;
4831 }
4832
4833 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4834 if (set_network(ifname, net_id, "mode", "2") < 0) {
4835 sigma_dut_print(dut, DUT_MSG_ERROR,
4836 "Failed to set supplicant network mode");
4837 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4838 }
4839
4840 sigma_dut_print(dut, DUT_MSG_DEBUG,
4841 "Supplicant set network with mode 2");
4842
4843 val = get_param(cmd, "Security");
4844 if (val && strcasecmp(val, "OPEN") == 0) {
4845 dut->ap_key_mgmt = AP_OPEN;
4846 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4847 sigma_dut_print(dut, DUT_MSG_ERROR,
4848 "Failed to set supplicant to %s security",
4849 val);
4850 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4851 }
4852 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4853 dut->ap_key_mgmt = AP_WPA2_PSK;
4854 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4855 sigma_dut_print(dut, DUT_MSG_ERROR,
4856 "Failed to set supplicant to %s security",
4857 val);
4858 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4859 }
4860
4861 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4862 sigma_dut_print(dut, DUT_MSG_ERROR,
4863 "Failed to set supplicant to proto RSN");
4864 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4865 }
4866 } else if (val) {
4867 sigma_dut_print(dut, DUT_MSG_ERROR,
4868 "Requested Security %s is not supported on 60GHz",
4869 val);
4870 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4871 }
4872
4873 val = get_param(cmd, "Encrypt");
4874 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4875 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4876 sigma_dut_print(dut, DUT_MSG_ERROR,
4877 "Failed to set supplicant to pairwise GCMP");
4878 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4879 }
4880 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4881 sigma_dut_print(dut, DUT_MSG_ERROR,
4882 "Failed to set supplicant to group GCMP");
4883 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4884 }
4885 } else if (val) {
4886 sigma_dut_print(dut, DUT_MSG_ERROR,
4887 "Requested Encrypt %s is not supported on 60 GHz",
4888 val);
4889 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4890 }
4891
4892 val = get_param(cmd, "PSK");
4893 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4894 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4895 val);
4896 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4897 }
4898
4899 /* Convert 60G channel to freq */
4900 switch (dut->ap_channel) {
4901 case 1:
4902 val = "58320";
4903 break;
4904 case 2:
4905 val = "60480";
4906 break;
4907 case 3:
4908 val = "62640";
4909 break;
4910 default:
4911 sigma_dut_print(dut, DUT_MSG_ERROR,
4912 "Failed to configure channel %d. Not supported",
4913 dut->ap_channel);
4914 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4915 }
4916
4917 if (set_network(ifname, net_id, "frequency", val) < 0) {
4918 sigma_dut_print(dut, DUT_MSG_ERROR,
4919 "Failed to set supplicant network frequency");
4920 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4921 }
4922
4923 sigma_dut_print(dut, DUT_MSG_DEBUG,
4924 "Supplicant set network with frequency");
4925
4926 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4927 if (wpa_command(ifname, buf) < 0) {
4928 sigma_dut_print(dut, DUT_MSG_INFO,
4929 "Failed to select network id %d on %s",
4930 net_id, ifname);
4931 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4932 }
4933
4934 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4935
4936 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4937}
4938
4939
Lior David67543f52017-01-03 19:04:22 +02004940static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4941{
4942 char buf[128], fname[128];
4943 FILE *f;
4944
4945 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4946 sigma_dut_print(dut, DUT_MSG_ERROR,
4947 "failed to get wil6210 debugfs dir");
4948 return -1;
4949 }
4950
4951 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4952 f = fopen(fname, "w");
4953 if (!f) {
4954 sigma_dut_print(dut, DUT_MSG_ERROR,
4955 "failed to open: %s", fname);
4956 return -1;
4957 }
4958
4959 fprintf(f, "%d\n", abft_len);
4960 fclose(f);
4961
4962 return 0;
4963}
4964
4965
4966static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4967 int abft_len)
4968{
4969 switch (get_driver_type()) {
4970 case DRIVER_WIL6210:
4971 return wil6210_set_abft_len(dut, abft_len);
4972 default:
4973 sigma_dut_print(dut, DUT_MSG_ERROR,
4974 "set abft_len not supported");
4975 return -1;
4976 }
4977}
4978
4979
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004980static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4981 struct sigma_cmd *cmd)
4982{
4983 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004984 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004985
4986 if (dut->dev_role != DEVROLE_PCP) {
4987 send_resp(dut, conn, SIGMA_INVALID,
4988 "ErrorCode,Invalid DevRole");
4989 return 0;
4990 }
4991
4992 val = get_param(cmd, "SSID");
4993 if (val) {
4994 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4995 send_resp(dut, conn, SIGMA_INVALID,
4996 "ErrorCode,Invalid SSID");
4997 return -1;
4998 }
4999
Peng Xub8fc5cc2017-05-10 17:27:28 -07005000 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005001 }
5002
5003 val = get_param(cmd, "CHANNEL");
5004 if (val) {
5005 const char *pos;
5006
5007 dut->ap_channel = atoi(val);
5008 pos = strchr(val, ';');
5009 if (pos) {
5010 pos++;
5011 dut->ap_channel_1 = atoi(pos);
5012 }
5013 }
5014
5015 switch (dut->ap_channel) {
5016 case 1:
5017 case 2:
5018 case 3:
5019 break;
5020 default:
5021 sigma_dut_print(dut, DUT_MSG_ERROR,
5022 "Channel %d is not supported", dut->ap_channel);
5023 send_resp(dut, conn, SIGMA_ERROR,
5024 "Requested channel is not supported");
5025 return -1;
5026 }
5027
5028 val = get_param(cmd, "BCNINT");
5029 if (val)
5030 dut->ap_bcnint = atoi(val);
5031
5032
5033 val = get_param(cmd, "ExtSchIE");
5034 if (val) {
5035 send_resp(dut, conn, SIGMA_ERROR,
5036 "ErrorCode,ExtSchIE is not supported yet");
5037 return -1;
5038 }
5039
5040 val = get_param(cmd, "AllocType");
5041 if (val) {
5042 send_resp(dut, conn, SIGMA_ERROR,
5043 "ErrorCode,AllocType is not supported yet");
5044 return -1;
5045 }
5046
5047 val = get_param(cmd, "PercentBI");
5048 if (val) {
5049 send_resp(dut, conn, SIGMA_ERROR,
5050 "ErrorCode,PercentBI is not supported yet");
5051 return -1;
5052 }
5053
5054 val = get_param(cmd, "CBAPOnly");
5055 if (val) {
5056 send_resp(dut, conn, SIGMA_ERROR,
5057 "ErrorCode,CBAPOnly is not supported yet");
5058 return -1;
5059 }
5060
5061 val = get_param(cmd, "AMPDU");
5062 if (val) {
5063 if (strcasecmp(val, "Enable") == 0)
5064 dut->ap_ampdu = 1;
5065 else if (strcasecmp(val, "Disable") == 0)
5066 dut->ap_ampdu = 2;
5067 else {
5068 send_resp(dut, conn, SIGMA_ERROR,
5069 "ErrorCode,AMPDU value is not Enable nor Disabled");
5070 return -1;
5071 }
5072 }
5073
5074 val = get_param(cmd, "AMSDU");
5075 if (val) {
5076 if (strcasecmp(val, "Enable") == 0)
5077 dut->ap_amsdu = 1;
5078 else if (strcasecmp(val, "Disable") == 0)
5079 dut->ap_amsdu = 2;
5080 }
5081
5082 val = get_param(cmd, "NumMSDU");
5083 if (val) {
5084 send_resp(dut, conn, SIGMA_ERROR,
5085 "ErrorCode, NumMSDU is not supported yet");
5086 return -1;
5087 }
5088
5089 val = get_param(cmd, "ABFTLRang");
5090 if (val) {
5091 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005092 "ABFTLRang parameter %s", val);
5093 if (strcmp(val, "Gt1") == 0)
5094 abft_len = 2; /* 2 slots in this case */
5095 }
5096
5097 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5098 send_resp(dut, conn, SIGMA_ERROR,
5099 "ErrorCode, Can't set ABFT length");
5100 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005101 }
5102
5103 if (sta_pcp_start(dut, conn, cmd) < 0) {
5104 send_resp(dut, conn, SIGMA_ERROR,
5105 "ErrorCode, Can't start PCP role");
5106 return -1;
5107 }
5108
5109 return sta_set_60g_common(dut, conn, cmd);
5110}
5111
5112
5113static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5114 struct sigma_cmd *cmd)
5115{
5116 const char *val = get_param(cmd, "DiscoveryMode");
5117
5118 if (dut->dev_role != DEVROLE_STA) {
5119 send_resp(dut, conn, SIGMA_INVALID,
5120 "ErrorCode,Invalid DevRole");
5121 return 0;
5122 }
5123
5124 if (val) {
5125 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5126 /* Ignore Discovery mode till Driver expose API. */
5127#if 0
5128 if (strcasecmp(val, "1") == 0) {
5129 send_resp(dut, conn, SIGMA_INVALID,
5130 "ErrorCode,DiscoveryMode 1 not supported");
5131 return 0;
5132 }
5133
5134 if (strcasecmp(val, "0") == 0) {
5135 /* OK */
5136 } else {
5137 send_resp(dut, conn, SIGMA_INVALID,
5138 "ErrorCode,DiscoveryMode not supported");
5139 return 0;
5140 }
5141#endif
5142 }
5143
5144 if (start_sta_mode(dut) != 0)
5145 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5146 return sta_set_60g_common(dut, conn, cmd);
5147}
5148
5149
5150static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5151 struct sigma_cmd *cmd)
5152{
5153 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005154 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305155
Jouni Malinened77e672018-01-10 16:45:13 +02005156 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005157 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005158 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305159 wpa_command(intf, "DISCONNECT");
5160 return 1;
5161 }
5162
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005163 disconnect_station(dut);
5164 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5165 * due to cached results. */
5166 wpa_command(intf, "SET ignore_old_scan_res 1");
5167 wpa_command(intf, "BSS_FLUSH");
5168 return 1;
5169}
5170
5171
5172static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5173 struct sigma_cmd *cmd)
5174{
5175 const char *intf = get_param(cmd, "Interface");
5176 const char *bssid = get_param(cmd, "bssid");
5177 const char *val = get_param(cmd, "CHANNEL");
5178 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305179 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305180 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181 int res;
5182 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305183 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305184 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005185
5186 if (bssid == NULL) {
5187 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5188 "argument");
5189 return 0;
5190 }
5191
5192 if (val)
5193 chan = atoi(val);
5194
5195 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5196 /* The current network may be from sta_associate or
5197 * sta_hs2_associate
5198 */
5199 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5200 0 ||
5201 set_network(intf, 0, "bssid", bssid) < 0)
5202 return -2;
5203 }
5204
5205 ctrl = open_wpa_mon(intf);
5206 if (ctrl == NULL) {
5207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5208 "wpa_supplicant monitor connection");
5209 return -1;
5210 }
5211
Sunil Duttd30ce092018-01-11 23:56:29 +05305212 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5213 sizeof(result)) < 0 ||
5214 strncmp(result, "COMPLETED", 9) != 0) {
5215 sigma_dut_print(dut, DUT_MSG_DEBUG,
5216 "sta_reassoc: Not connected");
5217 fastreassoc = 0;
5218 }
5219
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305220 if (dut->rsne_override) {
5221#ifdef NL80211_SUPPORT
5222 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5223 sta_config_rsnie(dut, 1);
5224 dut->config_rsnie = 1;
5225 }
5226#endif /* NL80211_SUPPORT */
5227 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5228 dut->rsne_override);
5229 if (wpa_command(intf, buf) < 0) {
5230 send_resp(dut, conn, SIGMA_ERROR,
5231 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5232 return 0;
5233 }
5234 }
5235
Sunil Duttd30ce092018-01-11 23:56:29 +05305236 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005237#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305238 if (chan) {
5239 unsigned int freq;
5240
5241 freq = channel_to_freq(chan);
5242 if (!freq) {
5243 sigma_dut_print(dut, DUT_MSG_ERROR,
5244 "Invalid channel number provided: %d",
5245 chan);
5246 send_resp(dut, conn, SIGMA_INVALID,
5247 "ErrorCode,Invalid channel number");
5248 goto close_mon_conn;
5249 }
5250 res = snprintf(buf, sizeof(buf),
5251 "SCAN TYPE=ONLY freq=%d", freq);
5252 } else {
5253 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5254 }
5255 if (res < 0 || res >= (int) sizeof(buf)) {
5256 send_resp(dut, conn, SIGMA_ERROR,
5257 "ErrorCode,snprintf failed");
5258 goto close_mon_conn;
5259 }
5260 if (wpa_command(intf, buf) < 0) {
5261 sigma_dut_print(dut, DUT_MSG_INFO,
5262 "Failed to start scan");
5263 send_resp(dut, conn, SIGMA_ERROR,
5264 "ErrorCode,scan failed");
5265 goto close_mon_conn;
5266 }
5267
5268 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5269 buf, sizeof(buf));
5270 if (res < 0) {
5271 sigma_dut_print(dut, DUT_MSG_INFO,
5272 "Scan did not complete");
5273 send_resp(dut, conn, SIGMA_ERROR,
5274 "ErrorCode,scan did not complete");
5275 goto close_mon_conn;
5276 }
5277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005278 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5279 < 0) {
5280 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5281 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305282 status = -2;
5283 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005284 }
5285 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5286 bssid, chan);
5287 if (res > 0 && res < (int) sizeof(buf))
5288 res = wpa_command(intf, buf);
5289
5290 if (res < 0 || res >= (int) sizeof(buf)) {
5291 send_resp(dut, conn, SIGMA_ERROR,
5292 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305293 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005294 }
5295#else /* ANDROID */
5296 sigma_dut_print(dut, DUT_MSG_DEBUG,
5297 "Reassoc using iwpriv - skip chan=%d info",
5298 chan);
5299 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5300 if (system(buf) != 0) {
5301 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305302 status = -2;
5303 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005304 }
5305#endif /* ANDROID */
5306 sigma_dut_print(dut, DUT_MSG_INFO,
5307 "sta_reassoc: Run %s successful", buf);
5308 } else if (wpa_command(intf, "REASSOCIATE")) {
5309 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5310 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305311 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005312 }
5313
5314 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5315 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305316 if (res < 0) {
5317 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5318 status = -1;
5319 goto close_mon_conn;
5320 }
5321 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005322
Ashwini Patil467efef2017-05-25 12:18:27 +05305323close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005324 wpa_ctrl_detach(ctrl);
5325 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305326 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005327}
5328
5329
5330static void hs2_clear_credentials(const char *intf)
5331{
5332 wpa_command(intf, "REMOVE_CRED all");
5333}
5334
5335
Lior Davidcc88b562017-01-03 18:52:09 +02005336#ifdef __linux__
5337static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5338 unsigned int *aid)
5339{
Lior David0fe101e2017-03-09 16:09:50 +02005340 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005341
Lior David0fe101e2017-03-09 16:09:50 +02005342 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005343}
5344#endif /* __linux__ */
5345
5346
5347static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5348 unsigned int *aid)
5349{
5350 switch (get_driver_type()) {
5351#ifdef __linux__
5352 case DRIVER_WIL6210:
5353 return wil6210_get_aid(dut, bssid, aid);
5354#endif /* __linux__ */
5355 default:
5356 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5357 return -1;
5358 }
5359}
5360
5361
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005362static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5363 struct sigma_cmd *cmd)
5364{
5365 char buf[MAX_CMD_LEN];
5366 char bss_list[MAX_CMD_LEN];
5367 const char *parameter = get_param(cmd, "Parameter");
5368
5369 if (parameter == NULL)
5370 return -1;
5371
Lior Davidcc88b562017-01-03 18:52:09 +02005372 if (strcasecmp(parameter, "AID") == 0) {
5373 unsigned int aid = 0;
5374 char bssid[20];
5375
5376 if (get_wpa_status(get_station_ifname(), "bssid",
5377 bssid, sizeof(bssid)) < 0) {
5378 sigma_dut_print(dut, DUT_MSG_ERROR,
5379 "could not get bssid");
5380 return -2;
5381 }
5382
5383 if (sta_get_aid_60g(dut, bssid, &aid))
5384 return -2;
5385
5386 snprintf(buf, sizeof(buf), "aid,%d", aid);
5387 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5388 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5389 return 0;
5390 }
5391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005392 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5393 char *bss_line;
5394 char *bss_id = NULL;
5395 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305396 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005397
5398 if (ifname == NULL) {
5399 sigma_dut_print(dut, DUT_MSG_INFO,
5400 "For get DiscoveredDevList need Interface name.");
5401 return -1;
5402 }
5403
5404 /*
5405 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5406 * of BSSIDs in "bssid=<BSSID>\n"
5407 */
5408 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5409 bss_list,
5410 sizeof(bss_list)) < 0) {
5411 sigma_dut_print(dut, DUT_MSG_ERROR,
5412 "Failed to get bss list");
5413 return -1;
5414 }
5415
5416 sigma_dut_print(dut, DUT_MSG_DEBUG,
5417 "bss list for ifname:%s is:%s",
5418 ifname, bss_list);
5419
5420 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305421 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005422 while (bss_line) {
5423 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5424 bss_id) {
5425 int len;
5426
5427 len = snprintf(buf + strlen(buf),
5428 sizeof(buf) - strlen(buf),
5429 ",%s", bss_id);
5430 free(bss_id);
5431 bss_id = NULL;
5432 if (len < 0) {
5433 sigma_dut_print(dut,
5434 DUT_MSG_ERROR,
5435 "Failed to read BSSID");
5436 send_resp(dut, conn, SIGMA_ERROR,
5437 "ErrorCode,Failed to read BSS ID");
5438 return 0;
5439 }
5440
5441 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5442 sigma_dut_print(dut,
5443 DUT_MSG_ERROR,
5444 "Response buf too small for list");
5445 send_resp(dut, conn,
5446 SIGMA_ERROR,
5447 "ErrorCode,Response buf too small for list");
5448 return 0;
5449 }
5450 }
5451
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305452 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005453 }
5454
5455 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5456 buf);
5457 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5458 return 0;
5459 }
5460
5461 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5462 return 0;
5463}
5464
5465
5466static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5467 struct sigma_cmd *cmd)
5468{
5469 const char *program = get_param(cmd, "Program");
5470
5471 if (program == NULL)
5472 return -1;
5473
5474 if (strcasecmp(program, "P2PNFC") == 0)
5475 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5476
5477 if (strcasecmp(program, "60ghz") == 0)
5478 return sta_get_parameter_60g(dut, conn, cmd);
5479
5480#ifdef ANDROID_NAN
5481 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005482 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005483#endif /* ANDROID_NAN */
5484
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005485#ifdef MIRACAST
5486 if (strcasecmp(program, "WFD") == 0 ||
5487 strcasecmp(program, "DisplayR2") == 0)
5488 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5489#endif /* MIRACAST */
5490
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005491 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5492 return 0;
5493}
5494
5495
5496static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5497 const char *type)
5498{
5499 char buf[100];
5500
5501 if (dut->program == PROGRAM_VHT) {
5502 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5503 if (system(buf) != 0) {
5504 sigma_dut_print(dut, DUT_MSG_ERROR,
5505 "iwpriv %s chwidth failed", intf);
5506 }
5507
5508 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5509 if (system(buf) != 0) {
5510 sigma_dut_print(dut, DUT_MSG_ERROR,
5511 "iwpriv %s mode 11ACVHT80 failed",
5512 intf);
5513 }
5514
5515 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5516 if (system(buf) != 0) {
5517 sigma_dut_print(dut, DUT_MSG_ERROR,
5518 "iwpriv %s vhtmcs -1 failed", intf);
5519 }
5520 }
5521
5522 if (dut->program == PROGRAM_HT) {
5523 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5524 if (system(buf) != 0) {
5525 sigma_dut_print(dut, DUT_MSG_ERROR,
5526 "iwpriv %s chwidth failed", intf);
5527 }
5528
5529 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5530 if (system(buf) != 0) {
5531 sigma_dut_print(dut, DUT_MSG_ERROR,
5532 "iwpriv %s mode 11naht40 failed",
5533 intf);
5534 }
5535
5536 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5537 if (system(buf) != 0) {
5538 sigma_dut_print(dut, DUT_MSG_ERROR,
5539 "iwpriv set11NRates failed");
5540 }
5541 }
5542
5543 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5544 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5545 if (system(buf) != 0) {
5546 sigma_dut_print(dut, DUT_MSG_ERROR,
5547 "disabling powersave failed");
5548 }
5549
5550 /* Reset CTS width */
5551 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5552 intf);
5553 if (system(buf) != 0) {
5554 sigma_dut_print(dut, DUT_MSG_ERROR,
5555 "wifitool %s beeliner_fw_test 54 0 failed",
5556 intf);
5557 }
5558
5559 /* Enable Dynamic Bandwidth signalling by default */
5560 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5561 if (system(buf) != 0) {
5562 sigma_dut_print(dut, DUT_MSG_ERROR,
5563 "iwpriv %s cwmenable 1 failed", intf);
5564 }
5565
5566 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5567 if (system(buf) != 0) {
5568 sigma_dut_print(dut, DUT_MSG_ERROR,
5569 "iwpriv rts failed");
5570 }
5571 }
5572
5573 if (type && strcasecmp(type, "Testbed") == 0) {
5574 dut->testbed_flag_txsp = 1;
5575 dut->testbed_flag_rxsp = 1;
5576 /* STA has to set spatial stream to 2 per Appendix H */
5577 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5578 if (system(buf) != 0) {
5579 sigma_dut_print(dut, DUT_MSG_ERROR,
5580 "iwpriv vht_mcsmap failed");
5581 }
5582
5583 /* Disable LDPC per Appendix H */
5584 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5585 if (system(buf) != 0) {
5586 sigma_dut_print(dut, DUT_MSG_ERROR,
5587 "iwpriv %s ldpc 0 failed", intf);
5588 }
5589
5590 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5591 if (system(buf) != 0) {
5592 sigma_dut_print(dut, DUT_MSG_ERROR,
5593 "iwpriv amsdu failed");
5594 }
5595
5596 /* TODO: Disable STBC 2x1 transmit and receive */
5597 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5598 if (system(buf) != 0) {
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "Disable tx_stbc 0 failed");
5601 }
5602
5603 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5604 if (system(buf) != 0) {
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Disable rx_stbc 0 failed");
5607 }
5608
5609 /* STA has to disable Short GI per Appendix H */
5610 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5611 if (system(buf) != 0) {
5612 sigma_dut_print(dut, DUT_MSG_ERROR,
5613 "iwpriv %s shortgi 0 failed", intf);
5614 }
5615 }
5616
5617 if (type && strcasecmp(type, "DUT") == 0) {
5618 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5619 if (system(buf) != 0) {
5620 sigma_dut_print(dut, DUT_MSG_ERROR,
5621 "iwpriv %s nss 3 failed", intf);
5622 }
5623
5624 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5625 if (system(buf) != 0) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR,
5627 "iwpriv %s shortgi 1 failed", intf);
5628 }
5629 }
5630}
5631
5632
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005633#ifdef NL80211_SUPPORT
5634static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5635 enum he_mcs_config mcs)
5636{
5637 struct nl_msg *msg;
5638 int ret = 0;
5639 struct nlattr *params;
5640 int ifindex;
5641
5642 ifindex = if_nametoindex(intf);
5643 if (ifindex == 0) {
5644 sigma_dut_print(dut, DUT_MSG_ERROR,
5645 "%s: Index for interface %s failed",
5646 __func__, intf);
5647 return -1;
5648 }
5649
5650 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5651 NL80211_CMD_VENDOR)) ||
5652 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5653 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5654 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5655 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5656 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5657 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5658 mcs)) {
5659 sigma_dut_print(dut, DUT_MSG_ERROR,
5660 "%s: err in adding vendor_cmd and vendor_data",
5661 __func__);
5662 nlmsg_free(msg);
5663 return -1;
5664 }
5665 nla_nest_end(msg, params);
5666
5667 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5668 if (ret) {
5669 sigma_dut_print(dut, DUT_MSG_ERROR,
5670 "%s: err in send_and_recv_msgs, ret=%d",
5671 __func__, ret);
5672 }
5673 return ret;
5674}
5675#endif /* NL80211_SUPPORT */
5676
5677
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005678static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5679 const char *intf, int enable)
5680{
5681#ifdef NL80211_SUPPORT
5682 struct nl_msg *msg;
5683 int ret = 0;
5684 struct nlattr *params;
5685 int ifindex;
5686
5687 ifindex = if_nametoindex(intf);
5688 if (ifindex == 0) {
5689 sigma_dut_print(dut, DUT_MSG_ERROR,
5690 "%s: Index for interface %s failed",
5691 __func__, intf);
5692 return -1;
5693 }
5694
5695 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5696 NL80211_CMD_VENDOR)) ||
5697 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5698 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5699 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5700 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5701 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5702 nla_put_u8(msg,
5703 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
5704 enable)) {
5705 sigma_dut_print(dut, DUT_MSG_ERROR,
5706 "%s: err in adding vendor_cmd and vendor_data",
5707 __func__);
5708 nlmsg_free(msg);
5709 return -1;
5710 }
5711 nla_nest_end(msg, params);
5712
5713 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5714 if (ret) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "%s: err in send_and_recv_msgs, ret=%d",
5717 __func__, ret);
5718 }
5719 return ret;
5720#else /* NL80211_SUPPORT */
5721 sigma_dut_print(dut, DUT_MSG_ERROR,
5722 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5723 return -1;
5724#endif /* NL80211_SUPPORT */
5725}
5726
5727
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005728static int sta_set_addba_buf_size(struct sigma_dut *dut,
5729 const char *intf, int bufsize)
5730{
5731#ifdef NL80211_SUPPORT
5732 struct nl_msg *msg;
5733 int ret = 0;
5734 struct nlattr *params;
5735 int ifindex;
5736
5737 ifindex = if_nametoindex(intf);
5738 if (ifindex == 0) {
5739 sigma_dut_print(dut, DUT_MSG_ERROR,
5740 "%s: Index for interface %s failed",
5741 __func__, intf);
5742 return -1;
5743 }
5744
5745 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5746 NL80211_CMD_VENDOR)) ||
5747 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5748 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5749 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5750 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5751 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5752 nla_put_u8(msg,
5753 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5754 bufsize)) {
5755 sigma_dut_print(dut, DUT_MSG_ERROR,
5756 "%s: err in adding vendor_cmd and vendor_data",
5757 __func__);
5758 nlmsg_free(msg);
5759 return -1;
5760 }
5761 nla_nest_end(msg, params);
5762
5763 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5764 if (ret) {
5765 sigma_dut_print(dut, DUT_MSG_ERROR,
5766 "%s: err in send_and_recv_msgs, ret=%d",
5767 __func__, ret);
5768 }
5769 return ret;
5770#else /* NL80211_SUPPORT */
5771 sigma_dut_print(dut, DUT_MSG_ERROR,
5772 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5773 return -1;
5774#endif /* NL80211_SUPPORT */
5775}
5776
5777
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005778static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5779 const char *type)
5780{
5781 char buf[60];
5782
5783 if (dut->program == PROGRAM_HE) {
5784 /* resetting phymode to auto in case of HE program */
5785 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5786 if (system(buf) != 0) {
5787 sigma_dut_print(dut, DUT_MSG_ERROR,
5788 "iwpriv %s setphymode failed", intf);
5789 }
5790
5791 /* remove all network profiles */
5792 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005793
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005794 /* Configure ADDBA Req/Rsp buffer size to be 64 */
5795 sta_set_addba_buf_size(dut, intf, 64);
5796
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08005797#ifdef NL80211_SUPPORT
5798 /* Disable noackpolicy for all AC */
5799 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
5800 sigma_dut_print(dut, DUT_MSG_ERROR,
5801 "Disable of noackpolicy for all AC failed");
5802 }
5803#endif /* NL80211_SUPPORT */
5804
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08005805 /* Enable WMM by default */
5806 if (wcn_sta_set_wmm(dut, intf, "on")) {
5807 sigma_dut_print(dut, DUT_MSG_ERROR,
5808 "Enable of WMM in sta_reset_default_wcn failed");
5809 }
5810
5811 /* Disable ADDBA_REJECT by default */
5812 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
5813 sigma_dut_print(dut, DUT_MSG_ERROR,
5814 "Disable of addba_reject in sta_reset_default_wcn failed");
5815 }
5816
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005817 /* Enable sending of ADDBA by default */
5818 if (nlvendor_config_send_addba(dut, intf, 1)) {
5819 sigma_dut_print(dut, DUT_MSG_ERROR,
5820 "Enable sending of ADDBA in sta_reset_default_wcn failed");
5821 }
5822
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08005823 /* Enable AMPDU by default */
5824 iwpriv_sta_set_ampdu(dut, intf, 1);
5825
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005826 /* Set nss to 1 and MCS 0-7 in case of testbed */
5827 if (type && strcasecmp(type, "Testbed") == 0) {
5828#ifdef NL80211_SUPPORT
5829 int ret;
5830#endif /* NL80211_SUPPORT */
5831
5832 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5833 if (system(buf) != 0) {
5834 sigma_dut_print(dut, DUT_MSG_ERROR,
5835 "iwpriv %s nss failed", intf);
5836 }
5837
5838#ifdef NL80211_SUPPORT
5839 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5840 if (ret) {
5841 sigma_dut_print(dut, DUT_MSG_ERROR,
5842 "Setting of MCS failed, ret:%d",
5843 ret);
5844 }
5845#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08005846
5847 /* Disable STBC as default */
5848 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005849
5850 /* Disable AMSDU as default */
5851 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005852
5853#ifdef NL80211_SUPPORT
5854 /* HE fragmentation default off */
5855 if (sta_set_he_fragmentation(dut, intf,
5856 HE_FRAG_DISABLE)) {
5857 sigma_dut_print(dut, DUT_MSG_ERROR,
5858 "Setting of HE fragmentation failed");
5859 }
5860#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005861
5862 /* Enable WEP/TKIP with HE capability in testbed */
5863 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
5864 sigma_dut_print(dut, DUT_MSG_ERROR,
5865 "Enabling HE config with WEP/TKIP failed");
5866 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005867 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08005868
5869 /* Defaults in case of DUT */
5870 if (type && strcasecmp(type, "DUT") == 0) {
5871 /* set nss to 2 */
5872 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
5873 if (system(buf) != 0) {
5874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "iwpriv %s nss 2 failed", intf);
5876 }
5877
5878#ifdef NL80211_SUPPORT
5879 /* Set HE_MCS to 0-7 */
5880 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_7)) {
5881 sigma_dut_print(dut, DUT_MSG_ERROR,
5882 "Setting of MCS failed");
5883 }
5884#endif /* NL80211_SUPPORT */
5885
5886 /* Disable WEP/TKIP with HE capability in DUT */
5887 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
5888 sigma_dut_print(dut, DUT_MSG_ERROR,
5889 "Enabling HE config with WEP/TKIP failed");
5890 }
5891 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005892 }
5893}
5894
5895
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005896static int cmd_sta_reset_default(struct sigma_dut *dut,
5897 struct sigma_conn *conn,
5898 struct sigma_cmd *cmd)
5899{
5900 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5901 struct sigma_cmd *cmd);
5902 const char *intf = get_param(cmd, "Interface");
5903 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005904 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305905 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005906
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005907 if (!program)
5908 program = get_param(cmd, "prog");
5909 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 dut->device_type = STA_unknown;
5911 type = get_param(cmd, "type");
5912 if (type && strcasecmp(type, "Testbed") == 0)
5913 dut->device_type = STA_testbed;
5914 if (type && strcasecmp(type, "DUT") == 0)
5915 dut->device_type = STA_dut;
5916
5917 if (dut->program == PROGRAM_TDLS) {
5918 /* Clear TDLS testing mode */
5919 wpa_command(intf, "SET tdls_disabled 0");
5920 wpa_command(intf, "SET tdls_testing 0");
5921 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305922 if (get_driver_type() == DRIVER_WCN) {
5923 /* Enable the WCN driver in TDLS Explicit trigger mode
5924 */
5925 wpa_command(intf, "SET tdls_external_control 0");
5926 wpa_command(intf, "SET tdls_trigger_control 0");
5927 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005928 }
5929
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005930#ifdef MIRACAST
5931 if (dut->program == PROGRAM_WFD ||
5932 dut->program == PROGRAM_DISPLAYR2)
5933 miracast_sta_reset_default(dut, conn, cmd);
5934#endif /* MIRACAST */
5935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005936 switch (get_driver_type()) {
5937 case DRIVER_ATHEROS:
5938 sta_reset_default_ath(dut, intf, type);
5939 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005940 case DRIVER_WCN:
5941 sta_reset_default_wcn(dut, intf, type);
5942 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 default:
5944 break;
5945 }
5946
5947#ifdef ANDROID_NAN
5948 if (dut->program == PROGRAM_NAN)
5949 nan_cmd_sta_reset_default(dut, conn, cmd);
5950#endif /* ANDROID_NAN */
5951
5952 if (dut->program == PROGRAM_HS2_R2) {
5953 unlink("SP/wi-fi.org/pps.xml");
5954 if (system("rm -r SP/*") != 0) {
5955 }
5956 unlink("next-client-cert.pem");
5957 unlink("next-client-key.pem");
5958 }
5959
5960 if (dut->program == PROGRAM_60GHZ) {
5961 const char *dev_role = get_param(cmd, "DevRole");
5962
5963 if (!dev_role) {
5964 send_resp(dut, conn, SIGMA_ERROR,
5965 "errorCode,Missing DevRole argument");
5966 return 0;
5967 }
5968
5969 if (strcasecmp(dev_role, "STA") == 0)
5970 dut->dev_role = DEVROLE_STA;
5971 else if (strcasecmp(dev_role, "PCP") == 0)
5972 dut->dev_role = DEVROLE_PCP;
5973 else {
5974 send_resp(dut, conn, SIGMA_ERROR,
5975 "errorCode,Unknown DevRole");
5976 return 0;
5977 }
5978
5979 if (dut->device_type == STA_unknown) {
5980 sigma_dut_print(dut, DUT_MSG_ERROR,
5981 "Device type is not STA testbed or DUT");
5982 send_resp(dut, conn, SIGMA_ERROR,
5983 "errorCode,Unknown device type");
5984 return 0;
5985 }
5986 }
5987
5988 wpa_command(intf, "WPS_ER_STOP");
5989 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305990 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005991 wpa_command(intf, "SET radio_disabled 0");
5992
5993 if (dut->tmp_mac_addr && dut->set_macaddr) {
5994 dut->tmp_mac_addr = 0;
5995 if (system(dut->set_macaddr) != 0) {
5996 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5997 "temporary MAC address");
5998 }
5999 }
6000
6001 set_ps(intf, dut, 0);
6002
6003 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
6004 wpa_command(intf, "SET interworking 1");
6005 wpa_command(intf, "SET hs20 1");
6006 }
6007
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006008 if (dut->program == PROGRAM_HS2_R2 ||
6009 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006010 wpa_command(intf, "SET pmf 1");
6011 } else {
6012 wpa_command(intf, "SET pmf 0");
6013 }
6014
6015 hs2_clear_credentials(intf);
6016 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6017 wpa_command(intf, "SET access_network_type 15");
6018
6019 static_ip_file(0, NULL, NULL, NULL);
6020 kill_dhcp_client(dut, intf);
6021 clear_ip_addr(dut, intf);
6022
6023 dut->er_oper_performed = 0;
6024 dut->er_oper_bssid[0] = '\0';
6025
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006026 if (dut->program == PROGRAM_LOC) {
6027 /* Disable Interworking by default */
6028 wpa_command(get_station_ifname(), "SET interworking 0");
6029 }
6030
Ashwini Patil00402582017-04-13 12:29:39 +05306031 if (dut->program == PROGRAM_MBO) {
6032 free(dut->non_pref_ch_list);
6033 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306034 free(dut->btm_query_cand_list);
6035 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306036 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306037 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306038 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306039 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306040 }
6041
Jouni Malinen3c367e82017-06-23 17:01:47 +03006042 free(dut->rsne_override);
6043 dut->rsne_override = NULL;
6044
Jouni Malinen68143132017-09-02 02:34:08 +03006045 free(dut->sae_commit_override);
6046 dut->sae_commit_override = NULL;
6047
Jouni Malinend86e5822017-08-29 03:55:32 +03006048 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006049 free(dut->dpp_peer_uri);
6050 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006051 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006052 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006053
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006054 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6055
vamsi krishnaa2799492017-12-05 14:28:01 +05306056 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306057 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306058 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306059 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6060 dut->fils_hlp = 0;
6061#ifdef ANDROID
6062 hlp_thread_cleanup(dut);
6063#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306064 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306065
Sunil Dutt076081f2018-02-05 19:45:50 +05306066#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306067 if (get_driver_type() == DRIVER_WCN &&
6068 dut->config_rsnie == 1) {
6069 dut->config_rsnie = 0;
6070 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306071 }
6072#endif /* NL80211_SUPPORT */
6073
Sunil Duttfebf8a82018-02-09 18:50:13 +05306074 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6075 dut->dev_role = DEVROLE_STA_CFON;
6076 return sta_cfon_reset_default(dut, conn, cmd);
6077 }
6078
6079 if (dut->program != PROGRAM_VHT)
6080 return cmd_sta_p2p_reset(dut, conn, cmd);
6081
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006082 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006083}
6084
6085
6086static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6087 struct sigma_cmd *cmd)
6088{
6089 const char *program = get_param(cmd, "Program");
6090
6091 if (program == NULL)
6092 return -1;
6093#ifdef ANDROID_NAN
6094 if (strcasecmp(program, "NAN") == 0)
6095 return nan_cmd_sta_get_events(dut, conn, cmd);
6096#endif /* ANDROID_NAN */
6097 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6098 return 0;
6099}
6100
6101
Jouni Malinen82905202018-04-29 17:20:10 +03006102static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6103 struct sigma_cmd *cmd)
6104{
6105 const char *url = get_param(cmd, "url");
6106 const char *method = get_param(cmd, "method");
6107 pid_t pid;
6108 int status;
6109
6110 if (!url || !method)
6111 return -1;
6112
6113 /* TODO: Add support for method,post */
6114 if (strcasecmp(method, "get") != 0) {
6115 send_resp(dut, conn, SIGMA_ERROR,
6116 "ErrorCode,Unsupported method");
6117 return 0;
6118 }
6119
6120 pid = fork();
6121 if (pid < 0) {
6122 perror("fork");
6123 return -1;
6124 }
6125
6126 if (pid == 0) {
6127 char * argv[5] = { "wget", "-O", "/dev/null",
6128 (char *) url, NULL };
6129
6130 execv("/usr/bin/wget", argv);
6131 perror("execv");
6132 exit(0);
6133 return -1;
6134 }
6135
6136 if (waitpid(pid, &status, 0) < 0) {
6137 perror("waitpid");
6138 return -1;
6139 }
6140
6141 if (WIFEXITED(status)) {
6142 const char *errmsg;
6143
6144 if (WEXITSTATUS(status) == 0)
6145 return 1;
6146 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6147 WEXITSTATUS(status));
6148 switch (WEXITSTATUS(status)) {
6149 case 4:
6150 errmsg = "errmsg,Network failure";
6151 break;
6152 case 8:
6153 errmsg = "errmsg,Server issued an error response";
6154 break;
6155 default:
6156 errmsg = "errmsg,Unknown failure from wget";
6157 break;
6158 }
6159 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6160 return 0;
6161 }
6162
6163 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6164 return 0;
6165}
6166
6167
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006168static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6169 struct sigma_cmd *cmd)
6170{
6171 const char *program = get_param(cmd, "Prog");
6172
Jouni Malinen82905202018-04-29 17:20:10 +03006173 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006174 return -1;
6175#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006176 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006177 return nan_cmd_sta_exec_action(dut, conn, cmd);
6178#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006179
6180 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006181 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006182
6183 if (get_param(cmd, "url"))
6184 return sta_exec_action_url(dut, conn, cmd);
6185
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006186 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6187 return 0;
6188}
6189
6190
6191static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6192 struct sigma_cmd *cmd)
6193{
6194 const char *intf = get_param(cmd, "Interface");
6195 const char *val, *mcs32, *rate;
6196
6197 val = get_param(cmd, "GREENFIELD");
6198 if (val) {
6199 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6200 /* Enable GD */
6201 send_resp(dut, conn, SIGMA_ERROR,
6202 "ErrorCode,GF not supported");
6203 return 0;
6204 }
6205 }
6206
6207 val = get_param(cmd, "SGI20");
6208 if (val) {
6209 switch (get_driver_type()) {
6210 case DRIVER_ATHEROS:
6211 ath_sta_set_sgi(dut, intf, val);
6212 break;
6213 default:
6214 send_resp(dut, conn, SIGMA_ERROR,
6215 "ErrorCode,SGI20 not supported");
6216 return 0;
6217 }
6218 }
6219
6220 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6221 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6222 if (mcs32 && rate) {
6223 /* TODO */
6224 send_resp(dut, conn, SIGMA_ERROR,
6225 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6226 return 0;
6227 } else if (mcs32 && !rate) {
6228 /* TODO */
6229 send_resp(dut, conn, SIGMA_ERROR,
6230 "ErrorCode,MCS32 not supported");
6231 return 0;
6232 } else if (!mcs32 && rate) {
6233 switch (get_driver_type()) {
6234 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006235 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006236 ath_sta_set_11nrates(dut, intf, rate);
6237 break;
6238 default:
6239 send_resp(dut, conn, SIGMA_ERROR,
6240 "ErrorCode,MCS32_FIXEDRATE not supported");
6241 return 0;
6242 }
6243 }
6244
6245 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6246}
6247
6248
6249static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
6250 struct sigma_conn *conn,
6251 struct sigma_cmd *cmd)
6252{
6253 const char *intf = get_param(cmd, "Interface");
6254 const char *val;
6255 char buf[30];
6256 int tkip = -1;
6257 int wep = -1;
6258
6259 val = get_param(cmd, "SGI80");
6260 if (val) {
6261 int sgi80;
6262
6263 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6264 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
6265 if (system(buf) != 0) {
6266 sigma_dut_print(dut, DUT_MSG_ERROR,
6267 "iwpriv shortgi failed");
6268 }
6269 }
6270
6271 val = get_param(cmd, "TxBF");
6272 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6273 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
6274 if (system(buf) != 0) {
6275 sigma_dut_print(dut, DUT_MSG_ERROR,
6276 "iwpriv vhtsubfee failed");
6277 }
6278 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
6279 if (system(buf) != 0) {
6280 sigma_dut_print(dut, DUT_MSG_ERROR,
6281 "iwpriv vhtsubfer failed");
6282 }
6283 }
6284
6285 val = get_param(cmd, "MU_TxBF");
6286 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6287 switch (get_driver_type()) {
6288 case DRIVER_ATHEROS:
6289 ath_sta_set_txsp_stream(dut, intf, "1SS");
6290 ath_sta_set_rxsp_stream(dut, intf, "1SS");
6291 case DRIVER_WCN:
6292 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
6293 send_resp(dut, conn, SIGMA_ERROR,
6294 "ErrorCode,Failed to set RX/TXSP_STREAM");
6295 return 0;
6296 }
6297 default:
6298 sigma_dut_print(dut, DUT_MSG_ERROR,
6299 "Setting SP_STREAM not supported");
6300 break;
6301 }
6302 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
6303 if (system(buf) != 0) {
6304 sigma_dut_print(dut, DUT_MSG_ERROR,
6305 "iwpriv vhtmubfee failed");
6306 }
6307 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
6308 if (system(buf) != 0) {
6309 sigma_dut_print(dut, DUT_MSG_ERROR,
6310 "iwpriv vhtmubfer failed");
6311 }
6312 }
6313
6314 val = get_param(cmd, "LDPC");
6315 if (val) {
6316 int ldpc;
6317
6318 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6319 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
6320 if (system(buf) != 0) {
6321 sigma_dut_print(dut, DUT_MSG_ERROR,
6322 "iwpriv ldpc failed");
6323 }
6324 }
6325
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08006326 val = get_param(cmd, "BCC");
6327 if (val) {
6328 int bcc;
6329
6330 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6331 /* use LDPC iwpriv itself to set bcc coding, bcc coding
6332 * is mutually exclusive to bcc */
6333 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
6334 if (system(buf) != 0) {
6335 sigma_dut_print(dut, DUT_MSG_ERROR,
6336 "Enabling/Disabling of BCC failed");
6337 }
6338 }
6339
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006340 val = get_param(cmd, "opt_md_notif_ie");
6341 if (val) {
6342 char *result = NULL;
6343 char delim[] = ";";
6344 char token[30];
6345 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306346 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347
Peng Xub8fc5cc2017-05-10 17:27:28 -07006348 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306349 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006350
6351 /* Extract the NSS information */
6352 if (result) {
6353 value = atoi(result);
6354 switch (value) {
6355 case 1:
6356 config_val = 1;
6357 break;
6358 case 2:
6359 config_val = 3;
6360 break;
6361 case 3:
6362 config_val = 7;
6363 break;
6364 case 4:
6365 config_val = 15;
6366 break;
6367 default:
6368 config_val = 3;
6369 break;
6370 }
6371
6372 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6373 intf, config_val);
6374 if (system(buf) != 0) {
6375 sigma_dut_print(dut, DUT_MSG_ERROR,
6376 "iwpriv rxchainmask failed");
6377 }
6378
6379 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
6380 intf, config_val);
6381 if (system(buf) != 0) {
6382 sigma_dut_print(dut, DUT_MSG_ERROR,
6383 "iwpriv txchainmask failed");
6384 }
6385 }
6386
6387 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306388 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006389 if (result) {
6390 value = atoi(result);
6391 switch (value) {
6392 case 20:
6393 config_val = 0;
6394 break;
6395 case 40:
6396 config_val = 1;
6397 break;
6398 case 80:
6399 config_val = 2;
6400 break;
6401 case 160:
6402 config_val = 3;
6403 break;
6404 default:
6405 config_val = 2;
6406 break;
6407 }
6408
6409 dut->chwidth = config_val;
6410
6411 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6412 intf, config_val);
6413 if (system(buf) != 0) {
6414 sigma_dut_print(dut, DUT_MSG_ERROR,
6415 "iwpriv chwidth failed");
6416 }
6417 }
6418
6419 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
6420 if (system(buf) != 0) {
6421 sigma_dut_print(dut, DUT_MSG_ERROR,
6422 "iwpriv opmode_notify failed");
6423 }
6424 }
6425
6426 val = get_param(cmd, "nss_mcs_cap");
6427 if (val) {
6428 int nss, mcs;
6429 char token[20];
6430 char *result = NULL;
6431 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306432 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006433
Peng Xub8fc5cc2017-05-10 17:27:28 -07006434 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306435 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306436 if (!result) {
6437 sigma_dut_print(dut, DUT_MSG_ERROR,
6438 "VHT NSS not specified");
6439 return 0;
6440 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006441 nss = atoi(result);
6442
6443 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
6444 if (system(buf) != 0) {
6445 sigma_dut_print(dut, DUT_MSG_ERROR,
6446 "iwpriv nss failed");
6447 }
6448
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306449 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006450 if (result == NULL) {
6451 sigma_dut_print(dut, DUT_MSG_ERROR,
6452 "VHTMCS NOT SPECIFIED!");
6453 return 0;
6454 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306455 result = strtok_r(result, "-", &saveptr);
6456 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306457 if (!result) {
6458 sigma_dut_print(dut, DUT_MSG_ERROR,
6459 "VHT MCS not specified");
6460 return 0;
6461 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006462 mcs = atoi(result);
6463
6464 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
6465 if (system(buf) != 0) {
6466 sigma_dut_print(dut, DUT_MSG_ERROR,
6467 "iwpriv mcs failed");
6468 }
6469
6470 switch (nss) {
6471 case 1:
6472 switch (mcs) {
6473 case 7:
6474 vht_mcsmap = 0xfffc;
6475 break;
6476 case 8:
6477 vht_mcsmap = 0xfffd;
6478 break;
6479 case 9:
6480 vht_mcsmap = 0xfffe;
6481 break;
6482 default:
6483 vht_mcsmap = 0xfffe;
6484 break;
6485 }
6486 break;
6487 case 2:
6488 switch (mcs) {
6489 case 7:
6490 vht_mcsmap = 0xfff0;
6491 break;
6492 case 8:
6493 vht_mcsmap = 0xfff5;
6494 break;
6495 case 9:
6496 vht_mcsmap = 0xfffa;
6497 break;
6498 default:
6499 vht_mcsmap = 0xfffa;
6500 break;
6501 }
6502 break;
6503 case 3:
6504 switch (mcs) {
6505 case 7:
6506 vht_mcsmap = 0xffc0;
6507 break;
6508 case 8:
6509 vht_mcsmap = 0xffd5;
6510 break;
6511 case 9:
6512 vht_mcsmap = 0xffea;
6513 break;
6514 default:
6515 vht_mcsmap = 0xffea;
6516 break;
6517 }
6518 break;
6519 default:
6520 vht_mcsmap = 0xffea;
6521 break;
6522 }
6523 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
6524 intf, vht_mcsmap);
6525 if (system(buf) != 0) {
6526 sigma_dut_print(dut, DUT_MSG_ERROR,
6527 "iwpriv vht_mcsmap failed");
6528 }
6529 }
6530
6531 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
6532
6533 val = get_param(cmd, "Vht_tkip");
6534 if (val)
6535 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6536
6537 val = get_param(cmd, "Vht_wep");
6538 if (val)
6539 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6540
6541 if (tkip != -1 || wep != -1) {
6542 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
6543 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
6544 intf);
6545 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
6546 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
6547 intf);
6548 } else {
6549 sigma_dut_print(dut, DUT_MSG_ERROR,
6550 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
6551 return 0;
6552 }
6553
6554 if (system(buf) != 0) {
6555 sigma_dut_print(dut, DUT_MSG_ERROR,
6556 "iwpriv htweptkip failed");
6557 }
6558 }
6559
6560 val = get_param(cmd, "txBandwidth");
6561 if (val) {
6562 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006563 case DRIVER_WCN:
6564 if (wcn_sta_set_width(dut, intf, val) < 0) {
6565 send_resp(dut, conn, SIGMA_ERROR,
6566 "ErrorCode,Failed to set txBandwidth");
6567 return 0;
6568 }
6569 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006570 case DRIVER_ATHEROS:
6571 if (ath_set_width(dut, conn, intf, val) < 0) {
6572 send_resp(dut, conn, SIGMA_ERROR,
6573 "ErrorCode,Failed to set txBandwidth");
6574 return 0;
6575 }
6576 break;
6577 default:
6578 sigma_dut_print(dut, DUT_MSG_ERROR,
6579 "Setting txBandwidth not supported");
6580 break;
6581 }
6582 }
6583
6584 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6585}
6586
6587
6588static int sta_set_wireless_60g(struct sigma_dut *dut,
6589 struct sigma_conn *conn,
6590 struct sigma_cmd *cmd)
6591{
6592 const char *dev_role = get_param(cmd, "DevRole");
6593
6594 if (!dev_role) {
6595 send_resp(dut, conn, SIGMA_INVALID,
6596 "ErrorCode,DevRole not specified");
6597 return 0;
6598 }
6599
6600 if (strcasecmp(dev_role, "PCP") == 0)
6601 return sta_set_60g_pcp(dut, conn, cmd);
6602 if (strcasecmp(dev_role, "STA") == 0)
6603 return sta_set_60g_sta(dut, conn, cmd);
6604 send_resp(dut, conn, SIGMA_INVALID,
6605 "ErrorCode,DevRole not supported");
6606 return 0;
6607}
6608
6609
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306610static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
6611 struct sigma_cmd *cmd)
6612{
6613 int status;
6614 const char *intf = get_param(cmd, "Interface");
6615 const char *val = get_param(cmd, "DevRole");
6616
6617 if (val && strcasecmp(val, "STA-CFON") == 0) {
6618 status = sta_cfon_set_wireless(dut, conn, cmd);
6619 if (status)
6620 return status;
6621 }
6622 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6623}
6624
6625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6627 struct sigma_cmd *cmd)
6628{
6629 const char *val;
6630
6631 val = get_param(cmd, "Program");
6632 if (val) {
6633 if (strcasecmp(val, "11n") == 0)
6634 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006635 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6637 if (strcasecmp(val, "60ghz") == 0)
6638 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306639 if (strcasecmp(val, "OCE") == 0)
6640 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006641 send_resp(dut, conn, SIGMA_ERROR,
6642 "ErrorCode,Program value not supported");
6643 } else {
6644 send_resp(dut, conn, SIGMA_ERROR,
6645 "ErrorCode,Program argument not available");
6646 }
6647
6648 return 0;
6649}
6650
6651
6652static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6653 int tid)
6654{
6655 char buf[100];
6656 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6657
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306658 if (tid < 0 ||
6659 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6660 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6661 return;
6662 }
6663
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006664 /*
6665 * Two ways to ensure that addba request with a
6666 * non zero TID could be sent out. EV 117296
6667 */
6668 snprintf(buf, sizeof(buf),
6669 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6670 tid);
6671 if (system(buf) != 0) {
6672 sigma_dut_print(dut, DUT_MSG_ERROR,
6673 "Ping did not send out");
6674 }
6675
6676 snprintf(buf, sizeof(buf),
6677 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6678 intf, VI_QOS_TMP_FILE);
6679 if (system(buf) != 0)
6680 return;
6681
6682 snprintf(buf, sizeof(buf),
6683 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6684 intf, VI_QOS_TMP_FILE);
6685 if (system(buf) != 0)
6686 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6687
6688 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6689 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6690 if (system(buf) != 0) {
6691 sigma_dut_print(dut, DUT_MSG_ERROR,
6692 "VI_QOS_TEMP_FILE generation error failed");
6693 }
6694 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6695 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6696 if (system(buf) != 0) {
6697 sigma_dut_print(dut, DUT_MSG_ERROR,
6698 "VI_QOS_FILE generation failed");
6699 }
6700
6701 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6702 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6703 if (system(buf) != 0) {
6704 sigma_dut_print(dut, DUT_MSG_ERROR,
6705 "VI_QOS_FILE generation failed");
6706 }
6707
6708 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6709 if (system(buf) != 0) {
6710 }
6711}
6712
6713
6714static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6715 struct sigma_cmd *cmd)
6716{
6717 const char *intf = get_param(cmd, "Interface");
6718 const char *val;
6719 int tid = 0;
6720 char buf[100];
6721
6722 val = get_param(cmd, "TID");
6723 if (val) {
6724 tid = atoi(val);
6725 if (tid)
6726 ath_sta_inject_frame(dut, intf, tid);
6727 }
6728
6729 /* Command sequence for ADDBA request on Peregrine based devices */
6730 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6731 if (system(buf) != 0) {
6732 sigma_dut_print(dut, DUT_MSG_ERROR,
6733 "iwpriv setaddbaoper failed");
6734 }
6735
6736 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6737 if (system(buf) != 0) {
6738 sigma_dut_print(dut, DUT_MSG_ERROR,
6739 "wifitool senddelba failed");
6740 }
6741
6742 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6743 if (system(buf) != 0) {
6744 sigma_dut_print(dut, DUT_MSG_ERROR,
6745 "wifitool sendaddba failed");
6746 }
6747
6748 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6749
6750 return 1;
6751}
6752
6753
Lior David9981b512017-01-20 13:16:40 +02006754#ifdef __linux__
6755
6756static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6757 int agg_size)
6758{
6759 char dir[128], buf[128];
6760 FILE *f;
6761 regex_t re;
6762 regmatch_t m[2];
6763 int rc, ret = -1, vring_id, found;
6764
6765 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6766 sigma_dut_print(dut, DUT_MSG_ERROR,
6767 "failed to get wil6210 debugfs dir");
6768 return -1;
6769 }
6770
6771 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6772 f = fopen(buf, "r");
6773 if (!f) {
6774 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6775 return -1;
6776 }
6777
6778 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6779 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6780 goto out;
6781 }
6782
6783 /* find TX VRING for the mac address */
6784 found = 0;
6785 while (fgets(buf, sizeof(buf), f)) {
6786 if (strcasestr(buf, dest_mac)) {
6787 found = 1;
6788 break;
6789 }
6790 }
6791
6792 if (!found) {
6793 sigma_dut_print(dut, DUT_MSG_ERROR,
6794 "no TX VRING for %s", dest_mac);
6795 goto out;
6796 }
6797
6798 /* extract VRING ID, "VRING tx_<id> = {" */
6799 if (!fgets(buf, sizeof(buf), f)) {
6800 sigma_dut_print(dut, DUT_MSG_ERROR,
6801 "no VRING start line for %s", dest_mac);
6802 goto out;
6803 }
6804
6805 rc = regexec(&re, buf, 2, m, 0);
6806 regfree(&re);
6807 if (rc || m[1].rm_so < 0) {
6808 sigma_dut_print(dut, DUT_MSG_ERROR,
6809 "no VRING TX ID for %s", dest_mac);
6810 goto out;
6811 }
6812 buf[m[1].rm_eo] = 0;
6813 vring_id = atoi(&buf[m[1].rm_so]);
6814
6815 /* send the addba command */
6816 fclose(f);
6817 snprintf(buf, sizeof(buf), "%s/back", dir);
6818 f = fopen(buf, "w");
6819 if (!f) {
6820 sigma_dut_print(dut, DUT_MSG_ERROR,
6821 "failed to open: %s", buf);
6822 return -1;
6823 }
6824
6825 fprintf(f, "add %d %d\n", vring_id, agg_size);
6826
6827 ret = 0;
6828
6829out:
6830 fclose(f);
6831
6832 return ret;
6833}
6834
6835
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006836static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6837 struct sigma_cmd *cmd)
6838{
6839 const char *val;
6840 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006841
6842 val = get_param(cmd, "TID");
6843 if (val) {
6844 tid = atoi(val);
6845 if (tid != 0) {
6846 sigma_dut_print(dut, DUT_MSG_ERROR,
6847 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6848 tid);
6849 }
6850 }
6851
6852 val = get_param(cmd, "Dest_mac");
6853 if (!val) {
6854 sigma_dut_print(dut, DUT_MSG_ERROR,
6855 "Currently not supporting addba for 60G without Dest_mac");
6856 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6857 }
6858
Lior David9981b512017-01-20 13:16:40 +02006859 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006860 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861
6862 return 1;
6863}
6864
Lior David9981b512017-01-20 13:16:40 +02006865#endif /* __linux__ */
6866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006867
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08006868static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6869 struct sigma_cmd *cmd)
6870{
6871#ifdef NL80211_SUPPORT
6872 const char *intf = get_param(cmd, "Interface");
6873 const char *val;
6874 int tid = -1;
6875 int bufsize = 64;
6876 struct nl_msg *msg;
6877 int ret = 0;
6878 struct nlattr *params;
6879 int ifindex;
6880
6881 val = get_param(cmd, "TID");
6882 if (val)
6883 tid = atoi(val);
6884
6885 if (tid == -1) {
6886 send_resp(dut, conn, SIGMA_ERROR,
6887 "ErrorCode,sta_send_addba tid invalid");
6888 return 0;
6889 }
6890
6891 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6892
6893 ifindex = if_nametoindex(intf);
6894 if (ifindex == 0) {
6895 sigma_dut_print(dut, DUT_MSG_ERROR,
6896 "%s: Index for interface %s failed",
6897 __func__, intf);
6898 send_resp(dut, conn, SIGMA_ERROR,
6899 "ErrorCode,sta_send_addba interface invalid");
6900 return 0;
6901 }
6902
6903 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6904 NL80211_CMD_VENDOR)) ||
6905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6906 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6907 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6908 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6909 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6910 nla_put_u8(msg,
6911 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
6912 QCA_WLAN_ADD_BA) ||
6913 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
6914 tid) ||
6915 nla_put_u8(msg,
6916 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6917 bufsize)) {
6918 sigma_dut_print(dut, DUT_MSG_ERROR,
6919 "%s: err in adding vendor_cmd and vendor_data",
6920 __func__);
6921 nlmsg_free(msg);
6922 send_resp(dut, conn, SIGMA_ERROR,
6923 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
6924 return 0;
6925 }
6926 nla_nest_end(msg, params);
6927
6928 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6929 if (ret) {
6930 sigma_dut_print(dut, DUT_MSG_ERROR,
6931 "%s: err in send_and_recv_msgs, ret=%d",
6932 __func__, ret);
6933 send_resp(dut, conn, SIGMA_ERROR,
6934 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
6935 return 0;
6936 }
6937 return 1;
6938#else /* NL80211_SUPPORT */
6939 sigma_dut_print(dut, DUT_MSG_ERROR,
6940 "sta_send_addba not supported without NL80211_SUPPORT defined");
6941 send_resp(dut, conn, SIGMA_ERROR,
6942 "ErrorCode,sta_send_addba not supported, NL80211_SUPPORT not enabled");
6943 return 0;
6944#endif /* NL80211_SUPPORT */
6945}
6946
6947
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006948static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6949 struct sigma_cmd *cmd)
6950{
6951 switch (get_driver_type()) {
6952 case DRIVER_ATHEROS:
6953 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08006954 case DRIVER_WCN:
6955 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006956#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006957 case DRIVER_WIL6210:
6958 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006959#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006960 default:
6961 /*
6962 * There is no driver specific implementation for other drivers.
6963 * Ignore the command and report COMPLETE since the following
6964 * throughput test operation will end up sending ADDBA anyway.
6965 */
6966 return 1;
6967 }
6968}
6969
6970
6971int inject_eth_frame(int s, const void *data, size_t len,
6972 unsigned short ethtype, char *dst, char *src)
6973{
6974 struct iovec iov[4] = {
6975 {
6976 .iov_base = dst,
6977 .iov_len = ETH_ALEN,
6978 },
6979 {
6980 .iov_base = src,
6981 .iov_len = ETH_ALEN,
6982 },
6983 {
6984 .iov_base = &ethtype,
6985 .iov_len = sizeof(unsigned short),
6986 },
6987 {
6988 .iov_base = (void *) data,
6989 .iov_len = len,
6990 }
6991 };
6992 struct msghdr msg = {
6993 .msg_name = NULL,
6994 .msg_namelen = 0,
6995 .msg_iov = iov,
6996 .msg_iovlen = 4,
6997 .msg_control = NULL,
6998 .msg_controllen = 0,
6999 .msg_flags = 0,
7000 };
7001
7002 return sendmsg(s, &msg, 0);
7003}
7004
7005#if defined(__linux__) || defined(__QNXNTO__)
7006
7007int inject_frame(int s, const void *data, size_t len, int encrypt)
7008{
7009#define IEEE80211_RADIOTAP_F_WEP 0x04
7010#define IEEE80211_RADIOTAP_F_FRAG 0x08
7011 unsigned char rtap_hdr[] = {
7012 0x00, 0x00, /* radiotap version */
7013 0x0e, 0x00, /* radiotap length */
7014 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
7015 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
7016 0x00, /* padding */
7017 0x00, 0x00, /* RX and TX flags to indicate that */
7018 0x00, 0x00, /* this is the injected frame directly */
7019 };
7020 struct iovec iov[2] = {
7021 {
7022 .iov_base = &rtap_hdr,
7023 .iov_len = sizeof(rtap_hdr),
7024 },
7025 {
7026 .iov_base = (void *) data,
7027 .iov_len = len,
7028 }
7029 };
7030 struct msghdr msg = {
7031 .msg_name = NULL,
7032 .msg_namelen = 0,
7033 .msg_iov = iov,
7034 .msg_iovlen = 2,
7035 .msg_control = NULL,
7036 .msg_controllen = 0,
7037 .msg_flags = 0,
7038 };
7039
7040 if (encrypt)
7041 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
7042
7043 return sendmsg(s, &msg, 0);
7044}
7045
7046
7047int open_monitor(const char *ifname)
7048{
7049#ifdef __QNXNTO__
7050 struct sockaddr_dl ll;
7051 int s;
7052
7053 memset(&ll, 0, sizeof(ll));
7054 ll.sdl_family = AF_LINK;
7055 ll.sdl_index = if_nametoindex(ifname);
7056 if (ll.sdl_index == 0) {
7057 perror("if_nametoindex");
7058 return -1;
7059 }
7060 s = socket(PF_INET, SOCK_RAW, 0);
7061#else /* __QNXNTO__ */
7062 struct sockaddr_ll ll;
7063 int s;
7064
7065 memset(&ll, 0, sizeof(ll));
7066 ll.sll_family = AF_PACKET;
7067 ll.sll_ifindex = if_nametoindex(ifname);
7068 if (ll.sll_ifindex == 0) {
7069 perror("if_nametoindex");
7070 return -1;
7071 }
7072 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
7073#endif /* __QNXNTO__ */
7074 if (s < 0) {
7075 perror("socket[PF_PACKET,SOCK_RAW]");
7076 return -1;
7077 }
7078
7079 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
7080 perror("monitor socket bind");
7081 close(s);
7082 return -1;
7083 }
7084
7085 return s;
7086}
7087
7088
7089static int hex2num(char c)
7090{
7091 if (c >= '0' && c <= '9')
7092 return c - '0';
7093 if (c >= 'a' && c <= 'f')
7094 return c - 'a' + 10;
7095 if (c >= 'A' && c <= 'F')
7096 return c - 'A' + 10;
7097 return -1;
7098}
7099
7100
7101int hwaddr_aton(const char *txt, unsigned char *addr)
7102{
7103 int i;
7104
7105 for (i = 0; i < 6; i++) {
7106 int a, b;
7107
7108 a = hex2num(*txt++);
7109 if (a < 0)
7110 return -1;
7111 b = hex2num(*txt++);
7112 if (b < 0)
7113 return -1;
7114 *addr++ = (a << 4) | b;
7115 if (i < 5 && *txt++ != ':')
7116 return -1;
7117 }
7118
7119 return 0;
7120}
7121
7122#endif /* defined(__linux__) || defined(__QNXNTO__) */
7123
7124enum send_frame_type {
7125 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
7126};
7127enum send_frame_protection {
7128 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
7129};
7130
7131
7132static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7133 enum send_frame_type frame,
7134 enum send_frame_protection protected,
7135 const char *dest)
7136{
7137#ifdef __linux__
7138 unsigned char buf[1000], *pos;
7139 int s, res;
7140 char bssid[20], addr[20];
7141 char result[32], ssid[100];
7142 size_t ssid_len;
7143
7144 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
7145 sizeof(result)) < 0 ||
7146 strncmp(result, "COMPLETED", 9) != 0) {
7147 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
7148 return 0;
7149 }
7150
7151 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
7152 < 0) {
7153 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7154 "current BSSID");
7155 return 0;
7156 }
7157
7158 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
7159 < 0) {
7160 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7161 "own MAC address");
7162 return 0;
7163 }
7164
7165 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
7166 < 0) {
7167 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7168 "current SSID");
7169 return 0;
7170 }
7171 ssid_len = strlen(ssid);
7172
7173 pos = buf;
7174
7175 /* Frame Control */
7176 switch (frame) {
7177 case DISASSOC:
7178 *pos++ = 0xa0;
7179 break;
7180 case DEAUTH:
7181 *pos++ = 0xc0;
7182 break;
7183 case SAQUERY:
7184 *pos++ = 0xd0;
7185 break;
7186 case AUTH:
7187 *pos++ = 0xb0;
7188 break;
7189 case ASSOCREQ:
7190 *pos++ = 0x00;
7191 break;
7192 case REASSOCREQ:
7193 *pos++ = 0x20;
7194 break;
7195 case DLS_REQ:
7196 *pos++ = 0xd0;
7197 break;
7198 }
7199
7200 if (protected == INCORRECT_KEY)
7201 *pos++ = 0x40; /* Set Protected field to 1 */
7202 else
7203 *pos++ = 0x00;
7204
7205 /* Duration */
7206 *pos++ = 0x00;
7207 *pos++ = 0x00;
7208
7209 /* addr1 = DA (current AP) */
7210 hwaddr_aton(bssid, pos);
7211 pos += 6;
7212 /* addr2 = SA (own address) */
7213 hwaddr_aton(addr, pos);
7214 pos += 6;
7215 /* addr3 = BSSID (current AP) */
7216 hwaddr_aton(bssid, pos);
7217 pos += 6;
7218
7219 /* Seq# (to be filled by driver/mac80211) */
7220 *pos++ = 0x00;
7221 *pos++ = 0x00;
7222
7223 if (protected == INCORRECT_KEY) {
7224 /* CCMP parameters */
7225 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
7226 pos += 8;
7227 }
7228
7229 if (protected == INCORRECT_KEY) {
7230 switch (frame) {
7231 case DEAUTH:
7232 /* Reason code (encrypted) */
7233 memcpy(pos, "\xa7\x39", 2);
7234 pos += 2;
7235 break;
7236 case DISASSOC:
7237 /* Reason code (encrypted) */
7238 memcpy(pos, "\xa7\x39", 2);
7239 pos += 2;
7240 break;
7241 case SAQUERY:
7242 /* Category|Action|TransID (encrypted) */
7243 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
7244 pos += 4;
7245 break;
7246 default:
7247 return -1;
7248 }
7249
7250 /* CCMP MIC */
7251 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
7252 pos += 8;
7253 } else {
7254 switch (frame) {
7255 case DEAUTH:
7256 /* reason code = 8 */
7257 *pos++ = 0x08;
7258 *pos++ = 0x00;
7259 break;
7260 case DISASSOC:
7261 /* reason code = 8 */
7262 *pos++ = 0x08;
7263 *pos++ = 0x00;
7264 break;
7265 case SAQUERY:
7266 /* Category - SA Query */
7267 *pos++ = 0x08;
7268 /* SA query Action - Request */
7269 *pos++ = 0x00;
7270 /* Transaction ID */
7271 *pos++ = 0x12;
7272 *pos++ = 0x34;
7273 break;
7274 case AUTH:
7275 /* Auth Alg (Open) */
7276 *pos++ = 0x00;
7277 *pos++ = 0x00;
7278 /* Seq# */
7279 *pos++ = 0x01;
7280 *pos++ = 0x00;
7281 /* Status code */
7282 *pos++ = 0x00;
7283 *pos++ = 0x00;
7284 break;
7285 case ASSOCREQ:
7286 /* Capability Information */
7287 *pos++ = 0x31;
7288 *pos++ = 0x04;
7289 /* Listen Interval */
7290 *pos++ = 0x0a;
7291 *pos++ = 0x00;
7292 /* SSID */
7293 *pos++ = 0x00;
7294 *pos++ = ssid_len;
7295 memcpy(pos, ssid, ssid_len);
7296 pos += ssid_len;
7297 /* Supported Rates */
7298 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
7299 10);
7300 pos += 10;
7301 /* Extended Supported Rates */
7302 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
7303 pos += 6;
7304 /* RSN */
7305 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7306 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7307 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7308 pos += 28;
7309 break;
7310 case REASSOCREQ:
7311 /* Capability Information */
7312 *pos++ = 0x31;
7313 *pos++ = 0x04;
7314 /* Listen Interval */
7315 *pos++ = 0x0a;
7316 *pos++ = 0x00;
7317 /* Current AP */
7318 hwaddr_aton(bssid, pos);
7319 pos += 6;
7320 /* SSID */
7321 *pos++ = 0x00;
7322 *pos++ = ssid_len;
7323 memcpy(pos, ssid, ssid_len);
7324 pos += ssid_len;
7325 /* Supported Rates */
7326 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
7327 10);
7328 pos += 10;
7329 /* Extended Supported Rates */
7330 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
7331 pos += 6;
7332 /* RSN */
7333 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7334 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7335 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7336 pos += 28;
7337 break;
7338 case DLS_REQ:
7339 /* Category - DLS */
7340 *pos++ = 0x02;
7341 /* DLS Action - Request */
7342 *pos++ = 0x00;
7343 /* Destination MACAddress */
7344 if (dest)
7345 hwaddr_aton(dest, pos);
7346 else
7347 memset(pos, 0, 6);
7348 pos += 6;
7349 /* Source MACAddress */
7350 hwaddr_aton(addr, pos);
7351 pos += 6;
7352 /* Capability Information */
7353 *pos++ = 0x10; /* Privacy */
7354 *pos++ = 0x06; /* QoS */
7355 /* DLS Timeout Value */
7356 *pos++ = 0x00;
7357 *pos++ = 0x01;
7358 /* Supported rates */
7359 *pos++ = 0x01;
7360 *pos++ = 0x08;
7361 *pos++ = 0x0c; /* 6 Mbps */
7362 *pos++ = 0x12; /* 9 Mbps */
7363 *pos++ = 0x18; /* 12 Mbps */
7364 *pos++ = 0x24; /* 18 Mbps */
7365 *pos++ = 0x30; /* 24 Mbps */
7366 *pos++ = 0x48; /* 36 Mbps */
7367 *pos++ = 0x60; /* 48 Mbps */
7368 *pos++ = 0x6c; /* 54 Mbps */
7369 /* TODO: Extended Supported Rates */
7370 /* TODO: HT Capabilities */
7371 break;
7372 }
7373 }
7374
7375 s = open_monitor("sigmadut");
7376 if (s < 0) {
7377 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7378 "monitor socket");
7379 return 0;
7380 }
7381
7382 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
7383 if (res < 0) {
7384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7385 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307386 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007387 return 0;
7388 }
7389 if (res < pos - buf) {
7390 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
7391 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307392 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007393 return 0;
7394 }
7395
7396 close(s);
7397
7398 return 1;
7399#else /* __linux__ */
7400 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
7401 "yet supported");
7402 return 0;
7403#endif /* __linux__ */
7404}
7405
7406
7407static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
7408 struct sigma_conn *conn,
7409 struct sigma_cmd *cmd)
7410{
7411 const char *intf = get_param(cmd, "Interface");
7412 const char *sta, *val;
7413 unsigned char addr[ETH_ALEN];
7414 char buf[100];
7415
7416 sta = get_param(cmd, "peer");
7417 if (sta == NULL)
7418 sta = get_param(cmd, "station");
7419 if (sta == NULL) {
7420 send_resp(dut, conn, SIGMA_ERROR,
7421 "ErrorCode,Missing peer address");
7422 return 0;
7423 }
7424 if (hwaddr_aton(sta, addr) < 0) {
7425 send_resp(dut, conn, SIGMA_ERROR,
7426 "ErrorCode,Invalid peer address");
7427 return 0;
7428 }
7429
7430 val = get_param(cmd, "type");
7431 if (val == NULL)
7432 return -1;
7433
7434 if (strcasecmp(val, "DISCOVERY") == 0) {
7435 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
7436 if (wpa_command(intf, buf) < 0) {
7437 send_resp(dut, conn, SIGMA_ERROR,
7438 "ErrorCode,Failed to send TDLS discovery");
7439 return 0;
7440 }
7441 return 1;
7442 }
7443
7444 if (strcasecmp(val, "SETUP") == 0) {
7445 int status = 0, timeout = 0;
7446
7447 val = get_param(cmd, "Status");
7448 if (val)
7449 status = atoi(val);
7450
7451 val = get_param(cmd, "Timeout");
7452 if (val)
7453 timeout = atoi(val);
7454
7455 if (status != 0 && status != 37) {
7456 send_resp(dut, conn, SIGMA_ERROR,
7457 "ErrorCode,Unsupported status value");
7458 return 0;
7459 }
7460
7461 if (timeout != 0 && timeout != 301) {
7462 send_resp(dut, conn, SIGMA_ERROR,
7463 "ErrorCode,Unsupported timeout value");
7464 return 0;
7465 }
7466
7467 if (status && timeout) {
7468 send_resp(dut, conn, SIGMA_ERROR,
7469 "ErrorCode,Unsupported timeout+status "
7470 "combination");
7471 return 0;
7472 }
7473
7474 if (status == 37 &&
7475 wpa_command(intf, "SET tdls_testing 0x200")) {
7476 send_resp(dut, conn, SIGMA_ERROR,
7477 "ErrorCode,Failed to enable "
7478 "decline setup response test mode");
7479 return 0;
7480 }
7481
7482 if (timeout == 301) {
7483 int res;
7484 if (dut->no_tpk_expiration)
7485 res = wpa_command(intf,
7486 "SET tdls_testing 0x108");
7487 else
7488 res = wpa_command(intf,
7489 "SET tdls_testing 0x8");
7490 if (res) {
7491 send_resp(dut, conn, SIGMA_ERROR,
7492 "ErrorCode,Failed to set short TPK "
7493 "lifetime");
7494 return 0;
7495 }
7496 }
7497
7498 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
7499 if (wpa_command(intf, buf) < 0) {
7500 send_resp(dut, conn, SIGMA_ERROR,
7501 "ErrorCode,Failed to send TDLS setup");
7502 return 0;
7503 }
7504 return 1;
7505 }
7506
7507 if (strcasecmp(val, "TEARDOWN") == 0) {
7508 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
7509 if (wpa_command(intf, buf) < 0) {
7510 send_resp(dut, conn, SIGMA_ERROR,
7511 "ErrorCode,Failed to send TDLS teardown");
7512 return 0;
7513 }
7514 return 1;
7515 }
7516
7517 send_resp(dut, conn, SIGMA_ERROR,
7518 "ErrorCode,Unsupported TDLS frame");
7519 return 0;
7520}
7521
7522
7523static int sta_ap_known(const char *ifname, const char *bssid)
7524{
7525 char buf[4096];
7526
7527 snprintf(buf, sizeof(buf), "BSS %s", bssid);
7528 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
7529 return 0;
7530 if (strncmp(buf, "id=", 3) != 0)
7531 return 0;
7532 return 1;
7533}
7534
7535
7536static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
7537 const char *bssid)
7538{
7539 int res;
7540 struct wpa_ctrl *ctrl;
7541 char buf[256];
7542
7543 if (sta_ap_known(ifname, bssid))
7544 return 0;
7545 sigma_dut_print(dut, DUT_MSG_DEBUG,
7546 "AP not in BSS table - start scan");
7547
7548 ctrl = open_wpa_mon(ifname);
7549 if (ctrl == NULL) {
7550 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7551 "wpa_supplicant monitor connection");
7552 return -1;
7553 }
7554
7555 if (wpa_command(ifname, "SCAN") < 0) {
7556 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
7557 wpa_ctrl_detach(ctrl);
7558 wpa_ctrl_close(ctrl);
7559 return -1;
7560 }
7561
7562 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7563 buf, sizeof(buf));
7564
7565 wpa_ctrl_detach(ctrl);
7566 wpa_ctrl_close(ctrl);
7567
7568 if (res < 0) {
7569 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
7570 return -1;
7571 }
7572
7573 if (sta_ap_known(ifname, bssid))
7574 return 0;
7575 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
7576 return -1;
7577}
7578
7579
7580static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
7581 struct sigma_conn *conn,
7582 struct sigma_cmd *cmd,
7583 const char *intf)
7584{
7585 char buf[200];
7586
7587 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
7588 if (system(buf) != 0) {
7589 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
7590 "ndsend");
7591 return 0;
7592 }
7593
7594 return 1;
7595}
7596
7597
7598static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
7599 struct sigma_conn *conn,
7600 struct sigma_cmd *cmd,
7601 const char *intf)
7602{
7603 char buf[200];
7604 const char *ip = get_param(cmd, "SenderIP");
7605
Peng Xu26b356d2017-10-04 17:58:16 -07007606 if (!ip)
7607 return 0;
7608
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007609 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
7610 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7611 if (system(buf) == 0) {
7612 sigma_dut_print(dut, DUT_MSG_INFO,
7613 "Neighbor Solicitation got a response "
7614 "for %s@%s", ip, intf);
7615 }
7616
7617 return 1;
7618}
7619
7620
7621static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
7622 struct sigma_conn *conn,
7623 struct sigma_cmd *cmd,
7624 const char *ifname)
7625{
7626 char buf[200];
7627 const char *ip = get_param(cmd, "SenderIP");
7628
7629 if (ip == NULL) {
7630 send_resp(dut, conn, SIGMA_ERROR,
7631 "ErrorCode,Missing SenderIP parameter");
7632 return 0;
7633 }
7634 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
7635 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7636 if (system(buf) != 0) {
7637 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
7638 "for %s@%s", ip, ifname);
7639 }
7640
7641 return 1;
7642}
7643
7644
7645static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
7646 struct sigma_conn *conn,
7647 struct sigma_cmd *cmd,
7648 const char *ifname)
7649{
7650 char buf[200];
7651 char ip[16];
7652 int s;
Peng Xub3756882017-10-04 14:39:09 -07007653 struct ifreq ifr;
7654 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007655
7656 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07007657 if (s < 0) {
7658 perror("socket");
7659 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007660 }
7661
Peng Xub3756882017-10-04 14:39:09 -07007662 memset(&ifr, 0, sizeof(ifr));
7663 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7664 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
7665 sigma_dut_print(dut, DUT_MSG_INFO,
7666 "Failed to get %s IP address: %s",
7667 ifname, strerror(errno));
7668 close(s);
7669 return -1;
7670 }
7671 close(s);
7672
7673 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
7674 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
7675
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007676 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
7677 ip);
7678 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7679 if (system(buf) != 0) {
7680 }
7681
7682 return 1;
7683}
7684
7685
7686static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
7687 struct sigma_conn *conn,
7688 struct sigma_cmd *cmd,
7689 const char *ifname)
7690{
7691 char buf[200], addr[20];
7692 char dst[ETH_ALEN], src[ETH_ALEN];
7693 short ethtype = htons(ETH_P_ARP);
7694 char *pos;
7695 int s, res;
7696 const char *val;
7697 struct sockaddr_in taddr;
7698
7699 val = get_param(cmd, "dest");
7700 if (val)
7701 hwaddr_aton(val, (unsigned char *) dst);
7702
7703 val = get_param(cmd, "DestIP");
7704 if (val)
7705 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007706 else
7707 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007708
7709 if (get_wpa_status(get_station_ifname(), "address", addr,
7710 sizeof(addr)) < 0)
7711 return -2;
7712 hwaddr_aton(addr, (unsigned char *) src);
7713
7714 pos = buf;
7715 *pos++ = 0x00;
7716 *pos++ = 0x01;
7717 *pos++ = 0x08;
7718 *pos++ = 0x00;
7719 *pos++ = 0x06;
7720 *pos++ = 0x04;
7721 *pos++ = 0x00;
7722 *pos++ = 0x02;
7723 memcpy(pos, src, ETH_ALEN);
7724 pos += ETH_ALEN;
7725 memcpy(pos, &taddr.sin_addr, 4);
7726 pos += 4;
7727 memcpy(pos, dst, ETH_ALEN);
7728 pos += ETH_ALEN;
7729 memcpy(pos, &taddr.sin_addr, 4);
7730 pos += 4;
7731
7732 s = open_monitor(get_station_ifname());
7733 if (s < 0) {
7734 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7735 "monitor socket");
7736 return 0;
7737 }
7738
7739 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7740 if (res < 0) {
7741 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7742 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307743 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007744 return 0;
7745 }
7746
7747 close(s);
7748
7749 return 1;
7750}
7751
7752
7753static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7754 struct sigma_conn *conn,
7755 struct sigma_cmd *cmd,
7756 const char *intf, const char *dest)
7757{
7758 char buf[100];
7759
7760 if (if_nametoindex("sigmadut") == 0) {
7761 snprintf(buf, sizeof(buf),
7762 "iw dev %s interface add sigmadut type monitor",
7763 get_station_ifname());
7764 if (system(buf) != 0 ||
7765 if_nametoindex("sigmadut") == 0) {
7766 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7767 "monitor interface with '%s'", buf);
7768 return -2;
7769 }
7770 }
7771
7772 if (system("ifconfig sigmadut up") != 0) {
7773 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7774 "monitor interface up");
7775 return -2;
7776 }
7777
7778 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7779}
7780
7781
7782static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7783 struct sigma_conn *conn,
7784 struct sigma_cmd *cmd)
7785{
7786 const char *intf = get_param(cmd, "Interface");
7787 const char *dest = get_param(cmd, "Dest");
7788 const char *type = get_param(cmd, "FrameName");
7789 const char *val;
7790 char buf[200], *pos, *end;
7791 int count, count2;
7792
7793 if (type == NULL)
7794 type = get_param(cmd, "Type");
7795
7796 if (intf == NULL || dest == NULL || type == NULL)
7797 return -1;
7798
7799 if (strcasecmp(type, "NeighAdv") == 0)
7800 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7801
7802 if (strcasecmp(type, "NeighSolicitReq") == 0)
7803 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7804
7805 if (strcasecmp(type, "ARPProbe") == 0)
7806 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7807
7808 if (strcasecmp(type, "ARPAnnounce") == 0)
7809 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7810
7811 if (strcasecmp(type, "ARPReply") == 0)
7812 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7813
7814 if (strcasecmp(type, "DLS-request") == 0 ||
7815 strcasecmp(type, "DLSrequest") == 0)
7816 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7817 dest);
7818
7819 if (strcasecmp(type, "ANQPQuery") != 0 &&
7820 strcasecmp(type, "Query") != 0) {
7821 send_resp(dut, conn, SIGMA_ERROR,
7822 "ErrorCode,Unsupported HS 2.0 send frame type");
7823 return 0;
7824 }
7825
7826 if (sta_scan_ap(dut, intf, dest) < 0) {
7827 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7828 "the requested AP");
7829 return 0;
7830 }
7831
7832 pos = buf;
7833 end = buf + sizeof(buf);
7834 count = 0;
7835 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7836
7837 val = get_param(cmd, "ANQP_CAP_LIST");
7838 if (val && atoi(val)) {
7839 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7840 count++;
7841 }
7842
7843 val = get_param(cmd, "VENUE_NAME");
7844 if (val && atoi(val)) {
7845 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7846 count++;
7847 }
7848
7849 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7850 if (val && atoi(val)) {
7851 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7852 count++;
7853 }
7854
7855 val = get_param(cmd, "ROAMING_CONS");
7856 if (val && atoi(val)) {
7857 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7858 count++;
7859 }
7860
7861 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7862 if (val && atoi(val)) {
7863 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7864 count++;
7865 }
7866
7867 val = get_param(cmd, "NAI_REALM_LIST");
7868 if (val && atoi(val)) {
7869 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7870 count++;
7871 }
7872
7873 val = get_param(cmd, "3GPP_INFO");
7874 if (val && atoi(val)) {
7875 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7876 count++;
7877 }
7878
7879 val = get_param(cmd, "DOMAIN_LIST");
7880 if (val && atoi(val)) {
7881 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7882 count++;
7883 }
7884
Jouni Malinend3bca5d2018-04-29 17:25:23 +03007885 val = get_param(cmd, "Advice_Of_Charge");
7886 if (val && atoi(val)) {
7887 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
7888 count++;
7889 }
7890
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007891 if (count && wpa_command(intf, buf)) {
7892 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7893 return 0;
7894 }
7895
7896 pos = buf;
7897 end = buf + sizeof(buf);
7898 count2 = 0;
7899 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7900
7901 val = get_param(cmd, "HS_CAP_LIST");
7902 if (val && atoi(val)) {
7903 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7904 count2++;
7905 }
7906
7907 val = get_param(cmd, "OPER_NAME");
7908 if (val && atoi(val)) {
7909 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7910 count2++;
7911 }
7912
7913 val = get_param(cmd, "WAN_METRICS");
7914 if (!val)
7915 val = get_param(cmd, "WAN_MAT");
7916 if (!val)
7917 val = get_param(cmd, "WAN_MET");
7918 if (val && atoi(val)) {
7919 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7920 count2++;
7921 }
7922
7923 val = get_param(cmd, "CONNECTION_CAPABILITY");
7924 if (val && atoi(val)) {
7925 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7926 count2++;
7927 }
7928
7929 val = get_param(cmd, "OP_CLASS");
7930 if (val && atoi(val)) {
7931 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7932 count2++;
7933 }
7934
7935 val = get_param(cmd, "OSU_PROVIDER_LIST");
7936 if (val && atoi(val)) {
7937 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7938 count2++;
7939 }
7940
Jouni Malinenf67afec2018-04-29 19:24:58 +03007941 val = get_param(cmd, "OPER_ICON_METADATA");
7942 if (!val)
7943 val = get_param(cmd, "OPERATOR_ICON_METADATA");
7944 if (val && atoi(val)) {
7945 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
7946 count2++;
7947 }
7948
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007949 if (count && count2) {
7950 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7951 "second query");
7952 sleep(1);
7953 }
7954
7955 if (count2 && wpa_command(intf, buf)) {
7956 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7957 "failed");
7958 return 0;
7959 }
7960
7961 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7962 if (val) {
7963 if (count || count2) {
7964 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7965 "sending out second query");
7966 sleep(1);
7967 }
7968
7969 if (strcmp(val, "1") == 0)
7970 val = "mail.example.com";
7971 snprintf(buf, end - pos,
7972 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7973 dest, val);
7974 if (wpa_command(intf, buf)) {
7975 send_resp(dut, conn, SIGMA_ERROR,
7976 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7977 "failed");
7978 return 0;
7979 }
7980 }
7981
7982 val = get_param(cmd, "ICON_REQUEST");
7983 if (val) {
7984 if (count || count2) {
7985 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7986 "sending out second query");
7987 sleep(1);
7988 }
7989
7990 snprintf(buf, end - pos,
7991 "HS20_ICON_REQUEST %s %s", dest, val);
7992 if (wpa_command(intf, buf)) {
7993 send_resp(dut, conn, SIGMA_ERROR,
7994 "ErrorCode,HS20_ICON_REQUEST failed");
7995 return 0;
7996 }
7997 }
7998
7999 return 1;
8000}
8001
8002
8003static int ath_sta_send_frame_vht(struct sigma_dut *dut,
8004 struct sigma_conn *conn,
8005 struct sigma_cmd *cmd)
8006{
8007 const char *val;
8008 char *ifname;
8009 char buf[100];
8010 int chwidth, nss;
8011
8012 val = get_param(cmd, "framename");
8013 if (!val)
8014 return -1;
8015 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
8016
8017 /* Command sequence to generate Op mode notification */
8018 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
8019 ifname = get_station_ifname();
8020
8021 /* Disable STBC */
8022 snprintf(buf, sizeof(buf),
8023 "iwpriv %s tx_stbc 0", ifname);
8024 if (system(buf) != 0) {
8025 sigma_dut_print(dut, DUT_MSG_ERROR,
8026 "iwpriv tx_stbc 0 failed!");
8027 }
8028
8029 /* Extract Channel width */
8030 val = get_param(cmd, "Channel_width");
8031 if (val) {
8032 switch (atoi(val)) {
8033 case 20:
8034 chwidth = 0;
8035 break;
8036 case 40:
8037 chwidth = 1;
8038 break;
8039 case 80:
8040 chwidth = 2;
8041 break;
8042 case 160:
8043 chwidth = 3;
8044 break;
8045 default:
8046 chwidth = 2;
8047 break;
8048 }
8049
8050 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8051 ifname, chwidth);
8052 if (system(buf) != 0) {
8053 sigma_dut_print(dut, DUT_MSG_ERROR,
8054 "iwpriv chwidth failed!");
8055 }
8056 }
8057
8058 /* Extract NSS */
8059 val = get_param(cmd, "NSS");
8060 if (val) {
8061 switch (atoi(val)) {
8062 case 1:
8063 nss = 1;
8064 break;
8065 case 2:
8066 nss = 3;
8067 break;
8068 case 3:
8069 nss = 7;
8070 break;
8071 default:
8072 /* We do not support NSS > 3 */
8073 nss = 3;
8074 break;
8075 }
8076 snprintf(buf, sizeof(buf),
8077 "iwpriv %s rxchainmask %d", ifname, nss);
8078 if (system(buf) != 0) {
8079 sigma_dut_print(dut, DUT_MSG_ERROR,
8080 "iwpriv rxchainmask failed!");
8081 }
8082 }
8083
8084 /* Opmode notify */
8085 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
8086 if (system(buf) != 0) {
8087 sigma_dut_print(dut, DUT_MSG_ERROR,
8088 "iwpriv opmode_notify failed!");
8089 } else {
8090 sigma_dut_print(dut, DUT_MSG_INFO,
8091 "Sent out the notify frame!");
8092 }
8093 }
8094
8095 return 1;
8096}
8097
8098
8099static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
8100 struct sigma_conn *conn,
8101 struct sigma_cmd *cmd)
8102{
8103 switch (get_driver_type()) {
8104 case DRIVER_ATHEROS:
8105 return ath_sta_send_frame_vht(dut, conn, cmd);
8106 default:
8107 send_resp(dut, conn, SIGMA_ERROR,
8108 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
8109 return 0;
8110 }
8111}
8112
8113
Lior David0fe101e2017-03-09 16:09:50 +02008114#ifdef __linux__
8115int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8116 struct sigma_cmd *cmd)
8117{
8118 const char *frame_name = get_param(cmd, "framename");
8119 const char *mac = get_param(cmd, "dest_mac");
8120
8121 if (!frame_name || !mac) {
8122 sigma_dut_print(dut, DUT_MSG_ERROR,
8123 "framename and dest_mac must be provided");
8124 return -1;
8125 }
8126
8127 if (strcasecmp(frame_name, "brp") == 0) {
8128 const char *l_rx = get_param(cmd, "L-RX");
8129 int l_rx_i;
8130
8131 if (!l_rx) {
8132 sigma_dut_print(dut, DUT_MSG_ERROR,
8133 "L-RX must be provided");
8134 return -1;
8135 }
8136 l_rx_i = atoi(l_rx);
8137
8138 sigma_dut_print(dut, DUT_MSG_INFO,
8139 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
8140 mac, l_rx);
8141 if (l_rx_i != 16) {
8142 sigma_dut_print(dut, DUT_MSG_ERROR,
8143 "unsupported L-RX: %s", l_rx);
8144 return -1;
8145 }
8146
8147 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
8148 return -1;
8149 } else if (strcasecmp(frame_name, "ssw") == 0) {
8150 sigma_dut_print(dut, DUT_MSG_INFO,
8151 "dev_send_frame: SLS, dest_mac %s", mac);
8152 if (wil6210_send_sls(dut, mac))
8153 return -1;
8154 } else {
8155 sigma_dut_print(dut, DUT_MSG_ERROR,
8156 "unsupported frame type: %s", frame_name);
8157 return -1;
8158 }
8159
8160 return 1;
8161}
8162#endif /* __linux__ */
8163
8164
8165static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
8166 struct sigma_conn *conn,
8167 struct sigma_cmd *cmd)
8168{
8169 switch (get_driver_type()) {
8170#ifdef __linux__
8171 case DRIVER_WIL6210:
8172 return wil6210_send_frame_60g(dut, conn, cmd);
8173#endif /* __linux__ */
8174 default:
8175 send_resp(dut, conn, SIGMA_ERROR,
8176 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
8177 return 0;
8178 }
8179}
8180
8181
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308182static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
8183 const char *intf, struct sigma_cmd *cmd)
8184{
8185 const char *val, *addr;
8186 char buf[100];
8187
8188 addr = get_param(cmd, "DestMac");
8189 if (!addr) {
8190 send_resp(dut, conn, SIGMA_INVALID,
8191 "ErrorCode,AP MAC address is missing");
8192 return 0;
8193 }
8194
8195 val = get_param(cmd, "ANQPQuery_ID");
8196 if (!val) {
8197 send_resp(dut, conn, SIGMA_INVALID,
8198 "ErrorCode,Missing ANQPQuery_ID");
8199 return 0;
8200 }
8201
8202 if (strcasecmp(val, "NeighborReportReq") == 0) {
8203 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
8204 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
8205 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
8206 } else {
8207 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
8208 val);
8209 send_resp(dut, conn, SIGMA_INVALID,
8210 "ErrorCode,Invalid ANQPQuery_ID");
8211 return 0;
8212 }
8213
Ashwini Patild174f2c2017-04-13 16:49:46 +05308214 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
8215 * (Address3 = Wildcard BSSID when sent to not-associated AP;
8216 * if associated, AP BSSID).
8217 */
8218 if (wpa_command(intf, "SET gas_address3 1") < 0) {
8219 send_resp(dut, conn, SIGMA_ERROR,
8220 "ErrorCode,Failed to set gas_address3");
8221 return 0;
8222 }
8223
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308224 if (wpa_command(intf, buf) < 0) {
8225 send_resp(dut, conn, SIGMA_ERROR,
8226 "ErrorCode,Failed to send ANQP query");
8227 return 0;
8228 }
8229
8230 return 1;
8231}
8232
8233
8234static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
8235 struct sigma_conn *conn,
8236 const char *intf,
8237 struct sigma_cmd *cmd)
8238{
8239 const char *val = get_param(cmd, "FrameName");
8240
8241 if (val && strcasecmp(val, "ANQPQuery") == 0)
8242 return mbo_send_anqp_query(dut, conn, intf, cmd);
8243
8244 return 2;
8245}
8246
8247
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008248int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8249 struct sigma_cmd *cmd)
8250{
8251 const char *intf = get_param(cmd, "Interface");
8252 const char *val;
8253 enum send_frame_type frame;
8254 enum send_frame_protection protected;
8255 char buf[100];
8256 unsigned char addr[ETH_ALEN];
8257 int res;
8258
8259 val = get_param(cmd, "program");
8260 if (val == NULL)
8261 val = get_param(cmd, "frame");
8262 if (val && strcasecmp(val, "TDLS") == 0)
8263 return cmd_sta_send_frame_tdls(dut, conn, cmd);
8264 if (val && (strcasecmp(val, "HS2") == 0 ||
8265 strcasecmp(val, "HS2-R2") == 0))
8266 return cmd_sta_send_frame_hs2(dut, conn, cmd);
8267 if (val && strcasecmp(val, "VHT") == 0)
8268 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008269 if (val && strcasecmp(val, "LOC") == 0)
8270 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02008271 if (val && strcasecmp(val, "60GHz") == 0)
8272 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308273 if (val && strcasecmp(val, "MBO") == 0) {
8274 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
8275 if (res != 2)
8276 return res;
8277 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008278
8279 val = get_param(cmd, "TD_DISC");
8280 if (val) {
8281 if (hwaddr_aton(val, addr) < 0)
8282 return -1;
8283 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
8284 if (wpa_command(intf, buf) < 0) {
8285 send_resp(dut, conn, SIGMA_ERROR,
8286 "ErrorCode,Failed to send TDLS discovery");
8287 return 0;
8288 }
8289 return 1;
8290 }
8291
8292 val = get_param(cmd, "TD_Setup");
8293 if (val) {
8294 if (hwaddr_aton(val, addr) < 0)
8295 return -1;
8296 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
8297 if (wpa_command(intf, buf) < 0) {
8298 send_resp(dut, conn, SIGMA_ERROR,
8299 "ErrorCode,Failed to start TDLS setup");
8300 return 0;
8301 }
8302 return 1;
8303 }
8304
8305 val = get_param(cmd, "TD_TearDown");
8306 if (val) {
8307 if (hwaddr_aton(val, addr) < 0)
8308 return -1;
8309 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
8310 if (wpa_command(intf, buf) < 0) {
8311 send_resp(dut, conn, SIGMA_ERROR,
8312 "ErrorCode,Failed to tear down TDLS link");
8313 return 0;
8314 }
8315 return 1;
8316 }
8317
8318 val = get_param(cmd, "TD_ChannelSwitch");
8319 if (val) {
8320 /* TODO */
8321 send_resp(dut, conn, SIGMA_ERROR,
8322 "ErrorCode,TD_ChannelSwitch not yet supported");
8323 return 0;
8324 }
8325
8326 val = get_param(cmd, "TD_NF");
8327 if (val) {
8328 /* TODO */
8329 send_resp(dut, conn, SIGMA_ERROR,
8330 "ErrorCode,TD_NF not yet supported");
8331 return 0;
8332 }
8333
8334 val = get_param(cmd, "PMFFrameType");
8335 if (val == NULL)
8336 val = get_param(cmd, "FrameName");
8337 if (val == NULL)
8338 val = get_param(cmd, "Type");
8339 if (val == NULL)
8340 return -1;
8341 if (strcasecmp(val, "disassoc") == 0)
8342 frame = DISASSOC;
8343 else if (strcasecmp(val, "deauth") == 0)
8344 frame = DEAUTH;
8345 else if (strcasecmp(val, "saquery") == 0)
8346 frame = SAQUERY;
8347 else if (strcasecmp(val, "auth") == 0)
8348 frame = AUTH;
8349 else if (strcasecmp(val, "assocreq") == 0)
8350 frame = ASSOCREQ;
8351 else if (strcasecmp(val, "reassocreq") == 0)
8352 frame = REASSOCREQ;
8353 else if (strcasecmp(val, "neigreq") == 0) {
8354 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
8355
8356 val = get_param(cmd, "ssid");
8357 if (val == NULL)
8358 return -1;
8359
8360 res = send_neighbor_request(dut, intf, val);
8361 if (res) {
8362 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8363 "Failed to send neighbor report request");
8364 return 0;
8365 }
8366
8367 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308368 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
8369 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008370 sigma_dut_print(dut, DUT_MSG_DEBUG,
8371 "Got Transition Management Query");
8372
Ashwini Patil5acd7382017-04-13 15:55:04 +05308373 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008374 if (res) {
8375 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8376 "Failed to send Transition Management Query");
8377 return 0;
8378 }
8379
8380 return 1;
8381 } else {
8382 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8383 "PMFFrameType");
8384 return 0;
8385 }
8386
8387 val = get_param(cmd, "PMFProtected");
8388 if (val == NULL)
8389 val = get_param(cmd, "Protected");
8390 if (val == NULL)
8391 return -1;
8392 if (strcasecmp(val, "Correct-key") == 0 ||
8393 strcasecmp(val, "CorrectKey") == 0)
8394 protected = CORRECT_KEY;
8395 else if (strcasecmp(val, "IncorrectKey") == 0)
8396 protected = INCORRECT_KEY;
8397 else if (strcasecmp(val, "Unprotected") == 0)
8398 protected = UNPROTECTED;
8399 else {
8400 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8401 "PMFProtected");
8402 return 0;
8403 }
8404
8405 if (protected != UNPROTECTED &&
8406 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
8407 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
8408 "PMFProtected for auth/assocreq/reassocreq");
8409 return 0;
8410 }
8411
8412 if (if_nametoindex("sigmadut") == 0) {
8413 snprintf(buf, sizeof(buf),
8414 "iw dev %s interface add sigmadut type monitor",
8415 get_station_ifname());
8416 if (system(buf) != 0 ||
8417 if_nametoindex("sigmadut") == 0) {
8418 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8419 "monitor interface with '%s'", buf);
8420 return -2;
8421 }
8422 }
8423
8424 if (system("ifconfig sigmadut up") != 0) {
8425 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8426 "monitor interface up");
8427 return -2;
8428 }
8429
8430 return sta_inject_frame(dut, conn, frame, protected, NULL);
8431}
8432
8433
8434static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
8435 struct sigma_conn *conn,
8436 struct sigma_cmd *cmd,
8437 const char *ifname)
8438{
8439 char buf[200];
8440 const char *val;
8441
8442 val = get_param(cmd, "ClearARP");
8443 if (val && atoi(val) == 1) {
8444 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
8445 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8446 if (system(buf) != 0) {
8447 send_resp(dut, conn, SIGMA_ERROR,
8448 "errorCode,Failed to clear ARP cache");
8449 return 0;
8450 }
8451 }
8452
8453 return 1;
8454}
8455
8456
8457int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
8458 struct sigma_cmd *cmd)
8459{
8460 const char *intf = get_param(cmd, "Interface");
8461 const char *val;
8462
8463 if (intf == NULL)
8464 return -1;
8465
8466 val = get_param(cmd, "program");
8467 if (val && (strcasecmp(val, "HS2") == 0 ||
8468 strcasecmp(val, "HS2-R2") == 0))
8469 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
8470
8471 return -1;
8472}
8473
8474
8475static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
8476 struct sigma_cmd *cmd)
8477{
8478 const char *intf = get_param(cmd, "Interface");
8479 const char *mac = get_param(cmd, "MAC");
8480
8481 if (intf == NULL || mac == NULL)
8482 return -1;
8483
8484 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
8485 "interface %s to %s", intf, mac);
8486
8487 if (dut->set_macaddr) {
8488 char buf[128];
8489 int res;
8490 if (strcasecmp(mac, "default") == 0) {
8491 res = snprintf(buf, sizeof(buf), "%s",
8492 dut->set_macaddr);
8493 dut->tmp_mac_addr = 0;
8494 } else {
8495 res = snprintf(buf, sizeof(buf), "%s %s",
8496 dut->set_macaddr, mac);
8497 dut->tmp_mac_addr = 1;
8498 }
8499 if (res < 0 || res >= (int) sizeof(buf))
8500 return -1;
8501 if (system(buf) != 0) {
8502 send_resp(dut, conn, SIGMA_ERROR,
8503 "errorCode,Failed to set MAC "
8504 "address");
8505 return 0;
8506 }
8507 return 1;
8508 }
8509
8510 if (strcasecmp(mac, "default") == 0)
8511 return 1;
8512
8513 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8514 "command");
8515 return 0;
8516}
8517
8518
8519static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
8520 struct sigma_conn *conn, const char *intf,
8521 int val)
8522{
8523 char buf[200];
8524 int res;
8525
8526 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
8527 intf, val);
8528 if (res < 0 || res >= (int) sizeof(buf))
8529 return -1;
8530 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8531 if (system(buf) != 0) {
8532 send_resp(dut, conn, SIGMA_ERROR,
8533 "errorCode,Failed to configure offchannel mode");
8534 return 0;
8535 }
8536
8537 return 1;
8538}
8539
8540
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008541static int off_chan_val(enum sec_ch_offset off)
8542{
8543 switch (off) {
8544 case SEC_CH_NO:
8545 return 0;
8546 case SEC_CH_40ABOVE:
8547 return 40;
8548 case SEC_CH_40BELOW:
8549 return -40;
8550 }
8551
8552 return 0;
8553}
8554
8555
8556static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
8557 const char *intf, int off_ch_num,
8558 enum sec_ch_offset sec)
8559{
8560 char buf[200];
8561 int res;
8562
8563 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
8564 intf, off_ch_num);
8565 if (res < 0 || res >= (int) sizeof(buf))
8566 return -1;
8567 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8568 if (system(buf) != 0) {
8569 send_resp(dut, conn, SIGMA_ERROR,
8570 "errorCode,Failed to set offchan");
8571 return 0;
8572 }
8573
8574 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
8575 intf, off_chan_val(sec));
8576 if (res < 0 || res >= (int) sizeof(buf))
8577 return -1;
8578 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8579 if (system(buf) != 0) {
8580 send_resp(dut, conn, SIGMA_ERROR,
8581 "errorCode,Failed to set sec chan offset");
8582 return 0;
8583 }
8584
8585 return 1;
8586}
8587
8588
8589static int tdls_set_offchannel_offset(struct sigma_dut *dut,
8590 struct sigma_conn *conn,
8591 const char *intf, int off_ch_num,
8592 enum sec_ch_offset sec)
8593{
8594 char buf[200];
8595 int res;
8596
8597 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
8598 off_ch_num);
8599 if (res < 0 || res >= (int) sizeof(buf))
8600 return -1;
8601 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8602
8603 if (wpa_command(intf, buf) < 0) {
8604 send_resp(dut, conn, SIGMA_ERROR,
8605 "ErrorCode,Failed to set offchan");
8606 return 0;
8607 }
8608 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
8609 off_chan_val(sec));
8610 if (res < 0 || res >= (int) sizeof(buf))
8611 return -1;
8612
8613 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8614
8615 if (wpa_command(intf, buf) < 0) {
8616 send_resp(dut, conn, SIGMA_ERROR,
8617 "ErrorCode,Failed to set sec chan offset");
8618 return 0;
8619 }
8620
8621 return 1;
8622}
8623
8624
8625static int tdls_set_offchannel_mode(struct sigma_dut *dut,
8626 struct sigma_conn *conn,
8627 const char *intf, int val)
8628{
8629 char buf[200];
8630 int res;
8631
8632 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
8633 val);
8634 if (res < 0 || res >= (int) sizeof(buf))
8635 return -1;
8636 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8637
8638 if (wpa_command(intf, buf) < 0) {
8639 send_resp(dut, conn, SIGMA_ERROR,
8640 "ErrorCode,Failed to configure offchannel mode");
8641 return 0;
8642 }
8643
8644 return 1;
8645}
8646
8647
8648static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
8649 struct sigma_conn *conn,
8650 struct sigma_cmd *cmd)
8651{
8652 const char *val;
8653 enum {
8654 CHSM_NOT_SET,
8655 CHSM_ENABLE,
8656 CHSM_DISABLE,
8657 CHSM_REJREQ,
8658 CHSM_UNSOLRESP
8659 } chsm = CHSM_NOT_SET;
8660 int off_ch_num = -1;
8661 enum sec_ch_offset sec_ch = SEC_CH_NO;
8662 int res;
8663
8664 val = get_param(cmd, "Uapsd");
8665 if (val) {
8666 char buf[100];
8667 if (strcasecmp(val, "Enable") == 0)
8668 snprintf(buf, sizeof(buf), "SET ps 99");
8669 else if (strcasecmp(val, "Disable") == 0)
8670 snprintf(buf, sizeof(buf), "SET ps 98");
8671 else {
8672 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8673 "Unsupported uapsd parameter value");
8674 return 0;
8675 }
8676 if (wpa_command(intf, buf)) {
8677 send_resp(dut, conn, SIGMA_ERROR,
8678 "ErrorCode,Failed to change U-APSD "
8679 "powersave mode");
8680 return 0;
8681 }
8682 }
8683
8684 val = get_param(cmd, "TPKTIMER");
8685 if (val && strcasecmp(val, "DISABLE") == 0) {
8686 if (wpa_command(intf, "SET tdls_testing 0x100")) {
8687 send_resp(dut, conn, SIGMA_ERROR,
8688 "ErrorCode,Failed to enable no TPK "
8689 "expiration test mode");
8690 return 0;
8691 }
8692 dut->no_tpk_expiration = 1;
8693 }
8694
8695 val = get_param(cmd, "ChSwitchMode");
8696 if (val) {
8697 if (strcasecmp(val, "Enable") == 0 ||
8698 strcasecmp(val, "Initiate") == 0)
8699 chsm = CHSM_ENABLE;
8700 else if (strcasecmp(val, "Disable") == 0 ||
8701 strcasecmp(val, "passive") == 0)
8702 chsm = CHSM_DISABLE;
8703 else if (strcasecmp(val, "RejReq") == 0)
8704 chsm = CHSM_REJREQ;
8705 else if (strcasecmp(val, "UnSolResp") == 0)
8706 chsm = CHSM_UNSOLRESP;
8707 else {
8708 send_resp(dut, conn, SIGMA_ERROR,
8709 "ErrorCode,Unknown ChSwitchMode value");
8710 return 0;
8711 }
8712 }
8713
8714 val = get_param(cmd, "OffChNum");
8715 if (val) {
8716 off_ch_num = atoi(val);
8717 if (off_ch_num == 0) {
8718 send_resp(dut, conn, SIGMA_ERROR,
8719 "ErrorCode,Invalid OffChNum");
8720 return 0;
8721 }
8722 }
8723
8724 val = get_param(cmd, "SecChOffset");
8725 if (val) {
8726 if (strcmp(val, "20") == 0)
8727 sec_ch = SEC_CH_NO;
8728 else if (strcasecmp(val, "40above") == 0)
8729 sec_ch = SEC_CH_40ABOVE;
8730 else if (strcasecmp(val, "40below") == 0)
8731 sec_ch = SEC_CH_40BELOW;
8732 else {
8733 send_resp(dut, conn, SIGMA_ERROR,
8734 "ErrorCode,Unknown SecChOffset value");
8735 return 0;
8736 }
8737 }
8738
8739 if (chsm == CHSM_NOT_SET) {
8740 /* no offchannel changes requested */
8741 return 1;
8742 }
8743
8744 if (strcmp(intf, get_main_ifname()) != 0 &&
8745 strcmp(intf, get_station_ifname()) != 0) {
8746 send_resp(dut, conn, SIGMA_ERROR,
8747 "ErrorCode,Unknown interface");
8748 return 0;
8749 }
8750
8751 switch (chsm) {
8752 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008753 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008754 break;
8755 case CHSM_ENABLE:
8756 if (off_ch_num < 0) {
8757 send_resp(dut, conn, SIGMA_ERROR,
8758 "ErrorCode,Missing OffChNum argument");
8759 return 0;
8760 }
8761 if (wifi_chip_type == DRIVER_WCN) {
8762 res = tdls_set_offchannel_offset(dut, conn, intf,
8763 off_ch_num, sec_ch);
8764 } else {
8765 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8766 sec_ch);
8767 }
8768 if (res != 1)
8769 return res;
8770 if (wifi_chip_type == DRIVER_WCN)
8771 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8772 else
8773 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8774 break;
8775 case CHSM_DISABLE:
8776 if (wifi_chip_type == DRIVER_WCN)
8777 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8778 else
8779 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8780 break;
8781 case CHSM_REJREQ:
8782 if (wifi_chip_type == DRIVER_WCN)
8783 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8784 else
8785 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8786 break;
8787 case CHSM_UNSOLRESP:
8788 if (off_ch_num < 0) {
8789 send_resp(dut, conn, SIGMA_ERROR,
8790 "ErrorCode,Missing OffChNum argument");
8791 return 0;
8792 }
8793 if (wifi_chip_type == DRIVER_WCN) {
8794 res = tdls_set_offchannel_offset(dut, conn, intf,
8795 off_ch_num, sec_ch);
8796 } else {
8797 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8798 sec_ch);
8799 }
8800 if (res != 1)
8801 return res;
8802 if (wifi_chip_type == DRIVER_WCN)
8803 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8804 else
8805 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8806 break;
8807 }
8808
8809 return res;
8810}
8811
8812
8813static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8814 struct sigma_conn *conn,
8815 struct sigma_cmd *cmd)
8816{
8817 const char *val;
8818 char *token, *result;
8819
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008820 novap_reset(dut, intf);
8821
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008822 val = get_param(cmd, "nss_mcs_opt");
8823 if (val) {
8824 /* String (nss_operating_mode; mcs_operating_mode) */
8825 int nss, mcs;
8826 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308827 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008828
8829 token = strdup(val);
8830 if (!token)
8831 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308832 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308833 if (!result) {
8834 sigma_dut_print(dut, DUT_MSG_ERROR,
8835 "VHT NSS not specified");
8836 goto failed;
8837 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008838 if (strcasecmp(result, "def") != 0) {
8839 nss = atoi(result);
8840 if (nss == 4)
8841 ath_disable_txbf(dut, intf);
8842 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8843 intf, nss);
8844 if (system(buf) != 0) {
8845 sigma_dut_print(dut, DUT_MSG_ERROR,
8846 "iwpriv nss failed");
8847 goto failed;
8848 }
8849 }
8850
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308851 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308852 if (!result) {
8853 sigma_dut_print(dut, DUT_MSG_ERROR,
8854 "VHT MCS not specified");
8855 goto failed;
8856 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008857 if (strcasecmp(result, "def") == 0) {
8858 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8859 intf);
8860 if (system(buf) != 0) {
8861 sigma_dut_print(dut, DUT_MSG_ERROR,
8862 "iwpriv set11NRates failed");
8863 goto failed;
8864 }
8865
8866 } else {
8867 mcs = atoi(result);
8868 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8869 intf, mcs);
8870 if (system(buf) != 0) {
8871 sigma_dut_print(dut, DUT_MSG_ERROR,
8872 "iwpriv vhtmcs failed");
8873 goto failed;
8874 }
8875 }
8876 /* Channel width gets messed up, fix this */
8877 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8878 intf, dut->chwidth);
8879 if (system(buf) != 0) {
8880 sigma_dut_print(dut, DUT_MSG_ERROR,
8881 "iwpriv chwidth failed");
8882 }
8883 }
8884
8885 return 1;
8886failed:
8887 free(token);
8888 return 0;
8889}
8890
8891
8892static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8893 struct sigma_conn *conn,
8894 struct sigma_cmd *cmd)
8895{
8896 switch (get_driver_type()) {
8897 case DRIVER_ATHEROS:
8898 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8899 default:
8900 send_resp(dut, conn, SIGMA_ERROR,
8901 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8902 return 0;
8903 }
8904}
8905
8906
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008907static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8908 struct sigma_conn *conn,
8909 struct sigma_cmd *cmd)
8910{
8911 const char *val;
8912 char *token = NULL, *result;
8913 char buf[60];
8914
8915 val = get_param(cmd, "nss_mcs_opt");
8916 if (val) {
8917 /* String (nss_operating_mode; mcs_operating_mode) */
8918 int nss, mcs, ratecode;
8919 char *saveptr;
8920
8921 token = strdup(val);
8922 if (!token)
8923 return -2;
8924
8925 result = strtok_r(token, ";", &saveptr);
8926 if (!result) {
8927 sigma_dut_print(dut, DUT_MSG_ERROR,
8928 "HE NSS not specified");
8929 goto failed;
8930 }
8931 nss = 1;
8932 if (strcasecmp(result, "def") != 0)
8933 nss = atoi(result);
8934
8935 result = strtok_r(NULL, ";", &saveptr);
8936 if (!result) {
8937 sigma_dut_print(dut, DUT_MSG_ERROR,
8938 "HE MCS not specified");
8939 goto failed;
8940 }
8941 mcs = 7;
8942 if (strcasecmp(result, "def") != 0)
8943 mcs = atoi(result);
8944
8945 ratecode = 0x400; /* for nss:1 MCS 0 */
8946 if (nss == 2) {
8947 ratecode = 0x420; /* for nss:2 MCS 0 */
8948 } else if (nss > 2) {
8949 sigma_dut_print(dut, DUT_MSG_ERROR,
8950 "HE NSS %d not supported", nss);
8951 goto failed;
8952 }
8953
8954 /* Add the MCS to the ratecode */
8955 if (mcs >= 0 && mcs <= 11) {
8956 ratecode += mcs;
8957 } else {
8958 sigma_dut_print(dut, DUT_MSG_ERROR,
8959 "HE MCS %d not supported", mcs);
8960 goto failed;
8961 }
8962 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8963 intf, ratecode);
8964 if (system(buf) != 0) {
8965 sigma_dut_print(dut, DUT_MSG_ERROR,
8966 "iwpriv setting of 11ax rates failed");
8967 goto failed;
8968 }
8969 free(token);
8970 }
8971
8972 val = get_param(cmd, "GI");
8973 if (val) {
8974 if (strcmp(val, "0.8") == 0) {
8975 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8976 } else if (strcmp(val, "1.6") == 0) {
8977 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8978 } else if (strcmp(val, "3.2") == 0) {
8979 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8980 } else {
8981 send_resp(dut, conn, SIGMA_ERROR,
8982 "errorCode,GI value not supported");
8983 return 0;
8984 }
8985 if (system(buf) != 0) {
8986 send_resp(dut, conn, SIGMA_ERROR,
8987 "errorCode,Failed to set shortgi");
8988 return 0;
8989 }
8990 }
8991
8992 return 1;
8993
8994failed:
8995 free(token);
8996 return -2;
8997}
8998
8999
9000static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9001 struct sigma_conn *conn,
9002 struct sigma_cmd *cmd)
9003{
9004 switch (get_driver_type()) {
9005 case DRIVER_WCN:
9006 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
9007 default:
9008 send_resp(dut, conn, SIGMA_ERROR,
9009 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
9010 return 0;
9011 }
9012}
9013
9014
Ashwini Patil5acd7382017-04-13 15:55:04 +05309015static int btm_query_candidate_list(struct sigma_dut *dut,
9016 struct sigma_conn *conn,
9017 struct sigma_cmd *cmd)
9018{
9019 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
9020 int len, ret;
9021 char buf[10];
9022
9023 /*
9024 * Neighbor Report elements format:
9025 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
9026 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
9027 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
9028 */
9029
9030 bssid = get_param(cmd, "Nebor_BSSID");
9031 if (!bssid) {
9032 send_resp(dut, conn, SIGMA_INVALID,
9033 "errorCode,Nebor_BSSID is missing");
9034 return 0;
9035 }
9036
9037 info = get_param(cmd, "Nebor_Bssid_Info");
9038 if (!info) {
9039 sigma_dut_print(dut, DUT_MSG_INFO,
9040 "Using default value for Nebor_Bssid_Info: %s",
9041 DEFAULT_NEIGHBOR_BSSID_INFO);
9042 info = DEFAULT_NEIGHBOR_BSSID_INFO;
9043 }
9044
9045 op_class = get_param(cmd, "Nebor_Op_Class");
9046 if (!op_class) {
9047 send_resp(dut, conn, SIGMA_INVALID,
9048 "errorCode,Nebor_Op_Class is missing");
9049 return 0;
9050 }
9051
9052 ch = get_param(cmd, "Nebor_Op_Ch");
9053 if (!ch) {
9054 send_resp(dut, conn, SIGMA_INVALID,
9055 "errorCode,Nebor_Op_Ch is missing");
9056 return 0;
9057 }
9058
9059 phy_type = get_param(cmd, "Nebor_Phy_Type");
9060 if (!phy_type) {
9061 sigma_dut_print(dut, DUT_MSG_INFO,
9062 "Using default value for Nebor_Phy_Type: %s",
9063 DEFAULT_NEIGHBOR_PHY_TYPE);
9064 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
9065 }
9066
9067 /* Parse optional subelements */
9068 buf[0] = '\0';
9069 pref = get_param(cmd, "Nebor_Pref");
9070 if (pref) {
9071 /* hexdump for preferrence subelement */
9072 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
9073 if (ret < 0 || ret >= (int) sizeof(buf)) {
9074 sigma_dut_print(dut, DUT_MSG_ERROR,
9075 "snprintf failed for optional subelement ret: %d",
9076 ret);
9077 send_resp(dut, conn, SIGMA_ERROR,
9078 "errorCode,snprintf failed for subelement");
9079 return 0;
9080 }
9081 }
9082
9083 if (!dut->btm_query_cand_list) {
9084 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
9085 if (!dut->btm_query_cand_list) {
9086 send_resp(dut, conn, SIGMA_ERROR,
9087 "errorCode,Failed to allocate memory for btm_query_cand_list");
9088 return 0;
9089 }
9090 }
9091
9092 len = strlen(dut->btm_query_cand_list);
9093 ret = snprintf(dut->btm_query_cand_list + len,
9094 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
9095 bssid, info, op_class, ch, phy_type, buf);
9096 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
9097 sigma_dut_print(dut, DUT_MSG_ERROR,
9098 "snprintf failed for neighbor report list ret: %d",
9099 ret);
9100 send_resp(dut, conn, SIGMA_ERROR,
9101 "errorCode,snprintf failed for neighbor report");
9102 free(dut->btm_query_cand_list);
9103 dut->btm_query_cand_list = NULL;
9104 return 0;
9105 }
9106
9107 return 1;
9108}
9109
9110
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009111static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
9112 struct sigma_cmd *cmd)
9113{
9114 const char *intf = get_param(cmd, "Interface");
9115 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309116 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009117
9118 if (intf == NULL || prog == NULL)
9119 return -1;
9120
Ashwini Patil5acd7382017-04-13 15:55:04 +05309121 /* BSS Transition candidate list for BTM query */
9122 val = get_param(cmd, "Nebor_BSSID");
9123 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
9124 return 0;
9125
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009126 if (strcasecmp(prog, "TDLS") == 0)
9127 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
9128
9129 if (strcasecmp(prog, "VHT") == 0)
9130 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
9131
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009132 if (strcasecmp(prog, "HE") == 0)
9133 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
9134
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309135 if (strcasecmp(prog, "MBO") == 0) {
9136 val = get_param(cmd, "Cellular_Data_Cap");
9137 if (val &&
9138 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
9139 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05309140
9141 val = get_param(cmd, "Ch_Pref");
9142 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
9143 return 0;
9144
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309145 return 1;
9146 }
9147
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009148 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
9149 return 0;
9150}
9151
9152
9153static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
9154 struct sigma_cmd *cmd)
9155{
9156 const char *intf = get_param(cmd, "Interface");
9157 const char *mode = get_param(cmd, "Mode");
9158 int res;
9159
9160 if (intf == NULL || mode == NULL)
9161 return -1;
9162
9163 if (strcasecmp(mode, "On") == 0)
9164 res = wpa_command(intf, "SET radio_disabled 0");
9165 else if (strcasecmp(mode, "Off") == 0)
9166 res = wpa_command(intf, "SET radio_disabled 1");
9167 else
9168 return -1;
9169
9170 if (res) {
9171 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
9172 "radio mode");
9173 return 0;
9174 }
9175
9176 return 1;
9177}
9178
9179
9180static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
9181 struct sigma_cmd *cmd)
9182{
9183 const char *intf = get_param(cmd, "Interface");
9184 const char *mode = get_param(cmd, "Mode");
9185 int res;
9186
9187 if (intf == NULL || mode == NULL)
9188 return -1;
9189
9190 if (strcasecmp(mode, "On") == 0)
9191 res = set_ps(intf, dut, 1);
9192 else if (strcasecmp(mode, "Off") == 0)
9193 res = set_ps(intf, dut, 0);
9194 else
9195 return -1;
9196
9197 if (res) {
9198 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
9199 "power save mode");
9200 return 0;
9201 }
9202
9203 return 1;
9204}
9205
9206
9207static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
9208 struct sigma_cmd *cmd)
9209{
9210 const char *intf = get_param(cmd, "Interface");
9211 const char *val, *bssid;
9212 int res;
9213 char *buf;
9214 size_t buf_len;
9215
9216 val = get_param(cmd, "BSSID_FILTER");
9217 if (val == NULL)
9218 return -1;
9219
9220 bssid = get_param(cmd, "BSSID_List");
9221 if (atoi(val) == 0 || bssid == NULL) {
9222 /* Disable BSSID filter */
9223 if (wpa_command(intf, "SET bssid_filter ")) {
9224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
9225 "to disable BSSID filter");
9226 return 0;
9227 }
9228
9229 return 1;
9230 }
9231
9232 buf_len = 100 + strlen(bssid);
9233 buf = malloc(buf_len);
9234 if (buf == NULL)
9235 return -1;
9236
9237 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
9238 res = wpa_command(intf, buf);
9239 free(buf);
9240 if (res) {
9241 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
9242 "BSSID filter");
9243 return 0;
9244 }
9245
9246 return 1;
9247}
9248
9249
9250static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
9251 struct sigma_cmd *cmd)
9252{
9253 const char *intf = get_param(cmd, "Interface");
9254 const char *val;
9255
9256 /* TODO: ARP */
9257
9258 val = get_param(cmd, "HS2_CACHE_PROFILE");
9259 if (val && strcasecmp(val, "All") == 0)
9260 hs2_clear_credentials(intf);
9261
9262 return 1;
9263}
9264
9265
9266static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
9267 struct sigma_cmd *cmd)
9268{
9269 const char *intf = get_param(cmd, "Interface");
9270 const char *key_type = get_param(cmd, "KeyType");
9271 char buf[100], resp[200];
9272
9273 if (key_type == NULL)
9274 return -1;
9275
9276 if (strcasecmp(key_type, "GTK") == 0) {
9277 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
9278 strncmp(buf, "FAIL", 4) == 0) {
9279 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9280 "not fetch current GTK");
9281 return 0;
9282 }
9283 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
9284 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9285 return 0;
9286 } else {
9287 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9288 "KeyType");
9289 return 0;
9290 }
9291
9292 return 1;
9293}
9294
9295
9296static int hs2_set_policy(struct sigma_dut *dut)
9297{
9298#ifdef ANDROID
9299 system("ip rule del prio 23000");
9300 if (system("ip rule add from all lookup main prio 23000") != 0) {
9301 sigma_dut_print(dut, DUT_MSG_ERROR,
9302 "Failed to run:ip rule add from all lookup main prio");
9303 return -1;
9304 }
9305 if (system("ip route flush cache") != 0) {
9306 sigma_dut_print(dut, DUT_MSG_ERROR,
9307 "Failed to run ip route flush cache");
9308 return -1;
9309 }
9310 return 1;
9311#else /* ANDROID */
9312 return 0;
9313#endif /* ANDROID */
9314}
9315
9316
9317static int cmd_sta_hs2_associate(struct sigma_dut *dut,
9318 struct sigma_conn *conn,
9319 struct sigma_cmd *cmd)
9320{
9321 const char *intf = get_param(cmd, "Interface");
9322 const char *val = get_param(cmd, "Ignore_blacklist");
9323 struct wpa_ctrl *ctrl;
9324 int res;
9325 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
9326 int tries = 0;
9327 int ignore_blacklist = 0;
9328 const char *events[] = {
9329 "CTRL-EVENT-CONNECTED",
9330 "INTERWORKING-BLACKLISTED",
9331 "INTERWORKING-NO-MATCH",
9332 NULL
9333 };
9334
9335 start_sta_mode(dut);
9336
9337 blacklisted[0] = '\0';
9338 if (val && atoi(val))
9339 ignore_blacklist = 1;
9340
9341try_again:
9342 ctrl = open_wpa_mon(intf);
9343 if (ctrl == NULL) {
9344 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9345 "wpa_supplicant monitor connection");
9346 return -2;
9347 }
9348
9349 tries++;
9350 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
9351 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
9352 "Interworking connection");
9353 wpa_ctrl_detach(ctrl);
9354 wpa_ctrl_close(ctrl);
9355 return 0;
9356 }
9357
9358 buf[0] = '\0';
9359 while (1) {
9360 char *pos;
9361 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9362 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
9363 if (!pos)
9364 break;
9365 pos += 25;
9366 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
9367 pos);
9368 if (!blacklisted[0])
9369 memcpy(blacklisted, pos, strlen(pos) + 1);
9370 }
9371
9372 if (ignore_blacklist && blacklisted[0]) {
9373 char *end;
9374 end = strchr(blacklisted, ' ');
9375 if (end)
9376 *end = '\0';
9377 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
9378 blacklisted);
9379 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
9380 blacklisted);
9381 if (wpa_command(intf, buf)) {
9382 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
9383 wpa_ctrl_detach(ctrl);
9384 wpa_ctrl_close(ctrl);
9385 return 0;
9386 }
9387 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9388 buf, sizeof(buf));
9389 }
9390
9391 wpa_ctrl_detach(ctrl);
9392 wpa_ctrl_close(ctrl);
9393
9394 if (res < 0) {
9395 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
9396 "connect");
9397 return 0;
9398 }
9399
9400 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
9401 strstr(buf, "INTERWORKING-BLACKLISTED")) {
9402 if (tries < 2) {
9403 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
9404 goto try_again;
9405 }
9406 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
9407 "matching credentials found");
9408 return 0;
9409 }
9410
9411 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9412 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9413 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
9414 "get current BSSID/SSID");
9415 return 0;
9416 }
9417
9418 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
9419 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9420 hs2_set_policy(dut);
9421 return 0;
9422}
9423
9424
9425static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
9426 struct sigma_conn *conn,
9427 const char *ifname,
9428 struct sigma_cmd *cmd)
9429{
9430 const char *val;
9431 int id;
9432
9433 id = add_cred(ifname);
9434 if (id < 0)
9435 return -2;
9436 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9437
9438 val = get_param(cmd, "prefer");
9439 if (val && atoi(val) > 0)
9440 set_cred(ifname, id, "priority", "1");
9441
9442 val = get_param(cmd, "REALM");
9443 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9444 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9445 "realm");
9446 return 0;
9447 }
9448
9449 val = get_param(cmd, "HOME_FQDN");
9450 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9451 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9452 "home_fqdn");
9453 return 0;
9454 }
9455
9456 val = get_param(cmd, "Username");
9457 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9458 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9459 "username");
9460 return 0;
9461 }
9462
9463 val = get_param(cmd, "Password");
9464 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
9465 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9466 "password");
9467 return 0;
9468 }
9469
9470 val = get_param(cmd, "ROOT_CA");
9471 if (val) {
9472 char fname[200];
9473 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9474#ifdef __linux__
9475 if (!file_exists(fname)) {
9476 char msg[300];
9477 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9478 "file (%s) not found", fname);
9479 send_resp(dut, conn, SIGMA_ERROR, msg);
9480 return 0;
9481 }
9482#endif /* __linux__ */
9483 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9485 "not set root CA");
9486 return 0;
9487 }
9488 }
9489
9490 return 1;
9491}
9492
9493
9494static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
9495{
9496 FILE *in, *out;
9497 char buf[500];
9498 int found = 0;
9499
9500 in = fopen("devdetail.xml", "r");
9501 if (in == NULL)
9502 return -1;
9503 out = fopen("devdetail.xml.tmp", "w");
9504 if (out == NULL) {
9505 fclose(in);
9506 return -1;
9507 }
9508
9509 while (fgets(buf, sizeof(buf), in)) {
9510 char *pos = strstr(buf, "<IMSI>");
9511 if (pos) {
9512 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
9513 imsi);
9514 pos += 6;
9515 *pos = '\0';
9516 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
9517 found++;
9518 } else {
9519 fprintf(out, "%s", buf);
9520 }
9521 }
9522
9523 fclose(out);
9524 fclose(in);
9525 if (found)
9526 rename("devdetail.xml.tmp", "devdetail.xml");
9527 else
9528 unlink("devdetail.xml.tmp");
9529
9530 return 0;
9531}
9532
9533
9534static int sta_add_credential_sim(struct sigma_dut *dut,
9535 struct sigma_conn *conn,
9536 const char *ifname, struct sigma_cmd *cmd)
9537{
9538 const char *val, *imsi = NULL;
9539 int id;
9540 char buf[200];
9541 int res;
9542 const char *pos;
9543 size_t mnc_len;
9544 char plmn_mcc[4];
9545 char plmn_mnc[4];
9546
9547 id = add_cred(ifname);
9548 if (id < 0)
9549 return -2;
9550 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9551
9552 val = get_param(cmd, "prefer");
9553 if (val && atoi(val) > 0)
9554 set_cred(ifname, id, "priority", "1");
9555
9556 val = get_param(cmd, "PLMN_MCC");
9557 if (val == NULL) {
9558 send_resp(dut, conn, SIGMA_ERROR,
9559 "errorCode,Missing PLMN_MCC");
9560 return 0;
9561 }
9562 if (strlen(val) != 3) {
9563 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
9564 return 0;
9565 }
9566 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
9567
9568 val = get_param(cmd, "PLMN_MNC");
9569 if (val == NULL) {
9570 send_resp(dut, conn, SIGMA_ERROR,
9571 "errorCode,Missing PLMN_MNC");
9572 return 0;
9573 }
9574 if (strlen(val) != 2 && strlen(val) != 3) {
9575 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
9576 return 0;
9577 }
9578 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
9579
9580 val = get_param(cmd, "IMSI");
9581 if (val == NULL) {
9582 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
9583 "IMSI");
9584 return 0;
9585 }
9586
9587 imsi = pos = val;
9588
9589 if (strncmp(plmn_mcc, pos, 3) != 0) {
9590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
9591 return 0;
9592 }
9593 pos += 3;
9594
9595 mnc_len = strlen(plmn_mnc);
9596 if (mnc_len < 2) {
9597 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
9598 return 0;
9599 }
9600
9601 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
9602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
9603 return 0;
9604 }
9605 pos += mnc_len;
9606
9607 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
9608 if (res < 0 || res >= (int) sizeof(buf))
9609 return -1;
9610 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
9611 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9612 "not set IMSI");
9613 return 0;
9614 }
9615
9616 val = get_param(cmd, "Password");
9617 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
9618 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9619 "not set password");
9620 return 0;
9621 }
9622
9623 if (dut->program == PROGRAM_HS2_R2) {
9624 /*
9625 * Set provisioning_sp for the test cases where SIM/USIM
9626 * provisioning is used.
9627 */
9628 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
9629 "wi-fi.org") < 0) {
9630 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9631 "not set provisioning_sp");
9632 return 0;
9633 }
9634
9635 update_devdetail_imsi(dut, imsi);
9636 }
9637
9638 return 1;
9639}
9640
9641
9642static int sta_add_credential_cert(struct sigma_dut *dut,
9643 struct sigma_conn *conn,
9644 const char *ifname,
9645 struct sigma_cmd *cmd)
9646{
9647 const char *val;
9648 int id;
9649
9650 id = add_cred(ifname);
9651 if (id < 0)
9652 return -2;
9653 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9654
9655 val = get_param(cmd, "prefer");
9656 if (val && atoi(val) > 0)
9657 set_cred(ifname, id, "priority", "1");
9658
9659 val = get_param(cmd, "REALM");
9660 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9661 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9662 "realm");
9663 return 0;
9664 }
9665
9666 val = get_param(cmd, "HOME_FQDN");
9667 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9669 "home_fqdn");
9670 return 0;
9671 }
9672
9673 val = get_param(cmd, "Username");
9674 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9676 "username");
9677 return 0;
9678 }
9679
9680 val = get_param(cmd, "clientCertificate");
9681 if (val) {
9682 char fname[200];
9683 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9684#ifdef __linux__
9685 if (!file_exists(fname)) {
9686 char msg[300];
9687 snprintf(msg, sizeof(msg),
9688 "ErrorCode,clientCertificate "
9689 "file (%s) not found", fname);
9690 send_resp(dut, conn, SIGMA_ERROR, msg);
9691 return 0;
9692 }
9693#endif /* __linux__ */
9694 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
9695 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9696 "not set client_cert");
9697 return 0;
9698 }
9699 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
9700 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9701 "not set private_key");
9702 return 0;
9703 }
9704 }
9705
9706 val = get_param(cmd, "ROOT_CA");
9707 if (val) {
9708 char fname[200];
9709 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9710#ifdef __linux__
9711 if (!file_exists(fname)) {
9712 char msg[300];
9713 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9714 "file (%s) not found", fname);
9715 send_resp(dut, conn, SIGMA_ERROR, msg);
9716 return 0;
9717 }
9718#endif /* __linux__ */
9719 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9720 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9721 "not set root CA");
9722 return 0;
9723 }
9724 }
9725
9726 return 1;
9727}
9728
9729
9730static int cmd_sta_add_credential(struct sigma_dut *dut,
9731 struct sigma_conn *conn,
9732 struct sigma_cmd *cmd)
9733{
9734 const char *intf = get_param(cmd, "Interface");
9735 const char *type;
9736
9737 start_sta_mode(dut);
9738
9739 type = get_param(cmd, "Type");
9740 if (!type)
9741 return -1;
9742
9743 if (strcasecmp(type, "uname_pwd") == 0)
9744 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9745
9746 if (strcasecmp(type, "sim") == 0)
9747 return sta_add_credential_sim(dut, conn, intf, cmd);
9748
9749 if (strcasecmp(type, "cert") == 0)
9750 return sta_add_credential_cert(dut, conn, intf, cmd);
9751
9752 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9753 "type");
9754 return 0;
9755}
9756
9757
9758static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9759 struct sigma_cmd *cmd)
9760{
9761 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309762 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009763 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309764 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009765 int res;
9766
9767 val = get_param(cmd, "HESSID");
9768 if (val) {
9769 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9770 if (res < 0 || res >= (int) sizeof(buf))
9771 return -1;
9772 wpa_command(intf, buf);
9773 }
9774
9775 val = get_param(cmd, "ACCS_NET_TYPE");
9776 if (val) {
9777 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9778 val);
9779 if (res < 0 || res >= (int) sizeof(buf))
9780 return -1;
9781 wpa_command(intf, buf);
9782 }
9783
vamsi krishna89ad8c62017-09-19 12:51:18 +05309784 bssid = get_param(cmd, "Bssid");
9785 ssid = get_param(cmd, "Ssid");
9786
9787 if (ssid) {
9788 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9789 send_resp(dut, conn, SIGMA_ERROR,
9790 "ErrorCode,Too long SSID");
9791 return 0;
9792 }
9793 ascii2hexstr(ssid, ssid_hex);
9794 }
9795
9796 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9797 bssid ? " bssid=": "",
9798 bssid ? bssid : "",
9799 ssid ? " ssid " : "",
9800 ssid ? ssid_hex : "");
9801 if (res < 0 || res >= (int) sizeof(buf))
9802 return -1;
9803
9804 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009805 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9806 "scan");
9807 return 0;
9808 }
9809
9810 return 1;
9811}
9812
9813
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009814static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9815 struct sigma_cmd *cmd)
9816{
9817 const char *intf = get_param(cmd, "Interface");
9818 const char *bssid;
9819 char buf[4096], *pos;
9820 int freq, chan;
9821 char *ssid;
9822 char resp[100];
9823 int res;
9824 struct wpa_ctrl *ctrl;
9825
9826 bssid = get_param(cmd, "BSSID");
9827 if (!bssid) {
9828 send_resp(dut, conn, SIGMA_INVALID,
9829 "errorCode,BSSID argument is missing");
9830 return 0;
9831 }
9832
9833 ctrl = open_wpa_mon(intf);
9834 if (!ctrl) {
9835 sigma_dut_print(dut, DUT_MSG_ERROR,
9836 "Failed to open wpa_supplicant monitor connection");
9837 return -1;
9838 }
9839
9840 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9841 send_resp(dut, conn, SIGMA_ERROR,
9842 "errorCode,Could not start scan");
9843 wpa_ctrl_detach(ctrl);
9844 wpa_ctrl_close(ctrl);
9845 return 0;
9846 }
9847
9848 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9849 buf, sizeof(buf));
9850
9851 wpa_ctrl_detach(ctrl);
9852 wpa_ctrl_close(ctrl);
9853
9854 if (res < 0) {
9855 send_resp(dut, conn, SIGMA_ERROR,
9856 "errorCode,Scan did not complete");
9857 return 0;
9858 }
9859
9860 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9861 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9862 strncmp(buf, "id=", 3) != 0) {
9863 send_resp(dut, conn, SIGMA_ERROR,
9864 "errorCode,Specified BSSID not found");
9865 return 0;
9866 }
9867
9868 pos = strstr(buf, "\nfreq=");
9869 if (!pos) {
9870 send_resp(dut, conn, SIGMA_ERROR,
9871 "errorCode,Channel not found");
9872 return 0;
9873 }
9874 freq = atoi(pos + 6);
9875 chan = freq_to_channel(freq);
9876
9877 pos = strstr(buf, "\nssid=");
9878 if (!pos) {
9879 send_resp(dut, conn, SIGMA_ERROR,
9880 "errorCode,SSID not found");
9881 return 0;
9882 }
9883 ssid = pos + 6;
9884 pos = strchr(ssid, '\n');
9885 if (pos)
9886 *pos = '\0';
9887 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9888 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9889 return 0;
9890}
9891
9892
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009893static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9894 struct sigma_cmd *cmd)
9895{
9896#ifdef __linux__
9897 struct timeval tv;
9898 struct tm tm;
9899 time_t t;
9900 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309901 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009902
9903 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9904
9905 memset(&tm, 0, sizeof(tm));
9906 val = get_param(cmd, "seconds");
9907 if (val)
9908 tm.tm_sec = atoi(val);
9909 val = get_param(cmd, "minutes");
9910 if (val)
9911 tm.tm_min = atoi(val);
9912 val = get_param(cmd, "hours");
9913 if (val)
9914 tm.tm_hour = atoi(val);
9915 val = get_param(cmd, "date");
9916 if (val)
9917 tm.tm_mday = atoi(val);
9918 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309919 if (val) {
9920 v = atoi(val);
9921 if (v < 1 || v > 12) {
9922 send_resp(dut, conn, SIGMA_INVALID,
9923 "errorCode,Invalid month");
9924 return 0;
9925 }
9926 tm.tm_mon = v - 1;
9927 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009928 val = get_param(cmd, "year");
9929 if (val) {
9930 int year = atoi(val);
9931#ifdef ANDROID
9932 if (year > 2035)
9933 year = 2035; /* years beyond 2035 not supported */
9934#endif /* ANDROID */
9935 tm.tm_year = year - 1900;
9936 }
9937 t = mktime(&tm);
9938 if (t == (time_t) -1) {
9939 send_resp(dut, conn, SIGMA_ERROR,
9940 "errorCode,Invalid date or time");
9941 return 0;
9942 }
9943
9944 memset(&tv, 0, sizeof(tv));
9945 tv.tv_sec = t;
9946
9947 if (settimeofday(&tv, NULL) < 0) {
9948 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9949 strerror(errno));
9950 send_resp(dut, conn, SIGMA_ERROR,
9951 "errorCode,Failed to set time");
9952 return 0;
9953 }
9954
9955 return 1;
9956#endif /* __linux__ */
9957
9958 return -1;
9959}
9960
9961
9962static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9963 struct sigma_cmd *cmd)
9964{
9965 const char *intf = get_param(cmd, "Interface");
9966 const char *name, *val;
9967 int prod_ess_assoc = 1;
9968 char buf[200], bssid[100], ssid[100];
9969 int res;
9970 struct wpa_ctrl *ctrl;
9971
9972 name = get_param(cmd, "osuFriendlyName");
9973
9974 val = get_param(cmd, "ProdESSAssoc");
9975 if (val)
9976 prod_ess_assoc = atoi(val);
9977
9978 kill_dhcp_client(dut, intf);
9979 if (start_dhcp_client(dut, intf) < 0)
9980 return -2;
9981
9982 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9983 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9984 res = snprintf(buf, sizeof(buf),
9985 "%s %s%s%s signup osu-ca.pem",
9986 prod_ess_assoc ? "" : "-N",
9987 name ? "-O'" : "", name ? name : "",
9988 name ? "'" : "");
9989
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309990 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009991 if (run_hs20_osu(dut, buf) < 0) {
9992 FILE *f;
9993
9994 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9995
9996 f = fopen("hs20-osu-client.res", "r");
9997 if (f) {
9998 char resp[400], res[300], *pos;
9999 if (!fgets(res, sizeof(res), f))
10000 res[0] = '\0';
10001 pos = strchr(res, '\n');
10002 if (pos)
10003 *pos = '\0';
10004 fclose(f);
10005 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
10006 res);
10007 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
10008 if (system(resp) != 0) {
10009 }
10010 snprintf(resp, sizeof(resp),
10011 "SSID,,BSSID,,failureReason,%s", res);
10012 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10013 return 0;
10014 }
10015
10016 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10017 return 0;
10018 }
10019
10020 if (!prod_ess_assoc)
10021 goto report;
10022
10023 ctrl = open_wpa_mon(intf);
10024 if (ctrl == NULL) {
10025 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10026 "wpa_supplicant monitor connection");
10027 return -1;
10028 }
10029
10030 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10031 buf, sizeof(buf));
10032
10033 wpa_ctrl_detach(ctrl);
10034 wpa_ctrl_close(ctrl);
10035
10036 if (res < 0) {
10037 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
10038 "network after OSU");
10039 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10040 return 0;
10041 }
10042
10043report:
10044 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10045 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10046 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
10047 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10048 return 0;
10049 }
10050
10051 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
10052 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010053 return 0;
10054}
10055
10056
10057static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
10058 struct sigma_cmd *cmd)
10059{
10060 const char *val;
10061 int timeout = 120;
10062
10063 val = get_param(cmd, "PolicyUpdate");
10064 if (val == NULL || atoi(val) == 0)
10065 return 1; /* No operation requested */
10066
10067 val = get_param(cmd, "Timeout");
10068 if (val)
10069 timeout = atoi(val);
10070
10071 if (timeout) {
10072 /* TODO: time out the command and return
10073 * PolicyUpdateStatus,TIMEOUT if needed. */
10074 }
10075
10076 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
10077 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
10078 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
10079 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
10080 return 0;
10081 }
10082
10083 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
10084 return 0;
10085}
10086
10087
10088static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
10089 struct sigma_cmd *cmd)
10090{
10091 struct wpa_ctrl *ctrl;
10092 const char *intf = get_param(cmd, "Interface");
10093 const char *bssid = get_param(cmd, "Bssid");
10094 const char *ssid = get_param(cmd, "SSID");
10095 const char *security = get_param(cmd, "Security");
10096 const char *passphrase = get_param(cmd, "Passphrase");
10097 const char *pin = get_param(cmd, "PIN");
10098 char buf[1000];
10099 char ssid_hex[200], passphrase_hex[200];
10100 const char *keymgmt, *cipher;
10101
10102 if (intf == NULL)
10103 intf = get_main_ifname();
10104
10105 if (!bssid) {
10106 send_resp(dut, conn, SIGMA_ERROR,
10107 "ErrorCode,Missing Bssid argument");
10108 return 0;
10109 }
10110
10111 if (!ssid) {
10112 send_resp(dut, conn, SIGMA_ERROR,
10113 "ErrorCode,Missing SSID argument");
10114 return 0;
10115 }
10116
10117 if (!security) {
10118 send_resp(dut, conn, SIGMA_ERROR,
10119 "ErrorCode,Missing Security argument");
10120 return 0;
10121 }
10122
10123 if (!passphrase) {
10124 send_resp(dut, conn, SIGMA_ERROR,
10125 "ErrorCode,Missing Passphrase argument");
10126 return 0;
10127 }
10128
10129 if (!pin) {
10130 send_resp(dut, conn, SIGMA_ERROR,
10131 "ErrorCode,Missing PIN argument");
10132 return 0;
10133 }
10134
vamsi krishna8c9c1562017-05-12 15:51:46 +053010135 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
10136 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010137 send_resp(dut, conn, SIGMA_ERROR,
10138 "ErrorCode,Too long SSID/passphrase");
10139 return 0;
10140 }
10141
10142 ctrl = open_wpa_mon(intf);
10143 if (ctrl == NULL) {
10144 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10145 "wpa_supplicant monitor connection");
10146 return -2;
10147 }
10148
10149 if (strcasecmp(security, "wpa2-psk") == 0) {
10150 keymgmt = "WPA2PSK";
10151 cipher = "CCMP";
10152 } else {
10153 wpa_ctrl_detach(ctrl);
10154 wpa_ctrl_close(ctrl);
10155 send_resp(dut, conn, SIGMA_ERROR,
10156 "ErrorCode,Unsupported Security value");
10157 return 0;
10158 }
10159
10160 ascii2hexstr(ssid, ssid_hex);
10161 ascii2hexstr(passphrase, passphrase_hex);
10162 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
10163 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
10164
10165 if (wpa_command(intf, buf) < 0) {
10166 wpa_ctrl_detach(ctrl);
10167 wpa_ctrl_close(ctrl);
10168 send_resp(dut, conn, SIGMA_ERROR,
10169 "ErrorCode,Failed to start registrar");
10170 return 0;
10171 }
10172
10173 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
10174 dut->er_oper_performed = 1;
10175
10176 return wps_connection_event(dut, conn, ctrl, intf, 0);
10177}
10178
10179
10180static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
10181 struct sigma_conn *conn,
10182 struct sigma_cmd *cmd)
10183{
10184 struct wpa_ctrl *ctrl;
10185 const char *intf = get_param(cmd, "Interface");
10186 const char *bssid = get_param(cmd, "Bssid");
10187 char buf[100];
10188
10189 if (!bssid) {
10190 send_resp(dut, conn, SIGMA_ERROR,
10191 "ErrorCode,Missing Bssid argument");
10192 return 0;
10193 }
10194
10195 ctrl = open_wpa_mon(intf);
10196 if (ctrl == NULL) {
10197 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10198 "wpa_supplicant monitor connection");
10199 return -2;
10200 }
10201
10202 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
10203
10204 if (wpa_command(intf, buf) < 0) {
10205 wpa_ctrl_detach(ctrl);
10206 wpa_ctrl_close(ctrl);
10207 send_resp(dut, conn, SIGMA_ERROR,
10208 "ErrorCode,Failed to start registrar");
10209 return 0;
10210 }
10211
10212 return wps_connection_event(dut, conn, ctrl, intf, 0);
10213}
10214
10215
vamsi krishna9b144002017-09-20 13:28:13 +053010216static int cmd_start_wps_registration(struct sigma_dut *dut,
10217 struct sigma_conn *conn,
10218 struct sigma_cmd *cmd)
10219{
10220 struct wpa_ctrl *ctrl;
10221 const char *intf = get_param(cmd, "Interface");
10222 const char *role, *method;
10223 int res;
10224 char buf[256];
10225 const char *events[] = {
10226 "CTRL-EVENT-CONNECTED",
10227 "WPS-OVERLAP-DETECTED",
10228 "WPS-TIMEOUT",
10229 "WPS-FAIL",
10230 NULL
10231 };
10232
10233 ctrl = open_wpa_mon(intf);
10234 if (!ctrl) {
10235 sigma_dut_print(dut, DUT_MSG_ERROR,
10236 "Failed to open wpa_supplicant monitor connection");
10237 return -2;
10238 }
10239
10240 role = get_param(cmd, "WpsRole");
10241 if (!role) {
10242 send_resp(dut, conn, SIGMA_INVALID,
10243 "ErrorCode,WpsRole not provided");
10244 goto fail;
10245 }
10246
10247 if (strcasecmp(role, "Enrollee") == 0) {
10248 method = get_param(cmd, "WpsConfigMethod");
10249 if (!method) {
10250 send_resp(dut, conn, SIGMA_INVALID,
10251 "ErrorCode,WpsConfigMethod not provided");
10252 goto fail;
10253 }
10254 if (strcasecmp(method, "PBC") == 0) {
10255 if (wpa_command(intf, "WPS_PBC") < 0) {
10256 send_resp(dut, conn, SIGMA_ERROR,
10257 "ErrorCode,Failed to enable PBC");
10258 goto fail;
10259 }
10260 } else {
10261 /* TODO: PIN method */
10262 send_resp(dut, conn, SIGMA_ERROR,
10263 "ErrorCode,Unsupported WpsConfigMethod value");
10264 goto fail;
10265 }
10266 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10267 if (res < 0) {
10268 send_resp(dut, conn, SIGMA_ERROR,
10269 "ErrorCode,WPS connection did not complete");
10270 goto fail;
10271 }
10272 if (strstr(buf, "WPS-TIMEOUT")) {
10273 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
10274 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
10275 send_resp(dut, conn, SIGMA_ERROR,
10276 "ErrorCode,OverlapSession");
10277 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
10278 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
10279 } else {
10280 send_resp(dut, conn, SIGMA_ERROR,
10281 "ErrorCode,WPS operation failed");
10282 }
10283 } else {
10284 /* TODO: Registrar role */
10285 send_resp(dut, conn, SIGMA_ERROR,
10286 "ErrorCode,Unsupported WpsRole value");
10287 }
10288
10289fail:
10290 wpa_ctrl_detach(ctrl);
10291 wpa_ctrl_close(ctrl);
10292 return 0;
10293}
10294
10295
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010296static int req_intf(struct sigma_cmd *cmd)
10297{
10298 return get_param(cmd, "interface") == NULL ? -1 : 0;
10299}
10300
10301
10302void sta_register_cmds(void)
10303{
10304 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
10305 cmd_sta_get_ip_config);
10306 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
10307 cmd_sta_set_ip_config);
10308 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
10309 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
10310 cmd_sta_get_mac_address);
10311 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
10312 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
10313 cmd_sta_verify_ip_connection);
10314 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
10315 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
10316 cmd_sta_set_encryption);
10317 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
10318 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
10319 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
10320 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
10321 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
10322 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
10323 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
10324 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
10325 cmd_sta_set_eapakaprime);
10326 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
10327 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
10328 /* TODO: sta_set_ibss */
10329 /* TODO: sta_set_mode */
10330 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
10331 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
10332 /* TODO: sta_up_load */
10333 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
10334 cmd_sta_preset_testparameters);
10335 /* TODO: sta_set_system */
10336 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
10337 /* TODO: sta_set_rifs_test */
10338 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
10339 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
10340 /* TODO: sta_send_coexist_mgmt */
10341 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
10342 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
10343 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
10344 sigma_dut_reg_cmd("sta_reset_default", req_intf,
10345 cmd_sta_reset_default);
10346 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
10347 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
10348 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
10349 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
10350 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
10351 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
10352 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
10353 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
10354 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
10355 cmd_sta_hs2_associate);
10356 sigma_dut_reg_cmd("sta_add_credential", req_intf,
10357 cmd_sta_add_credential);
10358 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020010359 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010360 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
10361 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
10362 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
10363 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
10364 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
10365 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030010366 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010367 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
10368 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053010369 sigma_dut_reg_cmd("start_wps_registration", req_intf,
10370 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010371}