blob: 0b5053596d03fece8efdbfc96e957083903e5dd0 [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"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070035#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020036
37/* Temporary files for sta_send_addba */
38#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
39#define VI_QOS_FILE "/tmp/vi-qos.txt"
40#define VI_QOS_REFFILE "/etc/vi-qos.txt"
41
42/*
43 * MTU for Ethernet need to take into account 8-byte SNAP header
44 * to be added when encapsulating Ethernet frame into 802.11
45 */
46#ifndef IEEE80211_MAX_DATA_LEN_DMG
47#define IEEE80211_MAX_DATA_LEN_DMG 7920
48#endif
49#ifndef IEEE80211_SNAP_LEN_DMG
50#define IEEE80211_SNAP_LEN_DMG 8
51#endif
52
Ashwini Patil00402582017-04-13 12:29:39 +053053#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053054#define NEIGHBOR_REPORT_SIZE 1000
55#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
56#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053057
Jouni Malinencd4e3c32015-10-29 12:39:56 +020058extern char *sigma_wpas_ctrl;
59extern char *sigma_cert_path;
60extern enum driver_type wifi_chip_type;
61extern char *sigma_radio_ifname[];
62
Lior David0fe101e2017-03-09 16:09:50 +020063#ifdef __linux__
64#define WIL_WMI_MAX_PAYLOAD 248
65#define WIL_WMI_BF_TRIG_CMDID 0x83a
66
67struct wil_wmi_header {
68 uint8_t mid;
69 uint8_t reserved;
70 uint16_t cmd;
71 uint32_t ts;
72} __attribute__((packed));
73
74enum wil_wmi_bf_trig_type {
75 WIL_WMI_SLS,
76 WIL_WMI_BRP_RX,
77 WIL_WMI_BRP_TX,
78};
79
80struct wil_wmi_bf_trig_cmd {
81 /* enum wil_wmi_bf_trig_type */
82 uint32_t bf_type;
83 /* cid when type == WMI_BRP_RX */
84 uint32_t sta_id;
85 uint32_t reserved;
86 /* mac address when type = WIL_WMI_SLS */
87 uint8_t dest_mac[6];
88} __attribute__((packed));
89#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020090
91#ifdef ANDROID
92
93static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
94
95#define ANDROID_KEYSTORE_GET 'g'
96#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
97
98static int android_keystore_get(char cmd, const char *key, unsigned char *val)
99{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200100 /* Android 4.3 changed keystore design, so need to use keystore_get() */
101#ifndef KEYSTORE_MESSAGE_SIZE
102#define KEYSTORE_MESSAGE_SIZE 65535
103#endif /* KEYSTORE_MESSAGE_SIZE */
104
105 ssize_t len;
106 uint8_t *value = NULL;
107
108 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
109 "keystore command '%c' key '%s' --> keystore_get",
110 cmd, key);
111
112 len = keystore_get(key, strlen(key), &value);
113 if (len < 0) {
114 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
115 "keystore_get() failed");
116 return -1;
117 }
118
119 if (len > KEYSTORE_MESSAGE_SIZE)
120 len = KEYSTORE_MESSAGE_SIZE;
121 memcpy(val, value, len);
122 free(value);
123 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200124}
125#endif /* ANDROID */
126
127
128int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
129{
130#ifdef __linux__
131 char buf[100];
132
133 if (wifi_chip_type == DRIVER_WCN) {
134 if (enabled) {
135 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530136 if (system(buf) != 0)
137 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200138 } else {
139 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530140 if (system(buf) != 0)
141 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200142 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530143 if (system(buf) != 0)
144 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200145 }
146
147 return 0;
148 }
149
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530150set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200151 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
152 intf, enabled ? "on" : "off");
153 if (system(buf) != 0) {
154 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
155 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530156 if (system(buf) != 0) {
157 sigma_dut_print(dut, DUT_MSG_ERROR,
158 "Failed to set power save %s",
159 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200160 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200162 }
163
164 return 0;
165#else /* __linux__ */
166 return -1;
167#endif /* __linux__ */
168}
169
170
Lior Davidcc88b562017-01-03 18:52:09 +0200171#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200172
Lior Davidcc88b562017-01-03 18:52:09 +0200173static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
174 size_t len)
175{
176 DIR *dir, *wil_dir;
177 struct dirent *entry;
178 int ret = -1;
179 const char *root_path = "/sys/kernel/debug/ieee80211";
180
181 dir = opendir(root_path);
182 if (!dir)
183 return -2;
184
185 while ((entry = readdir(dir))) {
186 if (strcmp(entry->d_name, ".") == 0 ||
187 strcmp(entry->d_name, "..") == 0)
188 continue;
189
190 if (snprintf(path, len, "%s/%s/wil6210",
191 root_path, entry->d_name) >= (int) len) {
192 ret = -3;
193 break;
194 }
195
196 wil_dir = opendir(path);
197 if (wil_dir) {
198 closedir(wil_dir);
199 ret = 0;
200 break;
201 }
202 }
203
204 closedir(dir);
205 return ret;
206}
Lior David0fe101e2017-03-09 16:09:50 +0200207
208
209static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
210 void *payload, uint16_t length)
211{
212 struct {
213 struct wil_wmi_header hdr;
214 char payload[WIL_WMI_MAX_PAYLOAD];
215 } __attribute__((packed)) cmd;
216 char buf[128], fname[128];
217 size_t towrite, written;
218 FILE *f;
219
220 if (length > WIL_WMI_MAX_PAYLOAD) {
221 sigma_dut_print(dut, DUT_MSG_ERROR,
222 "payload too large(%u, max %u)",
223 length, WIL_WMI_MAX_PAYLOAD);
224 return -1;
225 }
226
227 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
228 cmd.hdr.cmd = command;
229 memcpy(cmd.payload, payload, length);
230
231 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
232 sigma_dut_print(dut, DUT_MSG_ERROR,
233 "failed to get wil6210 debugfs dir");
234 return -1;
235 }
236
237 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
238 f = fopen(fname, "wb");
239 if (!f) {
240 sigma_dut_print(dut, DUT_MSG_ERROR,
241 "failed to open: %s", fname);
242 return -1;
243 }
244
245 towrite = sizeof(cmd.hdr) + length;
246 written = fwrite(&cmd, 1, towrite, f);
247 fclose(f);
248 if (written != towrite) {
249 sigma_dut_print(dut, DUT_MSG_ERROR,
250 "failed to send wmi %u", command);
251 return -1;
252 }
253
254 return 0;
255}
256
257
258static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
259 const char *pattern, unsigned int *field)
260{
261 char buf[128], fname[128];
262 FILE *f;
263 regex_t re;
264 regmatch_t m[2];
265 int rc, ret = -1;
266
267 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
268 sigma_dut_print(dut, DUT_MSG_ERROR,
269 "failed to get wil6210 debugfs dir");
270 return -1;
271 }
272
273 snprintf(fname, sizeof(fname), "%s/stations", buf);
274 f = fopen(fname, "r");
275 if (!f) {
276 sigma_dut_print(dut, DUT_MSG_ERROR,
277 "failed to open: %s", fname);
278 return -1;
279 }
280
281 if (regcomp(&re, pattern, REG_EXTENDED)) {
282 sigma_dut_print(dut, DUT_MSG_ERROR,
283 "regcomp failed: %s", pattern);
284 goto out;
285 }
286
287 /*
288 * find the entry for the mac address
289 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
290 */
291 while (fgets(buf, sizeof(buf), f)) {
292 if (strcasestr(buf, bssid)) {
293 /* extract the field (CID/AID/state) */
294 rc = regexec(&re, buf, 2, m, 0);
295 if (!rc && (m[1].rm_so >= 0)) {
296 buf[m[1].rm_eo] = 0;
297 *field = atoi(&buf[m[1].rm_so]);
298 ret = 0;
299 break;
300 }
301 }
302 }
303
304 regfree(&re);
305 if (ret)
306 sigma_dut_print(dut, DUT_MSG_ERROR,
307 "could not extract field");
308
309out:
310 fclose(f);
311
312 return ret;
313}
314
315
316static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
317 unsigned int *cid)
318{
319 const char *pattern = "\\[([0-9]+)\\]";
320
321 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
322}
323
324
325static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
326 int l_rx)
327{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700328 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200329 unsigned int cid;
330
Rakesh Sunki556237d2017-03-30 14:49:31 -0700331 memset(&cmd, 0, sizeof(cmd));
332
Lior David0fe101e2017-03-09 16:09:50 +0200333 if (wil6210_get_cid(dut, mac, &cid))
334 return -1;
335
336 cmd.bf_type = WIL_WMI_BRP_RX;
337 cmd.sta_id = cid;
338 /* training length (l_rx) is ignored, FW always uses length 16 */
339 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
340 &cmd, sizeof(cmd));
341}
342
343
344static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
345{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700346 struct wil_wmi_bf_trig_cmd cmd;
347
348 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200349
350 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
351 return -1;
352
353 cmd.bf_type = WIL_WMI_SLS;
354 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
355 &cmd, sizeof(cmd));
356}
357
Lior Davidcc88b562017-01-03 18:52:09 +0200358#endif /* __linux__ */
359
360
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200361static void static_ip_file(int proto, const char *addr, const char *mask,
362 const char *gw)
363{
364 if (proto) {
365 FILE *f = fopen("static-ip", "w");
366 if (f) {
367 fprintf(f, "%d %s %s %s\n", proto, addr,
368 mask ? mask : "N/A",
369 gw ? gw : "N/A");
370 fclose(f);
371 }
372 } else {
373 unlink("static-ip");
374 }
375}
376
377
378static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
379 const char *ssid)
380{
381#ifdef __linux__
382 char buf[100];
383
384 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
385 intf, ssid);
386 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
387
388 if (system(buf) != 0) {
389 sigma_dut_print(dut, DUT_MSG_ERROR,
390 "iwpriv neighbor request failed");
391 return -1;
392 }
393
394 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
395
396 return 0;
397#else /* __linux__ */
398 return -1;
399#endif /* __linux__ */
400}
401
402
403static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530404 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530406 const char *val;
407 int reason_code = 0;
408 char buf[1024];
409
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200410 /*
411 * In the earlier builds we used WNM_QUERY and in later
412 * builds used WNM_BSS_QUERY.
413 */
414
Ashwini Patil5acd7382017-04-13 15:55:04 +0530415 val = get_param(cmd, "BTMQuery_Reason_Code");
416 if (val)
417 reason_code = atoi(val);
418
419 val = get_param(cmd, "Cand_List");
420 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
421 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
422 dut->btm_query_cand_list);
423 free(dut->btm_query_cand_list);
424 dut->btm_query_cand_list = NULL;
425 } else {
426 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
427 }
428
429 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "transition management query failed");
432 return -1;
433 }
434
435 sigma_dut_print(dut, DUT_MSG_DEBUG,
436 "transition management query sent");
437
438 return 0;
439}
440
441
442int is_ip_addr(const char *str)
443{
444 const char *pos = str;
445 struct in_addr addr;
446
447 while (*pos) {
448 if (*pos != '.' && (*pos < '0' || *pos > '9'))
449 return 0;
450 pos++;
451 }
452
453 return inet_aton(str, &addr);
454}
455
456
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200457int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
458 size_t buf_len)
459{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530460 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200461 char ip[16], mask[15], dns[16], sec_dns[16];
462 int is_dhcp = 0;
463 int s;
464#ifdef ANDROID
465 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530466#else /* ANDROID */
467 FILE *f;
468#ifdef __linux__
469 const char *str_ps;
470#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200471#endif /* ANDROID */
472
473 ip[0] = '\0';
474 mask[0] = '\0';
475 dns[0] = '\0';
476 sec_dns[0] = '\0';
477
478 s = socket(PF_INET, SOCK_DGRAM, 0);
479 if (s >= 0) {
480 struct ifreq ifr;
481 struct sockaddr_in saddr;
482
483 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700484 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200485 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
486 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
487 "%s IP address: %s",
488 ifname, strerror(errno));
489 } else {
490 memcpy(&saddr, &ifr.ifr_addr,
491 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700492 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200493 }
494
495 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
496 memcpy(&saddr, &ifr.ifr_addr,
497 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700498 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200499 }
500 close(s);
501 }
502
503#ifdef ANDROID
504 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
505 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
506 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
507 if (property_get(tmp, prop, NULL) != 0 &&
508 strcmp(prop, "ok") == 0) {
509 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
510 ifname);
511 if (property_get(tmp, prop, NULL) != 0 &&
512 strcmp(ip, prop) == 0)
513 is_dhcp = 1;
514 }
515 }
516
517 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700518 if (property_get(tmp, prop, NULL) != 0)
519 strlcpy(dns, prop, sizeof(dns));
520 else if (property_get("net.dns1", prop, NULL) != 0)
521 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200522
523 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700524 if (property_get(tmp, prop, NULL) != 0)
525 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200526#else /* ANDROID */
527#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530528 if (get_driver_type() == DRIVER_OPENWRT)
529 str_ps = "ps -w";
530 else
531 str_ps = "ps ax";
532 snprintf(tmp, sizeof(tmp),
533 "%s | grep dhclient | grep -v grep | grep -q %s",
534 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200535 if (system(tmp) == 0)
536 is_dhcp = 1;
537 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530538 snprintf(tmp, sizeof(tmp),
539 "%s | grep udhcpc | grep -v grep | grep -q %s",
540 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200541 if (system(tmp) == 0)
542 is_dhcp = 1;
543 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530544 snprintf(tmp, sizeof(tmp),
545 "%s | grep dhcpcd | grep -v grep | grep -q %s",
546 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200547 if (system(tmp) == 0)
548 is_dhcp = 1;
549 }
550 }
551#endif /* __linux__ */
552
553 f = fopen("/etc/resolv.conf", "r");
554 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530555 char *pos, *pos2;
556
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200557 while (fgets(tmp, sizeof(tmp), f)) {
558 if (strncmp(tmp, "nameserver", 10) != 0)
559 continue;
560 pos = tmp + 10;
561 while (*pos == ' ' || *pos == '\t')
562 pos++;
563 pos2 = pos;
564 while (*pos2) {
565 if (*pos2 == '\n' || *pos2 == '\r') {
566 *pos2 = '\0';
567 break;
568 }
569 pos2++;
570 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700571 if (!dns[0])
572 strlcpy(dns, pos, sizeof(dns));
573 else if (!sec_dns[0])
574 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200575 }
576 fclose(f);
577 }
578#endif /* ANDROID */
579
580 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
581 is_dhcp, ip, mask, dns);
582 buf[buf_len - 1] = '\0';
583
584 return 0;
585}
586
587
588
589
590int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
591 size_t buf_len)
592{
593#ifdef __linux__
594#ifdef ANDROID
595 char cmd[200], result[1000], *pos, *end;
596 FILE *f;
597 size_t len;
598
599 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
600 f = popen(cmd, "r");
601 if (f == NULL)
602 return -1;
603 len = fread(result, 1, sizeof(result) - 1, f);
604 pclose(f);
605 if (len == 0)
606 return -1;
607 result[len] = '\0';
608 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
609
610 pos = strstr(result, "inet6 ");
611 if (pos == NULL)
612 return -1;
613 pos += 6;
614 end = strchr(pos, ' ');
615 if (end)
616 *end = '\0';
617 end = strchr(pos, '/');
618 if (end)
619 *end = '\0';
620 snprintf(buf, buf_len, "ip,%s", pos);
621 buf[buf_len - 1] = '\0';
622 return 0;
623#else /* ANDROID */
624 struct ifaddrs *ifaddr, *ifa;
625 int res, found = 0;
626 char host[NI_MAXHOST];
627
628 if (getifaddrs(&ifaddr) < 0) {
629 perror("getifaddrs");
630 return -1;
631 }
632
633 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
634 if (strcasecmp(ifname, ifa->ifa_name) != 0)
635 continue;
636 if (ifa->ifa_addr == NULL ||
637 ifa->ifa_addr->sa_family != AF_INET6)
638 continue;
639
640 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
641 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
642 if (res != 0) {
643 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
644 gai_strerror(res));
645 continue;
646 }
647 if (strncmp(host, "fe80::", 6) == 0)
648 continue; /* skip link-local */
649
650 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
651 found = 1;
652 break;
653 }
654
655 freeifaddrs(ifaddr);
656
657 if (found) {
658 char *pos;
659 pos = strchr(host, '%');
660 if (pos)
661 *pos = '\0';
662 snprintf(buf, buf_len, "ip,%s", host);
663 buf[buf_len - 1] = '\0';
664 return 0;
665 }
666
667#endif /* ANDROID */
668#endif /* __linux__ */
669 return -1;
670}
671
672
673static int cmd_sta_get_ip_config(struct sigma_dut *dut,
674 struct sigma_conn *conn,
675 struct sigma_cmd *cmd)
676{
677 const char *intf = get_param(cmd, "Interface");
678 const char *ifname;
679 char buf[200];
680 const char *val;
681 int type = 1;
682
683 if (intf == NULL)
684 return -1;
685
686 if (strcmp(intf, get_main_ifname()) == 0)
687 ifname = get_station_ifname();
688 else
689 ifname = intf;
690
691 /*
692 * UCC may assume the IP address to be available immediately after
693 * association without trying to run sta_get_ip_config multiple times.
694 * Sigma CAPI does not specify this command as a block command that
695 * would wait for the address to become available, but to pass tests
696 * more reliably, it looks like such a wait may be needed here.
697 */
698 if (wait_ip_addr(dut, ifname, 15) < 0) {
699 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
700 "for sta_get_ip_config");
701 /*
702 * Try to continue anyway since many UCC tests do not really
703 * care about the return value from here..
704 */
705 }
706
707 val = get_param(cmd, "Type");
708 if (val)
709 type = atoi(val);
710 if (type == 2 || dut->last_set_ip_config_ipv6) {
711 int i;
712
713 /*
714 * Since we do not have proper wait for IPv6 addresses, use a
715 * fixed two second delay here as a workaround for UCC script
716 * assuming IPv6 address is available when this command returns.
717 * Some scripts did not use Type,2 properly for IPv6, so include
718 * also the cases where the previous sta_set_ip_config indicated
719 * use of IPv6.
720 */
721 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
722 for (i = 0; i < 10; i++) {
723 sleep(1);
724 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
725 {
726 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
727 send_resp(dut, conn, SIGMA_COMPLETE, buf);
728#ifdef ANDROID
729 sigma_dut_print(dut, DUT_MSG_INFO,
730 "Adding IPv6 rule on Android");
731 add_ipv6_rule(dut, intf);
732#endif /* ANDROID */
733
734 return 0;
735 }
736 }
737 }
738 if (type == 1) {
739 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
740 return -2;
741 } else if (type == 2) {
742 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
743 return -2;
744 } else {
745 send_resp(dut, conn, SIGMA_ERROR,
746 "errorCode,Unsupported address type");
747 return 0;
748 }
749
750 send_resp(dut, conn, SIGMA_COMPLETE, buf);
751 return 0;
752}
753
754
755static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
756{
757#ifdef __linux__
758 char buf[200];
759 char path[128];
760 struct stat s;
761
762#ifdef ANDROID
763 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
764#else /* ANDROID */
765 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
766#endif /* ANDROID */
767 if (stat(path, &s) == 0) {
768 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
769 sigma_dut_print(dut, DUT_MSG_INFO,
770 "Kill previous DHCP client: %s", buf);
771 if (system(buf) != 0)
772 sigma_dut_print(dut, DUT_MSG_INFO,
773 "Failed to kill DHCP client");
774 unlink(path);
775 sleep(1);
776 } else {
777 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
778
779 if (stat(path, &s) == 0) {
780 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
781 sigma_dut_print(dut, DUT_MSG_INFO,
782 "Kill previous DHCP client: %s", buf);
783 if (system(buf) != 0)
784 sigma_dut_print(dut, DUT_MSG_INFO,
785 "Failed to kill DHCP client");
786 unlink(path);
787 sleep(1);
788 }
789 }
790#endif /* __linux__ */
791}
792
793
794static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
795{
796#ifdef __linux__
797 char buf[200];
798
799#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530800 if (access("/system/bin/dhcpcd", F_OK) != -1) {
801 snprintf(buf, sizeof(buf),
802 "/system/bin/dhcpcd -b %s", ifname);
803 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
804 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
805 } else {
806 sigma_dut_print(dut, DUT_MSG_ERROR,
807 "DHCP client program missing");
808 return 0;
809 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200810#else /* ANDROID */
811 snprintf(buf, sizeof(buf),
812 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
813 ifname, ifname);
814#endif /* ANDROID */
815 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
816 if (system(buf) != 0) {
817 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
818 if (system(buf) != 0) {
819 sigma_dut_print(dut, DUT_MSG_INFO,
820 "Failed to start DHCP client");
821#ifndef ANDROID
822 return -1;
823#endif /* ANDROID */
824 }
825 }
826#endif /* __linux__ */
827
828 return 0;
829}
830
831
832static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
833{
834#ifdef __linux__
835 char buf[200];
836
837 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
838 if (system(buf) != 0) {
839 sigma_dut_print(dut, DUT_MSG_INFO,
840 "Failed to clear IP addresses");
841 return -1;
842 }
843#endif /* __linux__ */
844
845 return 0;
846}
847
848
849#ifdef ANDROID
850static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
851{
852 char cmd[200], *result, *pos;
853 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530854 int tableid;
855 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200856
857 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
858 ifname);
859 fp = popen(cmd, "r");
860 if (fp == NULL)
861 return -1;
862
863 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530864 if (result == NULL) {
865 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200866 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530867 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200868
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530869 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200870 fclose(fp);
871
872 if (len == 0) {
873 free(result);
874 return -1;
875 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530876 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200877
878 pos = strstr(result, "table ");
879 if (pos == NULL) {
880 free(result);
881 return -1;
882 }
883
884 pos += strlen("table ");
885 tableid = atoi(pos);
886 if (tableid != 0) {
887 if (system("ip -6 rule del prio 22000") != 0) {
888 /* ignore any error */
889 }
890 snprintf(cmd, sizeof(cmd),
891 "ip -6 rule add from all lookup %d prio 22000",
892 tableid);
893 if (system(cmd) != 0) {
894 sigma_dut_print(dut, DUT_MSG_INFO,
895 "Failed to run %s", cmd);
896 free(result);
897 return -1;
898 }
899 } else {
900 sigma_dut_print(dut, DUT_MSG_INFO,
901 "No Valid Table Id found %s", pos);
902 free(result);
903 return -1;
904 }
905 free(result);
906
907 return 0;
908}
909#endif /* ANDROID */
910
911
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530912int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
913 const char *ip, const char *mask)
914{
915 char buf[200];
916
917 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
918 ifname, ip, mask);
919 return system(buf) == 0;
920}
921
922
923int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
924{
925 char buf[200];
926
927 if (!is_ip_addr(gw)) {
928 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
929 return -1;
930 }
931
932 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
933 if (!dut->no_ip_addr_set && system(buf) != 0) {
934 snprintf(buf, sizeof(buf), "ip ro re default via %s",
935 gw);
936 if (system(buf) != 0)
937 return 0;
938 }
939
940 return 1;
941}
942
943
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200944static int cmd_sta_set_ip_config(struct sigma_dut *dut,
945 struct sigma_conn *conn,
946 struct sigma_cmd *cmd)
947{
948 const char *intf = get_param(cmd, "Interface");
949 const char *ifname;
950 char buf[200];
951 const char *val, *ip, *mask, *gw;
952 int type = 1;
953
954 if (intf == NULL)
955 return -1;
956
957 if (strcmp(intf, get_main_ifname()) == 0)
958 ifname = get_station_ifname();
959 else
960 ifname = intf;
961
962 if (if_nametoindex(ifname) == 0) {
963 send_resp(dut, conn, SIGMA_ERROR,
964 "ErrorCode,Unknown interface");
965 return 0;
966 }
967
968 val = get_param(cmd, "Type");
969 if (val) {
970 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530971 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972 send_resp(dut, conn, SIGMA_ERROR,
973 "ErrorCode,Unsupported address type");
974 return 0;
975 }
976 }
977
978 dut->last_set_ip_config_ipv6 = 0;
979
980 val = get_param(cmd, "dhcp");
981 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
982 static_ip_file(0, NULL, NULL, NULL);
983#ifdef __linux__
984 if (type == 2) {
985 dut->last_set_ip_config_ipv6 = 1;
986 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
987 "stateless address autoconfiguration");
988#ifdef ANDROID
989 /*
990 * This sleep is required as the assignment in case of
991 * Android is taking time and is done by the kernel.
992 * The subsequent ping for IPv6 is impacting HS20 test
993 * case.
994 */
995 sleep(2);
996 add_ipv6_rule(dut, intf);
997#endif /* ANDROID */
998 /* Assume this happens by default */
999 return 1;
1000 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301001 if (type != 3) {
1002 kill_dhcp_client(dut, ifname);
1003 if (start_dhcp_client(dut, ifname) < 0)
1004 return -2;
1005 } else {
1006 sigma_dut_print(dut, DUT_MSG_DEBUG,
1007 "Using FILS HLP DHCPv4 Rapid Commit");
1008 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001009
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001010 return 1;
1011#endif /* __linux__ */
1012 return -2;
1013 }
1014
1015 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301016 if (!ip) {
1017 send_resp(dut, conn, SIGMA_INVALID,
1018 "ErrorCode,Missing IP address");
1019 return 0;
1020 }
1021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001022 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301023 if (!mask) {
1024 send_resp(dut, conn, SIGMA_INVALID,
1025 "ErrorCode,Missing subnet mask");
1026 return 0;
1027 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001028
1029 if (type == 2) {
1030 int net = atoi(mask);
1031
1032 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1033 return -1;
1034
1035 if (dut->no_ip_addr_set) {
1036 snprintf(buf, sizeof(buf),
1037 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1038 ifname);
1039 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1040 if (system(buf) != 0) {
1041 sigma_dut_print(dut, DUT_MSG_DEBUG,
1042 "Failed to disable IPv6 address before association");
1043 }
1044 } else {
1045 snprintf(buf, sizeof(buf),
1046 "ip -6 addr del %s/%s dev %s",
1047 ip, mask, ifname);
1048 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1049 if (system(buf) != 0) {
1050 /*
1051 * This command may fail if the address being
1052 * deleted does not exist. Inaction here is
1053 * intentional.
1054 */
1055 }
1056
1057 snprintf(buf, sizeof(buf),
1058 "ip -6 addr add %s/%s dev %s",
1059 ip, mask, ifname);
1060 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1061 if (system(buf) != 0) {
1062 send_resp(dut, conn, SIGMA_ERROR,
1063 "ErrorCode,Failed to set IPv6 address");
1064 return 0;
1065 }
1066 }
1067
1068 dut->last_set_ip_config_ipv6 = 1;
1069 static_ip_file(6, ip, mask, NULL);
1070 return 1;
1071 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301072 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001073 return -1;
1074 }
1075
1076 kill_dhcp_client(dut, ifname);
1077
1078 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301079 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001080 send_resp(dut, conn, SIGMA_ERROR,
1081 "ErrorCode,Failed to set IP address");
1082 return 0;
1083 }
1084 }
1085
1086 gw = get_param(cmd, "defaultGateway");
1087 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301088 if (set_ipv4_gw(dut, gw) < 1) {
1089 send_resp(dut, conn, SIGMA_ERROR,
1090 "ErrorCode,Failed to set default gateway");
1091 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001092 }
1093 }
1094
1095 val = get_param(cmd, "primary-dns");
1096 if (val) {
1097 /* TODO */
1098 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1099 "setting", val);
1100 }
1101
1102 val = get_param(cmd, "secondary-dns");
1103 if (val) {
1104 /* TODO */
1105 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1106 "setting", val);
1107 }
1108
1109 static_ip_file(4, ip, mask, gw);
1110
1111 return 1;
1112}
1113
1114
1115static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1116 struct sigma_cmd *cmd)
1117{
1118 /* const char *intf = get_param(cmd, "Interface"); */
1119 /* TODO: could report more details here */
1120 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1121 return 0;
1122}
1123
1124
1125static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1126 struct sigma_conn *conn,
1127 struct sigma_cmd *cmd)
1128{
1129 /* const char *intf = get_param(cmd, "Interface"); */
1130 char addr[20], resp[50];
1131
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301132 if (dut->dev_role == DEVROLE_STA_CFON)
1133 return sta_cfon_get_mac_address(dut, conn, cmd);
1134
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001135 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1136 < 0)
1137 return -2;
1138
1139 snprintf(resp, sizeof(resp), "mac,%s", addr);
1140 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1141 return 0;
1142}
1143
1144
1145static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1146 struct sigma_cmd *cmd)
1147{
1148 /* const char *intf = get_param(cmd, "Interface"); */
1149 int connected = 0;
1150 char result[32];
1151 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1152 sizeof(result)) < 0) {
1153 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1154 "%s status", get_station_ifname());
1155 return -2;
1156 }
1157
1158 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1159 if (strncmp(result, "COMPLETED", 9) == 0)
1160 connected = 1;
1161
1162 if (connected)
1163 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1164 else
1165 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1166
1167 return 0;
1168}
1169
1170
1171static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1172 struct sigma_conn *conn,
1173 struct sigma_cmd *cmd)
1174{
1175 /* const char *intf = get_param(cmd, "Interface"); */
1176 const char *dst, *timeout;
1177 int wait_time = 90;
1178 char buf[100];
1179 int res;
1180
1181 dst = get_param(cmd, "destination");
1182 if (dst == NULL || !is_ip_addr(dst))
1183 return -1;
1184
1185 timeout = get_param(cmd, "timeout");
1186 if (timeout) {
1187 wait_time = atoi(timeout);
1188 if (wait_time < 1)
1189 wait_time = 1;
1190 }
1191
1192 /* TODO: force renewal of IP lease if DHCP is enabled */
1193
1194 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1195 res = system(buf);
1196 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1197 if (res == 0)
1198 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1199 else if (res == 256)
1200 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1201 else
1202 return -2;
1203
1204 return 0;
1205}
1206
1207
1208static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1209 struct sigma_cmd *cmd)
1210{
1211 /* const char *intf = get_param(cmd, "Interface"); */
1212 char bssid[20], resp[50];
1213
1214 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1215 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001216 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001217
1218 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1219 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1220 return 0;
1221}
1222
1223
1224#ifdef __SAMSUNG__
1225static int add_use_network(const char *ifname)
1226{
1227 char buf[100];
1228
1229 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1230 wpa_command(ifname, buf);
1231 return 0;
1232}
1233#endif /* __SAMSUNG__ */
1234
1235
1236static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1237 const char *ifname, struct sigma_cmd *cmd)
1238{
1239 const char *ssid = get_param(cmd, "ssid");
1240 int id;
1241 const char *val;
1242
1243 if (ssid == NULL)
1244 return -1;
1245
1246 start_sta_mode(dut);
1247
1248#ifdef __SAMSUNG__
1249 add_use_network(ifname);
1250#endif /* __SAMSUNG__ */
1251
1252 id = add_network(ifname);
1253 if (id < 0)
1254 return -2;
1255 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1256
1257 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1258 return -2;
1259
1260 dut->infra_network_id = id;
1261 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1262
1263 val = get_param(cmd, "program");
1264 if (!val)
1265 val = get_param(cmd, "prog");
1266 if (val && strcasecmp(val, "hs2") == 0) {
1267 char buf[100];
1268 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1269 wpa_command(ifname, buf);
1270
1271 val = get_param(cmd, "prefer");
1272 if (val && atoi(val) > 0)
1273 set_network(ifname, id, "priority", "1");
1274 }
1275
1276 return id;
1277}
1278
1279
1280static int cmd_sta_set_encryption(struct sigma_dut *dut,
1281 struct sigma_conn *conn,
1282 struct sigma_cmd *cmd)
1283{
1284 const char *intf = get_param(cmd, "Interface");
1285 const char *ssid = get_param(cmd, "ssid");
1286 const char *type = get_param(cmd, "encpType");
1287 const char *ifname;
1288 char buf[200];
1289 int id;
1290
1291 if (intf == NULL || ssid == NULL)
1292 return -1;
1293
1294 if (strcmp(intf, get_main_ifname()) == 0)
1295 ifname = get_station_ifname();
1296 else
1297 ifname = intf;
1298
1299 id = add_network_common(dut, conn, ifname, cmd);
1300 if (id < 0)
1301 return id;
1302
1303 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1304 return -2;
1305
1306 if (type && strcasecmp(type, "wep") == 0) {
1307 const char *val;
1308 int i;
1309
1310 val = get_param(cmd, "activeKey");
1311 if (val) {
1312 int keyid;
1313 keyid = atoi(val);
1314 if (keyid < 1 || keyid > 4)
1315 return -1;
1316 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1317 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1318 return -2;
1319 }
1320
1321 for (i = 0; i < 4; i++) {
1322 snprintf(buf, sizeof(buf), "key%d", i + 1);
1323 val = get_param(cmd, buf);
1324 if (val == NULL)
1325 continue;
1326 snprintf(buf, sizeof(buf), "wep_key%d", i);
1327 if (set_network(ifname, id, buf, val) < 0)
1328 return -2;
1329 }
1330 }
1331
1332 return 1;
1333}
1334
1335
1336static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1337 const char *ifname, struct sigma_cmd *cmd)
1338{
1339 const char *val;
1340 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001341 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001342 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301343 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001344
1345 id = add_network_common(dut, conn, ifname, cmd);
1346 if (id < 0)
1347 return id;
1348
Jouni Malinen47dcc952017-10-09 16:43:24 +03001349 val = get_param(cmd, "Type");
1350 owe = val && strcasecmp(val, "OWE") == 0;
1351
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001352 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001353 if (!val && owe)
1354 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001355 if (val == NULL) {
1356 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1357 return 0;
1358 }
1359 if (strcasecmp(val, "wpa") == 0 ||
1360 strcasecmp(val, "wpa-psk") == 0) {
1361 if (set_network(ifname, id, "proto", "WPA") < 0)
1362 return -2;
1363 } else if (strcasecmp(val, "wpa2") == 0 ||
1364 strcasecmp(val, "wpa2-psk") == 0 ||
1365 strcasecmp(val, "wpa2-ft") == 0 ||
1366 strcasecmp(val, "wpa2-sha256") == 0) {
1367 if (set_network(ifname, id, "proto", "WPA2") < 0)
1368 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301369 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1370 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1372 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001373 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301374 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001375 if (set_network(ifname, id, "proto", "WPA2") < 0)
1376 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001377 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001378 } else {
1379 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1380 return 0;
1381 }
1382
1383 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001384 if (val) {
1385 cipher_set = 1;
1386 if (strcasecmp(val, "tkip") == 0) {
1387 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1388 return -2;
1389 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1390 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1391 return -2;
1392 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1393 if (set_network(ifname, id, "pairwise",
1394 "CCMP TKIP") < 0)
1395 return -2;
1396 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1397 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1398 return -2;
1399 if (set_network(ifname, id, "group", "GCMP") < 0)
1400 return -2;
1401 } else {
1402 send_resp(dut, conn, SIGMA_ERROR,
1403 "errorCode,Unrecognized encpType value");
1404 return 0;
1405 }
1406 }
1407
1408 val = get_param(cmd, "PairwiseCipher");
1409 if (val) {
1410 cipher_set = 1;
1411 /* TODO: Support space separated list */
1412 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1413 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1414 return -2;
1415 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1416 if (set_network(ifname, id, "pairwise",
1417 "CCMP-256") < 0)
1418 return -2;
1419 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1420 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1421 return -2;
1422 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1423 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1424 return -2;
1425 } else {
1426 send_resp(dut, conn, SIGMA_ERROR,
1427 "errorCode,Unrecognized PairwiseCipher value");
1428 return 0;
1429 }
1430 }
1431
Jouni Malinen47dcc952017-10-09 16:43:24 +03001432 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001433 send_resp(dut, conn, SIGMA_ERROR,
1434 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435 return 0;
1436 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001437
1438 val = get_param(cmd, "GroupCipher");
1439 if (val) {
1440 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1441 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1442 return -2;
1443 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1444 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1445 return -2;
1446 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1447 if (set_network(ifname, id, "group", "GCMP") < 0)
1448 return -2;
1449 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1450 if (set_network(ifname, id, "group", "CCMP") < 0)
1451 return -2;
1452 } else {
1453 send_resp(dut, conn, SIGMA_ERROR,
1454 "errorCode,Unrecognized GroupCipher value");
1455 return 0;
1456 }
1457 }
1458
Jouni Malinen7b239522017-09-14 21:37:18 +03001459 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001460 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001461 const char *cipher;
1462
1463 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1464 cipher = "BIP-GMAC-256";
1465 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1466 cipher = "BIP-CMAC-256";
1467 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1468 cipher = "BIP-GMAC-128";
1469 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1470 cipher = "AES-128-CMAC";
1471 } else {
1472 send_resp(dut, conn, SIGMA_INVALID,
1473 "errorCode,Unsupported GroupMgntCipher");
1474 return 0;
1475 }
1476 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1477 send_resp(dut, conn, SIGMA_INVALID,
1478 "errorCode,Failed to set GroupMgntCipher");
1479 return 0;
1480 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001481 }
1482
1483 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301484
1485 if (dut->program == PROGRAM_OCE) {
1486 dut->sta_pmf = STA_PMF_OPTIONAL;
1487 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1488 return -2;
1489 }
1490
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001491 val = get_param(cmd, "PMF");
1492 if (val) {
1493 if (strcasecmp(val, "Required") == 0 ||
1494 strcasecmp(val, "Forced_Required") == 0) {
1495 dut->sta_pmf = STA_PMF_REQUIRED;
1496 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1497 return -2;
1498 } else if (strcasecmp(val, "Optional") == 0) {
1499 dut->sta_pmf = STA_PMF_OPTIONAL;
1500 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1501 return -2;
1502 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08001503 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001504 strcasecmp(val, "Forced_Disabled") == 0) {
1505 dut->sta_pmf = STA_PMF_DISABLED;
1506 } else {
1507 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1508 return 0;
1509 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301510 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001511 dut->sta_pmf = STA_PMF_REQUIRED;
1512 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1513 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001514 }
1515
1516 return id;
1517}
1518
1519
1520static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1521 struct sigma_cmd *cmd)
1522{
1523 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001524 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001525 const char *pmf = get_param(cmd, "PMF");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001526 const char *ifname, *val, *alg;
1527 int id;
1528
1529 if (intf == NULL)
1530 return -1;
1531
1532 if (strcmp(intf, get_main_ifname()) == 0)
1533 ifname = get_station_ifname();
1534 else
1535 ifname = intf;
1536
1537 id = set_wpa_common(dut, conn, ifname, cmd);
1538 if (id < 0)
1539 return id;
1540
1541 val = get_param(cmd, "keyMgmtType");
1542 alg = get_param(cmd, "micAlg");
1543
Jouni Malinen992a81e2017-08-22 13:57:47 +03001544 if (type && strcasecmp(type, "SAE") == 0) {
1545 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1546 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1547 return -2;
1548 } else {
1549 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1550 return -2;
1551 }
1552 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1553 sigma_dut_print(dut, DUT_MSG_ERROR,
1554 "Failed to clear sae_groups to default");
1555 return -2;
1556 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001557 if (!pmf) {
1558 dut->sta_pmf = STA_PMF_REQUIRED;
1559 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1560 return -2;
1561 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001562 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1563 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1564 if (set_network(ifname, id, "key_mgmt",
1565 "FT-SAE FT-PSK") < 0)
1566 return -2;
1567 } else {
1568 if (set_network(ifname, id, "key_mgmt",
1569 "SAE WPA-PSK") < 0)
1570 return -2;
1571 }
1572 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1573 sigma_dut_print(dut, DUT_MSG_ERROR,
1574 "Failed to clear sae_groups to default");
1575 return -2;
1576 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001577 if (!pmf) {
1578 dut->sta_pmf = STA_PMF_OPTIONAL;
1579 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1580 return -2;
1581 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001582 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001583 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1584 return -2;
1585 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1586 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1587 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301588 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1589 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1590 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001591 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1592 dut->sta_pmf == STA_PMF_REQUIRED) {
1593 if (set_network(ifname, id, "key_mgmt",
1594 "WPA-PSK WPA-PSK-SHA256") < 0)
1595 return -2;
1596 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1597 if (set_network(ifname, id, "key_mgmt",
1598 "WPA-PSK WPA-PSK-SHA256") < 0)
1599 return -2;
1600 } else {
1601 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1602 return -2;
1603 }
1604
1605 val = get_param(cmd, "passPhrase");
1606 if (val == NULL)
1607 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001608 if (type && strcasecmp(type, "SAE") == 0) {
1609 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1610 return -2;
1611 } else {
1612 if (set_network_quoted(ifname, id, "psk", val) < 0)
1613 return -2;
1614 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001615
Jouni Malinen992a81e2017-08-22 13:57:47 +03001616 val = get_param(cmd, "ECGroupID");
1617 if (val) {
1618 char buf[50];
1619
1620 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1621 if (wpa_command(ifname, buf) != 0) {
1622 sigma_dut_print(dut, DUT_MSG_ERROR,
1623 "Failed to clear sae_groups");
1624 return -2;
1625 }
1626 }
1627
Jouni Malinen68143132017-09-02 02:34:08 +03001628 val = get_param(cmd, "InvalidSAEElement");
1629 if (val) {
1630 free(dut->sae_commit_override);
1631 dut->sae_commit_override = strdup(val);
1632 }
1633
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001634 return 1;
1635}
1636
1637
1638static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301639 const char *ifname, int username_identity,
1640 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301642 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643 int id;
1644 char buf[200];
1645#ifdef ANDROID
1646 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1647 int length;
1648#endif /* ANDROID */
1649
1650 id = set_wpa_common(dut, conn, ifname, cmd);
1651 if (id < 0)
1652 return id;
1653
1654 val = get_param(cmd, "keyMgmtType");
1655 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301656 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001657
Jouni Malinenad395a22017-09-01 21:13:46 +03001658 if (val && strcasecmp(val, "SuiteB") == 0) {
1659 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1660 0)
1661 return -2;
1662 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001663 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1664 return -2;
1665 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1666 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1667 return -2;
1668 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1669 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1670 return -2;
1671 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1672 dut->sta_pmf == STA_PMF_REQUIRED) {
1673 if (set_network(ifname, id, "key_mgmt",
1674 "WPA-EAP WPA-EAP-SHA256") < 0)
1675 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301676 } else if (akm && atoi(akm) == 14) {
1677 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1678 dut->sta_pmf == STA_PMF_REQUIRED) {
1679 if (set_network(ifname, id, "key_mgmt",
1680 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1681 return -2;
1682 } else {
1683 if (set_network(ifname, id, "key_mgmt",
1684 "WPA-EAP FILS-SHA256") < 0)
1685 return -2;
1686 }
1687
1688 if (set_network(ifname, id, "erp", "1") < 0)
1689 return -2;
1690 } else if (akm && atoi(akm) == 15) {
1691 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1692 dut->sta_pmf == STA_PMF_REQUIRED) {
1693 if (set_network(ifname, id, "key_mgmt",
1694 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1695 return -2;
1696 } else {
1697 if (set_network(ifname, id, "key_mgmt",
1698 "WPA-EAP FILS-SHA384") < 0)
1699 return -2;
1700 }
1701
1702 if (set_network(ifname, id, "erp", "1") < 0)
1703 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001704 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1705 if (set_network(ifname, id, "key_mgmt",
1706 "WPA-EAP WPA-EAP-SHA256") < 0)
1707 return -2;
1708 } else {
1709 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1710 return -2;
1711 }
1712
1713 val = get_param(cmd, "trustedRootCA");
1714 if (val) {
1715#ifdef ANDROID
1716 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1717 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1718 kvalue);
1719 if (length > 0) {
1720 sigma_dut_print(dut, DUT_MSG_INFO,
1721 "Use Android keystore [%s]", buf);
1722 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1723 val);
1724 goto ca_cert_selected;
1725 }
1726#endif /* ANDROID */
1727
1728 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1729#ifdef __linux__
1730 if (!file_exists(buf)) {
1731 char msg[300];
1732 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1733 "file (%s) not found", buf);
1734 send_resp(dut, conn, SIGMA_ERROR, msg);
1735 return -3;
1736 }
1737#endif /* __linux__ */
1738#ifdef ANDROID
1739ca_cert_selected:
1740#endif /* ANDROID */
1741 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1742 return -2;
1743 }
1744
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301745 if (username_identity) {
1746 val = get_param(cmd, "username");
1747 if (val) {
1748 if (set_network_quoted(ifname, id, "identity", val) < 0)
1749 return -2;
1750 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001751
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301752 val = get_param(cmd, "password");
1753 if (val) {
1754 if (set_network_quoted(ifname, id, "password", val) < 0)
1755 return -2;
1756 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001757 }
1758
1759 return id;
1760}
1761
1762
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001763static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1764{
1765 const char *val;
1766
1767 if (!cipher)
1768 return 0;
1769
1770 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1771 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1772 else if (strcasecmp(cipher,
1773 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1774 val = "ECDHE-RSA-AES256-GCM-SHA384";
1775 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1776 val = "DHE-RSA-AES256-GCM-SHA384";
1777 else if (strcasecmp(cipher,
1778 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1779 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1780 else
1781 return -1;
1782
1783 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1784 set_network_quoted(ifname, id, "phase1", "");
1785
1786 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1787}
1788
1789
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001790static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1791 struct sigma_cmd *cmd)
1792{
1793 const char *intf = get_param(cmd, "Interface");
1794 const char *ifname, *val;
1795 int id;
1796 char buf[200];
1797#ifdef ANDROID
1798 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1799 int length;
1800 int jb_or_newer = 0;
1801 char prop[PROPERTY_VALUE_MAX];
1802#endif /* ANDROID */
1803
1804 if (intf == NULL)
1805 return -1;
1806
1807 if (strcmp(intf, get_main_ifname()) == 0)
1808 ifname = get_station_ifname();
1809 else
1810 ifname = intf;
1811
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301812 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001813 if (id < 0)
1814 return id;
1815
1816 if (set_network(ifname, id, "eap", "TLS") < 0)
1817 return -2;
1818
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301819 if (!get_param(cmd, "username") &&
1820 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001821 "wifi-user@wifilabs.local") < 0)
1822 return -2;
1823
1824 val = get_param(cmd, "clientCertificate");
1825 if (val == NULL)
1826 return -1;
1827#ifdef ANDROID
1828 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1829 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1830 if (length < 0) {
1831 /*
1832 * JB started reporting keystore type mismatches, so retry with
1833 * the GET_PUBKEY command if the generic GET fails.
1834 */
1835 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1836 buf, kvalue);
1837 }
1838
1839 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1840 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1841 if (strncmp(prop, "4.0", 3) != 0)
1842 jb_or_newer = 1;
1843 } else
1844 jb_or_newer = 1; /* assume newer */
1845
1846 if (jb_or_newer && length > 0) {
1847 sigma_dut_print(dut, DUT_MSG_INFO,
1848 "Use Android keystore [%s]", buf);
1849 if (set_network(ifname, id, "engine", "1") < 0)
1850 return -2;
1851 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1852 return -2;
1853 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1854 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1855 return -2;
1856 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1857 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1858 return -2;
1859 return 1;
1860 } else if (length > 0) {
1861 sigma_dut_print(dut, DUT_MSG_INFO,
1862 "Use Android keystore [%s]", buf);
1863 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1864 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1865 return -2;
1866 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1867 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1868 return -2;
1869 return 1;
1870 }
1871#endif /* ANDROID */
1872
1873 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1874#ifdef __linux__
1875 if (!file_exists(buf)) {
1876 char msg[300];
1877 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1878 "(%s) not found", buf);
1879 send_resp(dut, conn, SIGMA_ERROR, msg);
1880 return -3;
1881 }
1882#endif /* __linux__ */
1883 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1884 return -2;
1885 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1886 return -2;
1887
1888 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1889 return -2;
1890
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001891 val = get_param(cmd, "keyMgmtType");
1892 if (val && strcasecmp(val, "SuiteB") == 0) {
1893 val = get_param(cmd, "CertType");
1894 if (val && strcasecmp(val, "RSA") == 0) {
1895 if (set_network_quoted(ifname, id, "phase1",
1896 "tls_suiteb=1") < 0)
1897 return -2;
1898 } else {
1899 if (set_network_quoted(ifname, id, "openssl_ciphers",
1900 "SUITEB192") < 0)
1901 return -2;
1902 }
1903
1904 val = get_param(cmd, "TLSCipher");
1905 if (set_tls_cipher(ifname, id, val) < 0) {
1906 send_resp(dut, conn, SIGMA_ERROR,
1907 "ErrorCode,Unsupported TLSCipher value");
1908 return -3;
1909 }
1910 }
1911
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001912 return 1;
1913}
1914
1915
1916static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1917 struct sigma_cmd *cmd)
1918{
1919 const char *intf = get_param(cmd, "Interface");
1920 const char *ifname;
1921 int id;
1922
1923 if (intf == NULL)
1924 return -1;
1925
1926 if (strcmp(intf, get_main_ifname()) == 0)
1927 ifname = get_station_ifname();
1928 else
1929 ifname = intf;
1930
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301931 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 if (id < 0)
1933 return id;
1934
1935 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1936 send_resp(dut, conn, SIGMA_ERROR,
1937 "errorCode,Failed to set TTLS method");
1938 return 0;
1939 }
1940
1941 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1942 send_resp(dut, conn, SIGMA_ERROR,
1943 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1944 return 0;
1945 }
1946
1947 return 1;
1948}
1949
1950
1951static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1952 struct sigma_cmd *cmd)
1953{
1954 const char *intf = get_param(cmd, "Interface");
1955 const char *ifname;
1956 int id;
1957
1958 if (intf == NULL)
1959 return -1;
1960
1961 if (strcmp(intf, get_main_ifname()) == 0)
1962 ifname = get_station_ifname();
1963 else
1964 ifname = intf;
1965
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301966 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001967 if (id < 0)
1968 return id;
1969
1970 if (set_network(ifname, id, "eap", "SIM") < 0)
1971 return -2;
1972
1973 return 1;
1974}
1975
1976
1977static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1978 struct sigma_cmd *cmd)
1979{
1980 const char *intf = get_param(cmd, "Interface");
1981 const char *ifname, *val;
1982 int id;
1983 char buf[100];
1984
1985 if (intf == NULL)
1986 return -1;
1987
1988 if (strcmp(intf, get_main_ifname()) == 0)
1989 ifname = get_station_ifname();
1990 else
1991 ifname = intf;
1992
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301993 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001994 if (id < 0)
1995 return id;
1996
1997 if (set_network(ifname, id, "eap", "PEAP") < 0)
1998 return -2;
1999
2000 val = get_param(cmd, "innerEAP");
2001 if (val) {
2002 if (strcasecmp(val, "MSCHAPv2") == 0) {
2003 if (set_network_quoted(ifname, id, "phase2",
2004 "auth=MSCHAPV2") < 0)
2005 return -2;
2006 } else if (strcasecmp(val, "GTC") == 0) {
2007 if (set_network_quoted(ifname, id, "phase2",
2008 "auth=GTC") < 0)
2009 return -2;
2010 } else
2011 return -1;
2012 }
2013
2014 val = get_param(cmd, "peapVersion");
2015 if (val) {
2016 int ver = atoi(val);
2017 if (ver < 0 || ver > 1)
2018 return -1;
2019 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2020 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2021 return -2;
2022 }
2023
2024 return 1;
2025}
2026
2027
2028static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2029 struct sigma_cmd *cmd)
2030{
2031 const char *intf = get_param(cmd, "Interface");
2032 const char *ifname, *val;
2033 int id;
2034 char buf[100];
2035
2036 if (intf == NULL)
2037 return -1;
2038
2039 if (strcmp(intf, get_main_ifname()) == 0)
2040 ifname = get_station_ifname();
2041 else
2042 ifname = intf;
2043
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302044 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002045 if (id < 0)
2046 return id;
2047
2048 if (set_network(ifname, id, "eap", "FAST") < 0)
2049 return -2;
2050
2051 val = get_param(cmd, "innerEAP");
2052 if (val) {
2053 if (strcasecmp(val, "MSCHAPV2") == 0) {
2054 if (set_network_quoted(ifname, id, "phase2",
2055 "auth=MSCHAPV2") < 0)
2056 return -2;
2057 } else if (strcasecmp(val, "GTC") == 0) {
2058 if (set_network_quoted(ifname, id, "phase2",
2059 "auth=GTC") < 0)
2060 return -2;
2061 } else
2062 return -1;
2063 }
2064
2065 val = get_param(cmd, "validateServer");
2066 if (val) {
2067 /* TODO */
2068 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2069 "validateServer=%s", val);
2070 }
2071
2072 val = get_param(cmd, "pacFile");
2073 if (val) {
2074 snprintf(buf, sizeof(buf), "blob://%s", val);
2075 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2076 return -2;
2077 }
2078
2079 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2080 0)
2081 return -2;
2082
2083 return 1;
2084}
2085
2086
2087static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2088 struct sigma_cmd *cmd)
2089{
2090 const char *intf = get_param(cmd, "Interface");
2091 const char *ifname;
2092 int id;
2093
2094 if (intf == NULL)
2095 return -1;
2096
2097 if (strcmp(intf, get_main_ifname()) == 0)
2098 ifname = get_station_ifname();
2099 else
2100 ifname = intf;
2101
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302102 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 if (id < 0)
2104 return id;
2105
2106 if (set_network(ifname, id, "eap", "AKA") < 0)
2107 return -2;
2108
2109 return 1;
2110}
2111
2112
2113static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2114 struct sigma_conn *conn,
2115 struct sigma_cmd *cmd)
2116{
2117 const char *intf = get_param(cmd, "Interface");
2118 const char *ifname;
2119 int id;
2120
2121 if (intf == NULL)
2122 return -1;
2123
2124 if (strcmp(intf, get_main_ifname()) == 0)
2125 ifname = get_station_ifname();
2126 else
2127 ifname = intf;
2128
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302129 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 if (id < 0)
2131 return id;
2132
2133 if (set_network(ifname, id, "eap", "AKA'") < 0)
2134 return -2;
2135
2136 return 1;
2137}
2138
2139
2140static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2141 struct sigma_cmd *cmd)
2142{
2143 const char *intf = get_param(cmd, "Interface");
2144 const char *ifname;
2145 int id;
2146
2147 if (strcmp(intf, get_main_ifname()) == 0)
2148 ifname = get_station_ifname();
2149 else
2150 ifname = intf;
2151
2152 id = add_network_common(dut, conn, ifname, cmd);
2153 if (id < 0)
2154 return id;
2155
2156 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2157 return -2;
2158
2159 return 1;
2160}
2161
2162
Jouni Malinen47dcc952017-10-09 16:43:24 +03002163static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2164 struct sigma_cmd *cmd)
2165{
2166 const char *intf = get_param(cmd, "Interface");
2167 const char *ifname, *val;
2168 int id;
2169
2170 if (intf == NULL)
2171 return -1;
2172
2173 if (strcmp(intf, get_main_ifname()) == 0)
2174 ifname = get_station_ifname();
2175 else
2176 ifname = intf;
2177
2178 id = set_wpa_common(dut, conn, ifname, cmd);
2179 if (id < 0)
2180 return id;
2181
2182 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2183 return -2;
2184
2185 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002186 if (val && strcmp(val, "0") == 0) {
2187 if (wpa_command(ifname,
2188 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2189 sigma_dut_print(dut, DUT_MSG_ERROR,
2190 "Failed to set OWE DH Param element override");
2191 return -2;
2192 }
2193 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002194 sigma_dut_print(dut, DUT_MSG_ERROR,
2195 "Failed to clear owe_group");
2196 return -2;
2197 }
2198
2199 return 1;
2200}
2201
2202
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002203static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2204 struct sigma_cmd *cmd)
2205{
2206 const char *type = get_param(cmd, "Type");
2207
2208 if (type == NULL) {
2209 send_resp(dut, conn, SIGMA_ERROR,
2210 "ErrorCode,Missing Type argument");
2211 return 0;
2212 }
2213
2214 if (strcasecmp(type, "OPEN") == 0)
2215 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002216 if (strcasecmp(type, "OWE") == 0)
2217 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002218 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002219 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002220 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002221 return cmd_sta_set_psk(dut, conn, cmd);
2222 if (strcasecmp(type, "EAPTLS") == 0)
2223 return cmd_sta_set_eaptls(dut, conn, cmd);
2224 if (strcasecmp(type, "EAPTTLS") == 0)
2225 return cmd_sta_set_eapttls(dut, conn, cmd);
2226 if (strcasecmp(type, "EAPPEAP") == 0)
2227 return cmd_sta_set_peap(dut, conn, cmd);
2228 if (strcasecmp(type, "EAPSIM") == 0)
2229 return cmd_sta_set_eapsim(dut, conn, cmd);
2230 if (strcasecmp(type, "EAPFAST") == 0)
2231 return cmd_sta_set_eapfast(dut, conn, cmd);
2232 if (strcasecmp(type, "EAPAKA") == 0)
2233 return cmd_sta_set_eapaka(dut, conn, cmd);
2234 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2235 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002236 if (strcasecmp(type, "wep") == 0)
2237 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002238
2239 send_resp(dut, conn, SIGMA_ERROR,
2240 "ErrorCode,Unsupported Type value");
2241 return 0;
2242}
2243
2244
2245int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2246{
2247#ifdef __linux__
2248 /* special handling for ath6kl */
2249 char path[128], fname[128], *pos;
2250 ssize_t res;
2251 FILE *f;
2252
2253 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2254 res = readlink(path, path, sizeof(path));
2255 if (res < 0)
2256 return 0; /* not ath6kl */
2257
2258 if (res >= (int) sizeof(path))
2259 res = sizeof(path) - 1;
2260 path[res] = '\0';
2261 pos = strrchr(path, '/');
2262 if (pos == NULL)
2263 pos = path;
2264 else
2265 pos++;
2266 snprintf(fname, sizeof(fname),
2267 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2268 "create_qos", pos);
2269 if (!file_exists(fname))
2270 return 0; /* not ath6kl */
2271
2272 if (uapsd) {
2273 f = fopen(fname, "w");
2274 if (f == NULL)
2275 return -1;
2276
2277 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2278 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2279 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2280 "20000 0\n");
2281 fclose(f);
2282 } else {
2283 snprintf(fname, sizeof(fname),
2284 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2285 "delete_qos", pos);
2286
2287 f = fopen(fname, "w");
2288 if (f == NULL)
2289 return -1;
2290
2291 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2292 fprintf(f, "2 4\n");
2293 fclose(f);
2294 }
2295#endif /* __linux__ */
2296
2297 return 0;
2298}
2299
2300
2301static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2302 struct sigma_cmd *cmd)
2303{
2304 const char *intf = get_param(cmd, "Interface");
2305 /* const char *ssid = get_param(cmd, "ssid"); */
2306 const char *val;
2307 int max_sp_len = 4;
2308 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2309 char buf[100];
2310 int ret1, ret2;
2311
2312 val = get_param(cmd, "maxSPLength");
2313 if (val) {
2314 max_sp_len = atoi(val);
2315 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2316 max_sp_len != 4)
2317 return -1;
2318 }
2319
2320 val = get_param(cmd, "acBE");
2321 if (val)
2322 ac_be = atoi(val);
2323
2324 val = get_param(cmd, "acBK");
2325 if (val)
2326 ac_bk = atoi(val);
2327
2328 val = get_param(cmd, "acVI");
2329 if (val)
2330 ac_vi = atoi(val);
2331
2332 val = get_param(cmd, "acVO");
2333 if (val)
2334 ac_vo = atoi(val);
2335
2336 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2337
2338 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2339 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2340 ret1 = wpa_command(intf, buf);
2341
2342 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2343 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2344 ret2 = wpa_command(intf, buf);
2345
2346 if (ret1 && ret2) {
2347 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2348 "UAPSD parameters.");
2349 return -2;
2350 }
2351
2352 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2353 send_resp(dut, conn, SIGMA_ERROR,
2354 "ErrorCode,Failed to set ath6kl QoS parameters");
2355 return 0;
2356 }
2357
2358 return 1;
2359}
2360
2361
2362static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2363 struct sigma_cmd *cmd)
2364{
2365 char buf[1000];
2366 const char *intf = get_param(cmd, "Interface");
2367 const char *grp = get_param(cmd, "Group");
2368 const char *act = get_param(cmd, "Action");
2369 const char *tid = get_param(cmd, "Tid");
2370 const char *dir = get_param(cmd, "Direction");
2371 const char *psb = get_param(cmd, "Psb");
2372 const char *up = get_param(cmd, "Up");
2373 const char *fixed = get_param(cmd, "Fixed");
2374 const char *size = get_param(cmd, "Size");
2375 const char *msize = get_param(cmd, "Maxsize");
2376 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2377 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2378 const char *inact = get_param(cmd, "Inactivity");
2379 const char *sus = get_param(cmd, "Suspension");
2380 const char *mindr = get_param(cmd, "Mindatarate");
2381 const char *meandr = get_param(cmd, "Meandatarate");
2382 const char *peakdr = get_param(cmd, "Peakdatarate");
2383 const char *phyrate = get_param(cmd, "Phyrate");
2384 const char *burstsize = get_param(cmd, "Burstsize");
2385 const char *sba = get_param(cmd, "Sba");
2386 int direction;
2387 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002388 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002389 int fixed_int;
2390 int psb_ts;
2391
2392 if (intf == NULL || grp == NULL || act == NULL )
2393 return -1;
2394
2395 if (strcasecmp(act, "addts") == 0) {
2396 if (tid == NULL || dir == NULL || psb == NULL ||
2397 up == NULL || fixed == NULL || size == NULL)
2398 return -1;
2399
2400 /*
2401 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2402 * possible values, but WMM-AC and V-E test scripts use "UP,
2403 * "DOWN", and "BIDI".
2404 */
2405 if (strcasecmp(dir, "uplink") == 0 ||
2406 strcasecmp(dir, "up") == 0) {
2407 direction = 0;
2408 } else if (strcasecmp(dir, "downlink") == 0 ||
2409 strcasecmp(dir, "down") == 0) {
2410 direction = 1;
2411 } else if (strcasecmp(dir, "bidi") == 0) {
2412 direction = 2;
2413 } else {
2414 sigma_dut_print(dut, DUT_MSG_ERROR,
2415 "Direction %s not supported", dir);
2416 return -1;
2417 }
2418
2419 if (strcasecmp(psb, "legacy") == 0) {
2420 psb_ts = 0;
2421 } else if (strcasecmp(psb, "uapsd") == 0) {
2422 psb_ts = 1;
2423 } else {
2424 sigma_dut_print(dut, DUT_MSG_ERROR,
2425 "PSB %s not supported", psb);
2426 return -1;
2427 }
2428
2429 if (atoi(tid) < 0 || atoi(tid) > 7) {
2430 sigma_dut_print(dut, DUT_MSG_ERROR,
2431 "TID %s not supported", tid);
2432 return -1;
2433 }
2434
2435 if (strcasecmp(fixed, "true") == 0) {
2436 fixed_int = 1;
2437 } else {
2438 fixed_int = 0;
2439 }
2440
Peng Xu93319622017-10-04 17:58:16 -07002441 if (sba)
2442 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002443
2444 dut->dialog_token++;
2445 handle = 7000 + dut->dialog_token;
2446
2447 /*
2448 * size: convert to hex
2449 * maxsi: convert to hex
2450 * mindr: convert to hex
2451 * meandr: convert to hex
2452 * peakdr: convert to hex
2453 * burstsize: convert to hex
2454 * phyrate: convert to hex
2455 * sba: convert to hex with modification
2456 * minsi: convert to integer
2457 * sus: convert to integer
2458 * inact: convert to integer
2459 * maxsi: convert to integer
2460 */
2461
2462 /*
2463 * The Nominal MSDU Size field is 2 octets long and contains an
2464 * unsigned integer that specifies the nominal size, in octets,
2465 * of MSDUs belonging to the traffic under this traffic
2466 * specification and is defined in Figure 16. If the Fixed
2467 * subfield is set to 1, then the size of the MSDU is fixed and
2468 * is indicated by the Size Subfield. If the Fixed subfield is
2469 * set to 0, then the size of the MSDU might not be fixed and
2470 * the Size indicates the nominal MSDU size.
2471 *
2472 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2473 * and specifies the excess allocation of time (and bandwidth)
2474 * over and above the stated rates required to transport an MSDU
2475 * belonging to the traffic in this TSPEC. This field is
2476 * represented as an unsigned binary number with an implicit
2477 * binary point after the leftmost 3 bits. For example, an SBA
2478 * of 1.75 is represented as 0x3800. This field is included to
2479 * account for retransmissions. As such, the value of this field
2480 * must be greater than unity.
2481 */
2482
2483 snprintf(buf, sizeof(buf),
2484 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2485 " 0x%X 0x%X 0x%X"
2486 " 0x%X 0x%X 0x%X"
2487 " 0x%X %d %d %d %d"
2488 " %d %d",
2489 intf, handle, tid, direction, psb_ts, up,
2490 (unsigned int) ((fixed_int << 15) | atoi(size)),
2491 msize ? atoi(msize) : 0,
2492 mindr ? atoi(mindr) : 0,
2493 meandr ? atoi(meandr) : 0,
2494 peakdr ? atoi(peakdr) : 0,
2495 burstsize ? atoi(burstsize) : 0,
2496 phyrate ? atoi(phyrate) : 0,
2497 sba ? ((unsigned int) (((int) sba_fv << 13) |
2498 (int)((sba_fv - (int) sba_fv) *
2499 8192))) : 0,
2500 minsi ? atoi(minsi) : 0,
2501 sus ? atoi(sus) : 0,
2502 0, 0,
2503 inact ? atoi(inact) : 0,
2504 maxsi ? atoi(maxsi) : 0);
2505
2506 if (system(buf) != 0) {
2507 sigma_dut_print(dut, DUT_MSG_ERROR,
2508 "iwpriv addtspec request failed");
2509 send_resp(dut, conn, SIGMA_ERROR,
2510 "errorCode,Failed to execute addTspec command");
2511 return 0;
2512 }
2513
2514 sigma_dut_print(dut, DUT_MSG_INFO,
2515 "iwpriv addtspec request send");
2516
2517 /* Mapping handle to a TID */
2518 dut->tid_to_handle[atoi(tid)] = handle;
2519 } else if (strcasecmp(act, "delts") == 0) {
2520 if (tid == NULL)
2521 return -1;
2522
2523 if (atoi(tid) < 0 || atoi(tid) > 7) {
2524 sigma_dut_print(dut, DUT_MSG_ERROR,
2525 "TID %s not supported", tid);
2526 send_resp(dut, conn, SIGMA_ERROR,
2527 "errorCode,Unsupported TID");
2528 return 0;
2529 }
2530
2531 handle = dut->tid_to_handle[atoi(tid)];
2532
2533 if (handle < 7000 || handle > 7255) {
2534 /* Invalid handle ie no mapping for that TID */
2535 sigma_dut_print(dut, DUT_MSG_ERROR,
2536 "handle-> %d not found", handle);
2537 }
2538
2539 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2540 intf, handle);
2541
2542 if (system(buf) != 0) {
2543 sigma_dut_print(dut, DUT_MSG_ERROR,
2544 "iwpriv deltspec request failed");
2545 send_resp(dut, conn, SIGMA_ERROR,
2546 "errorCode,Failed to execute delTspec command");
2547 return 0;
2548 }
2549
2550 sigma_dut_print(dut, DUT_MSG_INFO,
2551 "iwpriv deltspec request send");
2552
2553 dut->tid_to_handle[atoi(tid)] = 0;
2554 } else {
2555 sigma_dut_print(dut, DUT_MSG_ERROR,
2556 "Action type %s not supported", act);
2557 send_resp(dut, conn, SIGMA_ERROR,
2558 "errorCode,Unsupported Action");
2559 return 0;
2560 }
2561
2562 return 1;
2563}
2564
2565
vamsi krishna52e16f92017-08-29 12:37:34 +05302566static int find_network(struct sigma_dut *dut, const char *ssid)
2567{
2568 char list[4096];
2569 char *pos;
2570
2571 sigma_dut_print(dut, DUT_MSG_DEBUG,
2572 "Search for profile based on SSID: '%s'", ssid);
2573 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2574 list, sizeof(list)) < 0)
2575 return -1;
2576 pos = strstr(list, ssid);
2577 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2578 return -1;
2579
2580 while (pos > list && pos[-1] != '\n')
2581 pos--;
2582 dut->infra_network_id = atoi(pos);
2583 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2584 return 0;
2585}
2586
2587
Sunil Dutt44595082018-02-12 19:41:45 +05302588#ifdef NL80211_SUPPORT
2589static int sta_config_rsnie(struct sigma_dut *dut, int val)
2590{
2591 struct nl_msg *msg;
2592 int ret;
2593 struct nlattr *params;
2594 int ifindex;
2595
2596 ifindex = if_nametoindex("wlan0");
2597 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2598 NL80211_CMD_VENDOR)) ||
2599 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2600 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2601 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2602 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2603 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2604 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2605 sigma_dut_print(dut, DUT_MSG_ERROR,
2606 "%s: err in adding vendor_cmd and vendor_data",
2607 __func__);
2608 nlmsg_free(msg);
2609 return -1;
2610 }
2611 nla_nest_end(msg, params);
2612
2613 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2614 if (ret) {
2615 sigma_dut_print(dut, DUT_MSG_ERROR,
2616 "%s: err in send_and_recv_msgs, ret=%d",
2617 __func__, ret);
2618 return ret;
2619 }
2620
2621 return 0;
2622}
2623#endif /* NL80211_SUPPORT */
2624
2625
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002626static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2627 struct sigma_cmd *cmd)
2628{
2629 /* const char *intf = get_param(cmd, "Interface"); */
2630 const char *ssid = get_param(cmd, "ssid");
2631 const char *wps_param = get_param(cmd, "WPS");
2632 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002633 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002634 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002635 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002636
2637 if (ssid == NULL)
2638 return -1;
2639
Jouni Malinen3c367e82017-06-23 17:01:47 +03002640 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302641#ifdef NL80211_SUPPORT
2642 if (get_driver_type() == DRIVER_WCN) {
2643 sta_config_rsnie(dut, 1);
2644 dut->config_rsnie = 1;
2645 }
2646#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002647 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2648 dut->rsne_override);
2649 if (wpa_command(get_station_ifname(), buf) < 0) {
2650 send_resp(dut, conn, SIGMA_ERROR,
2651 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2652 return 0;
2653 }
2654 }
2655
Jouni Malinen68143132017-09-02 02:34:08 +03002656 if (dut->sae_commit_override) {
2657 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2658 dut->sae_commit_override);
2659 if (wpa_command(get_station_ifname(), buf) < 0) {
2660 send_resp(dut, conn, SIGMA_ERROR,
2661 "ErrorCode,Failed to set SAE commit override");
2662 return 0;
2663 }
2664 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302665#ifdef ANDROID
2666 if (dut->fils_hlp)
2667 process_fils_hlp(dut);
2668#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002670 if (wps_param &&
2671 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2672 wps = 1;
2673
2674 if (wps) {
2675 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2676 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2677 "parameters not yet set");
2678 return 0;
2679 }
2680 if (dut->wps_method == WFA_CS_WPS_PBC) {
2681 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2682 return -2;
2683 } else {
2684 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2685 dut->wps_pin);
2686 if (wpa_command(get_station_ifname(), buf) < 0)
2687 return -2;
2688 }
2689 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302690 if (strcmp(ssid, dut->infra_ssid) == 0) {
2691 sigma_dut_print(dut, DUT_MSG_DEBUG,
2692 "sta_associate for the most recently added network");
2693 } else if (find_network(dut, ssid) < 0) {
2694 sigma_dut_print(dut, DUT_MSG_DEBUG,
2695 "sta_associate for a previously stored network profile");
2696 send_resp(dut, conn, SIGMA_ERROR,
2697 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002698 return 0;
2699 }
2700
2701 if (bssid &&
2702 set_network(get_station_ifname(), dut->infra_network_id,
2703 "bssid", bssid) < 0) {
2704 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2705 "Invalid bssid argument");
2706 return 0;
2707 }
2708
Jouni Malinen46a19b62017-06-23 14:31:27 +03002709 extra[0] = '\0';
2710 if (chan)
2711 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02002712 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03002713 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2714 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002715 if (wpa_command(get_station_ifname(), buf) < 0) {
2716 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2717 "network id %d on %s",
2718 dut->infra_network_id,
2719 get_station_ifname());
2720 return -2;
2721 }
2722 }
2723
2724 return 1;
2725}
2726
2727
2728static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2729{
2730 char buf[500], cmd[200];
2731 int res;
2732
2733 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2734 * default path */
2735 res = snprintf(cmd, sizeof(cmd),
2736 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2737 file_exists("./hs20-osu-client") ?
2738 "./hs20-osu-client" : "hs20-osu-client",
2739 sigma_wpas_ctrl,
2740 dut->summary_log ? "-s " : "",
2741 dut->summary_log ? dut->summary_log : "");
2742 if (res < 0 || res >= (int) sizeof(cmd))
2743 return -1;
2744
2745 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2746 if (res < 0 || res >= (int) sizeof(buf))
2747 return -1;
2748 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2749
2750 if (system(buf) != 0) {
2751 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2752 return -1;
2753 }
2754 sigma_dut_print(dut, DUT_MSG_DEBUG,
2755 "Completed hs20-osu-client operation");
2756
2757 return 0;
2758}
2759
2760
2761static int download_ppsmo(struct sigma_dut *dut,
2762 struct sigma_conn *conn,
2763 const char *intf,
2764 struct sigma_cmd *cmd)
2765{
2766 const char *name, *path, *val;
2767 char url[500], buf[600], fbuf[100];
2768 char *fqdn = NULL;
2769
2770 name = get_param(cmd, "FileName");
2771 path = get_param(cmd, "FilePath");
2772 if (name == NULL || path == NULL)
2773 return -1;
2774
2775 if (strcasecmp(path, "VendorSpecific") == 0) {
2776 snprintf(url, sizeof(url), "PPS/%s", name);
2777 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2778 "from the device (%s)", url);
2779 if (!file_exists(url)) {
2780 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2781 "PPS MO file does not exist");
2782 return 0;
2783 }
2784 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2785 if (system(buf) != 0) {
2786 send_resp(dut, conn, SIGMA_ERROR,
2787 "errorCode,Failed to copy PPS MO");
2788 return 0;
2789 }
2790 } else if (strncasecmp(path, "http:", 5) != 0 &&
2791 strncasecmp(path, "https:", 6) != 0) {
2792 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2793 "Unsupported FilePath value");
2794 return 0;
2795 } else {
2796 snprintf(url, sizeof(url), "%s/%s", path, name);
2797 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2798 url);
2799 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2800 remove("pps-tnds.xml");
2801 if (system(buf) != 0) {
2802 send_resp(dut, conn, SIGMA_ERROR,
2803 "errorCode,Failed to download PPS MO");
2804 return 0;
2805 }
2806 }
2807
2808 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2809 send_resp(dut, conn, SIGMA_ERROR,
2810 "errorCode,Failed to parse downloaded PPSMO");
2811 return 0;
2812 }
2813 unlink("pps-tnds.xml");
2814
2815 val = get_param(cmd, "managementTreeURI");
2816 if (val) {
2817 const char *pos, *end;
2818 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2819 val);
2820 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2821 send_resp(dut, conn, SIGMA_ERROR,
2822 "errorCode,Invalid managementTreeURI prefix");
2823 return 0;
2824 }
2825 pos = val + 8;
2826 end = strchr(pos, '/');
2827 if (end == NULL ||
2828 strcmp(end, "/PerProviderSubscription") != 0) {
2829 send_resp(dut, conn, SIGMA_ERROR,
2830 "errorCode,Invalid managementTreeURI postfix");
2831 return 0;
2832 }
2833 if (end - pos >= (int) sizeof(fbuf)) {
2834 send_resp(dut, conn, SIGMA_ERROR,
2835 "errorCode,Too long FQDN in managementTreeURI");
2836 return 0;
2837 }
2838 memcpy(fbuf, pos, end - pos);
2839 fbuf[end - pos] = '\0';
2840 fqdn = fbuf;
2841 sigma_dut_print(dut, DUT_MSG_INFO,
2842 "FQDN from managementTreeURI: %s", fqdn);
2843 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2844 FILE *f = fopen("pps-fqdn", "r");
2845 if (f) {
2846 if (fgets(fbuf, sizeof(fbuf), f)) {
2847 fbuf[sizeof(fbuf) - 1] = '\0';
2848 fqdn = fbuf;
2849 sigma_dut_print(dut, DUT_MSG_DEBUG,
2850 "Use FQDN %s", fqdn);
2851 }
2852 fclose(f);
2853 }
2854 }
2855
2856 if (fqdn == NULL) {
2857 send_resp(dut, conn, SIGMA_ERROR,
2858 "errorCode,No FQDN specified");
2859 return 0;
2860 }
2861
2862 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2863 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2864 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2865
2866 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2867 if (rename("pps.xml", buf) < 0) {
2868 send_resp(dut, conn, SIGMA_ERROR,
2869 "errorCode,Could not move PPS MO");
2870 return 0;
2871 }
2872
2873 if (strcasecmp(path, "VendorSpecific") == 0) {
2874 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2875 fqdn);
2876 if (system(buf)) {
2877 send_resp(dut, conn, SIGMA_ERROR,
2878 "errorCode,Failed to copy OSU CA cert");
2879 return 0;
2880 }
2881
2882 snprintf(buf, sizeof(buf),
2883 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2884 fqdn);
2885 if (system(buf)) {
2886 send_resp(dut, conn, SIGMA_ERROR,
2887 "errorCode,Failed to copy AAA CA cert");
2888 return 0;
2889 }
2890 } else {
2891 snprintf(buf, sizeof(buf),
2892 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2893 fqdn, fqdn);
2894 if (run_hs20_osu(dut, buf) < 0) {
2895 send_resp(dut, conn, SIGMA_ERROR,
2896 "errorCode,Failed to download OSU CA cert");
2897 return 0;
2898 }
2899
2900 snprintf(buf, sizeof(buf),
2901 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2902 fqdn, fqdn);
2903 if (run_hs20_osu(dut, buf) < 0) {
2904 sigma_dut_print(dut, DUT_MSG_INFO,
2905 "Failed to download AAA CA cert");
2906 }
2907 }
2908
2909 if (file_exists("next-client-cert.pem")) {
2910 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2911 if (rename("next-client-cert.pem", buf) < 0) {
2912 send_resp(dut, conn, SIGMA_ERROR,
2913 "errorCode,Could not move client certificate");
2914 return 0;
2915 }
2916 }
2917
2918 if (file_exists("next-client-key.pem")) {
2919 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2920 if (rename("next-client-key.pem", buf) < 0) {
2921 send_resp(dut, conn, SIGMA_ERROR,
2922 "errorCode,Could not move client key");
2923 return 0;
2924 }
2925 }
2926
2927 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2928 if (run_hs20_osu(dut, buf) < 0) {
2929 send_resp(dut, conn, SIGMA_ERROR,
2930 "errorCode,Failed to configure credential from "
2931 "PPSMO");
2932 return 0;
2933 }
2934
2935 return 1;
2936}
2937
2938
2939static int download_cert(struct sigma_dut *dut,
2940 struct sigma_conn *conn,
2941 const char *intf,
2942 struct sigma_cmd *cmd)
2943{
2944 const char *name, *path;
2945 char url[500], buf[600];
2946
2947 name = get_param(cmd, "FileName");
2948 path = get_param(cmd, "FilePath");
2949 if (name == NULL || path == NULL)
2950 return -1;
2951
2952 if (strcasecmp(path, "VendorSpecific") == 0) {
2953 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2954 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2955 "certificate from the device (%s)", url);
2956 if (!file_exists(url)) {
2957 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2958 "certificate file does not exist");
2959 return 0;
2960 }
2961 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2962 if (system(buf) != 0) {
2963 send_resp(dut, conn, SIGMA_ERROR,
2964 "errorCode,Failed to copy client "
2965 "certificate");
2966 return 0;
2967 }
2968
2969 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2970 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2971 "private key from the device (%s)", url);
2972 if (!file_exists(url)) {
2973 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2974 "private key file does not exist");
2975 return 0;
2976 }
2977 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2978 if (system(buf) != 0) {
2979 send_resp(dut, conn, SIGMA_ERROR,
2980 "errorCode,Failed to copy client key");
2981 return 0;
2982 }
2983 } else if (strncasecmp(path, "http:", 5) != 0 &&
2984 strncasecmp(path, "https:", 6) != 0) {
2985 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2986 "Unsupported FilePath value");
2987 return 0;
2988 } else {
2989 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2990 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2991 "certificate/key from %s", url);
2992 snprintf(buf, sizeof(buf),
2993 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2994 if (system(buf) != 0) {
2995 send_resp(dut, conn, SIGMA_ERROR,
2996 "errorCode,Failed to download client "
2997 "certificate");
2998 return 0;
2999 }
3000
3001 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3002 {
3003 send_resp(dut, conn, SIGMA_ERROR,
3004 "errorCode,Failed to copy client key");
3005 return 0;
3006 }
3007 }
3008
3009 return 1;
3010}
3011
3012
3013static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3014 struct sigma_conn *conn,
3015 const char *intf,
3016 struct sigma_cmd *cmd)
3017{
3018 const char *val;
3019
3020 val = get_param(cmd, "FileType");
3021 if (val && strcasecmp(val, "PPSMO") == 0)
3022 return download_ppsmo(dut, conn, intf, cmd);
3023 if (val && strcasecmp(val, "CERT") == 0)
3024 return download_cert(dut, conn, intf, cmd);
3025 if (val) {
3026 send_resp(dut, conn, SIGMA_ERROR,
3027 "ErrorCode,Unsupported FileType");
3028 return 0;
3029 }
3030
3031 return 1;
3032}
3033
3034
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303035static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3036 struct sigma_conn *conn,
3037 const char *intf,
3038 struct sigma_cmd *cmd)
3039{
3040 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303041 char buf[1000];
3042 char text[20];
3043 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303044
3045 val = get_param(cmd, "OCESupport");
3046 if (val && strcasecmp(val, "Disable") == 0) {
3047 if (wpa_command(intf, "SET oce 0") < 0) {
3048 send_resp(dut, conn, SIGMA_ERROR,
3049 "ErrorCode,Failed to disable OCE");
3050 return 0;
3051 }
3052 } else if (val && strcasecmp(val, "Enable") == 0) {
3053 if (wpa_command(intf, "SET oce 1") < 0) {
3054 send_resp(dut, conn, SIGMA_ERROR,
3055 "ErrorCode,Failed to enable OCE");
3056 return 0;
3057 }
3058 }
3059
vamsi krishnaa2799492017-12-05 14:28:01 +05303060 val = get_param(cmd, "FILScap");
3061 if (val && (atoi(val) == 1)) {
3062 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3063 send_resp(dut, conn, SIGMA_ERROR,
3064 "ErrorCode,Failed to enable FILS");
3065 return 0;
3066 }
3067 } else if (val && (atoi(val) == 0)) {
3068 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3069 send_resp(dut, conn, SIGMA_ERROR,
3070 "ErrorCode,Failed to disable FILS");
3071 return 0;
3072 }
3073 }
3074
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303075 val = get_param(cmd, "FILSHLP");
3076 if (val && strcasecmp(val, "Enable") == 0) {
3077 if (get_wpa_status(get_station_ifname(), "address", text,
3078 sizeof(text)) < 0)
3079 return -2;
3080 hwaddr_aton(text, addr);
3081 snprintf(buf, sizeof(buf),
3082 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3083 "080045100140000040004011399e00000000ffffffff00440043"
3084 "012cb30001010600fd4f46410000000000000000000000000000"
3085 "000000000000"
3086 "%02x%02x%02x%02x%02x%02x"
3087 "0000000000000000000000000000000000000000000000000000"
3088 "0000000000000000000000000000000000000000000000000000"
3089 "0000000000000000000000000000000000000000000000000000"
3090 "0000000000000000000000000000000000000000000000000000"
3091 "0000000000000000000000000000000000000000000000000000"
3092 "0000000000000000000000000000000000000000000000000000"
3093 "0000000000000000000000000000000000000000000000000000"
3094 "0000000000000000000000000000000000000000638253633501"
3095 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3096 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3097 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3098 if (wpa_command(intf, buf)) {
3099 send_resp(dut, conn, SIGMA_ERROR,
3100 "ErrorCode,Failed to add HLP");
3101 return 0;
3102 }
3103 dut->fils_hlp = 1;
3104 }
3105
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303106 return 1;
3107}
3108
3109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3111 const char *val)
3112{
3113 int counter = 0;
3114 char token[50];
3115 char *result;
3116 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303117 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003118
Peng Xub8fc5cc2017-05-10 17:27:28 -07003119 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003120 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303121 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003122 while (result) {
3123 if (strcmp(result, "disable") == 0) {
3124 snprintf(buf, sizeof(buf),
3125 "iwpriv %s noackpolicy %d 1 0",
3126 intf, counter);
3127 } else {
3128 snprintf(buf, sizeof(buf),
3129 "iwpriv %s noackpolicy %d 1 1",
3130 intf, counter);
3131 }
3132 if (system(buf) != 0) {
3133 sigma_dut_print(dut, DUT_MSG_ERROR,
3134 "iwpriv noackpolicy failed");
3135 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303136 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003137 counter++;
3138 }
3139}
3140
3141
3142static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3143 const char *val)
3144{
3145 char buf[100];
3146
3147 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3148 if (system(buf) != 0) {
3149 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3150 }
3151}
3152
3153
3154static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3155 const char *val)
3156{
3157 char buf[100];
3158
3159 if (strcasecmp(val, "off") == 0) {
3160 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3161 if (system(buf) != 0) {
3162 sigma_dut_print(dut, DUT_MSG_ERROR,
3163 "Failed to turn off WMM");
3164 }
3165 }
3166}
3167
3168
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003169static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3170 const char *val)
3171{
3172#ifdef NL80211_SUPPORT
3173 struct nl_msg *msg;
3174 int ret = 0;
3175 struct nlattr *params;
3176 int ifindex;
3177 int wmmenable = 1;
3178
3179 if (val &&
3180 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3181 wmmenable = 0;
3182
3183 ifindex = if_nametoindex(intf);
3184 if (ifindex == 0) {
3185 sigma_dut_print(dut, DUT_MSG_ERROR,
3186 "%s: Index for interface %s failed",
3187 __func__, intf);
3188 return -1;
3189 }
3190
3191 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3192 NL80211_CMD_VENDOR)) ||
3193 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3194 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3195 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3196 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3197 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3198 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3199 wmmenable)) {
3200 sigma_dut_print(dut, DUT_MSG_ERROR,
3201 "%s: err in adding vendor_cmd and vendor_data",
3202 __func__);
3203 nlmsg_free(msg);
3204 return -1;
3205 }
3206 nla_nest_end(msg, params);
3207
3208 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3209 if (ret) {
3210 sigma_dut_print(dut, DUT_MSG_ERROR,
3211 "%s: err in send_and_recv_msgs, ret=%d",
3212 __func__, ret);
3213 }
3214 return ret;
3215#else /* NL80211_SUPPORT */
3216 sigma_dut_print(dut, DUT_MSG_ERROR,
3217 "WMM cannot be changed without NL80211_SUPPORT defined");
3218 return -1;
3219#endif /* NL80211_SUPPORT */
3220}
3221
3222
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3224 const char *val)
3225{
3226 char buf[100];
3227 int sgi20;
3228
3229 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3230
3231 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3232 if (system(buf) != 0)
3233 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3234}
3235
3236
3237static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3238 const char *val)
3239{
3240 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303241 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003242
3243 /* Disable Tx Beam forming when using a fixed rate */
3244 ath_disable_txbf(dut, intf);
3245
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303246 v = atoi(val);
3247 if (v < 0 || v > 32) {
3248 sigma_dut_print(dut, DUT_MSG_ERROR,
3249 "Invalid Fixed MCS rate: %d", v);
3250 return;
3251 }
3252 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003253
3254 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3255 intf, rate_code);
3256 if (system(buf) != 0) {
3257 sigma_dut_print(dut, DUT_MSG_ERROR,
3258 "iwpriv set11NRates failed");
3259 }
3260
3261 /* Channel width gets messed up, fix this */
3262 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3263 if (system(buf) != 0)
3264 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3265}
3266
3267
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003268static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3269 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003270{
3271 char buf[60];
3272
3273 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3274 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3275 else
3276 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3277
3278 if (system(buf) != 0)
3279 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3280}
3281
3282
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003283static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3284 int ampdu)
3285{
3286 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003287 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003288
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003289 if (ampdu)
3290 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003291 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3292 if (system(buf) != 0) {
3293 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3294 return -1;
3295 }
3296
3297 return 0;
3298}
3299
3300
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003301static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3302 const char *val)
3303{
3304 char buf[60];
3305
3306 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3307 if (system(buf) != 0) {
3308 sigma_dut_print(dut, DUT_MSG_ERROR,
3309 "iwpriv tx_stbc failed");
3310 }
3311
3312 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3313 if (system(buf) != 0) {
3314 sigma_dut_print(dut, DUT_MSG_ERROR,
3315 "iwpriv rx_stbc failed");
3316 }
3317}
3318
3319
3320static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3321 const char *val)
3322{
3323 char buf[60];
3324
Peng Xucc317ed2017-05-18 16:44:37 -07003325 if (strcmp(val, "160") == 0) {
3326 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3327 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003328 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3329 } else if (strcmp(val, "40") == 0) {
3330 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3331 } else if (strcmp(val, "20") == 0) {
3332 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3333 } else if (strcasecmp(val, "Auto") == 0) {
3334 buf[0] = '\0';
3335 } else {
3336 sigma_dut_print(dut, DUT_MSG_ERROR,
3337 "WIDTH/CTS_WIDTH value not supported");
3338 return -1;
3339 }
3340
3341 if (buf[0] != '\0' && system(buf) != 0) {
3342 sigma_dut_print(dut, DUT_MSG_ERROR,
3343 "Failed to set WIDTH/CTS_WIDTH");
3344 return -1;
3345 }
3346
3347 return 0;
3348}
3349
3350
3351int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3352 const char *intf, const char *val)
3353{
3354 char buf[60];
3355
3356 if (strcasecmp(val, "Auto") == 0) {
3357 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3358 dut->chwidth = 0;
3359 } else if (strcasecmp(val, "20") == 0) {
3360 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3361 dut->chwidth = 0;
3362 } else if (strcasecmp(val, "40") == 0) {
3363 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3364 dut->chwidth = 1;
3365 } else if (strcasecmp(val, "80") == 0) {
3366 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3367 dut->chwidth = 2;
3368 } else if (strcasecmp(val, "160") == 0) {
3369 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3370 dut->chwidth = 3;
3371 } else {
3372 send_resp(dut, conn, SIGMA_ERROR,
3373 "ErrorCode,WIDTH not supported");
3374 return -1;
3375 }
3376
3377 if (system(buf) != 0) {
3378 sigma_dut_print(dut, DUT_MSG_ERROR,
3379 "iwpriv chwidth failed");
3380 }
3381
3382 return 0;
3383}
3384
3385
3386static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3387 const char *val)
3388{
3389 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003390 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003391
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003392 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003393 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003394 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003395 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003396 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003397 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003398 } else {
3399 sigma_dut_print(dut, DUT_MSG_ERROR,
3400 "SP_STREAM value not supported");
3401 return -1;
3402 }
3403
3404 if (system(buf) != 0) {
3405 sigma_dut_print(dut, DUT_MSG_ERROR,
3406 "Failed to set SP_STREAM");
3407 return -1;
3408 }
3409
Arif Hussainac6c5112018-05-25 17:34:00 -07003410 dut->sta_nss = sta_nss;
3411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003412 return 0;
3413}
3414
3415
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303416static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3417 const char *val)
3418{
3419 char buf[60];
3420
3421 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3422 if (system(buf) != 0)
3423 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3424
3425 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3426 if (system(buf) != 0)
3427 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3428}
3429
3430
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303431static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3432 struct sigma_conn *conn,
3433 const char *intf, int capa)
3434{
3435 char buf[32];
3436
3437 if (capa > 0 && capa < 4) {
3438 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3439 if (wpa_command(intf, buf) < 0) {
3440 send_resp(dut, conn, SIGMA_ERROR,
3441 "ErrorCode, Failed to set cellular data capability");
3442 return 0;
3443 }
3444 return 1;
3445 }
3446
3447 sigma_dut_print(dut, DUT_MSG_ERROR,
3448 "Invalid Cellular data capability: %d", capa);
3449 send_resp(dut, conn, SIGMA_INVALID,
3450 "ErrorCode,Invalid cellular data capability");
3451 return 0;
3452}
3453
3454
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303455static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3456 const char *intf, const char *val)
3457{
3458 if (strcasecmp(val, "Disable") == 0) {
3459 if (wpa_command(intf, "SET roaming 0") < 0) {
3460 send_resp(dut, conn, SIGMA_ERROR,
3461 "ErrorCode,Failed to disable roaming");
3462 return 0;
3463 }
3464 return 1;
3465 }
3466
3467 if (strcasecmp(val, "Enable") == 0) {
3468 if (wpa_command(intf, "SET roaming 1") < 0) {
3469 send_resp(dut, conn, SIGMA_ERROR,
3470 "ErrorCode,Failed to enable roaming");
3471 return 0;
3472 }
3473 return 1;
3474 }
3475
3476 sigma_dut_print(dut, DUT_MSG_ERROR,
3477 "Invalid value provided for roaming: %s", val);
3478 send_resp(dut, conn, SIGMA_INVALID,
3479 "ErrorCode,Unknown value provided for Roaming");
3480 return 0;
3481}
3482
3483
Ashwini Patila75de5a2017-04-13 16:35:05 +05303484static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3485 struct sigma_conn *conn,
3486 const char *intf, const char *val)
3487{
3488 if (strcasecmp(val, "Disable") == 0) {
3489 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3490 send_resp(dut, conn, SIGMA_ERROR,
3491 "ErrorCode,Failed to disable Assoc_disallow");
3492 return 0;
3493 }
3494 return 1;
3495 }
3496
3497 if (strcasecmp(val, "Enable") == 0) {
3498 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3499 send_resp(dut, conn, SIGMA_ERROR,
3500 "ErrorCode,Failed to enable Assoc_disallow");
3501 return 0;
3502 }
3503 return 1;
3504 }
3505
3506 sigma_dut_print(dut, DUT_MSG_ERROR,
3507 "Invalid value provided for Assoc_disallow: %s", val);
3508 send_resp(dut, conn, SIGMA_INVALID,
3509 "ErrorCode,Unknown value provided for Assoc_disallow");
3510 return 0;
3511}
3512
3513
Ashwini Patilc63161e2017-04-13 16:30:23 +05303514static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3515 const char *intf, const char *val)
3516{
3517 if (strcasecmp(val, "Reject") == 0) {
3518 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3519 send_resp(dut, conn, SIGMA_ERROR,
3520 "ErrorCode,Failed to Reject BTM Request");
3521 return 0;
3522 }
3523 return 1;
3524 }
3525
3526 if (strcasecmp(val, "Accept") == 0) {
3527 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3528 send_resp(dut, conn, SIGMA_ERROR,
3529 "ErrorCode,Failed to Accept BTM Request");
3530 return 0;
3531 }
3532 return 1;
3533 }
3534
3535 sigma_dut_print(dut, DUT_MSG_ERROR,
3536 "Invalid value provided for BSS_Transition: %s", val);
3537 send_resp(dut, conn, SIGMA_INVALID,
3538 "ErrorCode,Unknown value provided for BSS_Transition");
3539 return 0;
3540}
3541
3542
Ashwini Patil00402582017-04-13 12:29:39 +05303543static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3544 struct sigma_conn *conn,
3545 const char *intf,
3546 struct sigma_cmd *cmd)
3547{
3548 const char *ch, *pref, *op_class, *reason;
3549 char buf[120];
3550 int len, ret;
3551
3552 pref = get_param(cmd, "Ch_Pref");
3553 if (!pref)
3554 return 1;
3555
3556 if (strcasecmp(pref, "clear") == 0) {
3557 free(dut->non_pref_ch_list);
3558 dut->non_pref_ch_list = NULL;
3559 } else {
3560 op_class = get_param(cmd, "Ch_Op_Class");
3561 if (!op_class) {
3562 send_resp(dut, conn, SIGMA_INVALID,
3563 "ErrorCode,Ch_Op_Class not provided");
3564 return 0;
3565 }
3566
3567 ch = get_param(cmd, "Ch_Pref_Num");
3568 if (!ch) {
3569 send_resp(dut, conn, SIGMA_INVALID,
3570 "ErrorCode,Ch_Pref_Num not provided");
3571 return 0;
3572 }
3573
3574 reason = get_param(cmd, "Ch_Reason_Code");
3575 if (!reason) {
3576 send_resp(dut, conn, SIGMA_INVALID,
3577 "ErrorCode,Ch_Reason_Code not provided");
3578 return 0;
3579 }
3580
3581 if (!dut->non_pref_ch_list) {
3582 dut->non_pref_ch_list =
3583 calloc(1, NON_PREF_CH_LIST_SIZE);
3584 if (!dut->non_pref_ch_list) {
3585 send_resp(dut, conn, SIGMA_ERROR,
3586 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3587 return 0;
3588 }
3589 }
3590 len = strlen(dut->non_pref_ch_list);
3591 ret = snprintf(dut->non_pref_ch_list + len,
3592 NON_PREF_CH_LIST_SIZE - len,
3593 " %s:%s:%s:%s", op_class, ch, pref, reason);
3594 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3595 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3596 dut->non_pref_ch_list);
3597 } else {
3598 sigma_dut_print(dut, DUT_MSG_ERROR,
3599 "snprintf failed for non_pref_list, ret = %d",
3600 ret);
3601 send_resp(dut, conn, SIGMA_ERROR,
3602 "ErrorCode,snprintf failed");
3603 free(dut->non_pref_ch_list);
3604 dut->non_pref_ch_list = NULL;
3605 return 0;
3606 }
3607 }
3608
3609 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3610 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3611 if (ret < 0 || ret >= (int) sizeof(buf)) {
3612 sigma_dut_print(dut, DUT_MSG_DEBUG,
3613 "snprintf failed for set non_pref_chan, ret: %d",
3614 ret);
3615 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3616 return 0;
3617 }
3618
3619 if (wpa_command(intf, buf) < 0) {
3620 send_resp(dut, conn, SIGMA_ERROR,
3621 "ErrorCode,Failed to set non-preferred channel list");
3622 return 0;
3623 }
3624
3625 return 1;
3626}
3627
3628
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003629#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003630
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08003631static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
3632 uint8_t cfg)
3633{
3634 struct nl_msg *msg;
3635 int ret = 0;
3636 struct nlattr *params;
3637 int ifindex;
3638
3639 ifindex = if_nametoindex(intf);
3640 if (ifindex == 0) {
3641 sigma_dut_print(dut, DUT_MSG_ERROR,
3642 "%s: Index for interface %s failed",
3643 __func__, intf);
3644 return -1;
3645 }
3646
3647 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3648 NL80211_CMD_VENDOR)) ||
3649 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3650 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3651 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3652 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3653 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3654 nla_put_u8(msg,
3655 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
3656 cfg)) {
3657 sigma_dut_print(dut, DUT_MSG_ERROR,
3658 "%s: err in adding vendor_cmd and vendor_data",
3659 __func__);
3660 nlmsg_free(msg);
3661 return -1;
3662 }
3663 nla_nest_end(msg, params);
3664
3665 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3666 if (ret) {
3667 sigma_dut_print(dut, DUT_MSG_ERROR,
3668 "%s: err in send_and_recv_msgs, ret=%d",
3669 __func__, ret);
3670 }
3671 return ret;
3672}
3673
3674
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003675static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3676 enum he_fragmentation_val frag)
3677{
3678 struct nl_msg *msg;
3679 int ret = 0;
3680 struct nlattr *params;
3681 int ifindex;
3682
3683 ifindex = if_nametoindex(intf);
3684 if (ifindex == 0) {
3685 sigma_dut_print(dut, DUT_MSG_ERROR,
3686 "%s: Index for interface %s failed",
3687 __func__, intf);
3688 return -1;
3689 }
3690
3691 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3692 NL80211_CMD_VENDOR)) ||
3693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3694 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3695 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3696 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3697 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3698 nla_put_u8(msg,
3699 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3700 frag)) {
3701 sigma_dut_print(dut, DUT_MSG_ERROR,
3702 "%s: err in adding vendor_cmd and vendor_data",
3703 __func__);
3704 nlmsg_free(msg);
3705 return -1;
3706 }
3707 nla_nest_end(msg, params);
3708
3709 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3710 if (ret) {
3711 sigma_dut_print(dut, DUT_MSG_ERROR,
3712 "%s: err in send_and_recv_msgs, ret=%d",
3713 __func__, ret);
3714 }
3715 return ret;
3716}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003717
3718
Subhani Shaik8e7a3052018-04-24 14:03:00 -07003719static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
3720 enum qca_wlan_he_ltf_cfg ltf)
3721{
3722 struct nl_msg *msg;
3723 int ret = 0;
3724 struct nlattr *params;
3725 int ifindex;
3726
3727 ifindex = if_nametoindex(intf);
3728 if (ifindex == 0) {
3729 sigma_dut_print(dut, DUT_MSG_ERROR,
3730 "%s: Index for interface %s failed",
3731 __func__, intf);
3732 return -1;
3733 }
3734
3735 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3736 NL80211_CMD_VENDOR)) ||
3737 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3738 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3739 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3740 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3741 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3742 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
3743 ltf)) {
3744 sigma_dut_print(dut, DUT_MSG_ERROR,
3745 "%s: err in adding vendor_cmd and vendor_data",
3746 __func__);
3747 nlmsg_free(msg);
3748 return -1;
3749 }
3750 nla_nest_end(msg, params);
3751
3752 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3753 if (ret) {
3754 sigma_dut_print(dut, DUT_MSG_ERROR,
3755 "%s: err in send_and_recv_msgs, ret=%d",
3756 __func__, ret);
3757 }
3758 return ret;
3759}
3760
3761
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003762static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
3763 int noack, enum qca_wlan_ac_type ac)
3764{
3765 struct nl_msg *msg;
3766 int ret = 0;
3767 struct nlattr *params;
3768 int ifindex;
3769
3770 ifindex = if_nametoindex(intf);
3771 if (ifindex == 0) {
3772 sigma_dut_print(dut, DUT_MSG_ERROR,
3773 "%s: Index for interface %s failed",
3774 __func__, intf);
3775 return -1;
3776 }
3777
3778 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3779 NL80211_CMD_VENDOR)) ||
3780 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3781 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3782 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3783 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3784 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3785 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
3786 noack) ||
3787 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
3788 ac)) {
3789 sigma_dut_print(dut, DUT_MSG_ERROR,
3790 "%s: err in adding vendor_cmd and vendor_data",
3791 __func__);
3792 nlmsg_free(msg);
3793 return -1;
3794 }
3795 nla_nest_end(msg, params);
3796
3797 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3798 if (ret) {
3799 sigma_dut_print(dut, DUT_MSG_ERROR,
3800 "%s: err in send_and_recv_msgs, ret=%d",
3801 __func__, ret);
3802 }
3803 return ret;
3804}
3805
3806
3807static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
3808 const char *val)
3809{
3810 int noack, ret;
3811 char token[100];
3812 char *result;
3813 char *saveptr;
3814 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
3815
3816 strlcpy(token, val, sizeof(token));
3817 token[sizeof(token) - 1] = '\0';
3818 result = strtok_r(token, ":", &saveptr);
3819 while (result) {
3820 noack = strcasecmp(result, "Disable") != 0;
3821 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
3822 if (ret) {
3823 sigma_dut_print(dut, DUT_MSG_ERROR,
3824 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
3825 ac, ret);
3826 }
3827 result = strtok_r(NULL, ":", &saveptr);
3828 ac++;
3829 }
3830}
3831
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003832#endif /* NL80211_SUPPORT */
3833
3834
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003835static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3836 struct sigma_conn *conn,
3837 struct sigma_cmd *cmd)
3838{
3839 const char *intf = get_param(cmd, "Interface");
3840 const char *val;
3841
3842 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03003843 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
3844 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003845 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3846 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003847
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003848 if (val && strcasecmp(val, "LOC") == 0)
3849 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003851#ifdef ANDROID_NAN
3852 if (val && strcasecmp(val, "NAN") == 0)
3853 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3854#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003855#ifdef MIRACAST
3856 if (val && (strcasecmp(val, "WFD") == 0 ||
3857 strcasecmp(val, "DisplayR2") == 0))
3858 return miracast_preset_testparameters(dut, conn, cmd);
3859#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003860
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303861 if (val && strcasecmp(val, "MBO") == 0) {
3862 val = get_param(cmd, "Cellular_Data_Cap");
3863 if (val &&
3864 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3865 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303866
3867 val = get_param(cmd, "Ch_Pref");
3868 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3869 return 0;
3870
Ashwini Patilc63161e2017-04-13 16:30:23 +05303871 val = get_param(cmd, "BSS_Transition");
3872 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3873 return 0;
3874
Ashwini Patila75de5a2017-04-13 16:35:05 +05303875 val = get_param(cmd, "Assoc_Disallow");
3876 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3877 return 0;
3878
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303879 val = get_param(cmd, "Roaming");
3880 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3881 return 0;
3882
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303883 return 1;
3884 }
3885
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303886 if (val && strcasecmp(val, "OCE") == 0)
3887 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3888
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003889#if 0
3890 val = get_param(cmd, "Supplicant");
3891 if (val && strcasecmp(val, "Default") != 0) {
3892 send_resp(dut, conn, SIGMA_ERROR,
3893 "ErrorCode,Only default(Vendor) supplicant "
3894 "supported");
3895 return 0;
3896 }
3897#endif
3898
3899 val = get_param(cmd, "RTS");
3900 if (val) {
3901 switch (get_driver_type()) {
3902 case DRIVER_ATHEROS:
3903 ath_sta_set_rts(dut, intf, val);
3904 break;
3905 default:
3906#if 0
3907 send_resp(dut, conn, SIGMA_ERROR,
3908 "ErrorCode,Setting RTS not supported");
3909 return 0;
3910#else
3911 sigma_dut_print(dut, DUT_MSG_DEBUG,
3912 "Setting RTS not supported");
3913 break;
3914#endif
3915 }
3916 }
3917
3918#if 0
3919 val = get_param(cmd, "FRGMNT");
3920 if (val) {
3921 /* TODO */
3922 send_resp(dut, conn, SIGMA_ERROR,
3923 "ErrorCode,Setting FRGMNT not supported");
3924 return 0;
3925 }
3926#endif
3927
3928#if 0
3929 val = get_param(cmd, "Preamble");
3930 if (val) {
3931 /* TODO: Long/Short */
3932 send_resp(dut, conn, SIGMA_ERROR,
3933 "ErrorCode,Setting Preamble not supported");
3934 return 0;
3935 }
3936#endif
3937
3938 val = get_param(cmd, "Mode");
3939 if (val) {
3940 if (strcmp(val, "11b") == 0 ||
3941 strcmp(val, "11g") == 0 ||
3942 strcmp(val, "11a") == 0 ||
3943 strcmp(val, "11n") == 0 ||
3944 strcmp(val, "11ng") == 0 ||
3945 strcmp(val, "11nl") == 0 ||
3946 strcmp(val, "11nl(nabg)") == 0 ||
3947 strcmp(val, "AC") == 0 ||
3948 strcmp(val, "11AC") == 0 ||
3949 strcmp(val, "11ac") == 0 ||
3950 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003951 strcmp(val, "11an") == 0 ||
3952 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003953 /* STA supports all modes by default */
3954 } else {
3955 send_resp(dut, conn, SIGMA_ERROR,
3956 "ErrorCode,Setting Mode not supported");
3957 return 0;
3958 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003959
3960 /* Change the mode only in case of testbed for HE program
3961 * and for 11a and 11g modes only. */
3962 if (dut->program == PROGRAM_HE &&
3963 dut->device_type == STA_testbed) {
3964 int phymode;
3965 char buf[60];
3966
3967 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08003968 phymode = 1; /* IEEE80211_MODE_11A */
3969 } else if (strcmp(val, "11g") == 0) {
3970 phymode = 3; /* IEEE80211_MODE_11G */
3971 } else if (strcmp(val, "11b") == 0) {
3972 phymode = 2; /* IEEE80211_MODE_11B */
3973 } else if (strcmp(val, "11n") == 0 ||
3974 strcmp(val, "11nl") == 0 ||
3975 strcmp(val, "11nl(nabg)") == 0) {
3976 phymode = 22; /* IEEE80211_MODE_11AGN */
3977 } else if (strcmp(val, "11ng") == 0) {
3978 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
3979 } else if (strcmp(val, "AC") == 0 ||
3980 strcasecmp(val, "11AC") == 0) {
3981 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
3982 } else if (strcmp(val, "11na") == 0 ||
3983 strcasecmp(val, "11an") == 0) {
3984 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
3985 } else if (strcmp(val, "11ax") == 0) {
3986 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003987 } else {
3988 sigma_dut_print(dut, DUT_MSG_DEBUG,
3989 "Ignoring mode change for mode: %s",
3990 val);
3991 phymode = -1;
3992 }
3993 if (phymode != -1) {
3994 snprintf(buf, sizeof(buf),
3995 "iwpriv %s setphymode %d",
3996 intf, phymode);
3997 if (system(buf) != 0) {
3998 sigma_dut_print(dut, DUT_MSG_ERROR,
3999 "iwpriv setting of phymode failed");
4000 }
4001 }
4002 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004003 }
4004
4005 val = get_param(cmd, "wmm");
4006 if (val) {
4007 switch (get_driver_type()) {
4008 case DRIVER_ATHEROS:
4009 ath_sta_set_wmm(dut, intf, val);
4010 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004011 case DRIVER_WCN:
4012 wcn_sta_set_wmm(dut, intf, val);
4013 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004014 default:
4015 sigma_dut_print(dut, DUT_MSG_DEBUG,
4016 "Setting wmm not supported");
4017 break;
4018 }
4019 }
4020
4021 val = get_param(cmd, "Powersave");
4022 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004023 char buf[60];
4024
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004025 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004026 if (get_driver_type() == DRIVER_WCN) {
4027 snprintf(buf, sizeof(buf),
4028 "iwpriv %s setPower 2", intf);
4029 if (system(buf) != 0) {
4030 sigma_dut_print(dut, DUT_MSG_ERROR,
4031 "iwpriv setPower 2 failed");
4032 return 0;
4033 }
4034 }
4035
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004036 if (wpa_command(get_station_ifname(),
4037 "P2P_SET ps 0") < 0)
4038 return -2;
4039 /* Make sure test modes are disabled */
4040 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4041 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4042 } else if (strcmp(val, "1") == 0 ||
4043 strcasecmp(val, "PSPoll") == 0 ||
4044 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004045 if (get_driver_type() == DRIVER_WCN) {
4046 snprintf(buf, sizeof(buf),
4047 "iwpriv %s setPower 1", intf);
4048 if (system(buf) != 0) {
4049 sigma_dut_print(dut, DUT_MSG_ERROR,
4050 "iwpriv setPower 1 failed");
4051 return 0;
4052 }
4053 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004054 /* Disable default power save mode */
4055 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4056 /* Enable PS-Poll test mode */
4057 if (wpa_command(get_station_ifname(),
4058 "P2P_SET ps 97") < 0 ||
4059 wpa_command(get_station_ifname(),
4060 "P2P_SET ps 99") < 0)
4061 return -2;
4062 } else if (strcmp(val, "2") == 0 ||
4063 strcasecmp(val, "Fast") == 0) {
4064 /* TODO */
4065 send_resp(dut, conn, SIGMA_ERROR,
4066 "ErrorCode,Powersave=Fast not supported");
4067 return 0;
4068 } else if (strcmp(val, "3") == 0 ||
4069 strcasecmp(val, "PSNonPoll") == 0) {
4070 /* Make sure test modes are disabled */
4071 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4072 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4073
4074 /* Enable default power save mode */
4075 if (wpa_command(get_station_ifname(),
4076 "P2P_SET ps 1") < 0)
4077 return -2;
4078 } else
4079 return -1;
4080 }
4081
4082 val = get_param(cmd, "NoAck");
4083 if (val) {
4084 switch (get_driver_type()) {
4085 case DRIVER_ATHEROS:
4086 ath_sta_set_noack(dut, intf, val);
4087 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004088#ifdef NL80211_SUPPORT
4089 case DRIVER_WCN:
4090 wcn_sta_set_noack(dut, intf, val);
4091 break;
4092#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004093 default:
4094 send_resp(dut, conn, SIGMA_ERROR,
4095 "ErrorCode,Setting NoAck not supported");
4096 return 0;
4097 }
4098 }
4099
4100 val = get_param(cmd, "IgnoreChswitchProhibit");
4101 if (val) {
4102 /* TODO: Enabled/disabled */
4103 if (strcasecmp(val, "Enabled") == 0) {
4104 send_resp(dut, conn, SIGMA_ERROR,
4105 "ErrorCode,Enabling IgnoreChswitchProhibit "
4106 "not supported");
4107 return 0;
4108 }
4109 }
4110
4111 val = get_param(cmd, "TDLS");
4112 if (val) {
4113 if (strcasecmp(val, "Disabled") == 0) {
4114 if (wpa_command(intf, "SET tdls_disabled 1")) {
4115 send_resp(dut, conn, SIGMA_ERROR,
4116 "ErrorCode,Failed to disable TDLS");
4117 return 0;
4118 }
4119 } else if (strcasecmp(val, "Enabled") == 0) {
4120 if (wpa_command(intf, "SET tdls_disabled 0")) {
4121 send_resp(dut, conn, SIGMA_ERROR,
4122 "ErrorCode,Failed to enable TDLS");
4123 return 0;
4124 }
4125 } else {
4126 send_resp(dut, conn, SIGMA_ERROR,
4127 "ErrorCode,Unsupported TDLS value");
4128 return 0;
4129 }
4130 }
4131
4132 val = get_param(cmd, "TDLSmode");
4133 if (val) {
4134 if (strcasecmp(val, "Default") == 0) {
4135 wpa_command(intf, "SET tdls_testing 0");
4136 } else if (strcasecmp(val, "APProhibit") == 0) {
4137 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4138 send_resp(dut, conn, SIGMA_ERROR,
4139 "ErrorCode,Failed to enable ignore "
4140 "APProhibit TDLS mode");
4141 return 0;
4142 }
4143 } else if (strcasecmp(val, "HiLoMac") == 0) {
4144 /* STA should respond with TDLS setup req for a TDLS
4145 * setup req */
4146 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4147 send_resp(dut, conn, SIGMA_ERROR,
4148 "ErrorCode,Failed to enable HiLoMac "
4149 "TDLS mode");
4150 return 0;
4151 }
4152 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4153 /*
4154 * Since all security modes are enabled by default when
4155 * Sigma control is used, there is no need to do
4156 * anything here.
4157 */
4158 } else if (strcasecmp(val, "ExistLink") == 0) {
4159 /*
4160 * Since we allow new TDLS Setup Request even if there
4161 * is an existing link, nothing needs to be done for
4162 * this.
4163 */
4164 } else {
4165 /* TODO:
4166 * ExistLink: STA should send TDLS setup req even if
4167 * direct link already exists
4168 */
4169 send_resp(dut, conn, SIGMA_ERROR,
4170 "ErrorCode,Unsupported TDLSmode value");
4171 return 0;
4172 }
4173 }
4174
4175 val = get_param(cmd, "FakePubKey");
4176 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4177 send_resp(dut, conn, SIGMA_ERROR,
4178 "ErrorCode,Failed to enable FakePubKey");
4179 return 0;
4180 }
4181
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004182#ifdef NL80211_SUPPORT
4183 val = get_param(cmd, "FrgmntSupport");
4184 if (val) {
4185 if (strcasecmp(val, "Enable") == 0) {
4186 if (sta_set_he_fragmentation(dut, intf,
4187 HE_FRAG_LEVEL1)) {
4188 send_resp(dut, conn, SIGMA_ERROR,
4189 "ErrorCode,Failed to enable HE Fragmentation");
4190 return 0;
4191 }
4192 } else if (strcasecmp(val, "Disable") == 0) {
4193 if (sta_set_he_fragmentation(dut, intf,
4194 HE_FRAG_DISABLE)) {
4195 send_resp(dut, conn, SIGMA_ERROR,
4196 "ErrorCode,Failed to disable HE Fragmentation");
4197 return 0;
4198 }
4199 }
4200 }
4201#endif /* NL80211_SUPPORT */
4202
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004203 return 1;
4204}
4205
4206
4207static const char * ath_get_radio_name(const char *radio_name)
4208{
4209 if (radio_name == NULL)
4210 return "wifi0";
4211 if (strcmp(radio_name, "wifi1") == 0)
4212 return "wifi1";
4213 if (strcmp(radio_name, "wifi2") == 0)
4214 return "wifi2";
4215 return "wifi0";
4216}
4217
4218
4219static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4220 const char *val)
4221{
4222 char buf[60];
4223 unsigned int vht_mcsmap = 0;
4224 int txchainmask = 0;
4225 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4226
4227 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4228 if (dut->testbed_flag_txsp == 1) {
4229 vht_mcsmap = 0xfffc;
4230 dut->testbed_flag_txsp = 0;
4231 } else {
4232 vht_mcsmap = 0xfffe;
4233 }
4234 txchainmask = 1;
4235 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4236 if (dut->testbed_flag_txsp == 1) {
4237 vht_mcsmap = 0xfff0;
4238 dut->testbed_flag_txsp = 0;
4239 } else {
4240 vht_mcsmap = 0xfffa;
4241 }
4242 txchainmask = 3;
4243 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4244 if (dut->testbed_flag_txsp == 1) {
4245 vht_mcsmap = 0xffc0;
4246 dut->testbed_flag_txsp = 0;
4247 } else {
4248 vht_mcsmap = 0xffea;
4249 }
4250 txchainmask = 7;
4251 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4252 if (dut->testbed_flag_txsp == 1) {
4253 vht_mcsmap = 0xff00;
4254 dut->testbed_flag_txsp = 0;
4255 } else {
4256 vht_mcsmap = 0xffaa;
4257 }
4258 txchainmask = 15;
4259 } else {
4260 if (dut->testbed_flag_txsp == 1) {
4261 vht_mcsmap = 0xffc0;
4262 dut->testbed_flag_txsp = 0;
4263 } else {
4264 vht_mcsmap = 0xffea;
4265 }
4266 }
4267
4268 if (txchainmask) {
4269 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4270 basedev, txchainmask);
4271 if (system(buf) != 0) {
4272 sigma_dut_print(dut, DUT_MSG_ERROR,
4273 "iwpriv txchainmask failed");
4274 }
4275 }
4276
4277 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4278 intf, vht_mcsmap);
4279 if (system(buf) != 0) {
4280 sigma_dut_print(dut, DUT_MSG_ERROR,
4281 "iwpriv %s vht_mcsmap 0x%04x failed",
4282 intf, vht_mcsmap);
4283 }
4284}
4285
4286
4287static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4288 const char *val)
4289{
4290 char buf[60];
4291 unsigned int vht_mcsmap = 0;
4292 int rxchainmask = 0;
4293 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4294
4295 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4296 if (dut->testbed_flag_rxsp == 1) {
4297 vht_mcsmap = 0xfffc;
4298 dut->testbed_flag_rxsp = 0;
4299 } else {
4300 vht_mcsmap = 0xfffe;
4301 }
4302 rxchainmask = 1;
4303 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4304 if (dut->testbed_flag_rxsp == 1) {
4305 vht_mcsmap = 0xfff0;
4306 dut->testbed_flag_rxsp = 0;
4307 } else {
4308 vht_mcsmap = 0xfffa;
4309 }
4310 rxchainmask = 3;
4311 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4312 if (dut->testbed_flag_rxsp == 1) {
4313 vht_mcsmap = 0xffc0;
4314 dut->testbed_flag_rxsp = 0;
4315 } else {
4316 vht_mcsmap = 0xffea;
4317 }
4318 rxchainmask = 7;
4319 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4320 if (dut->testbed_flag_rxsp == 1) {
4321 vht_mcsmap = 0xff00;
4322 dut->testbed_flag_rxsp = 0;
4323 } else {
4324 vht_mcsmap = 0xffaa;
4325 }
4326 rxchainmask = 15;
4327 } else {
4328 if (dut->testbed_flag_rxsp == 1) {
4329 vht_mcsmap = 0xffc0;
4330 dut->testbed_flag_rxsp = 0;
4331 } else {
4332 vht_mcsmap = 0xffea;
4333 }
4334 }
4335
4336 if (rxchainmask) {
4337 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4338 basedev, rxchainmask);
4339 if (system(buf) != 0) {
4340 sigma_dut_print(dut, DUT_MSG_ERROR,
4341 "iwpriv rxchainmask failed");
4342 }
4343 }
4344
4345 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4346 intf, vht_mcsmap);
4347 if (system(buf) != 0) {
4348 sigma_dut_print(dut, DUT_MSG_ERROR,
4349 "iwpriv %s vht_mcsmap 0x%04x",
4350 intf, vht_mcsmap);
4351 }
4352}
4353
4354
4355void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4356{
4357 if (strcasecmp(val, "enable") == 0) {
4358 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4359 != 0) {
4360 sigma_dut_print(dut, DUT_MSG_ERROR,
4361 "Disable BB_VHTSIGB_CRC_CALC failed");
4362 }
4363
4364 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4365 != 0) {
4366 sigma_dut_print(dut, DUT_MSG_ERROR,
4367 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4368 }
4369 } else {
4370 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4371 != 0) {
4372 sigma_dut_print(dut, DUT_MSG_ERROR,
4373 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4374 }
4375
4376 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4377 != 0) {
4378 sigma_dut_print(dut, DUT_MSG_ERROR,
4379 "Enable BB_VHTSIGB_CRC_CALC failed");
4380 }
4381 }
4382}
4383
4384
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004385static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4386 const char *val)
4387{
4388 char buf[60];
4389
4390 if (strcmp(val, "20") == 0) {
4391 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4392 dut->chwidth = 0;
4393 } else if (strcmp(val, "40") == 0) {
4394 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4395 dut->chwidth = 1;
4396 } else if (strcmp(val, "80") == 0) {
4397 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4398 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304399 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004400 buf[0] = '\0';
4401 } else {
4402 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4403 val);
4404 return -1;
4405 }
4406
4407 if (buf[0] != '\0' && system(buf) != 0) {
4408 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4409 return -1;
4410 }
4411
4412 return 0;
4413}
4414
4415
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004416static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4417 const char *intf, int addbareject)
4418{
4419#ifdef NL80211_SUPPORT
4420 struct nl_msg *msg;
4421 int ret = 0;
4422 struct nlattr *params;
4423 int ifindex;
4424
4425 ifindex = if_nametoindex(intf);
4426 if (ifindex == 0) {
4427 sigma_dut_print(dut, DUT_MSG_ERROR,
4428 "%s: Index for interface %s failed",
4429 __func__, intf);
4430 return -1;
4431 }
4432
4433 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4434 NL80211_CMD_VENDOR)) ||
4435 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4436 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4437 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4438 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4439 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4440 nla_put_u8(msg,
4441 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4442 !addbareject)) {
4443 sigma_dut_print(dut, DUT_MSG_ERROR,
4444 "%s: err in adding vendor_cmd and vendor_data",
4445 __func__);
4446 nlmsg_free(msg);
4447 return -1;
4448 }
4449 nla_nest_end(msg, params);
4450
4451 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4452 if (ret) {
4453 sigma_dut_print(dut, DUT_MSG_ERROR,
4454 "%s: err in send_and_recv_msgs, ret=%d",
4455 __func__, ret);
4456 }
4457 return ret;
4458#else /* NL80211_SUPPORT */
4459 sigma_dut_print(dut, DUT_MSG_ERROR,
4460 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4461 return -1;
4462#endif /* NL80211_SUPPORT */
4463}
4464
4465
4466static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4467 int addbareject)
4468{
4469 int ret;
4470
4471 switch (get_driver_type()) {
4472 case DRIVER_WCN:
4473 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4474 if (ret) {
4475 sigma_dut_print(dut, DUT_MSG_ERROR,
4476 "nlvendor_sta_set_addba_reject failed, ret:%d",
4477 ret);
4478 return ret;
4479 }
4480 break;
4481 default:
4482 sigma_dut_print(dut, DUT_MSG_ERROR,
4483 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4484 ret = -1;
4485 break;
4486 }
4487
4488 return ret;
4489}
4490
4491
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004492static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4493 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004494{
4495#ifdef NL80211_SUPPORT
4496 struct nl_msg *msg;
4497 int ret = 0;
4498 struct nlattr *params;
4499 int ifindex;
4500
4501 ifindex = if_nametoindex(intf);
4502 if (ifindex == 0) {
4503 sigma_dut_print(dut, DUT_MSG_ERROR,
4504 "%s: Index for interface %s failed",
4505 __func__, intf);
4506 return -1;
4507 }
4508
4509 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4510 NL80211_CMD_VENDOR)) ||
4511 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4512 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4513 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4514 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4515 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4516 nla_put_u8(msg,
4517 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004518 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004519 sigma_dut_print(dut, DUT_MSG_ERROR,
4520 "%s: err in adding vendor_cmd and vendor_data",
4521 __func__);
4522 nlmsg_free(msg);
4523 return -1;
4524 }
4525 nla_nest_end(msg, params);
4526
4527 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4528 if (ret) {
4529 sigma_dut_print(dut, DUT_MSG_ERROR,
4530 "%s: err in send_and_recv_msgs, ret=%d",
4531 __func__, ret);
4532 }
4533 return ret;
4534#else /* NL80211_SUPPORT */
4535 sigma_dut_print(dut, DUT_MSG_ERROR,
4536 "Disable addba not possible without NL80211_SUPPORT defined");
4537 return -1;
4538#endif /* NL80211_SUPPORT */
4539}
4540
4541
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004542static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4543 struct sigma_conn *conn,
4544 struct sigma_cmd *cmd)
4545{
4546 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004547 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004548 char buf[30];
4549
4550 val = get_param(cmd, "40_INTOLERANT");
4551 if (val) {
4552 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4553 /* TODO: iwpriv ht40intol through wpa_supplicant */
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,40_INTOLERANT not supported");
4556 return 0;
4557 }
4558 }
4559
4560 val = get_param(cmd, "ADDBA_REJECT");
4561 if (val) {
4562 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4563 /* reject any ADDBA with status "decline" */
4564 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004565 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004566 } else {
4567 /* accept ADDBA */
4568 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004569 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004570 }
4571 }
4572
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004573 if (addbareject >= 0 &&
4574 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4575 send_resp(dut, conn, SIGMA_ERROR,
4576 "ErrorCode,set addba_reject failed");
4577 return 0;
4578 }
4579
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004580 val = get_param(cmd, "AMPDU");
4581 if (val) {
4582 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4583 /* enable AMPDU Aggregation */
4584 if (ampdu == 0) {
4585 send_resp(dut, conn, SIGMA_ERROR,
4586 "ErrorCode,Mismatch in "
4587 "addba_reject/ampdu - "
4588 "not supported");
4589 return 0;
4590 }
4591 ampdu = 1;
4592 } else {
4593 /* disable AMPDU Aggregation */
4594 if (ampdu == 1) {
4595 send_resp(dut, conn, SIGMA_ERROR,
4596 "ErrorCode,Mismatch in "
4597 "addba_reject/ampdu - "
4598 "not supported");
4599 return 0;
4600 }
4601 ampdu = 0;
4602 }
4603 }
4604
4605 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004606 int ret;
4607
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004608 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4609 ampdu ? "Enabling" : "Disabling");
4610 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004611 if (wpa_command(intf, buf) < 0 &&
4612 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004613 send_resp(dut, conn, SIGMA_ERROR,
4614 "ErrorCode,set aggr failed");
4615 return 0;
4616 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004617
4618 if (ampdu == 0) {
4619 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004620 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004621 if (ret) {
4622 sigma_dut_print(dut, DUT_MSG_ERROR,
4623 "Failed to disable addba, ret:%d",
4624 ret);
4625 }
4626 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004627 }
4628
4629 val = get_param(cmd, "AMSDU");
4630 if (val) {
4631 switch (get_driver_type()) {
4632 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004633 case DRIVER_WCN:
4634 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004635 break;
4636 default:
4637 if (strcmp(val, "1") == 0 ||
4638 strcasecmp(val, "Enable") == 0) {
4639 /* Enable AMSDU Aggregation */
4640 send_resp(dut, conn, SIGMA_ERROR,
4641 "ErrorCode,AMSDU aggregation not supported");
4642 return 0;
4643 }
4644 break;
4645 }
4646 }
4647
4648 val = get_param(cmd, "STBC_RX");
4649 if (val) {
4650 switch (get_driver_type()) {
4651 case DRIVER_ATHEROS:
4652 ath_sta_set_stbc(dut, intf, val);
4653 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304654 case DRIVER_WCN:
4655 wcn_sta_set_stbc(dut, intf, val);
4656 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004657 default:
4658 send_resp(dut, conn, SIGMA_ERROR,
4659 "ErrorCode,STBC_RX not supported");
4660 return 0;
4661 }
4662 }
4663
4664 val = get_param(cmd, "WIDTH");
4665 if (val) {
4666 switch (get_driver_type()) {
4667 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004668 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004669 send_resp(dut, conn, SIGMA_ERROR,
4670 "ErrorCode,Failed to set WIDTH");
4671 return 0;
4672 }
4673 break;
4674 case DRIVER_ATHEROS:
4675 if (ath_set_width(dut, conn, intf, val) < 0)
4676 return 0;
4677 break;
4678 default:
4679 sigma_dut_print(dut, DUT_MSG_ERROR,
4680 "Setting WIDTH not supported");
4681 break;
4682 }
4683 }
4684
4685 val = get_param(cmd, "SMPS");
4686 if (val) {
4687 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4688 send_resp(dut, conn, SIGMA_ERROR,
4689 "ErrorCode,SMPS not supported");
4690 return 0;
4691 }
4692
4693 val = get_param(cmd, "TXSP_STREAM");
4694 if (val) {
4695 switch (get_driver_type()) {
4696 case DRIVER_WCN:
4697 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4698 send_resp(dut, conn, SIGMA_ERROR,
4699 "ErrorCode,Failed to set TXSP_STREAM");
4700 return 0;
4701 }
4702 break;
4703 case DRIVER_ATHEROS:
4704 ath_sta_set_txsp_stream(dut, intf, val);
4705 break;
4706 default:
4707 sigma_dut_print(dut, DUT_MSG_ERROR,
4708 "Setting TXSP_STREAM not supported");
4709 break;
4710 }
4711 }
4712
4713 val = get_param(cmd, "RXSP_STREAM");
4714 if (val) {
4715 switch (get_driver_type()) {
4716 case DRIVER_WCN:
4717 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4718 send_resp(dut, conn, SIGMA_ERROR,
4719 "ErrorCode,Failed to set RXSP_STREAM");
4720 return 0;
4721 }
4722 break;
4723 case DRIVER_ATHEROS:
4724 ath_sta_set_rxsp_stream(dut, intf, val);
4725 break;
4726 default:
4727 sigma_dut_print(dut, DUT_MSG_ERROR,
4728 "Setting RXSP_STREAM not supported");
4729 break;
4730 }
4731 }
4732
4733 val = get_param(cmd, "DYN_BW_SGNL");
4734 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004735 switch (get_driver_type()) {
4736 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004737 if (strcasecmp(val, "enable") == 0) {
4738 snprintf(buf, sizeof(buf),
4739 "iwpriv %s cwmenable 1", intf);
4740 if (system(buf) != 0) {
4741 sigma_dut_print(dut, DUT_MSG_ERROR,
4742 "iwpriv cwmenable 1 failed");
4743 return 0;
4744 }
4745 } else if (strcasecmp(val, "disable") == 0) {
4746 snprintf(buf, sizeof(buf),
4747 "iwpriv %s cwmenable 0", intf);
4748 if (system(buf) != 0) {
4749 sigma_dut_print(dut, DUT_MSG_ERROR,
4750 "iwpriv cwmenable 0 failed");
4751 return 0;
4752 }
4753 } else {
4754 sigma_dut_print(dut, DUT_MSG_ERROR,
4755 "Unsupported DYN_BW_SGL");
4756 }
4757
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004758 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4759 if (system(buf) != 0) {
4760 sigma_dut_print(dut, DUT_MSG_ERROR,
4761 "Failed to set cts_cbw in DYN_BW_SGNL");
4762 return 0;
4763 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004764 break;
4765 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004766 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004767 ath_config_dyn_bw_sig(dut, intf, val);
4768 break;
4769 default:
4770 sigma_dut_print(dut, DUT_MSG_ERROR,
4771 "Failed to set DYN_BW_SGNL");
4772 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004773 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004774 }
4775
4776 val = get_param(cmd, "RTS_FORCE");
4777 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004778 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004779 if (strcasecmp(val, "Enable") == 0) {
4780 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004781 if (system(buf) != 0) {
4782 sigma_dut_print(dut, DUT_MSG_ERROR,
4783 "Failed to set RTS_FORCE 64");
4784 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004785 snprintf(buf, sizeof(buf),
4786 "wifitool %s beeliner_fw_test 100 1", intf);
4787 if (system(buf) != 0) {
4788 sigma_dut_print(dut, DUT_MSG_ERROR,
4789 "wifitool beeliner_fw_test 100 1 failed");
4790 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004791 } else if (strcasecmp(val, "Disable") == 0) {
4792 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4793 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004794 if (system(buf) != 0) {
4795 sigma_dut_print(dut, DUT_MSG_ERROR,
4796 "Failed to set RTS_FORCE 2347");
4797 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004798 } else {
4799 send_resp(dut, conn, SIGMA_ERROR,
4800 "ErrorCode,RTS_FORCE value not supported");
4801 return 0;
4802 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004803 }
4804
4805 val = get_param(cmd, "CTS_WIDTH");
4806 if (val) {
4807 switch (get_driver_type()) {
4808 case DRIVER_WCN:
4809 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4810 send_resp(dut, conn, SIGMA_ERROR,
4811 "ErrorCode,Failed to set CTS_WIDTH");
4812 return 0;
4813 }
4814 break;
4815 case DRIVER_ATHEROS:
4816 ath_set_cts_width(dut, intf, val);
4817 break;
4818 default:
4819 sigma_dut_print(dut, DUT_MSG_ERROR,
4820 "Setting CTS_WIDTH not supported");
4821 break;
4822 }
4823 }
4824
4825 val = get_param(cmd, "BW_SGNL");
4826 if (val) {
4827 if (strcasecmp(val, "Enable") == 0) {
4828 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4829 intf);
4830 } else if (strcasecmp(val, "Disable") == 0) {
4831 /* TODO: Disable */
4832 buf[0] = '\0';
4833 } else {
4834 send_resp(dut, conn, SIGMA_ERROR,
4835 "ErrorCode,BW_SGNL value not supported");
4836 return 0;
4837 }
4838
4839 if (buf[0] != '\0' && system(buf) != 0) {
4840 sigma_dut_print(dut, DUT_MSG_ERROR,
4841 "Failed to set BW_SGNL");
4842 }
4843 }
4844
4845 val = get_param(cmd, "Band");
4846 if (val) {
4847 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4848 /* STA supports all bands by default */
4849 } else {
4850 send_resp(dut, conn, SIGMA_ERROR,
4851 "ErrorCode,Unsupported Band");
4852 return 0;
4853 }
4854 }
4855
4856 val = get_param(cmd, "zero_crc");
4857 if (val) {
4858 switch (get_driver_type()) {
4859 case DRIVER_ATHEROS:
4860 ath_set_zero_crc(dut, val);
4861 break;
4862 default:
4863 break;
4864 }
4865 }
4866
4867 return 1;
4868}
4869
4870
4871static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4872 struct sigma_cmd *cmd)
4873{
4874 const char *val;
4875 char buf[100];
4876
4877 val = get_param(cmd, "MSDUSize");
4878 if (val) {
4879 int mtu;
4880
4881 dut->amsdu_size = atoi(val);
4882 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4883 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4884 sigma_dut_print(dut, DUT_MSG_ERROR,
4885 "MSDUSize %d is above max %d or below min %d",
4886 dut->amsdu_size,
4887 IEEE80211_MAX_DATA_LEN_DMG,
4888 IEEE80211_SNAP_LEN_DMG);
4889 dut->amsdu_size = 0;
4890 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4891 }
4892
4893 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4894 sigma_dut_print(dut, DUT_MSG_DEBUG,
4895 "Setting amsdu_size to %d", mtu);
4896 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4897 get_station_ifname(), mtu);
4898
4899 if (system(buf) != 0) {
4900 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4901 buf);
4902 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4903 }
4904 }
4905
4906 val = get_param(cmd, "BAckRcvBuf");
4907 if (val) {
4908 dut->back_rcv_buf = atoi(val);
4909 if (dut->back_rcv_buf == 0) {
4910 sigma_dut_print(dut, DUT_MSG_ERROR,
4911 "Failed to convert %s or value is 0",
4912 val);
4913 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4914 }
4915
4916 sigma_dut_print(dut, DUT_MSG_DEBUG,
4917 "Setting BAckRcvBuf to %s", val);
4918 }
4919
4920 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4921}
4922
4923
4924static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4925 struct sigma_cmd *cmd)
4926{
4927 int net_id;
4928 char *ifname;
4929 const char *val;
4930 char buf[100];
4931
4932 dut->mode = SIGMA_MODE_STATION;
4933 ifname = get_main_ifname();
4934 if (wpa_command(ifname, "PING") != 0) {
4935 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4936 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4937 }
4938
4939 wpa_command(ifname, "FLUSH");
4940 net_id = add_network_common(dut, conn, ifname, cmd);
4941 if (net_id < 0) {
4942 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4943 return net_id;
4944 }
4945
4946 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4947 if (set_network(ifname, net_id, "mode", "2") < 0) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "Failed to set supplicant network mode");
4950 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4951 }
4952
4953 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02004954 "Supplicant set network with mode 2. network_id %d",
4955 net_id);
4956
4957 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
4958 sigma_dut_print(dut, DUT_MSG_INFO,
4959 "Failed to set supplicant to WPS ENABLE");
4960 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4961 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004962
4963 val = get_param(cmd, "Security");
4964 if (val && strcasecmp(val, "OPEN") == 0) {
4965 dut->ap_key_mgmt = AP_OPEN;
4966 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4967 sigma_dut_print(dut, DUT_MSG_ERROR,
4968 "Failed to set supplicant to %s security",
4969 val);
4970 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4971 }
4972 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4973 dut->ap_key_mgmt = AP_WPA2_PSK;
4974 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4975 sigma_dut_print(dut, DUT_MSG_ERROR,
4976 "Failed to set supplicant to %s security",
4977 val);
4978 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4979 }
4980
4981 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4982 sigma_dut_print(dut, DUT_MSG_ERROR,
4983 "Failed to set supplicant to proto RSN");
4984 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4985 }
4986 } else if (val) {
4987 sigma_dut_print(dut, DUT_MSG_ERROR,
4988 "Requested Security %s is not supported on 60GHz",
4989 val);
4990 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4991 }
4992
4993 val = get_param(cmd, "Encrypt");
4994 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4995 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4996 sigma_dut_print(dut, DUT_MSG_ERROR,
4997 "Failed to set supplicant to pairwise GCMP");
4998 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4999 }
5000 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5001 sigma_dut_print(dut, DUT_MSG_ERROR,
5002 "Failed to set supplicant to group GCMP");
5003 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5004 }
5005 } else if (val) {
5006 sigma_dut_print(dut, DUT_MSG_ERROR,
5007 "Requested Encrypt %s is not supported on 60 GHz",
5008 val);
5009 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
5010 }
5011
5012 val = get_param(cmd, "PSK");
5013 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5014 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5015 val);
5016 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5017 }
5018
5019 /* Convert 60G channel to freq */
5020 switch (dut->ap_channel) {
5021 case 1:
5022 val = "58320";
5023 break;
5024 case 2:
5025 val = "60480";
5026 break;
5027 case 3:
5028 val = "62640";
5029 break;
5030 default:
5031 sigma_dut_print(dut, DUT_MSG_ERROR,
5032 "Failed to configure channel %d. Not supported",
5033 dut->ap_channel);
5034 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5035 }
5036
5037 if (set_network(ifname, net_id, "frequency", val) < 0) {
5038 sigma_dut_print(dut, DUT_MSG_ERROR,
5039 "Failed to set supplicant network frequency");
5040 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5041 }
5042
5043 sigma_dut_print(dut, DUT_MSG_DEBUG,
5044 "Supplicant set network with frequency");
5045
5046 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5047 if (wpa_command(ifname, buf) < 0) {
5048 sigma_dut_print(dut, DUT_MSG_INFO,
5049 "Failed to select network id %d on %s",
5050 net_id, ifname);
5051 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5052 }
5053
5054 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5055
5056 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
5057}
5058
5059
Lior David67543f52017-01-03 19:04:22 +02005060static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5061{
5062 char buf[128], fname[128];
5063 FILE *f;
5064
5065 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5066 sigma_dut_print(dut, DUT_MSG_ERROR,
5067 "failed to get wil6210 debugfs dir");
5068 return -1;
5069 }
5070
5071 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5072 f = fopen(fname, "w");
5073 if (!f) {
5074 sigma_dut_print(dut, DUT_MSG_ERROR,
5075 "failed to open: %s", fname);
5076 return -1;
5077 }
5078
5079 fprintf(f, "%d\n", abft_len);
5080 fclose(f);
5081
5082 return 0;
5083}
5084
5085
5086static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5087 int abft_len)
5088{
5089 switch (get_driver_type()) {
5090 case DRIVER_WIL6210:
5091 return wil6210_set_abft_len(dut, abft_len);
5092 default:
5093 sigma_dut_print(dut, DUT_MSG_ERROR,
5094 "set abft_len not supported");
5095 return -1;
5096 }
5097}
5098
5099
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005100static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5101 struct sigma_cmd *cmd)
5102{
5103 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005104 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005105
5106 if (dut->dev_role != DEVROLE_PCP) {
5107 send_resp(dut, conn, SIGMA_INVALID,
5108 "ErrorCode,Invalid DevRole");
5109 return 0;
5110 }
5111
5112 val = get_param(cmd, "SSID");
5113 if (val) {
5114 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5115 send_resp(dut, conn, SIGMA_INVALID,
5116 "ErrorCode,Invalid SSID");
5117 return -1;
5118 }
5119
Peng Xub8fc5cc2017-05-10 17:27:28 -07005120 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005121 }
5122
5123 val = get_param(cmd, "CHANNEL");
5124 if (val) {
5125 const char *pos;
5126
5127 dut->ap_channel = atoi(val);
5128 pos = strchr(val, ';');
5129 if (pos) {
5130 pos++;
5131 dut->ap_channel_1 = atoi(pos);
5132 }
5133 }
5134
5135 switch (dut->ap_channel) {
5136 case 1:
5137 case 2:
5138 case 3:
5139 break;
5140 default:
5141 sigma_dut_print(dut, DUT_MSG_ERROR,
5142 "Channel %d is not supported", dut->ap_channel);
5143 send_resp(dut, conn, SIGMA_ERROR,
5144 "Requested channel is not supported");
5145 return -1;
5146 }
5147
5148 val = get_param(cmd, "BCNINT");
5149 if (val)
5150 dut->ap_bcnint = atoi(val);
5151
5152
5153 val = get_param(cmd, "ExtSchIE");
5154 if (val) {
5155 send_resp(dut, conn, SIGMA_ERROR,
5156 "ErrorCode,ExtSchIE is not supported yet");
5157 return -1;
5158 }
5159
5160 val = get_param(cmd, "AllocType");
5161 if (val) {
5162 send_resp(dut, conn, SIGMA_ERROR,
5163 "ErrorCode,AllocType is not supported yet");
5164 return -1;
5165 }
5166
5167 val = get_param(cmd, "PercentBI");
5168 if (val) {
5169 send_resp(dut, conn, SIGMA_ERROR,
5170 "ErrorCode,PercentBI is not supported yet");
5171 return -1;
5172 }
5173
5174 val = get_param(cmd, "CBAPOnly");
5175 if (val) {
5176 send_resp(dut, conn, SIGMA_ERROR,
5177 "ErrorCode,CBAPOnly is not supported yet");
5178 return -1;
5179 }
5180
5181 val = get_param(cmd, "AMPDU");
5182 if (val) {
5183 if (strcasecmp(val, "Enable") == 0)
5184 dut->ap_ampdu = 1;
5185 else if (strcasecmp(val, "Disable") == 0)
5186 dut->ap_ampdu = 2;
5187 else {
5188 send_resp(dut, conn, SIGMA_ERROR,
5189 "ErrorCode,AMPDU value is not Enable nor Disabled");
5190 return -1;
5191 }
5192 }
5193
5194 val = get_param(cmd, "AMSDU");
5195 if (val) {
5196 if (strcasecmp(val, "Enable") == 0)
5197 dut->ap_amsdu = 1;
5198 else if (strcasecmp(val, "Disable") == 0)
5199 dut->ap_amsdu = 2;
5200 }
5201
5202 val = get_param(cmd, "NumMSDU");
5203 if (val) {
5204 send_resp(dut, conn, SIGMA_ERROR,
5205 "ErrorCode, NumMSDU is not supported yet");
5206 return -1;
5207 }
5208
5209 val = get_param(cmd, "ABFTLRang");
5210 if (val) {
5211 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005212 "ABFTLRang parameter %s", val);
5213 if (strcmp(val, "Gt1") == 0)
5214 abft_len = 2; /* 2 slots in this case */
5215 }
5216
5217 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5218 send_resp(dut, conn, SIGMA_ERROR,
5219 "ErrorCode, Can't set ABFT length");
5220 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005221 }
5222
5223 if (sta_pcp_start(dut, conn, cmd) < 0) {
5224 send_resp(dut, conn, SIGMA_ERROR,
5225 "ErrorCode, Can't start PCP role");
5226 return -1;
5227 }
5228
5229 return sta_set_60g_common(dut, conn, cmd);
5230}
5231
5232
5233static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5234 struct sigma_cmd *cmd)
5235{
5236 const char *val = get_param(cmd, "DiscoveryMode");
5237
5238 if (dut->dev_role != DEVROLE_STA) {
5239 send_resp(dut, conn, SIGMA_INVALID,
5240 "ErrorCode,Invalid DevRole");
5241 return 0;
5242 }
5243
5244 if (val) {
5245 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5246 /* Ignore Discovery mode till Driver expose API. */
5247#if 0
5248 if (strcasecmp(val, "1") == 0) {
5249 send_resp(dut, conn, SIGMA_INVALID,
5250 "ErrorCode,DiscoveryMode 1 not supported");
5251 return 0;
5252 }
5253
5254 if (strcasecmp(val, "0") == 0) {
5255 /* OK */
5256 } else {
5257 send_resp(dut, conn, SIGMA_INVALID,
5258 "ErrorCode,DiscoveryMode not supported");
5259 return 0;
5260 }
5261#endif
5262 }
5263
5264 if (start_sta_mode(dut) != 0)
5265 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5266 return sta_set_60g_common(dut, conn, cmd);
5267}
5268
5269
5270static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5271 struct sigma_cmd *cmd)
5272{
5273 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005274 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305275
Jouni Malinened77e672018-01-10 16:45:13 +02005276 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005277 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005278 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305279 wpa_command(intf, "DISCONNECT");
5280 return 1;
5281 }
5282
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005283 disconnect_station(dut);
5284 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5285 * due to cached results. */
5286 wpa_command(intf, "SET ignore_old_scan_res 1");
5287 wpa_command(intf, "BSS_FLUSH");
5288 return 1;
5289}
5290
5291
5292static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5293 struct sigma_cmd *cmd)
5294{
5295 const char *intf = get_param(cmd, "Interface");
5296 const char *bssid = get_param(cmd, "bssid");
5297 const char *val = get_param(cmd, "CHANNEL");
5298 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305299 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305300 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005301 int res;
5302 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305303 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305304 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005305
5306 if (bssid == NULL) {
5307 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5308 "argument");
5309 return 0;
5310 }
5311
5312 if (val)
5313 chan = atoi(val);
5314
5315 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5316 /* The current network may be from sta_associate or
5317 * sta_hs2_associate
5318 */
5319 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5320 0 ||
5321 set_network(intf, 0, "bssid", bssid) < 0)
5322 return -2;
5323 }
5324
5325 ctrl = open_wpa_mon(intf);
5326 if (ctrl == NULL) {
5327 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5328 "wpa_supplicant monitor connection");
5329 return -1;
5330 }
5331
Sunil Duttd30ce092018-01-11 23:56:29 +05305332 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5333 sizeof(result)) < 0 ||
5334 strncmp(result, "COMPLETED", 9) != 0) {
5335 sigma_dut_print(dut, DUT_MSG_DEBUG,
5336 "sta_reassoc: Not connected");
5337 fastreassoc = 0;
5338 }
5339
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305340 if (dut->rsne_override) {
5341#ifdef NL80211_SUPPORT
5342 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5343 sta_config_rsnie(dut, 1);
5344 dut->config_rsnie = 1;
5345 }
5346#endif /* NL80211_SUPPORT */
5347 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5348 dut->rsne_override);
5349 if (wpa_command(intf, buf) < 0) {
5350 send_resp(dut, conn, SIGMA_ERROR,
5351 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5352 return 0;
5353 }
5354 }
5355
Sunil Duttd30ce092018-01-11 23:56:29 +05305356 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005357#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305358 if (chan) {
5359 unsigned int freq;
5360
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02005361 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305362 if (!freq) {
5363 sigma_dut_print(dut, DUT_MSG_ERROR,
5364 "Invalid channel number provided: %d",
5365 chan);
5366 send_resp(dut, conn, SIGMA_INVALID,
5367 "ErrorCode,Invalid channel number");
5368 goto close_mon_conn;
5369 }
5370 res = snprintf(buf, sizeof(buf),
5371 "SCAN TYPE=ONLY freq=%d", freq);
5372 } else {
5373 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5374 }
5375 if (res < 0 || res >= (int) sizeof(buf)) {
5376 send_resp(dut, conn, SIGMA_ERROR,
5377 "ErrorCode,snprintf failed");
5378 goto close_mon_conn;
5379 }
5380 if (wpa_command(intf, buf) < 0) {
5381 sigma_dut_print(dut, DUT_MSG_INFO,
5382 "Failed to start scan");
5383 send_resp(dut, conn, SIGMA_ERROR,
5384 "ErrorCode,scan failed");
5385 goto close_mon_conn;
5386 }
5387
5388 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5389 buf, sizeof(buf));
5390 if (res < 0) {
5391 sigma_dut_print(dut, DUT_MSG_INFO,
5392 "Scan did not complete");
5393 send_resp(dut, conn, SIGMA_ERROR,
5394 "ErrorCode,scan did not complete");
5395 goto close_mon_conn;
5396 }
5397
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005398 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5399 < 0) {
5400 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5401 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305402 status = -2;
5403 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005404 }
5405 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5406 bssid, chan);
5407 if (res > 0 && res < (int) sizeof(buf))
5408 res = wpa_command(intf, buf);
5409
5410 if (res < 0 || res >= (int) sizeof(buf)) {
5411 send_resp(dut, conn, SIGMA_ERROR,
5412 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305413 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005414 }
5415#else /* ANDROID */
5416 sigma_dut_print(dut, DUT_MSG_DEBUG,
5417 "Reassoc using iwpriv - skip chan=%d info",
5418 chan);
5419 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5420 if (system(buf) != 0) {
5421 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305422 status = -2;
5423 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005424 }
5425#endif /* ANDROID */
5426 sigma_dut_print(dut, DUT_MSG_INFO,
5427 "sta_reassoc: Run %s successful", buf);
5428 } else if (wpa_command(intf, "REASSOCIATE")) {
5429 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5430 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305431 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005432 }
5433
5434 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5435 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305436 if (res < 0) {
5437 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5438 status = -1;
5439 goto close_mon_conn;
5440 }
5441 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005442
Ashwini Patil467efef2017-05-25 12:18:27 +05305443close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005444 wpa_ctrl_detach(ctrl);
5445 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305446 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005447}
5448
5449
5450static void hs2_clear_credentials(const char *intf)
5451{
5452 wpa_command(intf, "REMOVE_CRED all");
5453}
5454
5455
Lior Davidcc88b562017-01-03 18:52:09 +02005456#ifdef __linux__
5457static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5458 unsigned int *aid)
5459{
Lior David0fe101e2017-03-09 16:09:50 +02005460 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005461
Lior David0fe101e2017-03-09 16:09:50 +02005462 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005463}
5464#endif /* __linux__ */
5465
5466
5467static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5468 unsigned int *aid)
5469{
5470 switch (get_driver_type()) {
5471#ifdef __linux__
5472 case DRIVER_WIL6210:
5473 return wil6210_get_aid(dut, bssid, aid);
5474#endif /* __linux__ */
5475 default:
5476 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5477 return -1;
5478 }
5479}
5480
5481
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005482static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5483 struct sigma_cmd *cmd)
5484{
5485 char buf[MAX_CMD_LEN];
5486 char bss_list[MAX_CMD_LEN];
5487 const char *parameter = get_param(cmd, "Parameter");
5488
5489 if (parameter == NULL)
5490 return -1;
5491
Lior Davidcc88b562017-01-03 18:52:09 +02005492 if (strcasecmp(parameter, "AID") == 0) {
5493 unsigned int aid = 0;
5494 char bssid[20];
5495
5496 if (get_wpa_status(get_station_ifname(), "bssid",
5497 bssid, sizeof(bssid)) < 0) {
5498 sigma_dut_print(dut, DUT_MSG_ERROR,
5499 "could not get bssid");
5500 return -2;
5501 }
5502
5503 if (sta_get_aid_60g(dut, bssid, &aid))
5504 return -2;
5505
5506 snprintf(buf, sizeof(buf), "aid,%d", aid);
5507 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5508 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5509 return 0;
5510 }
5511
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005512 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5513 char *bss_line;
5514 char *bss_id = NULL;
5515 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305516 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005517
5518 if (ifname == NULL) {
5519 sigma_dut_print(dut, DUT_MSG_INFO,
5520 "For get DiscoveredDevList need Interface name.");
5521 return -1;
5522 }
5523
5524 /*
5525 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5526 * of BSSIDs in "bssid=<BSSID>\n"
5527 */
5528 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5529 bss_list,
5530 sizeof(bss_list)) < 0) {
5531 sigma_dut_print(dut, DUT_MSG_ERROR,
5532 "Failed to get bss list");
5533 return -1;
5534 }
5535
5536 sigma_dut_print(dut, DUT_MSG_DEBUG,
5537 "bss list for ifname:%s is:%s",
5538 ifname, bss_list);
5539
5540 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305541 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005542 while (bss_line) {
5543 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5544 bss_id) {
5545 int len;
5546
5547 len = snprintf(buf + strlen(buf),
5548 sizeof(buf) - strlen(buf),
5549 ",%s", bss_id);
5550 free(bss_id);
5551 bss_id = NULL;
5552 if (len < 0) {
5553 sigma_dut_print(dut,
5554 DUT_MSG_ERROR,
5555 "Failed to read BSSID");
5556 send_resp(dut, conn, SIGMA_ERROR,
5557 "ErrorCode,Failed to read BSS ID");
5558 return 0;
5559 }
5560
5561 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5562 sigma_dut_print(dut,
5563 DUT_MSG_ERROR,
5564 "Response buf too small for list");
5565 send_resp(dut, conn,
5566 SIGMA_ERROR,
5567 "ErrorCode,Response buf too small for list");
5568 return 0;
5569 }
5570 }
5571
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305572 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005573 }
5574
5575 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5576 buf);
5577 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5578 return 0;
5579 }
5580
5581 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5582 return 0;
5583}
5584
5585
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005586static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
5587 struct sigma_cmd *cmd)
5588{
5589 char buf[MAX_CMD_LEN];
5590 const char *parameter = get_param(cmd, "Parameter");
5591
5592 if (!parameter)
5593 return -1;
5594
5595 if (strcasecmp(parameter, "RSSI") == 0) {
5596 char rssi[10];
5597
5598 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
5599 rssi, sizeof(rssi)) < 0) {
5600 sigma_dut_print(dut, DUT_MSG_ERROR,
5601 "Could not get RSSI");
5602 return -2;
5603 }
5604
5605 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
5606 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
5607 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5608 return 0;
5609 }
5610
5611 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5612 return 0;
5613}
5614
5615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005616static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5617 struct sigma_cmd *cmd)
5618{
5619 const char *program = get_param(cmd, "Program");
5620
5621 if (program == NULL)
5622 return -1;
5623
5624 if (strcasecmp(program, "P2PNFC") == 0)
5625 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5626
5627 if (strcasecmp(program, "60ghz") == 0)
5628 return sta_get_parameter_60g(dut, conn, cmd);
5629
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005630 if (strcasecmp(program, "he") == 0)
5631 return sta_get_parameter_he(dut, conn, cmd);
5632
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005633#ifdef ANDROID_NAN
5634 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005635 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636#endif /* ANDROID_NAN */
5637
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005638#ifdef MIRACAST
5639 if (strcasecmp(program, "WFD") == 0 ||
5640 strcasecmp(program, "DisplayR2") == 0)
5641 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5642#endif /* MIRACAST */
5643
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005644 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5645 return 0;
5646}
5647
5648
5649static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5650 const char *type)
5651{
5652 char buf[100];
5653
5654 if (dut->program == PROGRAM_VHT) {
5655 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5656 if (system(buf) != 0) {
5657 sigma_dut_print(dut, DUT_MSG_ERROR,
5658 "iwpriv %s chwidth failed", intf);
5659 }
5660
5661 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5662 if (system(buf) != 0) {
5663 sigma_dut_print(dut, DUT_MSG_ERROR,
5664 "iwpriv %s mode 11ACVHT80 failed",
5665 intf);
5666 }
5667
5668 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5669 if (system(buf) != 0) {
5670 sigma_dut_print(dut, DUT_MSG_ERROR,
5671 "iwpriv %s vhtmcs -1 failed", intf);
5672 }
5673 }
5674
5675 if (dut->program == PROGRAM_HT) {
5676 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5677 if (system(buf) != 0) {
5678 sigma_dut_print(dut, DUT_MSG_ERROR,
5679 "iwpriv %s chwidth failed", intf);
5680 }
5681
5682 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5683 if (system(buf) != 0) {
5684 sigma_dut_print(dut, DUT_MSG_ERROR,
5685 "iwpriv %s mode 11naht40 failed",
5686 intf);
5687 }
5688
5689 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5690 if (system(buf) != 0) {
5691 sigma_dut_print(dut, DUT_MSG_ERROR,
5692 "iwpriv set11NRates failed");
5693 }
5694 }
5695
5696 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5697 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5698 if (system(buf) != 0) {
5699 sigma_dut_print(dut, DUT_MSG_ERROR,
5700 "disabling powersave failed");
5701 }
5702
5703 /* Reset CTS width */
5704 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5705 intf);
5706 if (system(buf) != 0) {
5707 sigma_dut_print(dut, DUT_MSG_ERROR,
5708 "wifitool %s beeliner_fw_test 54 0 failed",
5709 intf);
5710 }
5711
5712 /* Enable Dynamic Bandwidth signalling by default */
5713 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5714 if (system(buf) != 0) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "iwpriv %s cwmenable 1 failed", intf);
5717 }
5718
5719 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5720 if (system(buf) != 0) {
5721 sigma_dut_print(dut, DUT_MSG_ERROR,
5722 "iwpriv rts failed");
5723 }
5724 }
5725
5726 if (type && strcasecmp(type, "Testbed") == 0) {
5727 dut->testbed_flag_txsp = 1;
5728 dut->testbed_flag_rxsp = 1;
5729 /* STA has to set spatial stream to 2 per Appendix H */
5730 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5731 if (system(buf) != 0) {
5732 sigma_dut_print(dut, DUT_MSG_ERROR,
5733 "iwpriv vht_mcsmap failed");
5734 }
5735
5736 /* Disable LDPC per Appendix H */
5737 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5738 if (system(buf) != 0) {
5739 sigma_dut_print(dut, DUT_MSG_ERROR,
5740 "iwpriv %s ldpc 0 failed", intf);
5741 }
5742
5743 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5744 if (system(buf) != 0) {
5745 sigma_dut_print(dut, DUT_MSG_ERROR,
5746 "iwpriv amsdu failed");
5747 }
5748
5749 /* TODO: Disable STBC 2x1 transmit and receive */
5750 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5751 if (system(buf) != 0) {
5752 sigma_dut_print(dut, DUT_MSG_ERROR,
5753 "Disable tx_stbc 0 failed");
5754 }
5755
5756 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5757 if (system(buf) != 0) {
5758 sigma_dut_print(dut, DUT_MSG_ERROR,
5759 "Disable rx_stbc 0 failed");
5760 }
5761
5762 /* STA has to disable Short GI per Appendix H */
5763 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5764 if (system(buf) != 0) {
5765 sigma_dut_print(dut, DUT_MSG_ERROR,
5766 "iwpriv %s shortgi 0 failed", intf);
5767 }
5768 }
5769
5770 if (type && strcasecmp(type, "DUT") == 0) {
5771 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5772 if (system(buf) != 0) {
5773 sigma_dut_print(dut, DUT_MSG_ERROR,
5774 "iwpriv %s nss 3 failed", intf);
5775 }
Arif Hussainac6c5112018-05-25 17:34:00 -07005776 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005777
5778 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5779 if (system(buf) != 0) {
5780 sigma_dut_print(dut, DUT_MSG_ERROR,
5781 "iwpriv %s shortgi 1 failed", intf);
5782 }
5783 }
5784}
5785
5786
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005787#ifdef NL80211_SUPPORT
5788static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5789 enum he_mcs_config mcs)
5790{
5791 struct nl_msg *msg;
5792 int ret = 0;
5793 struct nlattr *params;
5794 int ifindex;
5795
5796 ifindex = if_nametoindex(intf);
5797 if (ifindex == 0) {
5798 sigma_dut_print(dut, DUT_MSG_ERROR,
5799 "%s: Index for interface %s failed",
5800 __func__, intf);
5801 return -1;
5802 }
5803
5804 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5805 NL80211_CMD_VENDOR)) ||
5806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5807 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5808 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5809 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5810 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5811 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5812 mcs)) {
5813 sigma_dut_print(dut, DUT_MSG_ERROR,
5814 "%s: err in adding vendor_cmd and vendor_data",
5815 __func__);
5816 nlmsg_free(msg);
5817 return -1;
5818 }
5819 nla_nest_end(msg, params);
5820
5821 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5822 if (ret) {
5823 sigma_dut_print(dut, DUT_MSG_ERROR,
5824 "%s: err in send_and_recv_msgs, ret=%d",
5825 __func__, ret);
5826 }
5827 return ret;
5828}
5829#endif /* NL80211_SUPPORT */
5830
5831
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07005832static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
5833 const char *intf, 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_HE_ACTION_TX_TB_PPDU,
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 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
5877 return -1;
5878#endif /* NL80211_SUPPORT */
5879}
5880
5881
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005882static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5883 const char *intf, int enable)
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",
5895 __func__, intf);
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_WEP_TKIP_IN_HE,
5908 enable)) {
5909 sigma_dut_print(dut, DUT_MSG_ERROR,
5910 "%s: err in adding vendor_cmd and vendor_data",
5911 __func__);
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",
5921 __func__, ret);
5922 }
5923 return ret;
5924#else /* NL80211_SUPPORT */
5925 sigma_dut_print(dut, DUT_MSG_ERROR,
5926 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5927 return -1;
5928#endif /* NL80211_SUPPORT */
5929}
5930
5931
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005932static int sta_set_addba_buf_size(struct sigma_dut *dut,
5933 const char *intf, int bufsize)
5934{
5935#ifdef NL80211_SUPPORT
5936 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",
5945 __func__, intf);
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)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07005956 nla_put_u16(msg,
5957 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5958 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005959 sigma_dut_print(dut, DUT_MSG_ERROR,
5960 "%s: err in adding vendor_cmd and vendor_data",
5961 __func__);
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",
5971 __func__, ret);
5972 }
5973 return ret;
5974#else /* NL80211_SUPPORT */
5975 sigma_dut_print(dut, DUT_MSG_ERROR,
5976 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5977 return -1;
5978#endif /* NL80211_SUPPORT */
5979}
5980
5981
Arif Hussain8d5b27b2018-05-14 14:31:03 -07005982static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
5983 int enable)
5984{
5985#ifdef NL80211_SUPPORT
5986 struct nl_msg *msg;
5987 int ret = 0;
5988 struct nlattr *params;
5989 int ifindex;
5990
5991 ifindex = if_nametoindex(intf);
5992 if (ifindex == 0) {
5993 sigma_dut_print(dut, DUT_MSG_ERROR,
5994 "%s: Index for interface %s failed",
5995 __func__, intf);
5996 return -1;
5997 }
5998
5999 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6000 NL80211_CMD_VENDOR)) ||
6001 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6002 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6003 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6004 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6005 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6006 nla_put_u8(msg,
6007 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6008 enable)) {
6009 sigma_dut_print(dut, DUT_MSG_ERROR,
6010 "%s: err in adding vendor_cmd and vendor_data",
6011 __func__);
6012 nlmsg_free(msg);
6013 return -1;
6014 }
6015 nla_nest_end(msg, params);
6016
6017 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6018 if (ret) {
6019 sigma_dut_print(dut, DUT_MSG_ERROR,
6020 "%s: err in send_and_recv_msgs, ret=%d",
6021 __func__, ret);
6022 }
6023 return ret;
6024#else /* NL80211_SUPPORT */
6025 sigma_dut_print(dut, DUT_MSG_ERROR,
6026 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6027 return -1;
6028#endif /* NL80211_SUPPORT */
6029}
6030
6031
Arif Hussain9765f7d2018-07-03 08:28:26 -07006032static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6033 int val)
6034{
6035#ifdef NL80211_SUPPORT
6036 struct nl_msg *msg;
6037 int ret = 0;
6038 struct nlattr *params;
6039 int ifindex;
6040
6041 ifindex = if_nametoindex(intf);
6042 if (ifindex == 0) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "%s: Index for interface %s failed, val:%d",
6045 __func__, intf, val);
6046 return -1;
6047 }
6048
6049 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6050 NL80211_CMD_VENDOR)) ||
6051 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6052 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6053 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6054 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6055 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6056 nla_put_u8(msg,
6057 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6058 val)) {
6059 sigma_dut_print(dut, DUT_MSG_ERROR,
6060 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6061 __func__, val);
6062 nlmsg_free(msg);
6063 return -1;
6064 }
6065 nla_nest_end(msg, params);
6066
6067 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6068 if (ret) {
6069 sigma_dut_print(dut, DUT_MSG_ERROR,
6070 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6071 __func__, ret, val);
6072 }
6073 return ret;
6074#else /* NL80211_SUPPORT */
6075 sigma_dut_print(dut, DUT_MSG_ERROR,
6076 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6077 return -1;
6078#endif /* NL80211_SUPPORT */
6079}
6080
6081
Arif Hussain68d23f52018-07-11 13:39:08 -07006082#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006083static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6084 enum qca_wlan_he_mac_padding_dur val)
6085{
Arif Hussain68d23f52018-07-11 13:39:08 -07006086 struct nl_msg *msg;
6087 int ret = 0;
6088 struct nlattr *params;
6089 int ifindex;
6090
6091 ifindex = if_nametoindex(intf);
6092 if (ifindex == 0) {
6093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "%s: Index for interface %s failed, val:%d",
6095 __func__, intf, val);
6096 return -1;
6097 }
6098
6099 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6100 NL80211_CMD_VENDOR)) ||
6101 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6102 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6103 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6104 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6105 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6106 nla_put_u8(msg,
6107 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6108 val)) {
6109 sigma_dut_print(dut, DUT_MSG_ERROR,
6110 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6111 __func__, val);
6112 nlmsg_free(msg);
6113 return -1;
6114 }
6115 nla_nest_end(msg, params);
6116
6117 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6118 if (ret) {
6119 sigma_dut_print(dut, DUT_MSG_ERROR,
6120 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6121 __func__, ret, val);
6122 }
6123 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006124}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006125#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006126
6127
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006128static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6129 int val)
6130{
6131#ifdef NL80211_SUPPORT
6132 struct nl_msg *msg;
6133 int ret = 0;
6134 struct nlattr *params;
6135 int ifindex;
6136
6137 ifindex = if_nametoindex(intf);
6138 if (ifindex == 0) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR,
6140 "%s: Index for interface %s failed, val:%d",
6141 __func__, intf, val);
6142 return -1;
6143 }
6144
6145 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6146 NL80211_CMD_VENDOR)) ||
6147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6148 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6149 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6150 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6151 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6152 nla_put_u8(msg,
6153 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6154 val)) {
6155 sigma_dut_print(dut, DUT_MSG_ERROR,
6156 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6157 __func__, val);
6158 nlmsg_free(msg);
6159 return -1;
6160 }
6161 nla_nest_end(msg, params);
6162
6163 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6164 if (ret) {
6165 sigma_dut_print(dut, DUT_MSG_ERROR,
6166 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6167 __func__, ret, val);
6168 }
6169 return ret;
6170#else /* NL80211_SUPPORT */
6171 sigma_dut_print(dut, DUT_MSG_ERROR,
6172 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6173 return -1;
6174#endif /* NL80211_SUPPORT */
6175}
6176
6177
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006178static int sta_set_he_om_ctrl_nss(struct sigma_dut *dut, const char *intf,
6179 int val)
6180{
6181#ifdef NL80211_SUPPORT
6182 struct nl_msg *msg;
6183 int ret = 0;
6184 struct nlattr *params;
6185 int ifindex;
6186
6187 ifindex = if_nametoindex(intf);
6188 if (ifindex == 0) {
6189 sigma_dut_print(dut, DUT_MSG_ERROR,
6190 "%s: Index for interface %s failed, val:%d",
6191 __func__, intf, val);
6192 return -1;
6193 }
6194
6195 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6196 NL80211_CMD_VENDOR)) ||
6197 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6198 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6199 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6200 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6201 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6202 nla_put_u8(msg,
6203 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_NSS,
6204 val)) {
6205 sigma_dut_print(dut, DUT_MSG_ERROR,
6206 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6207 __func__, val);
6208 nlmsg_free(msg);
6209 return -1;
6210 }
6211 nla_nest_end(msg, params);
6212
6213 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6214 if (ret) {
6215 sigma_dut_print(dut, DUT_MSG_ERROR,
6216 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6217 __func__, ret, val);
6218 }
6219 return ret;
6220#else /* NL80211_SUPPORT */
6221 sigma_dut_print(dut, DUT_MSG_ERROR,
6222 "OM CTRL NSS cannot be set without NL80211_SUPPORT defined");
6223 return -1;
6224#endif /* NL80211_SUPPORT */
6225}
6226
6227
6228static int sta_set_he_om_ctrl_bw(struct sigma_dut *dut, const char *intf,
6229 enum qca_wlan_he_om_ctrl_ch_bw val)
6230{
6231#ifdef NL80211_SUPPORT
6232 struct nl_msg *msg;
6233 int ret = 0;
6234 struct nlattr *params;
6235 int ifindex;
6236
6237 ifindex = if_nametoindex(intf);
6238 if (ifindex == 0) {
6239 sigma_dut_print(dut, DUT_MSG_ERROR,
6240 "%s: Index for interface %s failed, val:%d",
6241 __func__, intf, val);
6242 return -1;
6243 }
6244
6245 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6246 NL80211_CMD_VENDOR)) ||
6247 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6248 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6249 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6250 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6251 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6252 nla_put_u8(msg,
6253 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_BW,
6254 val)) {
6255 sigma_dut_print(dut, DUT_MSG_ERROR,
6256 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6257 __func__, val);
6258 nlmsg_free(msg);
6259 return -1;
6260 }
6261 nla_nest_end(msg, params);
6262
6263 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6264 if (ret) {
6265 sigma_dut_print(dut, DUT_MSG_ERROR,
6266 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6267 __func__, ret, val);
6268 }
6269 return ret;
6270#else /* NL80211_SUPPORT */
6271 sigma_dut_print(dut, DUT_MSG_ERROR,
6272 "OM CTRL BW cannot be set without NL80211_SUPPORT defined");
6273 return -1;
6274#endif /* NL80211_SUPPORT */
6275}
6276
6277
6278#ifdef NL80211_SUPPORT
6279static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6280{
6281 struct nl_msg *msg;
6282 int ret = 0;
6283 struct nlattr *params;
6284 int ifindex;
6285
6286 ifindex = if_nametoindex(intf);
6287 if (ifindex == 0) {
6288 sigma_dut_print(dut, DUT_MSG_ERROR,
6289 "%s: Index for interface %s failed",
6290 __func__, intf);
6291 return -1;
6292 }
6293
6294 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6295 NL80211_CMD_VENDOR)) ||
6296 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6297 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6298 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6299 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6300 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6301 nla_put_flag(msg,
6302 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6303 sigma_dut_print(dut, DUT_MSG_ERROR,
6304 "%s: err in adding vendor_cmd and vendor_data",
6305 __func__);
6306 nlmsg_free(msg);
6307 return -1;
6308 }
6309 nla_nest_end(msg, params);
6310
6311 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6312 if (ret) {
6313 sigma_dut_print(dut, DUT_MSG_ERROR,
6314 "%s: err in send_and_recv_msgs, ret=%d",
6315 __func__, ret);
6316 }
6317 return ret;
6318}
6319#endif /* NL80211_SUPPORT */
6320
6321
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006322static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6323 int val)
6324{
6325#ifdef NL80211_SUPPORT
6326 struct nl_msg *msg;
6327 int ret = 0;
6328 struct nlattr *params;
6329 int ifindex;
6330
6331 ifindex = if_nametoindex(intf);
6332 if (ifindex == 0) {
6333 sigma_dut_print(dut, DUT_MSG_ERROR,
6334 "%s: Index for interface %s failed, val:%d",
6335 __func__, intf, val);
6336 return -1;
6337 }
6338
6339 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6340 NL80211_CMD_VENDOR)) ||
6341 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6342 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6343 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6344 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6345 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6346 nla_put_u8(msg,
6347 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6348 val)) {
6349 sigma_dut_print(dut, DUT_MSG_ERROR,
6350 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6351 __func__, val);
6352 nlmsg_free(msg);
6353 return -1;
6354 }
6355 nla_nest_end(msg, params);
6356
6357 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6358 if (ret) {
6359 sigma_dut_print(dut, DUT_MSG_ERROR,
6360 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6361 __func__, ret, val);
6362 }
6363 return ret;
6364#else /* NL80211_SUPPORT */
6365 sigma_dut_print(dut, DUT_MSG_ERROR,
6366 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6367 return -1;
6368#endif /* NL80211_SUPPORT */
6369}
6370
6371
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006372static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6373 int val)
6374{
6375#ifdef NL80211_SUPPORT
6376 struct nl_msg *msg;
6377 int ret = 0;
6378 struct nlattr *params;
6379 int ifindex;
6380
6381 ifindex = if_nametoindex(intf);
6382 if (ifindex == 0) {
6383 sigma_dut_print(dut, DUT_MSG_ERROR,
6384 "%s: Index for interface %s failed, val:%d",
6385 __func__, intf, val);
6386 return -1;
6387 }
6388
6389 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6390 NL80211_CMD_VENDOR)) ||
6391 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6392 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6393 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6394 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6395 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6396 nla_put_u8(msg,
6397 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
6398 val)) {
6399 sigma_dut_print(dut, DUT_MSG_ERROR,
6400 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6401 __func__, val);
6402 nlmsg_free(msg);
6403 return -1;
6404 }
6405 nla_nest_end(msg, params);
6406
6407 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6408 if (ret) {
6409 sigma_dut_print(dut, DUT_MSG_ERROR,
6410 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6411 __func__, ret, val);
6412 }
6413 return ret;
6414#else /* NL80211_SUPPORT */
6415 sigma_dut_print(dut, DUT_MSG_ERROR,
6416 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
6417 return -1;
6418#endif /* NL80211_SUPPORT */
6419}
6420
6421
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006422static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
6423 const char *type)
6424{
6425 char buf[60];
6426
6427 if (dut->program == PROGRAM_HE) {
6428 /* resetting phymode to auto in case of HE program */
6429 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
6430 if (system(buf) != 0) {
6431 sigma_dut_print(dut, DUT_MSG_ERROR,
6432 "iwpriv %s setphymode failed", intf);
6433 }
6434
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07006435 /* reset the rate to Auto rate */
6436 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
6437 intf);
6438 if (system(buf) != 0) {
6439 sigma_dut_print(dut, DUT_MSG_ERROR,
6440 "iwpriv %s set_11ax_rate 0xff failed",
6441 intf);
6442 }
6443
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07006444 /* reset the LDPC setting */
6445 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
6446 if (system(buf) != 0) {
6447 sigma_dut_print(dut, DUT_MSG_ERROR,
6448 "iwpriv %s ldpc 1 failed", intf);
6449 }
6450
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006451 /* reset the power save setting */
6452 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
6453 if (system(buf) != 0) {
6454 sigma_dut_print(dut, DUT_MSG_ERROR,
6455 "iwpriv %s setPower 2 failed", intf);
6456 }
6457
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006458 /* remove all network profiles */
6459 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006460
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006461 /* Configure ADDBA Req/Rsp buffer size to be 64 */
6462 sta_set_addba_buf_size(dut, intf, 64);
6463
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08006464#ifdef NL80211_SUPPORT
6465 /* Disable noackpolicy for all AC */
6466 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
6467 sigma_dut_print(dut, DUT_MSG_ERROR,
6468 "Disable of noackpolicy for all AC failed");
6469 }
6470#endif /* NL80211_SUPPORT */
6471
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08006472 /* Enable WMM by default */
6473 if (wcn_sta_set_wmm(dut, intf, "on")) {
6474 sigma_dut_print(dut, DUT_MSG_ERROR,
6475 "Enable of WMM in sta_reset_default_wcn failed");
6476 }
6477
6478 /* Disable ADDBA_REJECT by default */
6479 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
6480 sigma_dut_print(dut, DUT_MSG_ERROR,
6481 "Disable of addba_reject in sta_reset_default_wcn failed");
6482 }
6483
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006484 /* Enable sending of ADDBA by default */
6485 if (nlvendor_config_send_addba(dut, intf, 1)) {
6486 sigma_dut_print(dut, DUT_MSG_ERROR,
6487 "Enable sending of ADDBA in sta_reset_default_wcn failed");
6488 }
6489
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08006490 /* Enable AMPDU by default */
6491 iwpriv_sta_set_ampdu(dut, intf, 1);
6492
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006493#ifdef NL80211_SUPPORT
6494 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
6495 sigma_dut_print(dut, DUT_MSG_ERROR,
6496 "Set LTF config to default in sta_reset_default_wcn failed");
6497 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07006498
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08006499 /* set the beamformee NSTS(maximum number of
6500 * space-time streams) to default DUT config
6501 */
6502 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07006503 sigma_dut_print(dut, DUT_MSG_ERROR,
6504 "Failed to set BeamformeeSTS");
6505 }
Arif Hussain68d23f52018-07-11 13:39:08 -07006506
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006507 if (sta_set_mac_padding_duration(
6508 dut, intf,
6509 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07006510 sigma_dut_print(dut, DUT_MSG_ERROR,
6511 "Failed to set MAC padding duration");
6512 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006513
6514 if (sta_set_mu_edca_override(dut, intf, 0)) {
6515 sigma_dut_print(dut, DUT_MSG_ERROR,
6516 "ErrorCode,Failed to set MU EDCA override disable");
6517 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006518
6519 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
6520 sigma_dut_print(dut, DUT_MSG_ERROR,
6521 "Failed to set OM ctrl supp");
6522 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006523
6524 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
6525 sigma_dut_print(dut, DUT_MSG_ERROR,
6526 "Failed to set Tx SU PPDU enable");
6527 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006528
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006529 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
6530 sigma_dut_print(dut, DUT_MSG_ERROR,
6531 "failed to send TB PPDU Tx cfg");
6532 }
6533
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006534 if (sta_set_he_om_ctrl_reset(dut, intf)) {
6535 sigma_dut_print(dut, DUT_MSG_ERROR,
6536 "Failed to set OM ctrl reset");
6537 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08006538
6539 /* +HTC-HE support default on */
6540 if (sta_set_he_htc_supp(dut, intf, 1)) {
6541 sigma_dut_print(dut, DUT_MSG_ERROR,
6542 "Setting of +HTC-HE support failed");
6543 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006544#endif /* NL80211_SUPPORT */
6545
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006546 if (sta_set_tx_beamformee(dut, intf, 1)) {
6547 sigma_dut_print(dut, DUT_MSG_ERROR,
6548 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
6549 }
6550
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006551 /* Set nss to 1 and MCS 0-7 in case of testbed */
6552 if (type && strcasecmp(type, "Testbed") == 0) {
6553#ifdef NL80211_SUPPORT
6554 int ret;
6555#endif /* NL80211_SUPPORT */
6556
6557 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
6558 if (system(buf) != 0) {
6559 sigma_dut_print(dut, DUT_MSG_ERROR,
6560 "iwpriv %s nss failed", intf);
6561 }
6562
6563#ifdef NL80211_SUPPORT
6564 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
6565 if (ret) {
6566 sigma_dut_print(dut, DUT_MSG_ERROR,
6567 "Setting of MCS failed, ret:%d",
6568 ret);
6569 }
6570#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08006571
6572 /* Disable STBC as default */
6573 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006574
6575 /* Disable AMSDU as default */
6576 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006577
6578#ifdef NL80211_SUPPORT
6579 /* HE fragmentation default off */
6580 if (sta_set_he_fragmentation(dut, intf,
6581 HE_FRAG_DISABLE)) {
6582 sigma_dut_print(dut, DUT_MSG_ERROR,
6583 "Setting of HE fragmentation failed");
6584 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08006585
6586 /* set the beamformee NSTS(maximum number of
6587 * space-time streams) to default testbed config
6588 */
6589 if (sta_set_beamformee_sts(dut, intf, 3)) {
6590 sigma_dut_print(dut, DUT_MSG_ERROR,
6591 "Failed to set BeamformeeSTS");
6592 }
6593
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08006594 /* +HTC-HE support default off */
6595 if (sta_set_he_htc_supp(dut, intf, 0)) {
6596 sigma_dut_print(dut, DUT_MSG_ERROR,
6597 "Setting of +HTC-HE support failed");
6598 }
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006599#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006600
6601 /* Enable WEP/TKIP with HE capability in testbed */
6602 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
6603 sigma_dut_print(dut, DUT_MSG_ERROR,
6604 "Enabling HE config with WEP/TKIP failed");
6605 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006606 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006607
6608 /* Defaults in case of DUT */
6609 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07006610 /* Enable STBC by default */
6611 wcn_sta_set_stbc(dut, intf, "1");
6612
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006613 /* set nss to 2 */
6614 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
6615 if (system(buf) != 0) {
6616 sigma_dut_print(dut, DUT_MSG_ERROR,
6617 "iwpriv %s nss 2 failed", intf);
6618 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006619 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006620
6621#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07006622 /* Set HE_MCS to 0-11 */
6623 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "Setting of MCS failed");
6626 }
6627#endif /* NL80211_SUPPORT */
6628
6629 /* Disable WEP/TKIP with HE capability in DUT */
6630 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
6631 sigma_dut_print(dut, DUT_MSG_ERROR,
6632 "Enabling HE config with WEP/TKIP failed");
6633 }
6634 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006635 }
6636}
6637
6638
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006639static int cmd_sta_reset_default(struct sigma_dut *dut,
6640 struct sigma_conn *conn,
6641 struct sigma_cmd *cmd)
6642{
6643 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
6644 struct sigma_cmd *cmd);
6645 const char *intf = get_param(cmd, "Interface");
6646 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006647 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306648 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006649
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006650 if (!program)
6651 program = get_param(cmd, "prog");
6652 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006653 dut->device_type = STA_unknown;
6654 type = get_param(cmd, "type");
6655 if (type && strcasecmp(type, "Testbed") == 0)
6656 dut->device_type = STA_testbed;
6657 if (type && strcasecmp(type, "DUT") == 0)
6658 dut->device_type = STA_dut;
6659
6660 if (dut->program == PROGRAM_TDLS) {
6661 /* Clear TDLS testing mode */
6662 wpa_command(intf, "SET tdls_disabled 0");
6663 wpa_command(intf, "SET tdls_testing 0");
6664 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05306665 if (get_driver_type() == DRIVER_WCN) {
6666 /* Enable the WCN driver in TDLS Explicit trigger mode
6667 */
6668 wpa_command(intf, "SET tdls_external_control 0");
6669 wpa_command(intf, "SET tdls_trigger_control 0");
6670 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006671 }
6672
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006673#ifdef MIRACAST
6674 if (dut->program == PROGRAM_WFD ||
6675 dut->program == PROGRAM_DISPLAYR2)
6676 miracast_sta_reset_default(dut, conn, cmd);
6677#endif /* MIRACAST */
6678
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006679 switch (get_driver_type()) {
6680 case DRIVER_ATHEROS:
6681 sta_reset_default_ath(dut, intf, type);
6682 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006683 case DRIVER_WCN:
6684 sta_reset_default_wcn(dut, intf, type);
6685 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006686 default:
6687 break;
6688 }
6689
6690#ifdef ANDROID_NAN
6691 if (dut->program == PROGRAM_NAN)
6692 nan_cmd_sta_reset_default(dut, conn, cmd);
6693#endif /* ANDROID_NAN */
6694
Jouni Malinenba630452018-06-22 11:49:59 +03006695 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006696 unlink("SP/wi-fi.org/pps.xml");
6697 if (system("rm -r SP/*") != 0) {
6698 }
6699 unlink("next-client-cert.pem");
6700 unlink("next-client-key.pem");
6701 }
6702
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02006703 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006704 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02006705 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006706
6707 if (!dev_role) {
6708 send_resp(dut, conn, SIGMA_ERROR,
6709 "errorCode,Missing DevRole argument");
6710 return 0;
6711 }
6712
6713 if (strcasecmp(dev_role, "STA") == 0)
6714 dut->dev_role = DEVROLE_STA;
6715 else if (strcasecmp(dev_role, "PCP") == 0)
6716 dut->dev_role = DEVROLE_PCP;
6717 else {
6718 send_resp(dut, conn, SIGMA_ERROR,
6719 "errorCode,Unknown DevRole");
6720 return 0;
6721 }
6722
6723 if (dut->device_type == STA_unknown) {
6724 sigma_dut_print(dut, DUT_MSG_ERROR,
6725 "Device type is not STA testbed or DUT");
6726 send_resp(dut, conn, SIGMA_ERROR,
6727 "errorCode,Unknown device type");
6728 return 0;
6729 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02006730
6731 sigma_dut_print(dut, DUT_MSG_DEBUG,
6732 "Setting msdu_size to MAX: 7912");
6733 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
6734 get_station_ifname());
6735
6736 if (system(buf) != 0) {
6737 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6738 buf);
6739 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6740 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006741 }
6742
6743 wpa_command(intf, "WPS_ER_STOP");
6744 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05306745 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006746 wpa_command(intf, "SET radio_disabled 0");
6747
6748 if (dut->tmp_mac_addr && dut->set_macaddr) {
6749 dut->tmp_mac_addr = 0;
6750 if (system(dut->set_macaddr) != 0) {
6751 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
6752 "temporary MAC address");
6753 }
6754 }
6755
6756 set_ps(intf, dut, 0);
6757
Jouni Malinenba630452018-06-22 11:49:59 +03006758 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6759 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006760 wpa_command(intf, "SET interworking 1");
6761 wpa_command(intf, "SET hs20 1");
6762 }
6763
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006764 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03006765 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006766 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006767 wpa_command(intf, "SET pmf 1");
6768 } else {
6769 wpa_command(intf, "SET pmf 0");
6770 }
6771
6772 hs2_clear_credentials(intf);
6773 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6774 wpa_command(intf, "SET access_network_type 15");
6775
6776 static_ip_file(0, NULL, NULL, NULL);
6777 kill_dhcp_client(dut, intf);
6778 clear_ip_addr(dut, intf);
6779
6780 dut->er_oper_performed = 0;
6781 dut->er_oper_bssid[0] = '\0';
6782
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006783 if (dut->program == PROGRAM_LOC) {
6784 /* Disable Interworking by default */
6785 wpa_command(get_station_ifname(), "SET interworking 0");
6786 }
6787
Ashwini Patil00402582017-04-13 12:29:39 +05306788 if (dut->program == PROGRAM_MBO) {
6789 free(dut->non_pref_ch_list);
6790 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306791 free(dut->btm_query_cand_list);
6792 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306793 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306794 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306795 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306796 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05306797 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306798 }
6799
Jouni Malinen3c367e82017-06-23 17:01:47 +03006800 free(dut->rsne_override);
6801 dut->rsne_override = NULL;
6802
Jouni Malinen68143132017-09-02 02:34:08 +03006803 free(dut->sae_commit_override);
6804 dut->sae_commit_override = NULL;
6805
Jouni Malinend86e5822017-08-29 03:55:32 +03006806 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006807 free(dut->dpp_peer_uri);
6808 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006809 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006810 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006811
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006812 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6813
vamsi krishnaa2799492017-12-05 14:28:01 +05306814 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306815 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306816 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306817 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6818 dut->fils_hlp = 0;
6819#ifdef ANDROID
6820 hlp_thread_cleanup(dut);
6821#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306822 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306823
Sunil Dutt076081f2018-02-05 19:45:50 +05306824#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306825 if (get_driver_type() == DRIVER_WCN &&
6826 dut->config_rsnie == 1) {
6827 dut->config_rsnie = 0;
6828 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306829 }
6830#endif /* NL80211_SUPPORT */
6831
Sunil Duttfebf8a82018-02-09 18:50:13 +05306832 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6833 dut->dev_role = DEVROLE_STA_CFON;
6834 return sta_cfon_reset_default(dut, conn, cmd);
6835 }
6836
Jouni Malinen439352d2018-09-13 03:42:23 +03006837 wpa_command(intf, "SET setband AUTO");
6838
Sunil Duttfebf8a82018-02-09 18:50:13 +05306839 if (dut->program != PROGRAM_VHT)
6840 return cmd_sta_p2p_reset(dut, conn, cmd);
6841
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006842 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843}
6844
6845
6846static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6847 struct sigma_cmd *cmd)
6848{
6849 const char *program = get_param(cmd, "Program");
6850
6851 if (program == NULL)
6852 return -1;
6853#ifdef ANDROID_NAN
6854 if (strcasecmp(program, "NAN") == 0)
6855 return nan_cmd_sta_get_events(dut, conn, cmd);
6856#endif /* ANDROID_NAN */
6857 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6858 return 0;
6859}
6860
6861
Jouni Malinen82905202018-04-29 17:20:10 +03006862static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6863 struct sigma_cmd *cmd)
6864{
6865 const char *url = get_param(cmd, "url");
6866 const char *method = get_param(cmd, "method");
6867 pid_t pid;
6868 int status;
6869
6870 if (!url || !method)
6871 return -1;
6872
6873 /* TODO: Add support for method,post */
6874 if (strcasecmp(method, "get") != 0) {
6875 send_resp(dut, conn, SIGMA_ERROR,
6876 "ErrorCode,Unsupported method");
6877 return 0;
6878 }
6879
6880 pid = fork();
6881 if (pid < 0) {
6882 perror("fork");
6883 return -1;
6884 }
6885
6886 if (pid == 0) {
6887 char * argv[5] = { "wget", "-O", "/dev/null",
6888 (char *) url, NULL };
6889
6890 execv("/usr/bin/wget", argv);
6891 perror("execv");
6892 exit(0);
6893 return -1;
6894 }
6895
6896 if (waitpid(pid, &status, 0) < 0) {
6897 perror("waitpid");
6898 return -1;
6899 }
6900
6901 if (WIFEXITED(status)) {
6902 const char *errmsg;
6903
6904 if (WEXITSTATUS(status) == 0)
6905 return 1;
6906 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6907 WEXITSTATUS(status));
6908 switch (WEXITSTATUS(status)) {
6909 case 4:
6910 errmsg = "errmsg,Network failure";
6911 break;
6912 case 8:
6913 errmsg = "errmsg,Server issued an error response";
6914 break;
6915 default:
6916 errmsg = "errmsg,Unknown failure from wget";
6917 break;
6918 }
6919 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6920 return 0;
6921 }
6922
6923 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6924 return 0;
6925}
6926
6927
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006928static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6929 struct sigma_cmd *cmd)
6930{
6931 const char *program = get_param(cmd, "Prog");
6932
Jouni Malinen82905202018-04-29 17:20:10 +03006933 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006934 return -1;
6935#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006936 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006937 return nan_cmd_sta_exec_action(dut, conn, cmd);
6938#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006939
6940 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006941 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006942
6943 if (get_param(cmd, "url"))
6944 return sta_exec_action_url(dut, conn, cmd);
6945
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006946 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6947 return 0;
6948}
6949
6950
6951static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6952 struct sigma_cmd *cmd)
6953{
6954 const char *intf = get_param(cmd, "Interface");
6955 const char *val, *mcs32, *rate;
6956
6957 val = get_param(cmd, "GREENFIELD");
6958 if (val) {
6959 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6960 /* Enable GD */
6961 send_resp(dut, conn, SIGMA_ERROR,
6962 "ErrorCode,GF not supported");
6963 return 0;
6964 }
6965 }
6966
6967 val = get_param(cmd, "SGI20");
6968 if (val) {
6969 switch (get_driver_type()) {
6970 case DRIVER_ATHEROS:
6971 ath_sta_set_sgi(dut, intf, val);
6972 break;
6973 default:
6974 send_resp(dut, conn, SIGMA_ERROR,
6975 "ErrorCode,SGI20 not supported");
6976 return 0;
6977 }
6978 }
6979
6980 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6981 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6982 if (mcs32 && rate) {
6983 /* TODO */
6984 send_resp(dut, conn, SIGMA_ERROR,
6985 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6986 return 0;
6987 } else if (mcs32 && !rate) {
6988 /* TODO */
6989 send_resp(dut, conn, SIGMA_ERROR,
6990 "ErrorCode,MCS32 not supported");
6991 return 0;
6992 } else if (!mcs32 && rate) {
6993 switch (get_driver_type()) {
6994 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006995 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006996 ath_sta_set_11nrates(dut, intf, rate);
6997 break;
6998 default:
6999 send_resp(dut, conn, SIGMA_ERROR,
7000 "ErrorCode,MCS32_FIXEDRATE not supported");
7001 return 0;
7002 }
7003 }
7004
7005 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7006}
7007
7008
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007009static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7010 int mcs_config)
7011{
7012#ifdef NL80211_SUPPORT
7013 int ret;
7014
7015 switch (mcs_config) {
7016 case HE_80_MCS0_7:
7017 case HE_80_MCS0_9:
7018 case HE_80_MCS0_11:
7019 ret = sta_set_he_mcs(dut, intf, mcs_config);
7020 if (ret) {
7021 sigma_dut_print(dut, DUT_MSG_ERROR,
7022 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7023 mcs_config, ret);
7024 }
7025 break;
7026 default:
7027 sigma_dut_print(dut, DUT_MSG_ERROR,
7028 "cmd_set_max_he_mcs: Invalid mcs %d",
7029 mcs_config);
7030 break;
7031 }
7032#else /* NL80211_SUPPORT */
7033 sigma_dut_print(dut, DUT_MSG_ERROR,
7034 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7035#endif /* NL80211_SUPPORT */
7036}
7037
7038
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007039static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
7040 struct sigma_conn *conn,
7041 struct sigma_cmd *cmd)
7042{
7043 const char *intf = get_param(cmd, "Interface");
7044 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07007045 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07007046 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007047 int tkip = -1;
7048 int wep = -1;
7049
Arif Hussaina37e9552018-06-20 17:05:59 -07007050 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007051 val = get_param(cmd, "SGI80");
7052 if (val) {
7053 int sgi80;
7054
7055 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7056 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
7057 if (system(buf) != 0) {
7058 sigma_dut_print(dut, DUT_MSG_ERROR,
7059 "iwpriv shortgi failed");
7060 }
7061 }
7062
7063 val = get_param(cmd, "TxBF");
7064 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007065 switch (get_driver_type()) {
7066 case DRIVER_WCN:
7067 if (sta_set_tx_beamformee(dut, intf, 1)) {
7068 send_resp(dut, conn, SIGMA_ERROR,
7069 "ErrorCode,Failed to set TX beamformee enable");
7070 return 0;
7071 }
7072 break;
7073 case DRIVER_ATHEROS:
7074 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
7075 intf);
7076 if (system(buf) != 0) {
7077 send_resp(dut, conn, SIGMA_ERROR,
7078 "ErrorCode,Setting vhtsubfee failed");
7079 return 0;
7080 }
7081
7082 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
7083 intf);
7084 if (system(buf) != 0) {
7085 send_resp(dut, conn, SIGMA_ERROR,
7086 "ErrorCode,Setting vhtsubfer failed");
7087 return 0;
7088 }
7089 break;
7090 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007091 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007092 "Unsupported driver type");
7093 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007094 }
7095 }
7096
7097 val = get_param(cmd, "MU_TxBF");
7098 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
7099 switch (get_driver_type()) {
7100 case DRIVER_ATHEROS:
7101 ath_sta_set_txsp_stream(dut, intf, "1SS");
7102 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05307103 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
7104 intf);
7105 if (system(buf) != 0) {
7106 sigma_dut_print(dut, DUT_MSG_ERROR,
7107 "iwpriv vhtmubfee failed");
7108 }
7109 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
7110 intf);
7111 if (system(buf) != 0) {
7112 sigma_dut_print(dut, DUT_MSG_ERROR,
7113 "iwpriv vhtmubfer failed");
7114 }
7115 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007116 case DRIVER_WCN:
7117 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
7118 send_resp(dut, conn, SIGMA_ERROR,
7119 "ErrorCode,Failed to set RX/TXSP_STREAM");
7120 return 0;
7121 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05307122 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007123 default:
7124 sigma_dut_print(dut, DUT_MSG_ERROR,
7125 "Setting SP_STREAM not supported");
7126 break;
7127 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007128 }
7129
7130 val = get_param(cmd, "LDPC");
7131 if (val) {
7132 int ldpc;
7133
7134 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7135 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
7136 if (system(buf) != 0) {
7137 sigma_dut_print(dut, DUT_MSG_ERROR,
7138 "iwpriv ldpc failed");
7139 }
7140 }
7141
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08007142 val = get_param(cmd, "BCC");
7143 if (val) {
7144 int bcc;
7145
7146 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7147 /* use LDPC iwpriv itself to set bcc coding, bcc coding
7148 * is mutually exclusive to bcc */
7149 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
7150 if (system(buf) != 0) {
7151 sigma_dut_print(dut, DUT_MSG_ERROR,
7152 "Enabling/Disabling of BCC failed");
7153 }
7154 }
7155
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007156 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
7157 if (val && dut->sta_nss == 1)
7158 cmd_set_max_he_mcs(dut, intf, atoi(val));
7159
7160 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
7161 if (val && dut->sta_nss == 2)
7162 cmd_set_max_he_mcs(dut, intf, atoi(val));
7163
Arif Hussainac6c5112018-05-25 17:34:00 -07007164 val = get_param(cmd, "MCS_FixedRate");
7165 if (val) {
7166#ifdef NL80211_SUPPORT
7167 int mcs, ratecode = 0;
7168 enum he_mcs_config mcs_config;
7169 int ret;
7170
7171 ratecode = (0x07 & dut->sta_nss) << 5;
7172 mcs = atoi(val);
7173 /* Add the MCS to the ratecode */
7174 if (mcs >= 0 && mcs <= 11) {
7175 ratecode += mcs;
7176 if (dut->device_type == STA_testbed &&
7177 mcs > 7 && mcs <= 11) {
7178 if (mcs <= 9)
7179 mcs_config = HE_80_MCS0_9;
7180 else
7181 mcs_config = HE_80_MCS0_11;
7182 ret = sta_set_he_mcs(dut, intf, mcs_config);
7183 if (ret) {
7184 sigma_dut_print(dut, DUT_MSG_ERROR,
7185 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
7186 mcs, mcs_config, ret);
7187 }
7188 }
7189 snprintf(buf, sizeof(buf),
7190 "iwpriv %s set_11ax_rate 0x%03x",
7191 intf, ratecode);
7192 if (system(buf) != 0) {
7193 sigma_dut_print(dut, DUT_MSG_ERROR,
7194 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
7195 ratecode);
7196 }
7197 } else {
7198 sigma_dut_print(dut, DUT_MSG_ERROR,
7199 "MCS_FixedRate: HE MCS %d not supported",
7200 mcs);
7201 }
7202#else /* NL80211_SUPPORT */
7203 sigma_dut_print(dut, DUT_MSG_ERROR,
7204 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
7205#endif /* NL80211_SUPPORT */
7206 }
7207
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007208 val = get_param(cmd, "opt_md_notif_ie");
7209 if (val) {
7210 char *result = NULL;
7211 char delim[] = ";";
7212 char token[30];
7213 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307214 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007215
Peng Xub8fc5cc2017-05-10 17:27:28 -07007216 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307217 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007218
7219 /* Extract the NSS information */
7220 if (result) {
7221 value = atoi(result);
7222 switch (value) {
7223 case 1:
7224 config_val = 1;
7225 break;
7226 case 2:
7227 config_val = 3;
7228 break;
7229 case 3:
7230 config_val = 7;
7231 break;
7232 case 4:
7233 config_val = 15;
7234 break;
7235 default:
7236 config_val = 3;
7237 break;
7238 }
7239
7240 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7241 intf, config_val);
7242 if (system(buf) != 0) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "iwpriv rxchainmask failed");
7245 }
7246
7247 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
7248 intf, config_val);
7249 if (system(buf) != 0) {
7250 sigma_dut_print(dut, DUT_MSG_ERROR,
7251 "iwpriv txchainmask failed");
7252 }
7253 }
7254
7255 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307256 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007257 if (result) {
7258 value = atoi(result);
7259 switch (value) {
7260 case 20:
7261 config_val = 0;
7262 break;
7263 case 40:
7264 config_val = 1;
7265 break;
7266 case 80:
7267 config_val = 2;
7268 break;
7269 case 160:
7270 config_val = 3;
7271 break;
7272 default:
7273 config_val = 2;
7274 break;
7275 }
7276
7277 dut->chwidth = config_val;
7278
7279 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7280 intf, config_val);
7281 if (system(buf) != 0) {
7282 sigma_dut_print(dut, DUT_MSG_ERROR,
7283 "iwpriv chwidth failed");
7284 }
7285 }
7286
7287 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
7288 if (system(buf) != 0) {
7289 sigma_dut_print(dut, DUT_MSG_ERROR,
7290 "iwpriv opmode_notify failed");
7291 }
7292 }
7293
7294 val = get_param(cmd, "nss_mcs_cap");
7295 if (val) {
7296 int nss, mcs;
7297 char token[20];
7298 char *result = NULL;
7299 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307300 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007301
Peng Xub8fc5cc2017-05-10 17:27:28 -07007302 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307303 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307304 if (!result) {
7305 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007306 "NSS not specified");
7307 send_resp(dut, conn, SIGMA_ERROR,
7308 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307309 return 0;
7310 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007311 nss = atoi(result);
7312
7313 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
7314 if (system(buf) != 0) {
7315 sigma_dut_print(dut, DUT_MSG_ERROR,
7316 "iwpriv nss failed");
7317 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007318 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007319
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307320 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007321 if (result == NULL) {
7322 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007323 "MCS not specified");
7324 send_resp(dut, conn, SIGMA_ERROR,
7325 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007326 return 0;
7327 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307328 result = strtok_r(result, "-", &saveptr);
7329 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307330 if (!result) {
7331 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007332 "MCS not specified");
7333 send_resp(dut, conn, SIGMA_ERROR,
7334 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307335 return 0;
7336 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007337 mcs = atoi(result);
7338
Arif Hussaina37e9552018-06-20 17:05:59 -07007339 if (program && strcasecmp(program, "HE") == 0) {
7340#ifdef NL80211_SUPPORT
7341 enum he_mcs_config mcs_config;
7342 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007343
Arif Hussaina37e9552018-06-20 17:05:59 -07007344 if (mcs >= 0 && mcs <= 7) {
7345 mcs_config = HE_80_MCS0_7;
7346 } else if (mcs > 7 && mcs <= 9) {
7347 mcs_config = HE_80_MCS0_9;
7348 } else if (mcs > 9 && mcs <= 11) {
7349 mcs_config = HE_80_MCS0_11;
7350 } else {
7351 sigma_dut_print(dut, DUT_MSG_ERROR,
7352 "nss_mcs_cap: HE: Invalid mcs: %d",
7353 mcs);
7354 send_resp(dut, conn, SIGMA_ERROR,
7355 "errorCode,Invalid MCS");
7356 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007357 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007358
7359 ret = sta_set_he_mcs(dut, intf, mcs_config);
7360 if (ret) {
7361 sigma_dut_print(dut, DUT_MSG_ERROR,
7362 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
7363 mcs_config, ret);
7364 send_resp(dut, conn, SIGMA_ERROR,
7365 "errorCode,Failed to set MCS");
7366 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007367 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007368#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007369 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007370 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
7371#endif /* NL80211_SUPPORT */
7372 } else {
7373 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7374 intf, mcs);
7375 if (system(buf) != 0) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "iwpriv mcs failed");
7378 }
7379
7380 switch (nss) {
7381 case 1:
7382 switch (mcs) {
7383 case 7:
7384 vht_mcsmap = 0xfffc;
7385 break;
7386 case 8:
7387 vht_mcsmap = 0xfffd;
7388 break;
7389 case 9:
7390 vht_mcsmap = 0xfffe;
7391 break;
7392 default:
7393 vht_mcsmap = 0xfffe;
7394 break;
7395 }
7396 break;
7397 case 2:
7398 switch (mcs) {
7399 case 7:
7400 vht_mcsmap = 0xfff0;
7401 break;
7402 case 8:
7403 vht_mcsmap = 0xfff5;
7404 break;
7405 case 9:
7406 vht_mcsmap = 0xfffa;
7407 break;
7408 default:
7409 vht_mcsmap = 0xfffa;
7410 break;
7411 }
7412 break;
7413 case 3:
7414 switch (mcs) {
7415 case 7:
7416 vht_mcsmap = 0xffc0;
7417 break;
7418 case 8:
7419 vht_mcsmap = 0xffd5;
7420 break;
7421 case 9:
7422 vht_mcsmap = 0xffea;
7423 break;
7424 default:
7425 vht_mcsmap = 0xffea;
7426 break;
7427 }
7428 break;
7429 default:
7430 vht_mcsmap = 0xffea;
7431 break;
7432 }
7433 snprintf(buf, sizeof(buf),
7434 "iwpriv %s vht_mcsmap 0x%04x",
7435 intf, vht_mcsmap);
7436 if (system(buf) != 0) {
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "iwpriv vht_mcsmap failed");
7439 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007440 }
7441 }
7442
7443 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
7444
7445 val = get_param(cmd, "Vht_tkip");
7446 if (val)
7447 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7448
7449 val = get_param(cmd, "Vht_wep");
7450 if (val)
7451 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7452
7453 if (tkip != -1 || wep != -1) {
7454 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7455 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7456 intf);
7457 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7458 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7459 intf);
7460 } else {
7461 sigma_dut_print(dut, DUT_MSG_ERROR,
7462 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7463 return 0;
7464 }
7465
7466 if (system(buf) != 0) {
7467 sigma_dut_print(dut, DUT_MSG_ERROR,
7468 "iwpriv htweptkip failed");
7469 }
7470 }
7471
Arif Hussain55f00da2018-07-03 08:28:26 -07007472 val = get_param(cmd, "txBandwidth");
7473 if (val) {
7474 switch (get_driver_type()) {
7475 case DRIVER_WCN:
7476 if (wcn_sta_set_width(dut, intf, val) < 0) {
7477 send_resp(dut, conn, SIGMA_ERROR,
7478 "ErrorCode,Failed to set txBandwidth");
7479 return 0;
7480 }
7481 break;
7482 case DRIVER_ATHEROS:
7483 if (ath_set_width(dut, conn, intf, val) < 0) {
7484 send_resp(dut, conn, SIGMA_ERROR,
7485 "ErrorCode,Failed to set txBandwidth");
7486 return 0;
7487 }
7488 break;
7489 default:
7490 sigma_dut_print(dut, DUT_MSG_ERROR,
7491 "Setting txBandwidth not supported");
7492 break;
7493 }
7494 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007495
Arif Hussain9765f7d2018-07-03 08:28:26 -07007496 val = get_param(cmd, "BeamformeeSTS");
7497 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007498 if (sta_set_tx_beamformee(dut, intf, 1)) {
7499 send_resp(dut, conn, SIGMA_ERROR,
7500 "ErrorCode,Failed to set TX beamformee enable");
7501 return 0;
7502 }
7503
Arif Hussain9765f7d2018-07-03 08:28:26 -07007504 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7505 send_resp(dut, conn, SIGMA_ERROR,
7506 "ErrorCode,Failed to set BeamformeeSTS");
7507 return 0;
7508 }
7509 }
7510
Arif Hussain68d23f52018-07-11 13:39:08 -07007511 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7512 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007513#ifdef NL80211_SUPPORT
7514 enum qca_wlan_he_mac_padding_dur set_val;
7515
7516 switch (atoi(val)) {
7517 case 16:
7518 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7519 break;
7520 case 8:
7521 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7522 break;
7523 default:
7524 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7525 break;
7526 }
7527 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007528 send_resp(dut, conn, SIGMA_ERROR,
7529 "ErrorCode,Failed to set MAC padding duration");
7530 return 0;
7531 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007532#else /* NL80211_SUPPORT */
7533 sigma_dut_print(dut, DUT_MSG_ERROR,
7534 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7535#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007536 }
7537
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007538 val = get_param(cmd, "MU_EDCA");
7539 if (val && (strcasecmp(val, "Override") == 0)) {
7540 if (sta_set_mu_edca_override(dut, intf, 1)) {
7541 send_resp(dut, conn, SIGMA_ERROR,
7542 "ErrorCode,Failed to set MU EDCA override");
7543 return 0;
7544 }
7545 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007546
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007547 val = get_param(cmd, "OMControl");
7548 if (val) {
7549 int set_val = 1;
7550
7551 if (strcasecmp(val, "Enable") == 0)
7552 set_val = 1;
7553 else if (strcasecmp(val, "Disable") == 0)
7554 set_val = 0;
7555
7556 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
7557 send_resp(dut, conn, SIGMA_ERROR,
7558 "ErrorCode,Failed to set OM ctrl supp");
7559 return 0;
7560 }
7561 }
7562
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007563 val = get_param(cmd, "ADDBAResp_BufSize");
7564 if (val) {
7565 int buf_size;
7566
7567 if (strcasecmp(val, "gt64") == 0)
7568 buf_size = 256;
7569 else
7570 buf_size = 64;
7571 if (get_driver_type() == DRIVER_WCN &&
7572 sta_set_addba_buf_size(dut, intf, buf_size)) {
7573 send_resp(dut, conn, SIGMA_ERROR,
7574 "ErrorCode,set addbaresp_buff_size failed");
7575 return 0;
7576 }
7577 }
7578
7579 val = get_param(cmd, "ADDBAReq_BufSize");
7580 if (val) {
7581 int buf_size;
7582
7583 if (strcasecmp(val, "gt64") == 0)
7584 buf_size = 256;
7585 else
7586 buf_size = 64;
7587 if (get_driver_type() == DRIVER_WCN &&
7588 sta_set_addba_buf_size(dut, intf, buf_size)) {
7589 send_resp(dut, conn, SIGMA_ERROR,
7590 "ErrorCode,set addbareq_buff_size failed");
7591 return 0;
7592 }
7593 }
7594
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007595 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7596}
7597
7598
7599static int sta_set_wireless_60g(struct sigma_dut *dut,
7600 struct sigma_conn *conn,
7601 struct sigma_cmd *cmd)
7602{
7603 const char *dev_role = get_param(cmd, "DevRole");
7604
7605 if (!dev_role) {
7606 send_resp(dut, conn, SIGMA_INVALID,
7607 "ErrorCode,DevRole not specified");
7608 return 0;
7609 }
7610
7611 if (strcasecmp(dev_role, "PCP") == 0)
7612 return sta_set_60g_pcp(dut, conn, cmd);
7613 if (strcasecmp(dev_role, "STA") == 0)
7614 return sta_set_60g_sta(dut, conn, cmd);
7615 send_resp(dut, conn, SIGMA_INVALID,
7616 "ErrorCode,DevRole not supported");
7617 return 0;
7618}
7619
7620
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307621static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7622 struct sigma_cmd *cmd)
7623{
7624 int status;
7625 const char *intf = get_param(cmd, "Interface");
7626 const char *val = get_param(cmd, "DevRole");
7627
7628 if (val && strcasecmp(val, "STA-CFON") == 0) {
7629 status = sta_cfon_set_wireless(dut, conn, cmd);
7630 if (status)
7631 return status;
7632 }
7633 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7634}
7635
7636
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007637static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7638 struct sigma_cmd *cmd)
7639{
7640 const char *val;
7641
7642 val = get_param(cmd, "Program");
7643 if (val) {
7644 if (strcasecmp(val, "11n") == 0)
7645 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007646 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007647 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7648 if (strcasecmp(val, "60ghz") == 0)
7649 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307650 if (strcasecmp(val, "OCE") == 0)
7651 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007652 send_resp(dut, conn, SIGMA_ERROR,
7653 "ErrorCode,Program value not supported");
7654 } else {
7655 send_resp(dut, conn, SIGMA_ERROR,
7656 "ErrorCode,Program argument not available");
7657 }
7658
7659 return 0;
7660}
7661
7662
7663static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7664 int tid)
7665{
7666 char buf[100];
7667 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7668
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307669 if (tid < 0 ||
7670 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7671 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7672 return;
7673 }
7674
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007675 /*
7676 * Two ways to ensure that addba request with a
7677 * non zero TID could be sent out. EV 117296
7678 */
7679 snprintf(buf, sizeof(buf),
7680 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7681 tid);
7682 if (system(buf) != 0) {
7683 sigma_dut_print(dut, DUT_MSG_ERROR,
7684 "Ping did not send out");
7685 }
7686
7687 snprintf(buf, sizeof(buf),
7688 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7689 intf, VI_QOS_TMP_FILE);
7690 if (system(buf) != 0)
7691 return;
7692
7693 snprintf(buf, sizeof(buf),
7694 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
7695 intf, VI_QOS_TMP_FILE);
7696 if (system(buf) != 0)
7697 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
7698
7699 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
7700 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
7701 if (system(buf) != 0) {
7702 sigma_dut_print(dut, DUT_MSG_ERROR,
7703 "VI_QOS_TEMP_FILE generation error failed");
7704 }
7705 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7706 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7707 if (system(buf) != 0) {
7708 sigma_dut_print(dut, DUT_MSG_ERROR,
7709 "VI_QOS_FILE generation failed");
7710 }
7711
7712 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7713 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7714 if (system(buf) != 0) {
7715 sigma_dut_print(dut, DUT_MSG_ERROR,
7716 "VI_QOS_FILE generation failed");
7717 }
7718
7719 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
7720 if (system(buf) != 0) {
7721 }
7722}
7723
7724
7725static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7726 struct sigma_cmd *cmd)
7727{
7728 const char *intf = get_param(cmd, "Interface");
7729 const char *val;
7730 int tid = 0;
7731 char buf[100];
7732
7733 val = get_param(cmd, "TID");
7734 if (val) {
7735 tid = atoi(val);
7736 if (tid)
7737 ath_sta_inject_frame(dut, intf, tid);
7738 }
7739
7740 /* Command sequence for ADDBA request on Peregrine based devices */
7741 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
7742 if (system(buf) != 0) {
7743 sigma_dut_print(dut, DUT_MSG_ERROR,
7744 "iwpriv setaddbaoper failed");
7745 }
7746
7747 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
7748 if (system(buf) != 0) {
7749 sigma_dut_print(dut, DUT_MSG_ERROR,
7750 "wifitool senddelba failed");
7751 }
7752
7753 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
7754 if (system(buf) != 0) {
7755 sigma_dut_print(dut, DUT_MSG_ERROR,
7756 "wifitool sendaddba failed");
7757 }
7758
7759 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7760
7761 return 1;
7762}
7763
7764
Lior David9981b512017-01-20 13:16:40 +02007765#ifdef __linux__
7766
7767static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
7768 int agg_size)
7769{
7770 char dir[128], buf[128];
7771 FILE *f;
7772 regex_t re;
7773 regmatch_t m[2];
7774 int rc, ret = -1, vring_id, found;
7775
7776 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
7777 sigma_dut_print(dut, DUT_MSG_ERROR,
7778 "failed to get wil6210 debugfs dir");
7779 return -1;
7780 }
7781
7782 snprintf(buf, sizeof(buf), "%s/vrings", dir);
7783 f = fopen(buf, "r");
7784 if (!f) {
7785 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007786 /* newer wil6210 driver renamed file to "rings" */
7787 snprintf(buf, sizeof(buf), "%s/rings", dir);
7788 f = fopen(buf, "r");
7789 if (!f) {
7790 sigma_dut_print(dut, DUT_MSG_ERROR,
7791 "failed to open: %s", buf);
7792 return -1;
7793 }
Lior David9981b512017-01-20 13:16:40 +02007794 }
7795
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007796 /* can be either VRING tx... or RING... */
7797 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02007798 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
7799 goto out;
7800 }
7801
7802 /* find TX VRING for the mac address */
7803 found = 0;
7804 while (fgets(buf, sizeof(buf), f)) {
7805 if (strcasestr(buf, dest_mac)) {
7806 found = 1;
7807 break;
7808 }
7809 }
7810
7811 if (!found) {
7812 sigma_dut_print(dut, DUT_MSG_ERROR,
7813 "no TX VRING for %s", dest_mac);
7814 goto out;
7815 }
7816
7817 /* extract VRING ID, "VRING tx_<id> = {" */
7818 if (!fgets(buf, sizeof(buf), f)) {
7819 sigma_dut_print(dut, DUT_MSG_ERROR,
7820 "no VRING start line for %s", dest_mac);
7821 goto out;
7822 }
7823
7824 rc = regexec(&re, buf, 2, m, 0);
7825 regfree(&re);
7826 if (rc || m[1].rm_so < 0) {
7827 sigma_dut_print(dut, DUT_MSG_ERROR,
7828 "no VRING TX ID for %s", dest_mac);
7829 goto out;
7830 }
7831 buf[m[1].rm_eo] = 0;
7832 vring_id = atoi(&buf[m[1].rm_so]);
7833
7834 /* send the addba command */
7835 fclose(f);
7836 snprintf(buf, sizeof(buf), "%s/back", dir);
7837 f = fopen(buf, "w");
7838 if (!f) {
7839 sigma_dut_print(dut, DUT_MSG_ERROR,
7840 "failed to open: %s", buf);
7841 return -1;
7842 }
7843
7844 fprintf(f, "add %d %d\n", vring_id, agg_size);
7845
7846 ret = 0;
7847
7848out:
7849 fclose(f);
7850
7851 return ret;
7852}
7853
7854
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02007855int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7856 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007857{
7858 const char *val;
7859 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007860
7861 val = get_param(cmd, "TID");
7862 if (val) {
7863 tid = atoi(val);
7864 if (tid != 0) {
7865 sigma_dut_print(dut, DUT_MSG_ERROR,
7866 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
7867 tid);
7868 }
7869 }
7870
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02007871 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007872 if (!val) {
7873 sigma_dut_print(dut, DUT_MSG_ERROR,
7874 "Currently not supporting addba for 60G without Dest_mac");
7875 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7876 }
7877
Lior David9981b512017-01-20 13:16:40 +02007878 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007879 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007880
7881 return 1;
7882}
7883
Lior David9981b512017-01-20 13:16:40 +02007884#endif /* __linux__ */
7885
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007886
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007887static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7888 struct sigma_cmd *cmd)
7889{
7890#ifdef NL80211_SUPPORT
7891 const char *intf = get_param(cmd, "Interface");
7892 const char *val;
7893 int tid = -1;
7894 int bufsize = 64;
7895 struct nl_msg *msg;
7896 int ret = 0;
7897 struct nlattr *params;
7898 int ifindex;
7899
7900 val = get_param(cmd, "TID");
7901 if (val)
7902 tid = atoi(val);
7903
7904 if (tid == -1) {
7905 send_resp(dut, conn, SIGMA_ERROR,
7906 "ErrorCode,sta_send_addba tid invalid");
7907 return 0;
7908 }
7909
7910 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7911
7912 ifindex = if_nametoindex(intf);
7913 if (ifindex == 0) {
7914 sigma_dut_print(dut, DUT_MSG_ERROR,
7915 "%s: Index for interface %s failed",
7916 __func__, intf);
7917 send_resp(dut, conn, SIGMA_ERROR,
7918 "ErrorCode,sta_send_addba interface invalid");
7919 return 0;
7920 }
7921
7922 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7923 NL80211_CMD_VENDOR)) ||
7924 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7925 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7926 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7927 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7928 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7929 nla_put_u8(msg,
7930 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
7931 QCA_WLAN_ADD_BA) ||
7932 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
7933 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007934 nla_put_u16(msg,
7935 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7936 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007937 sigma_dut_print(dut, DUT_MSG_ERROR,
7938 "%s: err in adding vendor_cmd and vendor_data",
7939 __func__);
7940 nlmsg_free(msg);
7941 send_resp(dut, conn, SIGMA_ERROR,
7942 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
7943 return 0;
7944 }
7945 nla_nest_end(msg, params);
7946
7947 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7948 if (ret) {
7949 sigma_dut_print(dut, DUT_MSG_ERROR,
7950 "%s: err in send_and_recv_msgs, ret=%d",
7951 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05307952 if (ret == -EOPNOTSUPP)
7953 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007954 send_resp(dut, conn, SIGMA_ERROR,
7955 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
7956 return 0;
7957 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007958#else /* NL80211_SUPPORT */
7959 sigma_dut_print(dut, DUT_MSG_ERROR,
7960 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007961#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05307962
7963 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007964}
7965
7966
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007967static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7968 struct sigma_cmd *cmd)
7969{
7970 switch (get_driver_type()) {
7971 case DRIVER_ATHEROS:
7972 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007973 case DRIVER_WCN:
7974 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007975#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007976 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02007977 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02007978#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007979 default:
7980 /*
7981 * There is no driver specific implementation for other drivers.
7982 * Ignore the command and report COMPLETE since the following
7983 * throughput test operation will end up sending ADDBA anyway.
7984 */
7985 return 1;
7986 }
7987}
7988
7989
7990int inject_eth_frame(int s, const void *data, size_t len,
7991 unsigned short ethtype, char *dst, char *src)
7992{
7993 struct iovec iov[4] = {
7994 {
7995 .iov_base = dst,
7996 .iov_len = ETH_ALEN,
7997 },
7998 {
7999 .iov_base = src,
8000 .iov_len = ETH_ALEN,
8001 },
8002 {
8003 .iov_base = &ethtype,
8004 .iov_len = sizeof(unsigned short),
8005 },
8006 {
8007 .iov_base = (void *) data,
8008 .iov_len = len,
8009 }
8010 };
8011 struct msghdr msg = {
8012 .msg_name = NULL,
8013 .msg_namelen = 0,
8014 .msg_iov = iov,
8015 .msg_iovlen = 4,
8016 .msg_control = NULL,
8017 .msg_controllen = 0,
8018 .msg_flags = 0,
8019 };
8020
8021 return sendmsg(s, &msg, 0);
8022}
8023
8024#if defined(__linux__) || defined(__QNXNTO__)
8025
8026int inject_frame(int s, const void *data, size_t len, int encrypt)
8027{
8028#define IEEE80211_RADIOTAP_F_WEP 0x04
8029#define IEEE80211_RADIOTAP_F_FRAG 0x08
8030 unsigned char rtap_hdr[] = {
8031 0x00, 0x00, /* radiotap version */
8032 0x0e, 0x00, /* radiotap length */
8033 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8034 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8035 0x00, /* padding */
8036 0x00, 0x00, /* RX and TX flags to indicate that */
8037 0x00, 0x00, /* this is the injected frame directly */
8038 };
8039 struct iovec iov[2] = {
8040 {
8041 .iov_base = &rtap_hdr,
8042 .iov_len = sizeof(rtap_hdr),
8043 },
8044 {
8045 .iov_base = (void *) data,
8046 .iov_len = len,
8047 }
8048 };
8049 struct msghdr msg = {
8050 .msg_name = NULL,
8051 .msg_namelen = 0,
8052 .msg_iov = iov,
8053 .msg_iovlen = 2,
8054 .msg_control = NULL,
8055 .msg_controllen = 0,
8056 .msg_flags = 0,
8057 };
8058
8059 if (encrypt)
8060 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
8061
8062 return sendmsg(s, &msg, 0);
8063}
8064
8065
8066int open_monitor(const char *ifname)
8067{
8068#ifdef __QNXNTO__
8069 struct sockaddr_dl ll;
8070 int s;
8071
8072 memset(&ll, 0, sizeof(ll));
8073 ll.sdl_family = AF_LINK;
8074 ll.sdl_index = if_nametoindex(ifname);
8075 if (ll.sdl_index == 0) {
8076 perror("if_nametoindex");
8077 return -1;
8078 }
8079 s = socket(PF_INET, SOCK_RAW, 0);
8080#else /* __QNXNTO__ */
8081 struct sockaddr_ll ll;
8082 int s;
8083
8084 memset(&ll, 0, sizeof(ll));
8085 ll.sll_family = AF_PACKET;
8086 ll.sll_ifindex = if_nametoindex(ifname);
8087 if (ll.sll_ifindex == 0) {
8088 perror("if_nametoindex");
8089 return -1;
8090 }
8091 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
8092#endif /* __QNXNTO__ */
8093 if (s < 0) {
8094 perror("socket[PF_PACKET,SOCK_RAW]");
8095 return -1;
8096 }
8097
8098 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
8099 perror("monitor socket bind");
8100 close(s);
8101 return -1;
8102 }
8103
8104 return s;
8105}
8106
8107
8108static int hex2num(char c)
8109{
8110 if (c >= '0' && c <= '9')
8111 return c - '0';
8112 if (c >= 'a' && c <= 'f')
8113 return c - 'a' + 10;
8114 if (c >= 'A' && c <= 'F')
8115 return c - 'A' + 10;
8116 return -1;
8117}
8118
8119
8120int hwaddr_aton(const char *txt, unsigned char *addr)
8121{
8122 int i;
8123
8124 for (i = 0; i < 6; i++) {
8125 int a, b;
8126
8127 a = hex2num(*txt++);
8128 if (a < 0)
8129 return -1;
8130 b = hex2num(*txt++);
8131 if (b < 0)
8132 return -1;
8133 *addr++ = (a << 4) | b;
8134 if (i < 5 && *txt++ != ':')
8135 return -1;
8136 }
8137
8138 return 0;
8139}
8140
8141#endif /* defined(__linux__) || defined(__QNXNTO__) */
8142
8143enum send_frame_type {
8144 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
8145};
8146enum send_frame_protection {
8147 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8148};
8149
8150
8151static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8152 enum send_frame_type frame,
8153 enum send_frame_protection protected,
8154 const char *dest)
8155{
8156#ifdef __linux__
8157 unsigned char buf[1000], *pos;
8158 int s, res;
8159 char bssid[20], addr[20];
8160 char result[32], ssid[100];
8161 size_t ssid_len;
8162
8163 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
8164 sizeof(result)) < 0 ||
8165 strncmp(result, "COMPLETED", 9) != 0) {
8166 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
8167 return 0;
8168 }
8169
8170 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
8171 < 0) {
8172 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8173 "current BSSID");
8174 return 0;
8175 }
8176
8177 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
8178 < 0) {
8179 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8180 "own MAC address");
8181 return 0;
8182 }
8183
8184 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
8185 < 0) {
8186 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8187 "current SSID");
8188 return 0;
8189 }
8190 ssid_len = strlen(ssid);
8191
8192 pos = buf;
8193
8194 /* Frame Control */
8195 switch (frame) {
8196 case DISASSOC:
8197 *pos++ = 0xa0;
8198 break;
8199 case DEAUTH:
8200 *pos++ = 0xc0;
8201 break;
8202 case SAQUERY:
8203 *pos++ = 0xd0;
8204 break;
8205 case AUTH:
8206 *pos++ = 0xb0;
8207 break;
8208 case ASSOCREQ:
8209 *pos++ = 0x00;
8210 break;
8211 case REASSOCREQ:
8212 *pos++ = 0x20;
8213 break;
8214 case DLS_REQ:
8215 *pos++ = 0xd0;
8216 break;
8217 }
8218
8219 if (protected == INCORRECT_KEY)
8220 *pos++ = 0x40; /* Set Protected field to 1 */
8221 else
8222 *pos++ = 0x00;
8223
8224 /* Duration */
8225 *pos++ = 0x00;
8226 *pos++ = 0x00;
8227
8228 /* addr1 = DA (current AP) */
8229 hwaddr_aton(bssid, pos);
8230 pos += 6;
8231 /* addr2 = SA (own address) */
8232 hwaddr_aton(addr, pos);
8233 pos += 6;
8234 /* addr3 = BSSID (current AP) */
8235 hwaddr_aton(bssid, pos);
8236 pos += 6;
8237
8238 /* Seq# (to be filled by driver/mac80211) */
8239 *pos++ = 0x00;
8240 *pos++ = 0x00;
8241
8242 if (protected == INCORRECT_KEY) {
8243 /* CCMP parameters */
8244 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8245 pos += 8;
8246 }
8247
8248 if (protected == INCORRECT_KEY) {
8249 switch (frame) {
8250 case DEAUTH:
8251 /* Reason code (encrypted) */
8252 memcpy(pos, "\xa7\x39", 2);
8253 pos += 2;
8254 break;
8255 case DISASSOC:
8256 /* Reason code (encrypted) */
8257 memcpy(pos, "\xa7\x39", 2);
8258 pos += 2;
8259 break;
8260 case SAQUERY:
8261 /* Category|Action|TransID (encrypted) */
8262 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8263 pos += 4;
8264 break;
8265 default:
8266 return -1;
8267 }
8268
8269 /* CCMP MIC */
8270 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8271 pos += 8;
8272 } else {
8273 switch (frame) {
8274 case DEAUTH:
8275 /* reason code = 8 */
8276 *pos++ = 0x08;
8277 *pos++ = 0x00;
8278 break;
8279 case DISASSOC:
8280 /* reason code = 8 */
8281 *pos++ = 0x08;
8282 *pos++ = 0x00;
8283 break;
8284 case SAQUERY:
8285 /* Category - SA Query */
8286 *pos++ = 0x08;
8287 /* SA query Action - Request */
8288 *pos++ = 0x00;
8289 /* Transaction ID */
8290 *pos++ = 0x12;
8291 *pos++ = 0x34;
8292 break;
8293 case AUTH:
8294 /* Auth Alg (Open) */
8295 *pos++ = 0x00;
8296 *pos++ = 0x00;
8297 /* Seq# */
8298 *pos++ = 0x01;
8299 *pos++ = 0x00;
8300 /* Status code */
8301 *pos++ = 0x00;
8302 *pos++ = 0x00;
8303 break;
8304 case ASSOCREQ:
8305 /* Capability Information */
8306 *pos++ = 0x31;
8307 *pos++ = 0x04;
8308 /* Listen Interval */
8309 *pos++ = 0x0a;
8310 *pos++ = 0x00;
8311 /* SSID */
8312 *pos++ = 0x00;
8313 *pos++ = ssid_len;
8314 memcpy(pos, ssid, ssid_len);
8315 pos += ssid_len;
8316 /* Supported Rates */
8317 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8318 10);
8319 pos += 10;
8320 /* Extended Supported Rates */
8321 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8322 pos += 6;
8323 /* RSN */
8324 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8325 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8326 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8327 pos += 28;
8328 break;
8329 case REASSOCREQ:
8330 /* Capability Information */
8331 *pos++ = 0x31;
8332 *pos++ = 0x04;
8333 /* Listen Interval */
8334 *pos++ = 0x0a;
8335 *pos++ = 0x00;
8336 /* Current AP */
8337 hwaddr_aton(bssid, pos);
8338 pos += 6;
8339 /* SSID */
8340 *pos++ = 0x00;
8341 *pos++ = ssid_len;
8342 memcpy(pos, ssid, ssid_len);
8343 pos += ssid_len;
8344 /* Supported Rates */
8345 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8346 10);
8347 pos += 10;
8348 /* Extended Supported Rates */
8349 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8350 pos += 6;
8351 /* RSN */
8352 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8353 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8354 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8355 pos += 28;
8356 break;
8357 case DLS_REQ:
8358 /* Category - DLS */
8359 *pos++ = 0x02;
8360 /* DLS Action - Request */
8361 *pos++ = 0x00;
8362 /* Destination MACAddress */
8363 if (dest)
8364 hwaddr_aton(dest, pos);
8365 else
8366 memset(pos, 0, 6);
8367 pos += 6;
8368 /* Source MACAddress */
8369 hwaddr_aton(addr, pos);
8370 pos += 6;
8371 /* Capability Information */
8372 *pos++ = 0x10; /* Privacy */
8373 *pos++ = 0x06; /* QoS */
8374 /* DLS Timeout Value */
8375 *pos++ = 0x00;
8376 *pos++ = 0x01;
8377 /* Supported rates */
8378 *pos++ = 0x01;
8379 *pos++ = 0x08;
8380 *pos++ = 0x0c; /* 6 Mbps */
8381 *pos++ = 0x12; /* 9 Mbps */
8382 *pos++ = 0x18; /* 12 Mbps */
8383 *pos++ = 0x24; /* 18 Mbps */
8384 *pos++ = 0x30; /* 24 Mbps */
8385 *pos++ = 0x48; /* 36 Mbps */
8386 *pos++ = 0x60; /* 48 Mbps */
8387 *pos++ = 0x6c; /* 54 Mbps */
8388 /* TODO: Extended Supported Rates */
8389 /* TODO: HT Capabilities */
8390 break;
8391 }
8392 }
8393
8394 s = open_monitor("sigmadut");
8395 if (s < 0) {
8396 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8397 "monitor socket");
8398 return 0;
8399 }
8400
8401 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8402 if (res < 0) {
8403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8404 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308405 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008406 return 0;
8407 }
8408 if (res < pos - buf) {
8409 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8410 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308411 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008412 return 0;
8413 }
8414
8415 close(s);
8416
8417 return 1;
8418#else /* __linux__ */
8419 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8420 "yet supported");
8421 return 0;
8422#endif /* __linux__ */
8423}
8424
8425
8426static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8427 struct sigma_conn *conn,
8428 struct sigma_cmd *cmd)
8429{
8430 const char *intf = get_param(cmd, "Interface");
8431 const char *sta, *val;
8432 unsigned char addr[ETH_ALEN];
8433 char buf[100];
8434
8435 sta = get_param(cmd, "peer");
8436 if (sta == NULL)
8437 sta = get_param(cmd, "station");
8438 if (sta == NULL) {
8439 send_resp(dut, conn, SIGMA_ERROR,
8440 "ErrorCode,Missing peer address");
8441 return 0;
8442 }
8443 if (hwaddr_aton(sta, addr) < 0) {
8444 send_resp(dut, conn, SIGMA_ERROR,
8445 "ErrorCode,Invalid peer address");
8446 return 0;
8447 }
8448
8449 val = get_param(cmd, "type");
8450 if (val == NULL)
8451 return -1;
8452
8453 if (strcasecmp(val, "DISCOVERY") == 0) {
8454 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8455 if (wpa_command(intf, buf) < 0) {
8456 send_resp(dut, conn, SIGMA_ERROR,
8457 "ErrorCode,Failed to send TDLS discovery");
8458 return 0;
8459 }
8460 return 1;
8461 }
8462
8463 if (strcasecmp(val, "SETUP") == 0) {
8464 int status = 0, timeout = 0;
8465
8466 val = get_param(cmd, "Status");
8467 if (val)
8468 status = atoi(val);
8469
8470 val = get_param(cmd, "Timeout");
8471 if (val)
8472 timeout = atoi(val);
8473
8474 if (status != 0 && status != 37) {
8475 send_resp(dut, conn, SIGMA_ERROR,
8476 "ErrorCode,Unsupported status value");
8477 return 0;
8478 }
8479
8480 if (timeout != 0 && timeout != 301) {
8481 send_resp(dut, conn, SIGMA_ERROR,
8482 "ErrorCode,Unsupported timeout value");
8483 return 0;
8484 }
8485
8486 if (status && timeout) {
8487 send_resp(dut, conn, SIGMA_ERROR,
8488 "ErrorCode,Unsupported timeout+status "
8489 "combination");
8490 return 0;
8491 }
8492
8493 if (status == 37 &&
8494 wpa_command(intf, "SET tdls_testing 0x200")) {
8495 send_resp(dut, conn, SIGMA_ERROR,
8496 "ErrorCode,Failed to enable "
8497 "decline setup response test mode");
8498 return 0;
8499 }
8500
8501 if (timeout == 301) {
8502 int res;
8503 if (dut->no_tpk_expiration)
8504 res = wpa_command(intf,
8505 "SET tdls_testing 0x108");
8506 else
8507 res = wpa_command(intf,
8508 "SET tdls_testing 0x8");
8509 if (res) {
8510 send_resp(dut, conn, SIGMA_ERROR,
8511 "ErrorCode,Failed to set short TPK "
8512 "lifetime");
8513 return 0;
8514 }
8515 }
8516
8517 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8518 if (wpa_command(intf, buf) < 0) {
8519 send_resp(dut, conn, SIGMA_ERROR,
8520 "ErrorCode,Failed to send TDLS setup");
8521 return 0;
8522 }
8523 return 1;
8524 }
8525
8526 if (strcasecmp(val, "TEARDOWN") == 0) {
8527 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8528 if (wpa_command(intf, buf) < 0) {
8529 send_resp(dut, conn, SIGMA_ERROR,
8530 "ErrorCode,Failed to send TDLS teardown");
8531 return 0;
8532 }
8533 return 1;
8534 }
8535
8536 send_resp(dut, conn, SIGMA_ERROR,
8537 "ErrorCode,Unsupported TDLS frame");
8538 return 0;
8539}
8540
8541
8542static int sta_ap_known(const char *ifname, const char *bssid)
8543{
8544 char buf[4096];
8545
Jouni Malinendd32f192018-09-15 02:55:19 +03008546 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008547 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8548 return 0;
8549 if (strncmp(buf, "id=", 3) != 0)
8550 return 0;
8551 return 1;
8552}
8553
8554
8555static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8556 const char *bssid)
8557{
8558 int res;
8559 struct wpa_ctrl *ctrl;
8560 char buf[256];
8561
8562 if (sta_ap_known(ifname, bssid))
8563 return 0;
8564 sigma_dut_print(dut, DUT_MSG_DEBUG,
8565 "AP not in BSS table - start scan");
8566
8567 ctrl = open_wpa_mon(ifname);
8568 if (ctrl == NULL) {
8569 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8570 "wpa_supplicant monitor connection");
8571 return -1;
8572 }
8573
8574 if (wpa_command(ifname, "SCAN") < 0) {
8575 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8576 wpa_ctrl_detach(ctrl);
8577 wpa_ctrl_close(ctrl);
8578 return -1;
8579 }
8580
8581 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8582 buf, sizeof(buf));
8583
8584 wpa_ctrl_detach(ctrl);
8585 wpa_ctrl_close(ctrl);
8586
8587 if (res < 0) {
8588 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8589 return -1;
8590 }
8591
8592 if (sta_ap_known(ifname, bssid))
8593 return 0;
8594 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8595 return -1;
8596}
8597
8598
8599static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8600 struct sigma_conn *conn,
8601 struct sigma_cmd *cmd,
8602 const char *intf)
8603{
8604 char buf[200];
8605
8606 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8607 if (system(buf) != 0) {
8608 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8609 "ndsend");
8610 return 0;
8611 }
8612
8613 return 1;
8614}
8615
8616
8617static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8618 struct sigma_conn *conn,
8619 struct sigma_cmd *cmd,
8620 const char *intf)
8621{
8622 char buf[200];
8623 const char *ip = get_param(cmd, "SenderIP");
8624
Peng Xu26b356d2017-10-04 17:58:16 -07008625 if (!ip)
8626 return 0;
8627
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008628 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8629 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8630 if (system(buf) == 0) {
8631 sigma_dut_print(dut, DUT_MSG_INFO,
8632 "Neighbor Solicitation got a response "
8633 "for %s@%s", ip, intf);
8634 }
8635
8636 return 1;
8637}
8638
8639
8640static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8641 struct sigma_conn *conn,
8642 struct sigma_cmd *cmd,
8643 const char *ifname)
8644{
8645 char buf[200];
8646 const char *ip = get_param(cmd, "SenderIP");
8647
8648 if (ip == NULL) {
8649 send_resp(dut, conn, SIGMA_ERROR,
8650 "ErrorCode,Missing SenderIP parameter");
8651 return 0;
8652 }
8653 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8654 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8655 if (system(buf) != 0) {
8656 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8657 "for %s@%s", ip, ifname);
8658 }
8659
8660 return 1;
8661}
8662
8663
8664static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8665 struct sigma_conn *conn,
8666 struct sigma_cmd *cmd,
8667 const char *ifname)
8668{
8669 char buf[200];
8670 char ip[16];
8671 int s;
Peng Xub3756882017-10-04 14:39:09 -07008672 struct ifreq ifr;
8673 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008674
8675 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008676 if (s < 0) {
8677 perror("socket");
8678 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679 }
8680
Peng Xub3756882017-10-04 14:39:09 -07008681 memset(&ifr, 0, sizeof(ifr));
8682 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8683 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8684 sigma_dut_print(dut, DUT_MSG_INFO,
8685 "Failed to get %s IP address: %s",
8686 ifname, strerror(errno));
8687 close(s);
8688 return -1;
8689 }
8690 close(s);
8691
8692 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
8693 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
8694
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008695 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
8696 ip);
8697 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8698 if (system(buf) != 0) {
8699 }
8700
8701 return 1;
8702}
8703
8704
8705static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
8706 struct sigma_conn *conn,
8707 struct sigma_cmd *cmd,
8708 const char *ifname)
8709{
8710 char buf[200], addr[20];
8711 char dst[ETH_ALEN], src[ETH_ALEN];
8712 short ethtype = htons(ETH_P_ARP);
8713 char *pos;
8714 int s, res;
8715 const char *val;
8716 struct sockaddr_in taddr;
8717
8718 val = get_param(cmd, "dest");
8719 if (val)
8720 hwaddr_aton(val, (unsigned char *) dst);
8721
8722 val = get_param(cmd, "DestIP");
8723 if (val)
8724 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07008725 else
8726 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008727
8728 if (get_wpa_status(get_station_ifname(), "address", addr,
8729 sizeof(addr)) < 0)
8730 return -2;
8731 hwaddr_aton(addr, (unsigned char *) src);
8732
8733 pos = buf;
8734 *pos++ = 0x00;
8735 *pos++ = 0x01;
8736 *pos++ = 0x08;
8737 *pos++ = 0x00;
8738 *pos++ = 0x06;
8739 *pos++ = 0x04;
8740 *pos++ = 0x00;
8741 *pos++ = 0x02;
8742 memcpy(pos, src, ETH_ALEN);
8743 pos += ETH_ALEN;
8744 memcpy(pos, &taddr.sin_addr, 4);
8745 pos += 4;
8746 memcpy(pos, dst, ETH_ALEN);
8747 pos += ETH_ALEN;
8748 memcpy(pos, &taddr.sin_addr, 4);
8749 pos += 4;
8750
8751 s = open_monitor(get_station_ifname());
8752 if (s < 0) {
8753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8754 "monitor socket");
8755 return 0;
8756 }
8757
8758 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
8759 if (res < 0) {
8760 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8761 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308762 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008763 return 0;
8764 }
8765
8766 close(s);
8767
8768 return 1;
8769}
8770
8771
8772static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
8773 struct sigma_conn *conn,
8774 struct sigma_cmd *cmd,
8775 const char *intf, const char *dest)
8776{
8777 char buf[100];
8778
8779 if (if_nametoindex("sigmadut") == 0) {
8780 snprintf(buf, sizeof(buf),
8781 "iw dev %s interface add sigmadut type monitor",
8782 get_station_ifname());
8783 if (system(buf) != 0 ||
8784 if_nametoindex("sigmadut") == 0) {
8785 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8786 "monitor interface with '%s'", buf);
8787 return -2;
8788 }
8789 }
8790
8791 if (system("ifconfig sigmadut up") != 0) {
8792 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8793 "monitor interface up");
8794 return -2;
8795 }
8796
8797 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
8798}
8799
8800
8801static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
8802 struct sigma_conn *conn,
8803 struct sigma_cmd *cmd)
8804{
8805 const char *intf = get_param(cmd, "Interface");
8806 const char *dest = get_param(cmd, "Dest");
8807 const char *type = get_param(cmd, "FrameName");
8808 const char *val;
8809 char buf[200], *pos, *end;
8810 int count, count2;
8811
8812 if (type == NULL)
8813 type = get_param(cmd, "Type");
8814
8815 if (intf == NULL || dest == NULL || type == NULL)
8816 return -1;
8817
8818 if (strcasecmp(type, "NeighAdv") == 0)
8819 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
8820
8821 if (strcasecmp(type, "NeighSolicitReq") == 0)
8822 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
8823
8824 if (strcasecmp(type, "ARPProbe") == 0)
8825 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
8826
8827 if (strcasecmp(type, "ARPAnnounce") == 0)
8828 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
8829
8830 if (strcasecmp(type, "ARPReply") == 0)
8831 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
8832
8833 if (strcasecmp(type, "DLS-request") == 0 ||
8834 strcasecmp(type, "DLSrequest") == 0)
8835 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
8836 dest);
8837
8838 if (strcasecmp(type, "ANQPQuery") != 0 &&
8839 strcasecmp(type, "Query") != 0) {
8840 send_resp(dut, conn, SIGMA_ERROR,
8841 "ErrorCode,Unsupported HS 2.0 send frame type");
8842 return 0;
8843 }
8844
8845 if (sta_scan_ap(dut, intf, dest) < 0) {
8846 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
8847 "the requested AP");
8848 return 0;
8849 }
8850
8851 pos = buf;
8852 end = buf + sizeof(buf);
8853 count = 0;
8854 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
8855
8856 val = get_param(cmd, "ANQP_CAP_LIST");
8857 if (val && atoi(val)) {
8858 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
8859 count++;
8860 }
8861
8862 val = get_param(cmd, "VENUE_NAME");
8863 if (val && atoi(val)) {
8864 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
8865 count++;
8866 }
8867
8868 val = get_param(cmd, "NETWORK_AUTH_TYPE");
8869 if (val && atoi(val)) {
8870 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
8871 count++;
8872 }
8873
8874 val = get_param(cmd, "ROAMING_CONS");
8875 if (val && atoi(val)) {
8876 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
8877 count++;
8878 }
8879
8880 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
8881 if (val && atoi(val)) {
8882 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
8883 count++;
8884 }
8885
8886 val = get_param(cmd, "NAI_REALM_LIST");
8887 if (val && atoi(val)) {
8888 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
8889 count++;
8890 }
8891
8892 val = get_param(cmd, "3GPP_INFO");
8893 if (val && atoi(val)) {
8894 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
8895 count++;
8896 }
8897
8898 val = get_param(cmd, "DOMAIN_LIST");
8899 if (val && atoi(val)) {
8900 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
8901 count++;
8902 }
8903
Jouni Malinen34cf9532018-04-29 19:26:33 +03008904 val = get_param(cmd, "Venue_URL");
8905 if (val && atoi(val)) {
8906 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
8907 count++;
8908 }
8909
Jouni Malinend3bca5d2018-04-29 17:25:23 +03008910 val = get_param(cmd, "Advice_Of_Charge");
8911 if (val && atoi(val)) {
8912 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
8913 count++;
8914 }
8915
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008916 if (count && wpa_command(intf, buf)) {
8917 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
8918 return 0;
8919 }
8920
8921 pos = buf;
8922 end = buf + sizeof(buf);
8923 count2 = 0;
8924 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
8925
8926 val = get_param(cmd, "HS_CAP_LIST");
8927 if (val && atoi(val)) {
8928 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
8929 count2++;
8930 }
8931
8932 val = get_param(cmd, "OPER_NAME");
8933 if (val && atoi(val)) {
8934 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
8935 count2++;
8936 }
8937
8938 val = get_param(cmd, "WAN_METRICS");
8939 if (!val)
8940 val = get_param(cmd, "WAN_MAT");
8941 if (!val)
8942 val = get_param(cmd, "WAN_MET");
8943 if (val && atoi(val)) {
8944 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
8945 count2++;
8946 }
8947
8948 val = get_param(cmd, "CONNECTION_CAPABILITY");
8949 if (val && atoi(val)) {
8950 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
8951 count2++;
8952 }
8953
8954 val = get_param(cmd, "OP_CLASS");
8955 if (val && atoi(val)) {
8956 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
8957 count2++;
8958 }
8959
8960 val = get_param(cmd, "OSU_PROVIDER_LIST");
8961 if (val && atoi(val)) {
8962 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
8963 count2++;
8964 }
8965
Jouni Malinenf67afec2018-04-29 19:24:58 +03008966 val = get_param(cmd, "OPER_ICON_METADATA");
8967 if (!val)
8968 val = get_param(cmd, "OPERATOR_ICON_METADATA");
8969 if (val && atoi(val)) {
8970 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
8971 count2++;
8972 }
8973
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008974 if (count && count2) {
8975 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
8976 "second query");
8977 sleep(1);
8978 }
8979
8980 if (count2 && wpa_command(intf, buf)) {
8981 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
8982 "failed");
8983 return 0;
8984 }
8985
8986 val = get_param(cmd, "NAI_HOME_REALM_LIST");
8987 if (val) {
8988 if (count || count2) {
8989 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8990 "sending out second query");
8991 sleep(1);
8992 }
8993
8994 if (strcmp(val, "1") == 0)
8995 val = "mail.example.com";
8996 snprintf(buf, end - pos,
8997 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
8998 dest, val);
8999 if (wpa_command(intf, buf)) {
9000 send_resp(dut, conn, SIGMA_ERROR,
9001 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
9002 "failed");
9003 return 0;
9004 }
9005 }
9006
9007 val = get_param(cmd, "ICON_REQUEST");
9008 if (val) {
9009 if (count || count2) {
9010 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9011 "sending out second query");
9012 sleep(1);
9013 }
9014
9015 snprintf(buf, end - pos,
9016 "HS20_ICON_REQUEST %s %s", dest, val);
9017 if (wpa_command(intf, buf)) {
9018 send_resp(dut, conn, SIGMA_ERROR,
9019 "ErrorCode,HS20_ICON_REQUEST failed");
9020 return 0;
9021 }
9022 }
9023
9024 return 1;
9025}
9026
9027
9028static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9029 struct sigma_conn *conn,
9030 struct sigma_cmd *cmd)
9031{
9032 const char *val;
9033 char *ifname;
9034 char buf[100];
9035 int chwidth, nss;
9036
9037 val = get_param(cmd, "framename");
9038 if (!val)
9039 return -1;
9040 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9041
9042 /* Command sequence to generate Op mode notification */
9043 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9044 ifname = get_station_ifname();
9045
9046 /* Disable STBC */
9047 snprintf(buf, sizeof(buf),
9048 "iwpriv %s tx_stbc 0", ifname);
9049 if (system(buf) != 0) {
9050 sigma_dut_print(dut, DUT_MSG_ERROR,
9051 "iwpriv tx_stbc 0 failed!");
9052 }
9053
9054 /* Extract Channel width */
9055 val = get_param(cmd, "Channel_width");
9056 if (val) {
9057 switch (atoi(val)) {
9058 case 20:
9059 chwidth = 0;
9060 break;
9061 case 40:
9062 chwidth = 1;
9063 break;
9064 case 80:
9065 chwidth = 2;
9066 break;
9067 case 160:
9068 chwidth = 3;
9069 break;
9070 default:
9071 chwidth = 2;
9072 break;
9073 }
9074
9075 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9076 ifname, chwidth);
9077 if (system(buf) != 0) {
9078 sigma_dut_print(dut, DUT_MSG_ERROR,
9079 "iwpriv chwidth failed!");
9080 }
9081 }
9082
9083 /* Extract NSS */
9084 val = get_param(cmd, "NSS");
9085 if (val) {
9086 switch (atoi(val)) {
9087 case 1:
9088 nss = 1;
9089 break;
9090 case 2:
9091 nss = 3;
9092 break;
9093 case 3:
9094 nss = 7;
9095 break;
9096 default:
9097 /* We do not support NSS > 3 */
9098 nss = 3;
9099 break;
9100 }
9101 snprintf(buf, sizeof(buf),
9102 "iwpriv %s rxchainmask %d", ifname, nss);
9103 if (system(buf) != 0) {
9104 sigma_dut_print(dut, DUT_MSG_ERROR,
9105 "iwpriv rxchainmask failed!");
9106 }
9107 }
9108
9109 /* Opmode notify */
9110 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
9111 if (system(buf) != 0) {
9112 sigma_dut_print(dut, DUT_MSG_ERROR,
9113 "iwpriv opmode_notify failed!");
9114 } else {
9115 sigma_dut_print(dut, DUT_MSG_INFO,
9116 "Sent out the notify frame!");
9117 }
9118 }
9119
9120 return 1;
9121}
9122
9123
9124static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
9125 struct sigma_conn *conn,
9126 struct sigma_cmd *cmd)
9127{
9128 switch (get_driver_type()) {
9129 case DRIVER_ATHEROS:
9130 return ath_sta_send_frame_vht(dut, conn, cmd);
9131 default:
9132 send_resp(dut, conn, SIGMA_ERROR,
9133 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
9134 return 0;
9135 }
9136}
9137
9138
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009139static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
9140 struct sigma_cmd *cmd)
9141{
9142 const char *val;
9143 const char *intf = get_param(cmd, "Interface");
9144
9145 val = get_param(cmd, "framename");
9146 if (!val)
9147 return -1;
9148 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9149
9150 /* Command sequence to generate Op mode notification */
9151 if (val && strcasecmp(val, "action") == 0) {
9152 val = get_param(cmd, "PPDUTxType");
9153 if (val && strcasecmp(val, "TB") == 0) {
9154 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
9155 sigma_dut_print(dut, DUT_MSG_ERROR,
9156 "failed to send TB PPDU Tx cfg");
9157 send_resp(dut, conn, SIGMA_ERROR,
9158 "ErrorCode,set TB PPDU Tx cfg failed");
9159 return 0;
9160 }
9161 return 1;
9162 }
9163
9164 sigma_dut_print(dut, DUT_MSG_ERROR,
9165 "Action Tx type is not defined");
9166 }
9167
9168 return 1;
9169}
9170
9171
9172static int cmd_sta_send_frame_he(struct sigma_dut *dut,
9173 struct sigma_conn *conn,
9174 struct sigma_cmd *cmd)
9175{
9176 switch (get_driver_type()) {
9177 case DRIVER_WCN:
9178 return wcn_sta_send_frame_he(dut, conn, cmd);
9179 default:
9180 send_resp(dut, conn, SIGMA_ERROR,
9181 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
9182 return 0;
9183 }
9184}
9185
9186
Lior David0fe101e2017-03-09 16:09:50 +02009187#ifdef __linux__
9188int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9189 struct sigma_cmd *cmd)
9190{
9191 const char *frame_name = get_param(cmd, "framename");
9192 const char *mac = get_param(cmd, "dest_mac");
9193
9194 if (!frame_name || !mac) {
9195 sigma_dut_print(dut, DUT_MSG_ERROR,
9196 "framename and dest_mac must be provided");
9197 return -1;
9198 }
9199
9200 if (strcasecmp(frame_name, "brp") == 0) {
9201 const char *l_rx = get_param(cmd, "L-RX");
9202 int l_rx_i;
9203
9204 if (!l_rx) {
9205 sigma_dut_print(dut, DUT_MSG_ERROR,
9206 "L-RX must be provided");
9207 return -1;
9208 }
9209 l_rx_i = atoi(l_rx);
9210
9211 sigma_dut_print(dut, DUT_MSG_INFO,
9212 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
9213 mac, l_rx);
9214 if (l_rx_i != 16) {
9215 sigma_dut_print(dut, DUT_MSG_ERROR,
9216 "unsupported L-RX: %s", l_rx);
9217 return -1;
9218 }
9219
9220 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
9221 return -1;
9222 } else if (strcasecmp(frame_name, "ssw") == 0) {
9223 sigma_dut_print(dut, DUT_MSG_INFO,
9224 "dev_send_frame: SLS, dest_mac %s", mac);
9225 if (wil6210_send_sls(dut, mac))
9226 return -1;
9227 } else {
9228 sigma_dut_print(dut, DUT_MSG_ERROR,
9229 "unsupported frame type: %s", frame_name);
9230 return -1;
9231 }
9232
9233 return 1;
9234}
9235#endif /* __linux__ */
9236
9237
9238static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
9239 struct sigma_conn *conn,
9240 struct sigma_cmd *cmd)
9241{
9242 switch (get_driver_type()) {
9243#ifdef __linux__
9244 case DRIVER_WIL6210:
9245 return wil6210_send_frame_60g(dut, conn, cmd);
9246#endif /* __linux__ */
9247 default:
9248 send_resp(dut, conn, SIGMA_ERROR,
9249 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9250 return 0;
9251 }
9252}
9253
9254
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309255static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9256 const char *intf, struct sigma_cmd *cmd)
9257{
9258 const char *val, *addr;
9259 char buf[100];
9260
9261 addr = get_param(cmd, "DestMac");
9262 if (!addr) {
9263 send_resp(dut, conn, SIGMA_INVALID,
9264 "ErrorCode,AP MAC address is missing");
9265 return 0;
9266 }
9267
9268 val = get_param(cmd, "ANQPQuery_ID");
9269 if (!val) {
9270 send_resp(dut, conn, SIGMA_INVALID,
9271 "ErrorCode,Missing ANQPQuery_ID");
9272 return 0;
9273 }
9274
9275 if (strcasecmp(val, "NeighborReportReq") == 0) {
9276 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9277 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9278 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9279 } else {
9280 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9281 val);
9282 send_resp(dut, conn, SIGMA_INVALID,
9283 "ErrorCode,Invalid ANQPQuery_ID");
9284 return 0;
9285 }
9286
Ashwini Patild174f2c2017-04-13 16:49:46 +05309287 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9288 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9289 * if associated, AP BSSID).
9290 */
9291 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9292 send_resp(dut, conn, SIGMA_ERROR,
9293 "ErrorCode,Failed to set gas_address3");
9294 return 0;
9295 }
9296
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309297 if (wpa_command(intf, buf) < 0) {
9298 send_resp(dut, conn, SIGMA_ERROR,
9299 "ErrorCode,Failed to send ANQP query");
9300 return 0;
9301 }
9302
9303 return 1;
9304}
9305
9306
9307static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9308 struct sigma_conn *conn,
9309 const char *intf,
9310 struct sigma_cmd *cmd)
9311{
9312 const char *val = get_param(cmd, "FrameName");
9313
9314 if (val && strcasecmp(val, "ANQPQuery") == 0)
9315 return mbo_send_anqp_query(dut, conn, intf, cmd);
9316
9317 return 2;
9318}
9319
9320
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009321int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9322 struct sigma_cmd *cmd)
9323{
9324 const char *intf = get_param(cmd, "Interface");
9325 const char *val;
9326 enum send_frame_type frame;
9327 enum send_frame_protection protected;
9328 char buf[100];
9329 unsigned char addr[ETH_ALEN];
9330 int res;
9331
9332 val = get_param(cmd, "program");
9333 if (val == NULL)
9334 val = get_param(cmd, "frame");
9335 if (val && strcasecmp(val, "TDLS") == 0)
9336 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9337 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009338 strcasecmp(val, "HS2-R2") == 0 ||
9339 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009340 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9341 if (val && strcasecmp(val, "VHT") == 0)
9342 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009343 if (val && strcasecmp(val, "HE") == 0)
9344 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009345 if (val && strcasecmp(val, "LOC") == 0)
9346 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009347 if (val && strcasecmp(val, "60GHz") == 0)
9348 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309349 if (val && strcasecmp(val, "MBO") == 0) {
9350 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9351 if (res != 2)
9352 return res;
9353 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009354
9355 val = get_param(cmd, "TD_DISC");
9356 if (val) {
9357 if (hwaddr_aton(val, addr) < 0)
9358 return -1;
9359 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9360 if (wpa_command(intf, buf) < 0) {
9361 send_resp(dut, conn, SIGMA_ERROR,
9362 "ErrorCode,Failed to send TDLS discovery");
9363 return 0;
9364 }
9365 return 1;
9366 }
9367
9368 val = get_param(cmd, "TD_Setup");
9369 if (val) {
9370 if (hwaddr_aton(val, addr) < 0)
9371 return -1;
9372 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9373 if (wpa_command(intf, buf) < 0) {
9374 send_resp(dut, conn, SIGMA_ERROR,
9375 "ErrorCode,Failed to start TDLS setup");
9376 return 0;
9377 }
9378 return 1;
9379 }
9380
9381 val = get_param(cmd, "TD_TearDown");
9382 if (val) {
9383 if (hwaddr_aton(val, addr) < 0)
9384 return -1;
9385 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9386 if (wpa_command(intf, buf) < 0) {
9387 send_resp(dut, conn, SIGMA_ERROR,
9388 "ErrorCode,Failed to tear down TDLS link");
9389 return 0;
9390 }
9391 return 1;
9392 }
9393
9394 val = get_param(cmd, "TD_ChannelSwitch");
9395 if (val) {
9396 /* TODO */
9397 send_resp(dut, conn, SIGMA_ERROR,
9398 "ErrorCode,TD_ChannelSwitch not yet supported");
9399 return 0;
9400 }
9401
9402 val = get_param(cmd, "TD_NF");
9403 if (val) {
9404 /* TODO */
9405 send_resp(dut, conn, SIGMA_ERROR,
9406 "ErrorCode,TD_NF not yet supported");
9407 return 0;
9408 }
9409
9410 val = get_param(cmd, "PMFFrameType");
9411 if (val == NULL)
9412 val = get_param(cmd, "FrameName");
9413 if (val == NULL)
9414 val = get_param(cmd, "Type");
9415 if (val == NULL)
9416 return -1;
9417 if (strcasecmp(val, "disassoc") == 0)
9418 frame = DISASSOC;
9419 else if (strcasecmp(val, "deauth") == 0)
9420 frame = DEAUTH;
9421 else if (strcasecmp(val, "saquery") == 0)
9422 frame = SAQUERY;
9423 else if (strcasecmp(val, "auth") == 0)
9424 frame = AUTH;
9425 else if (strcasecmp(val, "assocreq") == 0)
9426 frame = ASSOCREQ;
9427 else if (strcasecmp(val, "reassocreq") == 0)
9428 frame = REASSOCREQ;
9429 else if (strcasecmp(val, "neigreq") == 0) {
9430 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9431
9432 val = get_param(cmd, "ssid");
9433 if (val == NULL)
9434 return -1;
9435
9436 res = send_neighbor_request(dut, intf, val);
9437 if (res) {
9438 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9439 "Failed to send neighbor report request");
9440 return 0;
9441 }
9442
9443 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309444 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9445 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009446 sigma_dut_print(dut, DUT_MSG_DEBUG,
9447 "Got Transition Management Query");
9448
Ashwini Patil5acd7382017-04-13 15:55:04 +05309449 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009450 if (res) {
9451 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9452 "Failed to send Transition Management Query");
9453 return 0;
9454 }
9455
9456 return 1;
9457 } else {
9458 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9459 "PMFFrameType");
9460 return 0;
9461 }
9462
9463 val = get_param(cmd, "PMFProtected");
9464 if (val == NULL)
9465 val = get_param(cmd, "Protected");
9466 if (val == NULL)
9467 return -1;
9468 if (strcasecmp(val, "Correct-key") == 0 ||
9469 strcasecmp(val, "CorrectKey") == 0)
9470 protected = CORRECT_KEY;
9471 else if (strcasecmp(val, "IncorrectKey") == 0)
9472 protected = INCORRECT_KEY;
9473 else if (strcasecmp(val, "Unprotected") == 0)
9474 protected = UNPROTECTED;
9475 else {
9476 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9477 "PMFProtected");
9478 return 0;
9479 }
9480
9481 if (protected != UNPROTECTED &&
9482 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9483 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9484 "PMFProtected for auth/assocreq/reassocreq");
9485 return 0;
9486 }
9487
9488 if (if_nametoindex("sigmadut") == 0) {
9489 snprintf(buf, sizeof(buf),
9490 "iw dev %s interface add sigmadut type monitor",
9491 get_station_ifname());
9492 if (system(buf) != 0 ||
9493 if_nametoindex("sigmadut") == 0) {
9494 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9495 "monitor interface with '%s'", buf);
9496 return -2;
9497 }
9498 }
9499
9500 if (system("ifconfig sigmadut up") != 0) {
9501 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9502 "monitor interface up");
9503 return -2;
9504 }
9505
9506 return sta_inject_frame(dut, conn, frame, protected, NULL);
9507}
9508
9509
9510static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9511 struct sigma_conn *conn,
9512 struct sigma_cmd *cmd,
9513 const char *ifname)
9514{
9515 char buf[200];
9516 const char *val;
9517
9518 val = get_param(cmd, "ClearARP");
9519 if (val && atoi(val) == 1) {
9520 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9521 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9522 if (system(buf) != 0) {
9523 send_resp(dut, conn, SIGMA_ERROR,
9524 "errorCode,Failed to clear ARP cache");
9525 return 0;
9526 }
9527 }
9528
9529 return 1;
9530}
9531
9532
9533int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9534 struct sigma_cmd *cmd)
9535{
9536 const char *intf = get_param(cmd, "Interface");
9537 const char *val;
9538
9539 if (intf == NULL)
9540 return -1;
9541
9542 val = get_param(cmd, "program");
9543 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009544 strcasecmp(val, "HS2-R2") == 0 ||
9545 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009546 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9547
9548 return -1;
9549}
9550
9551
9552static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9553 struct sigma_cmd *cmd)
9554{
9555 const char *intf = get_param(cmd, "Interface");
9556 const char *mac = get_param(cmd, "MAC");
9557
9558 if (intf == NULL || mac == NULL)
9559 return -1;
9560
9561 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9562 "interface %s to %s", intf, mac);
9563
9564 if (dut->set_macaddr) {
9565 char buf[128];
9566 int res;
9567 if (strcasecmp(mac, "default") == 0) {
9568 res = snprintf(buf, sizeof(buf), "%s",
9569 dut->set_macaddr);
9570 dut->tmp_mac_addr = 0;
9571 } else {
9572 res = snprintf(buf, sizeof(buf), "%s %s",
9573 dut->set_macaddr, mac);
9574 dut->tmp_mac_addr = 1;
9575 }
9576 if (res < 0 || res >= (int) sizeof(buf))
9577 return -1;
9578 if (system(buf) != 0) {
9579 send_resp(dut, conn, SIGMA_ERROR,
9580 "errorCode,Failed to set MAC "
9581 "address");
9582 return 0;
9583 }
9584 return 1;
9585 }
9586
9587 if (strcasecmp(mac, "default") == 0)
9588 return 1;
9589
9590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9591 "command");
9592 return 0;
9593}
9594
9595
9596static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9597 struct sigma_conn *conn, const char *intf,
9598 int val)
9599{
9600 char buf[200];
9601 int res;
9602
9603 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9604 intf, val);
9605 if (res < 0 || res >= (int) sizeof(buf))
9606 return -1;
9607 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9608 if (system(buf) != 0) {
9609 send_resp(dut, conn, SIGMA_ERROR,
9610 "errorCode,Failed to configure offchannel mode");
9611 return 0;
9612 }
9613
9614 return 1;
9615}
9616
9617
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009618static int off_chan_val(enum sec_ch_offset off)
9619{
9620 switch (off) {
9621 case SEC_CH_NO:
9622 return 0;
9623 case SEC_CH_40ABOVE:
9624 return 40;
9625 case SEC_CH_40BELOW:
9626 return -40;
9627 }
9628
9629 return 0;
9630}
9631
9632
9633static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9634 const char *intf, int off_ch_num,
9635 enum sec_ch_offset sec)
9636{
9637 char buf[200];
9638 int res;
9639
9640 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9641 intf, off_ch_num);
9642 if (res < 0 || res >= (int) sizeof(buf))
9643 return -1;
9644 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9645 if (system(buf) != 0) {
9646 send_resp(dut, conn, SIGMA_ERROR,
9647 "errorCode,Failed to set offchan");
9648 return 0;
9649 }
9650
9651 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9652 intf, off_chan_val(sec));
9653 if (res < 0 || res >= (int) sizeof(buf))
9654 return -1;
9655 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9656 if (system(buf) != 0) {
9657 send_resp(dut, conn, SIGMA_ERROR,
9658 "errorCode,Failed to set sec chan offset");
9659 return 0;
9660 }
9661
9662 return 1;
9663}
9664
9665
9666static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9667 struct sigma_conn *conn,
9668 const char *intf, int off_ch_num,
9669 enum sec_ch_offset sec)
9670{
9671 char buf[200];
9672 int res;
9673
9674 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9675 off_ch_num);
9676 if (res < 0 || res >= (int) sizeof(buf))
9677 return -1;
9678 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9679
9680 if (wpa_command(intf, buf) < 0) {
9681 send_resp(dut, conn, SIGMA_ERROR,
9682 "ErrorCode,Failed to set offchan");
9683 return 0;
9684 }
9685 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9686 off_chan_val(sec));
9687 if (res < 0 || res >= (int) sizeof(buf))
9688 return -1;
9689
9690 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9691
9692 if (wpa_command(intf, buf) < 0) {
9693 send_resp(dut, conn, SIGMA_ERROR,
9694 "ErrorCode,Failed to set sec chan offset");
9695 return 0;
9696 }
9697
9698 return 1;
9699}
9700
9701
9702static int tdls_set_offchannel_mode(struct sigma_dut *dut,
9703 struct sigma_conn *conn,
9704 const char *intf, int val)
9705{
9706 char buf[200];
9707 int res;
9708
9709 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
9710 val);
9711 if (res < 0 || res >= (int) sizeof(buf))
9712 return -1;
9713 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9714
9715 if (wpa_command(intf, buf) < 0) {
9716 send_resp(dut, conn, SIGMA_ERROR,
9717 "ErrorCode,Failed to configure offchannel mode");
9718 return 0;
9719 }
9720
9721 return 1;
9722}
9723
9724
9725static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
9726 struct sigma_conn *conn,
9727 struct sigma_cmd *cmd)
9728{
9729 const char *val;
9730 enum {
9731 CHSM_NOT_SET,
9732 CHSM_ENABLE,
9733 CHSM_DISABLE,
9734 CHSM_REJREQ,
9735 CHSM_UNSOLRESP
9736 } chsm = CHSM_NOT_SET;
9737 int off_ch_num = -1;
9738 enum sec_ch_offset sec_ch = SEC_CH_NO;
9739 int res;
9740
9741 val = get_param(cmd, "Uapsd");
9742 if (val) {
9743 char buf[100];
9744 if (strcasecmp(val, "Enable") == 0)
9745 snprintf(buf, sizeof(buf), "SET ps 99");
9746 else if (strcasecmp(val, "Disable") == 0)
9747 snprintf(buf, sizeof(buf), "SET ps 98");
9748 else {
9749 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9750 "Unsupported uapsd parameter value");
9751 return 0;
9752 }
9753 if (wpa_command(intf, buf)) {
9754 send_resp(dut, conn, SIGMA_ERROR,
9755 "ErrorCode,Failed to change U-APSD "
9756 "powersave mode");
9757 return 0;
9758 }
9759 }
9760
9761 val = get_param(cmd, "TPKTIMER");
9762 if (val && strcasecmp(val, "DISABLE") == 0) {
9763 if (wpa_command(intf, "SET tdls_testing 0x100")) {
9764 send_resp(dut, conn, SIGMA_ERROR,
9765 "ErrorCode,Failed to enable no TPK "
9766 "expiration test mode");
9767 return 0;
9768 }
9769 dut->no_tpk_expiration = 1;
9770 }
9771
9772 val = get_param(cmd, "ChSwitchMode");
9773 if (val) {
9774 if (strcasecmp(val, "Enable") == 0 ||
9775 strcasecmp(val, "Initiate") == 0)
9776 chsm = CHSM_ENABLE;
9777 else if (strcasecmp(val, "Disable") == 0 ||
9778 strcasecmp(val, "passive") == 0)
9779 chsm = CHSM_DISABLE;
9780 else if (strcasecmp(val, "RejReq") == 0)
9781 chsm = CHSM_REJREQ;
9782 else if (strcasecmp(val, "UnSolResp") == 0)
9783 chsm = CHSM_UNSOLRESP;
9784 else {
9785 send_resp(dut, conn, SIGMA_ERROR,
9786 "ErrorCode,Unknown ChSwitchMode value");
9787 return 0;
9788 }
9789 }
9790
9791 val = get_param(cmd, "OffChNum");
9792 if (val) {
9793 off_ch_num = atoi(val);
9794 if (off_ch_num == 0) {
9795 send_resp(dut, conn, SIGMA_ERROR,
9796 "ErrorCode,Invalid OffChNum");
9797 return 0;
9798 }
9799 }
9800
9801 val = get_param(cmd, "SecChOffset");
9802 if (val) {
9803 if (strcmp(val, "20") == 0)
9804 sec_ch = SEC_CH_NO;
9805 else if (strcasecmp(val, "40above") == 0)
9806 sec_ch = SEC_CH_40ABOVE;
9807 else if (strcasecmp(val, "40below") == 0)
9808 sec_ch = SEC_CH_40BELOW;
9809 else {
9810 send_resp(dut, conn, SIGMA_ERROR,
9811 "ErrorCode,Unknown SecChOffset value");
9812 return 0;
9813 }
9814 }
9815
9816 if (chsm == CHSM_NOT_SET) {
9817 /* no offchannel changes requested */
9818 return 1;
9819 }
9820
9821 if (strcmp(intf, get_main_ifname()) != 0 &&
9822 strcmp(intf, get_station_ifname()) != 0) {
9823 send_resp(dut, conn, SIGMA_ERROR,
9824 "ErrorCode,Unknown interface");
9825 return 0;
9826 }
9827
9828 switch (chsm) {
9829 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03009830 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009831 break;
9832 case CHSM_ENABLE:
9833 if (off_ch_num < 0) {
9834 send_resp(dut, conn, SIGMA_ERROR,
9835 "ErrorCode,Missing OffChNum argument");
9836 return 0;
9837 }
9838 if (wifi_chip_type == DRIVER_WCN) {
9839 res = tdls_set_offchannel_offset(dut, conn, intf,
9840 off_ch_num, sec_ch);
9841 } else {
9842 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9843 sec_ch);
9844 }
9845 if (res != 1)
9846 return res;
9847 if (wifi_chip_type == DRIVER_WCN)
9848 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
9849 else
9850 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
9851 break;
9852 case CHSM_DISABLE:
9853 if (wifi_chip_type == DRIVER_WCN)
9854 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
9855 else
9856 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
9857 break;
9858 case CHSM_REJREQ:
9859 if (wifi_chip_type == DRIVER_WCN)
9860 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
9861 else
9862 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
9863 break;
9864 case CHSM_UNSOLRESP:
9865 if (off_ch_num < 0) {
9866 send_resp(dut, conn, SIGMA_ERROR,
9867 "ErrorCode,Missing OffChNum argument");
9868 return 0;
9869 }
9870 if (wifi_chip_type == DRIVER_WCN) {
9871 res = tdls_set_offchannel_offset(dut, conn, intf,
9872 off_ch_num, sec_ch);
9873 } else {
9874 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9875 sec_ch);
9876 }
9877 if (res != 1)
9878 return res;
9879 if (wifi_chip_type == DRIVER_WCN)
9880 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
9881 else
9882 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
9883 break;
9884 }
9885
9886 return res;
9887}
9888
9889
9890static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9891 struct sigma_conn *conn,
9892 struct sigma_cmd *cmd)
9893{
9894 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309895 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009896
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009897 novap_reset(dut, intf);
9898
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009899 val = get_param(cmd, "nss_mcs_opt");
9900 if (val) {
9901 /* String (nss_operating_mode; mcs_operating_mode) */
9902 int nss, mcs;
9903 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309904 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009905
9906 token = strdup(val);
9907 if (!token)
9908 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309909 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309910 if (!result) {
9911 sigma_dut_print(dut, DUT_MSG_ERROR,
9912 "VHT NSS not specified");
9913 goto failed;
9914 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009915 if (strcasecmp(result, "def") != 0) {
9916 nss = atoi(result);
9917 if (nss == 4)
9918 ath_disable_txbf(dut, intf);
9919 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
9920 intf, nss);
9921 if (system(buf) != 0) {
9922 sigma_dut_print(dut, DUT_MSG_ERROR,
9923 "iwpriv nss failed");
9924 goto failed;
9925 }
9926 }
9927
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309928 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309929 if (!result) {
9930 sigma_dut_print(dut, DUT_MSG_ERROR,
9931 "VHT MCS not specified");
9932 goto failed;
9933 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009934 if (strcasecmp(result, "def") == 0) {
9935 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
9936 intf);
9937 if (system(buf) != 0) {
9938 sigma_dut_print(dut, DUT_MSG_ERROR,
9939 "iwpriv set11NRates failed");
9940 goto failed;
9941 }
9942
9943 } else {
9944 mcs = atoi(result);
9945 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
9946 intf, mcs);
9947 if (system(buf) != 0) {
9948 sigma_dut_print(dut, DUT_MSG_ERROR,
9949 "iwpriv vhtmcs failed");
9950 goto failed;
9951 }
9952 }
9953 /* Channel width gets messed up, fix this */
9954 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9955 intf, dut->chwidth);
9956 if (system(buf) != 0) {
9957 sigma_dut_print(dut, DUT_MSG_ERROR,
9958 "iwpriv chwidth failed");
9959 }
9960 }
9961
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309962 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009963 return 1;
9964failed:
9965 free(token);
9966 return 0;
9967}
9968
9969
9970static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9971 struct sigma_conn *conn,
9972 struct sigma_cmd *cmd)
9973{
9974 switch (get_driver_type()) {
9975 case DRIVER_ATHEROS:
9976 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
9977 default:
9978 send_resp(dut, conn, SIGMA_ERROR,
9979 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
9980 return 0;
9981 }
9982}
9983
9984
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009985static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9986 struct sigma_conn *conn,
9987 struct sigma_cmd *cmd)
9988{
9989 const char *val;
9990 char *token = NULL, *result;
9991 char buf[60];
9992
9993 val = get_param(cmd, "nss_mcs_opt");
9994 if (val) {
9995 /* String (nss_operating_mode; mcs_operating_mode) */
9996 int nss, mcs, ratecode;
9997 char *saveptr;
9998
9999 token = strdup(val);
10000 if (!token)
10001 return -2;
10002
10003 result = strtok_r(token, ";", &saveptr);
10004 if (!result) {
10005 sigma_dut_print(dut, DUT_MSG_ERROR,
10006 "HE NSS not specified");
10007 goto failed;
10008 }
10009 nss = 1;
10010 if (strcasecmp(result, "def") != 0)
10011 nss = atoi(result);
10012
10013 result = strtok_r(NULL, ";", &saveptr);
10014 if (!result) {
10015 sigma_dut_print(dut, DUT_MSG_ERROR,
10016 "HE MCS not specified");
10017 goto failed;
10018 }
10019 mcs = 7;
10020 if (strcasecmp(result, "def") != 0)
10021 mcs = atoi(result);
10022
Arif Hussain557bf412018-05-25 17:29:36 -070010023 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010024 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070010025 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010026 } else if (nss > 2) {
10027 sigma_dut_print(dut, DUT_MSG_ERROR,
10028 "HE NSS %d not supported", nss);
10029 goto failed;
10030 }
10031
Arif Hussain557bf412018-05-25 17:29:36 -070010032 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
10033 if (system(buf) != 0) {
10034 sigma_dut_print(dut, DUT_MSG_ERROR,
10035 "nss_mcs_opt: iwpriv %s nss %d failed",
10036 intf, nss);
10037 goto failed;
10038 }
Arif Hussainac6c5112018-05-25 17:34:00 -070010039 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070010040
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010041 /* Add the MCS to the ratecode */
10042 if (mcs >= 0 && mcs <= 11) {
10043 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070010044#ifdef NL80211_SUPPORT
10045 if (dut->device_type == STA_testbed) {
10046 enum he_mcs_config mcs_config;
10047 int ret;
10048
10049 if (mcs <= 7)
10050 mcs_config = HE_80_MCS0_7;
10051 else if (mcs <= 9)
10052 mcs_config = HE_80_MCS0_9;
10053 else
10054 mcs_config = HE_80_MCS0_11;
10055 ret = sta_set_he_mcs(dut, intf, mcs_config);
10056 if (ret) {
10057 sigma_dut_print(dut, DUT_MSG_ERROR,
10058 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10059 mcs, mcs_config, ret);
10060 goto failed;
10061 }
10062 }
10063#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010064 } else {
10065 sigma_dut_print(dut, DUT_MSG_ERROR,
10066 "HE MCS %d not supported", mcs);
10067 goto failed;
10068 }
10069 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
10070 intf, ratecode);
10071 if (system(buf) != 0) {
10072 sigma_dut_print(dut, DUT_MSG_ERROR,
10073 "iwpriv setting of 11ax rates failed");
10074 goto failed;
10075 }
10076 free(token);
10077 }
10078
10079 val = get_param(cmd, "GI");
10080 if (val) {
10081 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010082 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010083 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010084 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
10085 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010086 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010087 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
10088 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010089 } else {
10090 send_resp(dut, conn, SIGMA_ERROR,
10091 "errorCode,GI value not supported");
10092 return 0;
10093 }
10094 if (system(buf) != 0) {
10095 send_resp(dut, conn, SIGMA_ERROR,
10096 "errorCode,Failed to set shortgi");
10097 return 0;
10098 }
10099 }
10100
Subhani Shaik8e7a3052018-04-24 14:03:00 -070010101 val = get_param(cmd, "LTF");
10102 if (val) {
10103#ifdef NL80211_SUPPORT
10104 if (strcmp(val, "3.2") == 0) {
10105 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
10106 } if (strcmp(val, "6.4") == 0) {
10107 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
10108 } else if (strcmp(val, "12.8") == 0) {
10109 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
10110 } else {
10111 send_resp(dut, conn, SIGMA_ERROR,
10112 "errorCode, LTF value not supported");
10113 return 0;
10114 }
10115#else /* NL80211_SUPPORT */
10116 sigma_dut_print(dut, DUT_MSG_ERROR,
10117 "LTF cannot be set without NL80211_SUPPORT defined");
10118 return -2;
10119#endif /* NL80211_SUPPORT */
10120 }
10121
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070010122 val = get_param(cmd, "TxSUPPDU");
10123 if (val) {
10124 int set_val = 1;
10125
10126 if (strcasecmp(val, "Enable") == 0)
10127 set_val = 1;
10128 else if (strcasecmp(val, "Disable") == 0)
10129 set_val = 0;
10130
10131 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
10132 send_resp(dut, conn, SIGMA_ERROR,
10133 "ErrorCode,Failed to set Tx SU PPDU config");
10134 return 0;
10135 }
10136 }
10137
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070010138 val = get_param(cmd, "OMCtrl_RxNSS");
10139 if (val) {
10140 /*
10141 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
10142 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
10143 * the actual Nss value hence add 1 to the set value.
10144 */
10145 int set_val = atoi(val) + 1;
10146
10147 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
10148 send_resp(dut, conn, SIGMA_ERROR,
10149 "ErrorCode,Failed to set OM ctrl NSS config");
10150 return 0;
10151 }
10152 }
10153
10154 val = get_param(cmd, "OMCtrl_ChnlWidth");
10155 if (val) {
10156 int set_val = atoi(val);
10157
10158 if (sta_set_he_om_ctrl_bw(dut, intf,
10159 (enum qca_wlan_he_om_ctrl_ch_bw)
10160 set_val)) {
10161 send_resp(dut, conn, SIGMA_ERROR,
10162 "ErrorCode,Failed to set OM ctrl BW config");
10163 return 0;
10164 }
10165 }
10166
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080010167 val = get_param(cmd, "Powersave");
10168 if (val) {
10169 char buf[60];
10170
10171 if (strcasecmp(val, "off") == 0) {
10172 snprintf(buf, sizeof(buf),
10173 "iwpriv %s setPower 2", intf);
10174 if (system(buf) != 0) {
10175 sigma_dut_print(dut, DUT_MSG_ERROR,
10176 "iwpriv setPower 2 failed");
10177 return 0;
10178 }
10179 } else if (strcasecmp(val, "on") == 0) {
10180 snprintf(buf, sizeof(buf),
10181 "iwpriv %s setPower 1", intf);
10182 if (system(buf) != 0) {
10183 sigma_dut_print(dut, DUT_MSG_ERROR,
10184 "iwpriv setPower 1 failed");
10185 return 0;
10186 }
10187 } else {
10188 sigma_dut_print(dut, DUT_MSG_ERROR,
10189 "Unsupported Powersave value '%s'",
10190 val);
10191 return -1;
10192 }
10193 }
10194
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010195 return 1;
10196
10197failed:
10198 free(token);
10199 return -2;
10200}
10201
10202
10203static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10204 struct sigma_conn *conn,
10205 struct sigma_cmd *cmd)
10206{
10207 switch (get_driver_type()) {
10208 case DRIVER_WCN:
10209 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
10210 default:
10211 send_resp(dut, conn, SIGMA_ERROR,
10212 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
10213 return 0;
10214 }
10215}
10216
10217
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010218static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
10219 struct sigma_conn *conn,
10220 struct sigma_cmd *cmd)
10221{
10222 const char *val;
10223
10224 val = get_param(cmd, "powersave");
10225 if (val) {
10226 char buf[60];
10227
10228 if (strcasecmp(val, "off") == 0) {
10229 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
10230 intf);
10231 if (system(buf) != 0) {
10232 sigma_dut_print(dut, DUT_MSG_ERROR,
10233 "iwpriv setPower 2 failed");
10234 return 0;
10235 }
10236 } else if (strcasecmp(val, "on") == 0) {
10237 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
10238 intf);
10239 if (system(buf) != 0) {
10240 sigma_dut_print(dut, DUT_MSG_ERROR,
10241 "iwpriv setPower 1 failed");
10242 return 0;
10243 }
10244 } else {
10245 sigma_dut_print(dut, DUT_MSG_ERROR,
10246 "Unsupported power save config");
10247 return -1;
10248 }
10249 return 1;
10250 }
10251
10252 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
10253
10254 return 0;
10255}
10256
10257
Ashwini Patil5acd7382017-04-13 15:55:04 +053010258static int btm_query_candidate_list(struct sigma_dut *dut,
10259 struct sigma_conn *conn,
10260 struct sigma_cmd *cmd)
10261{
10262 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
10263 int len, ret;
10264 char buf[10];
10265
10266 /*
10267 * Neighbor Report elements format:
10268 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
10269 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
10270 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
10271 */
10272
10273 bssid = get_param(cmd, "Nebor_BSSID");
10274 if (!bssid) {
10275 send_resp(dut, conn, SIGMA_INVALID,
10276 "errorCode,Nebor_BSSID is missing");
10277 return 0;
10278 }
10279
10280 info = get_param(cmd, "Nebor_Bssid_Info");
10281 if (!info) {
10282 sigma_dut_print(dut, DUT_MSG_INFO,
10283 "Using default value for Nebor_Bssid_Info: %s",
10284 DEFAULT_NEIGHBOR_BSSID_INFO);
10285 info = DEFAULT_NEIGHBOR_BSSID_INFO;
10286 }
10287
10288 op_class = get_param(cmd, "Nebor_Op_Class");
10289 if (!op_class) {
10290 send_resp(dut, conn, SIGMA_INVALID,
10291 "errorCode,Nebor_Op_Class is missing");
10292 return 0;
10293 }
10294
10295 ch = get_param(cmd, "Nebor_Op_Ch");
10296 if (!ch) {
10297 send_resp(dut, conn, SIGMA_INVALID,
10298 "errorCode,Nebor_Op_Ch is missing");
10299 return 0;
10300 }
10301
10302 phy_type = get_param(cmd, "Nebor_Phy_Type");
10303 if (!phy_type) {
10304 sigma_dut_print(dut, DUT_MSG_INFO,
10305 "Using default value for Nebor_Phy_Type: %s",
10306 DEFAULT_NEIGHBOR_PHY_TYPE);
10307 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
10308 }
10309
10310 /* Parse optional subelements */
10311 buf[0] = '\0';
10312 pref = get_param(cmd, "Nebor_Pref");
10313 if (pref) {
10314 /* hexdump for preferrence subelement */
10315 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10316 if (ret < 0 || ret >= (int) sizeof(buf)) {
10317 sigma_dut_print(dut, DUT_MSG_ERROR,
10318 "snprintf failed for optional subelement ret: %d",
10319 ret);
10320 send_resp(dut, conn, SIGMA_ERROR,
10321 "errorCode,snprintf failed for subelement");
10322 return 0;
10323 }
10324 }
10325
10326 if (!dut->btm_query_cand_list) {
10327 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10328 if (!dut->btm_query_cand_list) {
10329 send_resp(dut, conn, SIGMA_ERROR,
10330 "errorCode,Failed to allocate memory for btm_query_cand_list");
10331 return 0;
10332 }
10333 }
10334
10335 len = strlen(dut->btm_query_cand_list);
10336 ret = snprintf(dut->btm_query_cand_list + len,
10337 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10338 bssid, info, op_class, ch, phy_type, buf);
10339 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10340 sigma_dut_print(dut, DUT_MSG_ERROR,
10341 "snprintf failed for neighbor report list ret: %d",
10342 ret);
10343 send_resp(dut, conn, SIGMA_ERROR,
10344 "errorCode,snprintf failed for neighbor report");
10345 free(dut->btm_query_cand_list);
10346 dut->btm_query_cand_list = NULL;
10347 return 0;
10348 }
10349
10350 return 1;
10351}
10352
10353
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010354static int cmd_sta_set_power_save(struct sigma_dut *dut,
10355 struct sigma_conn *conn,
10356 struct sigma_cmd *cmd)
10357{
10358 const char *intf = get_param(cmd, "interface");
10359 const char *prog = get_param(cmd, "program");
10360
10361 if (!intf || !prog)
10362 return -1;
10363
10364 if ((get_driver_type() == DRIVER_WCN) && (strcasecmp(prog, "HE") == 0))
10365 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
10366
10367 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10368 return 0;
10369}
10370
10371
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010372static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10373 struct sigma_cmd *cmd)
10374{
10375 const char *intf = get_param(cmd, "Interface");
10376 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010377 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010378
10379 if (intf == NULL || prog == NULL)
10380 return -1;
10381
Ashwini Patil5acd7382017-04-13 15:55:04 +053010382 /* BSS Transition candidate list for BTM query */
10383 val = get_param(cmd, "Nebor_BSSID");
10384 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10385 return 0;
10386
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010387 if (strcasecmp(prog, "TDLS") == 0)
10388 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10389
10390 if (strcasecmp(prog, "VHT") == 0)
10391 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10392
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010393 if (strcasecmp(prog, "HE") == 0)
10394 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10395
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010396 if (strcasecmp(prog, "MBO") == 0) {
10397 val = get_param(cmd, "Cellular_Data_Cap");
10398 if (val &&
10399 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10400 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010401
10402 val = get_param(cmd, "Ch_Pref");
10403 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10404 return 0;
10405
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010406 return 1;
10407 }
10408
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010409 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10410 return 0;
10411}
10412
10413
10414static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10415 struct sigma_cmd *cmd)
10416{
10417 const char *intf = get_param(cmd, "Interface");
10418 const char *mode = get_param(cmd, "Mode");
10419 int res;
10420
10421 if (intf == NULL || mode == NULL)
10422 return -1;
10423
10424 if (strcasecmp(mode, "On") == 0)
10425 res = wpa_command(intf, "SET radio_disabled 0");
10426 else if (strcasecmp(mode, "Off") == 0)
10427 res = wpa_command(intf, "SET radio_disabled 1");
10428 else
10429 return -1;
10430
10431 if (res) {
10432 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10433 "radio mode");
10434 return 0;
10435 }
10436
10437 return 1;
10438}
10439
10440
10441static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10442 struct sigma_cmd *cmd)
10443{
10444 const char *intf = get_param(cmd, "Interface");
10445 const char *mode = get_param(cmd, "Mode");
10446 int res;
10447
10448 if (intf == NULL || mode == NULL)
10449 return -1;
10450
10451 if (strcasecmp(mode, "On") == 0)
10452 res = set_ps(intf, dut, 1);
10453 else if (strcasecmp(mode, "Off") == 0)
10454 res = set_ps(intf, dut, 0);
10455 else
10456 return -1;
10457
10458 if (res) {
10459 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10460 "power save mode");
10461 return 0;
10462 }
10463
10464 return 1;
10465}
10466
10467
10468static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10469 struct sigma_cmd *cmd)
10470{
10471 const char *intf = get_param(cmd, "Interface");
10472 const char *val, *bssid;
10473 int res;
10474 char *buf;
10475 size_t buf_len;
10476
10477 val = get_param(cmd, "BSSID_FILTER");
10478 if (val == NULL)
10479 return -1;
10480
10481 bssid = get_param(cmd, "BSSID_List");
10482 if (atoi(val) == 0 || bssid == NULL) {
10483 /* Disable BSSID filter */
10484 if (wpa_command(intf, "SET bssid_filter ")) {
10485 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10486 "to disable BSSID filter");
10487 return 0;
10488 }
10489
10490 return 1;
10491 }
10492
10493 buf_len = 100 + strlen(bssid);
10494 buf = malloc(buf_len);
10495 if (buf == NULL)
10496 return -1;
10497
10498 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10499 res = wpa_command(intf, buf);
10500 free(buf);
10501 if (res) {
10502 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10503 "BSSID filter");
10504 return 0;
10505 }
10506
10507 return 1;
10508}
10509
10510
10511static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10512 struct sigma_cmd *cmd)
10513{
10514 const char *intf = get_param(cmd, "Interface");
10515 const char *val;
10516
10517 /* TODO: ARP */
10518
10519 val = get_param(cmd, "HS2_CACHE_PROFILE");
10520 if (val && strcasecmp(val, "All") == 0)
10521 hs2_clear_credentials(intf);
10522
10523 return 1;
10524}
10525
10526
10527static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10528 struct sigma_cmd *cmd)
10529{
10530 const char *intf = get_param(cmd, "Interface");
10531 const char *key_type = get_param(cmd, "KeyType");
10532 char buf[100], resp[200];
10533
10534 if (key_type == NULL)
10535 return -1;
10536
10537 if (strcasecmp(key_type, "GTK") == 0) {
10538 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10539 strncmp(buf, "FAIL", 4) == 0) {
10540 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10541 "not fetch current GTK");
10542 return 0;
10543 }
10544 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10545 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10546 return 0;
10547 } else {
10548 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10549 "KeyType");
10550 return 0;
10551 }
10552
10553 return 1;
10554}
10555
10556
10557static int hs2_set_policy(struct sigma_dut *dut)
10558{
10559#ifdef ANDROID
10560 system("ip rule del prio 23000");
10561 if (system("ip rule add from all lookup main prio 23000") != 0) {
10562 sigma_dut_print(dut, DUT_MSG_ERROR,
10563 "Failed to run:ip rule add from all lookup main prio");
10564 return -1;
10565 }
10566 if (system("ip route flush cache") != 0) {
10567 sigma_dut_print(dut, DUT_MSG_ERROR,
10568 "Failed to run ip route flush cache");
10569 return -1;
10570 }
10571 return 1;
10572#else /* ANDROID */
10573 return 0;
10574#endif /* ANDROID */
10575}
10576
10577
10578static int cmd_sta_hs2_associate(struct sigma_dut *dut,
10579 struct sigma_conn *conn,
10580 struct sigma_cmd *cmd)
10581{
10582 const char *intf = get_param(cmd, "Interface");
10583 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030010584 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010585 struct wpa_ctrl *ctrl;
10586 int res;
10587 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
10588 int tries = 0;
10589 int ignore_blacklist = 0;
10590 const char *events[] = {
10591 "CTRL-EVENT-CONNECTED",
10592 "INTERWORKING-BLACKLISTED",
10593 "INTERWORKING-NO-MATCH",
10594 NULL
10595 };
10596
10597 start_sta_mode(dut);
10598
Jouni Malinen439352d2018-09-13 03:42:23 +030010599 if (band) {
10600 if (strcmp(band, "2.4") == 0) {
10601 wpa_command(intf, "SET setband 2G");
10602 } else if (strcmp(band, "5") == 0) {
10603 wpa_command(intf, "SET setband 5G");
10604 } else {
10605 send_resp(dut, conn, SIGMA_ERROR,
10606 "errorCode,Unsupported band");
10607 return 0;
10608 }
10609 }
10610
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010611 blacklisted[0] = '\0';
10612 if (val && atoi(val))
10613 ignore_blacklist = 1;
10614
10615try_again:
10616 ctrl = open_wpa_mon(intf);
10617 if (ctrl == NULL) {
10618 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10619 "wpa_supplicant monitor connection");
10620 return -2;
10621 }
10622
10623 tries++;
10624 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
10625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
10626 "Interworking connection");
10627 wpa_ctrl_detach(ctrl);
10628 wpa_ctrl_close(ctrl);
10629 return 0;
10630 }
10631
10632 buf[0] = '\0';
10633 while (1) {
10634 char *pos;
10635 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10636 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
10637 if (!pos)
10638 break;
10639 pos += 25;
10640 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
10641 pos);
10642 if (!blacklisted[0])
10643 memcpy(blacklisted, pos, strlen(pos) + 1);
10644 }
10645
10646 if (ignore_blacklist && blacklisted[0]) {
10647 char *end;
10648 end = strchr(blacklisted, ' ');
10649 if (end)
10650 *end = '\0';
10651 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
10652 blacklisted);
10653 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
10654 blacklisted);
10655 if (wpa_command(intf, buf)) {
10656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
10657 wpa_ctrl_detach(ctrl);
10658 wpa_ctrl_close(ctrl);
10659 return 0;
10660 }
10661 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10662 buf, sizeof(buf));
10663 }
10664
10665 wpa_ctrl_detach(ctrl);
10666 wpa_ctrl_close(ctrl);
10667
10668 if (res < 0) {
10669 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10670 "connect");
10671 return 0;
10672 }
10673
10674 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
10675 strstr(buf, "INTERWORKING-BLACKLISTED")) {
10676 if (tries < 2) {
10677 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
10678 goto try_again;
10679 }
10680 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
10681 "matching credentials found");
10682 return 0;
10683 }
10684
10685 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10686 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10687 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10688 "get current BSSID/SSID");
10689 return 0;
10690 }
10691
10692 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
10693 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10694 hs2_set_policy(dut);
10695 return 0;
10696}
10697
10698
Jouni Malinenb639f1c2018-09-13 02:39:46 +030010699static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
10700 struct sigma_conn *conn,
10701 struct sigma_cmd *cmd)
10702{
10703 const char *intf = get_param(cmd, "Interface");
10704 const char *display = get_param(cmd, "Display");
10705 struct wpa_ctrl *ctrl;
10706 char buf[300], params[400], *pos;
10707 char bssid[20];
10708 int info_avail = 0;
10709 unsigned int old_timeout;
10710 int res;
10711
10712 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
10713 send_resp(dut, conn, SIGMA_ERROR,
10714 "ErrorCode,Could not get current BSSID");
10715 return 0;
10716 }
10717 ctrl = open_wpa_mon(intf);
10718 if (!ctrl) {
10719 sigma_dut_print(dut, DUT_MSG_ERROR,
10720 "Failed to open wpa_supplicant monitor connection");
10721 return -2;
10722 }
10723
10724 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
10725 wpa_command(intf, buf);
10726
10727 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
10728 if (res < 0) {
10729 send_resp(dut, conn, SIGMA_ERROR,
10730 "ErrorCode,Could not complete GAS query");
10731 goto fail;
10732 }
10733
10734 old_timeout = dut->default_timeout;
10735 dut->default_timeout = 2;
10736 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
10737 dut->default_timeout = old_timeout;
10738 if (res < 0)
10739 goto done;
10740 pos = strchr(buf, ' ');
10741 if (!pos)
10742 goto done;
10743 pos++;
10744 pos = strchr(pos, ' ');
10745 if (!pos)
10746 goto done;
10747 pos++;
10748 info_avail = 1;
10749 snprintf(params, sizeof(params), "browser %s", pos);
10750
10751 if (display && strcasecmp(display, "Yes") == 0) {
10752 pid_t pid;
10753
10754 pid = fork();
10755 if (pid < 0) {
10756 perror("fork");
10757 return -1;
10758 }
10759
10760 if (pid == 0) {
10761 run_hs20_osu(dut, params);
10762 exit(0);
10763 }
10764 }
10765
10766done:
10767 snprintf(buf, sizeof(buf), "Info_available,%s",
10768 info_avail ? "Yes" : "No");
10769 send_resp(dut, conn, SIGMA_COMPLETE, buf);
10770fail:
10771 wpa_ctrl_detach(ctrl);
10772 wpa_ctrl_close(ctrl);
10773 return 0;
10774}
10775
10776
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010777static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
10778 struct sigma_conn *conn,
10779 const char *ifname,
10780 struct sigma_cmd *cmd)
10781{
10782 const char *val;
10783 int id;
10784
10785 id = add_cred(ifname);
10786 if (id < 0)
10787 return -2;
10788 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10789
10790 val = get_param(cmd, "prefer");
10791 if (val && atoi(val) > 0)
10792 set_cred(ifname, id, "priority", "1");
10793
10794 val = get_param(cmd, "REALM");
10795 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10796 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10797 "realm");
10798 return 0;
10799 }
10800
10801 val = get_param(cmd, "HOME_FQDN");
10802 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10804 "home_fqdn");
10805 return 0;
10806 }
10807
10808 val = get_param(cmd, "Username");
10809 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10810 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10811 "username");
10812 return 0;
10813 }
10814
10815 val = get_param(cmd, "Password");
10816 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
10817 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10818 "password");
10819 return 0;
10820 }
10821
10822 val = get_param(cmd, "ROOT_CA");
10823 if (val) {
10824 char fname[200];
10825 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10826#ifdef __linux__
10827 if (!file_exists(fname)) {
10828 char msg[300];
10829 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10830 "file (%s) not found", fname);
10831 send_resp(dut, conn, SIGMA_ERROR, msg);
10832 return 0;
10833 }
10834#endif /* __linux__ */
10835 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10837 "not set root CA");
10838 return 0;
10839 }
10840 }
10841
10842 return 1;
10843}
10844
10845
10846static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
10847{
10848 FILE *in, *out;
10849 char buf[500];
10850 int found = 0;
10851
10852 in = fopen("devdetail.xml", "r");
10853 if (in == NULL)
10854 return -1;
10855 out = fopen("devdetail.xml.tmp", "w");
10856 if (out == NULL) {
10857 fclose(in);
10858 return -1;
10859 }
10860
10861 while (fgets(buf, sizeof(buf), in)) {
10862 char *pos = strstr(buf, "<IMSI>");
10863 if (pos) {
10864 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
10865 imsi);
10866 pos += 6;
10867 *pos = '\0';
10868 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
10869 found++;
10870 } else {
10871 fprintf(out, "%s", buf);
10872 }
10873 }
10874
10875 fclose(out);
10876 fclose(in);
10877 if (found)
10878 rename("devdetail.xml.tmp", "devdetail.xml");
10879 else
10880 unlink("devdetail.xml.tmp");
10881
10882 return 0;
10883}
10884
10885
10886static int sta_add_credential_sim(struct sigma_dut *dut,
10887 struct sigma_conn *conn,
10888 const char *ifname, struct sigma_cmd *cmd)
10889{
10890 const char *val, *imsi = NULL;
10891 int id;
10892 char buf[200];
10893 int res;
10894 const char *pos;
10895 size_t mnc_len;
10896 char plmn_mcc[4];
10897 char plmn_mnc[4];
10898
10899 id = add_cred(ifname);
10900 if (id < 0)
10901 return -2;
10902 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10903
10904 val = get_param(cmd, "prefer");
10905 if (val && atoi(val) > 0)
10906 set_cred(ifname, id, "priority", "1");
10907
10908 val = get_param(cmd, "PLMN_MCC");
10909 if (val == NULL) {
10910 send_resp(dut, conn, SIGMA_ERROR,
10911 "errorCode,Missing PLMN_MCC");
10912 return 0;
10913 }
10914 if (strlen(val) != 3) {
10915 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
10916 return 0;
10917 }
10918 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
10919
10920 val = get_param(cmd, "PLMN_MNC");
10921 if (val == NULL) {
10922 send_resp(dut, conn, SIGMA_ERROR,
10923 "errorCode,Missing PLMN_MNC");
10924 return 0;
10925 }
10926 if (strlen(val) != 2 && strlen(val) != 3) {
10927 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
10928 return 0;
10929 }
10930 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
10931
10932 val = get_param(cmd, "IMSI");
10933 if (val == NULL) {
10934 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
10935 "IMSI");
10936 return 0;
10937 }
10938
10939 imsi = pos = val;
10940
10941 if (strncmp(plmn_mcc, pos, 3) != 0) {
10942 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
10943 return 0;
10944 }
10945 pos += 3;
10946
10947 mnc_len = strlen(plmn_mnc);
10948 if (mnc_len < 2) {
10949 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
10950 return 0;
10951 }
10952
10953 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
10954 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
10955 return 0;
10956 }
10957 pos += mnc_len;
10958
10959 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
10960 if (res < 0 || res >= (int) sizeof(buf))
10961 return -1;
10962 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
10963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10964 "not set IMSI");
10965 return 0;
10966 }
10967
10968 val = get_param(cmd, "Password");
10969 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
10970 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10971 "not set password");
10972 return 0;
10973 }
10974
Jouni Malinenba630452018-06-22 11:49:59 +030010975 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010976 /*
10977 * Set provisioning_sp for the test cases where SIM/USIM
10978 * provisioning is used.
10979 */
10980 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
10981 "wi-fi.org") < 0) {
10982 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10983 "not set provisioning_sp");
10984 return 0;
10985 }
10986
10987 update_devdetail_imsi(dut, imsi);
10988 }
10989
10990 return 1;
10991}
10992
10993
10994static int sta_add_credential_cert(struct sigma_dut *dut,
10995 struct sigma_conn *conn,
10996 const char *ifname,
10997 struct sigma_cmd *cmd)
10998{
10999 const char *val;
11000 int id;
11001
11002 id = add_cred(ifname);
11003 if (id < 0)
11004 return -2;
11005 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11006
11007 val = get_param(cmd, "prefer");
11008 if (val && atoi(val) > 0)
11009 set_cred(ifname, id, "priority", "1");
11010
11011 val = get_param(cmd, "REALM");
11012 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11014 "realm");
11015 return 0;
11016 }
11017
11018 val = get_param(cmd, "HOME_FQDN");
11019 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11020 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11021 "home_fqdn");
11022 return 0;
11023 }
11024
11025 val = get_param(cmd, "Username");
11026 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11027 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11028 "username");
11029 return 0;
11030 }
11031
11032 val = get_param(cmd, "clientCertificate");
11033 if (val) {
11034 char fname[200];
11035 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11036#ifdef __linux__
11037 if (!file_exists(fname)) {
11038 char msg[300];
11039 snprintf(msg, sizeof(msg),
11040 "ErrorCode,clientCertificate "
11041 "file (%s) not found", fname);
11042 send_resp(dut, conn, SIGMA_ERROR, msg);
11043 return 0;
11044 }
11045#endif /* __linux__ */
11046 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
11047 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11048 "not set client_cert");
11049 return 0;
11050 }
11051 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
11052 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11053 "not set private_key");
11054 return 0;
11055 }
11056 }
11057
11058 val = get_param(cmd, "ROOT_CA");
11059 if (val) {
11060 char fname[200];
11061 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11062#ifdef __linux__
11063 if (!file_exists(fname)) {
11064 char msg[300];
11065 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11066 "file (%s) not found", fname);
11067 send_resp(dut, conn, SIGMA_ERROR, msg);
11068 return 0;
11069 }
11070#endif /* __linux__ */
11071 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11072 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11073 "not set root CA");
11074 return 0;
11075 }
11076 }
11077
11078 return 1;
11079}
11080
11081
11082static int cmd_sta_add_credential(struct sigma_dut *dut,
11083 struct sigma_conn *conn,
11084 struct sigma_cmd *cmd)
11085{
11086 const char *intf = get_param(cmd, "Interface");
11087 const char *type;
11088
11089 start_sta_mode(dut);
11090
11091 type = get_param(cmd, "Type");
11092 if (!type)
11093 return -1;
11094
11095 if (strcasecmp(type, "uname_pwd") == 0)
11096 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
11097
11098 if (strcasecmp(type, "sim") == 0)
11099 return sta_add_credential_sim(dut, conn, intf, cmd);
11100
11101 if (strcasecmp(type, "cert") == 0)
11102 return sta_add_credential_cert(dut, conn, intf, cmd);
11103
11104 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
11105 "type");
11106 return 0;
11107}
11108
11109
11110static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
11111 struct sigma_cmd *cmd)
11112{
11113 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053011114 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011115 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053011116 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011117 int res;
11118
11119 val = get_param(cmd, "HESSID");
11120 if (val) {
11121 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
11122 if (res < 0 || res >= (int) sizeof(buf))
11123 return -1;
11124 wpa_command(intf, buf);
11125 }
11126
11127 val = get_param(cmd, "ACCS_NET_TYPE");
11128 if (val) {
11129 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
11130 val);
11131 if (res < 0 || res >= (int) sizeof(buf))
11132 return -1;
11133 wpa_command(intf, buf);
11134 }
11135
vamsi krishna89ad8c62017-09-19 12:51:18 +053011136 bssid = get_param(cmd, "Bssid");
11137 ssid = get_param(cmd, "Ssid");
11138
11139 if (ssid) {
11140 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
11141 send_resp(dut, conn, SIGMA_ERROR,
11142 "ErrorCode,Too long SSID");
11143 return 0;
11144 }
11145 ascii2hexstr(ssid, ssid_hex);
11146 }
11147
11148 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
11149 bssid ? " bssid=": "",
11150 bssid ? bssid : "",
11151 ssid ? " ssid " : "",
11152 ssid ? ssid_hex : "");
11153 if (res < 0 || res >= (int) sizeof(buf))
11154 return -1;
11155
11156 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011157 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
11158 "scan");
11159 return 0;
11160 }
11161
11162 return 1;
11163}
11164
11165
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011166static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
11167 struct sigma_cmd *cmd)
11168{
11169 const char *intf = get_param(cmd, "Interface");
11170 const char *bssid;
11171 char buf[4096], *pos;
11172 int freq, chan;
11173 char *ssid;
11174 char resp[100];
11175 int res;
11176 struct wpa_ctrl *ctrl;
11177
11178 bssid = get_param(cmd, "BSSID");
11179 if (!bssid) {
11180 send_resp(dut, conn, SIGMA_INVALID,
11181 "errorCode,BSSID argument is missing");
11182 return 0;
11183 }
11184
11185 ctrl = open_wpa_mon(intf);
11186 if (!ctrl) {
11187 sigma_dut_print(dut, DUT_MSG_ERROR,
11188 "Failed to open wpa_supplicant monitor connection");
11189 return -1;
11190 }
11191
11192 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
11193 send_resp(dut, conn, SIGMA_ERROR,
11194 "errorCode,Could not start scan");
11195 wpa_ctrl_detach(ctrl);
11196 wpa_ctrl_close(ctrl);
11197 return 0;
11198 }
11199
11200 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11201 buf, sizeof(buf));
11202
11203 wpa_ctrl_detach(ctrl);
11204 wpa_ctrl_close(ctrl);
11205
11206 if (res < 0) {
11207 send_resp(dut, conn, SIGMA_ERROR,
11208 "errorCode,Scan did not complete");
11209 return 0;
11210 }
11211
11212 snprintf(buf, sizeof(buf), "BSS %s", bssid);
11213 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
11214 strncmp(buf, "id=", 3) != 0) {
11215 send_resp(dut, conn, SIGMA_ERROR,
11216 "errorCode,Specified BSSID not found");
11217 return 0;
11218 }
11219
11220 pos = strstr(buf, "\nfreq=");
11221 if (!pos) {
11222 send_resp(dut, conn, SIGMA_ERROR,
11223 "errorCode,Channel not found");
11224 return 0;
11225 }
11226 freq = atoi(pos + 6);
11227 chan = freq_to_channel(freq);
11228
11229 pos = strstr(buf, "\nssid=");
11230 if (!pos) {
11231 send_resp(dut, conn, SIGMA_ERROR,
11232 "errorCode,SSID not found");
11233 return 0;
11234 }
11235 ssid = pos + 6;
11236 pos = strchr(ssid, '\n');
11237 if (pos)
11238 *pos = '\0';
11239 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
11240 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11241 return 0;
11242}
11243
11244
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011245static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
11246 struct sigma_cmd *cmd)
11247{
11248#ifdef __linux__
11249 struct timeval tv;
11250 struct tm tm;
11251 time_t t;
11252 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011253 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011254
11255 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
11256
11257 memset(&tm, 0, sizeof(tm));
11258 val = get_param(cmd, "seconds");
11259 if (val)
11260 tm.tm_sec = atoi(val);
11261 val = get_param(cmd, "minutes");
11262 if (val)
11263 tm.tm_min = atoi(val);
11264 val = get_param(cmd, "hours");
11265 if (val)
11266 tm.tm_hour = atoi(val);
11267 val = get_param(cmd, "date");
11268 if (val)
11269 tm.tm_mday = atoi(val);
11270 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011271 if (val) {
11272 v = atoi(val);
11273 if (v < 1 || v > 12) {
11274 send_resp(dut, conn, SIGMA_INVALID,
11275 "errorCode,Invalid month");
11276 return 0;
11277 }
11278 tm.tm_mon = v - 1;
11279 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011280 val = get_param(cmd, "year");
11281 if (val) {
11282 int year = atoi(val);
11283#ifdef ANDROID
11284 if (year > 2035)
11285 year = 2035; /* years beyond 2035 not supported */
11286#endif /* ANDROID */
11287 tm.tm_year = year - 1900;
11288 }
11289 t = mktime(&tm);
11290 if (t == (time_t) -1) {
11291 send_resp(dut, conn, SIGMA_ERROR,
11292 "errorCode,Invalid date or time");
11293 return 0;
11294 }
11295
11296 memset(&tv, 0, sizeof(tv));
11297 tv.tv_sec = t;
11298
11299 if (settimeofday(&tv, NULL) < 0) {
11300 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
11301 strerror(errno));
11302 send_resp(dut, conn, SIGMA_ERROR,
11303 "errorCode,Failed to set time");
11304 return 0;
11305 }
11306
11307 return 1;
11308#endif /* __linux__ */
11309
11310 return -1;
11311}
11312
11313
11314static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
11315 struct sigma_cmd *cmd)
11316{
11317 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011318 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011319 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011320 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011321 int res;
11322 struct wpa_ctrl *ctrl;
11323
11324 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011325 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011326
11327 val = get_param(cmd, "ProdESSAssoc");
11328 if (val)
11329 prod_ess_assoc = atoi(val);
11330
11331 kill_dhcp_client(dut, intf);
11332 if (start_dhcp_client(dut, intf) < 0)
11333 return -2;
11334
11335 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11336 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11337 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011338 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011339 prod_ess_assoc ? "" : "-N",
11340 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011341 name ? "'" : "",
11342 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11343 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011344
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011345 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011346 if (run_hs20_osu(dut, buf) < 0) {
11347 FILE *f;
11348
11349 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11350
11351 f = fopen("hs20-osu-client.res", "r");
11352 if (f) {
11353 char resp[400], res[300], *pos;
11354 if (!fgets(res, sizeof(res), f))
11355 res[0] = '\0';
11356 pos = strchr(res, '\n');
11357 if (pos)
11358 *pos = '\0';
11359 fclose(f);
11360 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11361 res);
11362 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11363 if (system(resp) != 0) {
11364 }
11365 snprintf(resp, sizeof(resp),
11366 "SSID,,BSSID,,failureReason,%s", res);
11367 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11368 return 0;
11369 }
11370
11371 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11372 return 0;
11373 }
11374
11375 if (!prod_ess_assoc)
11376 goto report;
11377
11378 ctrl = open_wpa_mon(intf);
11379 if (ctrl == NULL) {
11380 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11381 "wpa_supplicant monitor connection");
11382 return -1;
11383 }
11384
11385 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11386 buf, sizeof(buf));
11387
11388 wpa_ctrl_detach(ctrl);
11389 wpa_ctrl_close(ctrl);
11390
11391 if (res < 0) {
11392 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11393 "network after OSU");
11394 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11395 return 0;
11396 }
11397
11398report:
11399 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11400 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11401 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11402 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11403 return 0;
11404 }
11405
11406 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11407 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011408 return 0;
11409}
11410
11411
11412static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11413 struct sigma_cmd *cmd)
11414{
11415 const char *val;
11416 int timeout = 120;
11417
11418 val = get_param(cmd, "PolicyUpdate");
11419 if (val == NULL || atoi(val) == 0)
11420 return 1; /* No operation requested */
11421
11422 val = get_param(cmd, "Timeout");
11423 if (val)
11424 timeout = atoi(val);
11425
11426 if (timeout) {
11427 /* TODO: time out the command and return
11428 * PolicyUpdateStatus,TIMEOUT if needed. */
11429 }
11430
11431 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11432 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11433 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11434 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11435 return 0;
11436 }
11437
11438 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11439 return 0;
11440}
11441
11442
11443static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11444 struct sigma_cmd *cmd)
11445{
11446 struct wpa_ctrl *ctrl;
11447 const char *intf = get_param(cmd, "Interface");
11448 const char *bssid = get_param(cmd, "Bssid");
11449 const char *ssid = get_param(cmd, "SSID");
11450 const char *security = get_param(cmd, "Security");
11451 const char *passphrase = get_param(cmd, "Passphrase");
11452 const char *pin = get_param(cmd, "PIN");
11453 char buf[1000];
11454 char ssid_hex[200], passphrase_hex[200];
11455 const char *keymgmt, *cipher;
11456
11457 if (intf == NULL)
11458 intf = get_main_ifname();
11459
11460 if (!bssid) {
11461 send_resp(dut, conn, SIGMA_ERROR,
11462 "ErrorCode,Missing Bssid argument");
11463 return 0;
11464 }
11465
11466 if (!ssid) {
11467 send_resp(dut, conn, SIGMA_ERROR,
11468 "ErrorCode,Missing SSID argument");
11469 return 0;
11470 }
11471
11472 if (!security) {
11473 send_resp(dut, conn, SIGMA_ERROR,
11474 "ErrorCode,Missing Security argument");
11475 return 0;
11476 }
11477
11478 if (!passphrase) {
11479 send_resp(dut, conn, SIGMA_ERROR,
11480 "ErrorCode,Missing Passphrase argument");
11481 return 0;
11482 }
11483
11484 if (!pin) {
11485 send_resp(dut, conn, SIGMA_ERROR,
11486 "ErrorCode,Missing PIN argument");
11487 return 0;
11488 }
11489
vamsi krishna8c9c1562017-05-12 15:51:46 +053011490 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11491 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011492 send_resp(dut, conn, SIGMA_ERROR,
11493 "ErrorCode,Too long SSID/passphrase");
11494 return 0;
11495 }
11496
11497 ctrl = open_wpa_mon(intf);
11498 if (ctrl == NULL) {
11499 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11500 "wpa_supplicant monitor connection");
11501 return -2;
11502 }
11503
11504 if (strcasecmp(security, "wpa2-psk") == 0) {
11505 keymgmt = "WPA2PSK";
11506 cipher = "CCMP";
11507 } else {
11508 wpa_ctrl_detach(ctrl);
11509 wpa_ctrl_close(ctrl);
11510 send_resp(dut, conn, SIGMA_ERROR,
11511 "ErrorCode,Unsupported Security value");
11512 return 0;
11513 }
11514
11515 ascii2hexstr(ssid, ssid_hex);
11516 ascii2hexstr(passphrase, passphrase_hex);
11517 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11518 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11519
11520 if (wpa_command(intf, buf) < 0) {
11521 wpa_ctrl_detach(ctrl);
11522 wpa_ctrl_close(ctrl);
11523 send_resp(dut, conn, SIGMA_ERROR,
11524 "ErrorCode,Failed to start registrar");
11525 return 0;
11526 }
11527
11528 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11529 dut->er_oper_performed = 1;
11530
11531 return wps_connection_event(dut, conn, ctrl, intf, 0);
11532}
11533
11534
11535static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11536 struct sigma_conn *conn,
11537 struct sigma_cmd *cmd)
11538{
11539 struct wpa_ctrl *ctrl;
11540 const char *intf = get_param(cmd, "Interface");
11541 const char *bssid = get_param(cmd, "Bssid");
11542 char buf[100];
11543
11544 if (!bssid) {
11545 send_resp(dut, conn, SIGMA_ERROR,
11546 "ErrorCode,Missing Bssid argument");
11547 return 0;
11548 }
11549
11550 ctrl = open_wpa_mon(intf);
11551 if (ctrl == NULL) {
11552 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11553 "wpa_supplicant monitor connection");
11554 return -2;
11555 }
11556
11557 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11558
11559 if (wpa_command(intf, buf) < 0) {
11560 wpa_ctrl_detach(ctrl);
11561 wpa_ctrl_close(ctrl);
11562 send_resp(dut, conn, SIGMA_ERROR,
11563 "ErrorCode,Failed to start registrar");
11564 return 0;
11565 }
11566
11567 return wps_connection_event(dut, conn, ctrl, intf, 0);
11568}
11569
11570
vamsi krishna9b144002017-09-20 13:28:13 +053011571static int cmd_start_wps_registration(struct sigma_dut *dut,
11572 struct sigma_conn *conn,
11573 struct sigma_cmd *cmd)
11574{
11575 struct wpa_ctrl *ctrl;
11576 const char *intf = get_param(cmd, "Interface");
11577 const char *role, *method;
11578 int res;
11579 char buf[256];
11580 const char *events[] = {
11581 "CTRL-EVENT-CONNECTED",
11582 "WPS-OVERLAP-DETECTED",
11583 "WPS-TIMEOUT",
11584 "WPS-FAIL",
11585 NULL
11586 };
11587
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020011588 /* 60G WPS tests do not pass Interface parameter */
11589 if (!intf)
11590 intf = get_main_ifname();
11591
vamsi krishna9b144002017-09-20 13:28:13 +053011592 ctrl = open_wpa_mon(intf);
11593 if (!ctrl) {
11594 sigma_dut_print(dut, DUT_MSG_ERROR,
11595 "Failed to open wpa_supplicant monitor connection");
11596 return -2;
11597 }
11598
11599 role = get_param(cmd, "WpsRole");
11600 if (!role) {
11601 send_resp(dut, conn, SIGMA_INVALID,
11602 "ErrorCode,WpsRole not provided");
11603 goto fail;
11604 }
11605
11606 if (strcasecmp(role, "Enrollee") == 0) {
11607 method = get_param(cmd, "WpsConfigMethod");
11608 if (!method) {
11609 send_resp(dut, conn, SIGMA_INVALID,
11610 "ErrorCode,WpsConfigMethod not provided");
11611 goto fail;
11612 }
11613 if (strcasecmp(method, "PBC") == 0) {
11614 if (wpa_command(intf, "WPS_PBC") < 0) {
11615 send_resp(dut, conn, SIGMA_ERROR,
11616 "ErrorCode,Failed to enable PBC");
11617 goto fail;
11618 }
11619 } else {
11620 /* TODO: PIN method */
11621 send_resp(dut, conn, SIGMA_ERROR,
11622 "ErrorCode,Unsupported WpsConfigMethod value");
11623 goto fail;
11624 }
11625 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11626 if (res < 0) {
11627 send_resp(dut, conn, SIGMA_ERROR,
11628 "ErrorCode,WPS connection did not complete");
11629 goto fail;
11630 }
11631 if (strstr(buf, "WPS-TIMEOUT")) {
11632 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
11633 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
11634 send_resp(dut, conn, SIGMA_ERROR,
11635 "ErrorCode,OverlapSession");
11636 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
11637 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
11638 } else {
11639 send_resp(dut, conn, SIGMA_ERROR,
11640 "ErrorCode,WPS operation failed");
11641 }
11642 } else {
11643 /* TODO: Registrar role */
11644 send_resp(dut, conn, SIGMA_ERROR,
11645 "ErrorCode,Unsupported WpsRole value");
11646 }
11647
11648fail:
11649 wpa_ctrl_detach(ctrl);
11650 wpa_ctrl_close(ctrl);
11651 return 0;
11652}
11653
11654
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011655static int req_intf(struct sigma_cmd *cmd)
11656{
11657 return get_param(cmd, "interface") == NULL ? -1 : 0;
11658}
11659
11660
11661void sta_register_cmds(void)
11662{
11663 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
11664 cmd_sta_get_ip_config);
11665 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
11666 cmd_sta_set_ip_config);
11667 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
11668 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
11669 cmd_sta_get_mac_address);
11670 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
11671 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
11672 cmd_sta_verify_ip_connection);
11673 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
11674 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
11675 cmd_sta_set_encryption);
11676 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
11677 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
11678 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
11679 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
11680 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
11681 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
11682 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
11683 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
11684 cmd_sta_set_eapakaprime);
11685 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
11686 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
11687 /* TODO: sta_set_ibss */
11688 /* TODO: sta_set_mode */
11689 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
11690 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
11691 /* TODO: sta_up_load */
11692 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
11693 cmd_sta_preset_testparameters);
11694 /* TODO: sta_set_system */
11695 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
11696 /* TODO: sta_set_rifs_test */
11697 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
11698 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
11699 /* TODO: sta_send_coexist_mgmt */
11700 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
11701 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
11702 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
11703 sigma_dut_reg_cmd("sta_reset_default", req_intf,
11704 cmd_sta_reset_default);
11705 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
11706 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
11707 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
11708 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
11709 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
11710 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
11711 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
11712 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
11713 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
11714 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011715 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
11716 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011717 sigma_dut_reg_cmd("sta_add_credential", req_intf,
11718 cmd_sta_add_credential);
11719 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011720 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011721 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
11722 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
11723 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
11724 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
11725 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
11726 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030011727 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011728 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
11729 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020011730 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053011731 cmd_start_wps_registration);
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011732 sigma_dut_reg_cmd("sta_set_power_save", req_intf,
11733 cmd_sta_set_power_save);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011734}