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