blob: 2ba0be4aadfb762127176b0f27c85d2170e45d5e [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
6703 if (dut->program == PROGRAM_60GHZ) {
6704 const char *dev_role = get_param(cmd, "DevRole");
6705
6706 if (!dev_role) {
6707 send_resp(dut, conn, SIGMA_ERROR,
6708 "errorCode,Missing DevRole argument");
6709 return 0;
6710 }
6711
6712 if (strcasecmp(dev_role, "STA") == 0)
6713 dut->dev_role = DEVROLE_STA;
6714 else if (strcasecmp(dev_role, "PCP") == 0)
6715 dut->dev_role = DEVROLE_PCP;
6716 else {
6717 send_resp(dut, conn, SIGMA_ERROR,
6718 "errorCode,Unknown DevRole");
6719 return 0;
6720 }
6721
6722 if (dut->device_type == STA_unknown) {
6723 sigma_dut_print(dut, DUT_MSG_ERROR,
6724 "Device type is not STA testbed or DUT");
6725 send_resp(dut, conn, SIGMA_ERROR,
6726 "errorCode,Unknown device type");
6727 return 0;
6728 }
6729 }
6730
6731 wpa_command(intf, "WPS_ER_STOP");
6732 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05306733 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006734 wpa_command(intf, "SET radio_disabled 0");
6735
6736 if (dut->tmp_mac_addr && dut->set_macaddr) {
6737 dut->tmp_mac_addr = 0;
6738 if (system(dut->set_macaddr) != 0) {
6739 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
6740 "temporary MAC address");
6741 }
6742 }
6743
6744 set_ps(intf, dut, 0);
6745
Jouni Malinenba630452018-06-22 11:49:59 +03006746 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6747 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006748 wpa_command(intf, "SET interworking 1");
6749 wpa_command(intf, "SET hs20 1");
6750 }
6751
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006752 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03006753 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006754 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006755 wpa_command(intf, "SET pmf 1");
6756 } else {
6757 wpa_command(intf, "SET pmf 0");
6758 }
6759
6760 hs2_clear_credentials(intf);
6761 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6762 wpa_command(intf, "SET access_network_type 15");
6763
6764 static_ip_file(0, NULL, NULL, NULL);
6765 kill_dhcp_client(dut, intf);
6766 clear_ip_addr(dut, intf);
6767
6768 dut->er_oper_performed = 0;
6769 dut->er_oper_bssid[0] = '\0';
6770
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006771 if (dut->program == PROGRAM_LOC) {
6772 /* Disable Interworking by default */
6773 wpa_command(get_station_ifname(), "SET interworking 0");
6774 }
6775
Ashwini Patil00402582017-04-13 12:29:39 +05306776 if (dut->program == PROGRAM_MBO) {
6777 free(dut->non_pref_ch_list);
6778 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306779 free(dut->btm_query_cand_list);
6780 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306781 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306782 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306783 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306784 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05306785 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306786 }
6787
Jouni Malinen3c367e82017-06-23 17:01:47 +03006788 free(dut->rsne_override);
6789 dut->rsne_override = NULL;
6790
Jouni Malinen68143132017-09-02 02:34:08 +03006791 free(dut->sae_commit_override);
6792 dut->sae_commit_override = NULL;
6793
Jouni Malinend86e5822017-08-29 03:55:32 +03006794 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006795 free(dut->dpp_peer_uri);
6796 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006797 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006798 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006799
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006800 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6801
vamsi krishnaa2799492017-12-05 14:28:01 +05306802 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306803 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306804 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306805 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6806 dut->fils_hlp = 0;
6807#ifdef ANDROID
6808 hlp_thread_cleanup(dut);
6809#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306810 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306811
Sunil Dutt076081f2018-02-05 19:45:50 +05306812#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306813 if (get_driver_type() == DRIVER_WCN &&
6814 dut->config_rsnie == 1) {
6815 dut->config_rsnie = 0;
6816 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306817 }
6818#endif /* NL80211_SUPPORT */
6819
Sunil Duttfebf8a82018-02-09 18:50:13 +05306820 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6821 dut->dev_role = DEVROLE_STA_CFON;
6822 return sta_cfon_reset_default(dut, conn, cmd);
6823 }
6824
Jouni Malinen439352d2018-09-13 03:42:23 +03006825 wpa_command(intf, "SET setband AUTO");
6826
Sunil Duttfebf8a82018-02-09 18:50:13 +05306827 if (dut->program != PROGRAM_VHT)
6828 return cmd_sta_p2p_reset(dut, conn, cmd);
6829
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006830 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006831}
6832
6833
6834static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6835 struct sigma_cmd *cmd)
6836{
6837 const char *program = get_param(cmd, "Program");
6838
6839 if (program == NULL)
6840 return -1;
6841#ifdef ANDROID_NAN
6842 if (strcasecmp(program, "NAN") == 0)
6843 return nan_cmd_sta_get_events(dut, conn, cmd);
6844#endif /* ANDROID_NAN */
6845 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6846 return 0;
6847}
6848
6849
Jouni Malinen82905202018-04-29 17:20:10 +03006850static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6851 struct sigma_cmd *cmd)
6852{
6853 const char *url = get_param(cmd, "url");
6854 const char *method = get_param(cmd, "method");
6855 pid_t pid;
6856 int status;
6857
6858 if (!url || !method)
6859 return -1;
6860
6861 /* TODO: Add support for method,post */
6862 if (strcasecmp(method, "get") != 0) {
6863 send_resp(dut, conn, SIGMA_ERROR,
6864 "ErrorCode,Unsupported method");
6865 return 0;
6866 }
6867
6868 pid = fork();
6869 if (pid < 0) {
6870 perror("fork");
6871 return -1;
6872 }
6873
6874 if (pid == 0) {
6875 char * argv[5] = { "wget", "-O", "/dev/null",
6876 (char *) url, NULL };
6877
6878 execv("/usr/bin/wget", argv);
6879 perror("execv");
6880 exit(0);
6881 return -1;
6882 }
6883
6884 if (waitpid(pid, &status, 0) < 0) {
6885 perror("waitpid");
6886 return -1;
6887 }
6888
6889 if (WIFEXITED(status)) {
6890 const char *errmsg;
6891
6892 if (WEXITSTATUS(status) == 0)
6893 return 1;
6894 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6895 WEXITSTATUS(status));
6896 switch (WEXITSTATUS(status)) {
6897 case 4:
6898 errmsg = "errmsg,Network failure";
6899 break;
6900 case 8:
6901 errmsg = "errmsg,Server issued an error response";
6902 break;
6903 default:
6904 errmsg = "errmsg,Unknown failure from wget";
6905 break;
6906 }
6907 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6908 return 0;
6909 }
6910
6911 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6912 return 0;
6913}
6914
6915
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006916static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6917 struct sigma_cmd *cmd)
6918{
6919 const char *program = get_param(cmd, "Prog");
6920
Jouni Malinen82905202018-04-29 17:20:10 +03006921 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006922 return -1;
6923#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006924 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006925 return nan_cmd_sta_exec_action(dut, conn, cmd);
6926#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006927
6928 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006929 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006930
6931 if (get_param(cmd, "url"))
6932 return sta_exec_action_url(dut, conn, cmd);
6933
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006934 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6935 return 0;
6936}
6937
6938
6939static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6940 struct sigma_cmd *cmd)
6941{
6942 const char *intf = get_param(cmd, "Interface");
6943 const char *val, *mcs32, *rate;
6944
6945 val = get_param(cmd, "GREENFIELD");
6946 if (val) {
6947 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6948 /* Enable GD */
6949 send_resp(dut, conn, SIGMA_ERROR,
6950 "ErrorCode,GF not supported");
6951 return 0;
6952 }
6953 }
6954
6955 val = get_param(cmd, "SGI20");
6956 if (val) {
6957 switch (get_driver_type()) {
6958 case DRIVER_ATHEROS:
6959 ath_sta_set_sgi(dut, intf, val);
6960 break;
6961 default:
6962 send_resp(dut, conn, SIGMA_ERROR,
6963 "ErrorCode,SGI20 not supported");
6964 return 0;
6965 }
6966 }
6967
6968 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6969 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6970 if (mcs32 && rate) {
6971 /* TODO */
6972 send_resp(dut, conn, SIGMA_ERROR,
6973 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6974 return 0;
6975 } else if (mcs32 && !rate) {
6976 /* TODO */
6977 send_resp(dut, conn, SIGMA_ERROR,
6978 "ErrorCode,MCS32 not supported");
6979 return 0;
6980 } else if (!mcs32 && rate) {
6981 switch (get_driver_type()) {
6982 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006983 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006984 ath_sta_set_11nrates(dut, intf, rate);
6985 break;
6986 default:
6987 send_resp(dut, conn, SIGMA_ERROR,
6988 "ErrorCode,MCS32_FIXEDRATE not supported");
6989 return 0;
6990 }
6991 }
6992
6993 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6994}
6995
6996
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006997static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
6998 int mcs_config)
6999{
7000#ifdef NL80211_SUPPORT
7001 int ret;
7002
7003 switch (mcs_config) {
7004 case HE_80_MCS0_7:
7005 case HE_80_MCS0_9:
7006 case HE_80_MCS0_11:
7007 ret = sta_set_he_mcs(dut, intf, mcs_config);
7008 if (ret) {
7009 sigma_dut_print(dut, DUT_MSG_ERROR,
7010 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7011 mcs_config, ret);
7012 }
7013 break;
7014 default:
7015 sigma_dut_print(dut, DUT_MSG_ERROR,
7016 "cmd_set_max_he_mcs: Invalid mcs %d",
7017 mcs_config);
7018 break;
7019 }
7020#else /* NL80211_SUPPORT */
7021 sigma_dut_print(dut, DUT_MSG_ERROR,
7022 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7023#endif /* NL80211_SUPPORT */
7024}
7025
7026
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007027static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
7028 struct sigma_conn *conn,
7029 struct sigma_cmd *cmd)
7030{
7031 const char *intf = get_param(cmd, "Interface");
7032 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07007033 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07007034 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007035 int tkip = -1;
7036 int wep = -1;
7037
Arif Hussaina37e9552018-06-20 17:05:59 -07007038 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007039 val = get_param(cmd, "SGI80");
7040 if (val) {
7041 int sgi80;
7042
7043 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7044 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
7045 if (system(buf) != 0) {
7046 sigma_dut_print(dut, DUT_MSG_ERROR,
7047 "iwpriv shortgi failed");
7048 }
7049 }
7050
7051 val = get_param(cmd, "TxBF");
7052 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007053 switch (get_driver_type()) {
7054 case DRIVER_WCN:
7055 if (sta_set_tx_beamformee(dut, intf, 1)) {
7056 send_resp(dut, conn, SIGMA_ERROR,
7057 "ErrorCode,Failed to set TX beamformee enable");
7058 return 0;
7059 }
7060 break;
7061 case DRIVER_ATHEROS:
7062 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
7063 intf);
7064 if (system(buf) != 0) {
7065 send_resp(dut, conn, SIGMA_ERROR,
7066 "ErrorCode,Setting vhtsubfee failed");
7067 return 0;
7068 }
7069
7070 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
7071 intf);
7072 if (system(buf) != 0) {
7073 send_resp(dut, conn, SIGMA_ERROR,
7074 "ErrorCode,Setting vhtsubfer failed");
7075 return 0;
7076 }
7077 break;
7078 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007079 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007080 "Unsupported driver type");
7081 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007082 }
7083 }
7084
7085 val = get_param(cmd, "MU_TxBF");
7086 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
7087 switch (get_driver_type()) {
7088 case DRIVER_ATHEROS:
7089 ath_sta_set_txsp_stream(dut, intf, "1SS");
7090 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05307091 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
7092 intf);
7093 if (system(buf) != 0) {
7094 sigma_dut_print(dut, DUT_MSG_ERROR,
7095 "iwpriv vhtmubfee failed");
7096 }
7097 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
7098 intf);
7099 if (system(buf) != 0) {
7100 sigma_dut_print(dut, DUT_MSG_ERROR,
7101 "iwpriv vhtmubfer failed");
7102 }
7103 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007104 case DRIVER_WCN:
7105 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
7106 send_resp(dut, conn, SIGMA_ERROR,
7107 "ErrorCode,Failed to set RX/TXSP_STREAM");
7108 return 0;
7109 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05307110 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007111 default:
7112 sigma_dut_print(dut, DUT_MSG_ERROR,
7113 "Setting SP_STREAM not supported");
7114 break;
7115 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007116 }
7117
7118 val = get_param(cmd, "LDPC");
7119 if (val) {
7120 int ldpc;
7121
7122 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7123 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
7124 if (system(buf) != 0) {
7125 sigma_dut_print(dut, DUT_MSG_ERROR,
7126 "iwpriv ldpc failed");
7127 }
7128 }
7129
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08007130 val = get_param(cmd, "BCC");
7131 if (val) {
7132 int bcc;
7133
7134 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7135 /* use LDPC iwpriv itself to set bcc coding, bcc coding
7136 * is mutually exclusive to bcc */
7137 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
7138 if (system(buf) != 0) {
7139 sigma_dut_print(dut, DUT_MSG_ERROR,
7140 "Enabling/Disabling of BCC failed");
7141 }
7142 }
7143
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007144 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
7145 if (val && dut->sta_nss == 1)
7146 cmd_set_max_he_mcs(dut, intf, atoi(val));
7147
7148 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
7149 if (val && dut->sta_nss == 2)
7150 cmd_set_max_he_mcs(dut, intf, atoi(val));
7151
Arif Hussainac6c5112018-05-25 17:34:00 -07007152 val = get_param(cmd, "MCS_FixedRate");
7153 if (val) {
7154#ifdef NL80211_SUPPORT
7155 int mcs, ratecode = 0;
7156 enum he_mcs_config mcs_config;
7157 int ret;
7158
7159 ratecode = (0x07 & dut->sta_nss) << 5;
7160 mcs = atoi(val);
7161 /* Add the MCS to the ratecode */
7162 if (mcs >= 0 && mcs <= 11) {
7163 ratecode += mcs;
7164 if (dut->device_type == STA_testbed &&
7165 mcs > 7 && mcs <= 11) {
7166 if (mcs <= 9)
7167 mcs_config = HE_80_MCS0_9;
7168 else
7169 mcs_config = HE_80_MCS0_11;
7170 ret = sta_set_he_mcs(dut, intf, mcs_config);
7171 if (ret) {
7172 sigma_dut_print(dut, DUT_MSG_ERROR,
7173 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
7174 mcs, mcs_config, ret);
7175 }
7176 }
7177 snprintf(buf, sizeof(buf),
7178 "iwpriv %s set_11ax_rate 0x%03x",
7179 intf, ratecode);
7180 if (system(buf) != 0) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
7183 ratecode);
7184 }
7185 } else {
7186 sigma_dut_print(dut, DUT_MSG_ERROR,
7187 "MCS_FixedRate: HE MCS %d not supported",
7188 mcs);
7189 }
7190#else /* NL80211_SUPPORT */
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
7193#endif /* NL80211_SUPPORT */
7194 }
7195
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007196 val = get_param(cmd, "opt_md_notif_ie");
7197 if (val) {
7198 char *result = NULL;
7199 char delim[] = ";";
7200 char token[30];
7201 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307202 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007203
Peng Xub8fc5cc2017-05-10 17:27:28 -07007204 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307205 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007206
7207 /* Extract the NSS information */
7208 if (result) {
7209 value = atoi(result);
7210 switch (value) {
7211 case 1:
7212 config_val = 1;
7213 break;
7214 case 2:
7215 config_val = 3;
7216 break;
7217 case 3:
7218 config_val = 7;
7219 break;
7220 case 4:
7221 config_val = 15;
7222 break;
7223 default:
7224 config_val = 3;
7225 break;
7226 }
7227
7228 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7229 intf, config_val);
7230 if (system(buf) != 0) {
7231 sigma_dut_print(dut, DUT_MSG_ERROR,
7232 "iwpriv rxchainmask failed");
7233 }
7234
7235 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
7236 intf, config_val);
7237 if (system(buf) != 0) {
7238 sigma_dut_print(dut, DUT_MSG_ERROR,
7239 "iwpriv txchainmask failed");
7240 }
7241 }
7242
7243 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307244 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007245 if (result) {
7246 value = atoi(result);
7247 switch (value) {
7248 case 20:
7249 config_val = 0;
7250 break;
7251 case 40:
7252 config_val = 1;
7253 break;
7254 case 80:
7255 config_val = 2;
7256 break;
7257 case 160:
7258 config_val = 3;
7259 break;
7260 default:
7261 config_val = 2;
7262 break;
7263 }
7264
7265 dut->chwidth = config_val;
7266
7267 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7268 intf, config_val);
7269 if (system(buf) != 0) {
7270 sigma_dut_print(dut, DUT_MSG_ERROR,
7271 "iwpriv chwidth failed");
7272 }
7273 }
7274
7275 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
7276 if (system(buf) != 0) {
7277 sigma_dut_print(dut, DUT_MSG_ERROR,
7278 "iwpriv opmode_notify failed");
7279 }
7280 }
7281
7282 val = get_param(cmd, "nss_mcs_cap");
7283 if (val) {
7284 int nss, mcs;
7285 char token[20];
7286 char *result = NULL;
7287 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307288 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007289
Peng Xub8fc5cc2017-05-10 17:27:28 -07007290 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307291 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307292 if (!result) {
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007294 "NSS not specified");
7295 send_resp(dut, conn, SIGMA_ERROR,
7296 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307297 return 0;
7298 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007299 nss = atoi(result);
7300
7301 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
7302 if (system(buf) != 0) {
7303 sigma_dut_print(dut, DUT_MSG_ERROR,
7304 "iwpriv nss failed");
7305 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007306 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007307
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307308 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007309 if (result == NULL) {
7310 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007311 "MCS not specified");
7312 send_resp(dut, conn, SIGMA_ERROR,
7313 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007314 return 0;
7315 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307316 result = strtok_r(result, "-", &saveptr);
7317 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307318 if (!result) {
7319 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007320 "MCS not specified");
7321 send_resp(dut, conn, SIGMA_ERROR,
7322 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307323 return 0;
7324 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007325 mcs = atoi(result);
7326
Arif Hussaina37e9552018-06-20 17:05:59 -07007327 if (program && strcasecmp(program, "HE") == 0) {
7328#ifdef NL80211_SUPPORT
7329 enum he_mcs_config mcs_config;
7330 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007331
Arif Hussaina37e9552018-06-20 17:05:59 -07007332 if (mcs >= 0 && mcs <= 7) {
7333 mcs_config = HE_80_MCS0_7;
7334 } else if (mcs > 7 && mcs <= 9) {
7335 mcs_config = HE_80_MCS0_9;
7336 } else if (mcs > 9 && mcs <= 11) {
7337 mcs_config = HE_80_MCS0_11;
7338 } else {
7339 sigma_dut_print(dut, DUT_MSG_ERROR,
7340 "nss_mcs_cap: HE: Invalid mcs: %d",
7341 mcs);
7342 send_resp(dut, conn, SIGMA_ERROR,
7343 "errorCode,Invalid MCS");
7344 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007345 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007346
7347 ret = sta_set_he_mcs(dut, intf, mcs_config);
7348 if (ret) {
7349 sigma_dut_print(dut, DUT_MSG_ERROR,
7350 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
7351 mcs_config, ret);
7352 send_resp(dut, conn, SIGMA_ERROR,
7353 "errorCode,Failed to set MCS");
7354 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007355 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007356#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007357 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007358 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
7359#endif /* NL80211_SUPPORT */
7360 } else {
7361 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7362 intf, mcs);
7363 if (system(buf) != 0) {
7364 sigma_dut_print(dut, DUT_MSG_ERROR,
7365 "iwpriv mcs failed");
7366 }
7367
7368 switch (nss) {
7369 case 1:
7370 switch (mcs) {
7371 case 7:
7372 vht_mcsmap = 0xfffc;
7373 break;
7374 case 8:
7375 vht_mcsmap = 0xfffd;
7376 break;
7377 case 9:
7378 vht_mcsmap = 0xfffe;
7379 break;
7380 default:
7381 vht_mcsmap = 0xfffe;
7382 break;
7383 }
7384 break;
7385 case 2:
7386 switch (mcs) {
7387 case 7:
7388 vht_mcsmap = 0xfff0;
7389 break;
7390 case 8:
7391 vht_mcsmap = 0xfff5;
7392 break;
7393 case 9:
7394 vht_mcsmap = 0xfffa;
7395 break;
7396 default:
7397 vht_mcsmap = 0xfffa;
7398 break;
7399 }
7400 break;
7401 case 3:
7402 switch (mcs) {
7403 case 7:
7404 vht_mcsmap = 0xffc0;
7405 break;
7406 case 8:
7407 vht_mcsmap = 0xffd5;
7408 break;
7409 case 9:
7410 vht_mcsmap = 0xffea;
7411 break;
7412 default:
7413 vht_mcsmap = 0xffea;
7414 break;
7415 }
7416 break;
7417 default:
7418 vht_mcsmap = 0xffea;
7419 break;
7420 }
7421 snprintf(buf, sizeof(buf),
7422 "iwpriv %s vht_mcsmap 0x%04x",
7423 intf, vht_mcsmap);
7424 if (system(buf) != 0) {
7425 sigma_dut_print(dut, DUT_MSG_ERROR,
7426 "iwpriv vht_mcsmap failed");
7427 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007428 }
7429 }
7430
7431 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
7432
7433 val = get_param(cmd, "Vht_tkip");
7434 if (val)
7435 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7436
7437 val = get_param(cmd, "Vht_wep");
7438 if (val)
7439 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7440
7441 if (tkip != -1 || wep != -1) {
7442 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7443 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7444 intf);
7445 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7446 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7447 intf);
7448 } else {
7449 sigma_dut_print(dut, DUT_MSG_ERROR,
7450 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7451 return 0;
7452 }
7453
7454 if (system(buf) != 0) {
7455 sigma_dut_print(dut, DUT_MSG_ERROR,
7456 "iwpriv htweptkip failed");
7457 }
7458 }
7459
Arif Hussain55f00da2018-07-03 08:28:26 -07007460 val = get_param(cmd, "txBandwidth");
7461 if (val) {
7462 switch (get_driver_type()) {
7463 case DRIVER_WCN:
7464 if (wcn_sta_set_width(dut, intf, val) < 0) {
7465 send_resp(dut, conn, SIGMA_ERROR,
7466 "ErrorCode,Failed to set txBandwidth");
7467 return 0;
7468 }
7469 break;
7470 case DRIVER_ATHEROS:
7471 if (ath_set_width(dut, conn, intf, val) < 0) {
7472 send_resp(dut, conn, SIGMA_ERROR,
7473 "ErrorCode,Failed to set txBandwidth");
7474 return 0;
7475 }
7476 break;
7477 default:
7478 sigma_dut_print(dut, DUT_MSG_ERROR,
7479 "Setting txBandwidth not supported");
7480 break;
7481 }
7482 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007483
Arif Hussain9765f7d2018-07-03 08:28:26 -07007484 val = get_param(cmd, "BeamformeeSTS");
7485 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007486 if (sta_set_tx_beamformee(dut, intf, 1)) {
7487 send_resp(dut, conn, SIGMA_ERROR,
7488 "ErrorCode,Failed to set TX beamformee enable");
7489 return 0;
7490 }
7491
Arif Hussain9765f7d2018-07-03 08:28:26 -07007492 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7493 send_resp(dut, conn, SIGMA_ERROR,
7494 "ErrorCode,Failed to set BeamformeeSTS");
7495 return 0;
7496 }
7497 }
7498
Arif Hussain68d23f52018-07-11 13:39:08 -07007499 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7500 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007501#ifdef NL80211_SUPPORT
7502 enum qca_wlan_he_mac_padding_dur set_val;
7503
7504 switch (atoi(val)) {
7505 case 16:
7506 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7507 break;
7508 case 8:
7509 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7510 break;
7511 default:
7512 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7513 break;
7514 }
7515 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007516 send_resp(dut, conn, SIGMA_ERROR,
7517 "ErrorCode,Failed to set MAC padding duration");
7518 return 0;
7519 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007520#else /* NL80211_SUPPORT */
7521 sigma_dut_print(dut, DUT_MSG_ERROR,
7522 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7523#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007524 }
7525
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007526 val = get_param(cmd, "MU_EDCA");
7527 if (val && (strcasecmp(val, "Override") == 0)) {
7528 if (sta_set_mu_edca_override(dut, intf, 1)) {
7529 send_resp(dut, conn, SIGMA_ERROR,
7530 "ErrorCode,Failed to set MU EDCA override");
7531 return 0;
7532 }
7533 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007534
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007535 val = get_param(cmd, "OMControl");
7536 if (val) {
7537 int set_val = 1;
7538
7539 if (strcasecmp(val, "Enable") == 0)
7540 set_val = 1;
7541 else if (strcasecmp(val, "Disable") == 0)
7542 set_val = 0;
7543
7544 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
7545 send_resp(dut, conn, SIGMA_ERROR,
7546 "ErrorCode,Failed to set OM ctrl supp");
7547 return 0;
7548 }
7549 }
7550
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007551 val = get_param(cmd, "ADDBAResp_BufSize");
7552 if (val) {
7553 int buf_size;
7554
7555 if (strcasecmp(val, "gt64") == 0)
7556 buf_size = 256;
7557 else
7558 buf_size = 64;
7559 if (get_driver_type() == DRIVER_WCN &&
7560 sta_set_addba_buf_size(dut, intf, buf_size)) {
7561 send_resp(dut, conn, SIGMA_ERROR,
7562 "ErrorCode,set addbaresp_buff_size failed");
7563 return 0;
7564 }
7565 }
7566
7567 val = get_param(cmd, "ADDBAReq_BufSize");
7568 if (val) {
7569 int buf_size;
7570
7571 if (strcasecmp(val, "gt64") == 0)
7572 buf_size = 256;
7573 else
7574 buf_size = 64;
7575 if (get_driver_type() == DRIVER_WCN &&
7576 sta_set_addba_buf_size(dut, intf, buf_size)) {
7577 send_resp(dut, conn, SIGMA_ERROR,
7578 "ErrorCode,set addbareq_buff_size failed");
7579 return 0;
7580 }
7581 }
7582
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007583 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7584}
7585
7586
7587static int sta_set_wireless_60g(struct sigma_dut *dut,
7588 struct sigma_conn *conn,
7589 struct sigma_cmd *cmd)
7590{
7591 const char *dev_role = get_param(cmd, "DevRole");
7592
7593 if (!dev_role) {
7594 send_resp(dut, conn, SIGMA_INVALID,
7595 "ErrorCode,DevRole not specified");
7596 return 0;
7597 }
7598
7599 if (strcasecmp(dev_role, "PCP") == 0)
7600 return sta_set_60g_pcp(dut, conn, cmd);
7601 if (strcasecmp(dev_role, "STA") == 0)
7602 return sta_set_60g_sta(dut, conn, cmd);
7603 send_resp(dut, conn, SIGMA_INVALID,
7604 "ErrorCode,DevRole not supported");
7605 return 0;
7606}
7607
7608
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307609static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7610 struct sigma_cmd *cmd)
7611{
7612 int status;
7613 const char *intf = get_param(cmd, "Interface");
7614 const char *val = get_param(cmd, "DevRole");
7615
7616 if (val && strcasecmp(val, "STA-CFON") == 0) {
7617 status = sta_cfon_set_wireless(dut, conn, cmd);
7618 if (status)
7619 return status;
7620 }
7621 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7622}
7623
7624
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007625static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7626 struct sigma_cmd *cmd)
7627{
7628 const char *val;
7629
7630 val = get_param(cmd, "Program");
7631 if (val) {
7632 if (strcasecmp(val, "11n") == 0)
7633 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007634 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007635 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7636 if (strcasecmp(val, "60ghz") == 0)
7637 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307638 if (strcasecmp(val, "OCE") == 0)
7639 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007640 send_resp(dut, conn, SIGMA_ERROR,
7641 "ErrorCode,Program value not supported");
7642 } else {
7643 send_resp(dut, conn, SIGMA_ERROR,
7644 "ErrorCode,Program argument not available");
7645 }
7646
7647 return 0;
7648}
7649
7650
7651static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7652 int tid)
7653{
7654 char buf[100];
7655 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7656
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307657 if (tid < 0 ||
7658 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7659 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7660 return;
7661 }
7662
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007663 /*
7664 * Two ways to ensure that addba request with a
7665 * non zero TID could be sent out. EV 117296
7666 */
7667 snprintf(buf, sizeof(buf),
7668 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7669 tid);
7670 if (system(buf) != 0) {
7671 sigma_dut_print(dut, DUT_MSG_ERROR,
7672 "Ping did not send out");
7673 }
7674
7675 snprintf(buf, sizeof(buf),
7676 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7677 intf, VI_QOS_TMP_FILE);
7678 if (system(buf) != 0)
7679 return;
7680
7681 snprintf(buf, sizeof(buf),
7682 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
7683 intf, VI_QOS_TMP_FILE);
7684 if (system(buf) != 0)
7685 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
7686
7687 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
7688 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
7689 if (system(buf) != 0) {
7690 sigma_dut_print(dut, DUT_MSG_ERROR,
7691 "VI_QOS_TEMP_FILE generation error failed");
7692 }
7693 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7694 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7695 if (system(buf) != 0) {
7696 sigma_dut_print(dut, DUT_MSG_ERROR,
7697 "VI_QOS_FILE generation failed");
7698 }
7699
7700 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7701 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7702 if (system(buf) != 0) {
7703 sigma_dut_print(dut, DUT_MSG_ERROR,
7704 "VI_QOS_FILE generation failed");
7705 }
7706
7707 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
7708 if (system(buf) != 0) {
7709 }
7710}
7711
7712
7713static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7714 struct sigma_cmd *cmd)
7715{
7716 const char *intf = get_param(cmd, "Interface");
7717 const char *val;
7718 int tid = 0;
7719 char buf[100];
7720
7721 val = get_param(cmd, "TID");
7722 if (val) {
7723 tid = atoi(val);
7724 if (tid)
7725 ath_sta_inject_frame(dut, intf, tid);
7726 }
7727
7728 /* Command sequence for ADDBA request on Peregrine based devices */
7729 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
7730 if (system(buf) != 0) {
7731 sigma_dut_print(dut, DUT_MSG_ERROR,
7732 "iwpriv setaddbaoper failed");
7733 }
7734
7735 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
7736 if (system(buf) != 0) {
7737 sigma_dut_print(dut, DUT_MSG_ERROR,
7738 "wifitool senddelba failed");
7739 }
7740
7741 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
7742 if (system(buf) != 0) {
7743 sigma_dut_print(dut, DUT_MSG_ERROR,
7744 "wifitool sendaddba failed");
7745 }
7746
7747 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7748
7749 return 1;
7750}
7751
7752
Lior David9981b512017-01-20 13:16:40 +02007753#ifdef __linux__
7754
7755static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
7756 int agg_size)
7757{
7758 char dir[128], buf[128];
7759 FILE *f;
7760 regex_t re;
7761 regmatch_t m[2];
7762 int rc, ret = -1, vring_id, found;
7763
7764 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
7765 sigma_dut_print(dut, DUT_MSG_ERROR,
7766 "failed to get wil6210 debugfs dir");
7767 return -1;
7768 }
7769
7770 snprintf(buf, sizeof(buf), "%s/vrings", dir);
7771 f = fopen(buf, "r");
7772 if (!f) {
7773 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007774 /* newer wil6210 driver renamed file to "rings" */
7775 snprintf(buf, sizeof(buf), "%s/rings", dir);
7776 f = fopen(buf, "r");
7777 if (!f) {
7778 sigma_dut_print(dut, DUT_MSG_ERROR,
7779 "failed to open: %s", buf);
7780 return -1;
7781 }
Lior David9981b512017-01-20 13:16:40 +02007782 }
7783
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007784 /* can be either VRING tx... or RING... */
7785 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02007786 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
7787 goto out;
7788 }
7789
7790 /* find TX VRING for the mac address */
7791 found = 0;
7792 while (fgets(buf, sizeof(buf), f)) {
7793 if (strcasestr(buf, dest_mac)) {
7794 found = 1;
7795 break;
7796 }
7797 }
7798
7799 if (!found) {
7800 sigma_dut_print(dut, DUT_MSG_ERROR,
7801 "no TX VRING for %s", dest_mac);
7802 goto out;
7803 }
7804
7805 /* extract VRING ID, "VRING tx_<id> = {" */
7806 if (!fgets(buf, sizeof(buf), f)) {
7807 sigma_dut_print(dut, DUT_MSG_ERROR,
7808 "no VRING start line for %s", dest_mac);
7809 goto out;
7810 }
7811
7812 rc = regexec(&re, buf, 2, m, 0);
7813 regfree(&re);
7814 if (rc || m[1].rm_so < 0) {
7815 sigma_dut_print(dut, DUT_MSG_ERROR,
7816 "no VRING TX ID for %s", dest_mac);
7817 goto out;
7818 }
7819 buf[m[1].rm_eo] = 0;
7820 vring_id = atoi(&buf[m[1].rm_so]);
7821
7822 /* send the addba command */
7823 fclose(f);
7824 snprintf(buf, sizeof(buf), "%s/back", dir);
7825 f = fopen(buf, "w");
7826 if (!f) {
7827 sigma_dut_print(dut, DUT_MSG_ERROR,
7828 "failed to open: %s", buf);
7829 return -1;
7830 }
7831
7832 fprintf(f, "add %d %d\n", vring_id, agg_size);
7833
7834 ret = 0;
7835
7836out:
7837 fclose(f);
7838
7839 return ret;
7840}
7841
7842
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007843static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7844 struct sigma_cmd *cmd)
7845{
7846 const char *val;
7847 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007848
7849 val = get_param(cmd, "TID");
7850 if (val) {
7851 tid = atoi(val);
7852 if (tid != 0) {
7853 sigma_dut_print(dut, DUT_MSG_ERROR,
7854 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
7855 tid);
7856 }
7857 }
7858
7859 val = get_param(cmd, "Dest_mac");
7860 if (!val) {
7861 sigma_dut_print(dut, DUT_MSG_ERROR,
7862 "Currently not supporting addba for 60G without Dest_mac");
7863 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7864 }
7865
Lior David9981b512017-01-20 13:16:40 +02007866 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007868
7869 return 1;
7870}
7871
Lior David9981b512017-01-20 13:16:40 +02007872#endif /* __linux__ */
7873
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007874
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007875static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7876 struct sigma_cmd *cmd)
7877{
7878#ifdef NL80211_SUPPORT
7879 const char *intf = get_param(cmd, "Interface");
7880 const char *val;
7881 int tid = -1;
7882 int bufsize = 64;
7883 struct nl_msg *msg;
7884 int ret = 0;
7885 struct nlattr *params;
7886 int ifindex;
7887
7888 val = get_param(cmd, "TID");
7889 if (val)
7890 tid = atoi(val);
7891
7892 if (tid == -1) {
7893 send_resp(dut, conn, SIGMA_ERROR,
7894 "ErrorCode,sta_send_addba tid invalid");
7895 return 0;
7896 }
7897
7898 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7899
7900 ifindex = if_nametoindex(intf);
7901 if (ifindex == 0) {
7902 sigma_dut_print(dut, DUT_MSG_ERROR,
7903 "%s: Index for interface %s failed",
7904 __func__, intf);
7905 send_resp(dut, conn, SIGMA_ERROR,
7906 "ErrorCode,sta_send_addba interface invalid");
7907 return 0;
7908 }
7909
7910 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7911 NL80211_CMD_VENDOR)) ||
7912 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7913 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7914 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7915 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7916 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7917 nla_put_u8(msg,
7918 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
7919 QCA_WLAN_ADD_BA) ||
7920 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
7921 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007922 nla_put_u16(msg,
7923 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7924 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007925 sigma_dut_print(dut, DUT_MSG_ERROR,
7926 "%s: err in adding vendor_cmd and vendor_data",
7927 __func__);
7928 nlmsg_free(msg);
7929 send_resp(dut, conn, SIGMA_ERROR,
7930 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
7931 return 0;
7932 }
7933 nla_nest_end(msg, params);
7934
7935 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7936 if (ret) {
7937 sigma_dut_print(dut, DUT_MSG_ERROR,
7938 "%s: err in send_and_recv_msgs, ret=%d",
7939 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05307940 if (ret == -EOPNOTSUPP)
7941 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007942 send_resp(dut, conn, SIGMA_ERROR,
7943 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
7944 return 0;
7945 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007946#else /* NL80211_SUPPORT */
7947 sigma_dut_print(dut, DUT_MSG_ERROR,
7948 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007949#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05307950
7951 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007952}
7953
7954
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007955static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7956 struct sigma_cmd *cmd)
7957{
7958 switch (get_driver_type()) {
7959 case DRIVER_ATHEROS:
7960 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007961 case DRIVER_WCN:
7962 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007963#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007964 case DRIVER_WIL6210:
7965 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007966#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007967 default:
7968 /*
7969 * There is no driver specific implementation for other drivers.
7970 * Ignore the command and report COMPLETE since the following
7971 * throughput test operation will end up sending ADDBA anyway.
7972 */
7973 return 1;
7974 }
7975}
7976
7977
7978int inject_eth_frame(int s, const void *data, size_t len,
7979 unsigned short ethtype, char *dst, char *src)
7980{
7981 struct iovec iov[4] = {
7982 {
7983 .iov_base = dst,
7984 .iov_len = ETH_ALEN,
7985 },
7986 {
7987 .iov_base = src,
7988 .iov_len = ETH_ALEN,
7989 },
7990 {
7991 .iov_base = &ethtype,
7992 .iov_len = sizeof(unsigned short),
7993 },
7994 {
7995 .iov_base = (void *) data,
7996 .iov_len = len,
7997 }
7998 };
7999 struct msghdr msg = {
8000 .msg_name = NULL,
8001 .msg_namelen = 0,
8002 .msg_iov = iov,
8003 .msg_iovlen = 4,
8004 .msg_control = NULL,
8005 .msg_controllen = 0,
8006 .msg_flags = 0,
8007 };
8008
8009 return sendmsg(s, &msg, 0);
8010}
8011
8012#if defined(__linux__) || defined(__QNXNTO__)
8013
8014int inject_frame(int s, const void *data, size_t len, int encrypt)
8015{
8016#define IEEE80211_RADIOTAP_F_WEP 0x04
8017#define IEEE80211_RADIOTAP_F_FRAG 0x08
8018 unsigned char rtap_hdr[] = {
8019 0x00, 0x00, /* radiotap version */
8020 0x0e, 0x00, /* radiotap length */
8021 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8022 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8023 0x00, /* padding */
8024 0x00, 0x00, /* RX and TX flags to indicate that */
8025 0x00, 0x00, /* this is the injected frame directly */
8026 };
8027 struct iovec iov[2] = {
8028 {
8029 .iov_base = &rtap_hdr,
8030 .iov_len = sizeof(rtap_hdr),
8031 },
8032 {
8033 .iov_base = (void *) data,
8034 .iov_len = len,
8035 }
8036 };
8037 struct msghdr msg = {
8038 .msg_name = NULL,
8039 .msg_namelen = 0,
8040 .msg_iov = iov,
8041 .msg_iovlen = 2,
8042 .msg_control = NULL,
8043 .msg_controllen = 0,
8044 .msg_flags = 0,
8045 };
8046
8047 if (encrypt)
8048 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
8049
8050 return sendmsg(s, &msg, 0);
8051}
8052
8053
8054int open_monitor(const char *ifname)
8055{
8056#ifdef __QNXNTO__
8057 struct sockaddr_dl ll;
8058 int s;
8059
8060 memset(&ll, 0, sizeof(ll));
8061 ll.sdl_family = AF_LINK;
8062 ll.sdl_index = if_nametoindex(ifname);
8063 if (ll.sdl_index == 0) {
8064 perror("if_nametoindex");
8065 return -1;
8066 }
8067 s = socket(PF_INET, SOCK_RAW, 0);
8068#else /* __QNXNTO__ */
8069 struct sockaddr_ll ll;
8070 int s;
8071
8072 memset(&ll, 0, sizeof(ll));
8073 ll.sll_family = AF_PACKET;
8074 ll.sll_ifindex = if_nametoindex(ifname);
8075 if (ll.sll_ifindex == 0) {
8076 perror("if_nametoindex");
8077 return -1;
8078 }
8079 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
8080#endif /* __QNXNTO__ */
8081 if (s < 0) {
8082 perror("socket[PF_PACKET,SOCK_RAW]");
8083 return -1;
8084 }
8085
8086 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
8087 perror("monitor socket bind");
8088 close(s);
8089 return -1;
8090 }
8091
8092 return s;
8093}
8094
8095
8096static int hex2num(char c)
8097{
8098 if (c >= '0' && c <= '9')
8099 return c - '0';
8100 if (c >= 'a' && c <= 'f')
8101 return c - 'a' + 10;
8102 if (c >= 'A' && c <= 'F')
8103 return c - 'A' + 10;
8104 return -1;
8105}
8106
8107
8108int hwaddr_aton(const char *txt, unsigned char *addr)
8109{
8110 int i;
8111
8112 for (i = 0; i < 6; i++) {
8113 int a, b;
8114
8115 a = hex2num(*txt++);
8116 if (a < 0)
8117 return -1;
8118 b = hex2num(*txt++);
8119 if (b < 0)
8120 return -1;
8121 *addr++ = (a << 4) | b;
8122 if (i < 5 && *txt++ != ':')
8123 return -1;
8124 }
8125
8126 return 0;
8127}
8128
8129#endif /* defined(__linux__) || defined(__QNXNTO__) */
8130
8131enum send_frame_type {
8132 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
8133};
8134enum send_frame_protection {
8135 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8136};
8137
8138
8139static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8140 enum send_frame_type frame,
8141 enum send_frame_protection protected,
8142 const char *dest)
8143{
8144#ifdef __linux__
8145 unsigned char buf[1000], *pos;
8146 int s, res;
8147 char bssid[20], addr[20];
8148 char result[32], ssid[100];
8149 size_t ssid_len;
8150
8151 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
8152 sizeof(result)) < 0 ||
8153 strncmp(result, "COMPLETED", 9) != 0) {
8154 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
8155 return 0;
8156 }
8157
8158 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
8159 < 0) {
8160 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8161 "current BSSID");
8162 return 0;
8163 }
8164
8165 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
8166 < 0) {
8167 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8168 "own MAC address");
8169 return 0;
8170 }
8171
8172 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
8173 < 0) {
8174 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8175 "current SSID");
8176 return 0;
8177 }
8178 ssid_len = strlen(ssid);
8179
8180 pos = buf;
8181
8182 /* Frame Control */
8183 switch (frame) {
8184 case DISASSOC:
8185 *pos++ = 0xa0;
8186 break;
8187 case DEAUTH:
8188 *pos++ = 0xc0;
8189 break;
8190 case SAQUERY:
8191 *pos++ = 0xd0;
8192 break;
8193 case AUTH:
8194 *pos++ = 0xb0;
8195 break;
8196 case ASSOCREQ:
8197 *pos++ = 0x00;
8198 break;
8199 case REASSOCREQ:
8200 *pos++ = 0x20;
8201 break;
8202 case DLS_REQ:
8203 *pos++ = 0xd0;
8204 break;
8205 }
8206
8207 if (protected == INCORRECT_KEY)
8208 *pos++ = 0x40; /* Set Protected field to 1 */
8209 else
8210 *pos++ = 0x00;
8211
8212 /* Duration */
8213 *pos++ = 0x00;
8214 *pos++ = 0x00;
8215
8216 /* addr1 = DA (current AP) */
8217 hwaddr_aton(bssid, pos);
8218 pos += 6;
8219 /* addr2 = SA (own address) */
8220 hwaddr_aton(addr, pos);
8221 pos += 6;
8222 /* addr3 = BSSID (current AP) */
8223 hwaddr_aton(bssid, pos);
8224 pos += 6;
8225
8226 /* Seq# (to be filled by driver/mac80211) */
8227 *pos++ = 0x00;
8228 *pos++ = 0x00;
8229
8230 if (protected == INCORRECT_KEY) {
8231 /* CCMP parameters */
8232 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8233 pos += 8;
8234 }
8235
8236 if (protected == INCORRECT_KEY) {
8237 switch (frame) {
8238 case DEAUTH:
8239 /* Reason code (encrypted) */
8240 memcpy(pos, "\xa7\x39", 2);
8241 pos += 2;
8242 break;
8243 case DISASSOC:
8244 /* Reason code (encrypted) */
8245 memcpy(pos, "\xa7\x39", 2);
8246 pos += 2;
8247 break;
8248 case SAQUERY:
8249 /* Category|Action|TransID (encrypted) */
8250 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8251 pos += 4;
8252 break;
8253 default:
8254 return -1;
8255 }
8256
8257 /* CCMP MIC */
8258 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8259 pos += 8;
8260 } else {
8261 switch (frame) {
8262 case DEAUTH:
8263 /* reason code = 8 */
8264 *pos++ = 0x08;
8265 *pos++ = 0x00;
8266 break;
8267 case DISASSOC:
8268 /* reason code = 8 */
8269 *pos++ = 0x08;
8270 *pos++ = 0x00;
8271 break;
8272 case SAQUERY:
8273 /* Category - SA Query */
8274 *pos++ = 0x08;
8275 /* SA query Action - Request */
8276 *pos++ = 0x00;
8277 /* Transaction ID */
8278 *pos++ = 0x12;
8279 *pos++ = 0x34;
8280 break;
8281 case AUTH:
8282 /* Auth Alg (Open) */
8283 *pos++ = 0x00;
8284 *pos++ = 0x00;
8285 /* Seq# */
8286 *pos++ = 0x01;
8287 *pos++ = 0x00;
8288 /* Status code */
8289 *pos++ = 0x00;
8290 *pos++ = 0x00;
8291 break;
8292 case ASSOCREQ:
8293 /* Capability Information */
8294 *pos++ = 0x31;
8295 *pos++ = 0x04;
8296 /* Listen Interval */
8297 *pos++ = 0x0a;
8298 *pos++ = 0x00;
8299 /* SSID */
8300 *pos++ = 0x00;
8301 *pos++ = ssid_len;
8302 memcpy(pos, ssid, ssid_len);
8303 pos += ssid_len;
8304 /* Supported Rates */
8305 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8306 10);
8307 pos += 10;
8308 /* Extended Supported Rates */
8309 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8310 pos += 6;
8311 /* RSN */
8312 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8313 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8314 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8315 pos += 28;
8316 break;
8317 case REASSOCREQ:
8318 /* Capability Information */
8319 *pos++ = 0x31;
8320 *pos++ = 0x04;
8321 /* Listen Interval */
8322 *pos++ = 0x0a;
8323 *pos++ = 0x00;
8324 /* Current AP */
8325 hwaddr_aton(bssid, pos);
8326 pos += 6;
8327 /* SSID */
8328 *pos++ = 0x00;
8329 *pos++ = ssid_len;
8330 memcpy(pos, ssid, ssid_len);
8331 pos += ssid_len;
8332 /* Supported Rates */
8333 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8334 10);
8335 pos += 10;
8336 /* Extended Supported Rates */
8337 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8338 pos += 6;
8339 /* RSN */
8340 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8341 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8342 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8343 pos += 28;
8344 break;
8345 case DLS_REQ:
8346 /* Category - DLS */
8347 *pos++ = 0x02;
8348 /* DLS Action - Request */
8349 *pos++ = 0x00;
8350 /* Destination MACAddress */
8351 if (dest)
8352 hwaddr_aton(dest, pos);
8353 else
8354 memset(pos, 0, 6);
8355 pos += 6;
8356 /* Source MACAddress */
8357 hwaddr_aton(addr, pos);
8358 pos += 6;
8359 /* Capability Information */
8360 *pos++ = 0x10; /* Privacy */
8361 *pos++ = 0x06; /* QoS */
8362 /* DLS Timeout Value */
8363 *pos++ = 0x00;
8364 *pos++ = 0x01;
8365 /* Supported rates */
8366 *pos++ = 0x01;
8367 *pos++ = 0x08;
8368 *pos++ = 0x0c; /* 6 Mbps */
8369 *pos++ = 0x12; /* 9 Mbps */
8370 *pos++ = 0x18; /* 12 Mbps */
8371 *pos++ = 0x24; /* 18 Mbps */
8372 *pos++ = 0x30; /* 24 Mbps */
8373 *pos++ = 0x48; /* 36 Mbps */
8374 *pos++ = 0x60; /* 48 Mbps */
8375 *pos++ = 0x6c; /* 54 Mbps */
8376 /* TODO: Extended Supported Rates */
8377 /* TODO: HT Capabilities */
8378 break;
8379 }
8380 }
8381
8382 s = open_monitor("sigmadut");
8383 if (s < 0) {
8384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8385 "monitor socket");
8386 return 0;
8387 }
8388
8389 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8390 if (res < 0) {
8391 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8392 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308393 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008394 return 0;
8395 }
8396 if (res < pos - buf) {
8397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8398 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308399 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008400 return 0;
8401 }
8402
8403 close(s);
8404
8405 return 1;
8406#else /* __linux__ */
8407 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8408 "yet supported");
8409 return 0;
8410#endif /* __linux__ */
8411}
8412
8413
8414static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8415 struct sigma_conn *conn,
8416 struct sigma_cmd *cmd)
8417{
8418 const char *intf = get_param(cmd, "Interface");
8419 const char *sta, *val;
8420 unsigned char addr[ETH_ALEN];
8421 char buf[100];
8422
8423 sta = get_param(cmd, "peer");
8424 if (sta == NULL)
8425 sta = get_param(cmd, "station");
8426 if (sta == NULL) {
8427 send_resp(dut, conn, SIGMA_ERROR,
8428 "ErrorCode,Missing peer address");
8429 return 0;
8430 }
8431 if (hwaddr_aton(sta, addr) < 0) {
8432 send_resp(dut, conn, SIGMA_ERROR,
8433 "ErrorCode,Invalid peer address");
8434 return 0;
8435 }
8436
8437 val = get_param(cmd, "type");
8438 if (val == NULL)
8439 return -1;
8440
8441 if (strcasecmp(val, "DISCOVERY") == 0) {
8442 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8443 if (wpa_command(intf, buf) < 0) {
8444 send_resp(dut, conn, SIGMA_ERROR,
8445 "ErrorCode,Failed to send TDLS discovery");
8446 return 0;
8447 }
8448 return 1;
8449 }
8450
8451 if (strcasecmp(val, "SETUP") == 0) {
8452 int status = 0, timeout = 0;
8453
8454 val = get_param(cmd, "Status");
8455 if (val)
8456 status = atoi(val);
8457
8458 val = get_param(cmd, "Timeout");
8459 if (val)
8460 timeout = atoi(val);
8461
8462 if (status != 0 && status != 37) {
8463 send_resp(dut, conn, SIGMA_ERROR,
8464 "ErrorCode,Unsupported status value");
8465 return 0;
8466 }
8467
8468 if (timeout != 0 && timeout != 301) {
8469 send_resp(dut, conn, SIGMA_ERROR,
8470 "ErrorCode,Unsupported timeout value");
8471 return 0;
8472 }
8473
8474 if (status && timeout) {
8475 send_resp(dut, conn, SIGMA_ERROR,
8476 "ErrorCode,Unsupported timeout+status "
8477 "combination");
8478 return 0;
8479 }
8480
8481 if (status == 37 &&
8482 wpa_command(intf, "SET tdls_testing 0x200")) {
8483 send_resp(dut, conn, SIGMA_ERROR,
8484 "ErrorCode,Failed to enable "
8485 "decline setup response test mode");
8486 return 0;
8487 }
8488
8489 if (timeout == 301) {
8490 int res;
8491 if (dut->no_tpk_expiration)
8492 res = wpa_command(intf,
8493 "SET tdls_testing 0x108");
8494 else
8495 res = wpa_command(intf,
8496 "SET tdls_testing 0x8");
8497 if (res) {
8498 send_resp(dut, conn, SIGMA_ERROR,
8499 "ErrorCode,Failed to set short TPK "
8500 "lifetime");
8501 return 0;
8502 }
8503 }
8504
8505 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8506 if (wpa_command(intf, buf) < 0) {
8507 send_resp(dut, conn, SIGMA_ERROR,
8508 "ErrorCode,Failed to send TDLS setup");
8509 return 0;
8510 }
8511 return 1;
8512 }
8513
8514 if (strcasecmp(val, "TEARDOWN") == 0) {
8515 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8516 if (wpa_command(intf, buf) < 0) {
8517 send_resp(dut, conn, SIGMA_ERROR,
8518 "ErrorCode,Failed to send TDLS teardown");
8519 return 0;
8520 }
8521 return 1;
8522 }
8523
8524 send_resp(dut, conn, SIGMA_ERROR,
8525 "ErrorCode,Unsupported TDLS frame");
8526 return 0;
8527}
8528
8529
8530static int sta_ap_known(const char *ifname, const char *bssid)
8531{
8532 char buf[4096];
8533
Jouni Malinendd32f192018-09-15 02:55:19 +03008534 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008535 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8536 return 0;
8537 if (strncmp(buf, "id=", 3) != 0)
8538 return 0;
8539 return 1;
8540}
8541
8542
8543static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8544 const char *bssid)
8545{
8546 int res;
8547 struct wpa_ctrl *ctrl;
8548 char buf[256];
8549
8550 if (sta_ap_known(ifname, bssid))
8551 return 0;
8552 sigma_dut_print(dut, DUT_MSG_DEBUG,
8553 "AP not in BSS table - start scan");
8554
8555 ctrl = open_wpa_mon(ifname);
8556 if (ctrl == NULL) {
8557 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8558 "wpa_supplicant monitor connection");
8559 return -1;
8560 }
8561
8562 if (wpa_command(ifname, "SCAN") < 0) {
8563 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8564 wpa_ctrl_detach(ctrl);
8565 wpa_ctrl_close(ctrl);
8566 return -1;
8567 }
8568
8569 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8570 buf, sizeof(buf));
8571
8572 wpa_ctrl_detach(ctrl);
8573 wpa_ctrl_close(ctrl);
8574
8575 if (res < 0) {
8576 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8577 return -1;
8578 }
8579
8580 if (sta_ap_known(ifname, bssid))
8581 return 0;
8582 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8583 return -1;
8584}
8585
8586
8587static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8588 struct sigma_conn *conn,
8589 struct sigma_cmd *cmd,
8590 const char *intf)
8591{
8592 char buf[200];
8593
8594 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8595 if (system(buf) != 0) {
8596 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8597 "ndsend");
8598 return 0;
8599 }
8600
8601 return 1;
8602}
8603
8604
8605static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8606 struct sigma_conn *conn,
8607 struct sigma_cmd *cmd,
8608 const char *intf)
8609{
8610 char buf[200];
8611 const char *ip = get_param(cmd, "SenderIP");
8612
Peng Xu26b356d2017-10-04 17:58:16 -07008613 if (!ip)
8614 return 0;
8615
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008616 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8617 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8618 if (system(buf) == 0) {
8619 sigma_dut_print(dut, DUT_MSG_INFO,
8620 "Neighbor Solicitation got a response "
8621 "for %s@%s", ip, intf);
8622 }
8623
8624 return 1;
8625}
8626
8627
8628static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8629 struct sigma_conn *conn,
8630 struct sigma_cmd *cmd,
8631 const char *ifname)
8632{
8633 char buf[200];
8634 const char *ip = get_param(cmd, "SenderIP");
8635
8636 if (ip == NULL) {
8637 send_resp(dut, conn, SIGMA_ERROR,
8638 "ErrorCode,Missing SenderIP parameter");
8639 return 0;
8640 }
8641 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8642 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8643 if (system(buf) != 0) {
8644 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8645 "for %s@%s", ip, ifname);
8646 }
8647
8648 return 1;
8649}
8650
8651
8652static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8653 struct sigma_conn *conn,
8654 struct sigma_cmd *cmd,
8655 const char *ifname)
8656{
8657 char buf[200];
8658 char ip[16];
8659 int s;
Peng Xub3756882017-10-04 14:39:09 -07008660 struct ifreq ifr;
8661 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008662
8663 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008664 if (s < 0) {
8665 perror("socket");
8666 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008667 }
8668
Peng Xub3756882017-10-04 14:39:09 -07008669 memset(&ifr, 0, sizeof(ifr));
8670 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8671 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8672 sigma_dut_print(dut, DUT_MSG_INFO,
8673 "Failed to get %s IP address: %s",
8674 ifname, strerror(errno));
8675 close(s);
8676 return -1;
8677 }
8678 close(s);
8679
8680 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
8681 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
8682
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008683 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
8684 ip);
8685 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8686 if (system(buf) != 0) {
8687 }
8688
8689 return 1;
8690}
8691
8692
8693static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
8694 struct sigma_conn *conn,
8695 struct sigma_cmd *cmd,
8696 const char *ifname)
8697{
8698 char buf[200], addr[20];
8699 char dst[ETH_ALEN], src[ETH_ALEN];
8700 short ethtype = htons(ETH_P_ARP);
8701 char *pos;
8702 int s, res;
8703 const char *val;
8704 struct sockaddr_in taddr;
8705
8706 val = get_param(cmd, "dest");
8707 if (val)
8708 hwaddr_aton(val, (unsigned char *) dst);
8709
8710 val = get_param(cmd, "DestIP");
8711 if (val)
8712 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07008713 else
8714 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008715
8716 if (get_wpa_status(get_station_ifname(), "address", addr,
8717 sizeof(addr)) < 0)
8718 return -2;
8719 hwaddr_aton(addr, (unsigned char *) src);
8720
8721 pos = buf;
8722 *pos++ = 0x00;
8723 *pos++ = 0x01;
8724 *pos++ = 0x08;
8725 *pos++ = 0x00;
8726 *pos++ = 0x06;
8727 *pos++ = 0x04;
8728 *pos++ = 0x00;
8729 *pos++ = 0x02;
8730 memcpy(pos, src, ETH_ALEN);
8731 pos += ETH_ALEN;
8732 memcpy(pos, &taddr.sin_addr, 4);
8733 pos += 4;
8734 memcpy(pos, dst, ETH_ALEN);
8735 pos += ETH_ALEN;
8736 memcpy(pos, &taddr.sin_addr, 4);
8737 pos += 4;
8738
8739 s = open_monitor(get_station_ifname());
8740 if (s < 0) {
8741 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8742 "monitor socket");
8743 return 0;
8744 }
8745
8746 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
8747 if (res < 0) {
8748 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8749 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308750 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008751 return 0;
8752 }
8753
8754 close(s);
8755
8756 return 1;
8757}
8758
8759
8760static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
8761 struct sigma_conn *conn,
8762 struct sigma_cmd *cmd,
8763 const char *intf, const char *dest)
8764{
8765 char buf[100];
8766
8767 if (if_nametoindex("sigmadut") == 0) {
8768 snprintf(buf, sizeof(buf),
8769 "iw dev %s interface add sigmadut type monitor",
8770 get_station_ifname());
8771 if (system(buf) != 0 ||
8772 if_nametoindex("sigmadut") == 0) {
8773 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8774 "monitor interface with '%s'", buf);
8775 return -2;
8776 }
8777 }
8778
8779 if (system("ifconfig sigmadut up") != 0) {
8780 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8781 "monitor interface up");
8782 return -2;
8783 }
8784
8785 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
8786}
8787
8788
8789static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
8790 struct sigma_conn *conn,
8791 struct sigma_cmd *cmd)
8792{
8793 const char *intf = get_param(cmd, "Interface");
8794 const char *dest = get_param(cmd, "Dest");
8795 const char *type = get_param(cmd, "FrameName");
8796 const char *val;
8797 char buf[200], *pos, *end;
8798 int count, count2;
8799
8800 if (type == NULL)
8801 type = get_param(cmd, "Type");
8802
8803 if (intf == NULL || dest == NULL || type == NULL)
8804 return -1;
8805
8806 if (strcasecmp(type, "NeighAdv") == 0)
8807 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
8808
8809 if (strcasecmp(type, "NeighSolicitReq") == 0)
8810 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
8811
8812 if (strcasecmp(type, "ARPProbe") == 0)
8813 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
8814
8815 if (strcasecmp(type, "ARPAnnounce") == 0)
8816 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
8817
8818 if (strcasecmp(type, "ARPReply") == 0)
8819 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
8820
8821 if (strcasecmp(type, "DLS-request") == 0 ||
8822 strcasecmp(type, "DLSrequest") == 0)
8823 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
8824 dest);
8825
8826 if (strcasecmp(type, "ANQPQuery") != 0 &&
8827 strcasecmp(type, "Query") != 0) {
8828 send_resp(dut, conn, SIGMA_ERROR,
8829 "ErrorCode,Unsupported HS 2.0 send frame type");
8830 return 0;
8831 }
8832
8833 if (sta_scan_ap(dut, intf, dest) < 0) {
8834 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
8835 "the requested AP");
8836 return 0;
8837 }
8838
8839 pos = buf;
8840 end = buf + sizeof(buf);
8841 count = 0;
8842 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
8843
8844 val = get_param(cmd, "ANQP_CAP_LIST");
8845 if (val && atoi(val)) {
8846 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
8847 count++;
8848 }
8849
8850 val = get_param(cmd, "VENUE_NAME");
8851 if (val && atoi(val)) {
8852 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
8853 count++;
8854 }
8855
8856 val = get_param(cmd, "NETWORK_AUTH_TYPE");
8857 if (val && atoi(val)) {
8858 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
8859 count++;
8860 }
8861
8862 val = get_param(cmd, "ROAMING_CONS");
8863 if (val && atoi(val)) {
8864 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
8865 count++;
8866 }
8867
8868 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
8869 if (val && atoi(val)) {
8870 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
8871 count++;
8872 }
8873
8874 val = get_param(cmd, "NAI_REALM_LIST");
8875 if (val && atoi(val)) {
8876 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
8877 count++;
8878 }
8879
8880 val = get_param(cmd, "3GPP_INFO");
8881 if (val && atoi(val)) {
8882 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
8883 count++;
8884 }
8885
8886 val = get_param(cmd, "DOMAIN_LIST");
8887 if (val && atoi(val)) {
8888 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
8889 count++;
8890 }
8891
Jouni Malinen34cf9532018-04-29 19:26:33 +03008892 val = get_param(cmd, "Venue_URL");
8893 if (val && atoi(val)) {
8894 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
8895 count++;
8896 }
8897
Jouni Malinend3bca5d2018-04-29 17:25:23 +03008898 val = get_param(cmd, "Advice_Of_Charge");
8899 if (val && atoi(val)) {
8900 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
8901 count++;
8902 }
8903
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008904 if (count && wpa_command(intf, buf)) {
8905 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
8906 return 0;
8907 }
8908
8909 pos = buf;
8910 end = buf + sizeof(buf);
8911 count2 = 0;
8912 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
8913
8914 val = get_param(cmd, "HS_CAP_LIST");
8915 if (val && atoi(val)) {
8916 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
8917 count2++;
8918 }
8919
8920 val = get_param(cmd, "OPER_NAME");
8921 if (val && atoi(val)) {
8922 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
8923 count2++;
8924 }
8925
8926 val = get_param(cmd, "WAN_METRICS");
8927 if (!val)
8928 val = get_param(cmd, "WAN_MAT");
8929 if (!val)
8930 val = get_param(cmd, "WAN_MET");
8931 if (val && atoi(val)) {
8932 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
8933 count2++;
8934 }
8935
8936 val = get_param(cmd, "CONNECTION_CAPABILITY");
8937 if (val && atoi(val)) {
8938 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
8939 count2++;
8940 }
8941
8942 val = get_param(cmd, "OP_CLASS");
8943 if (val && atoi(val)) {
8944 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
8945 count2++;
8946 }
8947
8948 val = get_param(cmd, "OSU_PROVIDER_LIST");
8949 if (val && atoi(val)) {
8950 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
8951 count2++;
8952 }
8953
Jouni Malinenf67afec2018-04-29 19:24:58 +03008954 val = get_param(cmd, "OPER_ICON_METADATA");
8955 if (!val)
8956 val = get_param(cmd, "OPERATOR_ICON_METADATA");
8957 if (val && atoi(val)) {
8958 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
8959 count2++;
8960 }
8961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008962 if (count && count2) {
8963 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
8964 "second query");
8965 sleep(1);
8966 }
8967
8968 if (count2 && wpa_command(intf, buf)) {
8969 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
8970 "failed");
8971 return 0;
8972 }
8973
8974 val = get_param(cmd, "NAI_HOME_REALM_LIST");
8975 if (val) {
8976 if (count || count2) {
8977 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8978 "sending out second query");
8979 sleep(1);
8980 }
8981
8982 if (strcmp(val, "1") == 0)
8983 val = "mail.example.com";
8984 snprintf(buf, end - pos,
8985 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
8986 dest, val);
8987 if (wpa_command(intf, buf)) {
8988 send_resp(dut, conn, SIGMA_ERROR,
8989 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
8990 "failed");
8991 return 0;
8992 }
8993 }
8994
8995 val = get_param(cmd, "ICON_REQUEST");
8996 if (val) {
8997 if (count || count2) {
8998 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8999 "sending out second query");
9000 sleep(1);
9001 }
9002
9003 snprintf(buf, end - pos,
9004 "HS20_ICON_REQUEST %s %s", dest, val);
9005 if (wpa_command(intf, buf)) {
9006 send_resp(dut, conn, SIGMA_ERROR,
9007 "ErrorCode,HS20_ICON_REQUEST failed");
9008 return 0;
9009 }
9010 }
9011
9012 return 1;
9013}
9014
9015
9016static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9017 struct sigma_conn *conn,
9018 struct sigma_cmd *cmd)
9019{
9020 const char *val;
9021 char *ifname;
9022 char buf[100];
9023 int chwidth, nss;
9024
9025 val = get_param(cmd, "framename");
9026 if (!val)
9027 return -1;
9028 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9029
9030 /* Command sequence to generate Op mode notification */
9031 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9032 ifname = get_station_ifname();
9033
9034 /* Disable STBC */
9035 snprintf(buf, sizeof(buf),
9036 "iwpriv %s tx_stbc 0", ifname);
9037 if (system(buf) != 0) {
9038 sigma_dut_print(dut, DUT_MSG_ERROR,
9039 "iwpriv tx_stbc 0 failed!");
9040 }
9041
9042 /* Extract Channel width */
9043 val = get_param(cmd, "Channel_width");
9044 if (val) {
9045 switch (atoi(val)) {
9046 case 20:
9047 chwidth = 0;
9048 break;
9049 case 40:
9050 chwidth = 1;
9051 break;
9052 case 80:
9053 chwidth = 2;
9054 break;
9055 case 160:
9056 chwidth = 3;
9057 break;
9058 default:
9059 chwidth = 2;
9060 break;
9061 }
9062
9063 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9064 ifname, chwidth);
9065 if (system(buf) != 0) {
9066 sigma_dut_print(dut, DUT_MSG_ERROR,
9067 "iwpriv chwidth failed!");
9068 }
9069 }
9070
9071 /* Extract NSS */
9072 val = get_param(cmd, "NSS");
9073 if (val) {
9074 switch (atoi(val)) {
9075 case 1:
9076 nss = 1;
9077 break;
9078 case 2:
9079 nss = 3;
9080 break;
9081 case 3:
9082 nss = 7;
9083 break;
9084 default:
9085 /* We do not support NSS > 3 */
9086 nss = 3;
9087 break;
9088 }
9089 snprintf(buf, sizeof(buf),
9090 "iwpriv %s rxchainmask %d", ifname, nss);
9091 if (system(buf) != 0) {
9092 sigma_dut_print(dut, DUT_MSG_ERROR,
9093 "iwpriv rxchainmask failed!");
9094 }
9095 }
9096
9097 /* Opmode notify */
9098 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
9099 if (system(buf) != 0) {
9100 sigma_dut_print(dut, DUT_MSG_ERROR,
9101 "iwpriv opmode_notify failed!");
9102 } else {
9103 sigma_dut_print(dut, DUT_MSG_INFO,
9104 "Sent out the notify frame!");
9105 }
9106 }
9107
9108 return 1;
9109}
9110
9111
9112static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
9113 struct sigma_conn *conn,
9114 struct sigma_cmd *cmd)
9115{
9116 switch (get_driver_type()) {
9117 case DRIVER_ATHEROS:
9118 return ath_sta_send_frame_vht(dut, conn, cmd);
9119 default:
9120 send_resp(dut, conn, SIGMA_ERROR,
9121 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
9122 return 0;
9123 }
9124}
9125
9126
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009127static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
9128 struct sigma_cmd *cmd)
9129{
9130 const char *val;
9131 const char *intf = get_param(cmd, "Interface");
9132
9133 val = get_param(cmd, "framename");
9134 if (!val)
9135 return -1;
9136 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9137
9138 /* Command sequence to generate Op mode notification */
9139 if (val && strcasecmp(val, "action") == 0) {
9140 val = get_param(cmd, "PPDUTxType");
9141 if (val && strcasecmp(val, "TB") == 0) {
9142 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
9143 sigma_dut_print(dut, DUT_MSG_ERROR,
9144 "failed to send TB PPDU Tx cfg");
9145 send_resp(dut, conn, SIGMA_ERROR,
9146 "ErrorCode,set TB PPDU Tx cfg failed");
9147 return 0;
9148 }
9149 return 1;
9150 }
9151
9152 sigma_dut_print(dut, DUT_MSG_ERROR,
9153 "Action Tx type is not defined");
9154 }
9155
9156 return 1;
9157}
9158
9159
9160static int cmd_sta_send_frame_he(struct sigma_dut *dut,
9161 struct sigma_conn *conn,
9162 struct sigma_cmd *cmd)
9163{
9164 switch (get_driver_type()) {
9165 case DRIVER_WCN:
9166 return wcn_sta_send_frame_he(dut, conn, cmd);
9167 default:
9168 send_resp(dut, conn, SIGMA_ERROR,
9169 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
9170 return 0;
9171 }
9172}
9173
9174
Lior David0fe101e2017-03-09 16:09:50 +02009175#ifdef __linux__
9176int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9177 struct sigma_cmd *cmd)
9178{
9179 const char *frame_name = get_param(cmd, "framename");
9180 const char *mac = get_param(cmd, "dest_mac");
9181
9182 if (!frame_name || !mac) {
9183 sigma_dut_print(dut, DUT_MSG_ERROR,
9184 "framename and dest_mac must be provided");
9185 return -1;
9186 }
9187
9188 if (strcasecmp(frame_name, "brp") == 0) {
9189 const char *l_rx = get_param(cmd, "L-RX");
9190 int l_rx_i;
9191
9192 if (!l_rx) {
9193 sigma_dut_print(dut, DUT_MSG_ERROR,
9194 "L-RX must be provided");
9195 return -1;
9196 }
9197 l_rx_i = atoi(l_rx);
9198
9199 sigma_dut_print(dut, DUT_MSG_INFO,
9200 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
9201 mac, l_rx);
9202 if (l_rx_i != 16) {
9203 sigma_dut_print(dut, DUT_MSG_ERROR,
9204 "unsupported L-RX: %s", l_rx);
9205 return -1;
9206 }
9207
9208 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
9209 return -1;
9210 } else if (strcasecmp(frame_name, "ssw") == 0) {
9211 sigma_dut_print(dut, DUT_MSG_INFO,
9212 "dev_send_frame: SLS, dest_mac %s", mac);
9213 if (wil6210_send_sls(dut, mac))
9214 return -1;
9215 } else {
9216 sigma_dut_print(dut, DUT_MSG_ERROR,
9217 "unsupported frame type: %s", frame_name);
9218 return -1;
9219 }
9220
9221 return 1;
9222}
9223#endif /* __linux__ */
9224
9225
9226static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
9227 struct sigma_conn *conn,
9228 struct sigma_cmd *cmd)
9229{
9230 switch (get_driver_type()) {
9231#ifdef __linux__
9232 case DRIVER_WIL6210:
9233 return wil6210_send_frame_60g(dut, conn, cmd);
9234#endif /* __linux__ */
9235 default:
9236 send_resp(dut, conn, SIGMA_ERROR,
9237 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9238 return 0;
9239 }
9240}
9241
9242
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309243static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9244 const char *intf, struct sigma_cmd *cmd)
9245{
9246 const char *val, *addr;
9247 char buf[100];
9248
9249 addr = get_param(cmd, "DestMac");
9250 if (!addr) {
9251 send_resp(dut, conn, SIGMA_INVALID,
9252 "ErrorCode,AP MAC address is missing");
9253 return 0;
9254 }
9255
9256 val = get_param(cmd, "ANQPQuery_ID");
9257 if (!val) {
9258 send_resp(dut, conn, SIGMA_INVALID,
9259 "ErrorCode,Missing ANQPQuery_ID");
9260 return 0;
9261 }
9262
9263 if (strcasecmp(val, "NeighborReportReq") == 0) {
9264 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9265 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9266 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9267 } else {
9268 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9269 val);
9270 send_resp(dut, conn, SIGMA_INVALID,
9271 "ErrorCode,Invalid ANQPQuery_ID");
9272 return 0;
9273 }
9274
Ashwini Patild174f2c2017-04-13 16:49:46 +05309275 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9276 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9277 * if associated, AP BSSID).
9278 */
9279 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9280 send_resp(dut, conn, SIGMA_ERROR,
9281 "ErrorCode,Failed to set gas_address3");
9282 return 0;
9283 }
9284
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309285 if (wpa_command(intf, buf) < 0) {
9286 send_resp(dut, conn, SIGMA_ERROR,
9287 "ErrorCode,Failed to send ANQP query");
9288 return 0;
9289 }
9290
9291 return 1;
9292}
9293
9294
9295static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9296 struct sigma_conn *conn,
9297 const char *intf,
9298 struct sigma_cmd *cmd)
9299{
9300 const char *val = get_param(cmd, "FrameName");
9301
9302 if (val && strcasecmp(val, "ANQPQuery") == 0)
9303 return mbo_send_anqp_query(dut, conn, intf, cmd);
9304
9305 return 2;
9306}
9307
9308
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009309int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9310 struct sigma_cmd *cmd)
9311{
9312 const char *intf = get_param(cmd, "Interface");
9313 const char *val;
9314 enum send_frame_type frame;
9315 enum send_frame_protection protected;
9316 char buf[100];
9317 unsigned char addr[ETH_ALEN];
9318 int res;
9319
9320 val = get_param(cmd, "program");
9321 if (val == NULL)
9322 val = get_param(cmd, "frame");
9323 if (val && strcasecmp(val, "TDLS") == 0)
9324 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9325 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009326 strcasecmp(val, "HS2-R2") == 0 ||
9327 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009328 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9329 if (val && strcasecmp(val, "VHT") == 0)
9330 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009331 if (val && strcasecmp(val, "HE") == 0)
9332 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009333 if (val && strcasecmp(val, "LOC") == 0)
9334 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009335 if (val && strcasecmp(val, "60GHz") == 0)
9336 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309337 if (val && strcasecmp(val, "MBO") == 0) {
9338 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9339 if (res != 2)
9340 return res;
9341 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009342
9343 val = get_param(cmd, "TD_DISC");
9344 if (val) {
9345 if (hwaddr_aton(val, addr) < 0)
9346 return -1;
9347 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9348 if (wpa_command(intf, buf) < 0) {
9349 send_resp(dut, conn, SIGMA_ERROR,
9350 "ErrorCode,Failed to send TDLS discovery");
9351 return 0;
9352 }
9353 return 1;
9354 }
9355
9356 val = get_param(cmd, "TD_Setup");
9357 if (val) {
9358 if (hwaddr_aton(val, addr) < 0)
9359 return -1;
9360 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9361 if (wpa_command(intf, buf) < 0) {
9362 send_resp(dut, conn, SIGMA_ERROR,
9363 "ErrorCode,Failed to start TDLS setup");
9364 return 0;
9365 }
9366 return 1;
9367 }
9368
9369 val = get_param(cmd, "TD_TearDown");
9370 if (val) {
9371 if (hwaddr_aton(val, addr) < 0)
9372 return -1;
9373 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9374 if (wpa_command(intf, buf) < 0) {
9375 send_resp(dut, conn, SIGMA_ERROR,
9376 "ErrorCode,Failed to tear down TDLS link");
9377 return 0;
9378 }
9379 return 1;
9380 }
9381
9382 val = get_param(cmd, "TD_ChannelSwitch");
9383 if (val) {
9384 /* TODO */
9385 send_resp(dut, conn, SIGMA_ERROR,
9386 "ErrorCode,TD_ChannelSwitch not yet supported");
9387 return 0;
9388 }
9389
9390 val = get_param(cmd, "TD_NF");
9391 if (val) {
9392 /* TODO */
9393 send_resp(dut, conn, SIGMA_ERROR,
9394 "ErrorCode,TD_NF not yet supported");
9395 return 0;
9396 }
9397
9398 val = get_param(cmd, "PMFFrameType");
9399 if (val == NULL)
9400 val = get_param(cmd, "FrameName");
9401 if (val == NULL)
9402 val = get_param(cmd, "Type");
9403 if (val == NULL)
9404 return -1;
9405 if (strcasecmp(val, "disassoc") == 0)
9406 frame = DISASSOC;
9407 else if (strcasecmp(val, "deauth") == 0)
9408 frame = DEAUTH;
9409 else if (strcasecmp(val, "saquery") == 0)
9410 frame = SAQUERY;
9411 else if (strcasecmp(val, "auth") == 0)
9412 frame = AUTH;
9413 else if (strcasecmp(val, "assocreq") == 0)
9414 frame = ASSOCREQ;
9415 else if (strcasecmp(val, "reassocreq") == 0)
9416 frame = REASSOCREQ;
9417 else if (strcasecmp(val, "neigreq") == 0) {
9418 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9419
9420 val = get_param(cmd, "ssid");
9421 if (val == NULL)
9422 return -1;
9423
9424 res = send_neighbor_request(dut, intf, val);
9425 if (res) {
9426 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9427 "Failed to send neighbor report request");
9428 return 0;
9429 }
9430
9431 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309432 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9433 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009434 sigma_dut_print(dut, DUT_MSG_DEBUG,
9435 "Got Transition Management Query");
9436
Ashwini Patil5acd7382017-04-13 15:55:04 +05309437 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009438 if (res) {
9439 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9440 "Failed to send Transition Management Query");
9441 return 0;
9442 }
9443
9444 return 1;
9445 } else {
9446 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9447 "PMFFrameType");
9448 return 0;
9449 }
9450
9451 val = get_param(cmd, "PMFProtected");
9452 if (val == NULL)
9453 val = get_param(cmd, "Protected");
9454 if (val == NULL)
9455 return -1;
9456 if (strcasecmp(val, "Correct-key") == 0 ||
9457 strcasecmp(val, "CorrectKey") == 0)
9458 protected = CORRECT_KEY;
9459 else if (strcasecmp(val, "IncorrectKey") == 0)
9460 protected = INCORRECT_KEY;
9461 else if (strcasecmp(val, "Unprotected") == 0)
9462 protected = UNPROTECTED;
9463 else {
9464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9465 "PMFProtected");
9466 return 0;
9467 }
9468
9469 if (protected != UNPROTECTED &&
9470 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9472 "PMFProtected for auth/assocreq/reassocreq");
9473 return 0;
9474 }
9475
9476 if (if_nametoindex("sigmadut") == 0) {
9477 snprintf(buf, sizeof(buf),
9478 "iw dev %s interface add sigmadut type monitor",
9479 get_station_ifname());
9480 if (system(buf) != 0 ||
9481 if_nametoindex("sigmadut") == 0) {
9482 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9483 "monitor interface with '%s'", buf);
9484 return -2;
9485 }
9486 }
9487
9488 if (system("ifconfig sigmadut up") != 0) {
9489 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9490 "monitor interface up");
9491 return -2;
9492 }
9493
9494 return sta_inject_frame(dut, conn, frame, protected, NULL);
9495}
9496
9497
9498static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9499 struct sigma_conn *conn,
9500 struct sigma_cmd *cmd,
9501 const char *ifname)
9502{
9503 char buf[200];
9504 const char *val;
9505
9506 val = get_param(cmd, "ClearARP");
9507 if (val && atoi(val) == 1) {
9508 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9509 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9510 if (system(buf) != 0) {
9511 send_resp(dut, conn, SIGMA_ERROR,
9512 "errorCode,Failed to clear ARP cache");
9513 return 0;
9514 }
9515 }
9516
9517 return 1;
9518}
9519
9520
9521int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9522 struct sigma_cmd *cmd)
9523{
9524 const char *intf = get_param(cmd, "Interface");
9525 const char *val;
9526
9527 if (intf == NULL)
9528 return -1;
9529
9530 val = get_param(cmd, "program");
9531 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009532 strcasecmp(val, "HS2-R2") == 0 ||
9533 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009534 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9535
9536 return -1;
9537}
9538
9539
9540static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9541 struct sigma_cmd *cmd)
9542{
9543 const char *intf = get_param(cmd, "Interface");
9544 const char *mac = get_param(cmd, "MAC");
9545
9546 if (intf == NULL || mac == NULL)
9547 return -1;
9548
9549 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9550 "interface %s to %s", intf, mac);
9551
9552 if (dut->set_macaddr) {
9553 char buf[128];
9554 int res;
9555 if (strcasecmp(mac, "default") == 0) {
9556 res = snprintf(buf, sizeof(buf), "%s",
9557 dut->set_macaddr);
9558 dut->tmp_mac_addr = 0;
9559 } else {
9560 res = snprintf(buf, sizeof(buf), "%s %s",
9561 dut->set_macaddr, mac);
9562 dut->tmp_mac_addr = 1;
9563 }
9564 if (res < 0 || res >= (int) sizeof(buf))
9565 return -1;
9566 if (system(buf) != 0) {
9567 send_resp(dut, conn, SIGMA_ERROR,
9568 "errorCode,Failed to set MAC "
9569 "address");
9570 return 0;
9571 }
9572 return 1;
9573 }
9574
9575 if (strcasecmp(mac, "default") == 0)
9576 return 1;
9577
9578 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9579 "command");
9580 return 0;
9581}
9582
9583
9584static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9585 struct sigma_conn *conn, const char *intf,
9586 int val)
9587{
9588 char buf[200];
9589 int res;
9590
9591 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9592 intf, val);
9593 if (res < 0 || res >= (int) sizeof(buf))
9594 return -1;
9595 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9596 if (system(buf) != 0) {
9597 send_resp(dut, conn, SIGMA_ERROR,
9598 "errorCode,Failed to configure offchannel mode");
9599 return 0;
9600 }
9601
9602 return 1;
9603}
9604
9605
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009606static int off_chan_val(enum sec_ch_offset off)
9607{
9608 switch (off) {
9609 case SEC_CH_NO:
9610 return 0;
9611 case SEC_CH_40ABOVE:
9612 return 40;
9613 case SEC_CH_40BELOW:
9614 return -40;
9615 }
9616
9617 return 0;
9618}
9619
9620
9621static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9622 const char *intf, int off_ch_num,
9623 enum sec_ch_offset sec)
9624{
9625 char buf[200];
9626 int res;
9627
9628 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9629 intf, off_ch_num);
9630 if (res < 0 || res >= (int) sizeof(buf))
9631 return -1;
9632 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9633 if (system(buf) != 0) {
9634 send_resp(dut, conn, SIGMA_ERROR,
9635 "errorCode,Failed to set offchan");
9636 return 0;
9637 }
9638
9639 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9640 intf, off_chan_val(sec));
9641 if (res < 0 || res >= (int) sizeof(buf))
9642 return -1;
9643 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9644 if (system(buf) != 0) {
9645 send_resp(dut, conn, SIGMA_ERROR,
9646 "errorCode,Failed to set sec chan offset");
9647 return 0;
9648 }
9649
9650 return 1;
9651}
9652
9653
9654static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9655 struct sigma_conn *conn,
9656 const char *intf, int off_ch_num,
9657 enum sec_ch_offset sec)
9658{
9659 char buf[200];
9660 int res;
9661
9662 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9663 off_ch_num);
9664 if (res < 0 || res >= (int) sizeof(buf))
9665 return -1;
9666 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9667
9668 if (wpa_command(intf, buf) < 0) {
9669 send_resp(dut, conn, SIGMA_ERROR,
9670 "ErrorCode,Failed to set offchan");
9671 return 0;
9672 }
9673 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9674 off_chan_val(sec));
9675 if (res < 0 || res >= (int) sizeof(buf))
9676 return -1;
9677
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 sec chan offset");
9683 return 0;
9684 }
9685
9686 return 1;
9687}
9688
9689
9690static int tdls_set_offchannel_mode(struct sigma_dut *dut,
9691 struct sigma_conn *conn,
9692 const char *intf, int val)
9693{
9694 char buf[200];
9695 int res;
9696
9697 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
9698 val);
9699 if (res < 0 || res >= (int) sizeof(buf))
9700 return -1;
9701 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9702
9703 if (wpa_command(intf, buf) < 0) {
9704 send_resp(dut, conn, SIGMA_ERROR,
9705 "ErrorCode,Failed to configure offchannel mode");
9706 return 0;
9707 }
9708
9709 return 1;
9710}
9711
9712
9713static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
9714 struct sigma_conn *conn,
9715 struct sigma_cmd *cmd)
9716{
9717 const char *val;
9718 enum {
9719 CHSM_NOT_SET,
9720 CHSM_ENABLE,
9721 CHSM_DISABLE,
9722 CHSM_REJREQ,
9723 CHSM_UNSOLRESP
9724 } chsm = CHSM_NOT_SET;
9725 int off_ch_num = -1;
9726 enum sec_ch_offset sec_ch = SEC_CH_NO;
9727 int res;
9728
9729 val = get_param(cmd, "Uapsd");
9730 if (val) {
9731 char buf[100];
9732 if (strcasecmp(val, "Enable") == 0)
9733 snprintf(buf, sizeof(buf), "SET ps 99");
9734 else if (strcasecmp(val, "Disable") == 0)
9735 snprintf(buf, sizeof(buf), "SET ps 98");
9736 else {
9737 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9738 "Unsupported uapsd parameter value");
9739 return 0;
9740 }
9741 if (wpa_command(intf, buf)) {
9742 send_resp(dut, conn, SIGMA_ERROR,
9743 "ErrorCode,Failed to change U-APSD "
9744 "powersave mode");
9745 return 0;
9746 }
9747 }
9748
9749 val = get_param(cmd, "TPKTIMER");
9750 if (val && strcasecmp(val, "DISABLE") == 0) {
9751 if (wpa_command(intf, "SET tdls_testing 0x100")) {
9752 send_resp(dut, conn, SIGMA_ERROR,
9753 "ErrorCode,Failed to enable no TPK "
9754 "expiration test mode");
9755 return 0;
9756 }
9757 dut->no_tpk_expiration = 1;
9758 }
9759
9760 val = get_param(cmd, "ChSwitchMode");
9761 if (val) {
9762 if (strcasecmp(val, "Enable") == 0 ||
9763 strcasecmp(val, "Initiate") == 0)
9764 chsm = CHSM_ENABLE;
9765 else if (strcasecmp(val, "Disable") == 0 ||
9766 strcasecmp(val, "passive") == 0)
9767 chsm = CHSM_DISABLE;
9768 else if (strcasecmp(val, "RejReq") == 0)
9769 chsm = CHSM_REJREQ;
9770 else if (strcasecmp(val, "UnSolResp") == 0)
9771 chsm = CHSM_UNSOLRESP;
9772 else {
9773 send_resp(dut, conn, SIGMA_ERROR,
9774 "ErrorCode,Unknown ChSwitchMode value");
9775 return 0;
9776 }
9777 }
9778
9779 val = get_param(cmd, "OffChNum");
9780 if (val) {
9781 off_ch_num = atoi(val);
9782 if (off_ch_num == 0) {
9783 send_resp(dut, conn, SIGMA_ERROR,
9784 "ErrorCode,Invalid OffChNum");
9785 return 0;
9786 }
9787 }
9788
9789 val = get_param(cmd, "SecChOffset");
9790 if (val) {
9791 if (strcmp(val, "20") == 0)
9792 sec_ch = SEC_CH_NO;
9793 else if (strcasecmp(val, "40above") == 0)
9794 sec_ch = SEC_CH_40ABOVE;
9795 else if (strcasecmp(val, "40below") == 0)
9796 sec_ch = SEC_CH_40BELOW;
9797 else {
9798 send_resp(dut, conn, SIGMA_ERROR,
9799 "ErrorCode,Unknown SecChOffset value");
9800 return 0;
9801 }
9802 }
9803
9804 if (chsm == CHSM_NOT_SET) {
9805 /* no offchannel changes requested */
9806 return 1;
9807 }
9808
9809 if (strcmp(intf, get_main_ifname()) != 0 &&
9810 strcmp(intf, get_station_ifname()) != 0) {
9811 send_resp(dut, conn, SIGMA_ERROR,
9812 "ErrorCode,Unknown interface");
9813 return 0;
9814 }
9815
9816 switch (chsm) {
9817 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03009818 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009819 break;
9820 case CHSM_ENABLE:
9821 if (off_ch_num < 0) {
9822 send_resp(dut, conn, SIGMA_ERROR,
9823 "ErrorCode,Missing OffChNum argument");
9824 return 0;
9825 }
9826 if (wifi_chip_type == DRIVER_WCN) {
9827 res = tdls_set_offchannel_offset(dut, conn, intf,
9828 off_ch_num, sec_ch);
9829 } else {
9830 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9831 sec_ch);
9832 }
9833 if (res != 1)
9834 return res;
9835 if (wifi_chip_type == DRIVER_WCN)
9836 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
9837 else
9838 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
9839 break;
9840 case CHSM_DISABLE:
9841 if (wifi_chip_type == DRIVER_WCN)
9842 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
9843 else
9844 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
9845 break;
9846 case CHSM_REJREQ:
9847 if (wifi_chip_type == DRIVER_WCN)
9848 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
9849 else
9850 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
9851 break;
9852 case CHSM_UNSOLRESP:
9853 if (off_ch_num < 0) {
9854 send_resp(dut, conn, SIGMA_ERROR,
9855 "ErrorCode,Missing OffChNum argument");
9856 return 0;
9857 }
9858 if (wifi_chip_type == DRIVER_WCN) {
9859 res = tdls_set_offchannel_offset(dut, conn, intf,
9860 off_ch_num, sec_ch);
9861 } else {
9862 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9863 sec_ch);
9864 }
9865 if (res != 1)
9866 return res;
9867 if (wifi_chip_type == DRIVER_WCN)
9868 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
9869 else
9870 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
9871 break;
9872 }
9873
9874 return res;
9875}
9876
9877
9878static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9879 struct sigma_conn *conn,
9880 struct sigma_cmd *cmd)
9881{
9882 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309883 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009884
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009885 novap_reset(dut, intf);
9886
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009887 val = get_param(cmd, "nss_mcs_opt");
9888 if (val) {
9889 /* String (nss_operating_mode; mcs_operating_mode) */
9890 int nss, mcs;
9891 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309892 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009893
9894 token = strdup(val);
9895 if (!token)
9896 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309897 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309898 if (!result) {
9899 sigma_dut_print(dut, DUT_MSG_ERROR,
9900 "VHT NSS not specified");
9901 goto failed;
9902 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009903 if (strcasecmp(result, "def") != 0) {
9904 nss = atoi(result);
9905 if (nss == 4)
9906 ath_disable_txbf(dut, intf);
9907 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
9908 intf, nss);
9909 if (system(buf) != 0) {
9910 sigma_dut_print(dut, DUT_MSG_ERROR,
9911 "iwpriv nss failed");
9912 goto failed;
9913 }
9914 }
9915
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309916 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309917 if (!result) {
9918 sigma_dut_print(dut, DUT_MSG_ERROR,
9919 "VHT MCS not specified");
9920 goto failed;
9921 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009922 if (strcasecmp(result, "def") == 0) {
9923 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
9924 intf);
9925 if (system(buf) != 0) {
9926 sigma_dut_print(dut, DUT_MSG_ERROR,
9927 "iwpriv set11NRates failed");
9928 goto failed;
9929 }
9930
9931 } else {
9932 mcs = atoi(result);
9933 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
9934 intf, mcs);
9935 if (system(buf) != 0) {
9936 sigma_dut_print(dut, DUT_MSG_ERROR,
9937 "iwpriv vhtmcs failed");
9938 goto failed;
9939 }
9940 }
9941 /* Channel width gets messed up, fix this */
9942 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9943 intf, dut->chwidth);
9944 if (system(buf) != 0) {
9945 sigma_dut_print(dut, DUT_MSG_ERROR,
9946 "iwpriv chwidth failed");
9947 }
9948 }
9949
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309950 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009951 return 1;
9952failed:
9953 free(token);
9954 return 0;
9955}
9956
9957
9958static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9959 struct sigma_conn *conn,
9960 struct sigma_cmd *cmd)
9961{
9962 switch (get_driver_type()) {
9963 case DRIVER_ATHEROS:
9964 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
9965 default:
9966 send_resp(dut, conn, SIGMA_ERROR,
9967 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
9968 return 0;
9969 }
9970}
9971
9972
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009973static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9974 struct sigma_conn *conn,
9975 struct sigma_cmd *cmd)
9976{
9977 const char *val;
9978 char *token = NULL, *result;
9979 char buf[60];
9980
9981 val = get_param(cmd, "nss_mcs_opt");
9982 if (val) {
9983 /* String (nss_operating_mode; mcs_operating_mode) */
9984 int nss, mcs, ratecode;
9985 char *saveptr;
9986
9987 token = strdup(val);
9988 if (!token)
9989 return -2;
9990
9991 result = strtok_r(token, ";", &saveptr);
9992 if (!result) {
9993 sigma_dut_print(dut, DUT_MSG_ERROR,
9994 "HE NSS not specified");
9995 goto failed;
9996 }
9997 nss = 1;
9998 if (strcasecmp(result, "def") != 0)
9999 nss = atoi(result);
10000
10001 result = strtok_r(NULL, ";", &saveptr);
10002 if (!result) {
10003 sigma_dut_print(dut, DUT_MSG_ERROR,
10004 "HE MCS not specified");
10005 goto failed;
10006 }
10007 mcs = 7;
10008 if (strcasecmp(result, "def") != 0)
10009 mcs = atoi(result);
10010
Arif Hussain557bf412018-05-25 17:29:36 -070010011 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010012 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070010013 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010014 } else if (nss > 2) {
10015 sigma_dut_print(dut, DUT_MSG_ERROR,
10016 "HE NSS %d not supported", nss);
10017 goto failed;
10018 }
10019
Arif Hussain557bf412018-05-25 17:29:36 -070010020 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
10021 if (system(buf) != 0) {
10022 sigma_dut_print(dut, DUT_MSG_ERROR,
10023 "nss_mcs_opt: iwpriv %s nss %d failed",
10024 intf, nss);
10025 goto failed;
10026 }
Arif Hussainac6c5112018-05-25 17:34:00 -070010027 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070010028
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010029 /* Add the MCS to the ratecode */
10030 if (mcs >= 0 && mcs <= 11) {
10031 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070010032#ifdef NL80211_SUPPORT
10033 if (dut->device_type == STA_testbed) {
10034 enum he_mcs_config mcs_config;
10035 int ret;
10036
10037 if (mcs <= 7)
10038 mcs_config = HE_80_MCS0_7;
10039 else if (mcs <= 9)
10040 mcs_config = HE_80_MCS0_9;
10041 else
10042 mcs_config = HE_80_MCS0_11;
10043 ret = sta_set_he_mcs(dut, intf, mcs_config);
10044 if (ret) {
10045 sigma_dut_print(dut, DUT_MSG_ERROR,
10046 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10047 mcs, mcs_config, ret);
10048 goto failed;
10049 }
10050 }
10051#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010052 } else {
10053 sigma_dut_print(dut, DUT_MSG_ERROR,
10054 "HE MCS %d not supported", mcs);
10055 goto failed;
10056 }
10057 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
10058 intf, ratecode);
10059 if (system(buf) != 0) {
10060 sigma_dut_print(dut, DUT_MSG_ERROR,
10061 "iwpriv setting of 11ax rates failed");
10062 goto failed;
10063 }
10064 free(token);
10065 }
10066
10067 val = get_param(cmd, "GI");
10068 if (val) {
10069 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010070 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010071 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010072 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
10073 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010074 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010075 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
10076 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010077 } else {
10078 send_resp(dut, conn, SIGMA_ERROR,
10079 "errorCode,GI value not supported");
10080 return 0;
10081 }
10082 if (system(buf) != 0) {
10083 send_resp(dut, conn, SIGMA_ERROR,
10084 "errorCode,Failed to set shortgi");
10085 return 0;
10086 }
10087 }
10088
Subhani Shaik8e7a3052018-04-24 14:03:00 -070010089 val = get_param(cmd, "LTF");
10090 if (val) {
10091#ifdef NL80211_SUPPORT
10092 if (strcmp(val, "3.2") == 0) {
10093 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
10094 } if (strcmp(val, "6.4") == 0) {
10095 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
10096 } else if (strcmp(val, "12.8") == 0) {
10097 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
10098 } else {
10099 send_resp(dut, conn, SIGMA_ERROR,
10100 "errorCode, LTF value not supported");
10101 return 0;
10102 }
10103#else /* NL80211_SUPPORT */
10104 sigma_dut_print(dut, DUT_MSG_ERROR,
10105 "LTF cannot be set without NL80211_SUPPORT defined");
10106 return -2;
10107#endif /* NL80211_SUPPORT */
10108 }
10109
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070010110 val = get_param(cmd, "TxSUPPDU");
10111 if (val) {
10112 int set_val = 1;
10113
10114 if (strcasecmp(val, "Enable") == 0)
10115 set_val = 1;
10116 else if (strcasecmp(val, "Disable") == 0)
10117 set_val = 0;
10118
10119 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
10120 send_resp(dut, conn, SIGMA_ERROR,
10121 "ErrorCode,Failed to set Tx SU PPDU config");
10122 return 0;
10123 }
10124 }
10125
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070010126 val = get_param(cmd, "OMCtrl_RxNSS");
10127 if (val) {
10128 /*
10129 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
10130 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
10131 * the actual Nss value hence add 1 to the set value.
10132 */
10133 int set_val = atoi(val) + 1;
10134
10135 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
10136 send_resp(dut, conn, SIGMA_ERROR,
10137 "ErrorCode,Failed to set OM ctrl NSS config");
10138 return 0;
10139 }
10140 }
10141
10142 val = get_param(cmd, "OMCtrl_ChnlWidth");
10143 if (val) {
10144 int set_val = atoi(val);
10145
10146 if (sta_set_he_om_ctrl_bw(dut, intf,
10147 (enum qca_wlan_he_om_ctrl_ch_bw)
10148 set_val)) {
10149 send_resp(dut, conn, SIGMA_ERROR,
10150 "ErrorCode,Failed to set OM ctrl BW config");
10151 return 0;
10152 }
10153 }
10154
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080010155 val = get_param(cmd, "Powersave");
10156 if (val) {
10157 char buf[60];
10158
10159 if (strcasecmp(val, "off") == 0) {
10160 snprintf(buf, sizeof(buf),
10161 "iwpriv %s setPower 2", intf);
10162 if (system(buf) != 0) {
10163 sigma_dut_print(dut, DUT_MSG_ERROR,
10164 "iwpriv setPower 2 failed");
10165 return 0;
10166 }
10167 } else if (strcasecmp(val, "on") == 0) {
10168 snprintf(buf, sizeof(buf),
10169 "iwpriv %s setPower 1", intf);
10170 if (system(buf) != 0) {
10171 sigma_dut_print(dut, DUT_MSG_ERROR,
10172 "iwpriv setPower 1 failed");
10173 return 0;
10174 }
10175 } else {
10176 sigma_dut_print(dut, DUT_MSG_ERROR,
10177 "Unsupported Powersave value '%s'",
10178 val);
10179 return -1;
10180 }
10181 }
10182
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010183 return 1;
10184
10185failed:
10186 free(token);
10187 return -2;
10188}
10189
10190
10191static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10192 struct sigma_conn *conn,
10193 struct sigma_cmd *cmd)
10194{
10195 switch (get_driver_type()) {
10196 case DRIVER_WCN:
10197 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
10198 default:
10199 send_resp(dut, conn, SIGMA_ERROR,
10200 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
10201 return 0;
10202 }
10203}
10204
10205
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010206static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
10207 struct sigma_conn *conn,
10208 struct sigma_cmd *cmd)
10209{
10210 const char *val;
10211
10212 val = get_param(cmd, "powersave");
10213 if (val) {
10214 char buf[60];
10215
10216 if (strcasecmp(val, "off") == 0) {
10217 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
10218 intf);
10219 if (system(buf) != 0) {
10220 sigma_dut_print(dut, DUT_MSG_ERROR,
10221 "iwpriv setPower 2 failed");
10222 return 0;
10223 }
10224 } else if (strcasecmp(val, "on") == 0) {
10225 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
10226 intf);
10227 if (system(buf) != 0) {
10228 sigma_dut_print(dut, DUT_MSG_ERROR,
10229 "iwpriv setPower 1 failed");
10230 return 0;
10231 }
10232 } else {
10233 sigma_dut_print(dut, DUT_MSG_ERROR,
10234 "Unsupported power save config");
10235 return -1;
10236 }
10237 return 1;
10238 }
10239
10240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
10241
10242 return 0;
10243}
10244
10245
Ashwini Patil5acd7382017-04-13 15:55:04 +053010246static int btm_query_candidate_list(struct sigma_dut *dut,
10247 struct sigma_conn *conn,
10248 struct sigma_cmd *cmd)
10249{
10250 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
10251 int len, ret;
10252 char buf[10];
10253
10254 /*
10255 * Neighbor Report elements format:
10256 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
10257 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
10258 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
10259 */
10260
10261 bssid = get_param(cmd, "Nebor_BSSID");
10262 if (!bssid) {
10263 send_resp(dut, conn, SIGMA_INVALID,
10264 "errorCode,Nebor_BSSID is missing");
10265 return 0;
10266 }
10267
10268 info = get_param(cmd, "Nebor_Bssid_Info");
10269 if (!info) {
10270 sigma_dut_print(dut, DUT_MSG_INFO,
10271 "Using default value for Nebor_Bssid_Info: %s",
10272 DEFAULT_NEIGHBOR_BSSID_INFO);
10273 info = DEFAULT_NEIGHBOR_BSSID_INFO;
10274 }
10275
10276 op_class = get_param(cmd, "Nebor_Op_Class");
10277 if (!op_class) {
10278 send_resp(dut, conn, SIGMA_INVALID,
10279 "errorCode,Nebor_Op_Class is missing");
10280 return 0;
10281 }
10282
10283 ch = get_param(cmd, "Nebor_Op_Ch");
10284 if (!ch) {
10285 send_resp(dut, conn, SIGMA_INVALID,
10286 "errorCode,Nebor_Op_Ch is missing");
10287 return 0;
10288 }
10289
10290 phy_type = get_param(cmd, "Nebor_Phy_Type");
10291 if (!phy_type) {
10292 sigma_dut_print(dut, DUT_MSG_INFO,
10293 "Using default value for Nebor_Phy_Type: %s",
10294 DEFAULT_NEIGHBOR_PHY_TYPE);
10295 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
10296 }
10297
10298 /* Parse optional subelements */
10299 buf[0] = '\0';
10300 pref = get_param(cmd, "Nebor_Pref");
10301 if (pref) {
10302 /* hexdump for preferrence subelement */
10303 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10304 if (ret < 0 || ret >= (int) sizeof(buf)) {
10305 sigma_dut_print(dut, DUT_MSG_ERROR,
10306 "snprintf failed for optional subelement ret: %d",
10307 ret);
10308 send_resp(dut, conn, SIGMA_ERROR,
10309 "errorCode,snprintf failed for subelement");
10310 return 0;
10311 }
10312 }
10313
10314 if (!dut->btm_query_cand_list) {
10315 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10316 if (!dut->btm_query_cand_list) {
10317 send_resp(dut, conn, SIGMA_ERROR,
10318 "errorCode,Failed to allocate memory for btm_query_cand_list");
10319 return 0;
10320 }
10321 }
10322
10323 len = strlen(dut->btm_query_cand_list);
10324 ret = snprintf(dut->btm_query_cand_list + len,
10325 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10326 bssid, info, op_class, ch, phy_type, buf);
10327 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10328 sigma_dut_print(dut, DUT_MSG_ERROR,
10329 "snprintf failed for neighbor report list ret: %d",
10330 ret);
10331 send_resp(dut, conn, SIGMA_ERROR,
10332 "errorCode,snprintf failed for neighbor report");
10333 free(dut->btm_query_cand_list);
10334 dut->btm_query_cand_list = NULL;
10335 return 0;
10336 }
10337
10338 return 1;
10339}
10340
10341
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010342static int cmd_sta_set_power_save(struct sigma_dut *dut,
10343 struct sigma_conn *conn,
10344 struct sigma_cmd *cmd)
10345{
10346 const char *intf = get_param(cmd, "interface");
10347 const char *prog = get_param(cmd, "program");
10348
10349 if (!intf || !prog)
10350 return -1;
10351
10352 if ((get_driver_type() == DRIVER_WCN) && (strcasecmp(prog, "HE") == 0))
10353 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
10354
10355 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10356 return 0;
10357}
10358
10359
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010360static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10361 struct sigma_cmd *cmd)
10362{
10363 const char *intf = get_param(cmd, "Interface");
10364 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010365 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010366
10367 if (intf == NULL || prog == NULL)
10368 return -1;
10369
Ashwini Patil5acd7382017-04-13 15:55:04 +053010370 /* BSS Transition candidate list for BTM query */
10371 val = get_param(cmd, "Nebor_BSSID");
10372 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10373 return 0;
10374
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010375 if (strcasecmp(prog, "TDLS") == 0)
10376 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10377
10378 if (strcasecmp(prog, "VHT") == 0)
10379 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10380
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010381 if (strcasecmp(prog, "HE") == 0)
10382 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10383
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010384 if (strcasecmp(prog, "MBO") == 0) {
10385 val = get_param(cmd, "Cellular_Data_Cap");
10386 if (val &&
10387 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10388 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010389
10390 val = get_param(cmd, "Ch_Pref");
10391 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10392 return 0;
10393
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010394 return 1;
10395 }
10396
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10398 return 0;
10399}
10400
10401
10402static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10403 struct sigma_cmd *cmd)
10404{
10405 const char *intf = get_param(cmd, "Interface");
10406 const char *mode = get_param(cmd, "Mode");
10407 int res;
10408
10409 if (intf == NULL || mode == NULL)
10410 return -1;
10411
10412 if (strcasecmp(mode, "On") == 0)
10413 res = wpa_command(intf, "SET radio_disabled 0");
10414 else if (strcasecmp(mode, "Off") == 0)
10415 res = wpa_command(intf, "SET radio_disabled 1");
10416 else
10417 return -1;
10418
10419 if (res) {
10420 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10421 "radio mode");
10422 return 0;
10423 }
10424
10425 return 1;
10426}
10427
10428
10429static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10430 struct sigma_cmd *cmd)
10431{
10432 const char *intf = get_param(cmd, "Interface");
10433 const char *mode = get_param(cmd, "Mode");
10434 int res;
10435
10436 if (intf == NULL || mode == NULL)
10437 return -1;
10438
10439 if (strcasecmp(mode, "On") == 0)
10440 res = set_ps(intf, dut, 1);
10441 else if (strcasecmp(mode, "Off") == 0)
10442 res = set_ps(intf, dut, 0);
10443 else
10444 return -1;
10445
10446 if (res) {
10447 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10448 "power save mode");
10449 return 0;
10450 }
10451
10452 return 1;
10453}
10454
10455
10456static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10457 struct sigma_cmd *cmd)
10458{
10459 const char *intf = get_param(cmd, "Interface");
10460 const char *val, *bssid;
10461 int res;
10462 char *buf;
10463 size_t buf_len;
10464
10465 val = get_param(cmd, "BSSID_FILTER");
10466 if (val == NULL)
10467 return -1;
10468
10469 bssid = get_param(cmd, "BSSID_List");
10470 if (atoi(val) == 0 || bssid == NULL) {
10471 /* Disable BSSID filter */
10472 if (wpa_command(intf, "SET bssid_filter ")) {
10473 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10474 "to disable BSSID filter");
10475 return 0;
10476 }
10477
10478 return 1;
10479 }
10480
10481 buf_len = 100 + strlen(bssid);
10482 buf = malloc(buf_len);
10483 if (buf == NULL)
10484 return -1;
10485
10486 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10487 res = wpa_command(intf, buf);
10488 free(buf);
10489 if (res) {
10490 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10491 "BSSID filter");
10492 return 0;
10493 }
10494
10495 return 1;
10496}
10497
10498
10499static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10500 struct sigma_cmd *cmd)
10501{
10502 const char *intf = get_param(cmd, "Interface");
10503 const char *val;
10504
10505 /* TODO: ARP */
10506
10507 val = get_param(cmd, "HS2_CACHE_PROFILE");
10508 if (val && strcasecmp(val, "All") == 0)
10509 hs2_clear_credentials(intf);
10510
10511 return 1;
10512}
10513
10514
10515static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10516 struct sigma_cmd *cmd)
10517{
10518 const char *intf = get_param(cmd, "Interface");
10519 const char *key_type = get_param(cmd, "KeyType");
10520 char buf[100], resp[200];
10521
10522 if (key_type == NULL)
10523 return -1;
10524
10525 if (strcasecmp(key_type, "GTK") == 0) {
10526 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10527 strncmp(buf, "FAIL", 4) == 0) {
10528 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10529 "not fetch current GTK");
10530 return 0;
10531 }
10532 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10533 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10534 return 0;
10535 } else {
10536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10537 "KeyType");
10538 return 0;
10539 }
10540
10541 return 1;
10542}
10543
10544
10545static int hs2_set_policy(struct sigma_dut *dut)
10546{
10547#ifdef ANDROID
10548 system("ip rule del prio 23000");
10549 if (system("ip rule add from all lookup main prio 23000") != 0) {
10550 sigma_dut_print(dut, DUT_MSG_ERROR,
10551 "Failed to run:ip rule add from all lookup main prio");
10552 return -1;
10553 }
10554 if (system("ip route flush cache") != 0) {
10555 sigma_dut_print(dut, DUT_MSG_ERROR,
10556 "Failed to run ip route flush cache");
10557 return -1;
10558 }
10559 return 1;
10560#else /* ANDROID */
10561 return 0;
10562#endif /* ANDROID */
10563}
10564
10565
10566static int cmd_sta_hs2_associate(struct sigma_dut *dut,
10567 struct sigma_conn *conn,
10568 struct sigma_cmd *cmd)
10569{
10570 const char *intf = get_param(cmd, "Interface");
10571 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030010572 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010573 struct wpa_ctrl *ctrl;
10574 int res;
10575 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
10576 int tries = 0;
10577 int ignore_blacklist = 0;
10578 const char *events[] = {
10579 "CTRL-EVENT-CONNECTED",
10580 "INTERWORKING-BLACKLISTED",
10581 "INTERWORKING-NO-MATCH",
10582 NULL
10583 };
10584
10585 start_sta_mode(dut);
10586
Jouni Malinen439352d2018-09-13 03:42:23 +030010587 if (band) {
10588 if (strcmp(band, "2.4") == 0) {
10589 wpa_command(intf, "SET setband 2G");
10590 } else if (strcmp(band, "5") == 0) {
10591 wpa_command(intf, "SET setband 5G");
10592 } else {
10593 send_resp(dut, conn, SIGMA_ERROR,
10594 "errorCode,Unsupported band");
10595 return 0;
10596 }
10597 }
10598
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010599 blacklisted[0] = '\0';
10600 if (val && atoi(val))
10601 ignore_blacklist = 1;
10602
10603try_again:
10604 ctrl = open_wpa_mon(intf);
10605 if (ctrl == NULL) {
10606 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10607 "wpa_supplicant monitor connection");
10608 return -2;
10609 }
10610
10611 tries++;
10612 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
10613 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
10614 "Interworking connection");
10615 wpa_ctrl_detach(ctrl);
10616 wpa_ctrl_close(ctrl);
10617 return 0;
10618 }
10619
10620 buf[0] = '\0';
10621 while (1) {
10622 char *pos;
10623 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10624 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
10625 if (!pos)
10626 break;
10627 pos += 25;
10628 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
10629 pos);
10630 if (!blacklisted[0])
10631 memcpy(blacklisted, pos, strlen(pos) + 1);
10632 }
10633
10634 if (ignore_blacklist && blacklisted[0]) {
10635 char *end;
10636 end = strchr(blacklisted, ' ');
10637 if (end)
10638 *end = '\0';
10639 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
10640 blacklisted);
10641 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
10642 blacklisted);
10643 if (wpa_command(intf, buf)) {
10644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
10645 wpa_ctrl_detach(ctrl);
10646 wpa_ctrl_close(ctrl);
10647 return 0;
10648 }
10649 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10650 buf, sizeof(buf));
10651 }
10652
10653 wpa_ctrl_detach(ctrl);
10654 wpa_ctrl_close(ctrl);
10655
10656 if (res < 0) {
10657 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10658 "connect");
10659 return 0;
10660 }
10661
10662 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
10663 strstr(buf, "INTERWORKING-BLACKLISTED")) {
10664 if (tries < 2) {
10665 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
10666 goto try_again;
10667 }
10668 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
10669 "matching credentials found");
10670 return 0;
10671 }
10672
10673 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10674 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10675 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10676 "get current BSSID/SSID");
10677 return 0;
10678 }
10679
10680 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
10681 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10682 hs2_set_policy(dut);
10683 return 0;
10684}
10685
10686
Jouni Malinenb639f1c2018-09-13 02:39:46 +030010687static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
10688 struct sigma_conn *conn,
10689 struct sigma_cmd *cmd)
10690{
10691 const char *intf = get_param(cmd, "Interface");
10692 const char *display = get_param(cmd, "Display");
10693 struct wpa_ctrl *ctrl;
10694 char buf[300], params[400], *pos;
10695 char bssid[20];
10696 int info_avail = 0;
10697 unsigned int old_timeout;
10698 int res;
10699
10700 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
10701 send_resp(dut, conn, SIGMA_ERROR,
10702 "ErrorCode,Could not get current BSSID");
10703 return 0;
10704 }
10705 ctrl = open_wpa_mon(intf);
10706 if (!ctrl) {
10707 sigma_dut_print(dut, DUT_MSG_ERROR,
10708 "Failed to open wpa_supplicant monitor connection");
10709 return -2;
10710 }
10711
10712 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
10713 wpa_command(intf, buf);
10714
10715 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
10716 if (res < 0) {
10717 send_resp(dut, conn, SIGMA_ERROR,
10718 "ErrorCode,Could not complete GAS query");
10719 goto fail;
10720 }
10721
10722 old_timeout = dut->default_timeout;
10723 dut->default_timeout = 2;
10724 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
10725 dut->default_timeout = old_timeout;
10726 if (res < 0)
10727 goto done;
10728 pos = strchr(buf, ' ');
10729 if (!pos)
10730 goto done;
10731 pos++;
10732 pos = strchr(pos, ' ');
10733 if (!pos)
10734 goto done;
10735 pos++;
10736 info_avail = 1;
10737 snprintf(params, sizeof(params), "browser %s", pos);
10738
10739 if (display && strcasecmp(display, "Yes") == 0) {
10740 pid_t pid;
10741
10742 pid = fork();
10743 if (pid < 0) {
10744 perror("fork");
10745 return -1;
10746 }
10747
10748 if (pid == 0) {
10749 run_hs20_osu(dut, params);
10750 exit(0);
10751 }
10752 }
10753
10754done:
10755 snprintf(buf, sizeof(buf), "Info_available,%s",
10756 info_avail ? "Yes" : "No");
10757 send_resp(dut, conn, SIGMA_COMPLETE, buf);
10758fail:
10759 wpa_ctrl_detach(ctrl);
10760 wpa_ctrl_close(ctrl);
10761 return 0;
10762}
10763
10764
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010765static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
10766 struct sigma_conn *conn,
10767 const char *ifname,
10768 struct sigma_cmd *cmd)
10769{
10770 const char *val;
10771 int id;
10772
10773 id = add_cred(ifname);
10774 if (id < 0)
10775 return -2;
10776 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10777
10778 val = get_param(cmd, "prefer");
10779 if (val && atoi(val) > 0)
10780 set_cred(ifname, id, "priority", "1");
10781
10782 val = get_param(cmd, "REALM");
10783 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10784 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10785 "realm");
10786 return 0;
10787 }
10788
10789 val = get_param(cmd, "HOME_FQDN");
10790 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10791 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10792 "home_fqdn");
10793 return 0;
10794 }
10795
10796 val = get_param(cmd, "Username");
10797 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10798 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10799 "username");
10800 return 0;
10801 }
10802
10803 val = get_param(cmd, "Password");
10804 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
10805 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10806 "password");
10807 return 0;
10808 }
10809
10810 val = get_param(cmd, "ROOT_CA");
10811 if (val) {
10812 char fname[200];
10813 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10814#ifdef __linux__
10815 if (!file_exists(fname)) {
10816 char msg[300];
10817 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10818 "file (%s) not found", fname);
10819 send_resp(dut, conn, SIGMA_ERROR, msg);
10820 return 0;
10821 }
10822#endif /* __linux__ */
10823 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10824 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10825 "not set root CA");
10826 return 0;
10827 }
10828 }
10829
10830 return 1;
10831}
10832
10833
10834static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
10835{
10836 FILE *in, *out;
10837 char buf[500];
10838 int found = 0;
10839
10840 in = fopen("devdetail.xml", "r");
10841 if (in == NULL)
10842 return -1;
10843 out = fopen("devdetail.xml.tmp", "w");
10844 if (out == NULL) {
10845 fclose(in);
10846 return -1;
10847 }
10848
10849 while (fgets(buf, sizeof(buf), in)) {
10850 char *pos = strstr(buf, "<IMSI>");
10851 if (pos) {
10852 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
10853 imsi);
10854 pos += 6;
10855 *pos = '\0';
10856 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
10857 found++;
10858 } else {
10859 fprintf(out, "%s", buf);
10860 }
10861 }
10862
10863 fclose(out);
10864 fclose(in);
10865 if (found)
10866 rename("devdetail.xml.tmp", "devdetail.xml");
10867 else
10868 unlink("devdetail.xml.tmp");
10869
10870 return 0;
10871}
10872
10873
10874static int sta_add_credential_sim(struct sigma_dut *dut,
10875 struct sigma_conn *conn,
10876 const char *ifname, struct sigma_cmd *cmd)
10877{
10878 const char *val, *imsi = NULL;
10879 int id;
10880 char buf[200];
10881 int res;
10882 const char *pos;
10883 size_t mnc_len;
10884 char plmn_mcc[4];
10885 char plmn_mnc[4];
10886
10887 id = add_cred(ifname);
10888 if (id < 0)
10889 return -2;
10890 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10891
10892 val = get_param(cmd, "prefer");
10893 if (val && atoi(val) > 0)
10894 set_cred(ifname, id, "priority", "1");
10895
10896 val = get_param(cmd, "PLMN_MCC");
10897 if (val == NULL) {
10898 send_resp(dut, conn, SIGMA_ERROR,
10899 "errorCode,Missing PLMN_MCC");
10900 return 0;
10901 }
10902 if (strlen(val) != 3) {
10903 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
10904 return 0;
10905 }
10906 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
10907
10908 val = get_param(cmd, "PLMN_MNC");
10909 if (val == NULL) {
10910 send_resp(dut, conn, SIGMA_ERROR,
10911 "errorCode,Missing PLMN_MNC");
10912 return 0;
10913 }
10914 if (strlen(val) != 2 && strlen(val) != 3) {
10915 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
10916 return 0;
10917 }
10918 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
10919
10920 val = get_param(cmd, "IMSI");
10921 if (val == NULL) {
10922 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
10923 "IMSI");
10924 return 0;
10925 }
10926
10927 imsi = pos = val;
10928
10929 if (strncmp(plmn_mcc, pos, 3) != 0) {
10930 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
10931 return 0;
10932 }
10933 pos += 3;
10934
10935 mnc_len = strlen(plmn_mnc);
10936 if (mnc_len < 2) {
10937 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
10938 return 0;
10939 }
10940
10941 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
10942 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
10943 return 0;
10944 }
10945 pos += mnc_len;
10946
10947 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
10948 if (res < 0 || res >= (int) sizeof(buf))
10949 return -1;
10950 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
10951 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10952 "not set IMSI");
10953 return 0;
10954 }
10955
10956 val = get_param(cmd, "Password");
10957 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
10958 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10959 "not set password");
10960 return 0;
10961 }
10962
Jouni Malinenba630452018-06-22 11:49:59 +030010963 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010964 /*
10965 * Set provisioning_sp for the test cases where SIM/USIM
10966 * provisioning is used.
10967 */
10968 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
10969 "wi-fi.org") < 0) {
10970 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10971 "not set provisioning_sp");
10972 return 0;
10973 }
10974
10975 update_devdetail_imsi(dut, imsi);
10976 }
10977
10978 return 1;
10979}
10980
10981
10982static int sta_add_credential_cert(struct sigma_dut *dut,
10983 struct sigma_conn *conn,
10984 const char *ifname,
10985 struct sigma_cmd *cmd)
10986{
10987 const char *val;
10988 int id;
10989
10990 id = add_cred(ifname);
10991 if (id < 0)
10992 return -2;
10993 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10994
10995 val = get_param(cmd, "prefer");
10996 if (val && atoi(val) > 0)
10997 set_cred(ifname, id, "priority", "1");
10998
10999 val = get_param(cmd, "REALM");
11000 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11001 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11002 "realm");
11003 return 0;
11004 }
11005
11006 val = get_param(cmd, "HOME_FQDN");
11007 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11008 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11009 "home_fqdn");
11010 return 0;
11011 }
11012
11013 val = get_param(cmd, "Username");
11014 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11015 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11016 "username");
11017 return 0;
11018 }
11019
11020 val = get_param(cmd, "clientCertificate");
11021 if (val) {
11022 char fname[200];
11023 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11024#ifdef __linux__
11025 if (!file_exists(fname)) {
11026 char msg[300];
11027 snprintf(msg, sizeof(msg),
11028 "ErrorCode,clientCertificate "
11029 "file (%s) not found", fname);
11030 send_resp(dut, conn, SIGMA_ERROR, msg);
11031 return 0;
11032 }
11033#endif /* __linux__ */
11034 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
11035 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11036 "not set client_cert");
11037 return 0;
11038 }
11039 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
11040 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11041 "not set private_key");
11042 return 0;
11043 }
11044 }
11045
11046 val = get_param(cmd, "ROOT_CA");
11047 if (val) {
11048 char fname[200];
11049 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11050#ifdef __linux__
11051 if (!file_exists(fname)) {
11052 char msg[300];
11053 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11054 "file (%s) not found", fname);
11055 send_resp(dut, conn, SIGMA_ERROR, msg);
11056 return 0;
11057 }
11058#endif /* __linux__ */
11059 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11060 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11061 "not set root CA");
11062 return 0;
11063 }
11064 }
11065
11066 return 1;
11067}
11068
11069
11070static int cmd_sta_add_credential(struct sigma_dut *dut,
11071 struct sigma_conn *conn,
11072 struct sigma_cmd *cmd)
11073{
11074 const char *intf = get_param(cmd, "Interface");
11075 const char *type;
11076
11077 start_sta_mode(dut);
11078
11079 type = get_param(cmd, "Type");
11080 if (!type)
11081 return -1;
11082
11083 if (strcasecmp(type, "uname_pwd") == 0)
11084 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
11085
11086 if (strcasecmp(type, "sim") == 0)
11087 return sta_add_credential_sim(dut, conn, intf, cmd);
11088
11089 if (strcasecmp(type, "cert") == 0)
11090 return sta_add_credential_cert(dut, conn, intf, cmd);
11091
11092 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
11093 "type");
11094 return 0;
11095}
11096
11097
11098static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
11099 struct sigma_cmd *cmd)
11100{
11101 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053011102 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011103 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053011104 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011105 int res;
11106
11107 val = get_param(cmd, "HESSID");
11108 if (val) {
11109 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
11110 if (res < 0 || res >= (int) sizeof(buf))
11111 return -1;
11112 wpa_command(intf, buf);
11113 }
11114
11115 val = get_param(cmd, "ACCS_NET_TYPE");
11116 if (val) {
11117 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
11118 val);
11119 if (res < 0 || res >= (int) sizeof(buf))
11120 return -1;
11121 wpa_command(intf, buf);
11122 }
11123
vamsi krishna89ad8c62017-09-19 12:51:18 +053011124 bssid = get_param(cmd, "Bssid");
11125 ssid = get_param(cmd, "Ssid");
11126
11127 if (ssid) {
11128 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
11129 send_resp(dut, conn, SIGMA_ERROR,
11130 "ErrorCode,Too long SSID");
11131 return 0;
11132 }
11133 ascii2hexstr(ssid, ssid_hex);
11134 }
11135
11136 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
11137 bssid ? " bssid=": "",
11138 bssid ? bssid : "",
11139 ssid ? " ssid " : "",
11140 ssid ? ssid_hex : "");
11141 if (res < 0 || res >= (int) sizeof(buf))
11142 return -1;
11143
11144 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011145 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
11146 "scan");
11147 return 0;
11148 }
11149
11150 return 1;
11151}
11152
11153
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011154static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
11155 struct sigma_cmd *cmd)
11156{
11157 const char *intf = get_param(cmd, "Interface");
11158 const char *bssid;
11159 char buf[4096], *pos;
11160 int freq, chan;
11161 char *ssid;
11162 char resp[100];
11163 int res;
11164 struct wpa_ctrl *ctrl;
11165
11166 bssid = get_param(cmd, "BSSID");
11167 if (!bssid) {
11168 send_resp(dut, conn, SIGMA_INVALID,
11169 "errorCode,BSSID argument is missing");
11170 return 0;
11171 }
11172
11173 ctrl = open_wpa_mon(intf);
11174 if (!ctrl) {
11175 sigma_dut_print(dut, DUT_MSG_ERROR,
11176 "Failed to open wpa_supplicant monitor connection");
11177 return -1;
11178 }
11179
11180 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
11181 send_resp(dut, conn, SIGMA_ERROR,
11182 "errorCode,Could not start scan");
11183 wpa_ctrl_detach(ctrl);
11184 wpa_ctrl_close(ctrl);
11185 return 0;
11186 }
11187
11188 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11189 buf, sizeof(buf));
11190
11191 wpa_ctrl_detach(ctrl);
11192 wpa_ctrl_close(ctrl);
11193
11194 if (res < 0) {
11195 send_resp(dut, conn, SIGMA_ERROR,
11196 "errorCode,Scan did not complete");
11197 return 0;
11198 }
11199
11200 snprintf(buf, sizeof(buf), "BSS %s", bssid);
11201 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
11202 strncmp(buf, "id=", 3) != 0) {
11203 send_resp(dut, conn, SIGMA_ERROR,
11204 "errorCode,Specified BSSID not found");
11205 return 0;
11206 }
11207
11208 pos = strstr(buf, "\nfreq=");
11209 if (!pos) {
11210 send_resp(dut, conn, SIGMA_ERROR,
11211 "errorCode,Channel not found");
11212 return 0;
11213 }
11214 freq = atoi(pos + 6);
11215 chan = freq_to_channel(freq);
11216
11217 pos = strstr(buf, "\nssid=");
11218 if (!pos) {
11219 send_resp(dut, conn, SIGMA_ERROR,
11220 "errorCode,SSID not found");
11221 return 0;
11222 }
11223 ssid = pos + 6;
11224 pos = strchr(ssid, '\n');
11225 if (pos)
11226 *pos = '\0';
11227 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
11228 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11229 return 0;
11230}
11231
11232
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011233static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
11234 struct sigma_cmd *cmd)
11235{
11236#ifdef __linux__
11237 struct timeval tv;
11238 struct tm tm;
11239 time_t t;
11240 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011241 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011242
11243 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
11244
11245 memset(&tm, 0, sizeof(tm));
11246 val = get_param(cmd, "seconds");
11247 if (val)
11248 tm.tm_sec = atoi(val);
11249 val = get_param(cmd, "minutes");
11250 if (val)
11251 tm.tm_min = atoi(val);
11252 val = get_param(cmd, "hours");
11253 if (val)
11254 tm.tm_hour = atoi(val);
11255 val = get_param(cmd, "date");
11256 if (val)
11257 tm.tm_mday = atoi(val);
11258 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011259 if (val) {
11260 v = atoi(val);
11261 if (v < 1 || v > 12) {
11262 send_resp(dut, conn, SIGMA_INVALID,
11263 "errorCode,Invalid month");
11264 return 0;
11265 }
11266 tm.tm_mon = v - 1;
11267 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011268 val = get_param(cmd, "year");
11269 if (val) {
11270 int year = atoi(val);
11271#ifdef ANDROID
11272 if (year > 2035)
11273 year = 2035; /* years beyond 2035 not supported */
11274#endif /* ANDROID */
11275 tm.tm_year = year - 1900;
11276 }
11277 t = mktime(&tm);
11278 if (t == (time_t) -1) {
11279 send_resp(dut, conn, SIGMA_ERROR,
11280 "errorCode,Invalid date or time");
11281 return 0;
11282 }
11283
11284 memset(&tv, 0, sizeof(tv));
11285 tv.tv_sec = t;
11286
11287 if (settimeofday(&tv, NULL) < 0) {
11288 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
11289 strerror(errno));
11290 send_resp(dut, conn, SIGMA_ERROR,
11291 "errorCode,Failed to set time");
11292 return 0;
11293 }
11294
11295 return 1;
11296#endif /* __linux__ */
11297
11298 return -1;
11299}
11300
11301
11302static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
11303 struct sigma_cmd *cmd)
11304{
11305 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011306 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011307 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011308 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011309 int res;
11310 struct wpa_ctrl *ctrl;
11311
11312 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011313 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011314
11315 val = get_param(cmd, "ProdESSAssoc");
11316 if (val)
11317 prod_ess_assoc = atoi(val);
11318
11319 kill_dhcp_client(dut, intf);
11320 if (start_dhcp_client(dut, intf) < 0)
11321 return -2;
11322
11323 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11324 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11325 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011326 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011327 prod_ess_assoc ? "" : "-N",
11328 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011329 name ? "'" : "",
11330 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11331 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011332
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011333 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011334 if (run_hs20_osu(dut, buf) < 0) {
11335 FILE *f;
11336
11337 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11338
11339 f = fopen("hs20-osu-client.res", "r");
11340 if (f) {
11341 char resp[400], res[300], *pos;
11342 if (!fgets(res, sizeof(res), f))
11343 res[0] = '\0';
11344 pos = strchr(res, '\n');
11345 if (pos)
11346 *pos = '\0';
11347 fclose(f);
11348 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11349 res);
11350 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11351 if (system(resp) != 0) {
11352 }
11353 snprintf(resp, sizeof(resp),
11354 "SSID,,BSSID,,failureReason,%s", res);
11355 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11356 return 0;
11357 }
11358
11359 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11360 return 0;
11361 }
11362
11363 if (!prod_ess_assoc)
11364 goto report;
11365
11366 ctrl = open_wpa_mon(intf);
11367 if (ctrl == NULL) {
11368 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11369 "wpa_supplicant monitor connection");
11370 return -1;
11371 }
11372
11373 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11374 buf, sizeof(buf));
11375
11376 wpa_ctrl_detach(ctrl);
11377 wpa_ctrl_close(ctrl);
11378
11379 if (res < 0) {
11380 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11381 "network after OSU");
11382 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11383 return 0;
11384 }
11385
11386report:
11387 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11388 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11389 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11390 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11391 return 0;
11392 }
11393
11394 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11395 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011396 return 0;
11397}
11398
11399
11400static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11401 struct sigma_cmd *cmd)
11402{
11403 const char *val;
11404 int timeout = 120;
11405
11406 val = get_param(cmd, "PolicyUpdate");
11407 if (val == NULL || atoi(val) == 0)
11408 return 1; /* No operation requested */
11409
11410 val = get_param(cmd, "Timeout");
11411 if (val)
11412 timeout = atoi(val);
11413
11414 if (timeout) {
11415 /* TODO: time out the command and return
11416 * PolicyUpdateStatus,TIMEOUT if needed. */
11417 }
11418
11419 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11420 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11421 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11422 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11423 return 0;
11424 }
11425
11426 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11427 return 0;
11428}
11429
11430
11431static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11432 struct sigma_cmd *cmd)
11433{
11434 struct wpa_ctrl *ctrl;
11435 const char *intf = get_param(cmd, "Interface");
11436 const char *bssid = get_param(cmd, "Bssid");
11437 const char *ssid = get_param(cmd, "SSID");
11438 const char *security = get_param(cmd, "Security");
11439 const char *passphrase = get_param(cmd, "Passphrase");
11440 const char *pin = get_param(cmd, "PIN");
11441 char buf[1000];
11442 char ssid_hex[200], passphrase_hex[200];
11443 const char *keymgmt, *cipher;
11444
11445 if (intf == NULL)
11446 intf = get_main_ifname();
11447
11448 if (!bssid) {
11449 send_resp(dut, conn, SIGMA_ERROR,
11450 "ErrorCode,Missing Bssid argument");
11451 return 0;
11452 }
11453
11454 if (!ssid) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "ErrorCode,Missing SSID argument");
11457 return 0;
11458 }
11459
11460 if (!security) {
11461 send_resp(dut, conn, SIGMA_ERROR,
11462 "ErrorCode,Missing Security argument");
11463 return 0;
11464 }
11465
11466 if (!passphrase) {
11467 send_resp(dut, conn, SIGMA_ERROR,
11468 "ErrorCode,Missing Passphrase argument");
11469 return 0;
11470 }
11471
11472 if (!pin) {
11473 send_resp(dut, conn, SIGMA_ERROR,
11474 "ErrorCode,Missing PIN argument");
11475 return 0;
11476 }
11477
vamsi krishna8c9c1562017-05-12 15:51:46 +053011478 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11479 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011480 send_resp(dut, conn, SIGMA_ERROR,
11481 "ErrorCode,Too long SSID/passphrase");
11482 return 0;
11483 }
11484
11485 ctrl = open_wpa_mon(intf);
11486 if (ctrl == NULL) {
11487 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11488 "wpa_supplicant monitor connection");
11489 return -2;
11490 }
11491
11492 if (strcasecmp(security, "wpa2-psk") == 0) {
11493 keymgmt = "WPA2PSK";
11494 cipher = "CCMP";
11495 } else {
11496 wpa_ctrl_detach(ctrl);
11497 wpa_ctrl_close(ctrl);
11498 send_resp(dut, conn, SIGMA_ERROR,
11499 "ErrorCode,Unsupported Security value");
11500 return 0;
11501 }
11502
11503 ascii2hexstr(ssid, ssid_hex);
11504 ascii2hexstr(passphrase, passphrase_hex);
11505 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11506 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11507
11508 if (wpa_command(intf, buf) < 0) {
11509 wpa_ctrl_detach(ctrl);
11510 wpa_ctrl_close(ctrl);
11511 send_resp(dut, conn, SIGMA_ERROR,
11512 "ErrorCode,Failed to start registrar");
11513 return 0;
11514 }
11515
11516 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11517 dut->er_oper_performed = 1;
11518
11519 return wps_connection_event(dut, conn, ctrl, intf, 0);
11520}
11521
11522
11523static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11524 struct sigma_conn *conn,
11525 struct sigma_cmd *cmd)
11526{
11527 struct wpa_ctrl *ctrl;
11528 const char *intf = get_param(cmd, "Interface");
11529 const char *bssid = get_param(cmd, "Bssid");
11530 char buf[100];
11531
11532 if (!bssid) {
11533 send_resp(dut, conn, SIGMA_ERROR,
11534 "ErrorCode,Missing Bssid argument");
11535 return 0;
11536 }
11537
11538 ctrl = open_wpa_mon(intf);
11539 if (ctrl == NULL) {
11540 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11541 "wpa_supplicant monitor connection");
11542 return -2;
11543 }
11544
11545 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11546
11547 if (wpa_command(intf, buf) < 0) {
11548 wpa_ctrl_detach(ctrl);
11549 wpa_ctrl_close(ctrl);
11550 send_resp(dut, conn, SIGMA_ERROR,
11551 "ErrorCode,Failed to start registrar");
11552 return 0;
11553 }
11554
11555 return wps_connection_event(dut, conn, ctrl, intf, 0);
11556}
11557
11558
vamsi krishna9b144002017-09-20 13:28:13 +053011559static int cmd_start_wps_registration(struct sigma_dut *dut,
11560 struct sigma_conn *conn,
11561 struct sigma_cmd *cmd)
11562{
11563 struct wpa_ctrl *ctrl;
11564 const char *intf = get_param(cmd, "Interface");
11565 const char *role, *method;
11566 int res;
11567 char buf[256];
11568 const char *events[] = {
11569 "CTRL-EVENT-CONNECTED",
11570 "WPS-OVERLAP-DETECTED",
11571 "WPS-TIMEOUT",
11572 "WPS-FAIL",
11573 NULL
11574 };
11575
11576 ctrl = open_wpa_mon(intf);
11577 if (!ctrl) {
11578 sigma_dut_print(dut, DUT_MSG_ERROR,
11579 "Failed to open wpa_supplicant monitor connection");
11580 return -2;
11581 }
11582
11583 role = get_param(cmd, "WpsRole");
11584 if (!role) {
11585 send_resp(dut, conn, SIGMA_INVALID,
11586 "ErrorCode,WpsRole not provided");
11587 goto fail;
11588 }
11589
11590 if (strcasecmp(role, "Enrollee") == 0) {
11591 method = get_param(cmd, "WpsConfigMethod");
11592 if (!method) {
11593 send_resp(dut, conn, SIGMA_INVALID,
11594 "ErrorCode,WpsConfigMethod not provided");
11595 goto fail;
11596 }
11597 if (strcasecmp(method, "PBC") == 0) {
11598 if (wpa_command(intf, "WPS_PBC") < 0) {
11599 send_resp(dut, conn, SIGMA_ERROR,
11600 "ErrorCode,Failed to enable PBC");
11601 goto fail;
11602 }
11603 } else {
11604 /* TODO: PIN method */
11605 send_resp(dut, conn, SIGMA_ERROR,
11606 "ErrorCode,Unsupported WpsConfigMethod value");
11607 goto fail;
11608 }
11609 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11610 if (res < 0) {
11611 send_resp(dut, conn, SIGMA_ERROR,
11612 "ErrorCode,WPS connection did not complete");
11613 goto fail;
11614 }
11615 if (strstr(buf, "WPS-TIMEOUT")) {
11616 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
11617 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
11618 send_resp(dut, conn, SIGMA_ERROR,
11619 "ErrorCode,OverlapSession");
11620 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
11621 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
11622 } else {
11623 send_resp(dut, conn, SIGMA_ERROR,
11624 "ErrorCode,WPS operation failed");
11625 }
11626 } else {
11627 /* TODO: Registrar role */
11628 send_resp(dut, conn, SIGMA_ERROR,
11629 "ErrorCode,Unsupported WpsRole value");
11630 }
11631
11632fail:
11633 wpa_ctrl_detach(ctrl);
11634 wpa_ctrl_close(ctrl);
11635 return 0;
11636}
11637
11638
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011639static int req_intf(struct sigma_cmd *cmd)
11640{
11641 return get_param(cmd, "interface") == NULL ? -1 : 0;
11642}
11643
11644
11645void sta_register_cmds(void)
11646{
11647 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
11648 cmd_sta_get_ip_config);
11649 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
11650 cmd_sta_set_ip_config);
11651 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
11652 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
11653 cmd_sta_get_mac_address);
11654 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
11655 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
11656 cmd_sta_verify_ip_connection);
11657 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
11658 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
11659 cmd_sta_set_encryption);
11660 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
11661 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
11662 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
11663 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
11664 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
11665 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
11666 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
11667 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
11668 cmd_sta_set_eapakaprime);
11669 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
11670 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
11671 /* TODO: sta_set_ibss */
11672 /* TODO: sta_set_mode */
11673 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
11674 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
11675 /* TODO: sta_up_load */
11676 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
11677 cmd_sta_preset_testparameters);
11678 /* TODO: sta_set_system */
11679 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
11680 /* TODO: sta_set_rifs_test */
11681 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
11682 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
11683 /* TODO: sta_send_coexist_mgmt */
11684 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
11685 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
11686 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
11687 sigma_dut_reg_cmd("sta_reset_default", req_intf,
11688 cmd_sta_reset_default);
11689 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
11690 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
11691 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
11692 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
11693 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
11694 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
11695 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
11696 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
11697 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
11698 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011699 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
11700 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011701 sigma_dut_reg_cmd("sta_add_credential", req_intf,
11702 cmd_sta_add_credential);
11703 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011704 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011705 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
11706 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
11707 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
11708 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
11709 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
11710 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030011711 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011712 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
11713 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053011714 sigma_dut_reg_cmd("start_wps_registration", req_intf,
11715 cmd_start_wps_registration);
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011716 sigma_dut_reg_cmd("sta_set_power_save", req_intf,
11717 cmd_sta_set_power_save);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011718}