blob: 26d0c348482d758dc773c634a4623c096b6c545f [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
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200456int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
457 size_t buf_len)
458{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530459 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200460 char ip[16], mask[15], dns[16], sec_dns[16];
461 int is_dhcp = 0;
462 int s;
463#ifdef ANDROID
464 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530465#else /* ANDROID */
466 FILE *f;
467#ifdef __linux__
468 const char *str_ps;
469#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200470#endif /* ANDROID */
471
472 ip[0] = '\0';
473 mask[0] = '\0';
474 dns[0] = '\0';
475 sec_dns[0] = '\0';
476
477 s = socket(PF_INET, SOCK_DGRAM, 0);
478 if (s >= 0) {
479 struct ifreq ifr;
480 struct sockaddr_in saddr;
481
482 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700483 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200484 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
485 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
486 "%s IP address: %s",
487 ifname, strerror(errno));
488 } else {
489 memcpy(&saddr, &ifr.ifr_addr,
490 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700491 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200492 }
493
494 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
495 memcpy(&saddr, &ifr.ifr_addr,
496 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700497 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200498 }
499 close(s);
500 }
501
502#ifdef ANDROID
503 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
504 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
505 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
506 if (property_get(tmp, prop, NULL) != 0 &&
507 strcmp(prop, "ok") == 0) {
508 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
509 ifname);
510 if (property_get(tmp, prop, NULL) != 0 &&
511 strcmp(ip, prop) == 0)
512 is_dhcp = 1;
513 }
514 }
515
516 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700517 if (property_get(tmp, prop, NULL) != 0)
518 strlcpy(dns, prop, sizeof(dns));
519 else if (property_get("net.dns1", prop, NULL) != 0)
520 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200521
522 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700523 if (property_get(tmp, prop, NULL) != 0)
524 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200525#else /* ANDROID */
526#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530527 if (get_driver_type() == DRIVER_OPENWRT)
528 str_ps = "ps -w";
529 else
530 str_ps = "ps ax";
531 snprintf(tmp, sizeof(tmp),
532 "%s | grep dhclient | grep -v grep | grep -q %s",
533 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200534 if (system(tmp) == 0)
535 is_dhcp = 1;
536 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530537 snprintf(tmp, sizeof(tmp),
538 "%s | grep udhcpc | grep -v grep | grep -q %s",
539 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200540 if (system(tmp) == 0)
541 is_dhcp = 1;
542 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530543 snprintf(tmp, sizeof(tmp),
544 "%s | grep dhcpcd | grep -v grep | grep -q %s",
545 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200546 if (system(tmp) == 0)
547 is_dhcp = 1;
548 }
549 }
550#endif /* __linux__ */
551
552 f = fopen("/etc/resolv.conf", "r");
553 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530554 char *pos, *pos2;
555
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200556 while (fgets(tmp, sizeof(tmp), f)) {
557 if (strncmp(tmp, "nameserver", 10) != 0)
558 continue;
559 pos = tmp + 10;
560 while (*pos == ' ' || *pos == '\t')
561 pos++;
562 pos2 = pos;
563 while (*pos2) {
564 if (*pos2 == '\n' || *pos2 == '\r') {
565 *pos2 = '\0';
566 break;
567 }
568 pos2++;
569 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700570 if (!dns[0])
571 strlcpy(dns, pos, sizeof(dns));
572 else if (!sec_dns[0])
573 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200574 }
575 fclose(f);
576 }
577#endif /* ANDROID */
578
579 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
580 is_dhcp, ip, mask, dns);
581 buf[buf_len - 1] = '\0';
582
583 return 0;
584}
585
586
587
588
589int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
590 size_t buf_len)
591{
592#ifdef __linux__
593#ifdef ANDROID
594 char cmd[200], result[1000], *pos, *end;
595 FILE *f;
596 size_t len;
597
598 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
599 f = popen(cmd, "r");
600 if (f == NULL)
601 return -1;
602 len = fread(result, 1, sizeof(result) - 1, f);
603 pclose(f);
604 if (len == 0)
605 return -1;
606 result[len] = '\0';
607 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
608
609 pos = strstr(result, "inet6 ");
610 if (pos == NULL)
611 return -1;
612 pos += 6;
613 end = strchr(pos, ' ');
614 if (end)
615 *end = '\0';
616 end = strchr(pos, '/');
617 if (end)
618 *end = '\0';
619 snprintf(buf, buf_len, "ip,%s", pos);
620 buf[buf_len - 1] = '\0';
621 return 0;
622#else /* ANDROID */
623 struct ifaddrs *ifaddr, *ifa;
624 int res, found = 0;
625 char host[NI_MAXHOST];
626
627 if (getifaddrs(&ifaddr) < 0) {
628 perror("getifaddrs");
629 return -1;
630 }
631
632 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
633 if (strcasecmp(ifname, ifa->ifa_name) != 0)
634 continue;
635 if (ifa->ifa_addr == NULL ||
636 ifa->ifa_addr->sa_family != AF_INET6)
637 continue;
638
639 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
640 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
641 if (res != 0) {
642 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
643 gai_strerror(res));
644 continue;
645 }
646 if (strncmp(host, "fe80::", 6) == 0)
647 continue; /* skip link-local */
648
649 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
650 found = 1;
651 break;
652 }
653
654 freeifaddrs(ifaddr);
655
656 if (found) {
657 char *pos;
658 pos = strchr(host, '%');
659 if (pos)
660 *pos = '\0';
661 snprintf(buf, buf_len, "ip,%s", host);
662 buf[buf_len - 1] = '\0';
663 return 0;
664 }
665
666#endif /* ANDROID */
667#endif /* __linux__ */
668 return -1;
669}
670
671
672static int cmd_sta_get_ip_config(struct sigma_dut *dut,
673 struct sigma_conn *conn,
674 struct sigma_cmd *cmd)
675{
676 const char *intf = get_param(cmd, "Interface");
677 const char *ifname;
678 char buf[200];
679 const char *val;
680 int type = 1;
681
682 if (intf == NULL)
683 return -1;
684
685 if (strcmp(intf, get_main_ifname()) == 0)
686 ifname = get_station_ifname();
687 else
688 ifname = intf;
689
690 /*
691 * UCC may assume the IP address to be available immediately after
692 * association without trying to run sta_get_ip_config multiple times.
693 * Sigma CAPI does not specify this command as a block command that
694 * would wait for the address to become available, but to pass tests
695 * more reliably, it looks like such a wait may be needed here.
696 */
697 if (wait_ip_addr(dut, ifname, 15) < 0) {
698 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
699 "for sta_get_ip_config");
700 /*
701 * Try to continue anyway since many UCC tests do not really
702 * care about the return value from here..
703 */
704 }
705
706 val = get_param(cmd, "Type");
707 if (val)
708 type = atoi(val);
709 if (type == 2 || dut->last_set_ip_config_ipv6) {
710 int i;
711
712 /*
713 * Since we do not have proper wait for IPv6 addresses, use a
714 * fixed two second delay here as a workaround for UCC script
715 * assuming IPv6 address is available when this command returns.
716 * Some scripts did not use Type,2 properly for IPv6, so include
717 * also the cases where the previous sta_set_ip_config indicated
718 * use of IPv6.
719 */
720 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
721 for (i = 0; i < 10; i++) {
722 sleep(1);
723 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
724 {
725 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
726 send_resp(dut, conn, SIGMA_COMPLETE, buf);
727#ifdef ANDROID
728 sigma_dut_print(dut, DUT_MSG_INFO,
729 "Adding IPv6 rule on Android");
730 add_ipv6_rule(dut, intf);
731#endif /* ANDROID */
732
733 return 0;
734 }
735 }
736 }
737 if (type == 1) {
738 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
739 return -2;
740 } else if (type == 2) {
741 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
742 return -2;
743 } else {
744 send_resp(dut, conn, SIGMA_ERROR,
745 "errorCode,Unsupported address type");
746 return 0;
747 }
748
749 send_resp(dut, conn, SIGMA_COMPLETE, buf);
750 return 0;
751}
752
753
754static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
755{
756#ifdef __linux__
757 char buf[200];
758 char path[128];
759 struct stat s;
760
761#ifdef ANDROID
762 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
763#else /* ANDROID */
764 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
765#endif /* ANDROID */
766 if (stat(path, &s) == 0) {
767 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
768 sigma_dut_print(dut, DUT_MSG_INFO,
769 "Kill previous DHCP client: %s", buf);
770 if (system(buf) != 0)
771 sigma_dut_print(dut, DUT_MSG_INFO,
772 "Failed to kill DHCP client");
773 unlink(path);
774 sleep(1);
775 } else {
776 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
777
778 if (stat(path, &s) == 0) {
779 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
780 sigma_dut_print(dut, DUT_MSG_INFO,
781 "Kill previous DHCP client: %s", buf);
782 if (system(buf) != 0)
783 sigma_dut_print(dut, DUT_MSG_INFO,
784 "Failed to kill DHCP client");
785 unlink(path);
786 sleep(1);
787 }
788 }
789#endif /* __linux__ */
790}
791
792
793static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
794{
795#ifdef __linux__
796 char buf[200];
797
798#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530799 if (access("/system/bin/dhcpcd", F_OK) != -1) {
800 snprintf(buf, sizeof(buf),
801 "/system/bin/dhcpcd -b %s", ifname);
802 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
803 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
804 } else {
805 sigma_dut_print(dut, DUT_MSG_ERROR,
806 "DHCP client program missing");
807 return 0;
808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200809#else /* ANDROID */
810 snprintf(buf, sizeof(buf),
811 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
812 ifname, ifname);
813#endif /* ANDROID */
814 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
815 if (system(buf) != 0) {
816 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
817 if (system(buf) != 0) {
818 sigma_dut_print(dut, DUT_MSG_INFO,
819 "Failed to start DHCP client");
820#ifndef ANDROID
821 return -1;
822#endif /* ANDROID */
823 }
824 }
825#endif /* __linux__ */
826
827 return 0;
828}
829
830
831static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
832{
833#ifdef __linux__
834 char buf[200];
835
836 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
837 if (system(buf) != 0) {
838 sigma_dut_print(dut, DUT_MSG_INFO,
839 "Failed to clear IP addresses");
840 return -1;
841 }
842#endif /* __linux__ */
843
844 return 0;
845}
846
847
848#ifdef ANDROID
849static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
850{
851 char cmd[200], *result, *pos;
852 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530853 int tableid;
854 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200855
856 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
857 ifname);
858 fp = popen(cmd, "r");
859 if (fp == NULL)
860 return -1;
861
862 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530863 if (result == NULL) {
864 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200865 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200867
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530868 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200869 fclose(fp);
870
871 if (len == 0) {
872 free(result);
873 return -1;
874 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530875 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200876
877 pos = strstr(result, "table ");
878 if (pos == NULL) {
879 free(result);
880 return -1;
881 }
882
883 pos += strlen("table ");
884 tableid = atoi(pos);
885 if (tableid != 0) {
886 if (system("ip -6 rule del prio 22000") != 0) {
887 /* ignore any error */
888 }
889 snprintf(cmd, sizeof(cmd),
890 "ip -6 rule add from all lookup %d prio 22000",
891 tableid);
892 if (system(cmd) != 0) {
893 sigma_dut_print(dut, DUT_MSG_INFO,
894 "Failed to run %s", cmd);
895 free(result);
896 return -1;
897 }
898 } else {
899 sigma_dut_print(dut, DUT_MSG_INFO,
900 "No Valid Table Id found %s", pos);
901 free(result);
902 return -1;
903 }
904 free(result);
905
906 return 0;
907}
908#endif /* ANDROID */
909
910
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530911int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
912 const char *ip, const char *mask)
913{
914 char buf[200];
915
916 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
917 ifname, ip, mask);
918 return system(buf) == 0;
919}
920
921
922int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
923{
924 char buf[200];
925
926 if (!is_ip_addr(gw)) {
927 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
928 return -1;
929 }
930
931 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
932 if (!dut->no_ip_addr_set && system(buf) != 0) {
933 snprintf(buf, sizeof(buf), "ip ro re default via %s",
934 gw);
935 if (system(buf) != 0)
936 return 0;
937 }
938
939 return 1;
940}
941
942
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200943static int cmd_sta_set_ip_config(struct sigma_dut *dut,
944 struct sigma_conn *conn,
945 struct sigma_cmd *cmd)
946{
947 const char *intf = get_param(cmd, "Interface");
948 const char *ifname;
949 char buf[200];
950 const char *val, *ip, *mask, *gw;
951 int type = 1;
952
953 if (intf == NULL)
954 return -1;
955
956 if (strcmp(intf, get_main_ifname()) == 0)
957 ifname = get_station_ifname();
958 else
959 ifname = intf;
960
961 if (if_nametoindex(ifname) == 0) {
962 send_resp(dut, conn, SIGMA_ERROR,
963 "ErrorCode,Unknown interface");
964 return 0;
965 }
966
967 val = get_param(cmd, "Type");
968 if (val) {
969 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530970 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200971 send_resp(dut, conn, SIGMA_ERROR,
972 "ErrorCode,Unsupported address type");
973 return 0;
974 }
975 }
976
977 dut->last_set_ip_config_ipv6 = 0;
978
979 val = get_param(cmd, "dhcp");
980 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
981 static_ip_file(0, NULL, NULL, NULL);
982#ifdef __linux__
983 if (type == 2) {
984 dut->last_set_ip_config_ipv6 = 1;
985 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
986 "stateless address autoconfiguration");
987#ifdef ANDROID
988 /*
989 * This sleep is required as the assignment in case of
990 * Android is taking time and is done by the kernel.
991 * The subsequent ping for IPv6 is impacting HS20 test
992 * case.
993 */
994 sleep(2);
995 add_ipv6_rule(dut, intf);
996#endif /* ANDROID */
997 /* Assume this happens by default */
998 return 1;
999 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301000 if (type != 3) {
1001 kill_dhcp_client(dut, ifname);
1002 if (start_dhcp_client(dut, ifname) < 0)
1003 return -2;
1004 } else {
1005 sigma_dut_print(dut, DUT_MSG_DEBUG,
1006 "Using FILS HLP DHCPv4 Rapid Commit");
1007 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001008
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001009 return 1;
1010#endif /* __linux__ */
1011 return -2;
1012 }
1013
1014 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301015 if (!ip) {
1016 send_resp(dut, conn, SIGMA_INVALID,
1017 "ErrorCode,Missing IP address");
1018 return 0;
1019 }
1020
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001021 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301022 if (!mask) {
1023 send_resp(dut, conn, SIGMA_INVALID,
1024 "ErrorCode,Missing subnet mask");
1025 return 0;
1026 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001027
1028 if (type == 2) {
1029 int net = atoi(mask);
1030
1031 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1032 return -1;
1033
1034 if (dut->no_ip_addr_set) {
1035 snprintf(buf, sizeof(buf),
1036 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1037 ifname);
1038 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1039 if (system(buf) != 0) {
1040 sigma_dut_print(dut, DUT_MSG_DEBUG,
1041 "Failed to disable IPv6 address before association");
1042 }
1043 } else {
1044 snprintf(buf, sizeof(buf),
1045 "ip -6 addr del %s/%s dev %s",
1046 ip, mask, ifname);
1047 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1048 if (system(buf) != 0) {
1049 /*
1050 * This command may fail if the address being
1051 * deleted does not exist. Inaction here is
1052 * intentional.
1053 */
1054 }
1055
1056 snprintf(buf, sizeof(buf),
1057 "ip -6 addr add %s/%s dev %s",
1058 ip, mask, ifname);
1059 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1060 if (system(buf) != 0) {
1061 send_resp(dut, conn, SIGMA_ERROR,
1062 "ErrorCode,Failed to set IPv6 address");
1063 return 0;
1064 }
1065 }
1066
1067 dut->last_set_ip_config_ipv6 = 1;
1068 static_ip_file(6, ip, mask, NULL);
1069 return 1;
1070 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301071 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001072 return -1;
1073 }
1074
1075 kill_dhcp_client(dut, ifname);
1076
1077 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301078 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001079 send_resp(dut, conn, SIGMA_ERROR,
1080 "ErrorCode,Failed to set IP address");
1081 return 0;
1082 }
1083 }
1084
1085 gw = get_param(cmd, "defaultGateway");
1086 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301087 if (set_ipv4_gw(dut, gw) < 1) {
1088 send_resp(dut, conn, SIGMA_ERROR,
1089 "ErrorCode,Failed to set default gateway");
1090 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001091 }
1092 }
1093
1094 val = get_param(cmd, "primary-dns");
1095 if (val) {
1096 /* TODO */
1097 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1098 "setting", val);
1099 }
1100
1101 val = get_param(cmd, "secondary-dns");
1102 if (val) {
1103 /* TODO */
1104 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1105 "setting", val);
1106 }
1107
1108 static_ip_file(4, ip, mask, gw);
1109
1110 return 1;
1111}
1112
1113
1114static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1115 struct sigma_cmd *cmd)
1116{
1117 /* const char *intf = get_param(cmd, "Interface"); */
1118 /* TODO: could report more details here */
1119 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1120 return 0;
1121}
1122
1123
1124static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1125 struct sigma_conn *conn,
1126 struct sigma_cmd *cmd)
1127{
1128 /* const char *intf = get_param(cmd, "Interface"); */
1129 char addr[20], resp[50];
1130
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301131 if (dut->dev_role == DEVROLE_STA_CFON)
1132 return sta_cfon_get_mac_address(dut, conn, cmd);
1133
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001134 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1135 < 0)
1136 return -2;
1137
1138 snprintf(resp, sizeof(resp), "mac,%s", addr);
1139 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1140 return 0;
1141}
1142
1143
1144static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1145 struct sigma_cmd *cmd)
1146{
1147 /* const char *intf = get_param(cmd, "Interface"); */
1148 int connected = 0;
1149 char result[32];
1150 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1151 sizeof(result)) < 0) {
1152 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1153 "%s status", get_station_ifname());
1154 return -2;
1155 }
1156
1157 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1158 if (strncmp(result, "COMPLETED", 9) == 0)
1159 connected = 1;
1160
1161 if (connected)
1162 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1163 else
1164 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1165
1166 return 0;
1167}
1168
1169
1170static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1171 struct sigma_conn *conn,
1172 struct sigma_cmd *cmd)
1173{
1174 /* const char *intf = get_param(cmd, "Interface"); */
1175 const char *dst, *timeout;
1176 int wait_time = 90;
1177 char buf[100];
1178 int res;
1179
1180 dst = get_param(cmd, "destination");
1181 if (dst == NULL || !is_ip_addr(dst))
1182 return -1;
1183
1184 timeout = get_param(cmd, "timeout");
1185 if (timeout) {
1186 wait_time = atoi(timeout);
1187 if (wait_time < 1)
1188 wait_time = 1;
1189 }
1190
1191 /* TODO: force renewal of IP lease if DHCP is enabled */
1192
1193 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1194 res = system(buf);
1195 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1196 if (res == 0)
1197 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1198 else if (res == 256)
1199 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1200 else
1201 return -2;
1202
1203 return 0;
1204}
1205
1206
1207static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1208 struct sigma_cmd *cmd)
1209{
1210 /* const char *intf = get_param(cmd, "Interface"); */
1211 char bssid[20], resp[50];
1212
1213 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1214 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001215 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001216
1217 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1218 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1219 return 0;
1220}
1221
1222
1223#ifdef __SAMSUNG__
1224static int add_use_network(const char *ifname)
1225{
1226 char buf[100];
1227
1228 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1229 wpa_command(ifname, buf);
1230 return 0;
1231}
1232#endif /* __SAMSUNG__ */
1233
1234
1235static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1236 const char *ifname, struct sigma_cmd *cmd)
1237{
1238 const char *ssid = get_param(cmd, "ssid");
1239 int id;
1240 const char *val;
1241
1242 if (ssid == NULL)
1243 return -1;
1244
1245 start_sta_mode(dut);
1246
1247#ifdef __SAMSUNG__
1248 add_use_network(ifname);
1249#endif /* __SAMSUNG__ */
1250
1251 id = add_network(ifname);
1252 if (id < 0)
1253 return -2;
1254 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1255
1256 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1257 return -2;
1258
1259 dut->infra_network_id = id;
1260 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1261
1262 val = get_param(cmd, "program");
1263 if (!val)
1264 val = get_param(cmd, "prog");
1265 if (val && strcasecmp(val, "hs2") == 0) {
1266 char buf[100];
1267 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1268 wpa_command(ifname, buf);
1269
1270 val = get_param(cmd, "prefer");
1271 if (val && atoi(val) > 0)
1272 set_network(ifname, id, "priority", "1");
1273 }
1274
1275 return id;
1276}
1277
1278
1279static int cmd_sta_set_encryption(struct sigma_dut *dut,
1280 struct sigma_conn *conn,
1281 struct sigma_cmd *cmd)
1282{
1283 const char *intf = get_param(cmd, "Interface");
1284 const char *ssid = get_param(cmd, "ssid");
1285 const char *type = get_param(cmd, "encpType");
1286 const char *ifname;
1287 char buf[200];
1288 int id;
1289
1290 if (intf == NULL || ssid == NULL)
1291 return -1;
1292
1293 if (strcmp(intf, get_main_ifname()) == 0)
1294 ifname = get_station_ifname();
1295 else
1296 ifname = intf;
1297
1298 id = add_network_common(dut, conn, ifname, cmd);
1299 if (id < 0)
1300 return id;
1301
1302 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1303 return -2;
1304
1305 if (type && strcasecmp(type, "wep") == 0) {
1306 const char *val;
1307 int i;
1308
1309 val = get_param(cmd, "activeKey");
1310 if (val) {
1311 int keyid;
1312 keyid = atoi(val);
1313 if (keyid < 1 || keyid > 4)
1314 return -1;
1315 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1316 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1317 return -2;
1318 }
1319
1320 for (i = 0; i < 4; i++) {
1321 snprintf(buf, sizeof(buf), "key%d", i + 1);
1322 val = get_param(cmd, buf);
1323 if (val == NULL)
1324 continue;
1325 snprintf(buf, sizeof(buf), "wep_key%d", i);
1326 if (set_network(ifname, id, buf, val) < 0)
1327 return -2;
1328 }
1329 }
1330
1331 return 1;
1332}
1333
1334
1335static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1336 const char *ifname, struct sigma_cmd *cmd)
1337{
1338 const char *val;
1339 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001340 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001341 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301342 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001343
1344 id = add_network_common(dut, conn, ifname, cmd);
1345 if (id < 0)
1346 return id;
1347
Jouni Malinen47dcc952017-10-09 16:43:24 +03001348 val = get_param(cmd, "Type");
1349 owe = val && strcasecmp(val, "OWE") == 0;
1350
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001351 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001352 if (!val && owe)
1353 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001354 if (val == NULL) {
1355 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1356 return 0;
1357 }
1358 if (strcasecmp(val, "wpa") == 0 ||
1359 strcasecmp(val, "wpa-psk") == 0) {
1360 if (set_network(ifname, id, "proto", "WPA") < 0)
1361 return -2;
1362 } else if (strcasecmp(val, "wpa2") == 0 ||
1363 strcasecmp(val, "wpa2-psk") == 0 ||
1364 strcasecmp(val, "wpa2-ft") == 0 ||
1365 strcasecmp(val, "wpa2-sha256") == 0) {
1366 if (set_network(ifname, id, "proto", "WPA2") < 0)
1367 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301368 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1369 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001370 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1371 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001372 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301373 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001374 if (set_network(ifname, id, "proto", "WPA2") < 0)
1375 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001376 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001377 } else {
1378 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1379 return 0;
1380 }
1381
1382 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001383 if (val) {
1384 cipher_set = 1;
1385 if (strcasecmp(val, "tkip") == 0) {
1386 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1387 return -2;
1388 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1389 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1390 return -2;
1391 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1392 if (set_network(ifname, id, "pairwise",
1393 "CCMP TKIP") < 0)
1394 return -2;
1395 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1396 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1397 return -2;
1398 if (set_network(ifname, id, "group", "GCMP") < 0)
1399 return -2;
1400 } else {
1401 send_resp(dut, conn, SIGMA_ERROR,
1402 "errorCode,Unrecognized encpType value");
1403 return 0;
1404 }
1405 }
1406
1407 val = get_param(cmd, "PairwiseCipher");
1408 if (val) {
1409 cipher_set = 1;
1410 /* TODO: Support space separated list */
1411 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1412 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1413 return -2;
1414 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1415 if (set_network(ifname, id, "pairwise",
1416 "CCMP-256") < 0)
1417 return -2;
1418 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1419 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1420 return -2;
1421 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1422 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1423 return -2;
1424 } else {
1425 send_resp(dut, conn, SIGMA_ERROR,
1426 "errorCode,Unrecognized PairwiseCipher value");
1427 return 0;
1428 }
1429 }
1430
Jouni Malinen47dcc952017-10-09 16:43:24 +03001431 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001432 send_resp(dut, conn, SIGMA_ERROR,
1433 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001434 return 0;
1435 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001436
1437 val = get_param(cmd, "GroupCipher");
1438 if (val) {
1439 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1440 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1441 return -2;
1442 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1443 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1444 return -2;
1445 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1446 if (set_network(ifname, id, "group", "GCMP") < 0)
1447 return -2;
1448 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1449 if (set_network(ifname, id, "group", "CCMP") < 0)
1450 return -2;
1451 } else {
1452 send_resp(dut, conn, SIGMA_ERROR,
1453 "errorCode,Unrecognized GroupCipher value");
1454 return 0;
1455 }
1456 }
1457
Jouni Malinen7b239522017-09-14 21:37:18 +03001458 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001459 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001460 const char *cipher;
1461
1462 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1463 cipher = "BIP-GMAC-256";
1464 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1465 cipher = "BIP-CMAC-256";
1466 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1467 cipher = "BIP-GMAC-128";
1468 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1469 cipher = "AES-128-CMAC";
1470 } else {
1471 send_resp(dut, conn, SIGMA_INVALID,
1472 "errorCode,Unsupported GroupMgntCipher");
1473 return 0;
1474 }
1475 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1476 send_resp(dut, conn, SIGMA_INVALID,
1477 "errorCode,Failed to set GroupMgntCipher");
1478 return 0;
1479 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001480 }
1481
1482 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301483
1484 if (dut->program == PROGRAM_OCE) {
1485 dut->sta_pmf = STA_PMF_OPTIONAL;
1486 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1487 return -2;
1488 }
1489
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001490 val = get_param(cmd, "PMF");
1491 if (val) {
1492 if (strcasecmp(val, "Required") == 0 ||
1493 strcasecmp(val, "Forced_Required") == 0) {
1494 dut->sta_pmf = STA_PMF_REQUIRED;
1495 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1496 return -2;
1497 } else if (strcasecmp(val, "Optional") == 0) {
1498 dut->sta_pmf = STA_PMF_OPTIONAL;
1499 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1500 return -2;
1501 } else if (strcasecmp(val, "Disabled") == 0 ||
1502 strcasecmp(val, "Forced_Disabled") == 0) {
1503 dut->sta_pmf = STA_PMF_DISABLED;
1504 } else {
1505 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1506 return 0;
1507 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301508 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001509 dut->sta_pmf = STA_PMF_REQUIRED;
1510 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1511 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001512 }
1513
1514 return id;
1515}
1516
1517
1518static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1519 struct sigma_cmd *cmd)
1520{
1521 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001522 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001523 const char *pmf = get_param(cmd, "PMF");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001524 const char *ifname, *val, *alg;
1525 int id;
1526
1527 if (intf == NULL)
1528 return -1;
1529
1530 if (strcmp(intf, get_main_ifname()) == 0)
1531 ifname = get_station_ifname();
1532 else
1533 ifname = intf;
1534
1535 id = set_wpa_common(dut, conn, ifname, cmd);
1536 if (id < 0)
1537 return id;
1538
1539 val = get_param(cmd, "keyMgmtType");
1540 alg = get_param(cmd, "micAlg");
1541
Jouni Malinen992a81e2017-08-22 13:57:47 +03001542 if (type && strcasecmp(type, "SAE") == 0) {
1543 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1544 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1545 return -2;
1546 } else {
1547 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1548 return -2;
1549 }
1550 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1551 sigma_dut_print(dut, DUT_MSG_ERROR,
1552 "Failed to clear sae_groups to default");
1553 return -2;
1554 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001555 if (!pmf) {
1556 dut->sta_pmf = STA_PMF_REQUIRED;
1557 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1558 return -2;
1559 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001560 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1561 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1562 if (set_network(ifname, id, "key_mgmt",
1563 "FT-SAE FT-PSK") < 0)
1564 return -2;
1565 } else {
1566 if (set_network(ifname, id, "key_mgmt",
1567 "SAE WPA-PSK") < 0)
1568 return -2;
1569 }
1570 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1571 sigma_dut_print(dut, DUT_MSG_ERROR,
1572 "Failed to clear sae_groups to default");
1573 return -2;
1574 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001575 if (!pmf) {
1576 dut->sta_pmf = STA_PMF_OPTIONAL;
1577 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1578 return -2;
1579 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001580 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001581 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1582 return -2;
1583 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1584 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1585 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301586 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1587 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1588 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001589 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1590 dut->sta_pmf == STA_PMF_REQUIRED) {
1591 if (set_network(ifname, id, "key_mgmt",
1592 "WPA-PSK WPA-PSK-SHA256") < 0)
1593 return -2;
1594 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1595 if (set_network(ifname, id, "key_mgmt",
1596 "WPA-PSK WPA-PSK-SHA256") < 0)
1597 return -2;
1598 } else {
1599 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1600 return -2;
1601 }
1602
1603 val = get_param(cmd, "passPhrase");
1604 if (val == NULL)
1605 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001606 if (type && strcasecmp(type, "SAE") == 0) {
1607 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1608 return -2;
1609 } else {
1610 if (set_network_quoted(ifname, id, "psk", val) < 0)
1611 return -2;
1612 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001613
Jouni Malinen992a81e2017-08-22 13:57:47 +03001614 val = get_param(cmd, "ECGroupID");
1615 if (val) {
1616 char buf[50];
1617
1618 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1619 if (wpa_command(ifname, buf) != 0) {
1620 sigma_dut_print(dut, DUT_MSG_ERROR,
1621 "Failed to clear sae_groups");
1622 return -2;
1623 }
1624 }
1625
Jouni Malinen68143132017-09-02 02:34:08 +03001626 val = get_param(cmd, "InvalidSAEElement");
1627 if (val) {
1628 free(dut->sae_commit_override);
1629 dut->sae_commit_override = strdup(val);
1630 }
1631
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001632 return 1;
1633}
1634
1635
1636static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301637 const char *ifname, int username_identity,
1638 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001639{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301640 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641 int id;
1642 char buf[200];
1643#ifdef ANDROID
1644 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1645 int length;
1646#endif /* ANDROID */
1647
1648 id = set_wpa_common(dut, conn, ifname, cmd);
1649 if (id < 0)
1650 return id;
1651
1652 val = get_param(cmd, "keyMgmtType");
1653 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301654 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001655
Jouni Malinenad395a22017-09-01 21:13:46 +03001656 if (val && strcasecmp(val, "SuiteB") == 0) {
1657 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1658 0)
1659 return -2;
1660 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001661 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1662 return -2;
1663 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1664 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1665 return -2;
1666 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1667 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1668 return -2;
1669 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1670 dut->sta_pmf == STA_PMF_REQUIRED) {
1671 if (set_network(ifname, id, "key_mgmt",
1672 "WPA-EAP WPA-EAP-SHA256") < 0)
1673 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301674 } else if (akm && atoi(akm) == 14) {
1675 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1676 dut->sta_pmf == STA_PMF_REQUIRED) {
1677 if (set_network(ifname, id, "key_mgmt",
1678 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1679 return -2;
1680 } else {
1681 if (set_network(ifname, id, "key_mgmt",
1682 "WPA-EAP FILS-SHA256") < 0)
1683 return -2;
1684 }
1685
1686 if (set_network(ifname, id, "erp", "1") < 0)
1687 return -2;
1688 } else if (akm && atoi(akm) == 15) {
1689 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1690 dut->sta_pmf == STA_PMF_REQUIRED) {
1691 if (set_network(ifname, id, "key_mgmt",
1692 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1693 return -2;
1694 } else {
1695 if (set_network(ifname, id, "key_mgmt",
1696 "WPA-EAP FILS-SHA384") < 0)
1697 return -2;
1698 }
1699
1700 if (set_network(ifname, id, "erp", "1") < 0)
1701 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001702 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1703 if (set_network(ifname, id, "key_mgmt",
1704 "WPA-EAP WPA-EAP-SHA256") < 0)
1705 return -2;
1706 } else {
1707 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1708 return -2;
1709 }
1710
1711 val = get_param(cmd, "trustedRootCA");
1712 if (val) {
1713#ifdef ANDROID
1714 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1715 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1716 kvalue);
1717 if (length > 0) {
1718 sigma_dut_print(dut, DUT_MSG_INFO,
1719 "Use Android keystore [%s]", buf);
1720 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1721 val);
1722 goto ca_cert_selected;
1723 }
1724#endif /* ANDROID */
1725
1726 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1727#ifdef __linux__
1728 if (!file_exists(buf)) {
1729 char msg[300];
1730 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1731 "file (%s) not found", buf);
1732 send_resp(dut, conn, SIGMA_ERROR, msg);
1733 return -3;
1734 }
1735#endif /* __linux__ */
1736#ifdef ANDROID
1737ca_cert_selected:
1738#endif /* ANDROID */
1739 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1740 return -2;
1741 }
1742
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301743 if (username_identity) {
1744 val = get_param(cmd, "username");
1745 if (val) {
1746 if (set_network_quoted(ifname, id, "identity", val) < 0)
1747 return -2;
1748 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001749
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301750 val = get_param(cmd, "password");
1751 if (val) {
1752 if (set_network_quoted(ifname, id, "password", val) < 0)
1753 return -2;
1754 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001755 }
1756
1757 return id;
1758}
1759
1760
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001761static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1762{
1763 const char *val;
1764
1765 if (!cipher)
1766 return 0;
1767
1768 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1769 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1770 else if (strcasecmp(cipher,
1771 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1772 val = "ECDHE-RSA-AES256-GCM-SHA384";
1773 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1774 val = "DHE-RSA-AES256-GCM-SHA384";
1775 else if (strcasecmp(cipher,
1776 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1777 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1778 else
1779 return -1;
1780
1781 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1782 set_network_quoted(ifname, id, "phase1", "");
1783
1784 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1785}
1786
1787
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001788static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1789 struct sigma_cmd *cmd)
1790{
1791 const char *intf = get_param(cmd, "Interface");
1792 const char *ifname, *val;
1793 int id;
1794 char buf[200];
1795#ifdef ANDROID
1796 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1797 int length;
1798 int jb_or_newer = 0;
1799 char prop[PROPERTY_VALUE_MAX];
1800#endif /* ANDROID */
1801
1802 if (intf == NULL)
1803 return -1;
1804
1805 if (strcmp(intf, get_main_ifname()) == 0)
1806 ifname = get_station_ifname();
1807 else
1808 ifname = intf;
1809
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301810 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001811 if (id < 0)
1812 return id;
1813
1814 if (set_network(ifname, id, "eap", "TLS") < 0)
1815 return -2;
1816
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301817 if (!get_param(cmd, "username") &&
1818 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001819 "wifi-user@wifilabs.local") < 0)
1820 return -2;
1821
1822 val = get_param(cmd, "clientCertificate");
1823 if (val == NULL)
1824 return -1;
1825#ifdef ANDROID
1826 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1827 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1828 if (length < 0) {
1829 /*
1830 * JB started reporting keystore type mismatches, so retry with
1831 * the GET_PUBKEY command if the generic GET fails.
1832 */
1833 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1834 buf, kvalue);
1835 }
1836
1837 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1838 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1839 if (strncmp(prop, "4.0", 3) != 0)
1840 jb_or_newer = 1;
1841 } else
1842 jb_or_newer = 1; /* assume newer */
1843
1844 if (jb_or_newer && length > 0) {
1845 sigma_dut_print(dut, DUT_MSG_INFO,
1846 "Use Android keystore [%s]", buf);
1847 if (set_network(ifname, id, "engine", "1") < 0)
1848 return -2;
1849 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1850 return -2;
1851 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1852 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1853 return -2;
1854 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1855 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1856 return -2;
1857 return 1;
1858 } else if (length > 0) {
1859 sigma_dut_print(dut, DUT_MSG_INFO,
1860 "Use Android keystore [%s]", buf);
1861 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1862 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1863 return -2;
1864 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1865 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1866 return -2;
1867 return 1;
1868 }
1869#endif /* ANDROID */
1870
1871 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1872#ifdef __linux__
1873 if (!file_exists(buf)) {
1874 char msg[300];
1875 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1876 "(%s) not found", buf);
1877 send_resp(dut, conn, SIGMA_ERROR, msg);
1878 return -3;
1879 }
1880#endif /* __linux__ */
1881 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1882 return -2;
1883 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1884 return -2;
1885
1886 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1887 return -2;
1888
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001889 val = get_param(cmd, "keyMgmtType");
1890 if (val && strcasecmp(val, "SuiteB") == 0) {
1891 val = get_param(cmd, "CertType");
1892 if (val && strcasecmp(val, "RSA") == 0) {
1893 if (set_network_quoted(ifname, id, "phase1",
1894 "tls_suiteb=1") < 0)
1895 return -2;
1896 } else {
1897 if (set_network_quoted(ifname, id, "openssl_ciphers",
1898 "SUITEB192") < 0)
1899 return -2;
1900 }
1901
1902 val = get_param(cmd, "TLSCipher");
1903 if (set_tls_cipher(ifname, id, val) < 0) {
1904 send_resp(dut, conn, SIGMA_ERROR,
1905 "ErrorCode,Unsupported TLSCipher value");
1906 return -3;
1907 }
1908 }
1909
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001910 return 1;
1911}
1912
1913
1914static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1915 struct sigma_cmd *cmd)
1916{
1917 const char *intf = get_param(cmd, "Interface");
1918 const char *ifname;
1919 int id;
1920
1921 if (intf == NULL)
1922 return -1;
1923
1924 if (strcmp(intf, get_main_ifname()) == 0)
1925 ifname = get_station_ifname();
1926 else
1927 ifname = intf;
1928
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301929 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001930 if (id < 0)
1931 return id;
1932
1933 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1934 send_resp(dut, conn, SIGMA_ERROR,
1935 "errorCode,Failed to set TTLS method");
1936 return 0;
1937 }
1938
1939 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1940 send_resp(dut, conn, SIGMA_ERROR,
1941 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1942 return 0;
1943 }
1944
1945 return 1;
1946}
1947
1948
1949static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1950 struct sigma_cmd *cmd)
1951{
1952 const char *intf = get_param(cmd, "Interface");
1953 const char *ifname;
1954 int id;
1955
1956 if (intf == NULL)
1957 return -1;
1958
1959 if (strcmp(intf, get_main_ifname()) == 0)
1960 ifname = get_station_ifname();
1961 else
1962 ifname = intf;
1963
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301964 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001965 if (id < 0)
1966 return id;
1967
1968 if (set_network(ifname, id, "eap", "SIM") < 0)
1969 return -2;
1970
1971 return 1;
1972}
1973
1974
1975static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1976 struct sigma_cmd *cmd)
1977{
1978 const char *intf = get_param(cmd, "Interface");
1979 const char *ifname, *val;
1980 int id;
1981 char buf[100];
1982
1983 if (intf == NULL)
1984 return -1;
1985
1986 if (strcmp(intf, get_main_ifname()) == 0)
1987 ifname = get_station_ifname();
1988 else
1989 ifname = intf;
1990
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301991 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001992 if (id < 0)
1993 return id;
1994
1995 if (set_network(ifname, id, "eap", "PEAP") < 0)
1996 return -2;
1997
1998 val = get_param(cmd, "innerEAP");
1999 if (val) {
2000 if (strcasecmp(val, "MSCHAPv2") == 0) {
2001 if (set_network_quoted(ifname, id, "phase2",
2002 "auth=MSCHAPV2") < 0)
2003 return -2;
2004 } else if (strcasecmp(val, "GTC") == 0) {
2005 if (set_network_quoted(ifname, id, "phase2",
2006 "auth=GTC") < 0)
2007 return -2;
2008 } else
2009 return -1;
2010 }
2011
2012 val = get_param(cmd, "peapVersion");
2013 if (val) {
2014 int ver = atoi(val);
2015 if (ver < 0 || ver > 1)
2016 return -1;
2017 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2018 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2019 return -2;
2020 }
2021
2022 return 1;
2023}
2024
2025
2026static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2027 struct sigma_cmd *cmd)
2028{
2029 const char *intf = get_param(cmd, "Interface");
2030 const char *ifname, *val;
2031 int id;
2032 char buf[100];
2033
2034 if (intf == NULL)
2035 return -1;
2036
2037 if (strcmp(intf, get_main_ifname()) == 0)
2038 ifname = get_station_ifname();
2039 else
2040 ifname = intf;
2041
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302042 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002043 if (id < 0)
2044 return id;
2045
2046 if (set_network(ifname, id, "eap", "FAST") < 0)
2047 return -2;
2048
2049 val = get_param(cmd, "innerEAP");
2050 if (val) {
2051 if (strcasecmp(val, "MSCHAPV2") == 0) {
2052 if (set_network_quoted(ifname, id, "phase2",
2053 "auth=MSCHAPV2") < 0)
2054 return -2;
2055 } else if (strcasecmp(val, "GTC") == 0) {
2056 if (set_network_quoted(ifname, id, "phase2",
2057 "auth=GTC") < 0)
2058 return -2;
2059 } else
2060 return -1;
2061 }
2062
2063 val = get_param(cmd, "validateServer");
2064 if (val) {
2065 /* TODO */
2066 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2067 "validateServer=%s", val);
2068 }
2069
2070 val = get_param(cmd, "pacFile");
2071 if (val) {
2072 snprintf(buf, sizeof(buf), "blob://%s", val);
2073 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2074 return -2;
2075 }
2076
2077 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2078 0)
2079 return -2;
2080
2081 return 1;
2082}
2083
2084
2085static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2086 struct sigma_cmd *cmd)
2087{
2088 const char *intf = get_param(cmd, "Interface");
2089 const char *ifname;
2090 int id;
2091
2092 if (intf == NULL)
2093 return -1;
2094
2095 if (strcmp(intf, get_main_ifname()) == 0)
2096 ifname = get_station_ifname();
2097 else
2098 ifname = intf;
2099
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302100 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002101 if (id < 0)
2102 return id;
2103
2104 if (set_network(ifname, id, "eap", "AKA") < 0)
2105 return -2;
2106
2107 return 1;
2108}
2109
2110
2111static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2112 struct sigma_conn *conn,
2113 struct sigma_cmd *cmd)
2114{
2115 const char *intf = get_param(cmd, "Interface");
2116 const char *ifname;
2117 int id;
2118
2119 if (intf == NULL)
2120 return -1;
2121
2122 if (strcmp(intf, get_main_ifname()) == 0)
2123 ifname = get_station_ifname();
2124 else
2125 ifname = intf;
2126
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302127 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002128 if (id < 0)
2129 return id;
2130
2131 if (set_network(ifname, id, "eap", "AKA'") < 0)
2132 return -2;
2133
2134 return 1;
2135}
2136
2137
2138static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2139 struct sigma_cmd *cmd)
2140{
2141 const char *intf = get_param(cmd, "Interface");
2142 const char *ifname;
2143 int id;
2144
2145 if (strcmp(intf, get_main_ifname()) == 0)
2146 ifname = get_station_ifname();
2147 else
2148 ifname = intf;
2149
2150 id = add_network_common(dut, conn, ifname, cmd);
2151 if (id < 0)
2152 return id;
2153
2154 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2155 return -2;
2156
2157 return 1;
2158}
2159
2160
Jouni Malinen47dcc952017-10-09 16:43:24 +03002161static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2162 struct sigma_cmd *cmd)
2163{
2164 const char *intf = get_param(cmd, "Interface");
2165 const char *ifname, *val;
2166 int id;
2167
2168 if (intf == NULL)
2169 return -1;
2170
2171 if (strcmp(intf, get_main_ifname()) == 0)
2172 ifname = get_station_ifname();
2173 else
2174 ifname = intf;
2175
2176 id = set_wpa_common(dut, conn, ifname, cmd);
2177 if (id < 0)
2178 return id;
2179
2180 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2181 return -2;
2182
2183 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002184 if (val && strcmp(val, "0") == 0) {
2185 if (wpa_command(ifname,
2186 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2187 sigma_dut_print(dut, DUT_MSG_ERROR,
2188 "Failed to set OWE DH Param element override");
2189 return -2;
2190 }
2191 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002192 sigma_dut_print(dut, DUT_MSG_ERROR,
2193 "Failed to clear owe_group");
2194 return -2;
2195 }
2196
2197 return 1;
2198}
2199
2200
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002201static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2202 struct sigma_cmd *cmd)
2203{
2204 const char *type = get_param(cmd, "Type");
2205
2206 if (type == NULL) {
2207 send_resp(dut, conn, SIGMA_ERROR,
2208 "ErrorCode,Missing Type argument");
2209 return 0;
2210 }
2211
2212 if (strcasecmp(type, "OPEN") == 0)
2213 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002214 if (strcasecmp(type, "OWE") == 0)
2215 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002216 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002217 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002218 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002219 return cmd_sta_set_psk(dut, conn, cmd);
2220 if (strcasecmp(type, "EAPTLS") == 0)
2221 return cmd_sta_set_eaptls(dut, conn, cmd);
2222 if (strcasecmp(type, "EAPTTLS") == 0)
2223 return cmd_sta_set_eapttls(dut, conn, cmd);
2224 if (strcasecmp(type, "EAPPEAP") == 0)
2225 return cmd_sta_set_peap(dut, conn, cmd);
2226 if (strcasecmp(type, "EAPSIM") == 0)
2227 return cmd_sta_set_eapsim(dut, conn, cmd);
2228 if (strcasecmp(type, "EAPFAST") == 0)
2229 return cmd_sta_set_eapfast(dut, conn, cmd);
2230 if (strcasecmp(type, "EAPAKA") == 0)
2231 return cmd_sta_set_eapaka(dut, conn, cmd);
2232 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2233 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002234 if (strcasecmp(type, "wep") == 0)
2235 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002236
2237 send_resp(dut, conn, SIGMA_ERROR,
2238 "ErrorCode,Unsupported Type value");
2239 return 0;
2240}
2241
2242
2243int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2244{
2245#ifdef __linux__
2246 /* special handling for ath6kl */
2247 char path[128], fname[128], *pos;
2248 ssize_t res;
2249 FILE *f;
2250
2251 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2252 res = readlink(path, path, sizeof(path));
2253 if (res < 0)
2254 return 0; /* not ath6kl */
2255
2256 if (res >= (int) sizeof(path))
2257 res = sizeof(path) - 1;
2258 path[res] = '\0';
2259 pos = strrchr(path, '/');
2260 if (pos == NULL)
2261 pos = path;
2262 else
2263 pos++;
2264 snprintf(fname, sizeof(fname),
2265 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2266 "create_qos", pos);
2267 if (!file_exists(fname))
2268 return 0; /* not ath6kl */
2269
2270 if (uapsd) {
2271 f = fopen(fname, "w");
2272 if (f == NULL)
2273 return -1;
2274
2275 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2276 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2277 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2278 "20000 0\n");
2279 fclose(f);
2280 } else {
2281 snprintf(fname, sizeof(fname),
2282 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2283 "delete_qos", pos);
2284
2285 f = fopen(fname, "w");
2286 if (f == NULL)
2287 return -1;
2288
2289 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2290 fprintf(f, "2 4\n");
2291 fclose(f);
2292 }
2293#endif /* __linux__ */
2294
2295 return 0;
2296}
2297
2298
2299static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2300 struct sigma_cmd *cmd)
2301{
2302 const char *intf = get_param(cmd, "Interface");
2303 /* const char *ssid = get_param(cmd, "ssid"); */
2304 const char *val;
2305 int max_sp_len = 4;
2306 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2307 char buf[100];
2308 int ret1, ret2;
2309
2310 val = get_param(cmd, "maxSPLength");
2311 if (val) {
2312 max_sp_len = atoi(val);
2313 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2314 max_sp_len != 4)
2315 return -1;
2316 }
2317
2318 val = get_param(cmd, "acBE");
2319 if (val)
2320 ac_be = atoi(val);
2321
2322 val = get_param(cmd, "acBK");
2323 if (val)
2324 ac_bk = atoi(val);
2325
2326 val = get_param(cmd, "acVI");
2327 if (val)
2328 ac_vi = atoi(val);
2329
2330 val = get_param(cmd, "acVO");
2331 if (val)
2332 ac_vo = atoi(val);
2333
2334 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2335
2336 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2337 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2338 ret1 = wpa_command(intf, buf);
2339
2340 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2341 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2342 ret2 = wpa_command(intf, buf);
2343
2344 if (ret1 && ret2) {
2345 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2346 "UAPSD parameters.");
2347 return -2;
2348 }
2349
2350 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2351 send_resp(dut, conn, SIGMA_ERROR,
2352 "ErrorCode,Failed to set ath6kl QoS parameters");
2353 return 0;
2354 }
2355
2356 return 1;
2357}
2358
2359
2360static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2361 struct sigma_cmd *cmd)
2362{
2363 char buf[1000];
2364 const char *intf = get_param(cmd, "Interface");
2365 const char *grp = get_param(cmd, "Group");
2366 const char *act = get_param(cmd, "Action");
2367 const char *tid = get_param(cmd, "Tid");
2368 const char *dir = get_param(cmd, "Direction");
2369 const char *psb = get_param(cmd, "Psb");
2370 const char *up = get_param(cmd, "Up");
2371 const char *fixed = get_param(cmd, "Fixed");
2372 const char *size = get_param(cmd, "Size");
2373 const char *msize = get_param(cmd, "Maxsize");
2374 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2375 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2376 const char *inact = get_param(cmd, "Inactivity");
2377 const char *sus = get_param(cmd, "Suspension");
2378 const char *mindr = get_param(cmd, "Mindatarate");
2379 const char *meandr = get_param(cmd, "Meandatarate");
2380 const char *peakdr = get_param(cmd, "Peakdatarate");
2381 const char *phyrate = get_param(cmd, "Phyrate");
2382 const char *burstsize = get_param(cmd, "Burstsize");
2383 const char *sba = get_param(cmd, "Sba");
2384 int direction;
2385 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002386 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002387 int fixed_int;
2388 int psb_ts;
2389
2390 if (intf == NULL || grp == NULL || act == NULL )
2391 return -1;
2392
2393 if (strcasecmp(act, "addts") == 0) {
2394 if (tid == NULL || dir == NULL || psb == NULL ||
2395 up == NULL || fixed == NULL || size == NULL)
2396 return -1;
2397
2398 /*
2399 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2400 * possible values, but WMM-AC and V-E test scripts use "UP,
2401 * "DOWN", and "BIDI".
2402 */
2403 if (strcasecmp(dir, "uplink") == 0 ||
2404 strcasecmp(dir, "up") == 0) {
2405 direction = 0;
2406 } else if (strcasecmp(dir, "downlink") == 0 ||
2407 strcasecmp(dir, "down") == 0) {
2408 direction = 1;
2409 } else if (strcasecmp(dir, "bidi") == 0) {
2410 direction = 2;
2411 } else {
2412 sigma_dut_print(dut, DUT_MSG_ERROR,
2413 "Direction %s not supported", dir);
2414 return -1;
2415 }
2416
2417 if (strcasecmp(psb, "legacy") == 0) {
2418 psb_ts = 0;
2419 } else if (strcasecmp(psb, "uapsd") == 0) {
2420 psb_ts = 1;
2421 } else {
2422 sigma_dut_print(dut, DUT_MSG_ERROR,
2423 "PSB %s not supported", psb);
2424 return -1;
2425 }
2426
2427 if (atoi(tid) < 0 || atoi(tid) > 7) {
2428 sigma_dut_print(dut, DUT_MSG_ERROR,
2429 "TID %s not supported", tid);
2430 return -1;
2431 }
2432
2433 if (strcasecmp(fixed, "true") == 0) {
2434 fixed_int = 1;
2435 } else {
2436 fixed_int = 0;
2437 }
2438
Peng Xu93319622017-10-04 17:58:16 -07002439 if (sba)
2440 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002441
2442 dut->dialog_token++;
2443 handle = 7000 + dut->dialog_token;
2444
2445 /*
2446 * size: convert to hex
2447 * maxsi: convert to hex
2448 * mindr: convert to hex
2449 * meandr: convert to hex
2450 * peakdr: convert to hex
2451 * burstsize: convert to hex
2452 * phyrate: convert to hex
2453 * sba: convert to hex with modification
2454 * minsi: convert to integer
2455 * sus: convert to integer
2456 * inact: convert to integer
2457 * maxsi: convert to integer
2458 */
2459
2460 /*
2461 * The Nominal MSDU Size field is 2 octets long and contains an
2462 * unsigned integer that specifies the nominal size, in octets,
2463 * of MSDUs belonging to the traffic under this traffic
2464 * specification and is defined in Figure 16. If the Fixed
2465 * subfield is set to 1, then the size of the MSDU is fixed and
2466 * is indicated by the Size Subfield. If the Fixed subfield is
2467 * set to 0, then the size of the MSDU might not be fixed and
2468 * the Size indicates the nominal MSDU size.
2469 *
2470 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2471 * and specifies the excess allocation of time (and bandwidth)
2472 * over and above the stated rates required to transport an MSDU
2473 * belonging to the traffic in this TSPEC. This field is
2474 * represented as an unsigned binary number with an implicit
2475 * binary point after the leftmost 3 bits. For example, an SBA
2476 * of 1.75 is represented as 0x3800. This field is included to
2477 * account for retransmissions. As such, the value of this field
2478 * must be greater than unity.
2479 */
2480
2481 snprintf(buf, sizeof(buf),
2482 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2483 " 0x%X 0x%X 0x%X"
2484 " 0x%X 0x%X 0x%X"
2485 " 0x%X %d %d %d %d"
2486 " %d %d",
2487 intf, handle, tid, direction, psb_ts, up,
2488 (unsigned int) ((fixed_int << 15) | atoi(size)),
2489 msize ? atoi(msize) : 0,
2490 mindr ? atoi(mindr) : 0,
2491 meandr ? atoi(meandr) : 0,
2492 peakdr ? atoi(peakdr) : 0,
2493 burstsize ? atoi(burstsize) : 0,
2494 phyrate ? atoi(phyrate) : 0,
2495 sba ? ((unsigned int) (((int) sba_fv << 13) |
2496 (int)((sba_fv - (int) sba_fv) *
2497 8192))) : 0,
2498 minsi ? atoi(minsi) : 0,
2499 sus ? atoi(sus) : 0,
2500 0, 0,
2501 inact ? atoi(inact) : 0,
2502 maxsi ? atoi(maxsi) : 0);
2503
2504 if (system(buf) != 0) {
2505 sigma_dut_print(dut, DUT_MSG_ERROR,
2506 "iwpriv addtspec request failed");
2507 send_resp(dut, conn, SIGMA_ERROR,
2508 "errorCode,Failed to execute addTspec command");
2509 return 0;
2510 }
2511
2512 sigma_dut_print(dut, DUT_MSG_INFO,
2513 "iwpriv addtspec request send");
2514
2515 /* Mapping handle to a TID */
2516 dut->tid_to_handle[atoi(tid)] = handle;
2517 } else if (strcasecmp(act, "delts") == 0) {
2518 if (tid == NULL)
2519 return -1;
2520
2521 if (atoi(tid) < 0 || atoi(tid) > 7) {
2522 sigma_dut_print(dut, DUT_MSG_ERROR,
2523 "TID %s not supported", tid);
2524 send_resp(dut, conn, SIGMA_ERROR,
2525 "errorCode,Unsupported TID");
2526 return 0;
2527 }
2528
2529 handle = dut->tid_to_handle[atoi(tid)];
2530
2531 if (handle < 7000 || handle > 7255) {
2532 /* Invalid handle ie no mapping for that TID */
2533 sigma_dut_print(dut, DUT_MSG_ERROR,
2534 "handle-> %d not found", handle);
2535 }
2536
2537 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2538 intf, handle);
2539
2540 if (system(buf) != 0) {
2541 sigma_dut_print(dut, DUT_MSG_ERROR,
2542 "iwpriv deltspec request failed");
2543 send_resp(dut, conn, SIGMA_ERROR,
2544 "errorCode,Failed to execute delTspec command");
2545 return 0;
2546 }
2547
2548 sigma_dut_print(dut, DUT_MSG_INFO,
2549 "iwpriv deltspec request send");
2550
2551 dut->tid_to_handle[atoi(tid)] = 0;
2552 } else {
2553 sigma_dut_print(dut, DUT_MSG_ERROR,
2554 "Action type %s not supported", act);
2555 send_resp(dut, conn, SIGMA_ERROR,
2556 "errorCode,Unsupported Action");
2557 return 0;
2558 }
2559
2560 return 1;
2561}
2562
2563
vamsi krishna52e16f92017-08-29 12:37:34 +05302564static int find_network(struct sigma_dut *dut, const char *ssid)
2565{
2566 char list[4096];
2567 char *pos;
2568
2569 sigma_dut_print(dut, DUT_MSG_DEBUG,
2570 "Search for profile based on SSID: '%s'", ssid);
2571 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2572 list, sizeof(list)) < 0)
2573 return -1;
2574 pos = strstr(list, ssid);
2575 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2576 return -1;
2577
2578 while (pos > list && pos[-1] != '\n')
2579 pos--;
2580 dut->infra_network_id = atoi(pos);
2581 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2582 return 0;
2583}
2584
2585
Sunil Dutt44595082018-02-12 19:41:45 +05302586#ifdef NL80211_SUPPORT
2587static int sta_config_rsnie(struct sigma_dut *dut, int val)
2588{
2589 struct nl_msg *msg;
2590 int ret;
2591 struct nlattr *params;
2592 int ifindex;
2593
2594 ifindex = if_nametoindex("wlan0");
2595 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2596 NL80211_CMD_VENDOR)) ||
2597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2598 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2599 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2600 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2601 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2602 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2603 sigma_dut_print(dut, DUT_MSG_ERROR,
2604 "%s: err in adding vendor_cmd and vendor_data",
2605 __func__);
2606 nlmsg_free(msg);
2607 return -1;
2608 }
2609 nla_nest_end(msg, params);
2610
2611 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2612 if (ret) {
2613 sigma_dut_print(dut, DUT_MSG_ERROR,
2614 "%s: err in send_and_recv_msgs, ret=%d",
2615 __func__, ret);
2616 return ret;
2617 }
2618
2619 return 0;
2620}
2621#endif /* NL80211_SUPPORT */
2622
2623
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002624static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2625 struct sigma_cmd *cmd)
2626{
2627 /* const char *intf = get_param(cmd, "Interface"); */
2628 const char *ssid = get_param(cmd, "ssid");
2629 const char *wps_param = get_param(cmd, "WPS");
2630 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002631 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002632 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002633 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002634
2635 if (ssid == NULL)
2636 return -1;
2637
Jouni Malinen3c367e82017-06-23 17:01:47 +03002638 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302639#ifdef NL80211_SUPPORT
2640 if (get_driver_type() == DRIVER_WCN) {
2641 sta_config_rsnie(dut, 1);
2642 dut->config_rsnie = 1;
2643 }
2644#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002645 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2646 dut->rsne_override);
2647 if (wpa_command(get_station_ifname(), buf) < 0) {
2648 send_resp(dut, conn, SIGMA_ERROR,
2649 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2650 return 0;
2651 }
2652 }
2653
Jouni Malinen68143132017-09-02 02:34:08 +03002654 if (dut->sae_commit_override) {
2655 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2656 dut->sae_commit_override);
2657 if (wpa_command(get_station_ifname(), buf) < 0) {
2658 send_resp(dut, conn, SIGMA_ERROR,
2659 "ErrorCode,Failed to set SAE commit override");
2660 return 0;
2661 }
2662 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302663#ifdef ANDROID
2664 if (dut->fils_hlp)
2665 process_fils_hlp(dut);
2666#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002667
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002668 if (wps_param &&
2669 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2670 wps = 1;
2671
2672 if (wps) {
2673 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2674 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2675 "parameters not yet set");
2676 return 0;
2677 }
2678 if (dut->wps_method == WFA_CS_WPS_PBC) {
2679 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2680 return -2;
2681 } else {
2682 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2683 dut->wps_pin);
2684 if (wpa_command(get_station_ifname(), buf) < 0)
2685 return -2;
2686 }
2687 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302688 if (strcmp(ssid, dut->infra_ssid) == 0) {
2689 sigma_dut_print(dut, DUT_MSG_DEBUG,
2690 "sta_associate for the most recently added network");
2691 } else if (find_network(dut, ssid) < 0) {
2692 sigma_dut_print(dut, DUT_MSG_DEBUG,
2693 "sta_associate for a previously stored network profile");
2694 send_resp(dut, conn, SIGMA_ERROR,
2695 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002696 return 0;
2697 }
2698
2699 if (bssid &&
2700 set_network(get_station_ifname(), dut->infra_network_id,
2701 "bssid", bssid) < 0) {
2702 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2703 "Invalid bssid argument");
2704 return 0;
2705 }
2706
Jouni Malinen46a19b62017-06-23 14:31:27 +03002707 extra[0] = '\0';
2708 if (chan)
2709 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02002710 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03002711 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2712 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713 if (wpa_command(get_station_ifname(), buf) < 0) {
2714 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2715 "network id %d on %s",
2716 dut->infra_network_id,
2717 get_station_ifname());
2718 return -2;
2719 }
2720 }
2721
2722 return 1;
2723}
2724
2725
2726static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2727{
2728 char buf[500], cmd[200];
2729 int res;
2730
2731 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2732 * default path */
2733 res = snprintf(cmd, sizeof(cmd),
2734 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2735 file_exists("./hs20-osu-client") ?
2736 "./hs20-osu-client" : "hs20-osu-client",
2737 sigma_wpas_ctrl,
2738 dut->summary_log ? "-s " : "",
2739 dut->summary_log ? dut->summary_log : "");
2740 if (res < 0 || res >= (int) sizeof(cmd))
2741 return -1;
2742
2743 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2744 if (res < 0 || res >= (int) sizeof(buf))
2745 return -1;
2746 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2747
2748 if (system(buf) != 0) {
2749 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2750 return -1;
2751 }
2752 sigma_dut_print(dut, DUT_MSG_DEBUG,
2753 "Completed hs20-osu-client operation");
2754
2755 return 0;
2756}
2757
2758
2759static int download_ppsmo(struct sigma_dut *dut,
2760 struct sigma_conn *conn,
2761 const char *intf,
2762 struct sigma_cmd *cmd)
2763{
2764 const char *name, *path, *val;
2765 char url[500], buf[600], fbuf[100];
2766 char *fqdn = NULL;
2767
2768 name = get_param(cmd, "FileName");
2769 path = get_param(cmd, "FilePath");
2770 if (name == NULL || path == NULL)
2771 return -1;
2772
2773 if (strcasecmp(path, "VendorSpecific") == 0) {
2774 snprintf(url, sizeof(url), "PPS/%s", name);
2775 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2776 "from the device (%s)", url);
2777 if (!file_exists(url)) {
2778 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2779 "PPS MO file does not exist");
2780 return 0;
2781 }
2782 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2783 if (system(buf) != 0) {
2784 send_resp(dut, conn, SIGMA_ERROR,
2785 "errorCode,Failed to copy PPS MO");
2786 return 0;
2787 }
2788 } else if (strncasecmp(path, "http:", 5) != 0 &&
2789 strncasecmp(path, "https:", 6) != 0) {
2790 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2791 "Unsupported FilePath value");
2792 return 0;
2793 } else {
2794 snprintf(url, sizeof(url), "%s/%s", path, name);
2795 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2796 url);
2797 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2798 remove("pps-tnds.xml");
2799 if (system(buf) != 0) {
2800 send_resp(dut, conn, SIGMA_ERROR,
2801 "errorCode,Failed to download PPS MO");
2802 return 0;
2803 }
2804 }
2805
2806 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2807 send_resp(dut, conn, SIGMA_ERROR,
2808 "errorCode,Failed to parse downloaded PPSMO");
2809 return 0;
2810 }
2811 unlink("pps-tnds.xml");
2812
2813 val = get_param(cmd, "managementTreeURI");
2814 if (val) {
2815 const char *pos, *end;
2816 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2817 val);
2818 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2819 send_resp(dut, conn, SIGMA_ERROR,
2820 "errorCode,Invalid managementTreeURI prefix");
2821 return 0;
2822 }
2823 pos = val + 8;
2824 end = strchr(pos, '/');
2825 if (end == NULL ||
2826 strcmp(end, "/PerProviderSubscription") != 0) {
2827 send_resp(dut, conn, SIGMA_ERROR,
2828 "errorCode,Invalid managementTreeURI postfix");
2829 return 0;
2830 }
2831 if (end - pos >= (int) sizeof(fbuf)) {
2832 send_resp(dut, conn, SIGMA_ERROR,
2833 "errorCode,Too long FQDN in managementTreeURI");
2834 return 0;
2835 }
2836 memcpy(fbuf, pos, end - pos);
2837 fbuf[end - pos] = '\0';
2838 fqdn = fbuf;
2839 sigma_dut_print(dut, DUT_MSG_INFO,
2840 "FQDN from managementTreeURI: %s", fqdn);
2841 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2842 FILE *f = fopen("pps-fqdn", "r");
2843 if (f) {
2844 if (fgets(fbuf, sizeof(fbuf), f)) {
2845 fbuf[sizeof(fbuf) - 1] = '\0';
2846 fqdn = fbuf;
2847 sigma_dut_print(dut, DUT_MSG_DEBUG,
2848 "Use FQDN %s", fqdn);
2849 }
2850 fclose(f);
2851 }
2852 }
2853
2854 if (fqdn == NULL) {
2855 send_resp(dut, conn, SIGMA_ERROR,
2856 "errorCode,No FQDN specified");
2857 return 0;
2858 }
2859
2860 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2861 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2862 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2863
2864 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2865 if (rename("pps.xml", buf) < 0) {
2866 send_resp(dut, conn, SIGMA_ERROR,
2867 "errorCode,Could not move PPS MO");
2868 return 0;
2869 }
2870
2871 if (strcasecmp(path, "VendorSpecific") == 0) {
2872 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2873 fqdn);
2874 if (system(buf)) {
2875 send_resp(dut, conn, SIGMA_ERROR,
2876 "errorCode,Failed to copy OSU CA cert");
2877 return 0;
2878 }
2879
2880 snprintf(buf, sizeof(buf),
2881 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2882 fqdn);
2883 if (system(buf)) {
2884 send_resp(dut, conn, SIGMA_ERROR,
2885 "errorCode,Failed to copy AAA CA cert");
2886 return 0;
2887 }
2888 } else {
2889 snprintf(buf, sizeof(buf),
2890 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2891 fqdn, fqdn);
2892 if (run_hs20_osu(dut, buf) < 0) {
2893 send_resp(dut, conn, SIGMA_ERROR,
2894 "errorCode,Failed to download OSU CA cert");
2895 return 0;
2896 }
2897
2898 snprintf(buf, sizeof(buf),
2899 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2900 fqdn, fqdn);
2901 if (run_hs20_osu(dut, buf) < 0) {
2902 sigma_dut_print(dut, DUT_MSG_INFO,
2903 "Failed to download AAA CA cert");
2904 }
2905 }
2906
2907 if (file_exists("next-client-cert.pem")) {
2908 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2909 if (rename("next-client-cert.pem", buf) < 0) {
2910 send_resp(dut, conn, SIGMA_ERROR,
2911 "errorCode,Could not move client certificate");
2912 return 0;
2913 }
2914 }
2915
2916 if (file_exists("next-client-key.pem")) {
2917 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2918 if (rename("next-client-key.pem", buf) < 0) {
2919 send_resp(dut, conn, SIGMA_ERROR,
2920 "errorCode,Could not move client key");
2921 return 0;
2922 }
2923 }
2924
2925 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2926 if (run_hs20_osu(dut, buf) < 0) {
2927 send_resp(dut, conn, SIGMA_ERROR,
2928 "errorCode,Failed to configure credential from "
2929 "PPSMO");
2930 return 0;
2931 }
2932
2933 return 1;
2934}
2935
2936
2937static int download_cert(struct sigma_dut *dut,
2938 struct sigma_conn *conn,
2939 const char *intf,
2940 struct sigma_cmd *cmd)
2941{
2942 const char *name, *path;
2943 char url[500], buf[600];
2944
2945 name = get_param(cmd, "FileName");
2946 path = get_param(cmd, "FilePath");
2947 if (name == NULL || path == NULL)
2948 return -1;
2949
2950 if (strcasecmp(path, "VendorSpecific") == 0) {
2951 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2952 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2953 "certificate from the device (%s)", url);
2954 if (!file_exists(url)) {
2955 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2956 "certificate file does not exist");
2957 return 0;
2958 }
2959 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2960 if (system(buf) != 0) {
2961 send_resp(dut, conn, SIGMA_ERROR,
2962 "errorCode,Failed to copy client "
2963 "certificate");
2964 return 0;
2965 }
2966
2967 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2968 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2969 "private key from the device (%s)", url);
2970 if (!file_exists(url)) {
2971 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2972 "private key file does not exist");
2973 return 0;
2974 }
2975 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2976 if (system(buf) != 0) {
2977 send_resp(dut, conn, SIGMA_ERROR,
2978 "errorCode,Failed to copy client key");
2979 return 0;
2980 }
2981 } else if (strncasecmp(path, "http:", 5) != 0 &&
2982 strncasecmp(path, "https:", 6) != 0) {
2983 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2984 "Unsupported FilePath value");
2985 return 0;
2986 } else {
2987 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2988 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2989 "certificate/key from %s", url);
2990 snprintf(buf, sizeof(buf),
2991 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2992 if (system(buf) != 0) {
2993 send_resp(dut, conn, SIGMA_ERROR,
2994 "errorCode,Failed to download client "
2995 "certificate");
2996 return 0;
2997 }
2998
2999 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3000 {
3001 send_resp(dut, conn, SIGMA_ERROR,
3002 "errorCode,Failed to copy client key");
3003 return 0;
3004 }
3005 }
3006
3007 return 1;
3008}
3009
3010
3011static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3012 struct sigma_conn *conn,
3013 const char *intf,
3014 struct sigma_cmd *cmd)
3015{
3016 const char *val;
3017
3018 val = get_param(cmd, "FileType");
3019 if (val && strcasecmp(val, "PPSMO") == 0)
3020 return download_ppsmo(dut, conn, intf, cmd);
3021 if (val && strcasecmp(val, "CERT") == 0)
3022 return download_cert(dut, conn, intf, cmd);
3023 if (val) {
3024 send_resp(dut, conn, SIGMA_ERROR,
3025 "ErrorCode,Unsupported FileType");
3026 return 0;
3027 }
3028
3029 return 1;
3030}
3031
3032
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303033static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3034 struct sigma_conn *conn,
3035 const char *intf,
3036 struct sigma_cmd *cmd)
3037{
3038 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303039 char buf[1000];
3040 char text[20];
3041 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303042
3043 val = get_param(cmd, "OCESupport");
3044 if (val && strcasecmp(val, "Disable") == 0) {
3045 if (wpa_command(intf, "SET oce 0") < 0) {
3046 send_resp(dut, conn, SIGMA_ERROR,
3047 "ErrorCode,Failed to disable OCE");
3048 return 0;
3049 }
3050 } else if (val && strcasecmp(val, "Enable") == 0) {
3051 if (wpa_command(intf, "SET oce 1") < 0) {
3052 send_resp(dut, conn, SIGMA_ERROR,
3053 "ErrorCode,Failed to enable OCE");
3054 return 0;
3055 }
3056 }
3057
vamsi krishnaa2799492017-12-05 14:28:01 +05303058 val = get_param(cmd, "FILScap");
3059 if (val && (atoi(val) == 1)) {
3060 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3061 send_resp(dut, conn, SIGMA_ERROR,
3062 "ErrorCode,Failed to enable FILS");
3063 return 0;
3064 }
3065 } else if (val && (atoi(val) == 0)) {
3066 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3067 send_resp(dut, conn, SIGMA_ERROR,
3068 "ErrorCode,Failed to disable FILS");
3069 return 0;
3070 }
3071 }
3072
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303073 val = get_param(cmd, "FILSHLP");
3074 if (val && strcasecmp(val, "Enable") == 0) {
3075 if (get_wpa_status(get_station_ifname(), "address", text,
3076 sizeof(text)) < 0)
3077 return -2;
3078 hwaddr_aton(text, addr);
3079 snprintf(buf, sizeof(buf),
3080 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3081 "080045100140000040004011399e00000000ffffffff00440043"
3082 "012cb30001010600fd4f46410000000000000000000000000000"
3083 "000000000000"
3084 "%02x%02x%02x%02x%02x%02x"
3085 "0000000000000000000000000000000000000000000000000000"
3086 "0000000000000000000000000000000000000000000000000000"
3087 "0000000000000000000000000000000000000000000000000000"
3088 "0000000000000000000000000000000000000000000000000000"
3089 "0000000000000000000000000000000000000000000000000000"
3090 "0000000000000000000000000000000000000000000000000000"
3091 "0000000000000000000000000000000000000000000000000000"
3092 "0000000000000000000000000000000000000000638253633501"
3093 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3094 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3095 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3096 if (wpa_command(intf, buf)) {
3097 send_resp(dut, conn, SIGMA_ERROR,
3098 "ErrorCode,Failed to add HLP");
3099 return 0;
3100 }
3101 dut->fils_hlp = 1;
3102 }
3103
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303104 return 1;
3105}
3106
3107
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003108static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3109 const char *val)
3110{
3111 int counter = 0;
3112 char token[50];
3113 char *result;
3114 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303115 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116
Peng Xub8fc5cc2017-05-10 17:27:28 -07003117 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003118 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303119 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003120 while (result) {
3121 if (strcmp(result, "disable") == 0) {
3122 snprintf(buf, sizeof(buf),
3123 "iwpriv %s noackpolicy %d 1 0",
3124 intf, counter);
3125 } else {
3126 snprintf(buf, sizeof(buf),
3127 "iwpriv %s noackpolicy %d 1 1",
3128 intf, counter);
3129 }
3130 if (system(buf) != 0) {
3131 sigma_dut_print(dut, DUT_MSG_ERROR,
3132 "iwpriv noackpolicy failed");
3133 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303134 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003135 counter++;
3136 }
3137}
3138
3139
3140static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3141 const char *val)
3142{
3143 char buf[100];
3144
3145 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3146 if (system(buf) != 0) {
3147 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3148 }
3149}
3150
3151
3152static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3153 const char *val)
3154{
3155 char buf[100];
3156
3157 if (strcasecmp(val, "off") == 0) {
3158 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3159 if (system(buf) != 0) {
3160 sigma_dut_print(dut, DUT_MSG_ERROR,
3161 "Failed to turn off WMM");
3162 }
3163 }
3164}
3165
3166
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003167static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3168 const char *val)
3169{
3170#ifdef NL80211_SUPPORT
3171 struct nl_msg *msg;
3172 int ret = 0;
3173 struct nlattr *params;
3174 int ifindex;
3175 int wmmenable = 1;
3176
3177 if (val &&
3178 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3179 wmmenable = 0;
3180
3181 ifindex = if_nametoindex(intf);
3182 if (ifindex == 0) {
3183 sigma_dut_print(dut, DUT_MSG_ERROR,
3184 "%s: Index for interface %s failed",
3185 __func__, intf);
3186 return -1;
3187 }
3188
3189 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3190 NL80211_CMD_VENDOR)) ||
3191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3192 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3193 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3194 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3195 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3196 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3197 wmmenable)) {
3198 sigma_dut_print(dut, DUT_MSG_ERROR,
3199 "%s: err in adding vendor_cmd and vendor_data",
3200 __func__);
3201 nlmsg_free(msg);
3202 return -1;
3203 }
3204 nla_nest_end(msg, params);
3205
3206 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3207 if (ret) {
3208 sigma_dut_print(dut, DUT_MSG_ERROR,
3209 "%s: err in send_and_recv_msgs, ret=%d",
3210 __func__, ret);
3211 }
3212 return ret;
3213#else /* NL80211_SUPPORT */
3214 sigma_dut_print(dut, DUT_MSG_ERROR,
3215 "WMM cannot be changed without NL80211_SUPPORT defined");
3216 return -1;
3217#endif /* NL80211_SUPPORT */
3218}
3219
3220
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003221static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3222 const char *val)
3223{
3224 char buf[100];
3225 int sgi20;
3226
3227 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3228
3229 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3230 if (system(buf) != 0)
3231 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3232}
3233
3234
3235static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3236 const char *val)
3237{
3238 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303239 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003240
3241 /* Disable Tx Beam forming when using a fixed rate */
3242 ath_disable_txbf(dut, intf);
3243
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303244 v = atoi(val);
3245 if (v < 0 || v > 32) {
3246 sigma_dut_print(dut, DUT_MSG_ERROR,
3247 "Invalid Fixed MCS rate: %d", v);
3248 return;
3249 }
3250 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003251
3252 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3253 intf, rate_code);
3254 if (system(buf) != 0) {
3255 sigma_dut_print(dut, DUT_MSG_ERROR,
3256 "iwpriv set11NRates failed");
3257 }
3258
3259 /* Channel width gets messed up, fix this */
3260 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3261 if (system(buf) != 0)
3262 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3263}
3264
3265
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003266static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3267 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003268{
3269 char buf[60];
3270
3271 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3272 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3273 else
3274 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3275
3276 if (system(buf) != 0)
3277 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3278}
3279
3280
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003281static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3282 int ampdu)
3283{
3284 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003285 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003286
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003287 if (ampdu)
3288 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003289 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3290 if (system(buf) != 0) {
3291 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3292 return -1;
3293 }
3294
3295 return 0;
3296}
3297
3298
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003299static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3300 const char *val)
3301{
3302 char buf[60];
3303
3304 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3305 if (system(buf) != 0) {
3306 sigma_dut_print(dut, DUT_MSG_ERROR,
3307 "iwpriv tx_stbc failed");
3308 }
3309
3310 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3311 if (system(buf) != 0) {
3312 sigma_dut_print(dut, DUT_MSG_ERROR,
3313 "iwpriv rx_stbc failed");
3314 }
3315}
3316
3317
3318static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3319 const char *val)
3320{
3321 char buf[60];
3322
Peng Xucc317ed2017-05-18 16:44:37 -07003323 if (strcmp(val, "160") == 0) {
3324 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3325 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003326 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3327 } else if (strcmp(val, "40") == 0) {
3328 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3329 } else if (strcmp(val, "20") == 0) {
3330 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3331 } else if (strcasecmp(val, "Auto") == 0) {
3332 buf[0] = '\0';
3333 } else {
3334 sigma_dut_print(dut, DUT_MSG_ERROR,
3335 "WIDTH/CTS_WIDTH value not supported");
3336 return -1;
3337 }
3338
3339 if (buf[0] != '\0' && system(buf) != 0) {
3340 sigma_dut_print(dut, DUT_MSG_ERROR,
3341 "Failed to set WIDTH/CTS_WIDTH");
3342 return -1;
3343 }
3344
3345 return 0;
3346}
3347
3348
3349int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3350 const char *intf, const char *val)
3351{
3352 char buf[60];
3353
3354 if (strcasecmp(val, "Auto") == 0) {
3355 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3356 dut->chwidth = 0;
3357 } else if (strcasecmp(val, "20") == 0) {
3358 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3359 dut->chwidth = 0;
3360 } else if (strcasecmp(val, "40") == 0) {
3361 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3362 dut->chwidth = 1;
3363 } else if (strcasecmp(val, "80") == 0) {
3364 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3365 dut->chwidth = 2;
3366 } else if (strcasecmp(val, "160") == 0) {
3367 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3368 dut->chwidth = 3;
3369 } else {
3370 send_resp(dut, conn, SIGMA_ERROR,
3371 "ErrorCode,WIDTH not supported");
3372 return -1;
3373 }
3374
3375 if (system(buf) != 0) {
3376 sigma_dut_print(dut, DUT_MSG_ERROR,
3377 "iwpriv chwidth failed");
3378 }
3379
3380 return 0;
3381}
3382
3383
3384static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3385 const char *val)
3386{
3387 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003388 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003389
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003390 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003391 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003392 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003393 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003394 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003395 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003396 } else {
3397 sigma_dut_print(dut, DUT_MSG_ERROR,
3398 "SP_STREAM value not supported");
3399 return -1;
3400 }
3401
3402 if (system(buf) != 0) {
3403 sigma_dut_print(dut, DUT_MSG_ERROR,
3404 "Failed to set SP_STREAM");
3405 return -1;
3406 }
3407
Arif Hussainac6c5112018-05-25 17:34:00 -07003408 dut->sta_nss = sta_nss;
3409
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003410 return 0;
3411}
3412
3413
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303414static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3415 const char *val)
3416{
3417 char buf[60];
3418
3419 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3420 if (system(buf) != 0)
3421 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3422
3423 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3424 if (system(buf) != 0)
3425 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3426}
3427
3428
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303429static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3430 struct sigma_conn *conn,
3431 const char *intf, int capa)
3432{
3433 char buf[32];
3434
3435 if (capa > 0 && capa < 4) {
3436 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3437 if (wpa_command(intf, buf) < 0) {
3438 send_resp(dut, conn, SIGMA_ERROR,
3439 "ErrorCode, Failed to set cellular data capability");
3440 return 0;
3441 }
3442 return 1;
3443 }
3444
3445 sigma_dut_print(dut, DUT_MSG_ERROR,
3446 "Invalid Cellular data capability: %d", capa);
3447 send_resp(dut, conn, SIGMA_INVALID,
3448 "ErrorCode,Invalid cellular data capability");
3449 return 0;
3450}
3451
3452
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303453static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3454 const char *intf, const char *val)
3455{
3456 if (strcasecmp(val, "Disable") == 0) {
3457 if (wpa_command(intf, "SET roaming 0") < 0) {
3458 send_resp(dut, conn, SIGMA_ERROR,
3459 "ErrorCode,Failed to disable roaming");
3460 return 0;
3461 }
3462 return 1;
3463 }
3464
3465 if (strcasecmp(val, "Enable") == 0) {
3466 if (wpa_command(intf, "SET roaming 1") < 0) {
3467 send_resp(dut, conn, SIGMA_ERROR,
3468 "ErrorCode,Failed to enable roaming");
3469 return 0;
3470 }
3471 return 1;
3472 }
3473
3474 sigma_dut_print(dut, DUT_MSG_ERROR,
3475 "Invalid value provided for roaming: %s", val);
3476 send_resp(dut, conn, SIGMA_INVALID,
3477 "ErrorCode,Unknown value provided for Roaming");
3478 return 0;
3479}
3480
3481
Ashwini Patila75de5a2017-04-13 16:35:05 +05303482static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3483 struct sigma_conn *conn,
3484 const char *intf, const char *val)
3485{
3486 if (strcasecmp(val, "Disable") == 0) {
3487 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3488 send_resp(dut, conn, SIGMA_ERROR,
3489 "ErrorCode,Failed to disable Assoc_disallow");
3490 return 0;
3491 }
3492 return 1;
3493 }
3494
3495 if (strcasecmp(val, "Enable") == 0) {
3496 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3497 send_resp(dut, conn, SIGMA_ERROR,
3498 "ErrorCode,Failed to enable Assoc_disallow");
3499 return 0;
3500 }
3501 return 1;
3502 }
3503
3504 sigma_dut_print(dut, DUT_MSG_ERROR,
3505 "Invalid value provided for Assoc_disallow: %s", val);
3506 send_resp(dut, conn, SIGMA_INVALID,
3507 "ErrorCode,Unknown value provided for Assoc_disallow");
3508 return 0;
3509}
3510
3511
Ashwini Patilc63161e2017-04-13 16:30:23 +05303512static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3513 const char *intf, const char *val)
3514{
3515 if (strcasecmp(val, "Reject") == 0) {
3516 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3517 send_resp(dut, conn, SIGMA_ERROR,
3518 "ErrorCode,Failed to Reject BTM Request");
3519 return 0;
3520 }
3521 return 1;
3522 }
3523
3524 if (strcasecmp(val, "Accept") == 0) {
3525 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3526 send_resp(dut, conn, SIGMA_ERROR,
3527 "ErrorCode,Failed to Accept BTM Request");
3528 return 0;
3529 }
3530 return 1;
3531 }
3532
3533 sigma_dut_print(dut, DUT_MSG_ERROR,
3534 "Invalid value provided for BSS_Transition: %s", val);
3535 send_resp(dut, conn, SIGMA_INVALID,
3536 "ErrorCode,Unknown value provided for BSS_Transition");
3537 return 0;
3538}
3539
3540
Ashwini Patil00402582017-04-13 12:29:39 +05303541static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3542 struct sigma_conn *conn,
3543 const char *intf,
3544 struct sigma_cmd *cmd)
3545{
3546 const char *ch, *pref, *op_class, *reason;
3547 char buf[120];
3548 int len, ret;
3549
3550 pref = get_param(cmd, "Ch_Pref");
3551 if (!pref)
3552 return 1;
3553
3554 if (strcasecmp(pref, "clear") == 0) {
3555 free(dut->non_pref_ch_list);
3556 dut->non_pref_ch_list = NULL;
3557 } else {
3558 op_class = get_param(cmd, "Ch_Op_Class");
3559 if (!op_class) {
3560 send_resp(dut, conn, SIGMA_INVALID,
3561 "ErrorCode,Ch_Op_Class not provided");
3562 return 0;
3563 }
3564
3565 ch = get_param(cmd, "Ch_Pref_Num");
3566 if (!ch) {
3567 send_resp(dut, conn, SIGMA_INVALID,
3568 "ErrorCode,Ch_Pref_Num not provided");
3569 return 0;
3570 }
3571
3572 reason = get_param(cmd, "Ch_Reason_Code");
3573 if (!reason) {
3574 send_resp(dut, conn, SIGMA_INVALID,
3575 "ErrorCode,Ch_Reason_Code not provided");
3576 return 0;
3577 }
3578
3579 if (!dut->non_pref_ch_list) {
3580 dut->non_pref_ch_list =
3581 calloc(1, NON_PREF_CH_LIST_SIZE);
3582 if (!dut->non_pref_ch_list) {
3583 send_resp(dut, conn, SIGMA_ERROR,
3584 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3585 return 0;
3586 }
3587 }
3588 len = strlen(dut->non_pref_ch_list);
3589 ret = snprintf(dut->non_pref_ch_list + len,
3590 NON_PREF_CH_LIST_SIZE - len,
3591 " %s:%s:%s:%s", op_class, ch, pref, reason);
3592 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3593 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3594 dut->non_pref_ch_list);
3595 } else {
3596 sigma_dut_print(dut, DUT_MSG_ERROR,
3597 "snprintf failed for non_pref_list, ret = %d",
3598 ret);
3599 send_resp(dut, conn, SIGMA_ERROR,
3600 "ErrorCode,snprintf failed");
3601 free(dut->non_pref_ch_list);
3602 dut->non_pref_ch_list = NULL;
3603 return 0;
3604 }
3605 }
3606
3607 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3608 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3609 if (ret < 0 || ret >= (int) sizeof(buf)) {
3610 sigma_dut_print(dut, DUT_MSG_DEBUG,
3611 "snprintf failed for set non_pref_chan, ret: %d",
3612 ret);
3613 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3614 return 0;
3615 }
3616
3617 if (wpa_command(intf, buf) < 0) {
3618 send_resp(dut, conn, SIGMA_ERROR,
3619 "ErrorCode,Failed to set non-preferred channel list");
3620 return 0;
3621 }
3622
3623 return 1;
3624}
3625
3626
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003627#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003628
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003629static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3630 enum he_fragmentation_val frag)
3631{
3632 struct nl_msg *msg;
3633 int ret = 0;
3634 struct nlattr *params;
3635 int ifindex;
3636
3637 ifindex = if_nametoindex(intf);
3638 if (ifindex == 0) {
3639 sigma_dut_print(dut, DUT_MSG_ERROR,
3640 "%s: Index for interface %s failed",
3641 __func__, intf);
3642 return -1;
3643 }
3644
3645 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3646 NL80211_CMD_VENDOR)) ||
3647 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3648 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3649 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3650 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3651 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3652 nla_put_u8(msg,
3653 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3654 frag)) {
3655 sigma_dut_print(dut, DUT_MSG_ERROR,
3656 "%s: err in adding vendor_cmd and vendor_data",
3657 __func__);
3658 nlmsg_free(msg);
3659 return -1;
3660 }
3661 nla_nest_end(msg, params);
3662
3663 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3664 if (ret) {
3665 sigma_dut_print(dut, DUT_MSG_ERROR,
3666 "%s: err in send_and_recv_msgs, ret=%d",
3667 __func__, ret);
3668 }
3669 return ret;
3670}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003671
3672
Subhani Shaik8e7a3052018-04-24 14:03:00 -07003673static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
3674 enum qca_wlan_he_ltf_cfg ltf)
3675{
3676 struct nl_msg *msg;
3677 int ret = 0;
3678 struct nlattr *params;
3679 int ifindex;
3680
3681 ifindex = if_nametoindex(intf);
3682 if (ifindex == 0) {
3683 sigma_dut_print(dut, DUT_MSG_ERROR,
3684 "%s: Index for interface %s failed",
3685 __func__, intf);
3686 return -1;
3687 }
3688
3689 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3690 NL80211_CMD_VENDOR)) ||
3691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3692 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3693 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3694 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3695 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3696 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
3697 ltf)) {
3698 sigma_dut_print(dut, DUT_MSG_ERROR,
3699 "%s: err in adding vendor_cmd and vendor_data",
3700 __func__);
3701 nlmsg_free(msg);
3702 return -1;
3703 }
3704 nla_nest_end(msg, params);
3705
3706 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3707 if (ret) {
3708 sigma_dut_print(dut, DUT_MSG_ERROR,
3709 "%s: err in send_and_recv_msgs, ret=%d",
3710 __func__, ret);
3711 }
3712 return ret;
3713}
3714
3715
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003716static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
3717 int noack, enum qca_wlan_ac_type ac)
3718{
3719 struct nl_msg *msg;
3720 int ret = 0;
3721 struct nlattr *params;
3722 int ifindex;
3723
3724 ifindex = if_nametoindex(intf);
3725 if (ifindex == 0) {
3726 sigma_dut_print(dut, DUT_MSG_ERROR,
3727 "%s: Index for interface %s failed",
3728 __func__, intf);
3729 return -1;
3730 }
3731
3732 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3733 NL80211_CMD_VENDOR)) ||
3734 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3735 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3736 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3737 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3738 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3739 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
3740 noack) ||
3741 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
3742 ac)) {
3743 sigma_dut_print(dut, DUT_MSG_ERROR,
3744 "%s: err in adding vendor_cmd and vendor_data",
3745 __func__);
3746 nlmsg_free(msg);
3747 return -1;
3748 }
3749 nla_nest_end(msg, params);
3750
3751 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3752 if (ret) {
3753 sigma_dut_print(dut, DUT_MSG_ERROR,
3754 "%s: err in send_and_recv_msgs, ret=%d",
3755 __func__, ret);
3756 }
3757 return ret;
3758}
3759
3760
3761static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
3762 const char *val)
3763{
3764 int noack, ret;
3765 char token[100];
3766 char *result;
3767 char *saveptr;
3768 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
3769
3770 strlcpy(token, val, sizeof(token));
3771 token[sizeof(token) - 1] = '\0';
3772 result = strtok_r(token, ":", &saveptr);
3773 while (result) {
3774 noack = strcasecmp(result, "Disable") != 0;
3775 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
3776 if (ret) {
3777 sigma_dut_print(dut, DUT_MSG_ERROR,
3778 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
3779 ac, ret);
3780 }
3781 result = strtok_r(NULL, ":", &saveptr);
3782 ac++;
3783 }
3784}
3785
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003786#endif /* NL80211_SUPPORT */
3787
3788
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003789static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3790 struct sigma_conn *conn,
3791 struct sigma_cmd *cmd)
3792{
3793 const char *intf = get_param(cmd, "Interface");
3794 const char *val;
3795
3796 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03003797 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
3798 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003799 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3800 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003801
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003802 if (val && strcasecmp(val, "LOC") == 0)
3803 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3804
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003805#ifdef ANDROID_NAN
3806 if (val && strcasecmp(val, "NAN") == 0)
3807 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3808#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003809#ifdef MIRACAST
3810 if (val && (strcasecmp(val, "WFD") == 0 ||
3811 strcasecmp(val, "DisplayR2") == 0))
3812 return miracast_preset_testparameters(dut, conn, cmd);
3813#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003814
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303815 if (val && strcasecmp(val, "MBO") == 0) {
3816 val = get_param(cmd, "Cellular_Data_Cap");
3817 if (val &&
3818 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3819 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303820
3821 val = get_param(cmd, "Ch_Pref");
3822 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3823 return 0;
3824
Ashwini Patilc63161e2017-04-13 16:30:23 +05303825 val = get_param(cmd, "BSS_Transition");
3826 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3827 return 0;
3828
Ashwini Patila75de5a2017-04-13 16:35:05 +05303829 val = get_param(cmd, "Assoc_Disallow");
3830 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3831 return 0;
3832
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303833 val = get_param(cmd, "Roaming");
3834 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3835 return 0;
3836
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303837 return 1;
3838 }
3839
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303840 if (val && strcasecmp(val, "OCE") == 0)
3841 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3842
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003843#if 0
3844 val = get_param(cmd, "Supplicant");
3845 if (val && strcasecmp(val, "Default") != 0) {
3846 send_resp(dut, conn, SIGMA_ERROR,
3847 "ErrorCode,Only default(Vendor) supplicant "
3848 "supported");
3849 return 0;
3850 }
3851#endif
3852
3853 val = get_param(cmd, "RTS");
3854 if (val) {
3855 switch (get_driver_type()) {
3856 case DRIVER_ATHEROS:
3857 ath_sta_set_rts(dut, intf, val);
3858 break;
3859 default:
3860#if 0
3861 send_resp(dut, conn, SIGMA_ERROR,
3862 "ErrorCode,Setting RTS not supported");
3863 return 0;
3864#else
3865 sigma_dut_print(dut, DUT_MSG_DEBUG,
3866 "Setting RTS not supported");
3867 break;
3868#endif
3869 }
3870 }
3871
3872#if 0
3873 val = get_param(cmd, "FRGMNT");
3874 if (val) {
3875 /* TODO */
3876 send_resp(dut, conn, SIGMA_ERROR,
3877 "ErrorCode,Setting FRGMNT not supported");
3878 return 0;
3879 }
3880#endif
3881
3882#if 0
3883 val = get_param(cmd, "Preamble");
3884 if (val) {
3885 /* TODO: Long/Short */
3886 send_resp(dut, conn, SIGMA_ERROR,
3887 "ErrorCode,Setting Preamble not supported");
3888 return 0;
3889 }
3890#endif
3891
3892 val = get_param(cmd, "Mode");
3893 if (val) {
3894 if (strcmp(val, "11b") == 0 ||
3895 strcmp(val, "11g") == 0 ||
3896 strcmp(val, "11a") == 0 ||
3897 strcmp(val, "11n") == 0 ||
3898 strcmp(val, "11ng") == 0 ||
3899 strcmp(val, "11nl") == 0 ||
3900 strcmp(val, "11nl(nabg)") == 0 ||
3901 strcmp(val, "AC") == 0 ||
3902 strcmp(val, "11AC") == 0 ||
3903 strcmp(val, "11ac") == 0 ||
3904 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003905 strcmp(val, "11an") == 0 ||
3906 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003907 /* STA supports all modes by default */
3908 } else {
3909 send_resp(dut, conn, SIGMA_ERROR,
3910 "ErrorCode,Setting Mode not supported");
3911 return 0;
3912 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003913
3914 /* Change the mode only in case of testbed for HE program
3915 * and for 11a and 11g modes only. */
3916 if (dut->program == PROGRAM_HE &&
3917 dut->device_type == STA_testbed) {
3918 int phymode;
3919 char buf[60];
3920
3921 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08003922 phymode = 1; /* IEEE80211_MODE_11A */
3923 } else if (strcmp(val, "11g") == 0) {
3924 phymode = 3; /* IEEE80211_MODE_11G */
3925 } else if (strcmp(val, "11b") == 0) {
3926 phymode = 2; /* IEEE80211_MODE_11B */
3927 } else if (strcmp(val, "11n") == 0 ||
3928 strcmp(val, "11nl") == 0 ||
3929 strcmp(val, "11nl(nabg)") == 0) {
3930 phymode = 22; /* IEEE80211_MODE_11AGN */
3931 } else if (strcmp(val, "11ng") == 0) {
3932 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
3933 } else if (strcmp(val, "AC") == 0 ||
3934 strcasecmp(val, "11AC") == 0) {
3935 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
3936 } else if (strcmp(val, "11na") == 0 ||
3937 strcasecmp(val, "11an") == 0) {
3938 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
3939 } else if (strcmp(val, "11ax") == 0) {
3940 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003941 } else {
3942 sigma_dut_print(dut, DUT_MSG_DEBUG,
3943 "Ignoring mode change for mode: %s",
3944 val);
3945 phymode = -1;
3946 }
3947 if (phymode != -1) {
3948 snprintf(buf, sizeof(buf),
3949 "iwpriv %s setphymode %d",
3950 intf, phymode);
3951 if (system(buf) != 0) {
3952 sigma_dut_print(dut, DUT_MSG_ERROR,
3953 "iwpriv setting of phymode failed");
3954 }
3955 }
3956 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003957 }
3958
3959 val = get_param(cmd, "wmm");
3960 if (val) {
3961 switch (get_driver_type()) {
3962 case DRIVER_ATHEROS:
3963 ath_sta_set_wmm(dut, intf, val);
3964 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003965 case DRIVER_WCN:
3966 wcn_sta_set_wmm(dut, intf, val);
3967 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003968 default:
3969 sigma_dut_print(dut, DUT_MSG_DEBUG,
3970 "Setting wmm not supported");
3971 break;
3972 }
3973 }
3974
3975 val = get_param(cmd, "Powersave");
3976 if (val) {
3977 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3978 if (wpa_command(get_station_ifname(),
3979 "P2P_SET ps 0") < 0)
3980 return -2;
3981 /* Make sure test modes are disabled */
3982 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3983 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3984 } else if (strcmp(val, "1") == 0 ||
3985 strcasecmp(val, "PSPoll") == 0 ||
3986 strcasecmp(val, "on") == 0) {
3987 /* Disable default power save mode */
3988 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3989 /* Enable PS-Poll test mode */
3990 if (wpa_command(get_station_ifname(),
3991 "P2P_SET ps 97") < 0 ||
3992 wpa_command(get_station_ifname(),
3993 "P2P_SET ps 99") < 0)
3994 return -2;
3995 } else if (strcmp(val, "2") == 0 ||
3996 strcasecmp(val, "Fast") == 0) {
3997 /* TODO */
3998 send_resp(dut, conn, SIGMA_ERROR,
3999 "ErrorCode,Powersave=Fast not supported");
4000 return 0;
4001 } else if (strcmp(val, "3") == 0 ||
4002 strcasecmp(val, "PSNonPoll") == 0) {
4003 /* Make sure test modes are disabled */
4004 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4005 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4006
4007 /* Enable default power save mode */
4008 if (wpa_command(get_station_ifname(),
4009 "P2P_SET ps 1") < 0)
4010 return -2;
4011 } else
4012 return -1;
4013 }
4014
4015 val = get_param(cmd, "NoAck");
4016 if (val) {
4017 switch (get_driver_type()) {
4018 case DRIVER_ATHEROS:
4019 ath_sta_set_noack(dut, intf, val);
4020 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004021#ifdef NL80211_SUPPORT
4022 case DRIVER_WCN:
4023 wcn_sta_set_noack(dut, intf, val);
4024 break;
4025#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004026 default:
4027 send_resp(dut, conn, SIGMA_ERROR,
4028 "ErrorCode,Setting NoAck not supported");
4029 return 0;
4030 }
4031 }
4032
4033 val = get_param(cmd, "IgnoreChswitchProhibit");
4034 if (val) {
4035 /* TODO: Enabled/disabled */
4036 if (strcasecmp(val, "Enabled") == 0) {
4037 send_resp(dut, conn, SIGMA_ERROR,
4038 "ErrorCode,Enabling IgnoreChswitchProhibit "
4039 "not supported");
4040 return 0;
4041 }
4042 }
4043
4044 val = get_param(cmd, "TDLS");
4045 if (val) {
4046 if (strcasecmp(val, "Disabled") == 0) {
4047 if (wpa_command(intf, "SET tdls_disabled 1")) {
4048 send_resp(dut, conn, SIGMA_ERROR,
4049 "ErrorCode,Failed to disable TDLS");
4050 return 0;
4051 }
4052 } else if (strcasecmp(val, "Enabled") == 0) {
4053 if (wpa_command(intf, "SET tdls_disabled 0")) {
4054 send_resp(dut, conn, SIGMA_ERROR,
4055 "ErrorCode,Failed to enable TDLS");
4056 return 0;
4057 }
4058 } else {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "ErrorCode,Unsupported TDLS value");
4061 return 0;
4062 }
4063 }
4064
4065 val = get_param(cmd, "TDLSmode");
4066 if (val) {
4067 if (strcasecmp(val, "Default") == 0) {
4068 wpa_command(intf, "SET tdls_testing 0");
4069 } else if (strcasecmp(val, "APProhibit") == 0) {
4070 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4071 send_resp(dut, conn, SIGMA_ERROR,
4072 "ErrorCode,Failed to enable ignore "
4073 "APProhibit TDLS mode");
4074 return 0;
4075 }
4076 } else if (strcasecmp(val, "HiLoMac") == 0) {
4077 /* STA should respond with TDLS setup req for a TDLS
4078 * setup req */
4079 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4080 send_resp(dut, conn, SIGMA_ERROR,
4081 "ErrorCode,Failed to enable HiLoMac "
4082 "TDLS mode");
4083 return 0;
4084 }
4085 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4086 /*
4087 * Since all security modes are enabled by default when
4088 * Sigma control is used, there is no need to do
4089 * anything here.
4090 */
4091 } else if (strcasecmp(val, "ExistLink") == 0) {
4092 /*
4093 * Since we allow new TDLS Setup Request even if there
4094 * is an existing link, nothing needs to be done for
4095 * this.
4096 */
4097 } else {
4098 /* TODO:
4099 * ExistLink: STA should send TDLS setup req even if
4100 * direct link already exists
4101 */
4102 send_resp(dut, conn, SIGMA_ERROR,
4103 "ErrorCode,Unsupported TDLSmode value");
4104 return 0;
4105 }
4106 }
4107
4108 val = get_param(cmd, "FakePubKey");
4109 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4110 send_resp(dut, conn, SIGMA_ERROR,
4111 "ErrorCode,Failed to enable FakePubKey");
4112 return 0;
4113 }
4114
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004115#ifdef NL80211_SUPPORT
4116 val = get_param(cmd, "FrgmntSupport");
4117 if (val) {
4118 if (strcasecmp(val, "Enable") == 0) {
4119 if (sta_set_he_fragmentation(dut, intf,
4120 HE_FRAG_LEVEL1)) {
4121 send_resp(dut, conn, SIGMA_ERROR,
4122 "ErrorCode,Failed to enable HE Fragmentation");
4123 return 0;
4124 }
4125 } else if (strcasecmp(val, "Disable") == 0) {
4126 if (sta_set_he_fragmentation(dut, intf,
4127 HE_FRAG_DISABLE)) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Failed to disable HE Fragmentation");
4130 return 0;
4131 }
4132 }
4133 }
4134#endif /* NL80211_SUPPORT */
4135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004136 return 1;
4137}
4138
4139
4140static const char * ath_get_radio_name(const char *radio_name)
4141{
4142 if (radio_name == NULL)
4143 return "wifi0";
4144 if (strcmp(radio_name, "wifi1") == 0)
4145 return "wifi1";
4146 if (strcmp(radio_name, "wifi2") == 0)
4147 return "wifi2";
4148 return "wifi0";
4149}
4150
4151
4152static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4153 const char *val)
4154{
4155 char buf[60];
4156 unsigned int vht_mcsmap = 0;
4157 int txchainmask = 0;
4158 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4159
4160 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4161 if (dut->testbed_flag_txsp == 1) {
4162 vht_mcsmap = 0xfffc;
4163 dut->testbed_flag_txsp = 0;
4164 } else {
4165 vht_mcsmap = 0xfffe;
4166 }
4167 txchainmask = 1;
4168 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4169 if (dut->testbed_flag_txsp == 1) {
4170 vht_mcsmap = 0xfff0;
4171 dut->testbed_flag_txsp = 0;
4172 } else {
4173 vht_mcsmap = 0xfffa;
4174 }
4175 txchainmask = 3;
4176 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4177 if (dut->testbed_flag_txsp == 1) {
4178 vht_mcsmap = 0xffc0;
4179 dut->testbed_flag_txsp = 0;
4180 } else {
4181 vht_mcsmap = 0xffea;
4182 }
4183 txchainmask = 7;
4184 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4185 if (dut->testbed_flag_txsp == 1) {
4186 vht_mcsmap = 0xff00;
4187 dut->testbed_flag_txsp = 0;
4188 } else {
4189 vht_mcsmap = 0xffaa;
4190 }
4191 txchainmask = 15;
4192 } else {
4193 if (dut->testbed_flag_txsp == 1) {
4194 vht_mcsmap = 0xffc0;
4195 dut->testbed_flag_txsp = 0;
4196 } else {
4197 vht_mcsmap = 0xffea;
4198 }
4199 }
4200
4201 if (txchainmask) {
4202 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4203 basedev, txchainmask);
4204 if (system(buf) != 0) {
4205 sigma_dut_print(dut, DUT_MSG_ERROR,
4206 "iwpriv txchainmask failed");
4207 }
4208 }
4209
4210 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4211 intf, vht_mcsmap);
4212 if (system(buf) != 0) {
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "iwpriv %s vht_mcsmap 0x%04x failed",
4215 intf, vht_mcsmap);
4216 }
4217}
4218
4219
4220static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4221 const char *val)
4222{
4223 char buf[60];
4224 unsigned int vht_mcsmap = 0;
4225 int rxchainmask = 0;
4226 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4227
4228 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4229 if (dut->testbed_flag_rxsp == 1) {
4230 vht_mcsmap = 0xfffc;
4231 dut->testbed_flag_rxsp = 0;
4232 } else {
4233 vht_mcsmap = 0xfffe;
4234 }
4235 rxchainmask = 1;
4236 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4237 if (dut->testbed_flag_rxsp == 1) {
4238 vht_mcsmap = 0xfff0;
4239 dut->testbed_flag_rxsp = 0;
4240 } else {
4241 vht_mcsmap = 0xfffa;
4242 }
4243 rxchainmask = 3;
4244 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4245 if (dut->testbed_flag_rxsp == 1) {
4246 vht_mcsmap = 0xffc0;
4247 dut->testbed_flag_rxsp = 0;
4248 } else {
4249 vht_mcsmap = 0xffea;
4250 }
4251 rxchainmask = 7;
4252 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4253 if (dut->testbed_flag_rxsp == 1) {
4254 vht_mcsmap = 0xff00;
4255 dut->testbed_flag_rxsp = 0;
4256 } else {
4257 vht_mcsmap = 0xffaa;
4258 }
4259 rxchainmask = 15;
4260 } else {
4261 if (dut->testbed_flag_rxsp == 1) {
4262 vht_mcsmap = 0xffc0;
4263 dut->testbed_flag_rxsp = 0;
4264 } else {
4265 vht_mcsmap = 0xffea;
4266 }
4267 }
4268
4269 if (rxchainmask) {
4270 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4271 basedev, rxchainmask);
4272 if (system(buf) != 0) {
4273 sigma_dut_print(dut, DUT_MSG_ERROR,
4274 "iwpriv rxchainmask failed");
4275 }
4276 }
4277
4278 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4279 intf, vht_mcsmap);
4280 if (system(buf) != 0) {
4281 sigma_dut_print(dut, DUT_MSG_ERROR,
4282 "iwpriv %s vht_mcsmap 0x%04x",
4283 intf, vht_mcsmap);
4284 }
4285}
4286
4287
4288void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4289{
4290 if (strcasecmp(val, "enable") == 0) {
4291 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4292 != 0) {
4293 sigma_dut_print(dut, DUT_MSG_ERROR,
4294 "Disable BB_VHTSIGB_CRC_CALC failed");
4295 }
4296
4297 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4298 != 0) {
4299 sigma_dut_print(dut, DUT_MSG_ERROR,
4300 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4301 }
4302 } else {
4303 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4304 != 0) {
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4307 }
4308
4309 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4310 != 0) {
4311 sigma_dut_print(dut, DUT_MSG_ERROR,
4312 "Enable BB_VHTSIGB_CRC_CALC failed");
4313 }
4314 }
4315}
4316
4317
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004318static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4319 const char *val)
4320{
4321 char buf[60];
4322
4323 if (strcmp(val, "20") == 0) {
4324 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4325 dut->chwidth = 0;
4326 } else if (strcmp(val, "40") == 0) {
4327 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4328 dut->chwidth = 1;
4329 } else if (strcmp(val, "80") == 0) {
4330 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4331 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304332 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004333 buf[0] = '\0';
4334 } else {
4335 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4336 val);
4337 return -1;
4338 }
4339
4340 if (buf[0] != '\0' && system(buf) != 0) {
4341 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4342 return -1;
4343 }
4344
4345 return 0;
4346}
4347
4348
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004349static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4350 const char *intf, int addbareject)
4351{
4352#ifdef NL80211_SUPPORT
4353 struct nl_msg *msg;
4354 int ret = 0;
4355 struct nlattr *params;
4356 int ifindex;
4357
4358 ifindex = if_nametoindex(intf);
4359 if (ifindex == 0) {
4360 sigma_dut_print(dut, DUT_MSG_ERROR,
4361 "%s: Index for interface %s failed",
4362 __func__, intf);
4363 return -1;
4364 }
4365
4366 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4367 NL80211_CMD_VENDOR)) ||
4368 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4369 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4370 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4371 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4372 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4373 nla_put_u8(msg,
4374 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4375 !addbareject)) {
4376 sigma_dut_print(dut, DUT_MSG_ERROR,
4377 "%s: err in adding vendor_cmd and vendor_data",
4378 __func__);
4379 nlmsg_free(msg);
4380 return -1;
4381 }
4382 nla_nest_end(msg, params);
4383
4384 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4385 if (ret) {
4386 sigma_dut_print(dut, DUT_MSG_ERROR,
4387 "%s: err in send_and_recv_msgs, ret=%d",
4388 __func__, ret);
4389 }
4390 return ret;
4391#else /* NL80211_SUPPORT */
4392 sigma_dut_print(dut, DUT_MSG_ERROR,
4393 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4394 return -1;
4395#endif /* NL80211_SUPPORT */
4396}
4397
4398
4399static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4400 int addbareject)
4401{
4402 int ret;
4403
4404 switch (get_driver_type()) {
4405 case DRIVER_WCN:
4406 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4407 if (ret) {
4408 sigma_dut_print(dut, DUT_MSG_ERROR,
4409 "nlvendor_sta_set_addba_reject failed, ret:%d",
4410 ret);
4411 return ret;
4412 }
4413 break;
4414 default:
4415 sigma_dut_print(dut, DUT_MSG_ERROR,
4416 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4417 ret = -1;
4418 break;
4419 }
4420
4421 return ret;
4422}
4423
4424
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004425static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4426 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004427{
4428#ifdef NL80211_SUPPORT
4429 struct nl_msg *msg;
4430 int ret = 0;
4431 struct nlattr *params;
4432 int ifindex;
4433
4434 ifindex = if_nametoindex(intf);
4435 if (ifindex == 0) {
4436 sigma_dut_print(dut, DUT_MSG_ERROR,
4437 "%s: Index for interface %s failed",
4438 __func__, intf);
4439 return -1;
4440 }
4441
4442 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4443 NL80211_CMD_VENDOR)) ||
4444 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4445 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4446 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4447 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4448 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4449 nla_put_u8(msg,
4450 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004451 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004452 sigma_dut_print(dut, DUT_MSG_ERROR,
4453 "%s: err in adding vendor_cmd and vendor_data",
4454 __func__);
4455 nlmsg_free(msg);
4456 return -1;
4457 }
4458 nla_nest_end(msg, params);
4459
4460 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4461 if (ret) {
4462 sigma_dut_print(dut, DUT_MSG_ERROR,
4463 "%s: err in send_and_recv_msgs, ret=%d",
4464 __func__, ret);
4465 }
4466 return ret;
4467#else /* NL80211_SUPPORT */
4468 sigma_dut_print(dut, DUT_MSG_ERROR,
4469 "Disable addba not possible without NL80211_SUPPORT defined");
4470 return -1;
4471#endif /* NL80211_SUPPORT */
4472}
4473
4474
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004475static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4476 struct sigma_conn *conn,
4477 struct sigma_cmd *cmd)
4478{
4479 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004480 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004481 char buf[30];
4482
4483 val = get_param(cmd, "40_INTOLERANT");
4484 if (val) {
4485 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4486 /* TODO: iwpriv ht40intol through wpa_supplicant */
4487 send_resp(dut, conn, SIGMA_ERROR,
4488 "ErrorCode,40_INTOLERANT not supported");
4489 return 0;
4490 }
4491 }
4492
4493 val = get_param(cmd, "ADDBA_REJECT");
4494 if (val) {
4495 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4496 /* reject any ADDBA with status "decline" */
4497 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004498 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004499 } else {
4500 /* accept ADDBA */
4501 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004502 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004503 }
4504 }
4505
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004506 if (addbareject >= 0 &&
4507 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4508 send_resp(dut, conn, SIGMA_ERROR,
4509 "ErrorCode,set addba_reject failed");
4510 return 0;
4511 }
4512
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004513 val = get_param(cmd, "AMPDU");
4514 if (val) {
4515 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4516 /* enable AMPDU Aggregation */
4517 if (ampdu == 0) {
4518 send_resp(dut, conn, SIGMA_ERROR,
4519 "ErrorCode,Mismatch in "
4520 "addba_reject/ampdu - "
4521 "not supported");
4522 return 0;
4523 }
4524 ampdu = 1;
4525 } else {
4526 /* disable AMPDU Aggregation */
4527 if (ampdu == 1) {
4528 send_resp(dut, conn, SIGMA_ERROR,
4529 "ErrorCode,Mismatch in "
4530 "addba_reject/ampdu - "
4531 "not supported");
4532 return 0;
4533 }
4534 ampdu = 0;
4535 }
4536 }
4537
4538 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004539 int ret;
4540
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004541 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4542 ampdu ? "Enabling" : "Disabling");
4543 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004544 if (wpa_command(intf, buf) < 0 &&
4545 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004546 send_resp(dut, conn, SIGMA_ERROR,
4547 "ErrorCode,set aggr failed");
4548 return 0;
4549 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004550
4551 if (ampdu == 0) {
4552 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004553 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004554 if (ret) {
4555 sigma_dut_print(dut, DUT_MSG_ERROR,
4556 "Failed to disable addba, ret:%d",
4557 ret);
4558 }
4559 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004560 }
4561
4562 val = get_param(cmd, "AMSDU");
4563 if (val) {
4564 switch (get_driver_type()) {
4565 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004566 case DRIVER_WCN:
4567 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004568 break;
4569 default:
4570 if (strcmp(val, "1") == 0 ||
4571 strcasecmp(val, "Enable") == 0) {
4572 /* Enable AMSDU Aggregation */
4573 send_resp(dut, conn, SIGMA_ERROR,
4574 "ErrorCode,AMSDU aggregation not supported");
4575 return 0;
4576 }
4577 break;
4578 }
4579 }
4580
4581 val = get_param(cmd, "STBC_RX");
4582 if (val) {
4583 switch (get_driver_type()) {
4584 case DRIVER_ATHEROS:
4585 ath_sta_set_stbc(dut, intf, val);
4586 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304587 case DRIVER_WCN:
4588 wcn_sta_set_stbc(dut, intf, val);
4589 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004590 default:
4591 send_resp(dut, conn, SIGMA_ERROR,
4592 "ErrorCode,STBC_RX not supported");
4593 return 0;
4594 }
4595 }
4596
4597 val = get_param(cmd, "WIDTH");
4598 if (val) {
4599 switch (get_driver_type()) {
4600 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004601 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004602 send_resp(dut, conn, SIGMA_ERROR,
4603 "ErrorCode,Failed to set WIDTH");
4604 return 0;
4605 }
4606 break;
4607 case DRIVER_ATHEROS:
4608 if (ath_set_width(dut, conn, intf, val) < 0)
4609 return 0;
4610 break;
4611 default:
4612 sigma_dut_print(dut, DUT_MSG_ERROR,
4613 "Setting WIDTH not supported");
4614 break;
4615 }
4616 }
4617
4618 val = get_param(cmd, "SMPS");
4619 if (val) {
4620 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4621 send_resp(dut, conn, SIGMA_ERROR,
4622 "ErrorCode,SMPS not supported");
4623 return 0;
4624 }
4625
4626 val = get_param(cmd, "TXSP_STREAM");
4627 if (val) {
4628 switch (get_driver_type()) {
4629 case DRIVER_WCN:
4630 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4631 send_resp(dut, conn, SIGMA_ERROR,
4632 "ErrorCode,Failed to set TXSP_STREAM");
4633 return 0;
4634 }
4635 break;
4636 case DRIVER_ATHEROS:
4637 ath_sta_set_txsp_stream(dut, intf, val);
4638 break;
4639 default:
4640 sigma_dut_print(dut, DUT_MSG_ERROR,
4641 "Setting TXSP_STREAM not supported");
4642 break;
4643 }
4644 }
4645
4646 val = get_param(cmd, "RXSP_STREAM");
4647 if (val) {
4648 switch (get_driver_type()) {
4649 case DRIVER_WCN:
4650 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4651 send_resp(dut, conn, SIGMA_ERROR,
4652 "ErrorCode,Failed to set RXSP_STREAM");
4653 return 0;
4654 }
4655 break;
4656 case DRIVER_ATHEROS:
4657 ath_sta_set_rxsp_stream(dut, intf, val);
4658 break;
4659 default:
4660 sigma_dut_print(dut, DUT_MSG_ERROR,
4661 "Setting RXSP_STREAM not supported");
4662 break;
4663 }
4664 }
4665
4666 val = get_param(cmd, "DYN_BW_SGNL");
4667 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004668 switch (get_driver_type()) {
4669 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004670 if (strcasecmp(val, "enable") == 0) {
4671 snprintf(buf, sizeof(buf),
4672 "iwpriv %s cwmenable 1", intf);
4673 if (system(buf) != 0) {
4674 sigma_dut_print(dut, DUT_MSG_ERROR,
4675 "iwpriv cwmenable 1 failed");
4676 return 0;
4677 }
4678 } else if (strcasecmp(val, "disable") == 0) {
4679 snprintf(buf, sizeof(buf),
4680 "iwpriv %s cwmenable 0", intf);
4681 if (system(buf) != 0) {
4682 sigma_dut_print(dut, DUT_MSG_ERROR,
4683 "iwpriv cwmenable 0 failed");
4684 return 0;
4685 }
4686 } else {
4687 sigma_dut_print(dut, DUT_MSG_ERROR,
4688 "Unsupported DYN_BW_SGL");
4689 }
4690
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004691 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4692 if (system(buf) != 0) {
4693 sigma_dut_print(dut, DUT_MSG_ERROR,
4694 "Failed to set cts_cbw in DYN_BW_SGNL");
4695 return 0;
4696 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004697 break;
4698 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004699 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004700 ath_config_dyn_bw_sig(dut, intf, val);
4701 break;
4702 default:
4703 sigma_dut_print(dut, DUT_MSG_ERROR,
4704 "Failed to set DYN_BW_SGNL");
4705 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004706 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004707 }
4708
4709 val = get_param(cmd, "RTS_FORCE");
4710 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004711 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004712 if (strcasecmp(val, "Enable") == 0) {
4713 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004714 if (system(buf) != 0) {
4715 sigma_dut_print(dut, DUT_MSG_ERROR,
4716 "Failed to set RTS_FORCE 64");
4717 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004718 snprintf(buf, sizeof(buf),
4719 "wifitool %s beeliner_fw_test 100 1", intf);
4720 if (system(buf) != 0) {
4721 sigma_dut_print(dut, DUT_MSG_ERROR,
4722 "wifitool beeliner_fw_test 100 1 failed");
4723 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004724 } else if (strcasecmp(val, "Disable") == 0) {
4725 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4726 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004727 if (system(buf) != 0) {
4728 sigma_dut_print(dut, DUT_MSG_ERROR,
4729 "Failed to set RTS_FORCE 2347");
4730 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004731 } else {
4732 send_resp(dut, conn, SIGMA_ERROR,
4733 "ErrorCode,RTS_FORCE value not supported");
4734 return 0;
4735 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004736 }
4737
4738 val = get_param(cmd, "CTS_WIDTH");
4739 if (val) {
4740 switch (get_driver_type()) {
4741 case DRIVER_WCN:
4742 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4743 send_resp(dut, conn, SIGMA_ERROR,
4744 "ErrorCode,Failed to set CTS_WIDTH");
4745 return 0;
4746 }
4747 break;
4748 case DRIVER_ATHEROS:
4749 ath_set_cts_width(dut, intf, val);
4750 break;
4751 default:
4752 sigma_dut_print(dut, DUT_MSG_ERROR,
4753 "Setting CTS_WIDTH not supported");
4754 break;
4755 }
4756 }
4757
4758 val = get_param(cmd, "BW_SGNL");
4759 if (val) {
4760 if (strcasecmp(val, "Enable") == 0) {
4761 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4762 intf);
4763 } else if (strcasecmp(val, "Disable") == 0) {
4764 /* TODO: Disable */
4765 buf[0] = '\0';
4766 } else {
4767 send_resp(dut, conn, SIGMA_ERROR,
4768 "ErrorCode,BW_SGNL value not supported");
4769 return 0;
4770 }
4771
4772 if (buf[0] != '\0' && system(buf) != 0) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "Failed to set BW_SGNL");
4775 }
4776 }
4777
4778 val = get_param(cmd, "Band");
4779 if (val) {
4780 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4781 /* STA supports all bands by default */
4782 } else {
4783 send_resp(dut, conn, SIGMA_ERROR,
4784 "ErrorCode,Unsupported Band");
4785 return 0;
4786 }
4787 }
4788
4789 val = get_param(cmd, "zero_crc");
4790 if (val) {
4791 switch (get_driver_type()) {
4792 case DRIVER_ATHEROS:
4793 ath_set_zero_crc(dut, val);
4794 break;
4795 default:
4796 break;
4797 }
4798 }
4799
4800 return 1;
4801}
4802
4803
4804static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4805 struct sigma_cmd *cmd)
4806{
4807 const char *val;
4808 char buf[100];
4809
4810 val = get_param(cmd, "MSDUSize");
4811 if (val) {
4812 int mtu;
4813
4814 dut->amsdu_size = atoi(val);
4815 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4816 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4817 sigma_dut_print(dut, DUT_MSG_ERROR,
4818 "MSDUSize %d is above max %d or below min %d",
4819 dut->amsdu_size,
4820 IEEE80211_MAX_DATA_LEN_DMG,
4821 IEEE80211_SNAP_LEN_DMG);
4822 dut->amsdu_size = 0;
4823 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4824 }
4825
4826 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4827 sigma_dut_print(dut, DUT_MSG_DEBUG,
4828 "Setting amsdu_size to %d", mtu);
4829 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4830 get_station_ifname(), mtu);
4831
4832 if (system(buf) != 0) {
4833 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4834 buf);
4835 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4836 }
4837 }
4838
4839 val = get_param(cmd, "BAckRcvBuf");
4840 if (val) {
4841 dut->back_rcv_buf = atoi(val);
4842 if (dut->back_rcv_buf == 0) {
4843 sigma_dut_print(dut, DUT_MSG_ERROR,
4844 "Failed to convert %s or value is 0",
4845 val);
4846 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4847 }
4848
4849 sigma_dut_print(dut, DUT_MSG_DEBUG,
4850 "Setting BAckRcvBuf to %s", val);
4851 }
4852
4853 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4854}
4855
4856
4857static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4858 struct sigma_cmd *cmd)
4859{
4860 int net_id;
4861 char *ifname;
4862 const char *val;
4863 char buf[100];
4864
4865 dut->mode = SIGMA_MODE_STATION;
4866 ifname = get_main_ifname();
4867 if (wpa_command(ifname, "PING") != 0) {
4868 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4869 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4870 }
4871
4872 wpa_command(ifname, "FLUSH");
4873 net_id = add_network_common(dut, conn, ifname, cmd);
4874 if (net_id < 0) {
4875 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4876 return net_id;
4877 }
4878
4879 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4880 if (set_network(ifname, net_id, "mode", "2") < 0) {
4881 sigma_dut_print(dut, DUT_MSG_ERROR,
4882 "Failed to set supplicant network mode");
4883 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4884 }
4885
4886 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02004887 "Supplicant set network with mode 2. network_id %d",
4888 net_id);
4889
4890 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
4891 sigma_dut_print(dut, DUT_MSG_INFO,
4892 "Failed to set supplicant to WPS ENABLE");
4893 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4894 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004895
4896 val = get_param(cmd, "Security");
4897 if (val && strcasecmp(val, "OPEN") == 0) {
4898 dut->ap_key_mgmt = AP_OPEN;
4899 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4900 sigma_dut_print(dut, DUT_MSG_ERROR,
4901 "Failed to set supplicant to %s security",
4902 val);
4903 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4904 }
4905 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4906 dut->ap_key_mgmt = AP_WPA2_PSK;
4907 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4908 sigma_dut_print(dut, DUT_MSG_ERROR,
4909 "Failed to set supplicant to %s security",
4910 val);
4911 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4912 }
4913
4914 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4915 sigma_dut_print(dut, DUT_MSG_ERROR,
4916 "Failed to set supplicant to proto RSN");
4917 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4918 }
4919 } else if (val) {
4920 sigma_dut_print(dut, DUT_MSG_ERROR,
4921 "Requested Security %s is not supported on 60GHz",
4922 val);
4923 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4924 }
4925
4926 val = get_param(cmd, "Encrypt");
4927 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4928 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4929 sigma_dut_print(dut, DUT_MSG_ERROR,
4930 "Failed to set supplicant to pairwise GCMP");
4931 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4932 }
4933 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4934 sigma_dut_print(dut, DUT_MSG_ERROR,
4935 "Failed to set supplicant to group GCMP");
4936 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4937 }
4938 } else if (val) {
4939 sigma_dut_print(dut, DUT_MSG_ERROR,
4940 "Requested Encrypt %s is not supported on 60 GHz",
4941 val);
4942 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4943 }
4944
4945 val = get_param(cmd, "PSK");
4946 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4947 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4948 val);
4949 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4950 }
4951
4952 /* Convert 60G channel to freq */
4953 switch (dut->ap_channel) {
4954 case 1:
4955 val = "58320";
4956 break;
4957 case 2:
4958 val = "60480";
4959 break;
4960 case 3:
4961 val = "62640";
4962 break;
4963 default:
4964 sigma_dut_print(dut, DUT_MSG_ERROR,
4965 "Failed to configure channel %d. Not supported",
4966 dut->ap_channel);
4967 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4968 }
4969
4970 if (set_network(ifname, net_id, "frequency", val) < 0) {
4971 sigma_dut_print(dut, DUT_MSG_ERROR,
4972 "Failed to set supplicant network frequency");
4973 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4974 }
4975
4976 sigma_dut_print(dut, DUT_MSG_DEBUG,
4977 "Supplicant set network with frequency");
4978
4979 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4980 if (wpa_command(ifname, buf) < 0) {
4981 sigma_dut_print(dut, DUT_MSG_INFO,
4982 "Failed to select network id %d on %s",
4983 net_id, ifname);
4984 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4985 }
4986
4987 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4988
4989 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4990}
4991
4992
Lior David67543f52017-01-03 19:04:22 +02004993static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4994{
4995 char buf[128], fname[128];
4996 FILE *f;
4997
4998 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4999 sigma_dut_print(dut, DUT_MSG_ERROR,
5000 "failed to get wil6210 debugfs dir");
5001 return -1;
5002 }
5003
5004 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5005 f = fopen(fname, "w");
5006 if (!f) {
5007 sigma_dut_print(dut, DUT_MSG_ERROR,
5008 "failed to open: %s", fname);
5009 return -1;
5010 }
5011
5012 fprintf(f, "%d\n", abft_len);
5013 fclose(f);
5014
5015 return 0;
5016}
5017
5018
5019static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5020 int abft_len)
5021{
5022 switch (get_driver_type()) {
5023 case DRIVER_WIL6210:
5024 return wil6210_set_abft_len(dut, abft_len);
5025 default:
5026 sigma_dut_print(dut, DUT_MSG_ERROR,
5027 "set abft_len not supported");
5028 return -1;
5029 }
5030}
5031
5032
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5034 struct sigma_cmd *cmd)
5035{
5036 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005037 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005038
5039 if (dut->dev_role != DEVROLE_PCP) {
5040 send_resp(dut, conn, SIGMA_INVALID,
5041 "ErrorCode,Invalid DevRole");
5042 return 0;
5043 }
5044
5045 val = get_param(cmd, "SSID");
5046 if (val) {
5047 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5048 send_resp(dut, conn, SIGMA_INVALID,
5049 "ErrorCode,Invalid SSID");
5050 return -1;
5051 }
5052
Peng Xub8fc5cc2017-05-10 17:27:28 -07005053 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005054 }
5055
5056 val = get_param(cmd, "CHANNEL");
5057 if (val) {
5058 const char *pos;
5059
5060 dut->ap_channel = atoi(val);
5061 pos = strchr(val, ';');
5062 if (pos) {
5063 pos++;
5064 dut->ap_channel_1 = atoi(pos);
5065 }
5066 }
5067
5068 switch (dut->ap_channel) {
5069 case 1:
5070 case 2:
5071 case 3:
5072 break;
5073 default:
5074 sigma_dut_print(dut, DUT_MSG_ERROR,
5075 "Channel %d is not supported", dut->ap_channel);
5076 send_resp(dut, conn, SIGMA_ERROR,
5077 "Requested channel is not supported");
5078 return -1;
5079 }
5080
5081 val = get_param(cmd, "BCNINT");
5082 if (val)
5083 dut->ap_bcnint = atoi(val);
5084
5085
5086 val = get_param(cmd, "ExtSchIE");
5087 if (val) {
5088 send_resp(dut, conn, SIGMA_ERROR,
5089 "ErrorCode,ExtSchIE is not supported yet");
5090 return -1;
5091 }
5092
5093 val = get_param(cmd, "AllocType");
5094 if (val) {
5095 send_resp(dut, conn, SIGMA_ERROR,
5096 "ErrorCode,AllocType is not supported yet");
5097 return -1;
5098 }
5099
5100 val = get_param(cmd, "PercentBI");
5101 if (val) {
5102 send_resp(dut, conn, SIGMA_ERROR,
5103 "ErrorCode,PercentBI is not supported yet");
5104 return -1;
5105 }
5106
5107 val = get_param(cmd, "CBAPOnly");
5108 if (val) {
5109 send_resp(dut, conn, SIGMA_ERROR,
5110 "ErrorCode,CBAPOnly is not supported yet");
5111 return -1;
5112 }
5113
5114 val = get_param(cmd, "AMPDU");
5115 if (val) {
5116 if (strcasecmp(val, "Enable") == 0)
5117 dut->ap_ampdu = 1;
5118 else if (strcasecmp(val, "Disable") == 0)
5119 dut->ap_ampdu = 2;
5120 else {
5121 send_resp(dut, conn, SIGMA_ERROR,
5122 "ErrorCode,AMPDU value is not Enable nor Disabled");
5123 return -1;
5124 }
5125 }
5126
5127 val = get_param(cmd, "AMSDU");
5128 if (val) {
5129 if (strcasecmp(val, "Enable") == 0)
5130 dut->ap_amsdu = 1;
5131 else if (strcasecmp(val, "Disable") == 0)
5132 dut->ap_amsdu = 2;
5133 }
5134
5135 val = get_param(cmd, "NumMSDU");
5136 if (val) {
5137 send_resp(dut, conn, SIGMA_ERROR,
5138 "ErrorCode, NumMSDU is not supported yet");
5139 return -1;
5140 }
5141
5142 val = get_param(cmd, "ABFTLRang");
5143 if (val) {
5144 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005145 "ABFTLRang parameter %s", val);
5146 if (strcmp(val, "Gt1") == 0)
5147 abft_len = 2; /* 2 slots in this case */
5148 }
5149
5150 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5151 send_resp(dut, conn, SIGMA_ERROR,
5152 "ErrorCode, Can't set ABFT length");
5153 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005154 }
5155
5156 if (sta_pcp_start(dut, conn, cmd) < 0) {
5157 send_resp(dut, conn, SIGMA_ERROR,
5158 "ErrorCode, Can't start PCP role");
5159 return -1;
5160 }
5161
5162 return sta_set_60g_common(dut, conn, cmd);
5163}
5164
5165
5166static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5167 struct sigma_cmd *cmd)
5168{
5169 const char *val = get_param(cmd, "DiscoveryMode");
5170
5171 if (dut->dev_role != DEVROLE_STA) {
5172 send_resp(dut, conn, SIGMA_INVALID,
5173 "ErrorCode,Invalid DevRole");
5174 return 0;
5175 }
5176
5177 if (val) {
5178 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5179 /* Ignore Discovery mode till Driver expose API. */
5180#if 0
5181 if (strcasecmp(val, "1") == 0) {
5182 send_resp(dut, conn, SIGMA_INVALID,
5183 "ErrorCode,DiscoveryMode 1 not supported");
5184 return 0;
5185 }
5186
5187 if (strcasecmp(val, "0") == 0) {
5188 /* OK */
5189 } else {
5190 send_resp(dut, conn, SIGMA_INVALID,
5191 "ErrorCode,DiscoveryMode not supported");
5192 return 0;
5193 }
5194#endif
5195 }
5196
5197 if (start_sta_mode(dut) != 0)
5198 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5199 return sta_set_60g_common(dut, conn, cmd);
5200}
5201
5202
5203static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5204 struct sigma_cmd *cmd)
5205{
5206 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005207 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305208
Jouni Malinened77e672018-01-10 16:45:13 +02005209 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005210 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005211 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305212 wpa_command(intf, "DISCONNECT");
5213 return 1;
5214 }
5215
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005216 disconnect_station(dut);
5217 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5218 * due to cached results. */
5219 wpa_command(intf, "SET ignore_old_scan_res 1");
5220 wpa_command(intf, "BSS_FLUSH");
5221 return 1;
5222}
5223
5224
5225static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5226 struct sigma_cmd *cmd)
5227{
5228 const char *intf = get_param(cmd, "Interface");
5229 const char *bssid = get_param(cmd, "bssid");
5230 const char *val = get_param(cmd, "CHANNEL");
5231 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305232 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305233 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005234 int res;
5235 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305236 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305237 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005238
5239 if (bssid == NULL) {
5240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5241 "argument");
5242 return 0;
5243 }
5244
5245 if (val)
5246 chan = atoi(val);
5247
5248 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5249 /* The current network may be from sta_associate or
5250 * sta_hs2_associate
5251 */
5252 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5253 0 ||
5254 set_network(intf, 0, "bssid", bssid) < 0)
5255 return -2;
5256 }
5257
5258 ctrl = open_wpa_mon(intf);
5259 if (ctrl == NULL) {
5260 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5261 "wpa_supplicant monitor connection");
5262 return -1;
5263 }
5264
Sunil Duttd30ce092018-01-11 23:56:29 +05305265 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5266 sizeof(result)) < 0 ||
5267 strncmp(result, "COMPLETED", 9) != 0) {
5268 sigma_dut_print(dut, DUT_MSG_DEBUG,
5269 "sta_reassoc: Not connected");
5270 fastreassoc = 0;
5271 }
5272
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305273 if (dut->rsne_override) {
5274#ifdef NL80211_SUPPORT
5275 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5276 sta_config_rsnie(dut, 1);
5277 dut->config_rsnie = 1;
5278 }
5279#endif /* NL80211_SUPPORT */
5280 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5281 dut->rsne_override);
5282 if (wpa_command(intf, buf) < 0) {
5283 send_resp(dut, conn, SIGMA_ERROR,
5284 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5285 return 0;
5286 }
5287 }
5288
Sunil Duttd30ce092018-01-11 23:56:29 +05305289 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005290#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305291 if (chan) {
5292 unsigned int freq;
5293
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02005294 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305295 if (!freq) {
5296 sigma_dut_print(dut, DUT_MSG_ERROR,
5297 "Invalid channel number provided: %d",
5298 chan);
5299 send_resp(dut, conn, SIGMA_INVALID,
5300 "ErrorCode,Invalid channel number");
5301 goto close_mon_conn;
5302 }
5303 res = snprintf(buf, sizeof(buf),
5304 "SCAN TYPE=ONLY freq=%d", freq);
5305 } else {
5306 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5307 }
5308 if (res < 0 || res >= (int) sizeof(buf)) {
5309 send_resp(dut, conn, SIGMA_ERROR,
5310 "ErrorCode,snprintf failed");
5311 goto close_mon_conn;
5312 }
5313 if (wpa_command(intf, buf) < 0) {
5314 sigma_dut_print(dut, DUT_MSG_INFO,
5315 "Failed to start scan");
5316 send_resp(dut, conn, SIGMA_ERROR,
5317 "ErrorCode,scan failed");
5318 goto close_mon_conn;
5319 }
5320
5321 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5322 buf, sizeof(buf));
5323 if (res < 0) {
5324 sigma_dut_print(dut, DUT_MSG_INFO,
5325 "Scan did not complete");
5326 send_resp(dut, conn, SIGMA_ERROR,
5327 "ErrorCode,scan did not complete");
5328 goto close_mon_conn;
5329 }
5330
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5332 < 0) {
5333 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5334 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305335 status = -2;
5336 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005337 }
5338 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5339 bssid, chan);
5340 if (res > 0 && res < (int) sizeof(buf))
5341 res = wpa_command(intf, buf);
5342
5343 if (res < 0 || res >= (int) sizeof(buf)) {
5344 send_resp(dut, conn, SIGMA_ERROR,
5345 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305346 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005347 }
5348#else /* ANDROID */
5349 sigma_dut_print(dut, DUT_MSG_DEBUG,
5350 "Reassoc using iwpriv - skip chan=%d info",
5351 chan);
5352 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5353 if (system(buf) != 0) {
5354 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305355 status = -2;
5356 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005357 }
5358#endif /* ANDROID */
5359 sigma_dut_print(dut, DUT_MSG_INFO,
5360 "sta_reassoc: Run %s successful", buf);
5361 } else if (wpa_command(intf, "REASSOCIATE")) {
5362 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5363 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305364 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005365 }
5366
5367 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5368 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305369 if (res < 0) {
5370 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5371 status = -1;
5372 goto close_mon_conn;
5373 }
5374 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005375
Ashwini Patil467efef2017-05-25 12:18:27 +05305376close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005377 wpa_ctrl_detach(ctrl);
5378 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305379 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005380}
5381
5382
5383static void hs2_clear_credentials(const char *intf)
5384{
5385 wpa_command(intf, "REMOVE_CRED all");
5386}
5387
5388
Lior Davidcc88b562017-01-03 18:52:09 +02005389#ifdef __linux__
5390static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5391 unsigned int *aid)
5392{
Lior David0fe101e2017-03-09 16:09:50 +02005393 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005394
Lior David0fe101e2017-03-09 16:09:50 +02005395 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005396}
5397#endif /* __linux__ */
5398
5399
5400static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5401 unsigned int *aid)
5402{
5403 switch (get_driver_type()) {
5404#ifdef __linux__
5405 case DRIVER_WIL6210:
5406 return wil6210_get_aid(dut, bssid, aid);
5407#endif /* __linux__ */
5408 default:
5409 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5410 return -1;
5411 }
5412}
5413
5414
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005415static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5416 struct sigma_cmd *cmd)
5417{
5418 char buf[MAX_CMD_LEN];
5419 char bss_list[MAX_CMD_LEN];
5420 const char *parameter = get_param(cmd, "Parameter");
5421
5422 if (parameter == NULL)
5423 return -1;
5424
Lior Davidcc88b562017-01-03 18:52:09 +02005425 if (strcasecmp(parameter, "AID") == 0) {
5426 unsigned int aid = 0;
5427 char bssid[20];
5428
5429 if (get_wpa_status(get_station_ifname(), "bssid",
5430 bssid, sizeof(bssid)) < 0) {
5431 sigma_dut_print(dut, DUT_MSG_ERROR,
5432 "could not get bssid");
5433 return -2;
5434 }
5435
5436 if (sta_get_aid_60g(dut, bssid, &aid))
5437 return -2;
5438
5439 snprintf(buf, sizeof(buf), "aid,%d", aid);
5440 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5441 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5442 return 0;
5443 }
5444
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005445 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5446 char *bss_line;
5447 char *bss_id = NULL;
5448 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305449 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005450
5451 if (ifname == NULL) {
5452 sigma_dut_print(dut, DUT_MSG_INFO,
5453 "For get DiscoveredDevList need Interface name.");
5454 return -1;
5455 }
5456
5457 /*
5458 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5459 * of BSSIDs in "bssid=<BSSID>\n"
5460 */
5461 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5462 bss_list,
5463 sizeof(bss_list)) < 0) {
5464 sigma_dut_print(dut, DUT_MSG_ERROR,
5465 "Failed to get bss list");
5466 return -1;
5467 }
5468
5469 sigma_dut_print(dut, DUT_MSG_DEBUG,
5470 "bss list for ifname:%s is:%s",
5471 ifname, bss_list);
5472
5473 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305474 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005475 while (bss_line) {
5476 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5477 bss_id) {
5478 int len;
5479
5480 len = snprintf(buf + strlen(buf),
5481 sizeof(buf) - strlen(buf),
5482 ",%s", bss_id);
5483 free(bss_id);
5484 bss_id = NULL;
5485 if (len < 0) {
5486 sigma_dut_print(dut,
5487 DUT_MSG_ERROR,
5488 "Failed to read BSSID");
5489 send_resp(dut, conn, SIGMA_ERROR,
5490 "ErrorCode,Failed to read BSS ID");
5491 return 0;
5492 }
5493
5494 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5495 sigma_dut_print(dut,
5496 DUT_MSG_ERROR,
5497 "Response buf too small for list");
5498 send_resp(dut, conn,
5499 SIGMA_ERROR,
5500 "ErrorCode,Response buf too small for list");
5501 return 0;
5502 }
5503 }
5504
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305505 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005506 }
5507
5508 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5509 buf);
5510 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5511 return 0;
5512 }
5513
5514 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5515 return 0;
5516}
5517
5518
5519static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5520 struct sigma_cmd *cmd)
5521{
5522 const char *program = get_param(cmd, "Program");
5523
5524 if (program == NULL)
5525 return -1;
5526
5527 if (strcasecmp(program, "P2PNFC") == 0)
5528 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5529
5530 if (strcasecmp(program, "60ghz") == 0)
5531 return sta_get_parameter_60g(dut, conn, cmd);
5532
5533#ifdef ANDROID_NAN
5534 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005535 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536#endif /* ANDROID_NAN */
5537
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005538#ifdef MIRACAST
5539 if (strcasecmp(program, "WFD") == 0 ||
5540 strcasecmp(program, "DisplayR2") == 0)
5541 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5542#endif /* MIRACAST */
5543
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005544 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5545 return 0;
5546}
5547
5548
5549static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5550 const char *type)
5551{
5552 char buf[100];
5553
5554 if (dut->program == PROGRAM_VHT) {
5555 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5556 if (system(buf) != 0) {
5557 sigma_dut_print(dut, DUT_MSG_ERROR,
5558 "iwpriv %s chwidth failed", intf);
5559 }
5560
5561 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5562 if (system(buf) != 0) {
5563 sigma_dut_print(dut, DUT_MSG_ERROR,
5564 "iwpriv %s mode 11ACVHT80 failed",
5565 intf);
5566 }
5567
5568 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5569 if (system(buf) != 0) {
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "iwpriv %s vhtmcs -1 failed", intf);
5572 }
5573 }
5574
5575 if (dut->program == PROGRAM_HT) {
5576 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5577 if (system(buf) != 0) {
5578 sigma_dut_print(dut, DUT_MSG_ERROR,
5579 "iwpriv %s chwidth failed", intf);
5580 }
5581
5582 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5583 if (system(buf) != 0) {
5584 sigma_dut_print(dut, DUT_MSG_ERROR,
5585 "iwpriv %s mode 11naht40 failed",
5586 intf);
5587 }
5588
5589 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5590 if (system(buf) != 0) {
5591 sigma_dut_print(dut, DUT_MSG_ERROR,
5592 "iwpriv set11NRates failed");
5593 }
5594 }
5595
5596 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5597 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5598 if (system(buf) != 0) {
5599 sigma_dut_print(dut, DUT_MSG_ERROR,
5600 "disabling powersave failed");
5601 }
5602
5603 /* Reset CTS width */
5604 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5605 intf);
5606 if (system(buf) != 0) {
5607 sigma_dut_print(dut, DUT_MSG_ERROR,
5608 "wifitool %s beeliner_fw_test 54 0 failed",
5609 intf);
5610 }
5611
5612 /* Enable Dynamic Bandwidth signalling by default */
5613 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5614 if (system(buf) != 0) {
5615 sigma_dut_print(dut, DUT_MSG_ERROR,
5616 "iwpriv %s cwmenable 1 failed", intf);
5617 }
5618
5619 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5620 if (system(buf) != 0) {
5621 sigma_dut_print(dut, DUT_MSG_ERROR,
5622 "iwpriv rts failed");
5623 }
5624 }
5625
5626 if (type && strcasecmp(type, "Testbed") == 0) {
5627 dut->testbed_flag_txsp = 1;
5628 dut->testbed_flag_rxsp = 1;
5629 /* STA has to set spatial stream to 2 per Appendix H */
5630 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5631 if (system(buf) != 0) {
5632 sigma_dut_print(dut, DUT_MSG_ERROR,
5633 "iwpriv vht_mcsmap failed");
5634 }
5635
5636 /* Disable LDPC per Appendix H */
5637 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5638 if (system(buf) != 0) {
5639 sigma_dut_print(dut, DUT_MSG_ERROR,
5640 "iwpriv %s ldpc 0 failed", intf);
5641 }
5642
5643 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5644 if (system(buf) != 0) {
5645 sigma_dut_print(dut, DUT_MSG_ERROR,
5646 "iwpriv amsdu failed");
5647 }
5648
5649 /* TODO: Disable STBC 2x1 transmit and receive */
5650 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5651 if (system(buf) != 0) {
5652 sigma_dut_print(dut, DUT_MSG_ERROR,
5653 "Disable tx_stbc 0 failed");
5654 }
5655
5656 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5657 if (system(buf) != 0) {
5658 sigma_dut_print(dut, DUT_MSG_ERROR,
5659 "Disable rx_stbc 0 failed");
5660 }
5661
5662 /* STA has to disable Short GI per Appendix H */
5663 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5664 if (system(buf) != 0) {
5665 sigma_dut_print(dut, DUT_MSG_ERROR,
5666 "iwpriv %s shortgi 0 failed", intf);
5667 }
5668 }
5669
5670 if (type && strcasecmp(type, "DUT") == 0) {
5671 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5672 if (system(buf) != 0) {
5673 sigma_dut_print(dut, DUT_MSG_ERROR,
5674 "iwpriv %s nss 3 failed", intf);
5675 }
Arif Hussainac6c5112018-05-25 17:34:00 -07005676 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005677
5678 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5679 if (system(buf) != 0) {
5680 sigma_dut_print(dut, DUT_MSG_ERROR,
5681 "iwpriv %s shortgi 1 failed", intf);
5682 }
5683 }
5684}
5685
5686
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005687#ifdef NL80211_SUPPORT
5688static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5689 enum he_mcs_config mcs)
5690{
5691 struct nl_msg *msg;
5692 int ret = 0;
5693 struct nlattr *params;
5694 int ifindex;
5695
5696 ifindex = if_nametoindex(intf);
5697 if (ifindex == 0) {
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "%s: Index for interface %s failed",
5700 __func__, intf);
5701 return -1;
5702 }
5703
5704 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5705 NL80211_CMD_VENDOR)) ||
5706 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5707 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5708 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5709 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5710 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5711 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5712 mcs)) {
5713 sigma_dut_print(dut, DUT_MSG_ERROR,
5714 "%s: err in adding vendor_cmd and vendor_data",
5715 __func__);
5716 nlmsg_free(msg);
5717 return -1;
5718 }
5719 nla_nest_end(msg, params);
5720
5721 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5722 if (ret) {
5723 sigma_dut_print(dut, DUT_MSG_ERROR,
5724 "%s: err in send_and_recv_msgs, ret=%d",
5725 __func__, ret);
5726 }
5727 return ret;
5728}
5729#endif /* NL80211_SUPPORT */
5730
5731
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005732static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5733 const char *intf, int enable)
5734{
5735#ifdef NL80211_SUPPORT
5736 struct nl_msg *msg;
5737 int ret = 0;
5738 struct nlattr *params;
5739 int ifindex;
5740
5741 ifindex = if_nametoindex(intf);
5742 if (ifindex == 0) {
5743 sigma_dut_print(dut, DUT_MSG_ERROR,
5744 "%s: Index for interface %s failed",
5745 __func__, intf);
5746 return -1;
5747 }
5748
5749 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5750 NL80211_CMD_VENDOR)) ||
5751 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5752 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5753 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5754 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5755 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5756 nla_put_u8(msg,
5757 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
5758 enable)) {
5759 sigma_dut_print(dut, DUT_MSG_ERROR,
5760 "%s: err in adding vendor_cmd and vendor_data",
5761 __func__);
5762 nlmsg_free(msg);
5763 return -1;
5764 }
5765 nla_nest_end(msg, params);
5766
5767 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5768 if (ret) {
5769 sigma_dut_print(dut, DUT_MSG_ERROR,
5770 "%s: err in send_and_recv_msgs, ret=%d",
5771 __func__, ret);
5772 }
5773 return ret;
5774#else /* NL80211_SUPPORT */
5775 sigma_dut_print(dut, DUT_MSG_ERROR,
5776 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5777 return -1;
5778#endif /* NL80211_SUPPORT */
5779}
5780
5781
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005782static int sta_set_addba_buf_size(struct sigma_dut *dut,
5783 const char *intf, int bufsize)
5784{
5785#ifdef NL80211_SUPPORT
5786 struct nl_msg *msg;
5787 int ret = 0;
5788 struct nlattr *params;
5789 int ifindex;
5790
5791 ifindex = if_nametoindex(intf);
5792 if (ifindex == 0) {
5793 sigma_dut_print(dut, DUT_MSG_ERROR,
5794 "%s: Index for interface %s failed",
5795 __func__, intf);
5796 return -1;
5797 }
5798
5799 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5800 NL80211_CMD_VENDOR)) ||
5801 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5802 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5803 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5804 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5805 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07005806 nla_put_u16(msg,
5807 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5808 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005809 sigma_dut_print(dut, DUT_MSG_ERROR,
5810 "%s: err in adding vendor_cmd and vendor_data",
5811 __func__);
5812 nlmsg_free(msg);
5813 return -1;
5814 }
5815 nla_nest_end(msg, params);
5816
5817 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5818 if (ret) {
5819 sigma_dut_print(dut, DUT_MSG_ERROR,
5820 "%s: err in send_and_recv_msgs, ret=%d",
5821 __func__, ret);
5822 }
5823 return ret;
5824#else /* NL80211_SUPPORT */
5825 sigma_dut_print(dut, DUT_MSG_ERROR,
5826 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5827 return -1;
5828#endif /* NL80211_SUPPORT */
5829}
5830
5831
Arif Hussain8d5b27b2018-05-14 14:31:03 -07005832static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
5833 int enable)
5834{
5835#ifdef NL80211_SUPPORT
5836 struct nl_msg *msg;
5837 int ret = 0;
5838 struct nlattr *params;
5839 int ifindex;
5840
5841 ifindex = if_nametoindex(intf);
5842 if (ifindex == 0) {
5843 sigma_dut_print(dut, DUT_MSG_ERROR,
5844 "%s: Index for interface %s failed",
5845 __func__, intf);
5846 return -1;
5847 }
5848
5849 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5850 NL80211_CMD_VENDOR)) ||
5851 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5852 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5853 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5854 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5855 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5856 nla_put_u8(msg,
5857 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
5858 enable)) {
5859 sigma_dut_print(dut, DUT_MSG_ERROR,
5860 "%s: err in adding vendor_cmd and vendor_data",
5861 __func__);
5862 nlmsg_free(msg);
5863 return -1;
5864 }
5865 nla_nest_end(msg, params);
5866
5867 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5868 if (ret) {
5869 sigma_dut_print(dut, DUT_MSG_ERROR,
5870 "%s: err in send_and_recv_msgs, ret=%d",
5871 __func__, ret);
5872 }
5873 return ret;
5874#else /* NL80211_SUPPORT */
5875 sigma_dut_print(dut, DUT_MSG_ERROR,
5876 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
5877 return -1;
5878#endif /* NL80211_SUPPORT */
5879}
5880
5881
Arif Hussain9765f7d2018-07-03 08:28:26 -07005882static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
5883 int val)
5884{
5885#ifdef NL80211_SUPPORT
5886 struct nl_msg *msg;
5887 int ret = 0;
5888 struct nlattr *params;
5889 int ifindex;
5890
5891 ifindex = if_nametoindex(intf);
5892 if (ifindex == 0) {
5893 sigma_dut_print(dut, DUT_MSG_ERROR,
5894 "%s: Index for interface %s failed, val:%d",
5895 __func__, intf, val);
5896 return -1;
5897 }
5898
5899 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5900 NL80211_CMD_VENDOR)) ||
5901 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5902 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5903 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5904 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5905 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5906 nla_put_u8(msg,
5907 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
5908 val)) {
5909 sigma_dut_print(dut, DUT_MSG_ERROR,
5910 "%s: err in adding vendor_cmd and vendor_data, val: %d",
5911 __func__, val);
5912 nlmsg_free(msg);
5913 return -1;
5914 }
5915 nla_nest_end(msg, params);
5916
5917 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5918 if (ret) {
5919 sigma_dut_print(dut, DUT_MSG_ERROR,
5920 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
5921 __func__, ret, val);
5922 }
5923 return ret;
5924#else /* NL80211_SUPPORT */
5925 sigma_dut_print(dut, DUT_MSG_ERROR,
5926 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
5927 return -1;
5928#endif /* NL80211_SUPPORT */
5929}
5930
5931
Arif Hussain68d23f52018-07-11 13:39:08 -07005932#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07005933static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
5934 enum qca_wlan_he_mac_padding_dur val)
5935{
Arif Hussain68d23f52018-07-11 13:39:08 -07005936 struct nl_msg *msg;
5937 int ret = 0;
5938 struct nlattr *params;
5939 int ifindex;
5940
5941 ifindex = if_nametoindex(intf);
5942 if (ifindex == 0) {
5943 sigma_dut_print(dut, DUT_MSG_ERROR,
5944 "%s: Index for interface %s failed, val:%d",
5945 __func__, intf, val);
5946 return -1;
5947 }
5948
5949 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5950 NL80211_CMD_VENDOR)) ||
5951 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5952 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5953 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5954 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5955 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5956 nla_put_u8(msg,
5957 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
5958 val)) {
5959 sigma_dut_print(dut, DUT_MSG_ERROR,
5960 "%s: err in adding vendor_cmd and vendor_data, val: %d",
5961 __func__, val);
5962 nlmsg_free(msg);
5963 return -1;
5964 }
5965 nla_nest_end(msg, params);
5966
5967 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5968 if (ret) {
5969 sigma_dut_print(dut, DUT_MSG_ERROR,
5970 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
5971 __func__, ret, val);
5972 }
5973 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07005974}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07005975#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07005976
5977
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07005978static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
5979 int val)
5980{
5981#ifdef NL80211_SUPPORT
5982 struct nl_msg *msg;
5983 int ret = 0;
5984 struct nlattr *params;
5985 int ifindex;
5986
5987 ifindex = if_nametoindex(intf);
5988 if (ifindex == 0) {
5989 sigma_dut_print(dut, DUT_MSG_ERROR,
5990 "%s: Index for interface %s failed, val:%d",
5991 __func__, intf, val);
5992 return -1;
5993 }
5994
5995 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5996 NL80211_CMD_VENDOR)) ||
5997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5998 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5999 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6000 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6001 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6002 nla_put_u8(msg,
6003 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6004 val)) {
6005 sigma_dut_print(dut, DUT_MSG_ERROR,
6006 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6007 __func__, val);
6008 nlmsg_free(msg);
6009 return -1;
6010 }
6011 nla_nest_end(msg, params);
6012
6013 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6014 if (ret) {
6015 sigma_dut_print(dut, DUT_MSG_ERROR,
6016 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6017 __func__, ret, val);
6018 }
6019 return ret;
6020#else /* NL80211_SUPPORT */
6021 sigma_dut_print(dut, DUT_MSG_ERROR,
6022 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6023 return -1;
6024#endif /* NL80211_SUPPORT */
6025}
6026
6027
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006028static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
6029 const char *type)
6030{
6031 char buf[60];
6032
6033 if (dut->program == PROGRAM_HE) {
6034 /* resetting phymode to auto in case of HE program */
6035 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
6036 if (system(buf) != 0) {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "iwpriv %s setphymode failed", intf);
6039 }
6040
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07006041 /* reset the rate to Auto rate */
6042 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
6043 intf);
6044 if (system(buf) != 0) {
6045 sigma_dut_print(dut, DUT_MSG_ERROR,
6046 "iwpriv %s set_11ax_rate 0xff failed",
6047 intf);
6048 }
6049
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07006050 /* reset the LDPC setting */
6051 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
6052 if (system(buf) != 0) {
6053 sigma_dut_print(dut, DUT_MSG_ERROR,
6054 "iwpriv %s ldpc 1 failed", intf);
6055 }
6056
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006057 /* remove all network profiles */
6058 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006059
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006060 /* Configure ADDBA Req/Rsp buffer size to be 64 */
6061 sta_set_addba_buf_size(dut, intf, 64);
6062
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08006063#ifdef NL80211_SUPPORT
6064 /* Disable noackpolicy for all AC */
6065 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
6067 "Disable of noackpolicy for all AC failed");
6068 }
6069#endif /* NL80211_SUPPORT */
6070
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08006071 /* Enable WMM by default */
6072 if (wcn_sta_set_wmm(dut, intf, "on")) {
6073 sigma_dut_print(dut, DUT_MSG_ERROR,
6074 "Enable of WMM in sta_reset_default_wcn failed");
6075 }
6076
6077 /* Disable ADDBA_REJECT by default */
6078 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
6079 sigma_dut_print(dut, DUT_MSG_ERROR,
6080 "Disable of addba_reject in sta_reset_default_wcn failed");
6081 }
6082
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006083 /* Enable sending of ADDBA by default */
6084 if (nlvendor_config_send_addba(dut, intf, 1)) {
6085 sigma_dut_print(dut, DUT_MSG_ERROR,
6086 "Enable sending of ADDBA in sta_reset_default_wcn failed");
6087 }
6088
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08006089 /* Enable AMPDU by default */
6090 iwpriv_sta_set_ampdu(dut, intf, 1);
6091
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006092#ifdef NL80211_SUPPORT
6093 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
6094 sigma_dut_print(dut, DUT_MSG_ERROR,
6095 "Set LTF config to default in sta_reset_default_wcn failed");
6096 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07006097
6098 if (sta_set_beamformee_sts(dut, intf, 0)) {
6099 sigma_dut_print(dut, DUT_MSG_ERROR,
6100 "Failed to set BeamformeeSTS");
6101 }
Arif Hussain68d23f52018-07-11 13:39:08 -07006102
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006103 if (sta_set_mac_padding_duration(
6104 dut, intf,
6105 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07006106 sigma_dut_print(dut, DUT_MSG_ERROR,
6107 "Failed to set MAC padding duration");
6108 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006109
6110 if (sta_set_mu_edca_override(dut, intf, 0)) {
6111 sigma_dut_print(dut, DUT_MSG_ERROR,
6112 "ErrorCode,Failed to set MU EDCA override disable");
6113 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006114#endif /* NL80211_SUPPORT */
6115
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006116 if (sta_set_tx_beamformee(dut, intf, 1)) {
6117 sigma_dut_print(dut, DUT_MSG_ERROR,
6118 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
6119 }
6120
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006121 /* Set nss to 1 and MCS 0-7 in case of testbed */
6122 if (type && strcasecmp(type, "Testbed") == 0) {
6123#ifdef NL80211_SUPPORT
6124 int ret;
6125#endif /* NL80211_SUPPORT */
6126
6127 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
6128 if (system(buf) != 0) {
6129 sigma_dut_print(dut, DUT_MSG_ERROR,
6130 "iwpriv %s nss failed", intf);
6131 }
6132
6133#ifdef NL80211_SUPPORT
6134 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
6135 if (ret) {
6136 sigma_dut_print(dut, DUT_MSG_ERROR,
6137 "Setting of MCS failed, ret:%d",
6138 ret);
6139 }
6140#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08006141
6142 /* Disable STBC as default */
6143 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006144
6145 /* Disable AMSDU as default */
6146 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006147
6148#ifdef NL80211_SUPPORT
6149 /* HE fragmentation default off */
6150 if (sta_set_he_fragmentation(dut, intf,
6151 HE_FRAG_DISABLE)) {
6152 sigma_dut_print(dut, DUT_MSG_ERROR,
6153 "Setting of HE fragmentation failed");
6154 }
6155#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006156
6157 /* Enable WEP/TKIP with HE capability in testbed */
6158 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
6159 sigma_dut_print(dut, DUT_MSG_ERROR,
6160 "Enabling HE config with WEP/TKIP failed");
6161 }
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006162
6163 if (sta_set_tx_beamformee(dut, intf, 0)) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "Set tx beamformee disable by default for testbed in sta_reset_default_wcn failed");
6166 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006167 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006168
6169 /* Defaults in case of DUT */
6170 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07006171 /* Enable STBC by default */
6172 wcn_sta_set_stbc(dut, intf, "1");
6173
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006174 /* set nss to 2 */
6175 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
6176 if (system(buf) != 0) {
6177 sigma_dut_print(dut, DUT_MSG_ERROR,
6178 "iwpriv %s nss 2 failed", intf);
6179 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006180 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006181
6182#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07006183 /* Set HE_MCS to 0-11 */
6184 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006185 sigma_dut_print(dut, DUT_MSG_ERROR,
6186 "Setting of MCS failed");
6187 }
6188#endif /* NL80211_SUPPORT */
6189
6190 /* Disable WEP/TKIP with HE capability in DUT */
6191 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
6192 sigma_dut_print(dut, DUT_MSG_ERROR,
6193 "Enabling HE config with WEP/TKIP failed");
6194 }
6195 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006196 }
6197}
6198
6199
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006200static int cmd_sta_reset_default(struct sigma_dut *dut,
6201 struct sigma_conn *conn,
6202 struct sigma_cmd *cmd)
6203{
6204 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
6205 struct sigma_cmd *cmd);
6206 const char *intf = get_param(cmd, "Interface");
6207 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006208 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306209 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006210
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006211 if (!program)
6212 program = get_param(cmd, "prog");
6213 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006214 dut->device_type = STA_unknown;
6215 type = get_param(cmd, "type");
6216 if (type && strcasecmp(type, "Testbed") == 0)
6217 dut->device_type = STA_testbed;
6218 if (type && strcasecmp(type, "DUT") == 0)
6219 dut->device_type = STA_dut;
6220
6221 if (dut->program == PROGRAM_TDLS) {
6222 /* Clear TDLS testing mode */
6223 wpa_command(intf, "SET tdls_disabled 0");
6224 wpa_command(intf, "SET tdls_testing 0");
6225 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05306226 if (get_driver_type() == DRIVER_WCN) {
6227 /* Enable the WCN driver in TDLS Explicit trigger mode
6228 */
6229 wpa_command(intf, "SET tdls_external_control 0");
6230 wpa_command(intf, "SET tdls_trigger_control 0");
6231 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006232 }
6233
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006234#ifdef MIRACAST
6235 if (dut->program == PROGRAM_WFD ||
6236 dut->program == PROGRAM_DISPLAYR2)
6237 miracast_sta_reset_default(dut, conn, cmd);
6238#endif /* MIRACAST */
6239
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006240 switch (get_driver_type()) {
6241 case DRIVER_ATHEROS:
6242 sta_reset_default_ath(dut, intf, type);
6243 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006244 case DRIVER_WCN:
6245 sta_reset_default_wcn(dut, intf, type);
6246 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006247 default:
6248 break;
6249 }
6250
6251#ifdef ANDROID_NAN
6252 if (dut->program == PROGRAM_NAN)
6253 nan_cmd_sta_reset_default(dut, conn, cmd);
6254#endif /* ANDROID_NAN */
6255
Jouni Malinenba630452018-06-22 11:49:59 +03006256 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 unlink("SP/wi-fi.org/pps.xml");
6258 if (system("rm -r SP/*") != 0) {
6259 }
6260 unlink("next-client-cert.pem");
6261 unlink("next-client-key.pem");
6262 }
6263
6264 if (dut->program == PROGRAM_60GHZ) {
6265 const char *dev_role = get_param(cmd, "DevRole");
6266
6267 if (!dev_role) {
6268 send_resp(dut, conn, SIGMA_ERROR,
6269 "errorCode,Missing DevRole argument");
6270 return 0;
6271 }
6272
6273 if (strcasecmp(dev_role, "STA") == 0)
6274 dut->dev_role = DEVROLE_STA;
6275 else if (strcasecmp(dev_role, "PCP") == 0)
6276 dut->dev_role = DEVROLE_PCP;
6277 else {
6278 send_resp(dut, conn, SIGMA_ERROR,
6279 "errorCode,Unknown DevRole");
6280 return 0;
6281 }
6282
6283 if (dut->device_type == STA_unknown) {
6284 sigma_dut_print(dut, DUT_MSG_ERROR,
6285 "Device type is not STA testbed or DUT");
6286 send_resp(dut, conn, SIGMA_ERROR,
6287 "errorCode,Unknown device type");
6288 return 0;
6289 }
6290 }
6291
6292 wpa_command(intf, "WPS_ER_STOP");
6293 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05306294 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006295 wpa_command(intf, "SET radio_disabled 0");
6296
6297 if (dut->tmp_mac_addr && dut->set_macaddr) {
6298 dut->tmp_mac_addr = 0;
6299 if (system(dut->set_macaddr) != 0) {
6300 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
6301 "temporary MAC address");
6302 }
6303 }
6304
6305 set_ps(intf, dut, 0);
6306
Jouni Malinenba630452018-06-22 11:49:59 +03006307 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6308 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309 wpa_command(intf, "SET interworking 1");
6310 wpa_command(intf, "SET hs20 1");
6311 }
6312
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006313 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03006314 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006315 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006316 wpa_command(intf, "SET pmf 1");
6317 } else {
6318 wpa_command(intf, "SET pmf 0");
6319 }
6320
6321 hs2_clear_credentials(intf);
6322 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6323 wpa_command(intf, "SET access_network_type 15");
6324
6325 static_ip_file(0, NULL, NULL, NULL);
6326 kill_dhcp_client(dut, intf);
6327 clear_ip_addr(dut, intf);
6328
6329 dut->er_oper_performed = 0;
6330 dut->er_oper_bssid[0] = '\0';
6331
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006332 if (dut->program == PROGRAM_LOC) {
6333 /* Disable Interworking by default */
6334 wpa_command(get_station_ifname(), "SET interworking 0");
6335 }
6336
Ashwini Patil00402582017-04-13 12:29:39 +05306337 if (dut->program == PROGRAM_MBO) {
6338 free(dut->non_pref_ch_list);
6339 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306340 free(dut->btm_query_cand_list);
6341 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306342 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306343 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306344 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306345 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05306346 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306347 }
6348
Jouni Malinen3c367e82017-06-23 17:01:47 +03006349 free(dut->rsne_override);
6350 dut->rsne_override = NULL;
6351
Jouni Malinen68143132017-09-02 02:34:08 +03006352 free(dut->sae_commit_override);
6353 dut->sae_commit_override = NULL;
6354
Jouni Malinend86e5822017-08-29 03:55:32 +03006355 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006356 free(dut->dpp_peer_uri);
6357 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006358 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006359 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006360
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006361 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6362
vamsi krishnaa2799492017-12-05 14:28:01 +05306363 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306364 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306365 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306366 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6367 dut->fils_hlp = 0;
6368#ifdef ANDROID
6369 hlp_thread_cleanup(dut);
6370#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306371 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306372
Sunil Dutt076081f2018-02-05 19:45:50 +05306373#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306374 if (get_driver_type() == DRIVER_WCN &&
6375 dut->config_rsnie == 1) {
6376 dut->config_rsnie = 0;
6377 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306378 }
6379#endif /* NL80211_SUPPORT */
6380
Sunil Duttfebf8a82018-02-09 18:50:13 +05306381 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6382 dut->dev_role = DEVROLE_STA_CFON;
6383 return sta_cfon_reset_default(dut, conn, cmd);
6384 }
6385
Jouni Malinen439352d2018-09-13 03:42:23 +03006386 wpa_command(intf, "SET setband AUTO");
6387
Sunil Duttfebf8a82018-02-09 18:50:13 +05306388 if (dut->program != PROGRAM_VHT)
6389 return cmd_sta_p2p_reset(dut, conn, cmd);
6390
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006391 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006392}
6393
6394
6395static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6396 struct sigma_cmd *cmd)
6397{
6398 const char *program = get_param(cmd, "Program");
6399
6400 if (program == NULL)
6401 return -1;
6402#ifdef ANDROID_NAN
6403 if (strcasecmp(program, "NAN") == 0)
6404 return nan_cmd_sta_get_events(dut, conn, cmd);
6405#endif /* ANDROID_NAN */
6406 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6407 return 0;
6408}
6409
6410
Jouni Malinen82905202018-04-29 17:20:10 +03006411static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6412 struct sigma_cmd *cmd)
6413{
6414 const char *url = get_param(cmd, "url");
6415 const char *method = get_param(cmd, "method");
6416 pid_t pid;
6417 int status;
6418
6419 if (!url || !method)
6420 return -1;
6421
6422 /* TODO: Add support for method,post */
6423 if (strcasecmp(method, "get") != 0) {
6424 send_resp(dut, conn, SIGMA_ERROR,
6425 "ErrorCode,Unsupported method");
6426 return 0;
6427 }
6428
6429 pid = fork();
6430 if (pid < 0) {
6431 perror("fork");
6432 return -1;
6433 }
6434
6435 if (pid == 0) {
6436 char * argv[5] = { "wget", "-O", "/dev/null",
6437 (char *) url, NULL };
6438
6439 execv("/usr/bin/wget", argv);
6440 perror("execv");
6441 exit(0);
6442 return -1;
6443 }
6444
6445 if (waitpid(pid, &status, 0) < 0) {
6446 perror("waitpid");
6447 return -1;
6448 }
6449
6450 if (WIFEXITED(status)) {
6451 const char *errmsg;
6452
6453 if (WEXITSTATUS(status) == 0)
6454 return 1;
6455 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6456 WEXITSTATUS(status));
6457 switch (WEXITSTATUS(status)) {
6458 case 4:
6459 errmsg = "errmsg,Network failure";
6460 break;
6461 case 8:
6462 errmsg = "errmsg,Server issued an error response";
6463 break;
6464 default:
6465 errmsg = "errmsg,Unknown failure from wget";
6466 break;
6467 }
6468 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6469 return 0;
6470 }
6471
6472 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6473 return 0;
6474}
6475
6476
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006477static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6478 struct sigma_cmd *cmd)
6479{
6480 const char *program = get_param(cmd, "Prog");
6481
Jouni Malinen82905202018-04-29 17:20:10 +03006482 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006483 return -1;
6484#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006485 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 return nan_cmd_sta_exec_action(dut, conn, cmd);
6487#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006488
6489 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006490 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006491
6492 if (get_param(cmd, "url"))
6493 return sta_exec_action_url(dut, conn, cmd);
6494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006495 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6496 return 0;
6497}
6498
6499
6500static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6501 struct sigma_cmd *cmd)
6502{
6503 const char *intf = get_param(cmd, "Interface");
6504 const char *val, *mcs32, *rate;
6505
6506 val = get_param(cmd, "GREENFIELD");
6507 if (val) {
6508 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6509 /* Enable GD */
6510 send_resp(dut, conn, SIGMA_ERROR,
6511 "ErrorCode,GF not supported");
6512 return 0;
6513 }
6514 }
6515
6516 val = get_param(cmd, "SGI20");
6517 if (val) {
6518 switch (get_driver_type()) {
6519 case DRIVER_ATHEROS:
6520 ath_sta_set_sgi(dut, intf, val);
6521 break;
6522 default:
6523 send_resp(dut, conn, SIGMA_ERROR,
6524 "ErrorCode,SGI20 not supported");
6525 return 0;
6526 }
6527 }
6528
6529 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6530 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6531 if (mcs32 && rate) {
6532 /* TODO */
6533 send_resp(dut, conn, SIGMA_ERROR,
6534 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6535 return 0;
6536 } else if (mcs32 && !rate) {
6537 /* TODO */
6538 send_resp(dut, conn, SIGMA_ERROR,
6539 "ErrorCode,MCS32 not supported");
6540 return 0;
6541 } else if (!mcs32 && rate) {
6542 switch (get_driver_type()) {
6543 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006544 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006545 ath_sta_set_11nrates(dut, intf, rate);
6546 break;
6547 default:
6548 send_resp(dut, conn, SIGMA_ERROR,
6549 "ErrorCode,MCS32_FIXEDRATE not supported");
6550 return 0;
6551 }
6552 }
6553
6554 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6555}
6556
6557
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006558static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
6559 int mcs_config)
6560{
6561#ifdef NL80211_SUPPORT
6562 int ret;
6563
6564 switch (mcs_config) {
6565 case HE_80_MCS0_7:
6566 case HE_80_MCS0_9:
6567 case HE_80_MCS0_11:
6568 ret = sta_set_he_mcs(dut, intf, mcs_config);
6569 if (ret) {
6570 sigma_dut_print(dut, DUT_MSG_ERROR,
6571 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
6572 mcs_config, ret);
6573 }
6574 break;
6575 default:
6576 sigma_dut_print(dut, DUT_MSG_ERROR,
6577 "cmd_set_max_he_mcs: Invalid mcs %d",
6578 mcs_config);
6579 break;
6580 }
6581#else /* NL80211_SUPPORT */
6582 sigma_dut_print(dut, DUT_MSG_ERROR,
6583 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
6584#endif /* NL80211_SUPPORT */
6585}
6586
6587
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006588static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
6589 struct sigma_conn *conn,
6590 struct sigma_cmd *cmd)
6591{
6592 const char *intf = get_param(cmd, "Interface");
6593 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07006594 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07006595 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006596 int tkip = -1;
6597 int wep = -1;
6598
Arif Hussaina37e9552018-06-20 17:05:59 -07006599 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006600 val = get_param(cmd, "SGI80");
6601 if (val) {
6602 int sgi80;
6603
6604 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6605 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
6606 if (system(buf) != 0) {
6607 sigma_dut_print(dut, DUT_MSG_ERROR,
6608 "iwpriv shortgi failed");
6609 }
6610 }
6611
6612 val = get_param(cmd, "TxBF");
6613 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07006614 switch (get_driver_type()) {
6615 case DRIVER_WCN:
6616 if (sta_set_tx_beamformee(dut, intf, 1)) {
6617 send_resp(dut, conn, SIGMA_ERROR,
6618 "ErrorCode,Failed to set TX beamformee enable");
6619 return 0;
6620 }
6621 break;
6622 case DRIVER_ATHEROS:
6623 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
6624 intf);
6625 if (system(buf) != 0) {
6626 send_resp(dut, conn, SIGMA_ERROR,
6627 "ErrorCode,Setting vhtsubfee failed");
6628 return 0;
6629 }
6630
6631 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
6632 intf);
6633 if (system(buf) != 0) {
6634 send_resp(dut, conn, SIGMA_ERROR,
6635 "ErrorCode,Setting vhtsubfer failed");
6636 return 0;
6637 }
6638 break;
6639 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006640 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07006641 "Unsupported driver type");
6642 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643 }
6644 }
6645
6646 val = get_param(cmd, "MU_TxBF");
6647 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6648 switch (get_driver_type()) {
6649 case DRIVER_ATHEROS:
6650 ath_sta_set_txsp_stream(dut, intf, "1SS");
6651 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05306652 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
6653 intf);
6654 if (system(buf) != 0) {
6655 sigma_dut_print(dut, DUT_MSG_ERROR,
6656 "iwpriv vhtmubfee failed");
6657 }
6658 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
6659 intf);
6660 if (system(buf) != 0) {
6661 sigma_dut_print(dut, DUT_MSG_ERROR,
6662 "iwpriv vhtmubfer failed");
6663 }
6664 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006665 case DRIVER_WCN:
6666 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
6667 send_resp(dut, conn, SIGMA_ERROR,
6668 "ErrorCode,Failed to set RX/TXSP_STREAM");
6669 return 0;
6670 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05306671 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672 default:
6673 sigma_dut_print(dut, DUT_MSG_ERROR,
6674 "Setting SP_STREAM not supported");
6675 break;
6676 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677 }
6678
6679 val = get_param(cmd, "LDPC");
6680 if (val) {
6681 int ldpc;
6682
6683 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6684 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
6685 if (system(buf) != 0) {
6686 sigma_dut_print(dut, DUT_MSG_ERROR,
6687 "iwpriv ldpc failed");
6688 }
6689 }
6690
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08006691 val = get_param(cmd, "BCC");
6692 if (val) {
6693 int bcc;
6694
6695 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6696 /* use LDPC iwpriv itself to set bcc coding, bcc coding
6697 * is mutually exclusive to bcc */
6698 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
6699 if (system(buf) != 0) {
6700 sigma_dut_print(dut, DUT_MSG_ERROR,
6701 "Enabling/Disabling of BCC failed");
6702 }
6703 }
6704
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006705 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
6706 if (val && dut->sta_nss == 1)
6707 cmd_set_max_he_mcs(dut, intf, atoi(val));
6708
6709 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
6710 if (val && dut->sta_nss == 2)
6711 cmd_set_max_he_mcs(dut, intf, atoi(val));
6712
Arif Hussainac6c5112018-05-25 17:34:00 -07006713 val = get_param(cmd, "MCS_FixedRate");
6714 if (val) {
6715#ifdef NL80211_SUPPORT
6716 int mcs, ratecode = 0;
6717 enum he_mcs_config mcs_config;
6718 int ret;
6719
6720 ratecode = (0x07 & dut->sta_nss) << 5;
6721 mcs = atoi(val);
6722 /* Add the MCS to the ratecode */
6723 if (mcs >= 0 && mcs <= 11) {
6724 ratecode += mcs;
6725 if (dut->device_type == STA_testbed &&
6726 mcs > 7 && mcs <= 11) {
6727 if (mcs <= 9)
6728 mcs_config = HE_80_MCS0_9;
6729 else
6730 mcs_config = HE_80_MCS0_11;
6731 ret = sta_set_he_mcs(dut, intf, mcs_config);
6732 if (ret) {
6733 sigma_dut_print(dut, DUT_MSG_ERROR,
6734 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
6735 mcs, mcs_config, ret);
6736 }
6737 }
6738 snprintf(buf, sizeof(buf),
6739 "iwpriv %s set_11ax_rate 0x%03x",
6740 intf, ratecode);
6741 if (system(buf) != 0) {
6742 sigma_dut_print(dut, DUT_MSG_ERROR,
6743 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
6744 ratecode);
6745 }
6746 } else {
6747 sigma_dut_print(dut, DUT_MSG_ERROR,
6748 "MCS_FixedRate: HE MCS %d not supported",
6749 mcs);
6750 }
6751#else /* NL80211_SUPPORT */
6752 sigma_dut_print(dut, DUT_MSG_ERROR,
6753 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
6754#endif /* NL80211_SUPPORT */
6755 }
6756
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006757 val = get_param(cmd, "opt_md_notif_ie");
6758 if (val) {
6759 char *result = NULL;
6760 char delim[] = ";";
6761 char token[30];
6762 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306763 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006764
Peng Xub8fc5cc2017-05-10 17:27:28 -07006765 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306766 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006767
6768 /* Extract the NSS information */
6769 if (result) {
6770 value = atoi(result);
6771 switch (value) {
6772 case 1:
6773 config_val = 1;
6774 break;
6775 case 2:
6776 config_val = 3;
6777 break;
6778 case 3:
6779 config_val = 7;
6780 break;
6781 case 4:
6782 config_val = 15;
6783 break;
6784 default:
6785 config_val = 3;
6786 break;
6787 }
6788
6789 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6790 intf, config_val);
6791 if (system(buf) != 0) {
6792 sigma_dut_print(dut, DUT_MSG_ERROR,
6793 "iwpriv rxchainmask failed");
6794 }
6795
6796 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
6797 intf, config_val);
6798 if (system(buf) != 0) {
6799 sigma_dut_print(dut, DUT_MSG_ERROR,
6800 "iwpriv txchainmask failed");
6801 }
6802 }
6803
6804 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306805 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 if (result) {
6807 value = atoi(result);
6808 switch (value) {
6809 case 20:
6810 config_val = 0;
6811 break;
6812 case 40:
6813 config_val = 1;
6814 break;
6815 case 80:
6816 config_val = 2;
6817 break;
6818 case 160:
6819 config_val = 3;
6820 break;
6821 default:
6822 config_val = 2;
6823 break;
6824 }
6825
6826 dut->chwidth = config_val;
6827
6828 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6829 intf, config_val);
6830 if (system(buf) != 0) {
6831 sigma_dut_print(dut, DUT_MSG_ERROR,
6832 "iwpriv chwidth failed");
6833 }
6834 }
6835
6836 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
6837 if (system(buf) != 0) {
6838 sigma_dut_print(dut, DUT_MSG_ERROR,
6839 "iwpriv opmode_notify failed");
6840 }
6841 }
6842
6843 val = get_param(cmd, "nss_mcs_cap");
6844 if (val) {
6845 int nss, mcs;
6846 char token[20];
6847 char *result = NULL;
6848 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306849 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006850
Peng Xub8fc5cc2017-05-10 17:27:28 -07006851 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306852 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306853 if (!result) {
6854 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07006855 "NSS not specified");
6856 send_resp(dut, conn, SIGMA_ERROR,
6857 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306858 return 0;
6859 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006860 nss = atoi(result);
6861
6862 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
6863 if (system(buf) != 0) {
6864 sigma_dut_print(dut, DUT_MSG_ERROR,
6865 "iwpriv nss failed");
6866 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006867 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006868
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306869 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006870 if (result == NULL) {
6871 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07006872 "MCS not specified");
6873 send_resp(dut, conn, SIGMA_ERROR,
6874 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006875 return 0;
6876 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306877 result = strtok_r(result, "-", &saveptr);
6878 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306879 if (!result) {
6880 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07006881 "MCS not specified");
6882 send_resp(dut, conn, SIGMA_ERROR,
6883 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306884 return 0;
6885 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006886 mcs = atoi(result);
6887
Arif Hussaina37e9552018-06-20 17:05:59 -07006888 if (program && strcasecmp(program, "HE") == 0) {
6889#ifdef NL80211_SUPPORT
6890 enum he_mcs_config mcs_config;
6891 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006892
Arif Hussaina37e9552018-06-20 17:05:59 -07006893 if (mcs >= 0 && mcs <= 7) {
6894 mcs_config = HE_80_MCS0_7;
6895 } else if (mcs > 7 && mcs <= 9) {
6896 mcs_config = HE_80_MCS0_9;
6897 } else if (mcs > 9 && mcs <= 11) {
6898 mcs_config = HE_80_MCS0_11;
6899 } else {
6900 sigma_dut_print(dut, DUT_MSG_ERROR,
6901 "nss_mcs_cap: HE: Invalid mcs: %d",
6902 mcs);
6903 send_resp(dut, conn, SIGMA_ERROR,
6904 "errorCode,Invalid MCS");
6905 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006906 }
Arif Hussaina37e9552018-06-20 17:05:59 -07006907
6908 ret = sta_set_he_mcs(dut, intf, mcs_config);
6909 if (ret) {
6910 sigma_dut_print(dut, DUT_MSG_ERROR,
6911 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
6912 mcs_config, ret);
6913 send_resp(dut, conn, SIGMA_ERROR,
6914 "errorCode,Failed to set MCS");
6915 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006916 }
Arif Hussaina37e9552018-06-20 17:05:59 -07006917#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006918 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07006919 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
6920#endif /* NL80211_SUPPORT */
6921 } else {
6922 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
6923 intf, mcs);
6924 if (system(buf) != 0) {
6925 sigma_dut_print(dut, DUT_MSG_ERROR,
6926 "iwpriv mcs failed");
6927 }
6928
6929 switch (nss) {
6930 case 1:
6931 switch (mcs) {
6932 case 7:
6933 vht_mcsmap = 0xfffc;
6934 break;
6935 case 8:
6936 vht_mcsmap = 0xfffd;
6937 break;
6938 case 9:
6939 vht_mcsmap = 0xfffe;
6940 break;
6941 default:
6942 vht_mcsmap = 0xfffe;
6943 break;
6944 }
6945 break;
6946 case 2:
6947 switch (mcs) {
6948 case 7:
6949 vht_mcsmap = 0xfff0;
6950 break;
6951 case 8:
6952 vht_mcsmap = 0xfff5;
6953 break;
6954 case 9:
6955 vht_mcsmap = 0xfffa;
6956 break;
6957 default:
6958 vht_mcsmap = 0xfffa;
6959 break;
6960 }
6961 break;
6962 case 3:
6963 switch (mcs) {
6964 case 7:
6965 vht_mcsmap = 0xffc0;
6966 break;
6967 case 8:
6968 vht_mcsmap = 0xffd5;
6969 break;
6970 case 9:
6971 vht_mcsmap = 0xffea;
6972 break;
6973 default:
6974 vht_mcsmap = 0xffea;
6975 break;
6976 }
6977 break;
6978 default:
6979 vht_mcsmap = 0xffea;
6980 break;
6981 }
6982 snprintf(buf, sizeof(buf),
6983 "iwpriv %s vht_mcsmap 0x%04x",
6984 intf, vht_mcsmap);
6985 if (system(buf) != 0) {
6986 sigma_dut_print(dut, DUT_MSG_ERROR,
6987 "iwpriv vht_mcsmap failed");
6988 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006989 }
6990 }
6991
6992 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
6993
6994 val = get_param(cmd, "Vht_tkip");
6995 if (val)
6996 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6997
6998 val = get_param(cmd, "Vht_wep");
6999 if (val)
7000 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7001
7002 if (tkip != -1 || wep != -1) {
7003 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7004 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7005 intf);
7006 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7007 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7008 intf);
7009 } else {
7010 sigma_dut_print(dut, DUT_MSG_ERROR,
7011 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7012 return 0;
7013 }
7014
7015 if (system(buf) != 0) {
7016 sigma_dut_print(dut, DUT_MSG_ERROR,
7017 "iwpriv htweptkip failed");
7018 }
7019 }
7020
Arif Hussain55f00da2018-07-03 08:28:26 -07007021 val = get_param(cmd, "txBandwidth");
7022 if (val) {
7023 switch (get_driver_type()) {
7024 case DRIVER_WCN:
7025 if (wcn_sta_set_width(dut, intf, val) < 0) {
7026 send_resp(dut, conn, SIGMA_ERROR,
7027 "ErrorCode,Failed to set txBandwidth");
7028 return 0;
7029 }
7030 break;
7031 case DRIVER_ATHEROS:
7032 if (ath_set_width(dut, conn, intf, val) < 0) {
7033 send_resp(dut, conn, SIGMA_ERROR,
7034 "ErrorCode,Failed to set txBandwidth");
7035 return 0;
7036 }
7037 break;
7038 default:
7039 sigma_dut_print(dut, DUT_MSG_ERROR,
7040 "Setting txBandwidth not supported");
7041 break;
7042 }
7043 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007044
Arif Hussain9765f7d2018-07-03 08:28:26 -07007045 val = get_param(cmd, "BeamformeeSTS");
7046 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007047 if (sta_set_tx_beamformee(dut, intf, 1)) {
7048 send_resp(dut, conn, SIGMA_ERROR,
7049 "ErrorCode,Failed to set TX beamformee enable");
7050 return 0;
7051 }
7052
Arif Hussain9765f7d2018-07-03 08:28:26 -07007053 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7054 send_resp(dut, conn, SIGMA_ERROR,
7055 "ErrorCode,Failed to set BeamformeeSTS");
7056 return 0;
7057 }
7058 }
7059
Arif Hussain68d23f52018-07-11 13:39:08 -07007060 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7061 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007062#ifdef NL80211_SUPPORT
7063 enum qca_wlan_he_mac_padding_dur set_val;
7064
7065 switch (atoi(val)) {
7066 case 16:
7067 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7068 break;
7069 case 8:
7070 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7071 break;
7072 default:
7073 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7074 break;
7075 }
7076 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007077 send_resp(dut, conn, SIGMA_ERROR,
7078 "ErrorCode,Failed to set MAC padding duration");
7079 return 0;
7080 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007081#else /* NL80211_SUPPORT */
7082 sigma_dut_print(dut, DUT_MSG_ERROR,
7083 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7084#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007085 }
7086
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007087 val = get_param(cmd, "MU_EDCA");
7088 if (val && (strcasecmp(val, "Override") == 0)) {
7089 if (sta_set_mu_edca_override(dut, intf, 1)) {
7090 send_resp(dut, conn, SIGMA_ERROR,
7091 "ErrorCode,Failed to set MU EDCA override");
7092 return 0;
7093 }
7094 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007095
7096 val = get_param(cmd, "ADDBAResp_BufSize");
7097 if (val) {
7098 int buf_size;
7099
7100 if (strcasecmp(val, "gt64") == 0)
7101 buf_size = 256;
7102 else
7103 buf_size = 64;
7104 if (get_driver_type() == DRIVER_WCN &&
7105 sta_set_addba_buf_size(dut, intf, buf_size)) {
7106 send_resp(dut, conn, SIGMA_ERROR,
7107 "ErrorCode,set addbaresp_buff_size failed");
7108 return 0;
7109 }
7110 }
7111
7112 val = get_param(cmd, "ADDBAReq_BufSize");
7113 if (val) {
7114 int buf_size;
7115
7116 if (strcasecmp(val, "gt64") == 0)
7117 buf_size = 256;
7118 else
7119 buf_size = 64;
7120 if (get_driver_type() == DRIVER_WCN &&
7121 sta_set_addba_buf_size(dut, intf, buf_size)) {
7122 send_resp(dut, conn, SIGMA_ERROR,
7123 "ErrorCode,set addbareq_buff_size failed");
7124 return 0;
7125 }
7126 }
7127
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007128 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7129}
7130
7131
7132static int sta_set_wireless_60g(struct sigma_dut *dut,
7133 struct sigma_conn *conn,
7134 struct sigma_cmd *cmd)
7135{
7136 const char *dev_role = get_param(cmd, "DevRole");
7137
7138 if (!dev_role) {
7139 send_resp(dut, conn, SIGMA_INVALID,
7140 "ErrorCode,DevRole not specified");
7141 return 0;
7142 }
7143
7144 if (strcasecmp(dev_role, "PCP") == 0)
7145 return sta_set_60g_pcp(dut, conn, cmd);
7146 if (strcasecmp(dev_role, "STA") == 0)
7147 return sta_set_60g_sta(dut, conn, cmd);
7148 send_resp(dut, conn, SIGMA_INVALID,
7149 "ErrorCode,DevRole not supported");
7150 return 0;
7151}
7152
7153
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307154static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7155 struct sigma_cmd *cmd)
7156{
7157 int status;
7158 const char *intf = get_param(cmd, "Interface");
7159 const char *val = get_param(cmd, "DevRole");
7160
7161 if (val && strcasecmp(val, "STA-CFON") == 0) {
7162 status = sta_cfon_set_wireless(dut, conn, cmd);
7163 if (status)
7164 return status;
7165 }
7166 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7167}
7168
7169
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007170static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7171 struct sigma_cmd *cmd)
7172{
7173 const char *val;
7174
7175 val = get_param(cmd, "Program");
7176 if (val) {
7177 if (strcasecmp(val, "11n") == 0)
7178 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007179 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007180 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7181 if (strcasecmp(val, "60ghz") == 0)
7182 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307183 if (strcasecmp(val, "OCE") == 0)
7184 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007185 send_resp(dut, conn, SIGMA_ERROR,
7186 "ErrorCode,Program value not supported");
7187 } else {
7188 send_resp(dut, conn, SIGMA_ERROR,
7189 "ErrorCode,Program argument not available");
7190 }
7191
7192 return 0;
7193}
7194
7195
7196static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7197 int tid)
7198{
7199 char buf[100];
7200 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7201
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307202 if (tid < 0 ||
7203 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7204 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7205 return;
7206 }
7207
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007208 /*
7209 * Two ways to ensure that addba request with a
7210 * non zero TID could be sent out. EV 117296
7211 */
7212 snprintf(buf, sizeof(buf),
7213 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7214 tid);
7215 if (system(buf) != 0) {
7216 sigma_dut_print(dut, DUT_MSG_ERROR,
7217 "Ping did not send out");
7218 }
7219
7220 snprintf(buf, sizeof(buf),
7221 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7222 intf, VI_QOS_TMP_FILE);
7223 if (system(buf) != 0)
7224 return;
7225
7226 snprintf(buf, sizeof(buf),
7227 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
7228 intf, VI_QOS_TMP_FILE);
7229 if (system(buf) != 0)
7230 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
7231
7232 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
7233 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
7234 if (system(buf) != 0) {
7235 sigma_dut_print(dut, DUT_MSG_ERROR,
7236 "VI_QOS_TEMP_FILE generation error failed");
7237 }
7238 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7239 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7240 if (system(buf) != 0) {
7241 sigma_dut_print(dut, DUT_MSG_ERROR,
7242 "VI_QOS_FILE generation failed");
7243 }
7244
7245 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7246 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7247 if (system(buf) != 0) {
7248 sigma_dut_print(dut, DUT_MSG_ERROR,
7249 "VI_QOS_FILE generation failed");
7250 }
7251
7252 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
7253 if (system(buf) != 0) {
7254 }
7255}
7256
7257
7258static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7259 struct sigma_cmd *cmd)
7260{
7261 const char *intf = get_param(cmd, "Interface");
7262 const char *val;
7263 int tid = 0;
7264 char buf[100];
7265
7266 val = get_param(cmd, "TID");
7267 if (val) {
7268 tid = atoi(val);
7269 if (tid)
7270 ath_sta_inject_frame(dut, intf, tid);
7271 }
7272
7273 /* Command sequence for ADDBA request on Peregrine based devices */
7274 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
7275 if (system(buf) != 0) {
7276 sigma_dut_print(dut, DUT_MSG_ERROR,
7277 "iwpriv setaddbaoper failed");
7278 }
7279
7280 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
7281 if (system(buf) != 0) {
7282 sigma_dut_print(dut, DUT_MSG_ERROR,
7283 "wifitool senddelba failed");
7284 }
7285
7286 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
7287 if (system(buf) != 0) {
7288 sigma_dut_print(dut, DUT_MSG_ERROR,
7289 "wifitool sendaddba failed");
7290 }
7291
7292 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7293
7294 return 1;
7295}
7296
7297
Lior David9981b512017-01-20 13:16:40 +02007298#ifdef __linux__
7299
7300static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
7301 int agg_size)
7302{
7303 char dir[128], buf[128];
7304 FILE *f;
7305 regex_t re;
7306 regmatch_t m[2];
7307 int rc, ret = -1, vring_id, found;
7308
7309 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
7310 sigma_dut_print(dut, DUT_MSG_ERROR,
7311 "failed to get wil6210 debugfs dir");
7312 return -1;
7313 }
7314
7315 snprintf(buf, sizeof(buf), "%s/vrings", dir);
7316 f = fopen(buf, "r");
7317 if (!f) {
7318 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
7319 return -1;
7320 }
7321
7322 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
7323 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
7324 goto out;
7325 }
7326
7327 /* find TX VRING for the mac address */
7328 found = 0;
7329 while (fgets(buf, sizeof(buf), f)) {
7330 if (strcasestr(buf, dest_mac)) {
7331 found = 1;
7332 break;
7333 }
7334 }
7335
7336 if (!found) {
7337 sigma_dut_print(dut, DUT_MSG_ERROR,
7338 "no TX VRING for %s", dest_mac);
7339 goto out;
7340 }
7341
7342 /* extract VRING ID, "VRING tx_<id> = {" */
7343 if (!fgets(buf, sizeof(buf), f)) {
7344 sigma_dut_print(dut, DUT_MSG_ERROR,
7345 "no VRING start line for %s", dest_mac);
7346 goto out;
7347 }
7348
7349 rc = regexec(&re, buf, 2, m, 0);
7350 regfree(&re);
7351 if (rc || m[1].rm_so < 0) {
7352 sigma_dut_print(dut, DUT_MSG_ERROR,
7353 "no VRING TX ID for %s", dest_mac);
7354 goto out;
7355 }
7356 buf[m[1].rm_eo] = 0;
7357 vring_id = atoi(&buf[m[1].rm_so]);
7358
7359 /* send the addba command */
7360 fclose(f);
7361 snprintf(buf, sizeof(buf), "%s/back", dir);
7362 f = fopen(buf, "w");
7363 if (!f) {
7364 sigma_dut_print(dut, DUT_MSG_ERROR,
7365 "failed to open: %s", buf);
7366 return -1;
7367 }
7368
7369 fprintf(f, "add %d %d\n", vring_id, agg_size);
7370
7371 ret = 0;
7372
7373out:
7374 fclose(f);
7375
7376 return ret;
7377}
7378
7379
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007380static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7381 struct sigma_cmd *cmd)
7382{
7383 const char *val;
7384 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007385
7386 val = get_param(cmd, "TID");
7387 if (val) {
7388 tid = atoi(val);
7389 if (tid != 0) {
7390 sigma_dut_print(dut, DUT_MSG_ERROR,
7391 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
7392 tid);
7393 }
7394 }
7395
7396 val = get_param(cmd, "Dest_mac");
7397 if (!val) {
7398 sigma_dut_print(dut, DUT_MSG_ERROR,
7399 "Currently not supporting addba for 60G without Dest_mac");
7400 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7401 }
7402
Lior David9981b512017-01-20 13:16:40 +02007403 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007404 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007405
7406 return 1;
7407}
7408
Lior David9981b512017-01-20 13:16:40 +02007409#endif /* __linux__ */
7410
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007411
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007412static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7413 struct sigma_cmd *cmd)
7414{
7415#ifdef NL80211_SUPPORT
7416 const char *intf = get_param(cmd, "Interface");
7417 const char *val;
7418 int tid = -1;
7419 int bufsize = 64;
7420 struct nl_msg *msg;
7421 int ret = 0;
7422 struct nlattr *params;
7423 int ifindex;
7424
7425 val = get_param(cmd, "TID");
7426 if (val)
7427 tid = atoi(val);
7428
7429 if (tid == -1) {
7430 send_resp(dut, conn, SIGMA_ERROR,
7431 "ErrorCode,sta_send_addba tid invalid");
7432 return 0;
7433 }
7434
7435 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7436
7437 ifindex = if_nametoindex(intf);
7438 if (ifindex == 0) {
7439 sigma_dut_print(dut, DUT_MSG_ERROR,
7440 "%s: Index for interface %s failed",
7441 __func__, intf);
7442 send_resp(dut, conn, SIGMA_ERROR,
7443 "ErrorCode,sta_send_addba interface invalid");
7444 return 0;
7445 }
7446
7447 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7448 NL80211_CMD_VENDOR)) ||
7449 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7450 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7451 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7452 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7453 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7454 nla_put_u8(msg,
7455 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
7456 QCA_WLAN_ADD_BA) ||
7457 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
7458 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007459 nla_put_u16(msg,
7460 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7461 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007462 sigma_dut_print(dut, DUT_MSG_ERROR,
7463 "%s: err in adding vendor_cmd and vendor_data",
7464 __func__);
7465 nlmsg_free(msg);
7466 send_resp(dut, conn, SIGMA_ERROR,
7467 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
7468 return 0;
7469 }
7470 nla_nest_end(msg, params);
7471
7472 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7473 if (ret) {
7474 sigma_dut_print(dut, DUT_MSG_ERROR,
7475 "%s: err in send_and_recv_msgs, ret=%d",
7476 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05307477 if (ret == -EOPNOTSUPP)
7478 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007479 send_resp(dut, conn, SIGMA_ERROR,
7480 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
7481 return 0;
7482 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007483#else /* NL80211_SUPPORT */
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007486#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05307487
7488 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007489}
7490
7491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007492static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7493 struct sigma_cmd *cmd)
7494{
7495 switch (get_driver_type()) {
7496 case DRIVER_ATHEROS:
7497 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007498 case DRIVER_WCN:
7499 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007500#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007501 case DRIVER_WIL6210:
7502 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007503#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007504 default:
7505 /*
7506 * There is no driver specific implementation for other drivers.
7507 * Ignore the command and report COMPLETE since the following
7508 * throughput test operation will end up sending ADDBA anyway.
7509 */
7510 return 1;
7511 }
7512}
7513
7514
7515int inject_eth_frame(int s, const void *data, size_t len,
7516 unsigned short ethtype, char *dst, char *src)
7517{
7518 struct iovec iov[4] = {
7519 {
7520 .iov_base = dst,
7521 .iov_len = ETH_ALEN,
7522 },
7523 {
7524 .iov_base = src,
7525 .iov_len = ETH_ALEN,
7526 },
7527 {
7528 .iov_base = &ethtype,
7529 .iov_len = sizeof(unsigned short),
7530 },
7531 {
7532 .iov_base = (void *) data,
7533 .iov_len = len,
7534 }
7535 };
7536 struct msghdr msg = {
7537 .msg_name = NULL,
7538 .msg_namelen = 0,
7539 .msg_iov = iov,
7540 .msg_iovlen = 4,
7541 .msg_control = NULL,
7542 .msg_controllen = 0,
7543 .msg_flags = 0,
7544 };
7545
7546 return sendmsg(s, &msg, 0);
7547}
7548
7549#if defined(__linux__) || defined(__QNXNTO__)
7550
7551int inject_frame(int s, const void *data, size_t len, int encrypt)
7552{
7553#define IEEE80211_RADIOTAP_F_WEP 0x04
7554#define IEEE80211_RADIOTAP_F_FRAG 0x08
7555 unsigned char rtap_hdr[] = {
7556 0x00, 0x00, /* radiotap version */
7557 0x0e, 0x00, /* radiotap length */
7558 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
7559 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
7560 0x00, /* padding */
7561 0x00, 0x00, /* RX and TX flags to indicate that */
7562 0x00, 0x00, /* this is the injected frame directly */
7563 };
7564 struct iovec iov[2] = {
7565 {
7566 .iov_base = &rtap_hdr,
7567 .iov_len = sizeof(rtap_hdr),
7568 },
7569 {
7570 .iov_base = (void *) data,
7571 .iov_len = len,
7572 }
7573 };
7574 struct msghdr msg = {
7575 .msg_name = NULL,
7576 .msg_namelen = 0,
7577 .msg_iov = iov,
7578 .msg_iovlen = 2,
7579 .msg_control = NULL,
7580 .msg_controllen = 0,
7581 .msg_flags = 0,
7582 };
7583
7584 if (encrypt)
7585 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
7586
7587 return sendmsg(s, &msg, 0);
7588}
7589
7590
7591int open_monitor(const char *ifname)
7592{
7593#ifdef __QNXNTO__
7594 struct sockaddr_dl ll;
7595 int s;
7596
7597 memset(&ll, 0, sizeof(ll));
7598 ll.sdl_family = AF_LINK;
7599 ll.sdl_index = if_nametoindex(ifname);
7600 if (ll.sdl_index == 0) {
7601 perror("if_nametoindex");
7602 return -1;
7603 }
7604 s = socket(PF_INET, SOCK_RAW, 0);
7605#else /* __QNXNTO__ */
7606 struct sockaddr_ll ll;
7607 int s;
7608
7609 memset(&ll, 0, sizeof(ll));
7610 ll.sll_family = AF_PACKET;
7611 ll.sll_ifindex = if_nametoindex(ifname);
7612 if (ll.sll_ifindex == 0) {
7613 perror("if_nametoindex");
7614 return -1;
7615 }
7616 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
7617#endif /* __QNXNTO__ */
7618 if (s < 0) {
7619 perror("socket[PF_PACKET,SOCK_RAW]");
7620 return -1;
7621 }
7622
7623 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
7624 perror("monitor socket bind");
7625 close(s);
7626 return -1;
7627 }
7628
7629 return s;
7630}
7631
7632
7633static int hex2num(char c)
7634{
7635 if (c >= '0' && c <= '9')
7636 return c - '0';
7637 if (c >= 'a' && c <= 'f')
7638 return c - 'a' + 10;
7639 if (c >= 'A' && c <= 'F')
7640 return c - 'A' + 10;
7641 return -1;
7642}
7643
7644
7645int hwaddr_aton(const char *txt, unsigned char *addr)
7646{
7647 int i;
7648
7649 for (i = 0; i < 6; i++) {
7650 int a, b;
7651
7652 a = hex2num(*txt++);
7653 if (a < 0)
7654 return -1;
7655 b = hex2num(*txt++);
7656 if (b < 0)
7657 return -1;
7658 *addr++ = (a << 4) | b;
7659 if (i < 5 && *txt++ != ':')
7660 return -1;
7661 }
7662
7663 return 0;
7664}
7665
7666#endif /* defined(__linux__) || defined(__QNXNTO__) */
7667
7668enum send_frame_type {
7669 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
7670};
7671enum send_frame_protection {
7672 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
7673};
7674
7675
7676static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7677 enum send_frame_type frame,
7678 enum send_frame_protection protected,
7679 const char *dest)
7680{
7681#ifdef __linux__
7682 unsigned char buf[1000], *pos;
7683 int s, res;
7684 char bssid[20], addr[20];
7685 char result[32], ssid[100];
7686 size_t ssid_len;
7687
7688 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
7689 sizeof(result)) < 0 ||
7690 strncmp(result, "COMPLETED", 9) != 0) {
7691 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
7692 return 0;
7693 }
7694
7695 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
7696 < 0) {
7697 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7698 "current BSSID");
7699 return 0;
7700 }
7701
7702 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
7703 < 0) {
7704 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7705 "own MAC address");
7706 return 0;
7707 }
7708
7709 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
7710 < 0) {
7711 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7712 "current SSID");
7713 return 0;
7714 }
7715 ssid_len = strlen(ssid);
7716
7717 pos = buf;
7718
7719 /* Frame Control */
7720 switch (frame) {
7721 case DISASSOC:
7722 *pos++ = 0xa0;
7723 break;
7724 case DEAUTH:
7725 *pos++ = 0xc0;
7726 break;
7727 case SAQUERY:
7728 *pos++ = 0xd0;
7729 break;
7730 case AUTH:
7731 *pos++ = 0xb0;
7732 break;
7733 case ASSOCREQ:
7734 *pos++ = 0x00;
7735 break;
7736 case REASSOCREQ:
7737 *pos++ = 0x20;
7738 break;
7739 case DLS_REQ:
7740 *pos++ = 0xd0;
7741 break;
7742 }
7743
7744 if (protected == INCORRECT_KEY)
7745 *pos++ = 0x40; /* Set Protected field to 1 */
7746 else
7747 *pos++ = 0x00;
7748
7749 /* Duration */
7750 *pos++ = 0x00;
7751 *pos++ = 0x00;
7752
7753 /* addr1 = DA (current AP) */
7754 hwaddr_aton(bssid, pos);
7755 pos += 6;
7756 /* addr2 = SA (own address) */
7757 hwaddr_aton(addr, pos);
7758 pos += 6;
7759 /* addr3 = BSSID (current AP) */
7760 hwaddr_aton(bssid, pos);
7761 pos += 6;
7762
7763 /* Seq# (to be filled by driver/mac80211) */
7764 *pos++ = 0x00;
7765 *pos++ = 0x00;
7766
7767 if (protected == INCORRECT_KEY) {
7768 /* CCMP parameters */
7769 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
7770 pos += 8;
7771 }
7772
7773 if (protected == INCORRECT_KEY) {
7774 switch (frame) {
7775 case DEAUTH:
7776 /* Reason code (encrypted) */
7777 memcpy(pos, "\xa7\x39", 2);
7778 pos += 2;
7779 break;
7780 case DISASSOC:
7781 /* Reason code (encrypted) */
7782 memcpy(pos, "\xa7\x39", 2);
7783 pos += 2;
7784 break;
7785 case SAQUERY:
7786 /* Category|Action|TransID (encrypted) */
7787 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
7788 pos += 4;
7789 break;
7790 default:
7791 return -1;
7792 }
7793
7794 /* CCMP MIC */
7795 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
7796 pos += 8;
7797 } else {
7798 switch (frame) {
7799 case DEAUTH:
7800 /* reason code = 8 */
7801 *pos++ = 0x08;
7802 *pos++ = 0x00;
7803 break;
7804 case DISASSOC:
7805 /* reason code = 8 */
7806 *pos++ = 0x08;
7807 *pos++ = 0x00;
7808 break;
7809 case SAQUERY:
7810 /* Category - SA Query */
7811 *pos++ = 0x08;
7812 /* SA query Action - Request */
7813 *pos++ = 0x00;
7814 /* Transaction ID */
7815 *pos++ = 0x12;
7816 *pos++ = 0x34;
7817 break;
7818 case AUTH:
7819 /* Auth Alg (Open) */
7820 *pos++ = 0x00;
7821 *pos++ = 0x00;
7822 /* Seq# */
7823 *pos++ = 0x01;
7824 *pos++ = 0x00;
7825 /* Status code */
7826 *pos++ = 0x00;
7827 *pos++ = 0x00;
7828 break;
7829 case ASSOCREQ:
7830 /* Capability Information */
7831 *pos++ = 0x31;
7832 *pos++ = 0x04;
7833 /* Listen Interval */
7834 *pos++ = 0x0a;
7835 *pos++ = 0x00;
7836 /* SSID */
7837 *pos++ = 0x00;
7838 *pos++ = ssid_len;
7839 memcpy(pos, ssid, ssid_len);
7840 pos += ssid_len;
7841 /* Supported Rates */
7842 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
7843 10);
7844 pos += 10;
7845 /* Extended Supported Rates */
7846 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
7847 pos += 6;
7848 /* RSN */
7849 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7850 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7851 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7852 pos += 28;
7853 break;
7854 case REASSOCREQ:
7855 /* Capability Information */
7856 *pos++ = 0x31;
7857 *pos++ = 0x04;
7858 /* Listen Interval */
7859 *pos++ = 0x0a;
7860 *pos++ = 0x00;
7861 /* Current AP */
7862 hwaddr_aton(bssid, pos);
7863 pos += 6;
7864 /* SSID */
7865 *pos++ = 0x00;
7866 *pos++ = ssid_len;
7867 memcpy(pos, ssid, ssid_len);
7868 pos += ssid_len;
7869 /* Supported Rates */
7870 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
7871 10);
7872 pos += 10;
7873 /* Extended Supported Rates */
7874 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
7875 pos += 6;
7876 /* RSN */
7877 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7878 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7879 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7880 pos += 28;
7881 break;
7882 case DLS_REQ:
7883 /* Category - DLS */
7884 *pos++ = 0x02;
7885 /* DLS Action - Request */
7886 *pos++ = 0x00;
7887 /* Destination MACAddress */
7888 if (dest)
7889 hwaddr_aton(dest, pos);
7890 else
7891 memset(pos, 0, 6);
7892 pos += 6;
7893 /* Source MACAddress */
7894 hwaddr_aton(addr, pos);
7895 pos += 6;
7896 /* Capability Information */
7897 *pos++ = 0x10; /* Privacy */
7898 *pos++ = 0x06; /* QoS */
7899 /* DLS Timeout Value */
7900 *pos++ = 0x00;
7901 *pos++ = 0x01;
7902 /* Supported rates */
7903 *pos++ = 0x01;
7904 *pos++ = 0x08;
7905 *pos++ = 0x0c; /* 6 Mbps */
7906 *pos++ = 0x12; /* 9 Mbps */
7907 *pos++ = 0x18; /* 12 Mbps */
7908 *pos++ = 0x24; /* 18 Mbps */
7909 *pos++ = 0x30; /* 24 Mbps */
7910 *pos++ = 0x48; /* 36 Mbps */
7911 *pos++ = 0x60; /* 48 Mbps */
7912 *pos++ = 0x6c; /* 54 Mbps */
7913 /* TODO: Extended Supported Rates */
7914 /* TODO: HT Capabilities */
7915 break;
7916 }
7917 }
7918
7919 s = open_monitor("sigmadut");
7920 if (s < 0) {
7921 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7922 "monitor socket");
7923 return 0;
7924 }
7925
7926 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
7927 if (res < 0) {
7928 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7929 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307930 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007931 return 0;
7932 }
7933 if (res < pos - buf) {
7934 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
7935 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307936 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007937 return 0;
7938 }
7939
7940 close(s);
7941
7942 return 1;
7943#else /* __linux__ */
7944 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
7945 "yet supported");
7946 return 0;
7947#endif /* __linux__ */
7948}
7949
7950
7951static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
7952 struct sigma_conn *conn,
7953 struct sigma_cmd *cmd)
7954{
7955 const char *intf = get_param(cmd, "Interface");
7956 const char *sta, *val;
7957 unsigned char addr[ETH_ALEN];
7958 char buf[100];
7959
7960 sta = get_param(cmd, "peer");
7961 if (sta == NULL)
7962 sta = get_param(cmd, "station");
7963 if (sta == NULL) {
7964 send_resp(dut, conn, SIGMA_ERROR,
7965 "ErrorCode,Missing peer address");
7966 return 0;
7967 }
7968 if (hwaddr_aton(sta, addr) < 0) {
7969 send_resp(dut, conn, SIGMA_ERROR,
7970 "ErrorCode,Invalid peer address");
7971 return 0;
7972 }
7973
7974 val = get_param(cmd, "type");
7975 if (val == NULL)
7976 return -1;
7977
7978 if (strcasecmp(val, "DISCOVERY") == 0) {
7979 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
7980 if (wpa_command(intf, buf) < 0) {
7981 send_resp(dut, conn, SIGMA_ERROR,
7982 "ErrorCode,Failed to send TDLS discovery");
7983 return 0;
7984 }
7985 return 1;
7986 }
7987
7988 if (strcasecmp(val, "SETUP") == 0) {
7989 int status = 0, timeout = 0;
7990
7991 val = get_param(cmd, "Status");
7992 if (val)
7993 status = atoi(val);
7994
7995 val = get_param(cmd, "Timeout");
7996 if (val)
7997 timeout = atoi(val);
7998
7999 if (status != 0 && status != 37) {
8000 send_resp(dut, conn, SIGMA_ERROR,
8001 "ErrorCode,Unsupported status value");
8002 return 0;
8003 }
8004
8005 if (timeout != 0 && timeout != 301) {
8006 send_resp(dut, conn, SIGMA_ERROR,
8007 "ErrorCode,Unsupported timeout value");
8008 return 0;
8009 }
8010
8011 if (status && timeout) {
8012 send_resp(dut, conn, SIGMA_ERROR,
8013 "ErrorCode,Unsupported timeout+status "
8014 "combination");
8015 return 0;
8016 }
8017
8018 if (status == 37 &&
8019 wpa_command(intf, "SET tdls_testing 0x200")) {
8020 send_resp(dut, conn, SIGMA_ERROR,
8021 "ErrorCode,Failed to enable "
8022 "decline setup response test mode");
8023 return 0;
8024 }
8025
8026 if (timeout == 301) {
8027 int res;
8028 if (dut->no_tpk_expiration)
8029 res = wpa_command(intf,
8030 "SET tdls_testing 0x108");
8031 else
8032 res = wpa_command(intf,
8033 "SET tdls_testing 0x8");
8034 if (res) {
8035 send_resp(dut, conn, SIGMA_ERROR,
8036 "ErrorCode,Failed to set short TPK "
8037 "lifetime");
8038 return 0;
8039 }
8040 }
8041
8042 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8043 if (wpa_command(intf, buf) < 0) {
8044 send_resp(dut, conn, SIGMA_ERROR,
8045 "ErrorCode,Failed to send TDLS setup");
8046 return 0;
8047 }
8048 return 1;
8049 }
8050
8051 if (strcasecmp(val, "TEARDOWN") == 0) {
8052 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8053 if (wpa_command(intf, buf) < 0) {
8054 send_resp(dut, conn, SIGMA_ERROR,
8055 "ErrorCode,Failed to send TDLS teardown");
8056 return 0;
8057 }
8058 return 1;
8059 }
8060
8061 send_resp(dut, conn, SIGMA_ERROR,
8062 "ErrorCode,Unsupported TDLS frame");
8063 return 0;
8064}
8065
8066
8067static int sta_ap_known(const char *ifname, const char *bssid)
8068{
8069 char buf[4096];
8070
Jouni Malinendd32f192018-09-15 02:55:19 +03008071 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008072 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8073 return 0;
8074 if (strncmp(buf, "id=", 3) != 0)
8075 return 0;
8076 return 1;
8077}
8078
8079
8080static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8081 const char *bssid)
8082{
8083 int res;
8084 struct wpa_ctrl *ctrl;
8085 char buf[256];
8086
8087 if (sta_ap_known(ifname, bssid))
8088 return 0;
8089 sigma_dut_print(dut, DUT_MSG_DEBUG,
8090 "AP not in BSS table - start scan");
8091
8092 ctrl = open_wpa_mon(ifname);
8093 if (ctrl == NULL) {
8094 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8095 "wpa_supplicant monitor connection");
8096 return -1;
8097 }
8098
8099 if (wpa_command(ifname, "SCAN") < 0) {
8100 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8101 wpa_ctrl_detach(ctrl);
8102 wpa_ctrl_close(ctrl);
8103 return -1;
8104 }
8105
8106 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8107 buf, sizeof(buf));
8108
8109 wpa_ctrl_detach(ctrl);
8110 wpa_ctrl_close(ctrl);
8111
8112 if (res < 0) {
8113 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8114 return -1;
8115 }
8116
8117 if (sta_ap_known(ifname, bssid))
8118 return 0;
8119 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8120 return -1;
8121}
8122
8123
8124static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8125 struct sigma_conn *conn,
8126 struct sigma_cmd *cmd,
8127 const char *intf)
8128{
8129 char buf[200];
8130
8131 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8132 if (system(buf) != 0) {
8133 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8134 "ndsend");
8135 return 0;
8136 }
8137
8138 return 1;
8139}
8140
8141
8142static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8143 struct sigma_conn *conn,
8144 struct sigma_cmd *cmd,
8145 const char *intf)
8146{
8147 char buf[200];
8148 const char *ip = get_param(cmd, "SenderIP");
8149
Peng Xu26b356d2017-10-04 17:58:16 -07008150 if (!ip)
8151 return 0;
8152
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8154 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8155 if (system(buf) == 0) {
8156 sigma_dut_print(dut, DUT_MSG_INFO,
8157 "Neighbor Solicitation got a response "
8158 "for %s@%s", ip, intf);
8159 }
8160
8161 return 1;
8162}
8163
8164
8165static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8166 struct sigma_conn *conn,
8167 struct sigma_cmd *cmd,
8168 const char *ifname)
8169{
8170 char buf[200];
8171 const char *ip = get_param(cmd, "SenderIP");
8172
8173 if (ip == NULL) {
8174 send_resp(dut, conn, SIGMA_ERROR,
8175 "ErrorCode,Missing SenderIP parameter");
8176 return 0;
8177 }
8178 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8179 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8180 if (system(buf) != 0) {
8181 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8182 "for %s@%s", ip, ifname);
8183 }
8184
8185 return 1;
8186}
8187
8188
8189static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8190 struct sigma_conn *conn,
8191 struct sigma_cmd *cmd,
8192 const char *ifname)
8193{
8194 char buf[200];
8195 char ip[16];
8196 int s;
Peng Xub3756882017-10-04 14:39:09 -07008197 struct ifreq ifr;
8198 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008199
8200 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008201 if (s < 0) {
8202 perror("socket");
8203 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008204 }
8205
Peng Xub3756882017-10-04 14:39:09 -07008206 memset(&ifr, 0, sizeof(ifr));
8207 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8208 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8209 sigma_dut_print(dut, DUT_MSG_INFO,
8210 "Failed to get %s IP address: %s",
8211 ifname, strerror(errno));
8212 close(s);
8213 return -1;
8214 }
8215 close(s);
8216
8217 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
8218 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
8219
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008220 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
8221 ip);
8222 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8223 if (system(buf) != 0) {
8224 }
8225
8226 return 1;
8227}
8228
8229
8230static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
8231 struct sigma_conn *conn,
8232 struct sigma_cmd *cmd,
8233 const char *ifname)
8234{
8235 char buf[200], addr[20];
8236 char dst[ETH_ALEN], src[ETH_ALEN];
8237 short ethtype = htons(ETH_P_ARP);
8238 char *pos;
8239 int s, res;
8240 const char *val;
8241 struct sockaddr_in taddr;
8242
8243 val = get_param(cmd, "dest");
8244 if (val)
8245 hwaddr_aton(val, (unsigned char *) dst);
8246
8247 val = get_param(cmd, "DestIP");
8248 if (val)
8249 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07008250 else
8251 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008252
8253 if (get_wpa_status(get_station_ifname(), "address", addr,
8254 sizeof(addr)) < 0)
8255 return -2;
8256 hwaddr_aton(addr, (unsigned char *) src);
8257
8258 pos = buf;
8259 *pos++ = 0x00;
8260 *pos++ = 0x01;
8261 *pos++ = 0x08;
8262 *pos++ = 0x00;
8263 *pos++ = 0x06;
8264 *pos++ = 0x04;
8265 *pos++ = 0x00;
8266 *pos++ = 0x02;
8267 memcpy(pos, src, ETH_ALEN);
8268 pos += ETH_ALEN;
8269 memcpy(pos, &taddr.sin_addr, 4);
8270 pos += 4;
8271 memcpy(pos, dst, ETH_ALEN);
8272 pos += ETH_ALEN;
8273 memcpy(pos, &taddr.sin_addr, 4);
8274 pos += 4;
8275
8276 s = open_monitor(get_station_ifname());
8277 if (s < 0) {
8278 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8279 "monitor socket");
8280 return 0;
8281 }
8282
8283 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
8284 if (res < 0) {
8285 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8286 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308287 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008288 return 0;
8289 }
8290
8291 close(s);
8292
8293 return 1;
8294}
8295
8296
8297static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
8298 struct sigma_conn *conn,
8299 struct sigma_cmd *cmd,
8300 const char *intf, const char *dest)
8301{
8302 char buf[100];
8303
8304 if (if_nametoindex("sigmadut") == 0) {
8305 snprintf(buf, sizeof(buf),
8306 "iw dev %s interface add sigmadut type monitor",
8307 get_station_ifname());
8308 if (system(buf) != 0 ||
8309 if_nametoindex("sigmadut") == 0) {
8310 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8311 "monitor interface with '%s'", buf);
8312 return -2;
8313 }
8314 }
8315
8316 if (system("ifconfig sigmadut up") != 0) {
8317 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8318 "monitor interface up");
8319 return -2;
8320 }
8321
8322 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
8323}
8324
8325
8326static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
8327 struct sigma_conn *conn,
8328 struct sigma_cmd *cmd)
8329{
8330 const char *intf = get_param(cmd, "Interface");
8331 const char *dest = get_param(cmd, "Dest");
8332 const char *type = get_param(cmd, "FrameName");
8333 const char *val;
8334 char buf[200], *pos, *end;
8335 int count, count2;
8336
8337 if (type == NULL)
8338 type = get_param(cmd, "Type");
8339
8340 if (intf == NULL || dest == NULL || type == NULL)
8341 return -1;
8342
8343 if (strcasecmp(type, "NeighAdv") == 0)
8344 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
8345
8346 if (strcasecmp(type, "NeighSolicitReq") == 0)
8347 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
8348
8349 if (strcasecmp(type, "ARPProbe") == 0)
8350 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
8351
8352 if (strcasecmp(type, "ARPAnnounce") == 0)
8353 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
8354
8355 if (strcasecmp(type, "ARPReply") == 0)
8356 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
8357
8358 if (strcasecmp(type, "DLS-request") == 0 ||
8359 strcasecmp(type, "DLSrequest") == 0)
8360 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
8361 dest);
8362
8363 if (strcasecmp(type, "ANQPQuery") != 0 &&
8364 strcasecmp(type, "Query") != 0) {
8365 send_resp(dut, conn, SIGMA_ERROR,
8366 "ErrorCode,Unsupported HS 2.0 send frame type");
8367 return 0;
8368 }
8369
8370 if (sta_scan_ap(dut, intf, dest) < 0) {
8371 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
8372 "the requested AP");
8373 return 0;
8374 }
8375
8376 pos = buf;
8377 end = buf + sizeof(buf);
8378 count = 0;
8379 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
8380
8381 val = get_param(cmd, "ANQP_CAP_LIST");
8382 if (val && atoi(val)) {
8383 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
8384 count++;
8385 }
8386
8387 val = get_param(cmd, "VENUE_NAME");
8388 if (val && atoi(val)) {
8389 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
8390 count++;
8391 }
8392
8393 val = get_param(cmd, "NETWORK_AUTH_TYPE");
8394 if (val && atoi(val)) {
8395 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
8396 count++;
8397 }
8398
8399 val = get_param(cmd, "ROAMING_CONS");
8400 if (val && atoi(val)) {
8401 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
8402 count++;
8403 }
8404
8405 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
8406 if (val && atoi(val)) {
8407 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
8408 count++;
8409 }
8410
8411 val = get_param(cmd, "NAI_REALM_LIST");
8412 if (val && atoi(val)) {
8413 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
8414 count++;
8415 }
8416
8417 val = get_param(cmd, "3GPP_INFO");
8418 if (val && atoi(val)) {
8419 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
8420 count++;
8421 }
8422
8423 val = get_param(cmd, "DOMAIN_LIST");
8424 if (val && atoi(val)) {
8425 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
8426 count++;
8427 }
8428
Jouni Malinen34cf9532018-04-29 19:26:33 +03008429 val = get_param(cmd, "Venue_URL");
8430 if (val && atoi(val)) {
8431 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
8432 count++;
8433 }
8434
Jouni Malinend3bca5d2018-04-29 17:25:23 +03008435 val = get_param(cmd, "Advice_Of_Charge");
8436 if (val && atoi(val)) {
8437 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
8438 count++;
8439 }
8440
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008441 if (count && wpa_command(intf, buf)) {
8442 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
8443 return 0;
8444 }
8445
8446 pos = buf;
8447 end = buf + sizeof(buf);
8448 count2 = 0;
8449 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
8450
8451 val = get_param(cmd, "HS_CAP_LIST");
8452 if (val && atoi(val)) {
8453 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
8454 count2++;
8455 }
8456
8457 val = get_param(cmd, "OPER_NAME");
8458 if (val && atoi(val)) {
8459 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
8460 count2++;
8461 }
8462
8463 val = get_param(cmd, "WAN_METRICS");
8464 if (!val)
8465 val = get_param(cmd, "WAN_MAT");
8466 if (!val)
8467 val = get_param(cmd, "WAN_MET");
8468 if (val && atoi(val)) {
8469 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
8470 count2++;
8471 }
8472
8473 val = get_param(cmd, "CONNECTION_CAPABILITY");
8474 if (val && atoi(val)) {
8475 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
8476 count2++;
8477 }
8478
8479 val = get_param(cmd, "OP_CLASS");
8480 if (val && atoi(val)) {
8481 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
8482 count2++;
8483 }
8484
8485 val = get_param(cmd, "OSU_PROVIDER_LIST");
8486 if (val && atoi(val)) {
8487 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
8488 count2++;
8489 }
8490
Jouni Malinenf67afec2018-04-29 19:24:58 +03008491 val = get_param(cmd, "OPER_ICON_METADATA");
8492 if (!val)
8493 val = get_param(cmd, "OPERATOR_ICON_METADATA");
8494 if (val && atoi(val)) {
8495 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
8496 count2++;
8497 }
8498
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008499 if (count && count2) {
8500 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
8501 "second query");
8502 sleep(1);
8503 }
8504
8505 if (count2 && wpa_command(intf, buf)) {
8506 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
8507 "failed");
8508 return 0;
8509 }
8510
8511 val = get_param(cmd, "NAI_HOME_REALM_LIST");
8512 if (val) {
8513 if (count || count2) {
8514 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8515 "sending out second query");
8516 sleep(1);
8517 }
8518
8519 if (strcmp(val, "1") == 0)
8520 val = "mail.example.com";
8521 snprintf(buf, end - pos,
8522 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
8523 dest, val);
8524 if (wpa_command(intf, buf)) {
8525 send_resp(dut, conn, SIGMA_ERROR,
8526 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
8527 "failed");
8528 return 0;
8529 }
8530 }
8531
8532 val = get_param(cmd, "ICON_REQUEST");
8533 if (val) {
8534 if (count || count2) {
8535 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8536 "sending out second query");
8537 sleep(1);
8538 }
8539
8540 snprintf(buf, end - pos,
8541 "HS20_ICON_REQUEST %s %s", dest, val);
8542 if (wpa_command(intf, buf)) {
8543 send_resp(dut, conn, SIGMA_ERROR,
8544 "ErrorCode,HS20_ICON_REQUEST failed");
8545 return 0;
8546 }
8547 }
8548
8549 return 1;
8550}
8551
8552
8553static int ath_sta_send_frame_vht(struct sigma_dut *dut,
8554 struct sigma_conn *conn,
8555 struct sigma_cmd *cmd)
8556{
8557 const char *val;
8558 char *ifname;
8559 char buf[100];
8560 int chwidth, nss;
8561
8562 val = get_param(cmd, "framename");
8563 if (!val)
8564 return -1;
8565 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
8566
8567 /* Command sequence to generate Op mode notification */
8568 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
8569 ifname = get_station_ifname();
8570
8571 /* Disable STBC */
8572 snprintf(buf, sizeof(buf),
8573 "iwpriv %s tx_stbc 0", ifname);
8574 if (system(buf) != 0) {
8575 sigma_dut_print(dut, DUT_MSG_ERROR,
8576 "iwpriv tx_stbc 0 failed!");
8577 }
8578
8579 /* Extract Channel width */
8580 val = get_param(cmd, "Channel_width");
8581 if (val) {
8582 switch (atoi(val)) {
8583 case 20:
8584 chwidth = 0;
8585 break;
8586 case 40:
8587 chwidth = 1;
8588 break;
8589 case 80:
8590 chwidth = 2;
8591 break;
8592 case 160:
8593 chwidth = 3;
8594 break;
8595 default:
8596 chwidth = 2;
8597 break;
8598 }
8599
8600 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8601 ifname, chwidth);
8602 if (system(buf) != 0) {
8603 sigma_dut_print(dut, DUT_MSG_ERROR,
8604 "iwpriv chwidth failed!");
8605 }
8606 }
8607
8608 /* Extract NSS */
8609 val = get_param(cmd, "NSS");
8610 if (val) {
8611 switch (atoi(val)) {
8612 case 1:
8613 nss = 1;
8614 break;
8615 case 2:
8616 nss = 3;
8617 break;
8618 case 3:
8619 nss = 7;
8620 break;
8621 default:
8622 /* We do not support NSS > 3 */
8623 nss = 3;
8624 break;
8625 }
8626 snprintf(buf, sizeof(buf),
8627 "iwpriv %s rxchainmask %d", ifname, nss);
8628 if (system(buf) != 0) {
8629 sigma_dut_print(dut, DUT_MSG_ERROR,
8630 "iwpriv rxchainmask failed!");
8631 }
8632 }
8633
8634 /* Opmode notify */
8635 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
8636 if (system(buf) != 0) {
8637 sigma_dut_print(dut, DUT_MSG_ERROR,
8638 "iwpriv opmode_notify failed!");
8639 } else {
8640 sigma_dut_print(dut, DUT_MSG_INFO,
8641 "Sent out the notify frame!");
8642 }
8643 }
8644
8645 return 1;
8646}
8647
8648
8649static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
8650 struct sigma_conn *conn,
8651 struct sigma_cmd *cmd)
8652{
8653 switch (get_driver_type()) {
8654 case DRIVER_ATHEROS:
8655 return ath_sta_send_frame_vht(dut, conn, cmd);
8656 default:
8657 send_resp(dut, conn, SIGMA_ERROR,
8658 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
8659 return 0;
8660 }
8661}
8662
8663
Lior David0fe101e2017-03-09 16:09:50 +02008664#ifdef __linux__
8665int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8666 struct sigma_cmd *cmd)
8667{
8668 const char *frame_name = get_param(cmd, "framename");
8669 const char *mac = get_param(cmd, "dest_mac");
8670
8671 if (!frame_name || !mac) {
8672 sigma_dut_print(dut, DUT_MSG_ERROR,
8673 "framename and dest_mac must be provided");
8674 return -1;
8675 }
8676
8677 if (strcasecmp(frame_name, "brp") == 0) {
8678 const char *l_rx = get_param(cmd, "L-RX");
8679 int l_rx_i;
8680
8681 if (!l_rx) {
8682 sigma_dut_print(dut, DUT_MSG_ERROR,
8683 "L-RX must be provided");
8684 return -1;
8685 }
8686 l_rx_i = atoi(l_rx);
8687
8688 sigma_dut_print(dut, DUT_MSG_INFO,
8689 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
8690 mac, l_rx);
8691 if (l_rx_i != 16) {
8692 sigma_dut_print(dut, DUT_MSG_ERROR,
8693 "unsupported L-RX: %s", l_rx);
8694 return -1;
8695 }
8696
8697 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
8698 return -1;
8699 } else if (strcasecmp(frame_name, "ssw") == 0) {
8700 sigma_dut_print(dut, DUT_MSG_INFO,
8701 "dev_send_frame: SLS, dest_mac %s", mac);
8702 if (wil6210_send_sls(dut, mac))
8703 return -1;
8704 } else {
8705 sigma_dut_print(dut, DUT_MSG_ERROR,
8706 "unsupported frame type: %s", frame_name);
8707 return -1;
8708 }
8709
8710 return 1;
8711}
8712#endif /* __linux__ */
8713
8714
8715static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
8716 struct sigma_conn *conn,
8717 struct sigma_cmd *cmd)
8718{
8719 switch (get_driver_type()) {
8720#ifdef __linux__
8721 case DRIVER_WIL6210:
8722 return wil6210_send_frame_60g(dut, conn, cmd);
8723#endif /* __linux__ */
8724 default:
8725 send_resp(dut, conn, SIGMA_ERROR,
8726 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
8727 return 0;
8728 }
8729}
8730
8731
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308732static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
8733 const char *intf, struct sigma_cmd *cmd)
8734{
8735 const char *val, *addr;
8736 char buf[100];
8737
8738 addr = get_param(cmd, "DestMac");
8739 if (!addr) {
8740 send_resp(dut, conn, SIGMA_INVALID,
8741 "ErrorCode,AP MAC address is missing");
8742 return 0;
8743 }
8744
8745 val = get_param(cmd, "ANQPQuery_ID");
8746 if (!val) {
8747 send_resp(dut, conn, SIGMA_INVALID,
8748 "ErrorCode,Missing ANQPQuery_ID");
8749 return 0;
8750 }
8751
8752 if (strcasecmp(val, "NeighborReportReq") == 0) {
8753 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
8754 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
8755 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
8756 } else {
8757 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
8758 val);
8759 send_resp(dut, conn, SIGMA_INVALID,
8760 "ErrorCode,Invalid ANQPQuery_ID");
8761 return 0;
8762 }
8763
Ashwini Patild174f2c2017-04-13 16:49:46 +05308764 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
8765 * (Address3 = Wildcard BSSID when sent to not-associated AP;
8766 * if associated, AP BSSID).
8767 */
8768 if (wpa_command(intf, "SET gas_address3 1") < 0) {
8769 send_resp(dut, conn, SIGMA_ERROR,
8770 "ErrorCode,Failed to set gas_address3");
8771 return 0;
8772 }
8773
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308774 if (wpa_command(intf, buf) < 0) {
8775 send_resp(dut, conn, SIGMA_ERROR,
8776 "ErrorCode,Failed to send ANQP query");
8777 return 0;
8778 }
8779
8780 return 1;
8781}
8782
8783
8784static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
8785 struct sigma_conn *conn,
8786 const char *intf,
8787 struct sigma_cmd *cmd)
8788{
8789 const char *val = get_param(cmd, "FrameName");
8790
8791 if (val && strcasecmp(val, "ANQPQuery") == 0)
8792 return mbo_send_anqp_query(dut, conn, intf, cmd);
8793
8794 return 2;
8795}
8796
8797
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8799 struct sigma_cmd *cmd)
8800{
8801 const char *intf = get_param(cmd, "Interface");
8802 const char *val;
8803 enum send_frame_type frame;
8804 enum send_frame_protection protected;
8805 char buf[100];
8806 unsigned char addr[ETH_ALEN];
8807 int res;
8808
8809 val = get_param(cmd, "program");
8810 if (val == NULL)
8811 val = get_param(cmd, "frame");
8812 if (val && strcasecmp(val, "TDLS") == 0)
8813 return cmd_sta_send_frame_tdls(dut, conn, cmd);
8814 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03008815 strcasecmp(val, "HS2-R2") == 0 ||
8816 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008817 return cmd_sta_send_frame_hs2(dut, conn, cmd);
8818 if (val && strcasecmp(val, "VHT") == 0)
8819 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008820 if (val && strcasecmp(val, "LOC") == 0)
8821 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02008822 if (val && strcasecmp(val, "60GHz") == 0)
8823 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05308824 if (val && strcasecmp(val, "MBO") == 0) {
8825 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
8826 if (res != 2)
8827 return res;
8828 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829
8830 val = get_param(cmd, "TD_DISC");
8831 if (val) {
8832 if (hwaddr_aton(val, addr) < 0)
8833 return -1;
8834 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
8835 if (wpa_command(intf, buf) < 0) {
8836 send_resp(dut, conn, SIGMA_ERROR,
8837 "ErrorCode,Failed to send TDLS discovery");
8838 return 0;
8839 }
8840 return 1;
8841 }
8842
8843 val = get_param(cmd, "TD_Setup");
8844 if (val) {
8845 if (hwaddr_aton(val, addr) < 0)
8846 return -1;
8847 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
8848 if (wpa_command(intf, buf) < 0) {
8849 send_resp(dut, conn, SIGMA_ERROR,
8850 "ErrorCode,Failed to start TDLS setup");
8851 return 0;
8852 }
8853 return 1;
8854 }
8855
8856 val = get_param(cmd, "TD_TearDown");
8857 if (val) {
8858 if (hwaddr_aton(val, addr) < 0)
8859 return -1;
8860 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
8861 if (wpa_command(intf, buf) < 0) {
8862 send_resp(dut, conn, SIGMA_ERROR,
8863 "ErrorCode,Failed to tear down TDLS link");
8864 return 0;
8865 }
8866 return 1;
8867 }
8868
8869 val = get_param(cmd, "TD_ChannelSwitch");
8870 if (val) {
8871 /* TODO */
8872 send_resp(dut, conn, SIGMA_ERROR,
8873 "ErrorCode,TD_ChannelSwitch not yet supported");
8874 return 0;
8875 }
8876
8877 val = get_param(cmd, "TD_NF");
8878 if (val) {
8879 /* TODO */
8880 send_resp(dut, conn, SIGMA_ERROR,
8881 "ErrorCode,TD_NF not yet supported");
8882 return 0;
8883 }
8884
8885 val = get_param(cmd, "PMFFrameType");
8886 if (val == NULL)
8887 val = get_param(cmd, "FrameName");
8888 if (val == NULL)
8889 val = get_param(cmd, "Type");
8890 if (val == NULL)
8891 return -1;
8892 if (strcasecmp(val, "disassoc") == 0)
8893 frame = DISASSOC;
8894 else if (strcasecmp(val, "deauth") == 0)
8895 frame = DEAUTH;
8896 else if (strcasecmp(val, "saquery") == 0)
8897 frame = SAQUERY;
8898 else if (strcasecmp(val, "auth") == 0)
8899 frame = AUTH;
8900 else if (strcasecmp(val, "assocreq") == 0)
8901 frame = ASSOCREQ;
8902 else if (strcasecmp(val, "reassocreq") == 0)
8903 frame = REASSOCREQ;
8904 else if (strcasecmp(val, "neigreq") == 0) {
8905 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
8906
8907 val = get_param(cmd, "ssid");
8908 if (val == NULL)
8909 return -1;
8910
8911 res = send_neighbor_request(dut, intf, val);
8912 if (res) {
8913 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8914 "Failed to send neighbor report request");
8915 return 0;
8916 }
8917
8918 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308919 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
8920 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008921 sigma_dut_print(dut, DUT_MSG_DEBUG,
8922 "Got Transition Management Query");
8923
Ashwini Patil5acd7382017-04-13 15:55:04 +05308924 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008925 if (res) {
8926 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8927 "Failed to send Transition Management Query");
8928 return 0;
8929 }
8930
8931 return 1;
8932 } else {
8933 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8934 "PMFFrameType");
8935 return 0;
8936 }
8937
8938 val = get_param(cmd, "PMFProtected");
8939 if (val == NULL)
8940 val = get_param(cmd, "Protected");
8941 if (val == NULL)
8942 return -1;
8943 if (strcasecmp(val, "Correct-key") == 0 ||
8944 strcasecmp(val, "CorrectKey") == 0)
8945 protected = CORRECT_KEY;
8946 else if (strcasecmp(val, "IncorrectKey") == 0)
8947 protected = INCORRECT_KEY;
8948 else if (strcasecmp(val, "Unprotected") == 0)
8949 protected = UNPROTECTED;
8950 else {
8951 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8952 "PMFProtected");
8953 return 0;
8954 }
8955
8956 if (protected != UNPROTECTED &&
8957 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
8958 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
8959 "PMFProtected for auth/assocreq/reassocreq");
8960 return 0;
8961 }
8962
8963 if (if_nametoindex("sigmadut") == 0) {
8964 snprintf(buf, sizeof(buf),
8965 "iw dev %s interface add sigmadut type monitor",
8966 get_station_ifname());
8967 if (system(buf) != 0 ||
8968 if_nametoindex("sigmadut") == 0) {
8969 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8970 "monitor interface with '%s'", buf);
8971 return -2;
8972 }
8973 }
8974
8975 if (system("ifconfig sigmadut up") != 0) {
8976 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8977 "monitor interface up");
8978 return -2;
8979 }
8980
8981 return sta_inject_frame(dut, conn, frame, protected, NULL);
8982}
8983
8984
8985static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
8986 struct sigma_conn *conn,
8987 struct sigma_cmd *cmd,
8988 const char *ifname)
8989{
8990 char buf[200];
8991 const char *val;
8992
8993 val = get_param(cmd, "ClearARP");
8994 if (val && atoi(val) == 1) {
8995 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
8996 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8997 if (system(buf) != 0) {
8998 send_resp(dut, conn, SIGMA_ERROR,
8999 "errorCode,Failed to clear ARP cache");
9000 return 0;
9001 }
9002 }
9003
9004 return 1;
9005}
9006
9007
9008int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9009 struct sigma_cmd *cmd)
9010{
9011 const char *intf = get_param(cmd, "Interface");
9012 const char *val;
9013
9014 if (intf == NULL)
9015 return -1;
9016
9017 val = get_param(cmd, "program");
9018 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009019 strcasecmp(val, "HS2-R2") == 0 ||
9020 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009021 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9022
9023 return -1;
9024}
9025
9026
9027static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9028 struct sigma_cmd *cmd)
9029{
9030 const char *intf = get_param(cmd, "Interface");
9031 const char *mac = get_param(cmd, "MAC");
9032
9033 if (intf == NULL || mac == NULL)
9034 return -1;
9035
9036 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9037 "interface %s to %s", intf, mac);
9038
9039 if (dut->set_macaddr) {
9040 char buf[128];
9041 int res;
9042 if (strcasecmp(mac, "default") == 0) {
9043 res = snprintf(buf, sizeof(buf), "%s",
9044 dut->set_macaddr);
9045 dut->tmp_mac_addr = 0;
9046 } else {
9047 res = snprintf(buf, sizeof(buf), "%s %s",
9048 dut->set_macaddr, mac);
9049 dut->tmp_mac_addr = 1;
9050 }
9051 if (res < 0 || res >= (int) sizeof(buf))
9052 return -1;
9053 if (system(buf) != 0) {
9054 send_resp(dut, conn, SIGMA_ERROR,
9055 "errorCode,Failed to set MAC "
9056 "address");
9057 return 0;
9058 }
9059 return 1;
9060 }
9061
9062 if (strcasecmp(mac, "default") == 0)
9063 return 1;
9064
9065 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9066 "command");
9067 return 0;
9068}
9069
9070
9071static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9072 struct sigma_conn *conn, const char *intf,
9073 int val)
9074{
9075 char buf[200];
9076 int res;
9077
9078 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9079 intf, val);
9080 if (res < 0 || res >= (int) sizeof(buf))
9081 return -1;
9082 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9083 if (system(buf) != 0) {
9084 send_resp(dut, conn, SIGMA_ERROR,
9085 "errorCode,Failed to configure offchannel mode");
9086 return 0;
9087 }
9088
9089 return 1;
9090}
9091
9092
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009093static int off_chan_val(enum sec_ch_offset off)
9094{
9095 switch (off) {
9096 case SEC_CH_NO:
9097 return 0;
9098 case SEC_CH_40ABOVE:
9099 return 40;
9100 case SEC_CH_40BELOW:
9101 return -40;
9102 }
9103
9104 return 0;
9105}
9106
9107
9108static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9109 const char *intf, int off_ch_num,
9110 enum sec_ch_offset sec)
9111{
9112 char buf[200];
9113 int res;
9114
9115 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9116 intf, off_ch_num);
9117 if (res < 0 || res >= (int) sizeof(buf))
9118 return -1;
9119 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9120 if (system(buf) != 0) {
9121 send_resp(dut, conn, SIGMA_ERROR,
9122 "errorCode,Failed to set offchan");
9123 return 0;
9124 }
9125
9126 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9127 intf, off_chan_val(sec));
9128 if (res < 0 || res >= (int) sizeof(buf))
9129 return -1;
9130 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9131 if (system(buf) != 0) {
9132 send_resp(dut, conn, SIGMA_ERROR,
9133 "errorCode,Failed to set sec chan offset");
9134 return 0;
9135 }
9136
9137 return 1;
9138}
9139
9140
9141static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9142 struct sigma_conn *conn,
9143 const char *intf, int off_ch_num,
9144 enum sec_ch_offset sec)
9145{
9146 char buf[200];
9147 int res;
9148
9149 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9150 off_ch_num);
9151 if (res < 0 || res >= (int) sizeof(buf))
9152 return -1;
9153 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9154
9155 if (wpa_command(intf, buf) < 0) {
9156 send_resp(dut, conn, SIGMA_ERROR,
9157 "ErrorCode,Failed to set offchan");
9158 return 0;
9159 }
9160 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9161 off_chan_val(sec));
9162 if (res < 0 || res >= (int) sizeof(buf))
9163 return -1;
9164
9165 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9166
9167 if (wpa_command(intf, buf) < 0) {
9168 send_resp(dut, conn, SIGMA_ERROR,
9169 "ErrorCode,Failed to set sec chan offset");
9170 return 0;
9171 }
9172
9173 return 1;
9174}
9175
9176
9177static int tdls_set_offchannel_mode(struct sigma_dut *dut,
9178 struct sigma_conn *conn,
9179 const char *intf, int val)
9180{
9181 char buf[200];
9182 int res;
9183
9184 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
9185 val);
9186 if (res < 0 || res >= (int) sizeof(buf))
9187 return -1;
9188 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9189
9190 if (wpa_command(intf, buf) < 0) {
9191 send_resp(dut, conn, SIGMA_ERROR,
9192 "ErrorCode,Failed to configure offchannel mode");
9193 return 0;
9194 }
9195
9196 return 1;
9197}
9198
9199
9200static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
9201 struct sigma_conn *conn,
9202 struct sigma_cmd *cmd)
9203{
9204 const char *val;
9205 enum {
9206 CHSM_NOT_SET,
9207 CHSM_ENABLE,
9208 CHSM_DISABLE,
9209 CHSM_REJREQ,
9210 CHSM_UNSOLRESP
9211 } chsm = CHSM_NOT_SET;
9212 int off_ch_num = -1;
9213 enum sec_ch_offset sec_ch = SEC_CH_NO;
9214 int res;
9215
9216 val = get_param(cmd, "Uapsd");
9217 if (val) {
9218 char buf[100];
9219 if (strcasecmp(val, "Enable") == 0)
9220 snprintf(buf, sizeof(buf), "SET ps 99");
9221 else if (strcasecmp(val, "Disable") == 0)
9222 snprintf(buf, sizeof(buf), "SET ps 98");
9223 else {
9224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9225 "Unsupported uapsd parameter value");
9226 return 0;
9227 }
9228 if (wpa_command(intf, buf)) {
9229 send_resp(dut, conn, SIGMA_ERROR,
9230 "ErrorCode,Failed to change U-APSD "
9231 "powersave mode");
9232 return 0;
9233 }
9234 }
9235
9236 val = get_param(cmd, "TPKTIMER");
9237 if (val && strcasecmp(val, "DISABLE") == 0) {
9238 if (wpa_command(intf, "SET tdls_testing 0x100")) {
9239 send_resp(dut, conn, SIGMA_ERROR,
9240 "ErrorCode,Failed to enable no TPK "
9241 "expiration test mode");
9242 return 0;
9243 }
9244 dut->no_tpk_expiration = 1;
9245 }
9246
9247 val = get_param(cmd, "ChSwitchMode");
9248 if (val) {
9249 if (strcasecmp(val, "Enable") == 0 ||
9250 strcasecmp(val, "Initiate") == 0)
9251 chsm = CHSM_ENABLE;
9252 else if (strcasecmp(val, "Disable") == 0 ||
9253 strcasecmp(val, "passive") == 0)
9254 chsm = CHSM_DISABLE;
9255 else if (strcasecmp(val, "RejReq") == 0)
9256 chsm = CHSM_REJREQ;
9257 else if (strcasecmp(val, "UnSolResp") == 0)
9258 chsm = CHSM_UNSOLRESP;
9259 else {
9260 send_resp(dut, conn, SIGMA_ERROR,
9261 "ErrorCode,Unknown ChSwitchMode value");
9262 return 0;
9263 }
9264 }
9265
9266 val = get_param(cmd, "OffChNum");
9267 if (val) {
9268 off_ch_num = atoi(val);
9269 if (off_ch_num == 0) {
9270 send_resp(dut, conn, SIGMA_ERROR,
9271 "ErrorCode,Invalid OffChNum");
9272 return 0;
9273 }
9274 }
9275
9276 val = get_param(cmd, "SecChOffset");
9277 if (val) {
9278 if (strcmp(val, "20") == 0)
9279 sec_ch = SEC_CH_NO;
9280 else if (strcasecmp(val, "40above") == 0)
9281 sec_ch = SEC_CH_40ABOVE;
9282 else if (strcasecmp(val, "40below") == 0)
9283 sec_ch = SEC_CH_40BELOW;
9284 else {
9285 send_resp(dut, conn, SIGMA_ERROR,
9286 "ErrorCode,Unknown SecChOffset value");
9287 return 0;
9288 }
9289 }
9290
9291 if (chsm == CHSM_NOT_SET) {
9292 /* no offchannel changes requested */
9293 return 1;
9294 }
9295
9296 if (strcmp(intf, get_main_ifname()) != 0 &&
9297 strcmp(intf, get_station_ifname()) != 0) {
9298 send_resp(dut, conn, SIGMA_ERROR,
9299 "ErrorCode,Unknown interface");
9300 return 0;
9301 }
9302
9303 switch (chsm) {
9304 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03009305 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009306 break;
9307 case CHSM_ENABLE:
9308 if (off_ch_num < 0) {
9309 send_resp(dut, conn, SIGMA_ERROR,
9310 "ErrorCode,Missing OffChNum argument");
9311 return 0;
9312 }
9313 if (wifi_chip_type == DRIVER_WCN) {
9314 res = tdls_set_offchannel_offset(dut, conn, intf,
9315 off_ch_num, sec_ch);
9316 } else {
9317 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9318 sec_ch);
9319 }
9320 if (res != 1)
9321 return res;
9322 if (wifi_chip_type == DRIVER_WCN)
9323 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
9324 else
9325 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
9326 break;
9327 case CHSM_DISABLE:
9328 if (wifi_chip_type == DRIVER_WCN)
9329 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
9330 else
9331 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
9332 break;
9333 case CHSM_REJREQ:
9334 if (wifi_chip_type == DRIVER_WCN)
9335 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
9336 else
9337 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
9338 break;
9339 case CHSM_UNSOLRESP:
9340 if (off_ch_num < 0) {
9341 send_resp(dut, conn, SIGMA_ERROR,
9342 "ErrorCode,Missing OffChNum argument");
9343 return 0;
9344 }
9345 if (wifi_chip_type == DRIVER_WCN) {
9346 res = tdls_set_offchannel_offset(dut, conn, intf,
9347 off_ch_num, sec_ch);
9348 } else {
9349 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9350 sec_ch);
9351 }
9352 if (res != 1)
9353 return res;
9354 if (wifi_chip_type == DRIVER_WCN)
9355 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
9356 else
9357 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
9358 break;
9359 }
9360
9361 return res;
9362}
9363
9364
9365static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9366 struct sigma_conn *conn,
9367 struct sigma_cmd *cmd)
9368{
9369 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309370 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009371
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009372 novap_reset(dut, intf);
9373
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009374 val = get_param(cmd, "nss_mcs_opt");
9375 if (val) {
9376 /* String (nss_operating_mode; mcs_operating_mode) */
9377 int nss, mcs;
9378 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309379 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009380
9381 token = strdup(val);
9382 if (!token)
9383 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309384 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309385 if (!result) {
9386 sigma_dut_print(dut, DUT_MSG_ERROR,
9387 "VHT NSS not specified");
9388 goto failed;
9389 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009390 if (strcasecmp(result, "def") != 0) {
9391 nss = atoi(result);
9392 if (nss == 4)
9393 ath_disable_txbf(dut, intf);
9394 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
9395 intf, nss);
9396 if (system(buf) != 0) {
9397 sigma_dut_print(dut, DUT_MSG_ERROR,
9398 "iwpriv nss failed");
9399 goto failed;
9400 }
9401 }
9402
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309403 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309404 if (!result) {
9405 sigma_dut_print(dut, DUT_MSG_ERROR,
9406 "VHT MCS not specified");
9407 goto failed;
9408 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009409 if (strcasecmp(result, "def") == 0) {
9410 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
9411 intf);
9412 if (system(buf) != 0) {
9413 sigma_dut_print(dut, DUT_MSG_ERROR,
9414 "iwpriv set11NRates failed");
9415 goto failed;
9416 }
9417
9418 } else {
9419 mcs = atoi(result);
9420 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
9421 intf, mcs);
9422 if (system(buf) != 0) {
9423 sigma_dut_print(dut, DUT_MSG_ERROR,
9424 "iwpriv vhtmcs failed");
9425 goto failed;
9426 }
9427 }
9428 /* Channel width gets messed up, fix this */
9429 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9430 intf, dut->chwidth);
9431 if (system(buf) != 0) {
9432 sigma_dut_print(dut, DUT_MSG_ERROR,
9433 "iwpriv chwidth failed");
9434 }
9435 }
9436
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309437 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009438 return 1;
9439failed:
9440 free(token);
9441 return 0;
9442}
9443
9444
9445static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9446 struct sigma_conn *conn,
9447 struct sigma_cmd *cmd)
9448{
9449 switch (get_driver_type()) {
9450 case DRIVER_ATHEROS:
9451 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
9452 default:
9453 send_resp(dut, conn, SIGMA_ERROR,
9454 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
9455 return 0;
9456 }
9457}
9458
9459
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009460static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9461 struct sigma_conn *conn,
9462 struct sigma_cmd *cmd)
9463{
9464 const char *val;
9465 char *token = NULL, *result;
9466 char buf[60];
9467
9468 val = get_param(cmd, "nss_mcs_opt");
9469 if (val) {
9470 /* String (nss_operating_mode; mcs_operating_mode) */
9471 int nss, mcs, ratecode;
9472 char *saveptr;
9473
9474 token = strdup(val);
9475 if (!token)
9476 return -2;
9477
9478 result = strtok_r(token, ";", &saveptr);
9479 if (!result) {
9480 sigma_dut_print(dut, DUT_MSG_ERROR,
9481 "HE NSS not specified");
9482 goto failed;
9483 }
9484 nss = 1;
9485 if (strcasecmp(result, "def") != 0)
9486 nss = atoi(result);
9487
9488 result = strtok_r(NULL, ";", &saveptr);
9489 if (!result) {
9490 sigma_dut_print(dut, DUT_MSG_ERROR,
9491 "HE MCS not specified");
9492 goto failed;
9493 }
9494 mcs = 7;
9495 if (strcasecmp(result, "def") != 0)
9496 mcs = atoi(result);
9497
Arif Hussain557bf412018-05-25 17:29:36 -07009498 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009499 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -07009500 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009501 } else if (nss > 2) {
9502 sigma_dut_print(dut, DUT_MSG_ERROR,
9503 "HE NSS %d not supported", nss);
9504 goto failed;
9505 }
9506
Arif Hussain557bf412018-05-25 17:29:36 -07009507 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
9508 if (system(buf) != 0) {
9509 sigma_dut_print(dut, DUT_MSG_ERROR,
9510 "nss_mcs_opt: iwpriv %s nss %d failed",
9511 intf, nss);
9512 goto failed;
9513 }
Arif Hussainac6c5112018-05-25 17:34:00 -07009514 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -07009515
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009516 /* Add the MCS to the ratecode */
9517 if (mcs >= 0 && mcs <= 11) {
9518 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -07009519#ifdef NL80211_SUPPORT
9520 if (dut->device_type == STA_testbed) {
9521 enum he_mcs_config mcs_config;
9522 int ret;
9523
9524 if (mcs <= 7)
9525 mcs_config = HE_80_MCS0_7;
9526 else if (mcs <= 9)
9527 mcs_config = HE_80_MCS0_9;
9528 else
9529 mcs_config = HE_80_MCS0_11;
9530 ret = sta_set_he_mcs(dut, intf, mcs_config);
9531 if (ret) {
9532 sigma_dut_print(dut, DUT_MSG_ERROR,
9533 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9534 mcs, mcs_config, ret);
9535 goto failed;
9536 }
9537 }
9538#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009539 } else {
9540 sigma_dut_print(dut, DUT_MSG_ERROR,
9541 "HE MCS %d not supported", mcs);
9542 goto failed;
9543 }
9544 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
9545 intf, ratecode);
9546 if (system(buf) != 0) {
9547 sigma_dut_print(dut, DUT_MSG_ERROR,
9548 "iwpriv setting of 11ax rates failed");
9549 goto failed;
9550 }
9551 free(token);
9552 }
9553
9554 val = get_param(cmd, "GI");
9555 if (val) {
9556 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009557 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009558 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009559 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
9560 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009561 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009562 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
9563 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009564 } else {
9565 send_resp(dut, conn, SIGMA_ERROR,
9566 "errorCode,GI value not supported");
9567 return 0;
9568 }
9569 if (system(buf) != 0) {
9570 send_resp(dut, conn, SIGMA_ERROR,
9571 "errorCode,Failed to set shortgi");
9572 return 0;
9573 }
9574 }
9575
Subhani Shaik8e7a3052018-04-24 14:03:00 -07009576 val = get_param(cmd, "LTF");
9577 if (val) {
9578#ifdef NL80211_SUPPORT
9579 if (strcmp(val, "3.2") == 0) {
9580 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
9581 } if (strcmp(val, "6.4") == 0) {
9582 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
9583 } else if (strcmp(val, "12.8") == 0) {
9584 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
9585 } else {
9586 send_resp(dut, conn, SIGMA_ERROR,
9587 "errorCode, LTF value not supported");
9588 return 0;
9589 }
9590#else /* NL80211_SUPPORT */
9591 sigma_dut_print(dut, DUT_MSG_ERROR,
9592 "LTF cannot be set without NL80211_SUPPORT defined");
9593 return -2;
9594#endif /* NL80211_SUPPORT */
9595 }
9596
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009597 return 1;
9598
9599failed:
9600 free(token);
9601 return -2;
9602}
9603
9604
9605static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9606 struct sigma_conn *conn,
9607 struct sigma_cmd *cmd)
9608{
9609 switch (get_driver_type()) {
9610 case DRIVER_WCN:
9611 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
9612 default:
9613 send_resp(dut, conn, SIGMA_ERROR,
9614 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
9615 return 0;
9616 }
9617}
9618
9619
Ashwini Patil5acd7382017-04-13 15:55:04 +05309620static int btm_query_candidate_list(struct sigma_dut *dut,
9621 struct sigma_conn *conn,
9622 struct sigma_cmd *cmd)
9623{
9624 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
9625 int len, ret;
9626 char buf[10];
9627
9628 /*
9629 * Neighbor Report elements format:
9630 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
9631 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
9632 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
9633 */
9634
9635 bssid = get_param(cmd, "Nebor_BSSID");
9636 if (!bssid) {
9637 send_resp(dut, conn, SIGMA_INVALID,
9638 "errorCode,Nebor_BSSID is missing");
9639 return 0;
9640 }
9641
9642 info = get_param(cmd, "Nebor_Bssid_Info");
9643 if (!info) {
9644 sigma_dut_print(dut, DUT_MSG_INFO,
9645 "Using default value for Nebor_Bssid_Info: %s",
9646 DEFAULT_NEIGHBOR_BSSID_INFO);
9647 info = DEFAULT_NEIGHBOR_BSSID_INFO;
9648 }
9649
9650 op_class = get_param(cmd, "Nebor_Op_Class");
9651 if (!op_class) {
9652 send_resp(dut, conn, SIGMA_INVALID,
9653 "errorCode,Nebor_Op_Class is missing");
9654 return 0;
9655 }
9656
9657 ch = get_param(cmd, "Nebor_Op_Ch");
9658 if (!ch) {
9659 send_resp(dut, conn, SIGMA_INVALID,
9660 "errorCode,Nebor_Op_Ch is missing");
9661 return 0;
9662 }
9663
9664 phy_type = get_param(cmd, "Nebor_Phy_Type");
9665 if (!phy_type) {
9666 sigma_dut_print(dut, DUT_MSG_INFO,
9667 "Using default value for Nebor_Phy_Type: %s",
9668 DEFAULT_NEIGHBOR_PHY_TYPE);
9669 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
9670 }
9671
9672 /* Parse optional subelements */
9673 buf[0] = '\0';
9674 pref = get_param(cmd, "Nebor_Pref");
9675 if (pref) {
9676 /* hexdump for preferrence subelement */
9677 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
9678 if (ret < 0 || ret >= (int) sizeof(buf)) {
9679 sigma_dut_print(dut, DUT_MSG_ERROR,
9680 "snprintf failed for optional subelement ret: %d",
9681 ret);
9682 send_resp(dut, conn, SIGMA_ERROR,
9683 "errorCode,snprintf failed for subelement");
9684 return 0;
9685 }
9686 }
9687
9688 if (!dut->btm_query_cand_list) {
9689 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
9690 if (!dut->btm_query_cand_list) {
9691 send_resp(dut, conn, SIGMA_ERROR,
9692 "errorCode,Failed to allocate memory for btm_query_cand_list");
9693 return 0;
9694 }
9695 }
9696
9697 len = strlen(dut->btm_query_cand_list);
9698 ret = snprintf(dut->btm_query_cand_list + len,
9699 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
9700 bssid, info, op_class, ch, phy_type, buf);
9701 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
9702 sigma_dut_print(dut, DUT_MSG_ERROR,
9703 "snprintf failed for neighbor report list ret: %d",
9704 ret);
9705 send_resp(dut, conn, SIGMA_ERROR,
9706 "errorCode,snprintf failed for neighbor report");
9707 free(dut->btm_query_cand_list);
9708 dut->btm_query_cand_list = NULL;
9709 return 0;
9710 }
9711
9712 return 1;
9713}
9714
9715
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009716static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
9717 struct sigma_cmd *cmd)
9718{
9719 const char *intf = get_param(cmd, "Interface");
9720 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309721 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009722
9723 if (intf == NULL || prog == NULL)
9724 return -1;
9725
Ashwini Patil5acd7382017-04-13 15:55:04 +05309726 /* BSS Transition candidate list for BTM query */
9727 val = get_param(cmd, "Nebor_BSSID");
9728 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
9729 return 0;
9730
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009731 if (strcasecmp(prog, "TDLS") == 0)
9732 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
9733
9734 if (strcasecmp(prog, "VHT") == 0)
9735 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
9736
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009737 if (strcasecmp(prog, "HE") == 0)
9738 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
9739
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309740 if (strcasecmp(prog, "MBO") == 0) {
9741 val = get_param(cmd, "Cellular_Data_Cap");
9742 if (val &&
9743 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
9744 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05309745
9746 val = get_param(cmd, "Ch_Pref");
9747 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
9748 return 0;
9749
Ashwini Patil68d02cd2017-01-10 15:39:16 +05309750 return 1;
9751 }
9752
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
9754 return 0;
9755}
9756
9757
9758static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
9759 struct sigma_cmd *cmd)
9760{
9761 const char *intf = get_param(cmd, "Interface");
9762 const char *mode = get_param(cmd, "Mode");
9763 int res;
9764
9765 if (intf == NULL || mode == NULL)
9766 return -1;
9767
9768 if (strcasecmp(mode, "On") == 0)
9769 res = wpa_command(intf, "SET radio_disabled 0");
9770 else if (strcasecmp(mode, "Off") == 0)
9771 res = wpa_command(intf, "SET radio_disabled 1");
9772 else
9773 return -1;
9774
9775 if (res) {
9776 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
9777 "radio mode");
9778 return 0;
9779 }
9780
9781 return 1;
9782}
9783
9784
9785static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
9786 struct sigma_cmd *cmd)
9787{
9788 const char *intf = get_param(cmd, "Interface");
9789 const char *mode = get_param(cmd, "Mode");
9790 int res;
9791
9792 if (intf == NULL || mode == NULL)
9793 return -1;
9794
9795 if (strcasecmp(mode, "On") == 0)
9796 res = set_ps(intf, dut, 1);
9797 else if (strcasecmp(mode, "Off") == 0)
9798 res = set_ps(intf, dut, 0);
9799 else
9800 return -1;
9801
9802 if (res) {
9803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
9804 "power save mode");
9805 return 0;
9806 }
9807
9808 return 1;
9809}
9810
9811
9812static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
9813 struct sigma_cmd *cmd)
9814{
9815 const char *intf = get_param(cmd, "Interface");
9816 const char *val, *bssid;
9817 int res;
9818 char *buf;
9819 size_t buf_len;
9820
9821 val = get_param(cmd, "BSSID_FILTER");
9822 if (val == NULL)
9823 return -1;
9824
9825 bssid = get_param(cmd, "BSSID_List");
9826 if (atoi(val) == 0 || bssid == NULL) {
9827 /* Disable BSSID filter */
9828 if (wpa_command(intf, "SET bssid_filter ")) {
9829 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
9830 "to disable BSSID filter");
9831 return 0;
9832 }
9833
9834 return 1;
9835 }
9836
9837 buf_len = 100 + strlen(bssid);
9838 buf = malloc(buf_len);
9839 if (buf == NULL)
9840 return -1;
9841
9842 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
9843 res = wpa_command(intf, buf);
9844 free(buf);
9845 if (res) {
9846 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
9847 "BSSID filter");
9848 return 0;
9849 }
9850
9851 return 1;
9852}
9853
9854
9855static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
9856 struct sigma_cmd *cmd)
9857{
9858 const char *intf = get_param(cmd, "Interface");
9859 const char *val;
9860
9861 /* TODO: ARP */
9862
9863 val = get_param(cmd, "HS2_CACHE_PROFILE");
9864 if (val && strcasecmp(val, "All") == 0)
9865 hs2_clear_credentials(intf);
9866
9867 return 1;
9868}
9869
9870
9871static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
9872 struct sigma_cmd *cmd)
9873{
9874 const char *intf = get_param(cmd, "Interface");
9875 const char *key_type = get_param(cmd, "KeyType");
9876 char buf[100], resp[200];
9877
9878 if (key_type == NULL)
9879 return -1;
9880
9881 if (strcasecmp(key_type, "GTK") == 0) {
9882 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
9883 strncmp(buf, "FAIL", 4) == 0) {
9884 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9885 "not fetch current GTK");
9886 return 0;
9887 }
9888 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
9889 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9890 return 0;
9891 } else {
9892 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9893 "KeyType");
9894 return 0;
9895 }
9896
9897 return 1;
9898}
9899
9900
9901static int hs2_set_policy(struct sigma_dut *dut)
9902{
9903#ifdef ANDROID
9904 system("ip rule del prio 23000");
9905 if (system("ip rule add from all lookup main prio 23000") != 0) {
9906 sigma_dut_print(dut, DUT_MSG_ERROR,
9907 "Failed to run:ip rule add from all lookup main prio");
9908 return -1;
9909 }
9910 if (system("ip route flush cache") != 0) {
9911 sigma_dut_print(dut, DUT_MSG_ERROR,
9912 "Failed to run ip route flush cache");
9913 return -1;
9914 }
9915 return 1;
9916#else /* ANDROID */
9917 return 0;
9918#endif /* ANDROID */
9919}
9920
9921
9922static int cmd_sta_hs2_associate(struct sigma_dut *dut,
9923 struct sigma_conn *conn,
9924 struct sigma_cmd *cmd)
9925{
9926 const char *intf = get_param(cmd, "Interface");
9927 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +03009928 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009929 struct wpa_ctrl *ctrl;
9930 int res;
9931 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
9932 int tries = 0;
9933 int ignore_blacklist = 0;
9934 const char *events[] = {
9935 "CTRL-EVENT-CONNECTED",
9936 "INTERWORKING-BLACKLISTED",
9937 "INTERWORKING-NO-MATCH",
9938 NULL
9939 };
9940
9941 start_sta_mode(dut);
9942
Jouni Malinen439352d2018-09-13 03:42:23 +03009943 if (band) {
9944 if (strcmp(band, "2.4") == 0) {
9945 wpa_command(intf, "SET setband 2G");
9946 } else if (strcmp(band, "5") == 0) {
9947 wpa_command(intf, "SET setband 5G");
9948 } else {
9949 send_resp(dut, conn, SIGMA_ERROR,
9950 "errorCode,Unsupported band");
9951 return 0;
9952 }
9953 }
9954
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009955 blacklisted[0] = '\0';
9956 if (val && atoi(val))
9957 ignore_blacklist = 1;
9958
9959try_again:
9960 ctrl = open_wpa_mon(intf);
9961 if (ctrl == NULL) {
9962 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9963 "wpa_supplicant monitor connection");
9964 return -2;
9965 }
9966
9967 tries++;
9968 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
9969 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
9970 "Interworking connection");
9971 wpa_ctrl_detach(ctrl);
9972 wpa_ctrl_close(ctrl);
9973 return 0;
9974 }
9975
9976 buf[0] = '\0';
9977 while (1) {
9978 char *pos;
9979 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9980 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
9981 if (!pos)
9982 break;
9983 pos += 25;
9984 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
9985 pos);
9986 if (!blacklisted[0])
9987 memcpy(blacklisted, pos, strlen(pos) + 1);
9988 }
9989
9990 if (ignore_blacklist && blacklisted[0]) {
9991 char *end;
9992 end = strchr(blacklisted, ' ');
9993 if (end)
9994 *end = '\0';
9995 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
9996 blacklisted);
9997 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
9998 blacklisted);
9999 if (wpa_command(intf, buf)) {
10000 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
10001 wpa_ctrl_detach(ctrl);
10002 wpa_ctrl_close(ctrl);
10003 return 0;
10004 }
10005 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10006 buf, sizeof(buf));
10007 }
10008
10009 wpa_ctrl_detach(ctrl);
10010 wpa_ctrl_close(ctrl);
10011
10012 if (res < 0) {
10013 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10014 "connect");
10015 return 0;
10016 }
10017
10018 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
10019 strstr(buf, "INTERWORKING-BLACKLISTED")) {
10020 if (tries < 2) {
10021 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
10022 goto try_again;
10023 }
10024 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
10025 "matching credentials found");
10026 return 0;
10027 }
10028
10029 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10030 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10031 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10032 "get current BSSID/SSID");
10033 return 0;
10034 }
10035
10036 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
10037 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10038 hs2_set_policy(dut);
10039 return 0;
10040}
10041
10042
Jouni Malinenb639f1c2018-09-13 02:39:46 +030010043static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
10044 struct sigma_conn *conn,
10045 struct sigma_cmd *cmd)
10046{
10047 const char *intf = get_param(cmd, "Interface");
10048 const char *display = get_param(cmd, "Display");
10049 struct wpa_ctrl *ctrl;
10050 char buf[300], params[400], *pos;
10051 char bssid[20];
10052 int info_avail = 0;
10053 unsigned int old_timeout;
10054 int res;
10055
10056 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
10057 send_resp(dut, conn, SIGMA_ERROR,
10058 "ErrorCode,Could not get current BSSID");
10059 return 0;
10060 }
10061 ctrl = open_wpa_mon(intf);
10062 if (!ctrl) {
10063 sigma_dut_print(dut, DUT_MSG_ERROR,
10064 "Failed to open wpa_supplicant monitor connection");
10065 return -2;
10066 }
10067
10068 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
10069 wpa_command(intf, buf);
10070
10071 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
10072 if (res < 0) {
10073 send_resp(dut, conn, SIGMA_ERROR,
10074 "ErrorCode,Could not complete GAS query");
10075 goto fail;
10076 }
10077
10078 old_timeout = dut->default_timeout;
10079 dut->default_timeout = 2;
10080 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
10081 dut->default_timeout = old_timeout;
10082 if (res < 0)
10083 goto done;
10084 pos = strchr(buf, ' ');
10085 if (!pos)
10086 goto done;
10087 pos++;
10088 pos = strchr(pos, ' ');
10089 if (!pos)
10090 goto done;
10091 pos++;
10092 info_avail = 1;
10093 snprintf(params, sizeof(params), "browser %s", pos);
10094
10095 if (display && strcasecmp(display, "Yes") == 0) {
10096 pid_t pid;
10097
10098 pid = fork();
10099 if (pid < 0) {
10100 perror("fork");
10101 return -1;
10102 }
10103
10104 if (pid == 0) {
10105 run_hs20_osu(dut, params);
10106 exit(0);
10107 }
10108 }
10109
10110done:
10111 snprintf(buf, sizeof(buf), "Info_available,%s",
10112 info_avail ? "Yes" : "No");
10113 send_resp(dut, conn, SIGMA_COMPLETE, buf);
10114fail:
10115 wpa_ctrl_detach(ctrl);
10116 wpa_ctrl_close(ctrl);
10117 return 0;
10118}
10119
10120
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010121static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
10122 struct sigma_conn *conn,
10123 const char *ifname,
10124 struct sigma_cmd *cmd)
10125{
10126 const char *val;
10127 int id;
10128
10129 id = add_cred(ifname);
10130 if (id < 0)
10131 return -2;
10132 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10133
10134 val = get_param(cmd, "prefer");
10135 if (val && atoi(val) > 0)
10136 set_cred(ifname, id, "priority", "1");
10137
10138 val = get_param(cmd, "REALM");
10139 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10140 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10141 "realm");
10142 return 0;
10143 }
10144
10145 val = get_param(cmd, "HOME_FQDN");
10146 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10147 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10148 "home_fqdn");
10149 return 0;
10150 }
10151
10152 val = get_param(cmd, "Username");
10153 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10154 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10155 "username");
10156 return 0;
10157 }
10158
10159 val = get_param(cmd, "Password");
10160 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
10161 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10162 "password");
10163 return 0;
10164 }
10165
10166 val = get_param(cmd, "ROOT_CA");
10167 if (val) {
10168 char fname[200];
10169 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10170#ifdef __linux__
10171 if (!file_exists(fname)) {
10172 char msg[300];
10173 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10174 "file (%s) not found", fname);
10175 send_resp(dut, conn, SIGMA_ERROR, msg);
10176 return 0;
10177 }
10178#endif /* __linux__ */
10179 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10180 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10181 "not set root CA");
10182 return 0;
10183 }
10184 }
10185
10186 return 1;
10187}
10188
10189
10190static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
10191{
10192 FILE *in, *out;
10193 char buf[500];
10194 int found = 0;
10195
10196 in = fopen("devdetail.xml", "r");
10197 if (in == NULL)
10198 return -1;
10199 out = fopen("devdetail.xml.tmp", "w");
10200 if (out == NULL) {
10201 fclose(in);
10202 return -1;
10203 }
10204
10205 while (fgets(buf, sizeof(buf), in)) {
10206 char *pos = strstr(buf, "<IMSI>");
10207 if (pos) {
10208 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
10209 imsi);
10210 pos += 6;
10211 *pos = '\0';
10212 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
10213 found++;
10214 } else {
10215 fprintf(out, "%s", buf);
10216 }
10217 }
10218
10219 fclose(out);
10220 fclose(in);
10221 if (found)
10222 rename("devdetail.xml.tmp", "devdetail.xml");
10223 else
10224 unlink("devdetail.xml.tmp");
10225
10226 return 0;
10227}
10228
10229
10230static int sta_add_credential_sim(struct sigma_dut *dut,
10231 struct sigma_conn *conn,
10232 const char *ifname, struct sigma_cmd *cmd)
10233{
10234 const char *val, *imsi = NULL;
10235 int id;
10236 char buf[200];
10237 int res;
10238 const char *pos;
10239 size_t mnc_len;
10240 char plmn_mcc[4];
10241 char plmn_mnc[4];
10242
10243 id = add_cred(ifname);
10244 if (id < 0)
10245 return -2;
10246 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10247
10248 val = get_param(cmd, "prefer");
10249 if (val && atoi(val) > 0)
10250 set_cred(ifname, id, "priority", "1");
10251
10252 val = get_param(cmd, "PLMN_MCC");
10253 if (val == NULL) {
10254 send_resp(dut, conn, SIGMA_ERROR,
10255 "errorCode,Missing PLMN_MCC");
10256 return 0;
10257 }
10258 if (strlen(val) != 3) {
10259 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
10260 return 0;
10261 }
10262 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
10263
10264 val = get_param(cmd, "PLMN_MNC");
10265 if (val == NULL) {
10266 send_resp(dut, conn, SIGMA_ERROR,
10267 "errorCode,Missing PLMN_MNC");
10268 return 0;
10269 }
10270 if (strlen(val) != 2 && strlen(val) != 3) {
10271 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
10272 return 0;
10273 }
10274 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
10275
10276 val = get_param(cmd, "IMSI");
10277 if (val == NULL) {
10278 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
10279 "IMSI");
10280 return 0;
10281 }
10282
10283 imsi = pos = val;
10284
10285 if (strncmp(plmn_mcc, pos, 3) != 0) {
10286 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
10287 return 0;
10288 }
10289 pos += 3;
10290
10291 mnc_len = strlen(plmn_mnc);
10292 if (mnc_len < 2) {
10293 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
10294 return 0;
10295 }
10296
10297 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
10298 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
10299 return 0;
10300 }
10301 pos += mnc_len;
10302
10303 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
10304 if (res < 0 || res >= (int) sizeof(buf))
10305 return -1;
10306 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
10307 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10308 "not set IMSI");
10309 return 0;
10310 }
10311
10312 val = get_param(cmd, "Password");
10313 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
10314 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10315 "not set password");
10316 return 0;
10317 }
10318
Jouni Malinenba630452018-06-22 11:49:59 +030010319 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010320 /*
10321 * Set provisioning_sp for the test cases where SIM/USIM
10322 * provisioning is used.
10323 */
10324 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
10325 "wi-fi.org") < 0) {
10326 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10327 "not set provisioning_sp");
10328 return 0;
10329 }
10330
10331 update_devdetail_imsi(dut, imsi);
10332 }
10333
10334 return 1;
10335}
10336
10337
10338static int sta_add_credential_cert(struct sigma_dut *dut,
10339 struct sigma_conn *conn,
10340 const char *ifname,
10341 struct sigma_cmd *cmd)
10342{
10343 const char *val;
10344 int id;
10345
10346 id = add_cred(ifname);
10347 if (id < 0)
10348 return -2;
10349 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10350
10351 val = get_param(cmd, "prefer");
10352 if (val && atoi(val) > 0)
10353 set_cred(ifname, id, "priority", "1");
10354
10355 val = get_param(cmd, "REALM");
10356 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10357 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10358 "realm");
10359 return 0;
10360 }
10361
10362 val = get_param(cmd, "HOME_FQDN");
10363 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10364 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10365 "home_fqdn");
10366 return 0;
10367 }
10368
10369 val = get_param(cmd, "Username");
10370 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10371 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10372 "username");
10373 return 0;
10374 }
10375
10376 val = get_param(cmd, "clientCertificate");
10377 if (val) {
10378 char fname[200];
10379 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10380#ifdef __linux__
10381 if (!file_exists(fname)) {
10382 char msg[300];
10383 snprintf(msg, sizeof(msg),
10384 "ErrorCode,clientCertificate "
10385 "file (%s) not found", fname);
10386 send_resp(dut, conn, SIGMA_ERROR, msg);
10387 return 0;
10388 }
10389#endif /* __linux__ */
10390 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
10391 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10392 "not set client_cert");
10393 return 0;
10394 }
10395 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
10396 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10397 "not set private_key");
10398 return 0;
10399 }
10400 }
10401
10402 val = get_param(cmd, "ROOT_CA");
10403 if (val) {
10404 char fname[200];
10405 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10406#ifdef __linux__
10407 if (!file_exists(fname)) {
10408 char msg[300];
10409 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10410 "file (%s) not found", fname);
10411 send_resp(dut, conn, SIGMA_ERROR, msg);
10412 return 0;
10413 }
10414#endif /* __linux__ */
10415 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10416 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10417 "not set root CA");
10418 return 0;
10419 }
10420 }
10421
10422 return 1;
10423}
10424
10425
10426static int cmd_sta_add_credential(struct sigma_dut *dut,
10427 struct sigma_conn *conn,
10428 struct sigma_cmd *cmd)
10429{
10430 const char *intf = get_param(cmd, "Interface");
10431 const char *type;
10432
10433 start_sta_mode(dut);
10434
10435 type = get_param(cmd, "Type");
10436 if (!type)
10437 return -1;
10438
10439 if (strcasecmp(type, "uname_pwd") == 0)
10440 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
10441
10442 if (strcasecmp(type, "sim") == 0)
10443 return sta_add_credential_sim(dut, conn, intf, cmd);
10444
10445 if (strcasecmp(type, "cert") == 0)
10446 return sta_add_credential_cert(dut, conn, intf, cmd);
10447
10448 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
10449 "type");
10450 return 0;
10451}
10452
10453
10454static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
10455 struct sigma_cmd *cmd)
10456{
10457 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053010458 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010459 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053010460 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010461 int res;
10462
10463 val = get_param(cmd, "HESSID");
10464 if (val) {
10465 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
10466 if (res < 0 || res >= (int) sizeof(buf))
10467 return -1;
10468 wpa_command(intf, buf);
10469 }
10470
10471 val = get_param(cmd, "ACCS_NET_TYPE");
10472 if (val) {
10473 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
10474 val);
10475 if (res < 0 || res >= (int) sizeof(buf))
10476 return -1;
10477 wpa_command(intf, buf);
10478 }
10479
vamsi krishna89ad8c62017-09-19 12:51:18 +053010480 bssid = get_param(cmd, "Bssid");
10481 ssid = get_param(cmd, "Ssid");
10482
10483 if (ssid) {
10484 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
10485 send_resp(dut, conn, SIGMA_ERROR,
10486 "ErrorCode,Too long SSID");
10487 return 0;
10488 }
10489 ascii2hexstr(ssid, ssid_hex);
10490 }
10491
10492 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
10493 bssid ? " bssid=": "",
10494 bssid ? bssid : "",
10495 ssid ? " ssid " : "",
10496 ssid ? ssid_hex : "");
10497 if (res < 0 || res >= (int) sizeof(buf))
10498 return -1;
10499
10500 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010501 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
10502 "scan");
10503 return 0;
10504 }
10505
10506 return 1;
10507}
10508
10509
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020010510static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
10511 struct sigma_cmd *cmd)
10512{
10513 const char *intf = get_param(cmd, "Interface");
10514 const char *bssid;
10515 char buf[4096], *pos;
10516 int freq, chan;
10517 char *ssid;
10518 char resp[100];
10519 int res;
10520 struct wpa_ctrl *ctrl;
10521
10522 bssid = get_param(cmd, "BSSID");
10523 if (!bssid) {
10524 send_resp(dut, conn, SIGMA_INVALID,
10525 "errorCode,BSSID argument is missing");
10526 return 0;
10527 }
10528
10529 ctrl = open_wpa_mon(intf);
10530 if (!ctrl) {
10531 sigma_dut_print(dut, DUT_MSG_ERROR,
10532 "Failed to open wpa_supplicant monitor connection");
10533 return -1;
10534 }
10535
10536 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
10537 send_resp(dut, conn, SIGMA_ERROR,
10538 "errorCode,Could not start scan");
10539 wpa_ctrl_detach(ctrl);
10540 wpa_ctrl_close(ctrl);
10541 return 0;
10542 }
10543
10544 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10545 buf, sizeof(buf));
10546
10547 wpa_ctrl_detach(ctrl);
10548 wpa_ctrl_close(ctrl);
10549
10550 if (res < 0) {
10551 send_resp(dut, conn, SIGMA_ERROR,
10552 "errorCode,Scan did not complete");
10553 return 0;
10554 }
10555
10556 snprintf(buf, sizeof(buf), "BSS %s", bssid);
10557 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
10558 strncmp(buf, "id=", 3) != 0) {
10559 send_resp(dut, conn, SIGMA_ERROR,
10560 "errorCode,Specified BSSID not found");
10561 return 0;
10562 }
10563
10564 pos = strstr(buf, "\nfreq=");
10565 if (!pos) {
10566 send_resp(dut, conn, SIGMA_ERROR,
10567 "errorCode,Channel not found");
10568 return 0;
10569 }
10570 freq = atoi(pos + 6);
10571 chan = freq_to_channel(freq);
10572
10573 pos = strstr(buf, "\nssid=");
10574 if (!pos) {
10575 send_resp(dut, conn, SIGMA_ERROR,
10576 "errorCode,SSID not found");
10577 return 0;
10578 }
10579 ssid = pos + 6;
10580 pos = strchr(ssid, '\n');
10581 if (pos)
10582 *pos = '\0';
10583 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
10584 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10585 return 0;
10586}
10587
10588
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010589static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
10590 struct sigma_cmd *cmd)
10591{
10592#ifdef __linux__
10593 struct timeval tv;
10594 struct tm tm;
10595 time_t t;
10596 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053010597 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010598
10599 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
10600
10601 memset(&tm, 0, sizeof(tm));
10602 val = get_param(cmd, "seconds");
10603 if (val)
10604 tm.tm_sec = atoi(val);
10605 val = get_param(cmd, "minutes");
10606 if (val)
10607 tm.tm_min = atoi(val);
10608 val = get_param(cmd, "hours");
10609 if (val)
10610 tm.tm_hour = atoi(val);
10611 val = get_param(cmd, "date");
10612 if (val)
10613 tm.tm_mday = atoi(val);
10614 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053010615 if (val) {
10616 v = atoi(val);
10617 if (v < 1 || v > 12) {
10618 send_resp(dut, conn, SIGMA_INVALID,
10619 "errorCode,Invalid month");
10620 return 0;
10621 }
10622 tm.tm_mon = v - 1;
10623 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010624 val = get_param(cmd, "year");
10625 if (val) {
10626 int year = atoi(val);
10627#ifdef ANDROID
10628 if (year > 2035)
10629 year = 2035; /* years beyond 2035 not supported */
10630#endif /* ANDROID */
10631 tm.tm_year = year - 1900;
10632 }
10633 t = mktime(&tm);
10634 if (t == (time_t) -1) {
10635 send_resp(dut, conn, SIGMA_ERROR,
10636 "errorCode,Invalid date or time");
10637 return 0;
10638 }
10639
10640 memset(&tv, 0, sizeof(tv));
10641 tv.tv_sec = t;
10642
10643 if (settimeofday(&tv, NULL) < 0) {
10644 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
10645 strerror(errno));
10646 send_resp(dut, conn, SIGMA_ERROR,
10647 "errorCode,Failed to set time");
10648 return 0;
10649 }
10650
10651 return 1;
10652#endif /* __linux__ */
10653
10654 return -1;
10655}
10656
10657
10658static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
10659 struct sigma_cmd *cmd)
10660{
10661 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010662 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010663 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010664 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010665 int res;
10666 struct wpa_ctrl *ctrl;
10667
10668 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010669 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010670
10671 val = get_param(cmd, "ProdESSAssoc");
10672 if (val)
10673 prod_ess_assoc = atoi(val);
10674
10675 kill_dhcp_client(dut, intf);
10676 if (start_dhcp_client(dut, intf) < 0)
10677 return -2;
10678
10679 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
10680 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
10681 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010682 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010683 prod_ess_assoc ? "" : "-N",
10684 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010685 name ? "'" : "",
10686 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
10687 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010688
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053010689 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010690 if (run_hs20_osu(dut, buf) < 0) {
10691 FILE *f;
10692
10693 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
10694
10695 f = fopen("hs20-osu-client.res", "r");
10696 if (f) {
10697 char resp[400], res[300], *pos;
10698 if (!fgets(res, sizeof(res), f))
10699 res[0] = '\0';
10700 pos = strchr(res, '\n');
10701 if (pos)
10702 *pos = '\0';
10703 fclose(f);
10704 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
10705 res);
10706 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
10707 if (system(resp) != 0) {
10708 }
10709 snprintf(resp, sizeof(resp),
10710 "SSID,,BSSID,,failureReason,%s", res);
10711 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10712 return 0;
10713 }
10714
10715 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10716 return 0;
10717 }
10718
10719 if (!prod_ess_assoc)
10720 goto report;
10721
10722 ctrl = open_wpa_mon(intf);
10723 if (ctrl == NULL) {
10724 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10725 "wpa_supplicant monitor connection");
10726 return -1;
10727 }
10728
10729 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10730 buf, sizeof(buf));
10731
10732 wpa_ctrl_detach(ctrl);
10733 wpa_ctrl_close(ctrl);
10734
10735 if (res < 0) {
10736 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
10737 "network after OSU");
10738 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10739 return 0;
10740 }
10741
10742report:
10743 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10744 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10745 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
10746 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
10747 return 0;
10748 }
10749
10750 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
10751 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010752 return 0;
10753}
10754
10755
10756static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
10757 struct sigma_cmd *cmd)
10758{
10759 const char *val;
10760 int timeout = 120;
10761
10762 val = get_param(cmd, "PolicyUpdate");
10763 if (val == NULL || atoi(val) == 0)
10764 return 1; /* No operation requested */
10765
10766 val = get_param(cmd, "Timeout");
10767 if (val)
10768 timeout = atoi(val);
10769
10770 if (timeout) {
10771 /* TODO: time out the command and return
10772 * PolicyUpdateStatus,TIMEOUT if needed. */
10773 }
10774
10775 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
10776 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
10777 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
10778 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
10779 return 0;
10780 }
10781
10782 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
10783 return 0;
10784}
10785
10786
10787static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
10788 struct sigma_cmd *cmd)
10789{
10790 struct wpa_ctrl *ctrl;
10791 const char *intf = get_param(cmd, "Interface");
10792 const char *bssid = get_param(cmd, "Bssid");
10793 const char *ssid = get_param(cmd, "SSID");
10794 const char *security = get_param(cmd, "Security");
10795 const char *passphrase = get_param(cmd, "Passphrase");
10796 const char *pin = get_param(cmd, "PIN");
10797 char buf[1000];
10798 char ssid_hex[200], passphrase_hex[200];
10799 const char *keymgmt, *cipher;
10800
10801 if (intf == NULL)
10802 intf = get_main_ifname();
10803
10804 if (!bssid) {
10805 send_resp(dut, conn, SIGMA_ERROR,
10806 "ErrorCode,Missing Bssid argument");
10807 return 0;
10808 }
10809
10810 if (!ssid) {
10811 send_resp(dut, conn, SIGMA_ERROR,
10812 "ErrorCode,Missing SSID argument");
10813 return 0;
10814 }
10815
10816 if (!security) {
10817 send_resp(dut, conn, SIGMA_ERROR,
10818 "ErrorCode,Missing Security argument");
10819 return 0;
10820 }
10821
10822 if (!passphrase) {
10823 send_resp(dut, conn, SIGMA_ERROR,
10824 "ErrorCode,Missing Passphrase argument");
10825 return 0;
10826 }
10827
10828 if (!pin) {
10829 send_resp(dut, conn, SIGMA_ERROR,
10830 "ErrorCode,Missing PIN argument");
10831 return 0;
10832 }
10833
vamsi krishna8c9c1562017-05-12 15:51:46 +053010834 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
10835 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010836 send_resp(dut, conn, SIGMA_ERROR,
10837 "ErrorCode,Too long SSID/passphrase");
10838 return 0;
10839 }
10840
10841 ctrl = open_wpa_mon(intf);
10842 if (ctrl == NULL) {
10843 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10844 "wpa_supplicant monitor connection");
10845 return -2;
10846 }
10847
10848 if (strcasecmp(security, "wpa2-psk") == 0) {
10849 keymgmt = "WPA2PSK";
10850 cipher = "CCMP";
10851 } else {
10852 wpa_ctrl_detach(ctrl);
10853 wpa_ctrl_close(ctrl);
10854 send_resp(dut, conn, SIGMA_ERROR,
10855 "ErrorCode,Unsupported Security value");
10856 return 0;
10857 }
10858
10859 ascii2hexstr(ssid, ssid_hex);
10860 ascii2hexstr(passphrase, passphrase_hex);
10861 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
10862 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
10863
10864 if (wpa_command(intf, buf) < 0) {
10865 wpa_ctrl_detach(ctrl);
10866 wpa_ctrl_close(ctrl);
10867 send_resp(dut, conn, SIGMA_ERROR,
10868 "ErrorCode,Failed to start registrar");
10869 return 0;
10870 }
10871
10872 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
10873 dut->er_oper_performed = 1;
10874
10875 return wps_connection_event(dut, conn, ctrl, intf, 0);
10876}
10877
10878
10879static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
10880 struct sigma_conn *conn,
10881 struct sigma_cmd *cmd)
10882{
10883 struct wpa_ctrl *ctrl;
10884 const char *intf = get_param(cmd, "Interface");
10885 const char *bssid = get_param(cmd, "Bssid");
10886 char buf[100];
10887
10888 if (!bssid) {
10889 send_resp(dut, conn, SIGMA_ERROR,
10890 "ErrorCode,Missing Bssid argument");
10891 return 0;
10892 }
10893
10894 ctrl = open_wpa_mon(intf);
10895 if (ctrl == NULL) {
10896 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10897 "wpa_supplicant monitor connection");
10898 return -2;
10899 }
10900
10901 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
10902
10903 if (wpa_command(intf, buf) < 0) {
10904 wpa_ctrl_detach(ctrl);
10905 wpa_ctrl_close(ctrl);
10906 send_resp(dut, conn, SIGMA_ERROR,
10907 "ErrorCode,Failed to start registrar");
10908 return 0;
10909 }
10910
10911 return wps_connection_event(dut, conn, ctrl, intf, 0);
10912}
10913
10914
vamsi krishna9b144002017-09-20 13:28:13 +053010915static int cmd_start_wps_registration(struct sigma_dut *dut,
10916 struct sigma_conn *conn,
10917 struct sigma_cmd *cmd)
10918{
10919 struct wpa_ctrl *ctrl;
10920 const char *intf = get_param(cmd, "Interface");
10921 const char *role, *method;
10922 int res;
10923 char buf[256];
10924 const char *events[] = {
10925 "CTRL-EVENT-CONNECTED",
10926 "WPS-OVERLAP-DETECTED",
10927 "WPS-TIMEOUT",
10928 "WPS-FAIL",
10929 NULL
10930 };
10931
10932 ctrl = open_wpa_mon(intf);
10933 if (!ctrl) {
10934 sigma_dut_print(dut, DUT_MSG_ERROR,
10935 "Failed to open wpa_supplicant monitor connection");
10936 return -2;
10937 }
10938
10939 role = get_param(cmd, "WpsRole");
10940 if (!role) {
10941 send_resp(dut, conn, SIGMA_INVALID,
10942 "ErrorCode,WpsRole not provided");
10943 goto fail;
10944 }
10945
10946 if (strcasecmp(role, "Enrollee") == 0) {
10947 method = get_param(cmd, "WpsConfigMethod");
10948 if (!method) {
10949 send_resp(dut, conn, SIGMA_INVALID,
10950 "ErrorCode,WpsConfigMethod not provided");
10951 goto fail;
10952 }
10953 if (strcasecmp(method, "PBC") == 0) {
10954 if (wpa_command(intf, "WPS_PBC") < 0) {
10955 send_resp(dut, conn, SIGMA_ERROR,
10956 "ErrorCode,Failed to enable PBC");
10957 goto fail;
10958 }
10959 } else {
10960 /* TODO: PIN method */
10961 send_resp(dut, conn, SIGMA_ERROR,
10962 "ErrorCode,Unsupported WpsConfigMethod value");
10963 goto fail;
10964 }
10965 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10966 if (res < 0) {
10967 send_resp(dut, conn, SIGMA_ERROR,
10968 "ErrorCode,WPS connection did not complete");
10969 goto fail;
10970 }
10971 if (strstr(buf, "WPS-TIMEOUT")) {
10972 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
10973 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
10974 send_resp(dut, conn, SIGMA_ERROR,
10975 "ErrorCode,OverlapSession");
10976 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
10977 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
10978 } else {
10979 send_resp(dut, conn, SIGMA_ERROR,
10980 "ErrorCode,WPS operation failed");
10981 }
10982 } else {
10983 /* TODO: Registrar role */
10984 send_resp(dut, conn, SIGMA_ERROR,
10985 "ErrorCode,Unsupported WpsRole value");
10986 }
10987
10988fail:
10989 wpa_ctrl_detach(ctrl);
10990 wpa_ctrl_close(ctrl);
10991 return 0;
10992}
10993
10994
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010995static int req_intf(struct sigma_cmd *cmd)
10996{
10997 return get_param(cmd, "interface") == NULL ? -1 : 0;
10998}
10999
11000
11001void sta_register_cmds(void)
11002{
11003 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
11004 cmd_sta_get_ip_config);
11005 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
11006 cmd_sta_set_ip_config);
11007 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
11008 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
11009 cmd_sta_get_mac_address);
11010 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
11011 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
11012 cmd_sta_verify_ip_connection);
11013 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
11014 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
11015 cmd_sta_set_encryption);
11016 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
11017 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
11018 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
11019 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
11020 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
11021 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
11022 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
11023 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
11024 cmd_sta_set_eapakaprime);
11025 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
11026 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
11027 /* TODO: sta_set_ibss */
11028 /* TODO: sta_set_mode */
11029 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
11030 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
11031 /* TODO: sta_up_load */
11032 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
11033 cmd_sta_preset_testparameters);
11034 /* TODO: sta_set_system */
11035 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
11036 /* TODO: sta_set_rifs_test */
11037 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
11038 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
11039 /* TODO: sta_send_coexist_mgmt */
11040 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
11041 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
11042 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
11043 sigma_dut_reg_cmd("sta_reset_default", req_intf,
11044 cmd_sta_reset_default);
11045 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
11046 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
11047 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
11048 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
11049 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
11050 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
11051 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
11052 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
11053 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
11054 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011055 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
11056 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011057 sigma_dut_reg_cmd("sta_add_credential", req_intf,
11058 cmd_sta_add_credential);
11059 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011060 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011061 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
11062 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
11063 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
11064 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
11065 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
11066 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030011067 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011068 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
11069 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053011070 sigma_dut_reg_cmd("start_wps_registration", req_intf,
11071 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011072}