blob: 9a4c74234664838822fa2a04197c080ab409d8fc [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>
13#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020014#include <regex.h>
15#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016#include <sys/time.h>
17#include <netpacket/packet.h>
18#include <linux/if_ether.h>
19#ifdef ANDROID
20#include <cutils/properties.h>
21#include <android/log.h>
22#include "keystore_get.h"
23#else /* ANDROID */
24#include <ifaddrs.h>
25#endif /* ANDROID */
26#include <netdb.h>
27#endif /* __linux__ */
28#ifdef __QNXNTO__
29#include <net/if_dl.h>
30#endif /* __QNXNTO__ */
31#include "wpa_ctrl.h"
32#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070033#include "miracast.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020034
35/* Temporary files for sta_send_addba */
36#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
37#define VI_QOS_FILE "/tmp/vi-qos.txt"
38#define VI_QOS_REFFILE "/etc/vi-qos.txt"
39
40/*
41 * MTU for Ethernet need to take into account 8-byte SNAP header
42 * to be added when encapsulating Ethernet frame into 802.11
43 */
44#ifndef IEEE80211_MAX_DATA_LEN_DMG
45#define IEEE80211_MAX_DATA_LEN_DMG 7920
46#endif
47#ifndef IEEE80211_SNAP_LEN_DMG
48#define IEEE80211_SNAP_LEN_DMG 8
49#endif
50
Ashwini Patil00402582017-04-13 12:29:39 +053051#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053052#define NEIGHBOR_REPORT_SIZE 1000
53#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
54#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053055
Jouni Malinencd4e3c32015-10-29 12:39:56 +020056extern char *sigma_wpas_ctrl;
57extern char *sigma_cert_path;
58extern enum driver_type wifi_chip_type;
59extern char *sigma_radio_ifname[];
60
Lior David0fe101e2017-03-09 16:09:50 +020061#ifdef __linux__
62#define WIL_WMI_MAX_PAYLOAD 248
63#define WIL_WMI_BF_TRIG_CMDID 0x83a
64
65struct wil_wmi_header {
66 uint8_t mid;
67 uint8_t reserved;
68 uint16_t cmd;
69 uint32_t ts;
70} __attribute__((packed));
71
72enum wil_wmi_bf_trig_type {
73 WIL_WMI_SLS,
74 WIL_WMI_BRP_RX,
75 WIL_WMI_BRP_TX,
76};
77
78struct wil_wmi_bf_trig_cmd {
79 /* enum wil_wmi_bf_trig_type */
80 uint32_t bf_type;
81 /* cid when type == WMI_BRP_RX */
82 uint32_t sta_id;
83 uint32_t reserved;
84 /* mac address when type = WIL_WMI_SLS */
85 uint8_t dest_mac[6];
86} __attribute__((packed));
87#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020088
89#ifdef ANDROID
90
91static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
92
93#define ANDROID_KEYSTORE_GET 'g'
94#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
95
96static int android_keystore_get(char cmd, const char *key, unsigned char *val)
97{
Jouni Malinencd4e3c32015-10-29 12:39:56 +020098 /* Android 4.3 changed keystore design, so need to use keystore_get() */
99#ifndef KEYSTORE_MESSAGE_SIZE
100#define KEYSTORE_MESSAGE_SIZE 65535
101#endif /* KEYSTORE_MESSAGE_SIZE */
102
103 ssize_t len;
104 uint8_t *value = NULL;
105
106 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
107 "keystore command '%c' key '%s' --> keystore_get",
108 cmd, key);
109
110 len = keystore_get(key, strlen(key), &value);
111 if (len < 0) {
112 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
113 "keystore_get() failed");
114 return -1;
115 }
116
117 if (len > KEYSTORE_MESSAGE_SIZE)
118 len = KEYSTORE_MESSAGE_SIZE;
119 memcpy(val, value, len);
120 free(value);
121 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200122}
123#endif /* ANDROID */
124
125
126int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
127{
128#ifdef __linux__
129 char buf[100];
130
131 if (wifi_chip_type == DRIVER_WCN) {
132 if (enabled) {
133 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530134 if (system(buf) != 0)
135 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200136 } else {
137 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530138 if (system(buf) != 0)
139 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200140 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530141 if (system(buf) != 0)
142 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200143 }
144
145 return 0;
146 }
147
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530148set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200149 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
150 intf, enabled ? "on" : "off");
151 if (system(buf) != 0) {
152 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
153 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530154 if (system(buf) != 0) {
155 sigma_dut_print(dut, DUT_MSG_ERROR,
156 "Failed to set power save %s",
157 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200158 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530159 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200160 }
161
162 return 0;
163#else /* __linux__ */
164 return -1;
165#endif /* __linux__ */
166}
167
168
Lior Davidcc88b562017-01-03 18:52:09 +0200169#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200170
Lior Davidcc88b562017-01-03 18:52:09 +0200171static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
172 size_t len)
173{
174 DIR *dir, *wil_dir;
175 struct dirent *entry;
176 int ret = -1;
177 const char *root_path = "/sys/kernel/debug/ieee80211";
178
179 dir = opendir(root_path);
180 if (!dir)
181 return -2;
182
183 while ((entry = readdir(dir))) {
184 if (strcmp(entry->d_name, ".") == 0 ||
185 strcmp(entry->d_name, "..") == 0)
186 continue;
187
188 if (snprintf(path, len, "%s/%s/wil6210",
189 root_path, entry->d_name) >= (int) len) {
190 ret = -3;
191 break;
192 }
193
194 wil_dir = opendir(path);
195 if (wil_dir) {
196 closedir(wil_dir);
197 ret = 0;
198 break;
199 }
200 }
201
202 closedir(dir);
203 return ret;
204}
Lior David0fe101e2017-03-09 16:09:50 +0200205
206
207static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
208 void *payload, uint16_t length)
209{
210 struct {
211 struct wil_wmi_header hdr;
212 char payload[WIL_WMI_MAX_PAYLOAD];
213 } __attribute__((packed)) cmd;
214 char buf[128], fname[128];
215 size_t towrite, written;
216 FILE *f;
217
218 if (length > WIL_WMI_MAX_PAYLOAD) {
219 sigma_dut_print(dut, DUT_MSG_ERROR,
220 "payload too large(%u, max %u)",
221 length, WIL_WMI_MAX_PAYLOAD);
222 return -1;
223 }
224
225 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
226 cmd.hdr.cmd = command;
227 memcpy(cmd.payload, payload, length);
228
229 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
230 sigma_dut_print(dut, DUT_MSG_ERROR,
231 "failed to get wil6210 debugfs dir");
232 return -1;
233 }
234
235 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
236 f = fopen(fname, "wb");
237 if (!f) {
238 sigma_dut_print(dut, DUT_MSG_ERROR,
239 "failed to open: %s", fname);
240 return -1;
241 }
242
243 towrite = sizeof(cmd.hdr) + length;
244 written = fwrite(&cmd, 1, towrite, f);
245 fclose(f);
246 if (written != towrite) {
247 sigma_dut_print(dut, DUT_MSG_ERROR,
248 "failed to send wmi %u", command);
249 return -1;
250 }
251
252 return 0;
253}
254
255
256static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
257 const char *pattern, unsigned int *field)
258{
259 char buf[128], fname[128];
260 FILE *f;
261 regex_t re;
262 regmatch_t m[2];
263 int rc, ret = -1;
264
265 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
266 sigma_dut_print(dut, DUT_MSG_ERROR,
267 "failed to get wil6210 debugfs dir");
268 return -1;
269 }
270
271 snprintf(fname, sizeof(fname), "%s/stations", buf);
272 f = fopen(fname, "r");
273 if (!f) {
274 sigma_dut_print(dut, DUT_MSG_ERROR,
275 "failed to open: %s", fname);
276 return -1;
277 }
278
279 if (regcomp(&re, pattern, REG_EXTENDED)) {
280 sigma_dut_print(dut, DUT_MSG_ERROR,
281 "regcomp failed: %s", pattern);
282 goto out;
283 }
284
285 /*
286 * find the entry for the mac address
287 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
288 */
289 while (fgets(buf, sizeof(buf), f)) {
290 if (strcasestr(buf, bssid)) {
291 /* extract the field (CID/AID/state) */
292 rc = regexec(&re, buf, 2, m, 0);
293 if (!rc && (m[1].rm_so >= 0)) {
294 buf[m[1].rm_eo] = 0;
295 *field = atoi(&buf[m[1].rm_so]);
296 ret = 0;
297 break;
298 }
299 }
300 }
301
302 regfree(&re);
303 if (ret)
304 sigma_dut_print(dut, DUT_MSG_ERROR,
305 "could not extract field");
306
307out:
308 fclose(f);
309
310 return ret;
311}
312
313
314static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
315 unsigned int *cid)
316{
317 const char *pattern = "\\[([0-9]+)\\]";
318
319 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
320}
321
322
323static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
324 int l_rx)
325{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700326 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200327 unsigned int cid;
328
Rakesh Sunki556237d2017-03-30 14:49:31 -0700329 memset(&cmd, 0, sizeof(cmd));
330
Lior David0fe101e2017-03-09 16:09:50 +0200331 if (wil6210_get_cid(dut, mac, &cid))
332 return -1;
333
334 cmd.bf_type = WIL_WMI_BRP_RX;
335 cmd.sta_id = cid;
336 /* training length (l_rx) is ignored, FW always uses length 16 */
337 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
338 &cmd, sizeof(cmd));
339}
340
341
342static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
343{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700344 struct wil_wmi_bf_trig_cmd cmd;
345
346 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200347
348 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
349 return -1;
350
351 cmd.bf_type = WIL_WMI_SLS;
352 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
353 &cmd, sizeof(cmd));
354}
355
Lior Davidcc88b562017-01-03 18:52:09 +0200356#endif /* __linux__ */
357
358
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200359static void static_ip_file(int proto, const char *addr, const char *mask,
360 const char *gw)
361{
362 if (proto) {
363 FILE *f = fopen("static-ip", "w");
364 if (f) {
365 fprintf(f, "%d %s %s %s\n", proto, addr,
366 mask ? mask : "N/A",
367 gw ? gw : "N/A");
368 fclose(f);
369 }
370 } else {
371 unlink("static-ip");
372 }
373}
374
375
376static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
377 const char *ssid)
378{
379#ifdef __linux__
380 char buf[100];
381
382 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
383 intf, ssid);
384 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
385
386 if (system(buf) != 0) {
387 sigma_dut_print(dut, DUT_MSG_ERROR,
388 "iwpriv neighbor request failed");
389 return -1;
390 }
391
392 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
393
394 return 0;
395#else /* __linux__ */
396 return -1;
397#endif /* __linux__ */
398}
399
400
401static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530402 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200403{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530404 const char *val;
405 int reason_code = 0;
406 char buf[1024];
407
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200408 /*
409 * In the earlier builds we used WNM_QUERY and in later
410 * builds used WNM_BSS_QUERY.
411 */
412
Ashwini Patil5acd7382017-04-13 15:55:04 +0530413 val = get_param(cmd, "BTMQuery_Reason_Code");
414 if (val)
415 reason_code = atoi(val);
416
417 val = get_param(cmd, "Cand_List");
418 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
419 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
420 dut->btm_query_cand_list);
421 free(dut->btm_query_cand_list);
422 dut->btm_query_cand_list = NULL;
423 } else {
424 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
425 }
426
427 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200428 sigma_dut_print(dut, DUT_MSG_ERROR,
429 "transition management query failed");
430 return -1;
431 }
432
433 sigma_dut_print(dut, DUT_MSG_DEBUG,
434 "transition management query sent");
435
436 return 0;
437}
438
439
440int is_ip_addr(const char *str)
441{
442 const char *pos = str;
443 struct in_addr addr;
444
445 while (*pos) {
446 if (*pos != '.' && (*pos < '0' || *pos > '9'))
447 return 0;
448 pos++;
449 }
450
451 return inet_aton(str, &addr);
452}
453
454
455int is_ipv6_addr(const char *str)
456{
457 struct sockaddr_in6 addr;
458
459 return inet_pton(AF_INET6, str, &(addr.sin6_addr));
460}
461
462
463int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
464 size_t buf_len)
465{
466 char tmp[256], *pos, *pos2;
467 FILE *f;
468 char ip[16], mask[15], dns[16], sec_dns[16];
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530469 const char *str_ps;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200470 int is_dhcp = 0;
471 int s;
472#ifdef ANDROID
473 char prop[PROPERTY_VALUE_MAX];
474#endif /* ANDROID */
475
476 ip[0] = '\0';
477 mask[0] = '\0';
478 dns[0] = '\0';
479 sec_dns[0] = '\0';
480
481 s = socket(PF_INET, SOCK_DGRAM, 0);
482 if (s >= 0) {
483 struct ifreq ifr;
484 struct sockaddr_in saddr;
485
486 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700487 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200488 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
489 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
490 "%s IP address: %s",
491 ifname, strerror(errno));
492 } else {
493 memcpy(&saddr, &ifr.ifr_addr,
494 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700495 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200496 }
497
498 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
499 memcpy(&saddr, &ifr.ifr_addr,
500 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700501 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200502 }
503 close(s);
504 }
505
506#ifdef ANDROID
507 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
508 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
509 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
510 if (property_get(tmp, prop, NULL) != 0 &&
511 strcmp(prop, "ok") == 0) {
512 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
513 ifname);
514 if (property_get(tmp, prop, NULL) != 0 &&
515 strcmp(ip, prop) == 0)
516 is_dhcp = 1;
517 }
518 }
519
520 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700521 if (property_get(tmp, prop, NULL) != 0)
522 strlcpy(dns, prop, sizeof(dns));
523 else if (property_get("net.dns1", prop, NULL) != 0)
524 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200525
526 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700527 if (property_get(tmp, prop, NULL) != 0)
528 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200529#else /* ANDROID */
530#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530531 if (get_driver_type() == DRIVER_OPENWRT)
532 str_ps = "ps -w";
533 else
534 str_ps = "ps ax";
535 snprintf(tmp, sizeof(tmp),
536 "%s | grep dhclient | grep -v grep | grep -q %s",
537 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200538 if (system(tmp) == 0)
539 is_dhcp = 1;
540 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530541 snprintf(tmp, sizeof(tmp),
542 "%s | grep udhcpc | grep -v grep | grep -q %s",
543 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200544 if (system(tmp) == 0)
545 is_dhcp = 1;
546 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530547 snprintf(tmp, sizeof(tmp),
548 "%s | grep dhcpcd | grep -v grep | grep -q %s",
549 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200550 if (system(tmp) == 0)
551 is_dhcp = 1;
552 }
553 }
554#endif /* __linux__ */
555
556 f = fopen("/etc/resolv.conf", "r");
557 if (f) {
558 while (fgets(tmp, sizeof(tmp), f)) {
559 if (strncmp(tmp, "nameserver", 10) != 0)
560 continue;
561 pos = tmp + 10;
562 while (*pos == ' ' || *pos == '\t')
563 pos++;
564 pos2 = pos;
565 while (*pos2) {
566 if (*pos2 == '\n' || *pos2 == '\r') {
567 *pos2 = '\0';
568 break;
569 }
570 pos2++;
571 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700572 if (!dns[0])
573 strlcpy(dns, pos, sizeof(dns));
574 else if (!sec_dns[0])
575 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200576 }
577 fclose(f);
578 }
579#endif /* ANDROID */
580
581 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
582 is_dhcp, ip, mask, dns);
583 buf[buf_len - 1] = '\0';
584
585 return 0;
586}
587
588
589
590
591int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
592 size_t buf_len)
593{
594#ifdef __linux__
595#ifdef ANDROID
596 char cmd[200], result[1000], *pos, *end;
597 FILE *f;
598 size_t len;
599
600 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
601 f = popen(cmd, "r");
602 if (f == NULL)
603 return -1;
604 len = fread(result, 1, sizeof(result) - 1, f);
605 pclose(f);
606 if (len == 0)
607 return -1;
608 result[len] = '\0';
609 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
610
611 pos = strstr(result, "inet6 ");
612 if (pos == NULL)
613 return -1;
614 pos += 6;
615 end = strchr(pos, ' ');
616 if (end)
617 *end = '\0';
618 end = strchr(pos, '/');
619 if (end)
620 *end = '\0';
621 snprintf(buf, buf_len, "ip,%s", pos);
622 buf[buf_len - 1] = '\0';
623 return 0;
624#else /* ANDROID */
625 struct ifaddrs *ifaddr, *ifa;
626 int res, found = 0;
627 char host[NI_MAXHOST];
628
629 if (getifaddrs(&ifaddr) < 0) {
630 perror("getifaddrs");
631 return -1;
632 }
633
634 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
635 if (strcasecmp(ifname, ifa->ifa_name) != 0)
636 continue;
637 if (ifa->ifa_addr == NULL ||
638 ifa->ifa_addr->sa_family != AF_INET6)
639 continue;
640
641 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
642 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
643 if (res != 0) {
644 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
645 gai_strerror(res));
646 continue;
647 }
648 if (strncmp(host, "fe80::", 6) == 0)
649 continue; /* skip link-local */
650
651 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
652 found = 1;
653 break;
654 }
655
656 freeifaddrs(ifaddr);
657
658 if (found) {
659 char *pos;
660 pos = strchr(host, '%');
661 if (pos)
662 *pos = '\0';
663 snprintf(buf, buf_len, "ip,%s", host);
664 buf[buf_len - 1] = '\0';
665 return 0;
666 }
667
668#endif /* ANDROID */
669#endif /* __linux__ */
670 return -1;
671}
672
673
674static int cmd_sta_get_ip_config(struct sigma_dut *dut,
675 struct sigma_conn *conn,
676 struct sigma_cmd *cmd)
677{
678 const char *intf = get_param(cmd, "Interface");
679 const char *ifname;
680 char buf[200];
681 const char *val;
682 int type = 1;
683
684 if (intf == NULL)
685 return -1;
686
687 if (strcmp(intf, get_main_ifname()) == 0)
688 ifname = get_station_ifname();
689 else
690 ifname = intf;
691
692 /*
693 * UCC may assume the IP address to be available immediately after
694 * association without trying to run sta_get_ip_config multiple times.
695 * Sigma CAPI does not specify this command as a block command that
696 * would wait for the address to become available, but to pass tests
697 * more reliably, it looks like such a wait may be needed here.
698 */
699 if (wait_ip_addr(dut, ifname, 15) < 0) {
700 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
701 "for sta_get_ip_config");
702 /*
703 * Try to continue anyway since many UCC tests do not really
704 * care about the return value from here..
705 */
706 }
707
708 val = get_param(cmd, "Type");
709 if (val)
710 type = atoi(val);
711 if (type == 2 || dut->last_set_ip_config_ipv6) {
712 int i;
713
714 /*
715 * Since we do not have proper wait for IPv6 addresses, use a
716 * fixed two second delay here as a workaround for UCC script
717 * assuming IPv6 address is available when this command returns.
718 * Some scripts did not use Type,2 properly for IPv6, so include
719 * also the cases where the previous sta_set_ip_config indicated
720 * use of IPv6.
721 */
722 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
723 for (i = 0; i < 10; i++) {
724 sleep(1);
725 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
726 {
727 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
728 send_resp(dut, conn, SIGMA_COMPLETE, buf);
729#ifdef ANDROID
730 sigma_dut_print(dut, DUT_MSG_INFO,
731 "Adding IPv6 rule on Android");
732 add_ipv6_rule(dut, intf);
733#endif /* ANDROID */
734
735 return 0;
736 }
737 }
738 }
739 if (type == 1) {
740 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
741 return -2;
742 } else if (type == 2) {
743 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
744 return -2;
745 } else {
746 send_resp(dut, conn, SIGMA_ERROR,
747 "errorCode,Unsupported address type");
748 return 0;
749 }
750
751 send_resp(dut, conn, SIGMA_COMPLETE, buf);
752 return 0;
753}
754
755
756static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
757{
758#ifdef __linux__
759 char buf[200];
760 char path[128];
761 struct stat s;
762
763#ifdef ANDROID
764 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
765#else /* ANDROID */
766 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
767#endif /* ANDROID */
768 if (stat(path, &s) == 0) {
769 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
770 sigma_dut_print(dut, DUT_MSG_INFO,
771 "Kill previous DHCP client: %s", buf);
772 if (system(buf) != 0)
773 sigma_dut_print(dut, DUT_MSG_INFO,
774 "Failed to kill DHCP client");
775 unlink(path);
776 sleep(1);
777 } else {
778 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
779
780 if (stat(path, &s) == 0) {
781 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
782 sigma_dut_print(dut, DUT_MSG_INFO,
783 "Kill previous DHCP client: %s", buf);
784 if (system(buf) != 0)
785 sigma_dut_print(dut, DUT_MSG_INFO,
786 "Failed to kill DHCP client");
787 unlink(path);
788 sleep(1);
789 }
790 }
791#endif /* __linux__ */
792}
793
794
795static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
796{
797#ifdef __linux__
798 char buf[200];
799
800#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530801 if (access("/system/bin/dhcpcd", F_OK) != -1) {
802 snprintf(buf, sizeof(buf),
803 "/system/bin/dhcpcd -b %s", ifname);
804 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
805 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
806 } else {
807 sigma_dut_print(dut, DUT_MSG_ERROR,
808 "DHCP client program missing");
809 return 0;
810 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200811#else /* ANDROID */
812 snprintf(buf, sizeof(buf),
813 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
814 ifname, ifname);
815#endif /* ANDROID */
816 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
817 if (system(buf) != 0) {
818 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
819 if (system(buf) != 0) {
820 sigma_dut_print(dut, DUT_MSG_INFO,
821 "Failed to start DHCP client");
822#ifndef ANDROID
823 return -1;
824#endif /* ANDROID */
825 }
826 }
827#endif /* __linux__ */
828
829 return 0;
830}
831
832
833static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
834{
835#ifdef __linux__
836 char buf[200];
837
838 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
839 if (system(buf) != 0) {
840 sigma_dut_print(dut, DUT_MSG_INFO,
841 "Failed to clear IP addresses");
842 return -1;
843 }
844#endif /* __linux__ */
845
846 return 0;
847}
848
849
850#ifdef ANDROID
851static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
852{
853 char cmd[200], *result, *pos;
854 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530855 int tableid;
856 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200857
858 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
859 ifname);
860 fp = popen(cmd, "r");
861 if (fp == NULL)
862 return -1;
863
864 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530865 if (result == NULL) {
866 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200867 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530868 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200869
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530870 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200871 fclose(fp);
872
873 if (len == 0) {
874 free(result);
875 return -1;
876 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530877 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200878
879 pos = strstr(result, "table ");
880 if (pos == NULL) {
881 free(result);
882 return -1;
883 }
884
885 pos += strlen("table ");
886 tableid = atoi(pos);
887 if (tableid != 0) {
888 if (system("ip -6 rule del prio 22000") != 0) {
889 /* ignore any error */
890 }
891 snprintf(cmd, sizeof(cmd),
892 "ip -6 rule add from all lookup %d prio 22000",
893 tableid);
894 if (system(cmd) != 0) {
895 sigma_dut_print(dut, DUT_MSG_INFO,
896 "Failed to run %s", cmd);
897 free(result);
898 return -1;
899 }
900 } else {
901 sigma_dut_print(dut, DUT_MSG_INFO,
902 "No Valid Table Id found %s", pos);
903 free(result);
904 return -1;
905 }
906 free(result);
907
908 return 0;
909}
910#endif /* ANDROID */
911
912
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530913int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
914 const char *ip, const char *mask)
915{
916 char buf[200];
917
918 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
919 ifname, ip, mask);
920 return system(buf) == 0;
921}
922
923
924int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
925{
926 char buf[200];
927
928 if (!is_ip_addr(gw)) {
929 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
930 return -1;
931 }
932
933 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
934 if (!dut->no_ip_addr_set && system(buf) != 0) {
935 snprintf(buf, sizeof(buf), "ip ro re default via %s",
936 gw);
937 if (system(buf) != 0)
938 return 0;
939 }
940
941 return 1;
942}
943
944
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200945static int cmd_sta_set_ip_config(struct sigma_dut *dut,
946 struct sigma_conn *conn,
947 struct sigma_cmd *cmd)
948{
949 const char *intf = get_param(cmd, "Interface");
950 const char *ifname;
951 char buf[200];
952 const char *val, *ip, *mask, *gw;
953 int type = 1;
954
955 if (intf == NULL)
956 return -1;
957
958 if (strcmp(intf, get_main_ifname()) == 0)
959 ifname = get_station_ifname();
960 else
961 ifname = intf;
962
963 if (if_nametoindex(ifname) == 0) {
964 send_resp(dut, conn, SIGMA_ERROR,
965 "ErrorCode,Unknown interface");
966 return 0;
967 }
968
969 val = get_param(cmd, "Type");
970 if (val) {
971 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530972 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200973 send_resp(dut, conn, SIGMA_ERROR,
974 "ErrorCode,Unsupported address type");
975 return 0;
976 }
977 }
978
979 dut->last_set_ip_config_ipv6 = 0;
980
981 val = get_param(cmd, "dhcp");
982 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
983 static_ip_file(0, NULL, NULL, NULL);
984#ifdef __linux__
985 if (type == 2) {
986 dut->last_set_ip_config_ipv6 = 1;
987 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
988 "stateless address autoconfiguration");
989#ifdef ANDROID
990 /*
991 * This sleep is required as the assignment in case of
992 * Android is taking time and is done by the kernel.
993 * The subsequent ping for IPv6 is impacting HS20 test
994 * case.
995 */
996 sleep(2);
997 add_ipv6_rule(dut, intf);
998#endif /* ANDROID */
999 /* Assume this happens by default */
1000 return 1;
1001 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301002 if (type != 3) {
1003 kill_dhcp_client(dut, ifname);
1004 if (start_dhcp_client(dut, ifname) < 0)
1005 return -2;
1006 } else {
1007 sigma_dut_print(dut, DUT_MSG_DEBUG,
1008 "Using FILS HLP DHCPv4 Rapid Commit");
1009 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001010
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001011 return 1;
1012#endif /* __linux__ */
1013 return -2;
1014 }
1015
1016 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301017 if (!ip) {
1018 send_resp(dut, conn, SIGMA_INVALID,
1019 "ErrorCode,Missing IP address");
1020 return 0;
1021 }
1022
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301024 if (!mask) {
1025 send_resp(dut, conn, SIGMA_INVALID,
1026 "ErrorCode,Missing subnet mask");
1027 return 0;
1028 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001029
1030 if (type == 2) {
1031 int net = atoi(mask);
1032
1033 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1034 return -1;
1035
1036 if (dut->no_ip_addr_set) {
1037 snprintf(buf, sizeof(buf),
1038 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1039 ifname);
1040 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1041 if (system(buf) != 0) {
1042 sigma_dut_print(dut, DUT_MSG_DEBUG,
1043 "Failed to disable IPv6 address before association");
1044 }
1045 } else {
1046 snprintf(buf, sizeof(buf),
1047 "ip -6 addr del %s/%s dev %s",
1048 ip, mask, ifname);
1049 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1050 if (system(buf) != 0) {
1051 /*
1052 * This command may fail if the address being
1053 * deleted does not exist. Inaction here is
1054 * intentional.
1055 */
1056 }
1057
1058 snprintf(buf, sizeof(buf),
1059 "ip -6 addr add %s/%s dev %s",
1060 ip, mask, ifname);
1061 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1062 if (system(buf) != 0) {
1063 send_resp(dut, conn, SIGMA_ERROR,
1064 "ErrorCode,Failed to set IPv6 address");
1065 return 0;
1066 }
1067 }
1068
1069 dut->last_set_ip_config_ipv6 = 1;
1070 static_ip_file(6, ip, mask, NULL);
1071 return 1;
1072 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301073 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001074 return -1;
1075 }
1076
1077 kill_dhcp_client(dut, ifname);
1078
1079 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301080 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001081 send_resp(dut, conn, SIGMA_ERROR,
1082 "ErrorCode,Failed to set IP address");
1083 return 0;
1084 }
1085 }
1086
1087 gw = get_param(cmd, "defaultGateway");
1088 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301089 if (set_ipv4_gw(dut, gw) < 1) {
1090 send_resp(dut, conn, SIGMA_ERROR,
1091 "ErrorCode,Failed to set default gateway");
1092 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001093 }
1094 }
1095
1096 val = get_param(cmd, "primary-dns");
1097 if (val) {
1098 /* TODO */
1099 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1100 "setting", val);
1101 }
1102
1103 val = get_param(cmd, "secondary-dns");
1104 if (val) {
1105 /* TODO */
1106 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1107 "setting", val);
1108 }
1109
1110 static_ip_file(4, ip, mask, gw);
1111
1112 return 1;
1113}
1114
1115
1116static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1117 struct sigma_cmd *cmd)
1118{
1119 /* const char *intf = get_param(cmd, "Interface"); */
1120 /* TODO: could report more details here */
1121 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1122 return 0;
1123}
1124
1125
1126static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1127 struct sigma_conn *conn,
1128 struct sigma_cmd *cmd)
1129{
1130 /* const char *intf = get_param(cmd, "Interface"); */
1131 char addr[20], resp[50];
1132
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301133 if (dut->dev_role == DEVROLE_STA_CFON)
1134 return sta_cfon_get_mac_address(dut, conn, cmd);
1135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001136 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1137 < 0)
1138 return -2;
1139
1140 snprintf(resp, sizeof(resp), "mac,%s", addr);
1141 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1142 return 0;
1143}
1144
1145
1146static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1147 struct sigma_cmd *cmd)
1148{
1149 /* const char *intf = get_param(cmd, "Interface"); */
1150 int connected = 0;
1151 char result[32];
1152 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1153 sizeof(result)) < 0) {
1154 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1155 "%s status", get_station_ifname());
1156 return -2;
1157 }
1158
1159 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1160 if (strncmp(result, "COMPLETED", 9) == 0)
1161 connected = 1;
1162
1163 if (connected)
1164 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1165 else
1166 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1167
1168 return 0;
1169}
1170
1171
1172static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1173 struct sigma_conn *conn,
1174 struct sigma_cmd *cmd)
1175{
1176 /* const char *intf = get_param(cmd, "Interface"); */
1177 const char *dst, *timeout;
1178 int wait_time = 90;
1179 char buf[100];
1180 int res;
1181
1182 dst = get_param(cmd, "destination");
1183 if (dst == NULL || !is_ip_addr(dst))
1184 return -1;
1185
1186 timeout = get_param(cmd, "timeout");
1187 if (timeout) {
1188 wait_time = atoi(timeout);
1189 if (wait_time < 1)
1190 wait_time = 1;
1191 }
1192
1193 /* TODO: force renewal of IP lease if DHCP is enabled */
1194
1195 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1196 res = system(buf);
1197 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1198 if (res == 0)
1199 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1200 else if (res == 256)
1201 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1202 else
1203 return -2;
1204
1205 return 0;
1206}
1207
1208
1209static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1210 struct sigma_cmd *cmd)
1211{
1212 /* const char *intf = get_param(cmd, "Interface"); */
1213 char bssid[20], resp[50];
1214
1215 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1216 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001217 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001218
1219 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1220 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1221 return 0;
1222}
1223
1224
1225#ifdef __SAMSUNG__
1226static int add_use_network(const char *ifname)
1227{
1228 char buf[100];
1229
1230 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1231 wpa_command(ifname, buf);
1232 return 0;
1233}
1234#endif /* __SAMSUNG__ */
1235
1236
1237static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1238 const char *ifname, struct sigma_cmd *cmd)
1239{
1240 const char *ssid = get_param(cmd, "ssid");
1241 int id;
1242 const char *val;
1243
1244 if (ssid == NULL)
1245 return -1;
1246
1247 start_sta_mode(dut);
1248
1249#ifdef __SAMSUNG__
1250 add_use_network(ifname);
1251#endif /* __SAMSUNG__ */
1252
1253 id = add_network(ifname);
1254 if (id < 0)
1255 return -2;
1256 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1257
1258 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1259 return -2;
1260
1261 dut->infra_network_id = id;
1262 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1263
1264 val = get_param(cmd, "program");
1265 if (!val)
1266 val = get_param(cmd, "prog");
1267 if (val && strcasecmp(val, "hs2") == 0) {
1268 char buf[100];
1269 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1270 wpa_command(ifname, buf);
1271
1272 val = get_param(cmd, "prefer");
1273 if (val && atoi(val) > 0)
1274 set_network(ifname, id, "priority", "1");
1275 }
1276
1277 return id;
1278}
1279
1280
1281static int cmd_sta_set_encryption(struct sigma_dut *dut,
1282 struct sigma_conn *conn,
1283 struct sigma_cmd *cmd)
1284{
1285 const char *intf = get_param(cmd, "Interface");
1286 const char *ssid = get_param(cmd, "ssid");
1287 const char *type = get_param(cmd, "encpType");
1288 const char *ifname;
1289 char buf[200];
1290 int id;
1291
1292 if (intf == NULL || ssid == NULL)
1293 return -1;
1294
1295 if (strcmp(intf, get_main_ifname()) == 0)
1296 ifname = get_station_ifname();
1297 else
1298 ifname = intf;
1299
1300 id = add_network_common(dut, conn, ifname, cmd);
1301 if (id < 0)
1302 return id;
1303
1304 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1305 return -2;
1306
1307 if (type && strcasecmp(type, "wep") == 0) {
1308 const char *val;
1309 int i;
1310
1311 val = get_param(cmd, "activeKey");
1312 if (val) {
1313 int keyid;
1314 keyid = atoi(val);
1315 if (keyid < 1 || keyid > 4)
1316 return -1;
1317 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1318 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1319 return -2;
1320 }
1321
1322 for (i = 0; i < 4; i++) {
1323 snprintf(buf, sizeof(buf), "key%d", i + 1);
1324 val = get_param(cmd, buf);
1325 if (val == NULL)
1326 continue;
1327 snprintf(buf, sizeof(buf), "wep_key%d", i);
1328 if (set_network(ifname, id, buf, val) < 0)
1329 return -2;
1330 }
1331 }
1332
1333 return 1;
1334}
1335
1336
1337static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1338 const char *ifname, struct sigma_cmd *cmd)
1339{
1340 const char *val;
1341 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001342 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001343 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301344 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001345
1346 id = add_network_common(dut, conn, ifname, cmd);
1347 if (id < 0)
1348 return id;
1349
Jouni Malinen47dcc952017-10-09 16:43:24 +03001350 val = get_param(cmd, "Type");
1351 owe = val && strcasecmp(val, "OWE") == 0;
1352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001353 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001354 if (!val && owe)
1355 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001356 if (val == NULL) {
1357 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1358 return 0;
1359 }
1360 if (strcasecmp(val, "wpa") == 0 ||
1361 strcasecmp(val, "wpa-psk") == 0) {
1362 if (set_network(ifname, id, "proto", "WPA") < 0)
1363 return -2;
1364 } else if (strcasecmp(val, "wpa2") == 0 ||
1365 strcasecmp(val, "wpa2-psk") == 0 ||
1366 strcasecmp(val, "wpa2-ft") == 0 ||
1367 strcasecmp(val, "wpa2-sha256") == 0) {
1368 if (set_network(ifname, id, "proto", "WPA2") < 0)
1369 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301370 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1371 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001372 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1373 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001374 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301375 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001376 if (set_network(ifname, id, "proto", "WPA2") < 0)
1377 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001378 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001379 } else {
1380 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1381 return 0;
1382 }
1383
1384 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001385 if (val) {
1386 cipher_set = 1;
1387 if (strcasecmp(val, "tkip") == 0) {
1388 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1389 return -2;
1390 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1391 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1392 return -2;
1393 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1394 if (set_network(ifname, id, "pairwise",
1395 "CCMP TKIP") < 0)
1396 return -2;
1397 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1398 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1399 return -2;
1400 if (set_network(ifname, id, "group", "GCMP") < 0)
1401 return -2;
1402 } else {
1403 send_resp(dut, conn, SIGMA_ERROR,
1404 "errorCode,Unrecognized encpType value");
1405 return 0;
1406 }
1407 }
1408
1409 val = get_param(cmd, "PairwiseCipher");
1410 if (val) {
1411 cipher_set = 1;
1412 /* TODO: Support space separated list */
1413 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1414 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1415 return -2;
1416 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1417 if (set_network(ifname, id, "pairwise",
1418 "CCMP-256") < 0)
1419 return -2;
1420 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1421 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1422 return -2;
1423 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1424 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1425 return -2;
1426 } else {
1427 send_resp(dut, conn, SIGMA_ERROR,
1428 "errorCode,Unrecognized PairwiseCipher value");
1429 return 0;
1430 }
1431 }
1432
Jouni Malinen47dcc952017-10-09 16:43:24 +03001433 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001434 send_resp(dut, conn, SIGMA_ERROR,
1435 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001436 return 0;
1437 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001438
1439 val = get_param(cmd, "GroupCipher");
1440 if (val) {
1441 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1442 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1443 return -2;
1444 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1445 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1446 return -2;
1447 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1448 if (set_network(ifname, id, "group", "GCMP") < 0)
1449 return -2;
1450 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1451 if (set_network(ifname, id, "group", "CCMP") < 0)
1452 return -2;
1453 } else {
1454 send_resp(dut, conn, SIGMA_ERROR,
1455 "errorCode,Unrecognized GroupCipher value");
1456 return 0;
1457 }
1458 }
1459
Jouni Malinen7b239522017-09-14 21:37:18 +03001460 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001461 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001462 const char *cipher;
1463
1464 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1465 cipher = "BIP-GMAC-256";
1466 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1467 cipher = "BIP-CMAC-256";
1468 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1469 cipher = "BIP-GMAC-128";
1470 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1471 cipher = "AES-128-CMAC";
1472 } else {
1473 send_resp(dut, conn, SIGMA_INVALID,
1474 "errorCode,Unsupported GroupMgntCipher");
1475 return 0;
1476 }
1477 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1478 send_resp(dut, conn, SIGMA_INVALID,
1479 "errorCode,Failed to set GroupMgntCipher");
1480 return 0;
1481 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001482 }
1483
1484 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301485
1486 if (dut->program == PROGRAM_OCE) {
1487 dut->sta_pmf = STA_PMF_OPTIONAL;
1488 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1489 return -2;
1490 }
1491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001492 val = get_param(cmd, "PMF");
1493 if (val) {
1494 if (strcasecmp(val, "Required") == 0 ||
1495 strcasecmp(val, "Forced_Required") == 0) {
1496 dut->sta_pmf = STA_PMF_REQUIRED;
1497 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1498 return -2;
1499 } else if (strcasecmp(val, "Optional") == 0) {
1500 dut->sta_pmf = STA_PMF_OPTIONAL;
1501 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1502 return -2;
1503 } else if (strcasecmp(val, "Disabled") == 0 ||
1504 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",
2712 channel_to_freq(atoi(chan)));
2713 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];
3287
3288 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3289 if (system(buf) != 0) {
3290 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3291 return -1;
3292 }
3293
3294 return 0;
3295}
3296
3297
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003298static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3299 const char *val)
3300{
3301 char buf[60];
3302
3303 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3304 if (system(buf) != 0) {
3305 sigma_dut_print(dut, DUT_MSG_ERROR,
3306 "iwpriv tx_stbc failed");
3307 }
3308
3309 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3310 if (system(buf) != 0) {
3311 sigma_dut_print(dut, DUT_MSG_ERROR,
3312 "iwpriv rx_stbc failed");
3313 }
3314}
3315
3316
3317static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3318 const char *val)
3319{
3320 char buf[60];
3321
Peng Xucc317ed2017-05-18 16:44:37 -07003322 if (strcmp(val, "160") == 0) {
3323 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3324 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003325 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3326 } else if (strcmp(val, "40") == 0) {
3327 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3328 } else if (strcmp(val, "20") == 0) {
3329 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3330 } else if (strcasecmp(val, "Auto") == 0) {
3331 buf[0] = '\0';
3332 } else {
3333 sigma_dut_print(dut, DUT_MSG_ERROR,
3334 "WIDTH/CTS_WIDTH value not supported");
3335 return -1;
3336 }
3337
3338 if (buf[0] != '\0' && system(buf) != 0) {
3339 sigma_dut_print(dut, DUT_MSG_ERROR,
3340 "Failed to set WIDTH/CTS_WIDTH");
3341 return -1;
3342 }
3343
3344 return 0;
3345}
3346
3347
3348int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3349 const char *intf, const char *val)
3350{
3351 char buf[60];
3352
3353 if (strcasecmp(val, "Auto") == 0) {
3354 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3355 dut->chwidth = 0;
3356 } else if (strcasecmp(val, "20") == 0) {
3357 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3358 dut->chwidth = 0;
3359 } else if (strcasecmp(val, "40") == 0) {
3360 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3361 dut->chwidth = 1;
3362 } else if (strcasecmp(val, "80") == 0) {
3363 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3364 dut->chwidth = 2;
3365 } else if (strcasecmp(val, "160") == 0) {
3366 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3367 dut->chwidth = 3;
3368 } else {
3369 send_resp(dut, conn, SIGMA_ERROR,
3370 "ErrorCode,WIDTH not supported");
3371 return -1;
3372 }
3373
3374 if (system(buf) != 0) {
3375 sigma_dut_print(dut, DUT_MSG_ERROR,
3376 "iwpriv chwidth failed");
3377 }
3378
3379 return 0;
3380}
3381
3382
3383static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3384 const char *val)
3385{
3386 char buf[60];
3387
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003388 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003389 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003390 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003391 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
3392 } else {
3393 sigma_dut_print(dut, DUT_MSG_ERROR,
3394 "SP_STREAM value not supported");
3395 return -1;
3396 }
3397
3398 if (system(buf) != 0) {
3399 sigma_dut_print(dut, DUT_MSG_ERROR,
3400 "Failed to set SP_STREAM");
3401 return -1;
3402 }
3403
3404 return 0;
3405}
3406
3407
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303408static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3409 const char *val)
3410{
3411 char buf[60];
3412
3413 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3414 if (system(buf) != 0)
3415 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3416
3417 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3418 if (system(buf) != 0)
3419 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3420}
3421
3422
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303423static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3424 struct sigma_conn *conn,
3425 const char *intf, int capa)
3426{
3427 char buf[32];
3428
3429 if (capa > 0 && capa < 4) {
3430 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3431 if (wpa_command(intf, buf) < 0) {
3432 send_resp(dut, conn, SIGMA_ERROR,
3433 "ErrorCode, Failed to set cellular data capability");
3434 return 0;
3435 }
3436 return 1;
3437 }
3438
3439 sigma_dut_print(dut, DUT_MSG_ERROR,
3440 "Invalid Cellular data capability: %d", capa);
3441 send_resp(dut, conn, SIGMA_INVALID,
3442 "ErrorCode,Invalid cellular data capability");
3443 return 0;
3444}
3445
3446
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303447static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3448 const char *intf, const char *val)
3449{
3450 if (strcasecmp(val, "Disable") == 0) {
3451 if (wpa_command(intf, "SET roaming 0") < 0) {
3452 send_resp(dut, conn, SIGMA_ERROR,
3453 "ErrorCode,Failed to disable roaming");
3454 return 0;
3455 }
3456 return 1;
3457 }
3458
3459 if (strcasecmp(val, "Enable") == 0) {
3460 if (wpa_command(intf, "SET roaming 1") < 0) {
3461 send_resp(dut, conn, SIGMA_ERROR,
3462 "ErrorCode,Failed to enable roaming");
3463 return 0;
3464 }
3465 return 1;
3466 }
3467
3468 sigma_dut_print(dut, DUT_MSG_ERROR,
3469 "Invalid value provided for roaming: %s", val);
3470 send_resp(dut, conn, SIGMA_INVALID,
3471 "ErrorCode,Unknown value provided for Roaming");
3472 return 0;
3473}
3474
3475
Ashwini Patila75de5a2017-04-13 16:35:05 +05303476static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3477 struct sigma_conn *conn,
3478 const char *intf, const char *val)
3479{
3480 if (strcasecmp(val, "Disable") == 0) {
3481 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3482 send_resp(dut, conn, SIGMA_ERROR,
3483 "ErrorCode,Failed to disable Assoc_disallow");
3484 return 0;
3485 }
3486 return 1;
3487 }
3488
3489 if (strcasecmp(val, "Enable") == 0) {
3490 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3491 send_resp(dut, conn, SIGMA_ERROR,
3492 "ErrorCode,Failed to enable Assoc_disallow");
3493 return 0;
3494 }
3495 return 1;
3496 }
3497
3498 sigma_dut_print(dut, DUT_MSG_ERROR,
3499 "Invalid value provided for Assoc_disallow: %s", val);
3500 send_resp(dut, conn, SIGMA_INVALID,
3501 "ErrorCode,Unknown value provided for Assoc_disallow");
3502 return 0;
3503}
3504
3505
Ashwini Patilc63161e2017-04-13 16:30:23 +05303506static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3507 const char *intf, const char *val)
3508{
3509 if (strcasecmp(val, "Reject") == 0) {
3510 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3511 send_resp(dut, conn, SIGMA_ERROR,
3512 "ErrorCode,Failed to Reject BTM Request");
3513 return 0;
3514 }
3515 return 1;
3516 }
3517
3518 if (strcasecmp(val, "Accept") == 0) {
3519 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3520 send_resp(dut, conn, SIGMA_ERROR,
3521 "ErrorCode,Failed to Accept BTM Request");
3522 return 0;
3523 }
3524 return 1;
3525 }
3526
3527 sigma_dut_print(dut, DUT_MSG_ERROR,
3528 "Invalid value provided for BSS_Transition: %s", val);
3529 send_resp(dut, conn, SIGMA_INVALID,
3530 "ErrorCode,Unknown value provided for BSS_Transition");
3531 return 0;
3532}
3533
3534
Ashwini Patil00402582017-04-13 12:29:39 +05303535static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3536 struct sigma_conn *conn,
3537 const char *intf,
3538 struct sigma_cmd *cmd)
3539{
3540 const char *ch, *pref, *op_class, *reason;
3541 char buf[120];
3542 int len, ret;
3543
3544 pref = get_param(cmd, "Ch_Pref");
3545 if (!pref)
3546 return 1;
3547
3548 if (strcasecmp(pref, "clear") == 0) {
3549 free(dut->non_pref_ch_list);
3550 dut->non_pref_ch_list = NULL;
3551 } else {
3552 op_class = get_param(cmd, "Ch_Op_Class");
3553 if (!op_class) {
3554 send_resp(dut, conn, SIGMA_INVALID,
3555 "ErrorCode,Ch_Op_Class not provided");
3556 return 0;
3557 }
3558
3559 ch = get_param(cmd, "Ch_Pref_Num");
3560 if (!ch) {
3561 send_resp(dut, conn, SIGMA_INVALID,
3562 "ErrorCode,Ch_Pref_Num not provided");
3563 return 0;
3564 }
3565
3566 reason = get_param(cmd, "Ch_Reason_Code");
3567 if (!reason) {
3568 send_resp(dut, conn, SIGMA_INVALID,
3569 "ErrorCode,Ch_Reason_Code not provided");
3570 return 0;
3571 }
3572
3573 if (!dut->non_pref_ch_list) {
3574 dut->non_pref_ch_list =
3575 calloc(1, NON_PREF_CH_LIST_SIZE);
3576 if (!dut->non_pref_ch_list) {
3577 send_resp(dut, conn, SIGMA_ERROR,
3578 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3579 return 0;
3580 }
3581 }
3582 len = strlen(dut->non_pref_ch_list);
3583 ret = snprintf(dut->non_pref_ch_list + len,
3584 NON_PREF_CH_LIST_SIZE - len,
3585 " %s:%s:%s:%s", op_class, ch, pref, reason);
3586 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3587 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3588 dut->non_pref_ch_list);
3589 } else {
3590 sigma_dut_print(dut, DUT_MSG_ERROR,
3591 "snprintf failed for non_pref_list, ret = %d",
3592 ret);
3593 send_resp(dut, conn, SIGMA_ERROR,
3594 "ErrorCode,snprintf failed");
3595 free(dut->non_pref_ch_list);
3596 dut->non_pref_ch_list = NULL;
3597 return 0;
3598 }
3599 }
3600
3601 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3602 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3603 if (ret < 0 || ret >= (int) sizeof(buf)) {
3604 sigma_dut_print(dut, DUT_MSG_DEBUG,
3605 "snprintf failed for set non_pref_chan, ret: %d",
3606 ret);
3607 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3608 return 0;
3609 }
3610
3611 if (wpa_command(intf, buf) < 0) {
3612 send_resp(dut, conn, SIGMA_ERROR,
3613 "ErrorCode,Failed to set non-preferred channel list");
3614 return 0;
3615 }
3616
3617 return 1;
3618}
3619
3620
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003621#ifdef NL80211_SUPPORT
3622static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3623 enum he_fragmentation_val frag)
3624{
3625 struct nl_msg *msg;
3626 int ret = 0;
3627 struct nlattr *params;
3628 int ifindex;
3629
3630 ifindex = if_nametoindex(intf);
3631 if (ifindex == 0) {
3632 sigma_dut_print(dut, DUT_MSG_ERROR,
3633 "%s: Index for interface %s failed",
3634 __func__, intf);
3635 return -1;
3636 }
3637
3638 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3639 NL80211_CMD_VENDOR)) ||
3640 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3641 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3642 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3643 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3644 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3645 nla_put_u8(msg,
3646 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3647 frag)) {
3648 sigma_dut_print(dut, DUT_MSG_ERROR,
3649 "%s: err in adding vendor_cmd and vendor_data",
3650 __func__);
3651 nlmsg_free(msg);
3652 return -1;
3653 }
3654 nla_nest_end(msg, params);
3655
3656 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3657 if (ret) {
3658 sigma_dut_print(dut, DUT_MSG_ERROR,
3659 "%s: err in send_and_recv_msgs, ret=%d",
3660 __func__, ret);
3661 }
3662 return ret;
3663}
3664#endif /* NL80211_SUPPORT */
3665
3666
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003667static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3668 struct sigma_conn *conn,
3669 struct sigma_cmd *cmd)
3670{
3671 const char *intf = get_param(cmd, "Interface");
3672 const char *val;
3673
3674 val = get_param(cmd, "Program");
Peng Xue9fa7952017-05-09 15:59:49 -07003675 if (val && strcasecmp(val, "HS2-R2") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003676 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3677 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003678
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003679 if (val && strcasecmp(val, "LOC") == 0)
3680 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3681
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003682#ifdef ANDROID_NAN
3683 if (val && strcasecmp(val, "NAN") == 0)
3684 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3685#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003686#ifdef MIRACAST
3687 if (val && (strcasecmp(val, "WFD") == 0 ||
3688 strcasecmp(val, "DisplayR2") == 0))
3689 return miracast_preset_testparameters(dut, conn, cmd);
3690#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003691
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303692 if (val && strcasecmp(val, "MBO") == 0) {
3693 val = get_param(cmd, "Cellular_Data_Cap");
3694 if (val &&
3695 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3696 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303697
3698 val = get_param(cmd, "Ch_Pref");
3699 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3700 return 0;
3701
Ashwini Patilc63161e2017-04-13 16:30:23 +05303702 val = get_param(cmd, "BSS_Transition");
3703 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3704 return 0;
3705
Ashwini Patila75de5a2017-04-13 16:35:05 +05303706 val = get_param(cmd, "Assoc_Disallow");
3707 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3708 return 0;
3709
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303710 val = get_param(cmd, "Roaming");
3711 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3712 return 0;
3713
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303714 return 1;
3715 }
3716
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303717 if (val && strcasecmp(val, "OCE") == 0)
3718 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003720#if 0
3721 val = get_param(cmd, "Supplicant");
3722 if (val && strcasecmp(val, "Default") != 0) {
3723 send_resp(dut, conn, SIGMA_ERROR,
3724 "ErrorCode,Only default(Vendor) supplicant "
3725 "supported");
3726 return 0;
3727 }
3728#endif
3729
3730 val = get_param(cmd, "RTS");
3731 if (val) {
3732 switch (get_driver_type()) {
3733 case DRIVER_ATHEROS:
3734 ath_sta_set_rts(dut, intf, val);
3735 break;
3736 default:
3737#if 0
3738 send_resp(dut, conn, SIGMA_ERROR,
3739 "ErrorCode,Setting RTS not supported");
3740 return 0;
3741#else
3742 sigma_dut_print(dut, DUT_MSG_DEBUG,
3743 "Setting RTS not supported");
3744 break;
3745#endif
3746 }
3747 }
3748
3749#if 0
3750 val = get_param(cmd, "FRGMNT");
3751 if (val) {
3752 /* TODO */
3753 send_resp(dut, conn, SIGMA_ERROR,
3754 "ErrorCode,Setting FRGMNT not supported");
3755 return 0;
3756 }
3757#endif
3758
3759#if 0
3760 val = get_param(cmd, "Preamble");
3761 if (val) {
3762 /* TODO: Long/Short */
3763 send_resp(dut, conn, SIGMA_ERROR,
3764 "ErrorCode,Setting Preamble not supported");
3765 return 0;
3766 }
3767#endif
3768
3769 val = get_param(cmd, "Mode");
3770 if (val) {
3771 if (strcmp(val, "11b") == 0 ||
3772 strcmp(val, "11g") == 0 ||
3773 strcmp(val, "11a") == 0 ||
3774 strcmp(val, "11n") == 0 ||
3775 strcmp(val, "11ng") == 0 ||
3776 strcmp(val, "11nl") == 0 ||
3777 strcmp(val, "11nl(nabg)") == 0 ||
3778 strcmp(val, "AC") == 0 ||
3779 strcmp(val, "11AC") == 0 ||
3780 strcmp(val, "11ac") == 0 ||
3781 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003782 strcmp(val, "11an") == 0 ||
3783 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003784 /* STA supports all modes by default */
3785 } else {
3786 send_resp(dut, conn, SIGMA_ERROR,
3787 "ErrorCode,Setting Mode not supported");
3788 return 0;
3789 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003790
3791 /* Change the mode only in case of testbed for HE program
3792 * and for 11a and 11g modes only. */
3793 if (dut->program == PROGRAM_HE &&
3794 dut->device_type == STA_testbed) {
3795 int phymode;
3796 char buf[60];
3797
3798 if (strcmp(val, "11a") == 0) {
3799 phymode = 1;
3800 } else if (strcmp (val, "11g") == 0) {
3801 phymode = 3;
3802 } else {
3803 sigma_dut_print(dut, DUT_MSG_DEBUG,
3804 "Ignoring mode change for mode: %s",
3805 val);
3806 phymode = -1;
3807 }
3808 if (phymode != -1) {
3809 snprintf(buf, sizeof(buf),
3810 "iwpriv %s setphymode %d",
3811 intf, phymode);
3812 if (system(buf) != 0) {
3813 sigma_dut_print(dut, DUT_MSG_ERROR,
3814 "iwpriv setting of phymode failed");
3815 }
3816 }
3817 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003818 }
3819
3820 val = get_param(cmd, "wmm");
3821 if (val) {
3822 switch (get_driver_type()) {
3823 case DRIVER_ATHEROS:
3824 ath_sta_set_wmm(dut, intf, val);
3825 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003826 case DRIVER_WCN:
3827 wcn_sta_set_wmm(dut, intf, val);
3828 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003829 default:
3830 sigma_dut_print(dut, DUT_MSG_DEBUG,
3831 "Setting wmm not supported");
3832 break;
3833 }
3834 }
3835
3836 val = get_param(cmd, "Powersave");
3837 if (val) {
3838 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3839 if (wpa_command(get_station_ifname(),
3840 "P2P_SET ps 0") < 0)
3841 return -2;
3842 /* Make sure test modes are disabled */
3843 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3844 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3845 } else if (strcmp(val, "1") == 0 ||
3846 strcasecmp(val, "PSPoll") == 0 ||
3847 strcasecmp(val, "on") == 0) {
3848 /* Disable default power save mode */
3849 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3850 /* Enable PS-Poll test mode */
3851 if (wpa_command(get_station_ifname(),
3852 "P2P_SET ps 97") < 0 ||
3853 wpa_command(get_station_ifname(),
3854 "P2P_SET ps 99") < 0)
3855 return -2;
3856 } else if (strcmp(val, "2") == 0 ||
3857 strcasecmp(val, "Fast") == 0) {
3858 /* TODO */
3859 send_resp(dut, conn, SIGMA_ERROR,
3860 "ErrorCode,Powersave=Fast not supported");
3861 return 0;
3862 } else if (strcmp(val, "3") == 0 ||
3863 strcasecmp(val, "PSNonPoll") == 0) {
3864 /* Make sure test modes are disabled */
3865 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3866 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3867
3868 /* Enable default power save mode */
3869 if (wpa_command(get_station_ifname(),
3870 "P2P_SET ps 1") < 0)
3871 return -2;
3872 } else
3873 return -1;
3874 }
3875
3876 val = get_param(cmd, "NoAck");
3877 if (val) {
3878 switch (get_driver_type()) {
3879 case DRIVER_ATHEROS:
3880 ath_sta_set_noack(dut, intf, val);
3881 break;
3882 default:
3883 send_resp(dut, conn, SIGMA_ERROR,
3884 "ErrorCode,Setting NoAck not supported");
3885 return 0;
3886 }
3887 }
3888
3889 val = get_param(cmd, "IgnoreChswitchProhibit");
3890 if (val) {
3891 /* TODO: Enabled/disabled */
3892 if (strcasecmp(val, "Enabled") == 0) {
3893 send_resp(dut, conn, SIGMA_ERROR,
3894 "ErrorCode,Enabling IgnoreChswitchProhibit "
3895 "not supported");
3896 return 0;
3897 }
3898 }
3899
3900 val = get_param(cmd, "TDLS");
3901 if (val) {
3902 if (strcasecmp(val, "Disabled") == 0) {
3903 if (wpa_command(intf, "SET tdls_disabled 1")) {
3904 send_resp(dut, conn, SIGMA_ERROR,
3905 "ErrorCode,Failed to disable TDLS");
3906 return 0;
3907 }
3908 } else if (strcasecmp(val, "Enabled") == 0) {
3909 if (wpa_command(intf, "SET tdls_disabled 0")) {
3910 send_resp(dut, conn, SIGMA_ERROR,
3911 "ErrorCode,Failed to enable TDLS");
3912 return 0;
3913 }
3914 } else {
3915 send_resp(dut, conn, SIGMA_ERROR,
3916 "ErrorCode,Unsupported TDLS value");
3917 return 0;
3918 }
3919 }
3920
3921 val = get_param(cmd, "TDLSmode");
3922 if (val) {
3923 if (strcasecmp(val, "Default") == 0) {
3924 wpa_command(intf, "SET tdls_testing 0");
3925 } else if (strcasecmp(val, "APProhibit") == 0) {
3926 if (wpa_command(intf, "SET tdls_testing 0x400")) {
3927 send_resp(dut, conn, SIGMA_ERROR,
3928 "ErrorCode,Failed to enable ignore "
3929 "APProhibit TDLS mode");
3930 return 0;
3931 }
3932 } else if (strcasecmp(val, "HiLoMac") == 0) {
3933 /* STA should respond with TDLS setup req for a TDLS
3934 * setup req */
3935 if (wpa_command(intf, "SET tdls_testing 0x80")) {
3936 send_resp(dut, conn, SIGMA_ERROR,
3937 "ErrorCode,Failed to enable HiLoMac "
3938 "TDLS mode");
3939 return 0;
3940 }
3941 } else if (strcasecmp(val, "WeakSecurity") == 0) {
3942 /*
3943 * Since all security modes are enabled by default when
3944 * Sigma control is used, there is no need to do
3945 * anything here.
3946 */
3947 } else if (strcasecmp(val, "ExistLink") == 0) {
3948 /*
3949 * Since we allow new TDLS Setup Request even if there
3950 * is an existing link, nothing needs to be done for
3951 * this.
3952 */
3953 } else {
3954 /* TODO:
3955 * ExistLink: STA should send TDLS setup req even if
3956 * direct link already exists
3957 */
3958 send_resp(dut, conn, SIGMA_ERROR,
3959 "ErrorCode,Unsupported TDLSmode value");
3960 return 0;
3961 }
3962 }
3963
3964 val = get_param(cmd, "FakePubKey");
3965 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
3966 send_resp(dut, conn, SIGMA_ERROR,
3967 "ErrorCode,Failed to enable FakePubKey");
3968 return 0;
3969 }
3970
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08003971#ifdef NL80211_SUPPORT
3972 val = get_param(cmd, "FrgmntSupport");
3973 if (val) {
3974 if (strcasecmp(val, "Enable") == 0) {
3975 if (sta_set_he_fragmentation(dut, intf,
3976 HE_FRAG_LEVEL1)) {
3977 send_resp(dut, conn, SIGMA_ERROR,
3978 "ErrorCode,Failed to enable HE Fragmentation");
3979 return 0;
3980 }
3981 } else if (strcasecmp(val, "Disable") == 0) {
3982 if (sta_set_he_fragmentation(dut, intf,
3983 HE_FRAG_DISABLE)) {
3984 send_resp(dut, conn, SIGMA_ERROR,
3985 "ErrorCode,Failed to disable HE Fragmentation");
3986 return 0;
3987 }
3988 }
3989 }
3990#endif /* NL80211_SUPPORT */
3991
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003992 return 1;
3993}
3994
3995
3996static const char * ath_get_radio_name(const char *radio_name)
3997{
3998 if (radio_name == NULL)
3999 return "wifi0";
4000 if (strcmp(radio_name, "wifi1") == 0)
4001 return "wifi1";
4002 if (strcmp(radio_name, "wifi2") == 0)
4003 return "wifi2";
4004 return "wifi0";
4005}
4006
4007
4008static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4009 const char *val)
4010{
4011 char buf[60];
4012 unsigned int vht_mcsmap = 0;
4013 int txchainmask = 0;
4014 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4015
4016 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4017 if (dut->testbed_flag_txsp == 1) {
4018 vht_mcsmap = 0xfffc;
4019 dut->testbed_flag_txsp = 0;
4020 } else {
4021 vht_mcsmap = 0xfffe;
4022 }
4023 txchainmask = 1;
4024 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4025 if (dut->testbed_flag_txsp == 1) {
4026 vht_mcsmap = 0xfff0;
4027 dut->testbed_flag_txsp = 0;
4028 } else {
4029 vht_mcsmap = 0xfffa;
4030 }
4031 txchainmask = 3;
4032 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4033 if (dut->testbed_flag_txsp == 1) {
4034 vht_mcsmap = 0xffc0;
4035 dut->testbed_flag_txsp = 0;
4036 } else {
4037 vht_mcsmap = 0xffea;
4038 }
4039 txchainmask = 7;
4040 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4041 if (dut->testbed_flag_txsp == 1) {
4042 vht_mcsmap = 0xff00;
4043 dut->testbed_flag_txsp = 0;
4044 } else {
4045 vht_mcsmap = 0xffaa;
4046 }
4047 txchainmask = 15;
4048 } else {
4049 if (dut->testbed_flag_txsp == 1) {
4050 vht_mcsmap = 0xffc0;
4051 dut->testbed_flag_txsp = 0;
4052 } else {
4053 vht_mcsmap = 0xffea;
4054 }
4055 }
4056
4057 if (txchainmask) {
4058 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4059 basedev, txchainmask);
4060 if (system(buf) != 0) {
4061 sigma_dut_print(dut, DUT_MSG_ERROR,
4062 "iwpriv txchainmask failed");
4063 }
4064 }
4065
4066 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4067 intf, vht_mcsmap);
4068 if (system(buf) != 0) {
4069 sigma_dut_print(dut, DUT_MSG_ERROR,
4070 "iwpriv %s vht_mcsmap 0x%04x failed",
4071 intf, vht_mcsmap);
4072 }
4073}
4074
4075
4076static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4077 const char *val)
4078{
4079 char buf[60];
4080 unsigned int vht_mcsmap = 0;
4081 int rxchainmask = 0;
4082 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4083
4084 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4085 if (dut->testbed_flag_rxsp == 1) {
4086 vht_mcsmap = 0xfffc;
4087 dut->testbed_flag_rxsp = 0;
4088 } else {
4089 vht_mcsmap = 0xfffe;
4090 }
4091 rxchainmask = 1;
4092 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4093 if (dut->testbed_flag_rxsp == 1) {
4094 vht_mcsmap = 0xfff0;
4095 dut->testbed_flag_rxsp = 0;
4096 } else {
4097 vht_mcsmap = 0xfffa;
4098 }
4099 rxchainmask = 3;
4100 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4101 if (dut->testbed_flag_rxsp == 1) {
4102 vht_mcsmap = 0xffc0;
4103 dut->testbed_flag_rxsp = 0;
4104 } else {
4105 vht_mcsmap = 0xffea;
4106 }
4107 rxchainmask = 7;
4108 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4109 if (dut->testbed_flag_rxsp == 1) {
4110 vht_mcsmap = 0xff00;
4111 dut->testbed_flag_rxsp = 0;
4112 } else {
4113 vht_mcsmap = 0xffaa;
4114 }
4115 rxchainmask = 15;
4116 } else {
4117 if (dut->testbed_flag_rxsp == 1) {
4118 vht_mcsmap = 0xffc0;
4119 dut->testbed_flag_rxsp = 0;
4120 } else {
4121 vht_mcsmap = 0xffea;
4122 }
4123 }
4124
4125 if (rxchainmask) {
4126 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4127 basedev, rxchainmask);
4128 if (system(buf) != 0) {
4129 sigma_dut_print(dut, DUT_MSG_ERROR,
4130 "iwpriv rxchainmask failed");
4131 }
4132 }
4133
4134 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4135 intf, vht_mcsmap);
4136 if (system(buf) != 0) {
4137 sigma_dut_print(dut, DUT_MSG_ERROR,
4138 "iwpriv %s vht_mcsmap 0x%04x",
4139 intf, vht_mcsmap);
4140 }
4141}
4142
4143
4144void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4145{
4146 if (strcasecmp(val, "enable") == 0) {
4147 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4148 != 0) {
4149 sigma_dut_print(dut, DUT_MSG_ERROR,
4150 "Disable BB_VHTSIGB_CRC_CALC failed");
4151 }
4152
4153 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4154 != 0) {
4155 sigma_dut_print(dut, DUT_MSG_ERROR,
4156 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4157 }
4158 } else {
4159 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4160 != 0) {
4161 sigma_dut_print(dut, DUT_MSG_ERROR,
4162 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4163 }
4164
4165 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4166 != 0) {
4167 sigma_dut_print(dut, DUT_MSG_ERROR,
4168 "Enable BB_VHTSIGB_CRC_CALC failed");
4169 }
4170 }
4171}
4172
4173
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004174static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4175 const char *val)
4176{
4177 char buf[60];
4178
4179 if (strcmp(val, "20") == 0) {
4180 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4181 dut->chwidth = 0;
4182 } else if (strcmp(val, "40") == 0) {
4183 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4184 dut->chwidth = 1;
4185 } else if (strcmp(val, "80") == 0) {
4186 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4187 dut->chwidth = 2;
4188 } else if (strcmp(val, "Auto") == 0) {
4189 buf[0] = '\0';
4190 } else {
4191 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4192 val);
4193 return -1;
4194 }
4195
4196 if (buf[0] != '\0' && system(buf) != 0) {
4197 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4198 return -1;
4199 }
4200
4201 return 0;
4202}
4203
4204
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004205static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4206 const char *intf, int addbareject)
4207{
4208#ifdef NL80211_SUPPORT
4209 struct nl_msg *msg;
4210 int ret = 0;
4211 struct nlattr *params;
4212 int ifindex;
4213
4214 ifindex = if_nametoindex(intf);
4215 if (ifindex == 0) {
4216 sigma_dut_print(dut, DUT_MSG_ERROR,
4217 "%s: Index for interface %s failed",
4218 __func__, intf);
4219 return -1;
4220 }
4221
4222 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4223 NL80211_CMD_VENDOR)) ||
4224 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4225 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4226 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4227 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4228 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4229 nla_put_u8(msg,
4230 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4231 !addbareject)) {
4232 sigma_dut_print(dut, DUT_MSG_ERROR,
4233 "%s: err in adding vendor_cmd and vendor_data",
4234 __func__);
4235 nlmsg_free(msg);
4236 return -1;
4237 }
4238 nla_nest_end(msg, params);
4239
4240 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4241 if (ret) {
4242 sigma_dut_print(dut, DUT_MSG_ERROR,
4243 "%s: err in send_and_recv_msgs, ret=%d",
4244 __func__, ret);
4245 }
4246 return ret;
4247#else /* NL80211_SUPPORT */
4248 sigma_dut_print(dut, DUT_MSG_ERROR,
4249 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4250 return -1;
4251#endif /* NL80211_SUPPORT */
4252}
4253
4254
4255static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4256 int addbareject)
4257{
4258 int ret;
4259
4260 switch (get_driver_type()) {
4261 case DRIVER_WCN:
4262 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4263 if (ret) {
4264 sigma_dut_print(dut, DUT_MSG_ERROR,
4265 "nlvendor_sta_set_addba_reject failed, ret:%d",
4266 ret);
4267 return ret;
4268 }
4269 break;
4270 default:
4271 sigma_dut_print(dut, DUT_MSG_ERROR,
4272 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4273 ret = -1;
4274 break;
4275 }
4276
4277 return ret;
4278}
4279
4280
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004281static int nlvendor_disable_addba(struct sigma_dut *dut, const char *intf)
4282{
4283#ifdef NL80211_SUPPORT
4284 struct nl_msg *msg;
4285 int ret = 0;
4286 struct nlattr *params;
4287 int ifindex;
4288
4289 ifindex = if_nametoindex(intf);
4290 if (ifindex == 0) {
4291 sigma_dut_print(dut, DUT_MSG_ERROR,
4292 "%s: Index for interface %s failed",
4293 __func__, intf);
4294 return -1;
4295 }
4296
4297 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4298 NL80211_CMD_VENDOR)) ||
4299 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4300 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4301 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4302 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4303 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4304 nla_put_u8(msg,
4305 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
4306 0)) {
4307 sigma_dut_print(dut, DUT_MSG_ERROR,
4308 "%s: err in adding vendor_cmd and vendor_data",
4309 __func__);
4310 nlmsg_free(msg);
4311 return -1;
4312 }
4313 nla_nest_end(msg, params);
4314
4315 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4316 if (ret) {
4317 sigma_dut_print(dut, DUT_MSG_ERROR,
4318 "%s: err in send_and_recv_msgs, ret=%d",
4319 __func__, ret);
4320 }
4321 return ret;
4322#else /* NL80211_SUPPORT */
4323 sigma_dut_print(dut, DUT_MSG_ERROR,
4324 "Disable addba not possible without NL80211_SUPPORT defined");
4325 return -1;
4326#endif /* NL80211_SUPPORT */
4327}
4328
4329
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004330static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4331 struct sigma_conn *conn,
4332 struct sigma_cmd *cmd)
4333{
4334 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004335 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004336 char buf[30];
4337
4338 val = get_param(cmd, "40_INTOLERANT");
4339 if (val) {
4340 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4341 /* TODO: iwpriv ht40intol through wpa_supplicant */
4342 send_resp(dut, conn, SIGMA_ERROR,
4343 "ErrorCode,40_INTOLERANT not supported");
4344 return 0;
4345 }
4346 }
4347
4348 val = get_param(cmd, "ADDBA_REJECT");
4349 if (val) {
4350 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4351 /* reject any ADDBA with status "decline" */
4352 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004353 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004354 } else {
4355 /* accept ADDBA */
4356 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004357 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004358 }
4359 }
4360
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004361 if (addbareject >= 0 &&
4362 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4363 send_resp(dut, conn, SIGMA_ERROR,
4364 "ErrorCode,set addba_reject failed");
4365 return 0;
4366 }
4367
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004368 val = get_param(cmd, "AMPDU");
4369 if (val) {
4370 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4371 /* enable AMPDU Aggregation */
4372 if (ampdu == 0) {
4373 send_resp(dut, conn, SIGMA_ERROR,
4374 "ErrorCode,Mismatch in "
4375 "addba_reject/ampdu - "
4376 "not supported");
4377 return 0;
4378 }
4379 ampdu = 1;
4380 } else {
4381 /* disable AMPDU Aggregation */
4382 if (ampdu == 1) {
4383 send_resp(dut, conn, SIGMA_ERROR,
4384 "ErrorCode,Mismatch in "
4385 "addba_reject/ampdu - "
4386 "not supported");
4387 return 0;
4388 }
4389 ampdu = 0;
4390 }
4391 }
4392
4393 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004394 int ret;
4395
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004396 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4397 ampdu ? "Enabling" : "Disabling");
4398 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004399 if (wpa_command(intf, buf) < 0 &&
4400 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004401 send_resp(dut, conn, SIGMA_ERROR,
4402 "ErrorCode,set aggr failed");
4403 return 0;
4404 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004405
4406 if (ampdu == 0) {
4407 /* Disable sending of addba using nl vendor command */
4408 ret = nlvendor_disable_addba(dut, intf);
4409 if (ret) {
4410 sigma_dut_print(dut, DUT_MSG_ERROR,
4411 "Failed to disable addba, ret:%d",
4412 ret);
4413 }
4414 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004415 }
4416
4417 val = get_param(cmd, "AMSDU");
4418 if (val) {
4419 switch (get_driver_type()) {
4420 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004421 case DRIVER_WCN:
4422 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004423 break;
4424 default:
4425 if (strcmp(val, "1") == 0 ||
4426 strcasecmp(val, "Enable") == 0) {
4427 /* Enable AMSDU Aggregation */
4428 send_resp(dut, conn, SIGMA_ERROR,
4429 "ErrorCode,AMSDU aggregation not supported");
4430 return 0;
4431 }
4432 break;
4433 }
4434 }
4435
4436 val = get_param(cmd, "STBC_RX");
4437 if (val) {
4438 switch (get_driver_type()) {
4439 case DRIVER_ATHEROS:
4440 ath_sta_set_stbc(dut, intf, val);
4441 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304442 case DRIVER_WCN:
4443 wcn_sta_set_stbc(dut, intf, val);
4444 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004445 default:
4446 send_resp(dut, conn, SIGMA_ERROR,
4447 "ErrorCode,STBC_RX not supported");
4448 return 0;
4449 }
4450 }
4451
4452 val = get_param(cmd, "WIDTH");
4453 if (val) {
4454 switch (get_driver_type()) {
4455 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004456 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004457 send_resp(dut, conn, SIGMA_ERROR,
4458 "ErrorCode,Failed to set WIDTH");
4459 return 0;
4460 }
4461 break;
4462 case DRIVER_ATHEROS:
4463 if (ath_set_width(dut, conn, intf, val) < 0)
4464 return 0;
4465 break;
4466 default:
4467 sigma_dut_print(dut, DUT_MSG_ERROR,
4468 "Setting WIDTH not supported");
4469 break;
4470 }
4471 }
4472
4473 val = get_param(cmd, "SMPS");
4474 if (val) {
4475 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4476 send_resp(dut, conn, SIGMA_ERROR,
4477 "ErrorCode,SMPS not supported");
4478 return 0;
4479 }
4480
4481 val = get_param(cmd, "TXSP_STREAM");
4482 if (val) {
4483 switch (get_driver_type()) {
4484 case DRIVER_WCN:
4485 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4486 send_resp(dut, conn, SIGMA_ERROR,
4487 "ErrorCode,Failed to set TXSP_STREAM");
4488 return 0;
4489 }
4490 break;
4491 case DRIVER_ATHEROS:
4492 ath_sta_set_txsp_stream(dut, intf, val);
4493 break;
4494 default:
4495 sigma_dut_print(dut, DUT_MSG_ERROR,
4496 "Setting TXSP_STREAM not supported");
4497 break;
4498 }
4499 }
4500
4501 val = get_param(cmd, "RXSP_STREAM");
4502 if (val) {
4503 switch (get_driver_type()) {
4504 case DRIVER_WCN:
4505 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4506 send_resp(dut, conn, SIGMA_ERROR,
4507 "ErrorCode,Failed to set RXSP_STREAM");
4508 return 0;
4509 }
4510 break;
4511 case DRIVER_ATHEROS:
4512 ath_sta_set_rxsp_stream(dut, intf, val);
4513 break;
4514 default:
4515 sigma_dut_print(dut, DUT_MSG_ERROR,
4516 "Setting RXSP_STREAM not supported");
4517 break;
4518 }
4519 }
4520
4521 val = get_param(cmd, "DYN_BW_SGNL");
4522 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004523 switch (get_driver_type()) {
4524 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004525 if (strcasecmp(val, "enable") == 0) {
4526 snprintf(buf, sizeof(buf),
4527 "iwpriv %s cwmenable 1", intf);
4528 if (system(buf) != 0) {
4529 sigma_dut_print(dut, DUT_MSG_ERROR,
4530 "iwpriv cwmenable 1 failed");
4531 return 0;
4532 }
4533 } else if (strcasecmp(val, "disable") == 0) {
4534 snprintf(buf, sizeof(buf),
4535 "iwpriv %s cwmenable 0", intf);
4536 if (system(buf) != 0) {
4537 sigma_dut_print(dut, DUT_MSG_ERROR,
4538 "iwpriv cwmenable 0 failed");
4539 return 0;
4540 }
4541 } else {
4542 sigma_dut_print(dut, DUT_MSG_ERROR,
4543 "Unsupported DYN_BW_SGL");
4544 }
4545
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004546 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4547 if (system(buf) != 0) {
4548 sigma_dut_print(dut, DUT_MSG_ERROR,
4549 "Failed to set cts_cbw in DYN_BW_SGNL");
4550 return 0;
4551 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004552 break;
4553 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004554 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004555 ath_config_dyn_bw_sig(dut, intf, val);
4556 break;
4557 default:
4558 sigma_dut_print(dut, DUT_MSG_ERROR,
4559 "Failed to set DYN_BW_SGNL");
4560 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004561 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004562 }
4563
4564 val = get_param(cmd, "RTS_FORCE");
4565 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004566 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004567 if (strcasecmp(val, "Enable") == 0) {
4568 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004569 if (system(buf) != 0) {
4570 sigma_dut_print(dut, DUT_MSG_ERROR,
4571 "Failed to set RTS_FORCE 64");
4572 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004573 snprintf(buf, sizeof(buf),
4574 "wifitool %s beeliner_fw_test 100 1", intf);
4575 if (system(buf) != 0) {
4576 sigma_dut_print(dut, DUT_MSG_ERROR,
4577 "wifitool beeliner_fw_test 100 1 failed");
4578 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004579 } else if (strcasecmp(val, "Disable") == 0) {
4580 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4581 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004582 if (system(buf) != 0) {
4583 sigma_dut_print(dut, DUT_MSG_ERROR,
4584 "Failed to set RTS_FORCE 2347");
4585 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004586 } else {
4587 send_resp(dut, conn, SIGMA_ERROR,
4588 "ErrorCode,RTS_FORCE value not supported");
4589 return 0;
4590 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004591 }
4592
4593 val = get_param(cmd, "CTS_WIDTH");
4594 if (val) {
4595 switch (get_driver_type()) {
4596 case DRIVER_WCN:
4597 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4598 send_resp(dut, conn, SIGMA_ERROR,
4599 "ErrorCode,Failed to set CTS_WIDTH");
4600 return 0;
4601 }
4602 break;
4603 case DRIVER_ATHEROS:
4604 ath_set_cts_width(dut, intf, val);
4605 break;
4606 default:
4607 sigma_dut_print(dut, DUT_MSG_ERROR,
4608 "Setting CTS_WIDTH not supported");
4609 break;
4610 }
4611 }
4612
4613 val = get_param(cmd, "BW_SGNL");
4614 if (val) {
4615 if (strcasecmp(val, "Enable") == 0) {
4616 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4617 intf);
4618 } else if (strcasecmp(val, "Disable") == 0) {
4619 /* TODO: Disable */
4620 buf[0] = '\0';
4621 } else {
4622 send_resp(dut, conn, SIGMA_ERROR,
4623 "ErrorCode,BW_SGNL value not supported");
4624 return 0;
4625 }
4626
4627 if (buf[0] != '\0' && system(buf) != 0) {
4628 sigma_dut_print(dut, DUT_MSG_ERROR,
4629 "Failed to set BW_SGNL");
4630 }
4631 }
4632
4633 val = get_param(cmd, "Band");
4634 if (val) {
4635 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4636 /* STA supports all bands by default */
4637 } else {
4638 send_resp(dut, conn, SIGMA_ERROR,
4639 "ErrorCode,Unsupported Band");
4640 return 0;
4641 }
4642 }
4643
4644 val = get_param(cmd, "zero_crc");
4645 if (val) {
4646 switch (get_driver_type()) {
4647 case DRIVER_ATHEROS:
4648 ath_set_zero_crc(dut, val);
4649 break;
4650 default:
4651 break;
4652 }
4653 }
4654
4655 return 1;
4656}
4657
4658
4659static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4660 struct sigma_cmd *cmd)
4661{
4662 const char *val;
4663 char buf[100];
4664
4665 val = get_param(cmd, "MSDUSize");
4666 if (val) {
4667 int mtu;
4668
4669 dut->amsdu_size = atoi(val);
4670 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4671 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4672 sigma_dut_print(dut, DUT_MSG_ERROR,
4673 "MSDUSize %d is above max %d or below min %d",
4674 dut->amsdu_size,
4675 IEEE80211_MAX_DATA_LEN_DMG,
4676 IEEE80211_SNAP_LEN_DMG);
4677 dut->amsdu_size = 0;
4678 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4679 }
4680
4681 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4682 sigma_dut_print(dut, DUT_MSG_DEBUG,
4683 "Setting amsdu_size to %d", mtu);
4684 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4685 get_station_ifname(), mtu);
4686
4687 if (system(buf) != 0) {
4688 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4689 buf);
4690 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4691 }
4692 }
4693
4694 val = get_param(cmd, "BAckRcvBuf");
4695 if (val) {
4696 dut->back_rcv_buf = atoi(val);
4697 if (dut->back_rcv_buf == 0) {
4698 sigma_dut_print(dut, DUT_MSG_ERROR,
4699 "Failed to convert %s or value is 0",
4700 val);
4701 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4702 }
4703
4704 sigma_dut_print(dut, DUT_MSG_DEBUG,
4705 "Setting BAckRcvBuf to %s", val);
4706 }
4707
4708 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4709}
4710
4711
4712static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4713 struct sigma_cmd *cmd)
4714{
4715 int net_id;
4716 char *ifname;
4717 const char *val;
4718 char buf[100];
4719
4720 dut->mode = SIGMA_MODE_STATION;
4721 ifname = get_main_ifname();
4722 if (wpa_command(ifname, "PING") != 0) {
4723 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4724 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4725 }
4726
4727 wpa_command(ifname, "FLUSH");
4728 net_id = add_network_common(dut, conn, ifname, cmd);
4729 if (net_id < 0) {
4730 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4731 return net_id;
4732 }
4733
4734 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4735 if (set_network(ifname, net_id, "mode", "2") < 0) {
4736 sigma_dut_print(dut, DUT_MSG_ERROR,
4737 "Failed to set supplicant network mode");
4738 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4739 }
4740
4741 sigma_dut_print(dut, DUT_MSG_DEBUG,
4742 "Supplicant set network with mode 2");
4743
4744 val = get_param(cmd, "Security");
4745 if (val && strcasecmp(val, "OPEN") == 0) {
4746 dut->ap_key_mgmt = AP_OPEN;
4747 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4748 sigma_dut_print(dut, DUT_MSG_ERROR,
4749 "Failed to set supplicant to %s security",
4750 val);
4751 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4752 }
4753 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4754 dut->ap_key_mgmt = AP_WPA2_PSK;
4755 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4756 sigma_dut_print(dut, DUT_MSG_ERROR,
4757 "Failed to set supplicant to %s security",
4758 val);
4759 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4760 }
4761
4762 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4763 sigma_dut_print(dut, DUT_MSG_ERROR,
4764 "Failed to set supplicant to proto RSN");
4765 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4766 }
4767 } else if (val) {
4768 sigma_dut_print(dut, DUT_MSG_ERROR,
4769 "Requested Security %s is not supported on 60GHz",
4770 val);
4771 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4772 }
4773
4774 val = get_param(cmd, "Encrypt");
4775 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4776 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4777 sigma_dut_print(dut, DUT_MSG_ERROR,
4778 "Failed to set supplicant to pairwise GCMP");
4779 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4780 }
4781 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4782 sigma_dut_print(dut, DUT_MSG_ERROR,
4783 "Failed to set supplicant to group GCMP");
4784 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4785 }
4786 } else if (val) {
4787 sigma_dut_print(dut, DUT_MSG_ERROR,
4788 "Requested Encrypt %s is not supported on 60 GHz",
4789 val);
4790 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4791 }
4792
4793 val = get_param(cmd, "PSK");
4794 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4795 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4796 val);
4797 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4798 }
4799
4800 /* Convert 60G channel to freq */
4801 switch (dut->ap_channel) {
4802 case 1:
4803 val = "58320";
4804 break;
4805 case 2:
4806 val = "60480";
4807 break;
4808 case 3:
4809 val = "62640";
4810 break;
4811 default:
4812 sigma_dut_print(dut, DUT_MSG_ERROR,
4813 "Failed to configure channel %d. Not supported",
4814 dut->ap_channel);
4815 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4816 }
4817
4818 if (set_network(ifname, net_id, "frequency", val) < 0) {
4819 sigma_dut_print(dut, DUT_MSG_ERROR,
4820 "Failed to set supplicant network frequency");
4821 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4822 }
4823
4824 sigma_dut_print(dut, DUT_MSG_DEBUG,
4825 "Supplicant set network with frequency");
4826
4827 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4828 if (wpa_command(ifname, buf) < 0) {
4829 sigma_dut_print(dut, DUT_MSG_INFO,
4830 "Failed to select network id %d on %s",
4831 net_id, ifname);
4832 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4833 }
4834
4835 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4836
4837 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4838}
4839
4840
Lior David67543f52017-01-03 19:04:22 +02004841static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4842{
4843 char buf[128], fname[128];
4844 FILE *f;
4845
4846 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4847 sigma_dut_print(dut, DUT_MSG_ERROR,
4848 "failed to get wil6210 debugfs dir");
4849 return -1;
4850 }
4851
4852 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4853 f = fopen(fname, "w");
4854 if (!f) {
4855 sigma_dut_print(dut, DUT_MSG_ERROR,
4856 "failed to open: %s", fname);
4857 return -1;
4858 }
4859
4860 fprintf(f, "%d\n", abft_len);
4861 fclose(f);
4862
4863 return 0;
4864}
4865
4866
4867static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4868 int abft_len)
4869{
4870 switch (get_driver_type()) {
4871 case DRIVER_WIL6210:
4872 return wil6210_set_abft_len(dut, abft_len);
4873 default:
4874 sigma_dut_print(dut, DUT_MSG_ERROR,
4875 "set abft_len not supported");
4876 return -1;
4877 }
4878}
4879
4880
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004881static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4882 struct sigma_cmd *cmd)
4883{
4884 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004885 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004886
4887 if (dut->dev_role != DEVROLE_PCP) {
4888 send_resp(dut, conn, SIGMA_INVALID,
4889 "ErrorCode,Invalid DevRole");
4890 return 0;
4891 }
4892
4893 val = get_param(cmd, "SSID");
4894 if (val) {
4895 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4896 send_resp(dut, conn, SIGMA_INVALID,
4897 "ErrorCode,Invalid SSID");
4898 return -1;
4899 }
4900
Peng Xub8fc5cc2017-05-10 17:27:28 -07004901 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004902 }
4903
4904 val = get_param(cmd, "CHANNEL");
4905 if (val) {
4906 const char *pos;
4907
4908 dut->ap_channel = atoi(val);
4909 pos = strchr(val, ';');
4910 if (pos) {
4911 pos++;
4912 dut->ap_channel_1 = atoi(pos);
4913 }
4914 }
4915
4916 switch (dut->ap_channel) {
4917 case 1:
4918 case 2:
4919 case 3:
4920 break;
4921 default:
4922 sigma_dut_print(dut, DUT_MSG_ERROR,
4923 "Channel %d is not supported", dut->ap_channel);
4924 send_resp(dut, conn, SIGMA_ERROR,
4925 "Requested channel is not supported");
4926 return -1;
4927 }
4928
4929 val = get_param(cmd, "BCNINT");
4930 if (val)
4931 dut->ap_bcnint = atoi(val);
4932
4933
4934 val = get_param(cmd, "ExtSchIE");
4935 if (val) {
4936 send_resp(dut, conn, SIGMA_ERROR,
4937 "ErrorCode,ExtSchIE is not supported yet");
4938 return -1;
4939 }
4940
4941 val = get_param(cmd, "AllocType");
4942 if (val) {
4943 send_resp(dut, conn, SIGMA_ERROR,
4944 "ErrorCode,AllocType is not supported yet");
4945 return -1;
4946 }
4947
4948 val = get_param(cmd, "PercentBI");
4949 if (val) {
4950 send_resp(dut, conn, SIGMA_ERROR,
4951 "ErrorCode,PercentBI is not supported yet");
4952 return -1;
4953 }
4954
4955 val = get_param(cmd, "CBAPOnly");
4956 if (val) {
4957 send_resp(dut, conn, SIGMA_ERROR,
4958 "ErrorCode,CBAPOnly is not supported yet");
4959 return -1;
4960 }
4961
4962 val = get_param(cmd, "AMPDU");
4963 if (val) {
4964 if (strcasecmp(val, "Enable") == 0)
4965 dut->ap_ampdu = 1;
4966 else if (strcasecmp(val, "Disable") == 0)
4967 dut->ap_ampdu = 2;
4968 else {
4969 send_resp(dut, conn, SIGMA_ERROR,
4970 "ErrorCode,AMPDU value is not Enable nor Disabled");
4971 return -1;
4972 }
4973 }
4974
4975 val = get_param(cmd, "AMSDU");
4976 if (val) {
4977 if (strcasecmp(val, "Enable") == 0)
4978 dut->ap_amsdu = 1;
4979 else if (strcasecmp(val, "Disable") == 0)
4980 dut->ap_amsdu = 2;
4981 }
4982
4983 val = get_param(cmd, "NumMSDU");
4984 if (val) {
4985 send_resp(dut, conn, SIGMA_ERROR,
4986 "ErrorCode, NumMSDU is not supported yet");
4987 return -1;
4988 }
4989
4990 val = get_param(cmd, "ABFTLRang");
4991 if (val) {
4992 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004993 "ABFTLRang parameter %s", val);
4994 if (strcmp(val, "Gt1") == 0)
4995 abft_len = 2; /* 2 slots in this case */
4996 }
4997
4998 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4999 send_resp(dut, conn, SIGMA_ERROR,
5000 "ErrorCode, Can't set ABFT length");
5001 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005002 }
5003
5004 if (sta_pcp_start(dut, conn, cmd) < 0) {
5005 send_resp(dut, conn, SIGMA_ERROR,
5006 "ErrorCode, Can't start PCP role");
5007 return -1;
5008 }
5009
5010 return sta_set_60g_common(dut, conn, cmd);
5011}
5012
5013
5014static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5015 struct sigma_cmd *cmd)
5016{
5017 const char *val = get_param(cmd, "DiscoveryMode");
5018
5019 if (dut->dev_role != DEVROLE_STA) {
5020 send_resp(dut, conn, SIGMA_INVALID,
5021 "ErrorCode,Invalid DevRole");
5022 return 0;
5023 }
5024
5025 if (val) {
5026 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5027 /* Ignore Discovery mode till Driver expose API. */
5028#if 0
5029 if (strcasecmp(val, "1") == 0) {
5030 send_resp(dut, conn, SIGMA_INVALID,
5031 "ErrorCode,DiscoveryMode 1 not supported");
5032 return 0;
5033 }
5034
5035 if (strcasecmp(val, "0") == 0) {
5036 /* OK */
5037 } else {
5038 send_resp(dut, conn, SIGMA_INVALID,
5039 "ErrorCode,DiscoveryMode not supported");
5040 return 0;
5041 }
5042#endif
5043 }
5044
5045 if (start_sta_mode(dut) != 0)
5046 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5047 return sta_set_60g_common(dut, conn, cmd);
5048}
5049
5050
5051static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5052 struct sigma_cmd *cmd)
5053{
5054 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005055 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305056
Jouni Malinened77e672018-01-10 16:45:13 +02005057 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005058 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005059 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305060 wpa_command(intf, "DISCONNECT");
5061 return 1;
5062 }
5063
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005064 disconnect_station(dut);
5065 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5066 * due to cached results. */
5067 wpa_command(intf, "SET ignore_old_scan_res 1");
5068 wpa_command(intf, "BSS_FLUSH");
5069 return 1;
5070}
5071
5072
5073static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5074 struct sigma_cmd *cmd)
5075{
5076 const char *intf = get_param(cmd, "Interface");
5077 const char *bssid = get_param(cmd, "bssid");
5078 const char *val = get_param(cmd, "CHANNEL");
5079 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305080 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305081 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005082 int res;
5083 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305084 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305085 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005086
5087 if (bssid == NULL) {
5088 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5089 "argument");
5090 return 0;
5091 }
5092
5093 if (val)
5094 chan = atoi(val);
5095
5096 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5097 /* The current network may be from sta_associate or
5098 * sta_hs2_associate
5099 */
5100 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5101 0 ||
5102 set_network(intf, 0, "bssid", bssid) < 0)
5103 return -2;
5104 }
5105
5106 ctrl = open_wpa_mon(intf);
5107 if (ctrl == NULL) {
5108 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5109 "wpa_supplicant monitor connection");
5110 return -1;
5111 }
5112
Sunil Duttd30ce092018-01-11 23:56:29 +05305113 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5114 sizeof(result)) < 0 ||
5115 strncmp(result, "COMPLETED", 9) != 0) {
5116 sigma_dut_print(dut, DUT_MSG_DEBUG,
5117 "sta_reassoc: Not connected");
5118 fastreassoc = 0;
5119 }
5120
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305121 if (dut->rsne_override) {
5122#ifdef NL80211_SUPPORT
5123 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5124 sta_config_rsnie(dut, 1);
5125 dut->config_rsnie = 1;
5126 }
5127#endif /* NL80211_SUPPORT */
5128 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5129 dut->rsne_override);
5130 if (wpa_command(intf, buf) < 0) {
5131 send_resp(dut, conn, SIGMA_ERROR,
5132 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5133 return 0;
5134 }
5135 }
5136
Sunil Duttd30ce092018-01-11 23:56:29 +05305137 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005138#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305139 if (chan) {
5140 unsigned int freq;
5141
5142 freq = channel_to_freq(chan);
5143 if (!freq) {
5144 sigma_dut_print(dut, DUT_MSG_ERROR,
5145 "Invalid channel number provided: %d",
5146 chan);
5147 send_resp(dut, conn, SIGMA_INVALID,
5148 "ErrorCode,Invalid channel number");
5149 goto close_mon_conn;
5150 }
5151 res = snprintf(buf, sizeof(buf),
5152 "SCAN TYPE=ONLY freq=%d", freq);
5153 } else {
5154 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5155 }
5156 if (res < 0 || res >= (int) sizeof(buf)) {
5157 send_resp(dut, conn, SIGMA_ERROR,
5158 "ErrorCode,snprintf failed");
5159 goto close_mon_conn;
5160 }
5161 if (wpa_command(intf, buf) < 0) {
5162 sigma_dut_print(dut, DUT_MSG_INFO,
5163 "Failed to start scan");
5164 send_resp(dut, conn, SIGMA_ERROR,
5165 "ErrorCode,scan failed");
5166 goto close_mon_conn;
5167 }
5168
5169 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5170 buf, sizeof(buf));
5171 if (res < 0) {
5172 sigma_dut_print(dut, DUT_MSG_INFO,
5173 "Scan did not complete");
5174 send_resp(dut, conn, SIGMA_ERROR,
5175 "ErrorCode,scan did not complete");
5176 goto close_mon_conn;
5177 }
5178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005179 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5180 < 0) {
5181 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5182 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305183 status = -2;
5184 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005185 }
5186 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5187 bssid, chan);
5188 if (res > 0 && res < (int) sizeof(buf))
5189 res = wpa_command(intf, buf);
5190
5191 if (res < 0 || res >= (int) sizeof(buf)) {
5192 send_resp(dut, conn, SIGMA_ERROR,
5193 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305194 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005195 }
5196#else /* ANDROID */
5197 sigma_dut_print(dut, DUT_MSG_DEBUG,
5198 "Reassoc using iwpriv - skip chan=%d info",
5199 chan);
5200 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5201 if (system(buf) != 0) {
5202 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305203 status = -2;
5204 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005205 }
5206#endif /* ANDROID */
5207 sigma_dut_print(dut, DUT_MSG_INFO,
5208 "sta_reassoc: Run %s successful", buf);
5209 } else if (wpa_command(intf, "REASSOCIATE")) {
5210 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5211 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305212 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005213 }
5214
5215 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5216 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305217 if (res < 0) {
5218 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5219 status = -1;
5220 goto close_mon_conn;
5221 }
5222 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005223
Ashwini Patil467efef2017-05-25 12:18:27 +05305224close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005225 wpa_ctrl_detach(ctrl);
5226 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305227 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005228}
5229
5230
5231static void hs2_clear_credentials(const char *intf)
5232{
5233 wpa_command(intf, "REMOVE_CRED all");
5234}
5235
5236
Lior Davidcc88b562017-01-03 18:52:09 +02005237#ifdef __linux__
5238static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5239 unsigned int *aid)
5240{
Lior David0fe101e2017-03-09 16:09:50 +02005241 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005242
Lior David0fe101e2017-03-09 16:09:50 +02005243 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005244}
5245#endif /* __linux__ */
5246
5247
5248static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5249 unsigned int *aid)
5250{
5251 switch (get_driver_type()) {
5252#ifdef __linux__
5253 case DRIVER_WIL6210:
5254 return wil6210_get_aid(dut, bssid, aid);
5255#endif /* __linux__ */
5256 default:
5257 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5258 return -1;
5259 }
5260}
5261
5262
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5264 struct sigma_cmd *cmd)
5265{
5266 char buf[MAX_CMD_LEN];
5267 char bss_list[MAX_CMD_LEN];
5268 const char *parameter = get_param(cmd, "Parameter");
5269
5270 if (parameter == NULL)
5271 return -1;
5272
Lior Davidcc88b562017-01-03 18:52:09 +02005273 if (strcasecmp(parameter, "AID") == 0) {
5274 unsigned int aid = 0;
5275 char bssid[20];
5276
5277 if (get_wpa_status(get_station_ifname(), "bssid",
5278 bssid, sizeof(bssid)) < 0) {
5279 sigma_dut_print(dut, DUT_MSG_ERROR,
5280 "could not get bssid");
5281 return -2;
5282 }
5283
5284 if (sta_get_aid_60g(dut, bssid, &aid))
5285 return -2;
5286
5287 snprintf(buf, sizeof(buf), "aid,%d", aid);
5288 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5289 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5290 return 0;
5291 }
5292
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005293 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5294 char *bss_line;
5295 char *bss_id = NULL;
5296 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305297 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005298
5299 if (ifname == NULL) {
5300 sigma_dut_print(dut, DUT_MSG_INFO,
5301 "For get DiscoveredDevList need Interface name.");
5302 return -1;
5303 }
5304
5305 /*
5306 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5307 * of BSSIDs in "bssid=<BSSID>\n"
5308 */
5309 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5310 bss_list,
5311 sizeof(bss_list)) < 0) {
5312 sigma_dut_print(dut, DUT_MSG_ERROR,
5313 "Failed to get bss list");
5314 return -1;
5315 }
5316
5317 sigma_dut_print(dut, DUT_MSG_DEBUG,
5318 "bss list for ifname:%s is:%s",
5319 ifname, bss_list);
5320
5321 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305322 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005323 while (bss_line) {
5324 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5325 bss_id) {
5326 int len;
5327
5328 len = snprintf(buf + strlen(buf),
5329 sizeof(buf) - strlen(buf),
5330 ",%s", bss_id);
5331 free(bss_id);
5332 bss_id = NULL;
5333 if (len < 0) {
5334 sigma_dut_print(dut,
5335 DUT_MSG_ERROR,
5336 "Failed to read BSSID");
5337 send_resp(dut, conn, SIGMA_ERROR,
5338 "ErrorCode,Failed to read BSS ID");
5339 return 0;
5340 }
5341
5342 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5343 sigma_dut_print(dut,
5344 DUT_MSG_ERROR,
5345 "Response buf too small for list");
5346 send_resp(dut, conn,
5347 SIGMA_ERROR,
5348 "ErrorCode,Response buf too small for list");
5349 return 0;
5350 }
5351 }
5352
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305353 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005354 }
5355
5356 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5357 buf);
5358 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5359 return 0;
5360 }
5361
5362 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5363 return 0;
5364}
5365
5366
5367static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5368 struct sigma_cmd *cmd)
5369{
5370 const char *program = get_param(cmd, "Program");
5371
5372 if (program == NULL)
5373 return -1;
5374
5375 if (strcasecmp(program, "P2PNFC") == 0)
5376 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5377
5378 if (strcasecmp(program, "60ghz") == 0)
5379 return sta_get_parameter_60g(dut, conn, cmd);
5380
5381#ifdef ANDROID_NAN
5382 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005383 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005384#endif /* ANDROID_NAN */
5385
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005386#ifdef MIRACAST
5387 if (strcasecmp(program, "WFD") == 0 ||
5388 strcasecmp(program, "DisplayR2") == 0)
5389 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5390#endif /* MIRACAST */
5391
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005392 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5393 return 0;
5394}
5395
5396
5397static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5398 const char *type)
5399{
5400 char buf[100];
5401
5402 if (dut->program == PROGRAM_VHT) {
5403 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5404 if (system(buf) != 0) {
5405 sigma_dut_print(dut, DUT_MSG_ERROR,
5406 "iwpriv %s chwidth failed", intf);
5407 }
5408
5409 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5410 if (system(buf) != 0) {
5411 sigma_dut_print(dut, DUT_MSG_ERROR,
5412 "iwpriv %s mode 11ACVHT80 failed",
5413 intf);
5414 }
5415
5416 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5417 if (system(buf) != 0) {
5418 sigma_dut_print(dut, DUT_MSG_ERROR,
5419 "iwpriv %s vhtmcs -1 failed", intf);
5420 }
5421 }
5422
5423 if (dut->program == PROGRAM_HT) {
5424 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5425 if (system(buf) != 0) {
5426 sigma_dut_print(dut, DUT_MSG_ERROR,
5427 "iwpriv %s chwidth failed", intf);
5428 }
5429
5430 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5431 if (system(buf) != 0) {
5432 sigma_dut_print(dut, DUT_MSG_ERROR,
5433 "iwpriv %s mode 11naht40 failed",
5434 intf);
5435 }
5436
5437 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5438 if (system(buf) != 0) {
5439 sigma_dut_print(dut, DUT_MSG_ERROR,
5440 "iwpriv set11NRates failed");
5441 }
5442 }
5443
5444 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5445 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5446 if (system(buf) != 0) {
5447 sigma_dut_print(dut, DUT_MSG_ERROR,
5448 "disabling powersave failed");
5449 }
5450
5451 /* Reset CTS width */
5452 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5453 intf);
5454 if (system(buf) != 0) {
5455 sigma_dut_print(dut, DUT_MSG_ERROR,
5456 "wifitool %s beeliner_fw_test 54 0 failed",
5457 intf);
5458 }
5459
5460 /* Enable Dynamic Bandwidth signalling by default */
5461 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5462 if (system(buf) != 0) {
5463 sigma_dut_print(dut, DUT_MSG_ERROR,
5464 "iwpriv %s cwmenable 1 failed", intf);
5465 }
5466
5467 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5468 if (system(buf) != 0) {
5469 sigma_dut_print(dut, DUT_MSG_ERROR,
5470 "iwpriv rts failed");
5471 }
5472 }
5473
5474 if (type && strcasecmp(type, "Testbed") == 0) {
5475 dut->testbed_flag_txsp = 1;
5476 dut->testbed_flag_rxsp = 1;
5477 /* STA has to set spatial stream to 2 per Appendix H */
5478 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5479 if (system(buf) != 0) {
5480 sigma_dut_print(dut, DUT_MSG_ERROR,
5481 "iwpriv vht_mcsmap failed");
5482 }
5483
5484 /* Disable LDPC per Appendix H */
5485 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5486 if (system(buf) != 0) {
5487 sigma_dut_print(dut, DUT_MSG_ERROR,
5488 "iwpriv %s ldpc 0 failed", intf);
5489 }
5490
5491 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5492 if (system(buf) != 0) {
5493 sigma_dut_print(dut, DUT_MSG_ERROR,
5494 "iwpriv amsdu failed");
5495 }
5496
5497 /* TODO: Disable STBC 2x1 transmit and receive */
5498 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5499 if (system(buf) != 0) {
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "Disable tx_stbc 0 failed");
5502 }
5503
5504 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5505 if (system(buf) != 0) {
5506 sigma_dut_print(dut, DUT_MSG_ERROR,
5507 "Disable rx_stbc 0 failed");
5508 }
5509
5510 /* STA has to disable Short GI per Appendix H */
5511 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5512 if (system(buf) != 0) {
5513 sigma_dut_print(dut, DUT_MSG_ERROR,
5514 "iwpriv %s shortgi 0 failed", intf);
5515 }
5516 }
5517
5518 if (type && strcasecmp(type, "DUT") == 0) {
5519 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5520 if (system(buf) != 0) {
5521 sigma_dut_print(dut, DUT_MSG_ERROR,
5522 "iwpriv %s nss 3 failed", intf);
5523 }
5524
5525 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5526 if (system(buf) != 0) {
5527 sigma_dut_print(dut, DUT_MSG_ERROR,
5528 "iwpriv %s shortgi 1 failed", intf);
5529 }
5530 }
5531}
5532
5533
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005534#ifdef NL80211_SUPPORT
5535static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5536 enum he_mcs_config mcs)
5537{
5538 struct nl_msg *msg;
5539 int ret = 0;
5540 struct nlattr *params;
5541 int ifindex;
5542
5543 ifindex = if_nametoindex(intf);
5544 if (ifindex == 0) {
5545 sigma_dut_print(dut, DUT_MSG_ERROR,
5546 "%s: Index for interface %s failed",
5547 __func__, intf);
5548 return -1;
5549 }
5550
5551 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5552 NL80211_CMD_VENDOR)) ||
5553 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5554 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5555 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5556 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5557 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5558 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5559 mcs)) {
5560 sigma_dut_print(dut, DUT_MSG_ERROR,
5561 "%s: err in adding vendor_cmd and vendor_data",
5562 __func__);
5563 nlmsg_free(msg);
5564 return -1;
5565 }
5566 nla_nest_end(msg, params);
5567
5568 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5569 if (ret) {
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "%s: err in send_and_recv_msgs, ret=%d",
5572 __func__, ret);
5573 }
5574 return ret;
5575}
5576#endif /* NL80211_SUPPORT */
5577
5578
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005579static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5580 const char *intf, int enable)
5581{
5582#ifdef NL80211_SUPPORT
5583 struct nl_msg *msg;
5584 int ret = 0;
5585 struct nlattr *params;
5586 int ifindex;
5587
5588 ifindex = if_nametoindex(intf);
5589 if (ifindex == 0) {
5590 sigma_dut_print(dut, DUT_MSG_ERROR,
5591 "%s: Index for interface %s failed",
5592 __func__, intf);
5593 return -1;
5594 }
5595
5596 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5597 NL80211_CMD_VENDOR)) ||
5598 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5599 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5600 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5601 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5602 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5603 nla_put_u8(msg,
5604 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
5605 enable)) {
5606 sigma_dut_print(dut, DUT_MSG_ERROR,
5607 "%s: err in adding vendor_cmd and vendor_data",
5608 __func__);
5609 nlmsg_free(msg);
5610 return -1;
5611 }
5612 nla_nest_end(msg, params);
5613
5614 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5615 if (ret) {
5616 sigma_dut_print(dut, DUT_MSG_ERROR,
5617 "%s: err in send_and_recv_msgs, ret=%d",
5618 __func__, ret);
5619 }
5620 return ret;
5621#else /* NL80211_SUPPORT */
5622 sigma_dut_print(dut, DUT_MSG_ERROR,
5623 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5624 return -1;
5625#endif /* NL80211_SUPPORT */
5626}
5627
5628
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005629static int sta_set_addba_buf_size(struct sigma_dut *dut,
5630 const char *intf, int bufsize)
5631{
5632#ifdef NL80211_SUPPORT
5633 struct nl_msg *msg;
5634 int ret = 0;
5635 struct nlattr *params;
5636 int ifindex;
5637
5638 ifindex = if_nametoindex(intf);
5639 if (ifindex == 0) {
5640 sigma_dut_print(dut, DUT_MSG_ERROR,
5641 "%s: Index for interface %s failed",
5642 __func__, intf);
5643 return -1;
5644 }
5645
5646 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5647 NL80211_CMD_VENDOR)) ||
5648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5649 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5650 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5651 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5652 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5653 nla_put_u8(msg,
5654 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5655 bufsize)) {
5656 sigma_dut_print(dut, DUT_MSG_ERROR,
5657 "%s: err in adding vendor_cmd and vendor_data",
5658 __func__);
5659 nlmsg_free(msg);
5660 return -1;
5661 }
5662 nla_nest_end(msg, params);
5663
5664 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5665 if (ret) {
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "%s: err in send_and_recv_msgs, ret=%d",
5668 __func__, ret);
5669 }
5670 return ret;
5671#else /* NL80211_SUPPORT */
5672 sigma_dut_print(dut, DUT_MSG_ERROR,
5673 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5674 return -1;
5675#endif /* NL80211_SUPPORT */
5676}
5677
5678
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005679static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5680 const char *type)
5681{
5682 char buf[60];
5683
5684 if (dut->program == PROGRAM_HE) {
5685 /* resetting phymode to auto in case of HE program */
5686 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5687 if (system(buf) != 0) {
5688 sigma_dut_print(dut, DUT_MSG_ERROR,
5689 "iwpriv %s setphymode failed", intf);
5690 }
5691
5692 /* remove all network profiles */
5693 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005694
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005695 /* Configure ADDBA Req/Rsp buffer size to be 64 */
5696 sta_set_addba_buf_size(dut, intf, 64);
5697
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005698 /* Set nss to 1 and MCS 0-7 in case of testbed */
5699 if (type && strcasecmp(type, "Testbed") == 0) {
5700#ifdef NL80211_SUPPORT
5701 int ret;
5702#endif /* NL80211_SUPPORT */
5703
5704 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5705 if (system(buf) != 0) {
5706 sigma_dut_print(dut, DUT_MSG_ERROR,
5707 "iwpriv %s nss failed", intf);
5708 }
5709
5710#ifdef NL80211_SUPPORT
5711 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5712 if (ret) {
5713 sigma_dut_print(dut, DUT_MSG_ERROR,
5714 "Setting of MCS failed, ret:%d",
5715 ret);
5716 }
5717#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08005718
5719 /* Disable STBC as default */
5720 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005721
5722 /* Disable AMSDU as default */
5723 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005724
5725#ifdef NL80211_SUPPORT
5726 /* HE fragmentation default off */
5727 if (sta_set_he_fragmentation(dut, intf,
5728 HE_FRAG_DISABLE)) {
5729 sigma_dut_print(dut, DUT_MSG_ERROR,
5730 "Setting of HE fragmentation failed");
5731 }
5732#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005733
5734 /* Enable WEP/TKIP with HE capability in testbed */
5735 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
5736 sigma_dut_print(dut, DUT_MSG_ERROR,
5737 "Enabling HE config with WEP/TKIP failed");
5738 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005739 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005740 }
5741}
5742
5743
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744static int cmd_sta_reset_default(struct sigma_dut *dut,
5745 struct sigma_conn *conn,
5746 struct sigma_cmd *cmd)
5747{
5748 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5749 struct sigma_cmd *cmd);
5750 const char *intf = get_param(cmd, "Interface");
5751 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005752 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305753 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005754
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005755 if (!program)
5756 program = get_param(cmd, "prog");
5757 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005758 dut->device_type = STA_unknown;
5759 type = get_param(cmd, "type");
5760 if (type && strcasecmp(type, "Testbed") == 0)
5761 dut->device_type = STA_testbed;
5762 if (type && strcasecmp(type, "DUT") == 0)
5763 dut->device_type = STA_dut;
5764
5765 if (dut->program == PROGRAM_TDLS) {
5766 /* Clear TDLS testing mode */
5767 wpa_command(intf, "SET tdls_disabled 0");
5768 wpa_command(intf, "SET tdls_testing 0");
5769 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305770 if (get_driver_type() == DRIVER_WCN) {
5771 /* Enable the WCN driver in TDLS Explicit trigger mode
5772 */
5773 wpa_command(intf, "SET tdls_external_control 0");
5774 wpa_command(intf, "SET tdls_trigger_control 0");
5775 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005776 }
5777
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005778#ifdef MIRACAST
5779 if (dut->program == PROGRAM_WFD ||
5780 dut->program == PROGRAM_DISPLAYR2)
5781 miracast_sta_reset_default(dut, conn, cmd);
5782#endif /* MIRACAST */
5783
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005784 switch (get_driver_type()) {
5785 case DRIVER_ATHEROS:
5786 sta_reset_default_ath(dut, intf, type);
5787 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005788 case DRIVER_WCN:
5789 sta_reset_default_wcn(dut, intf, type);
5790 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005791 default:
5792 break;
5793 }
5794
5795#ifdef ANDROID_NAN
5796 if (dut->program == PROGRAM_NAN)
5797 nan_cmd_sta_reset_default(dut, conn, cmd);
5798#endif /* ANDROID_NAN */
5799
5800 if (dut->program == PROGRAM_HS2_R2) {
5801 unlink("SP/wi-fi.org/pps.xml");
5802 if (system("rm -r SP/*") != 0) {
5803 }
5804 unlink("next-client-cert.pem");
5805 unlink("next-client-key.pem");
5806 }
5807
5808 if (dut->program == PROGRAM_60GHZ) {
5809 const char *dev_role = get_param(cmd, "DevRole");
5810
5811 if (!dev_role) {
5812 send_resp(dut, conn, SIGMA_ERROR,
5813 "errorCode,Missing DevRole argument");
5814 return 0;
5815 }
5816
5817 if (strcasecmp(dev_role, "STA") == 0)
5818 dut->dev_role = DEVROLE_STA;
5819 else if (strcasecmp(dev_role, "PCP") == 0)
5820 dut->dev_role = DEVROLE_PCP;
5821 else {
5822 send_resp(dut, conn, SIGMA_ERROR,
5823 "errorCode,Unknown DevRole");
5824 return 0;
5825 }
5826
5827 if (dut->device_type == STA_unknown) {
5828 sigma_dut_print(dut, DUT_MSG_ERROR,
5829 "Device type is not STA testbed or DUT");
5830 send_resp(dut, conn, SIGMA_ERROR,
5831 "errorCode,Unknown device type");
5832 return 0;
5833 }
5834 }
5835
5836 wpa_command(intf, "WPS_ER_STOP");
5837 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305838 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005839 wpa_command(intf, "SET radio_disabled 0");
5840
5841 if (dut->tmp_mac_addr && dut->set_macaddr) {
5842 dut->tmp_mac_addr = 0;
5843 if (system(dut->set_macaddr) != 0) {
5844 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5845 "temporary MAC address");
5846 }
5847 }
5848
5849 set_ps(intf, dut, 0);
5850
5851 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5852 wpa_command(intf, "SET interworking 1");
5853 wpa_command(intf, "SET hs20 1");
5854 }
5855
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08005856 if (dut->program == PROGRAM_HS2_R2 ||
5857 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005858 wpa_command(intf, "SET pmf 1");
5859 } else {
5860 wpa_command(intf, "SET pmf 0");
5861 }
5862
5863 hs2_clear_credentials(intf);
5864 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
5865 wpa_command(intf, "SET access_network_type 15");
5866
5867 static_ip_file(0, NULL, NULL, NULL);
5868 kill_dhcp_client(dut, intf);
5869 clear_ip_addr(dut, intf);
5870
5871 dut->er_oper_performed = 0;
5872 dut->er_oper_bssid[0] = '\0';
5873
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07005874 if (dut->program == PROGRAM_LOC) {
5875 /* Disable Interworking by default */
5876 wpa_command(get_station_ifname(), "SET interworking 0");
5877 }
5878
Ashwini Patil00402582017-04-13 12:29:39 +05305879 if (dut->program == PROGRAM_MBO) {
5880 free(dut->non_pref_ch_list);
5881 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05305882 free(dut->btm_query_cand_list);
5883 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05305884 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05305885 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05305886 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305887 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05305888 }
5889
Jouni Malinen3c367e82017-06-23 17:01:47 +03005890 free(dut->rsne_override);
5891 dut->rsne_override = NULL;
5892
Jouni Malinen68143132017-09-02 02:34:08 +03005893 free(dut->sae_commit_override);
5894 dut->sae_commit_override = NULL;
5895
Jouni Malinend86e5822017-08-29 03:55:32 +03005896 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02005897 free(dut->dpp_peer_uri);
5898 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02005899 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02005900 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03005901
Jouni Malinenfac9cad2017-10-10 18:35:55 +03005902 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
5903
vamsi krishnaa2799492017-12-05 14:28:01 +05305904 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305905 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05305906 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305907 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
5908 dut->fils_hlp = 0;
5909#ifdef ANDROID
5910 hlp_thread_cleanup(dut);
5911#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05305912 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305913
Sunil Dutt076081f2018-02-05 19:45:50 +05305914#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05305915 if (get_driver_type() == DRIVER_WCN &&
5916 dut->config_rsnie == 1) {
5917 dut->config_rsnie = 0;
5918 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05305919 }
5920#endif /* NL80211_SUPPORT */
5921
Sunil Duttfebf8a82018-02-09 18:50:13 +05305922 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
5923 dut->dev_role = DEVROLE_STA_CFON;
5924 return sta_cfon_reset_default(dut, conn, cmd);
5925 }
5926
5927 if (dut->program != PROGRAM_VHT)
5928 return cmd_sta_p2p_reset(dut, conn, cmd);
5929
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08005930 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005931}
5932
5933
5934static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
5935 struct sigma_cmd *cmd)
5936{
5937 const char *program = get_param(cmd, "Program");
5938
5939 if (program == NULL)
5940 return -1;
5941#ifdef ANDROID_NAN
5942 if (strcasecmp(program, "NAN") == 0)
5943 return nan_cmd_sta_get_events(dut, conn, cmd);
5944#endif /* ANDROID_NAN */
5945 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5946 return 0;
5947}
5948
5949
5950static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
5951 struct sigma_cmd *cmd)
5952{
5953 const char *program = get_param(cmd, "Prog");
5954
5955 if (program == NULL)
5956 return -1;
5957#ifdef ANDROID_NAN
5958 if (strcasecmp(program, "NAN") == 0)
5959 return nan_cmd_sta_exec_action(dut, conn, cmd);
5960#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005961 if (strcasecmp(program, "Loc") == 0)
5962 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005963 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5964 return 0;
5965}
5966
5967
5968static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
5969 struct sigma_cmd *cmd)
5970{
5971 const char *intf = get_param(cmd, "Interface");
5972 const char *val, *mcs32, *rate;
5973
5974 val = get_param(cmd, "GREENFIELD");
5975 if (val) {
5976 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5977 /* Enable GD */
5978 send_resp(dut, conn, SIGMA_ERROR,
5979 "ErrorCode,GF not supported");
5980 return 0;
5981 }
5982 }
5983
5984 val = get_param(cmd, "SGI20");
5985 if (val) {
5986 switch (get_driver_type()) {
5987 case DRIVER_ATHEROS:
5988 ath_sta_set_sgi(dut, intf, val);
5989 break;
5990 default:
5991 send_resp(dut, conn, SIGMA_ERROR,
5992 "ErrorCode,SGI20 not supported");
5993 return 0;
5994 }
5995 }
5996
5997 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
5998 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
5999 if (mcs32 && rate) {
6000 /* TODO */
6001 send_resp(dut, conn, SIGMA_ERROR,
6002 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6003 return 0;
6004 } else if (mcs32 && !rate) {
6005 /* TODO */
6006 send_resp(dut, conn, SIGMA_ERROR,
6007 "ErrorCode,MCS32 not supported");
6008 return 0;
6009 } else if (!mcs32 && rate) {
6010 switch (get_driver_type()) {
6011 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006012 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006013 ath_sta_set_11nrates(dut, intf, rate);
6014 break;
6015 default:
6016 send_resp(dut, conn, SIGMA_ERROR,
6017 "ErrorCode,MCS32_FIXEDRATE not supported");
6018 return 0;
6019 }
6020 }
6021
6022 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6023}
6024
6025
6026static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
6027 struct sigma_conn *conn,
6028 struct sigma_cmd *cmd)
6029{
6030 const char *intf = get_param(cmd, "Interface");
6031 const char *val;
6032 char buf[30];
6033 int tkip = -1;
6034 int wep = -1;
6035
6036 val = get_param(cmd, "SGI80");
6037 if (val) {
6038 int sgi80;
6039
6040 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6041 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
6042 if (system(buf) != 0) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "iwpriv shortgi failed");
6045 }
6046 }
6047
6048 val = get_param(cmd, "TxBF");
6049 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6050 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
6051 if (system(buf) != 0) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "iwpriv vhtsubfee failed");
6054 }
6055 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
6056 if (system(buf) != 0) {
6057 sigma_dut_print(dut, DUT_MSG_ERROR,
6058 "iwpriv vhtsubfer failed");
6059 }
6060 }
6061
6062 val = get_param(cmd, "MU_TxBF");
6063 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6064 switch (get_driver_type()) {
6065 case DRIVER_ATHEROS:
6066 ath_sta_set_txsp_stream(dut, intf, "1SS");
6067 ath_sta_set_rxsp_stream(dut, intf, "1SS");
6068 case DRIVER_WCN:
6069 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
6070 send_resp(dut, conn, SIGMA_ERROR,
6071 "ErrorCode,Failed to set RX/TXSP_STREAM");
6072 return 0;
6073 }
6074 default:
6075 sigma_dut_print(dut, DUT_MSG_ERROR,
6076 "Setting SP_STREAM not supported");
6077 break;
6078 }
6079 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
6080 if (system(buf) != 0) {
6081 sigma_dut_print(dut, DUT_MSG_ERROR,
6082 "iwpriv vhtmubfee failed");
6083 }
6084 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
6085 if (system(buf) != 0) {
6086 sigma_dut_print(dut, DUT_MSG_ERROR,
6087 "iwpriv vhtmubfer failed");
6088 }
6089 }
6090
6091 val = get_param(cmd, "LDPC");
6092 if (val) {
6093 int ldpc;
6094
6095 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6096 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
6097 if (system(buf) != 0) {
6098 sigma_dut_print(dut, DUT_MSG_ERROR,
6099 "iwpriv ldpc failed");
6100 }
6101 }
6102
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08006103 val = get_param(cmd, "BCC");
6104 if (val) {
6105 int bcc;
6106
6107 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6108 /* use LDPC iwpriv itself to set bcc coding, bcc coding
6109 * is mutually exclusive to bcc */
6110 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
6111 if (system(buf) != 0) {
6112 sigma_dut_print(dut, DUT_MSG_ERROR,
6113 "Enabling/Disabling of BCC failed");
6114 }
6115 }
6116
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 val = get_param(cmd, "opt_md_notif_ie");
6118 if (val) {
6119 char *result = NULL;
6120 char delim[] = ";";
6121 char token[30];
6122 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306123 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006124
Peng Xub8fc5cc2017-05-10 17:27:28 -07006125 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306126 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006127
6128 /* Extract the NSS information */
6129 if (result) {
6130 value = atoi(result);
6131 switch (value) {
6132 case 1:
6133 config_val = 1;
6134 break;
6135 case 2:
6136 config_val = 3;
6137 break;
6138 case 3:
6139 config_val = 7;
6140 break;
6141 case 4:
6142 config_val = 15;
6143 break;
6144 default:
6145 config_val = 3;
6146 break;
6147 }
6148
6149 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6150 intf, config_val);
6151 if (system(buf) != 0) {
6152 sigma_dut_print(dut, DUT_MSG_ERROR,
6153 "iwpriv rxchainmask failed");
6154 }
6155
6156 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
6157 intf, config_val);
6158 if (system(buf) != 0) {
6159 sigma_dut_print(dut, DUT_MSG_ERROR,
6160 "iwpriv txchainmask failed");
6161 }
6162 }
6163
6164 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306165 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006166 if (result) {
6167 value = atoi(result);
6168 switch (value) {
6169 case 20:
6170 config_val = 0;
6171 break;
6172 case 40:
6173 config_val = 1;
6174 break;
6175 case 80:
6176 config_val = 2;
6177 break;
6178 case 160:
6179 config_val = 3;
6180 break;
6181 default:
6182 config_val = 2;
6183 break;
6184 }
6185
6186 dut->chwidth = config_val;
6187
6188 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6189 intf, config_val);
6190 if (system(buf) != 0) {
6191 sigma_dut_print(dut, DUT_MSG_ERROR,
6192 "iwpriv chwidth failed");
6193 }
6194 }
6195
6196 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
6197 if (system(buf) != 0) {
6198 sigma_dut_print(dut, DUT_MSG_ERROR,
6199 "iwpriv opmode_notify failed");
6200 }
6201 }
6202
6203 val = get_param(cmd, "nss_mcs_cap");
6204 if (val) {
6205 int nss, mcs;
6206 char token[20];
6207 char *result = NULL;
6208 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306209 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006210
Peng Xub8fc5cc2017-05-10 17:27:28 -07006211 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306212 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306213 if (!result) {
6214 sigma_dut_print(dut, DUT_MSG_ERROR,
6215 "VHT NSS not specified");
6216 return 0;
6217 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006218 nss = atoi(result);
6219
6220 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
6221 if (system(buf) != 0) {
6222 sigma_dut_print(dut, DUT_MSG_ERROR,
6223 "iwpriv nss failed");
6224 }
6225
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306226 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006227 if (result == NULL) {
6228 sigma_dut_print(dut, DUT_MSG_ERROR,
6229 "VHTMCS NOT SPECIFIED!");
6230 return 0;
6231 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306232 result = strtok_r(result, "-", &saveptr);
6233 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306234 if (!result) {
6235 sigma_dut_print(dut, DUT_MSG_ERROR,
6236 "VHT MCS not specified");
6237 return 0;
6238 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006239 mcs = atoi(result);
6240
6241 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
6242 if (system(buf) != 0) {
6243 sigma_dut_print(dut, DUT_MSG_ERROR,
6244 "iwpriv mcs failed");
6245 }
6246
6247 switch (nss) {
6248 case 1:
6249 switch (mcs) {
6250 case 7:
6251 vht_mcsmap = 0xfffc;
6252 break;
6253 case 8:
6254 vht_mcsmap = 0xfffd;
6255 break;
6256 case 9:
6257 vht_mcsmap = 0xfffe;
6258 break;
6259 default:
6260 vht_mcsmap = 0xfffe;
6261 break;
6262 }
6263 break;
6264 case 2:
6265 switch (mcs) {
6266 case 7:
6267 vht_mcsmap = 0xfff0;
6268 break;
6269 case 8:
6270 vht_mcsmap = 0xfff5;
6271 break;
6272 case 9:
6273 vht_mcsmap = 0xfffa;
6274 break;
6275 default:
6276 vht_mcsmap = 0xfffa;
6277 break;
6278 }
6279 break;
6280 case 3:
6281 switch (mcs) {
6282 case 7:
6283 vht_mcsmap = 0xffc0;
6284 break;
6285 case 8:
6286 vht_mcsmap = 0xffd5;
6287 break;
6288 case 9:
6289 vht_mcsmap = 0xffea;
6290 break;
6291 default:
6292 vht_mcsmap = 0xffea;
6293 break;
6294 }
6295 break;
6296 default:
6297 vht_mcsmap = 0xffea;
6298 break;
6299 }
6300 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
6301 intf, vht_mcsmap);
6302 if (system(buf) != 0) {
6303 sigma_dut_print(dut, DUT_MSG_ERROR,
6304 "iwpriv vht_mcsmap failed");
6305 }
6306 }
6307
6308 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
6309
6310 val = get_param(cmd, "Vht_tkip");
6311 if (val)
6312 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6313
6314 val = get_param(cmd, "Vht_wep");
6315 if (val)
6316 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6317
6318 if (tkip != -1 || wep != -1) {
6319 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
6320 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
6321 intf);
6322 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
6323 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
6324 intf);
6325 } else {
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
6328 return 0;
6329 }
6330
6331 if (system(buf) != 0) {
6332 sigma_dut_print(dut, DUT_MSG_ERROR,
6333 "iwpriv htweptkip failed");
6334 }
6335 }
6336
6337 val = get_param(cmd, "txBandwidth");
6338 if (val) {
6339 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006340 case DRIVER_WCN:
6341 if (wcn_sta_set_width(dut, intf, val) < 0) {
6342 send_resp(dut, conn, SIGMA_ERROR,
6343 "ErrorCode,Failed to set txBandwidth");
6344 return 0;
6345 }
6346 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347 case DRIVER_ATHEROS:
6348 if (ath_set_width(dut, conn, intf, val) < 0) {
6349 send_resp(dut, conn, SIGMA_ERROR,
6350 "ErrorCode,Failed to set txBandwidth");
6351 return 0;
6352 }
6353 break;
6354 default:
6355 sigma_dut_print(dut, DUT_MSG_ERROR,
6356 "Setting txBandwidth not supported");
6357 break;
6358 }
6359 }
6360
6361 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6362}
6363
6364
6365static int sta_set_wireless_60g(struct sigma_dut *dut,
6366 struct sigma_conn *conn,
6367 struct sigma_cmd *cmd)
6368{
6369 const char *dev_role = get_param(cmd, "DevRole");
6370
6371 if (!dev_role) {
6372 send_resp(dut, conn, SIGMA_INVALID,
6373 "ErrorCode,DevRole not specified");
6374 return 0;
6375 }
6376
6377 if (strcasecmp(dev_role, "PCP") == 0)
6378 return sta_set_60g_pcp(dut, conn, cmd);
6379 if (strcasecmp(dev_role, "STA") == 0)
6380 return sta_set_60g_sta(dut, conn, cmd);
6381 send_resp(dut, conn, SIGMA_INVALID,
6382 "ErrorCode,DevRole not supported");
6383 return 0;
6384}
6385
6386
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306387static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
6388 struct sigma_cmd *cmd)
6389{
6390 int status;
6391 const char *intf = get_param(cmd, "Interface");
6392 const char *val = get_param(cmd, "DevRole");
6393
6394 if (val && strcasecmp(val, "STA-CFON") == 0) {
6395 status = sta_cfon_set_wireless(dut, conn, cmd);
6396 if (status)
6397 return status;
6398 }
6399 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6400}
6401
6402
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006403static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6404 struct sigma_cmd *cmd)
6405{
6406 const char *val;
6407
6408 val = get_param(cmd, "Program");
6409 if (val) {
6410 if (strcasecmp(val, "11n") == 0)
6411 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006412 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006413 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6414 if (strcasecmp(val, "60ghz") == 0)
6415 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306416 if (strcasecmp(val, "OCE") == 0)
6417 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418 send_resp(dut, conn, SIGMA_ERROR,
6419 "ErrorCode,Program value not supported");
6420 } else {
6421 send_resp(dut, conn, SIGMA_ERROR,
6422 "ErrorCode,Program argument not available");
6423 }
6424
6425 return 0;
6426}
6427
6428
6429static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6430 int tid)
6431{
6432 char buf[100];
6433 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6434
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306435 if (tid < 0 ||
6436 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6437 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6438 return;
6439 }
6440
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006441 /*
6442 * Two ways to ensure that addba request with a
6443 * non zero TID could be sent out. EV 117296
6444 */
6445 snprintf(buf, sizeof(buf),
6446 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6447 tid);
6448 if (system(buf) != 0) {
6449 sigma_dut_print(dut, DUT_MSG_ERROR,
6450 "Ping did not send out");
6451 }
6452
6453 snprintf(buf, sizeof(buf),
6454 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6455 intf, VI_QOS_TMP_FILE);
6456 if (system(buf) != 0)
6457 return;
6458
6459 snprintf(buf, sizeof(buf),
6460 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6461 intf, VI_QOS_TMP_FILE);
6462 if (system(buf) != 0)
6463 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6464
6465 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6466 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6467 if (system(buf) != 0) {
6468 sigma_dut_print(dut, DUT_MSG_ERROR,
6469 "VI_QOS_TEMP_FILE generation error failed");
6470 }
6471 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6472 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6473 if (system(buf) != 0) {
6474 sigma_dut_print(dut, DUT_MSG_ERROR,
6475 "VI_QOS_FILE generation failed");
6476 }
6477
6478 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6479 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6480 if (system(buf) != 0) {
6481 sigma_dut_print(dut, DUT_MSG_ERROR,
6482 "VI_QOS_FILE generation failed");
6483 }
6484
6485 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6486 if (system(buf) != 0) {
6487 }
6488}
6489
6490
6491static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6492 struct sigma_cmd *cmd)
6493{
6494 const char *intf = get_param(cmd, "Interface");
6495 const char *val;
6496 int tid = 0;
6497 char buf[100];
6498
6499 val = get_param(cmd, "TID");
6500 if (val) {
6501 tid = atoi(val);
6502 if (tid)
6503 ath_sta_inject_frame(dut, intf, tid);
6504 }
6505
6506 /* Command sequence for ADDBA request on Peregrine based devices */
6507 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6508 if (system(buf) != 0) {
6509 sigma_dut_print(dut, DUT_MSG_ERROR,
6510 "iwpriv setaddbaoper failed");
6511 }
6512
6513 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6514 if (system(buf) != 0) {
6515 sigma_dut_print(dut, DUT_MSG_ERROR,
6516 "wifitool senddelba failed");
6517 }
6518
6519 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6520 if (system(buf) != 0) {
6521 sigma_dut_print(dut, DUT_MSG_ERROR,
6522 "wifitool sendaddba failed");
6523 }
6524
6525 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6526
6527 return 1;
6528}
6529
6530
Lior David9981b512017-01-20 13:16:40 +02006531#ifdef __linux__
6532
6533static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6534 int agg_size)
6535{
6536 char dir[128], buf[128];
6537 FILE *f;
6538 regex_t re;
6539 regmatch_t m[2];
6540 int rc, ret = -1, vring_id, found;
6541
6542 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6543 sigma_dut_print(dut, DUT_MSG_ERROR,
6544 "failed to get wil6210 debugfs dir");
6545 return -1;
6546 }
6547
6548 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6549 f = fopen(buf, "r");
6550 if (!f) {
6551 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6552 return -1;
6553 }
6554
6555 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6556 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6557 goto out;
6558 }
6559
6560 /* find TX VRING for the mac address */
6561 found = 0;
6562 while (fgets(buf, sizeof(buf), f)) {
6563 if (strcasestr(buf, dest_mac)) {
6564 found = 1;
6565 break;
6566 }
6567 }
6568
6569 if (!found) {
6570 sigma_dut_print(dut, DUT_MSG_ERROR,
6571 "no TX VRING for %s", dest_mac);
6572 goto out;
6573 }
6574
6575 /* extract VRING ID, "VRING tx_<id> = {" */
6576 if (!fgets(buf, sizeof(buf), f)) {
6577 sigma_dut_print(dut, DUT_MSG_ERROR,
6578 "no VRING start line for %s", dest_mac);
6579 goto out;
6580 }
6581
6582 rc = regexec(&re, buf, 2, m, 0);
6583 regfree(&re);
6584 if (rc || m[1].rm_so < 0) {
6585 sigma_dut_print(dut, DUT_MSG_ERROR,
6586 "no VRING TX ID for %s", dest_mac);
6587 goto out;
6588 }
6589 buf[m[1].rm_eo] = 0;
6590 vring_id = atoi(&buf[m[1].rm_so]);
6591
6592 /* send the addba command */
6593 fclose(f);
6594 snprintf(buf, sizeof(buf), "%s/back", dir);
6595 f = fopen(buf, "w");
6596 if (!f) {
6597 sigma_dut_print(dut, DUT_MSG_ERROR,
6598 "failed to open: %s", buf);
6599 return -1;
6600 }
6601
6602 fprintf(f, "add %d %d\n", vring_id, agg_size);
6603
6604 ret = 0;
6605
6606out:
6607 fclose(f);
6608
6609 return ret;
6610}
6611
6612
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006613static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6614 struct sigma_cmd *cmd)
6615{
6616 const char *val;
6617 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006618
6619 val = get_param(cmd, "TID");
6620 if (val) {
6621 tid = atoi(val);
6622 if (tid != 0) {
6623 sigma_dut_print(dut, DUT_MSG_ERROR,
6624 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6625 tid);
6626 }
6627 }
6628
6629 val = get_param(cmd, "Dest_mac");
6630 if (!val) {
6631 sigma_dut_print(dut, DUT_MSG_ERROR,
6632 "Currently not supporting addba for 60G without Dest_mac");
6633 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6634 }
6635
Lior David9981b512017-01-20 13:16:40 +02006636 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006637 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006638
6639 return 1;
6640}
6641
Lior David9981b512017-01-20 13:16:40 +02006642#endif /* __linux__ */
6643
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006644
6645static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6646 struct sigma_cmd *cmd)
6647{
6648 switch (get_driver_type()) {
6649 case DRIVER_ATHEROS:
6650 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006651#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006652 case DRIVER_WIL6210:
6653 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006654#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 default:
6656 /*
6657 * There is no driver specific implementation for other drivers.
6658 * Ignore the command and report COMPLETE since the following
6659 * throughput test operation will end up sending ADDBA anyway.
6660 */
6661 return 1;
6662 }
6663}
6664
6665
6666int inject_eth_frame(int s, const void *data, size_t len,
6667 unsigned short ethtype, char *dst, char *src)
6668{
6669 struct iovec iov[4] = {
6670 {
6671 .iov_base = dst,
6672 .iov_len = ETH_ALEN,
6673 },
6674 {
6675 .iov_base = src,
6676 .iov_len = ETH_ALEN,
6677 },
6678 {
6679 .iov_base = &ethtype,
6680 .iov_len = sizeof(unsigned short),
6681 },
6682 {
6683 .iov_base = (void *) data,
6684 .iov_len = len,
6685 }
6686 };
6687 struct msghdr msg = {
6688 .msg_name = NULL,
6689 .msg_namelen = 0,
6690 .msg_iov = iov,
6691 .msg_iovlen = 4,
6692 .msg_control = NULL,
6693 .msg_controllen = 0,
6694 .msg_flags = 0,
6695 };
6696
6697 return sendmsg(s, &msg, 0);
6698}
6699
6700#if defined(__linux__) || defined(__QNXNTO__)
6701
6702int inject_frame(int s, const void *data, size_t len, int encrypt)
6703{
6704#define IEEE80211_RADIOTAP_F_WEP 0x04
6705#define IEEE80211_RADIOTAP_F_FRAG 0x08
6706 unsigned char rtap_hdr[] = {
6707 0x00, 0x00, /* radiotap version */
6708 0x0e, 0x00, /* radiotap length */
6709 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6710 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
6711 0x00, /* padding */
6712 0x00, 0x00, /* RX and TX flags to indicate that */
6713 0x00, 0x00, /* this is the injected frame directly */
6714 };
6715 struct iovec iov[2] = {
6716 {
6717 .iov_base = &rtap_hdr,
6718 .iov_len = sizeof(rtap_hdr),
6719 },
6720 {
6721 .iov_base = (void *) data,
6722 .iov_len = len,
6723 }
6724 };
6725 struct msghdr msg = {
6726 .msg_name = NULL,
6727 .msg_namelen = 0,
6728 .msg_iov = iov,
6729 .msg_iovlen = 2,
6730 .msg_control = NULL,
6731 .msg_controllen = 0,
6732 .msg_flags = 0,
6733 };
6734
6735 if (encrypt)
6736 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
6737
6738 return sendmsg(s, &msg, 0);
6739}
6740
6741
6742int open_monitor(const char *ifname)
6743{
6744#ifdef __QNXNTO__
6745 struct sockaddr_dl ll;
6746 int s;
6747
6748 memset(&ll, 0, sizeof(ll));
6749 ll.sdl_family = AF_LINK;
6750 ll.sdl_index = if_nametoindex(ifname);
6751 if (ll.sdl_index == 0) {
6752 perror("if_nametoindex");
6753 return -1;
6754 }
6755 s = socket(PF_INET, SOCK_RAW, 0);
6756#else /* __QNXNTO__ */
6757 struct sockaddr_ll ll;
6758 int s;
6759
6760 memset(&ll, 0, sizeof(ll));
6761 ll.sll_family = AF_PACKET;
6762 ll.sll_ifindex = if_nametoindex(ifname);
6763 if (ll.sll_ifindex == 0) {
6764 perror("if_nametoindex");
6765 return -1;
6766 }
6767 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
6768#endif /* __QNXNTO__ */
6769 if (s < 0) {
6770 perror("socket[PF_PACKET,SOCK_RAW]");
6771 return -1;
6772 }
6773
6774 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
6775 perror("monitor socket bind");
6776 close(s);
6777 return -1;
6778 }
6779
6780 return s;
6781}
6782
6783
6784static int hex2num(char c)
6785{
6786 if (c >= '0' && c <= '9')
6787 return c - '0';
6788 if (c >= 'a' && c <= 'f')
6789 return c - 'a' + 10;
6790 if (c >= 'A' && c <= 'F')
6791 return c - 'A' + 10;
6792 return -1;
6793}
6794
6795
6796int hwaddr_aton(const char *txt, unsigned char *addr)
6797{
6798 int i;
6799
6800 for (i = 0; i < 6; i++) {
6801 int a, b;
6802
6803 a = hex2num(*txt++);
6804 if (a < 0)
6805 return -1;
6806 b = hex2num(*txt++);
6807 if (b < 0)
6808 return -1;
6809 *addr++ = (a << 4) | b;
6810 if (i < 5 && *txt++ != ':')
6811 return -1;
6812 }
6813
6814 return 0;
6815}
6816
6817#endif /* defined(__linux__) || defined(__QNXNTO__) */
6818
6819enum send_frame_type {
6820 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
6821};
6822enum send_frame_protection {
6823 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6824};
6825
6826
6827static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6828 enum send_frame_type frame,
6829 enum send_frame_protection protected,
6830 const char *dest)
6831{
6832#ifdef __linux__
6833 unsigned char buf[1000], *pos;
6834 int s, res;
6835 char bssid[20], addr[20];
6836 char result[32], ssid[100];
6837 size_t ssid_len;
6838
6839 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6840 sizeof(result)) < 0 ||
6841 strncmp(result, "COMPLETED", 9) != 0) {
6842 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
6843 return 0;
6844 }
6845
6846 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
6847 < 0) {
6848 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6849 "current BSSID");
6850 return 0;
6851 }
6852
6853 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
6854 < 0) {
6855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6856 "own MAC address");
6857 return 0;
6858 }
6859
6860 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
6861 < 0) {
6862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6863 "current SSID");
6864 return 0;
6865 }
6866 ssid_len = strlen(ssid);
6867
6868 pos = buf;
6869
6870 /* Frame Control */
6871 switch (frame) {
6872 case DISASSOC:
6873 *pos++ = 0xa0;
6874 break;
6875 case DEAUTH:
6876 *pos++ = 0xc0;
6877 break;
6878 case SAQUERY:
6879 *pos++ = 0xd0;
6880 break;
6881 case AUTH:
6882 *pos++ = 0xb0;
6883 break;
6884 case ASSOCREQ:
6885 *pos++ = 0x00;
6886 break;
6887 case REASSOCREQ:
6888 *pos++ = 0x20;
6889 break;
6890 case DLS_REQ:
6891 *pos++ = 0xd0;
6892 break;
6893 }
6894
6895 if (protected == INCORRECT_KEY)
6896 *pos++ = 0x40; /* Set Protected field to 1 */
6897 else
6898 *pos++ = 0x00;
6899
6900 /* Duration */
6901 *pos++ = 0x00;
6902 *pos++ = 0x00;
6903
6904 /* addr1 = DA (current AP) */
6905 hwaddr_aton(bssid, pos);
6906 pos += 6;
6907 /* addr2 = SA (own address) */
6908 hwaddr_aton(addr, pos);
6909 pos += 6;
6910 /* addr3 = BSSID (current AP) */
6911 hwaddr_aton(bssid, pos);
6912 pos += 6;
6913
6914 /* Seq# (to be filled by driver/mac80211) */
6915 *pos++ = 0x00;
6916 *pos++ = 0x00;
6917
6918 if (protected == INCORRECT_KEY) {
6919 /* CCMP parameters */
6920 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6921 pos += 8;
6922 }
6923
6924 if (protected == INCORRECT_KEY) {
6925 switch (frame) {
6926 case DEAUTH:
6927 /* Reason code (encrypted) */
6928 memcpy(pos, "\xa7\x39", 2);
6929 pos += 2;
6930 break;
6931 case DISASSOC:
6932 /* Reason code (encrypted) */
6933 memcpy(pos, "\xa7\x39", 2);
6934 pos += 2;
6935 break;
6936 case SAQUERY:
6937 /* Category|Action|TransID (encrypted) */
6938 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6939 pos += 4;
6940 break;
6941 default:
6942 return -1;
6943 }
6944
6945 /* CCMP MIC */
6946 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6947 pos += 8;
6948 } else {
6949 switch (frame) {
6950 case DEAUTH:
6951 /* reason code = 8 */
6952 *pos++ = 0x08;
6953 *pos++ = 0x00;
6954 break;
6955 case DISASSOC:
6956 /* reason code = 8 */
6957 *pos++ = 0x08;
6958 *pos++ = 0x00;
6959 break;
6960 case SAQUERY:
6961 /* Category - SA Query */
6962 *pos++ = 0x08;
6963 /* SA query Action - Request */
6964 *pos++ = 0x00;
6965 /* Transaction ID */
6966 *pos++ = 0x12;
6967 *pos++ = 0x34;
6968 break;
6969 case AUTH:
6970 /* Auth Alg (Open) */
6971 *pos++ = 0x00;
6972 *pos++ = 0x00;
6973 /* Seq# */
6974 *pos++ = 0x01;
6975 *pos++ = 0x00;
6976 /* Status code */
6977 *pos++ = 0x00;
6978 *pos++ = 0x00;
6979 break;
6980 case ASSOCREQ:
6981 /* Capability Information */
6982 *pos++ = 0x31;
6983 *pos++ = 0x04;
6984 /* Listen Interval */
6985 *pos++ = 0x0a;
6986 *pos++ = 0x00;
6987 /* SSID */
6988 *pos++ = 0x00;
6989 *pos++ = ssid_len;
6990 memcpy(pos, ssid, ssid_len);
6991 pos += ssid_len;
6992 /* Supported Rates */
6993 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6994 10);
6995 pos += 10;
6996 /* Extended Supported Rates */
6997 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6998 pos += 6;
6999 /* RSN */
7000 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7001 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7002 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7003 pos += 28;
7004 break;
7005 case REASSOCREQ:
7006 /* Capability Information */
7007 *pos++ = 0x31;
7008 *pos++ = 0x04;
7009 /* Listen Interval */
7010 *pos++ = 0x0a;
7011 *pos++ = 0x00;
7012 /* Current AP */
7013 hwaddr_aton(bssid, pos);
7014 pos += 6;
7015 /* SSID */
7016 *pos++ = 0x00;
7017 *pos++ = ssid_len;
7018 memcpy(pos, ssid, ssid_len);
7019 pos += ssid_len;
7020 /* Supported Rates */
7021 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
7022 10);
7023 pos += 10;
7024 /* Extended Supported Rates */
7025 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
7026 pos += 6;
7027 /* RSN */
7028 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
7029 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
7030 "\x00\x00\x00\x00\x0f\xac\x06", 28);
7031 pos += 28;
7032 break;
7033 case DLS_REQ:
7034 /* Category - DLS */
7035 *pos++ = 0x02;
7036 /* DLS Action - Request */
7037 *pos++ = 0x00;
7038 /* Destination MACAddress */
7039 if (dest)
7040 hwaddr_aton(dest, pos);
7041 else
7042 memset(pos, 0, 6);
7043 pos += 6;
7044 /* Source MACAddress */
7045 hwaddr_aton(addr, pos);
7046 pos += 6;
7047 /* Capability Information */
7048 *pos++ = 0x10; /* Privacy */
7049 *pos++ = 0x06; /* QoS */
7050 /* DLS Timeout Value */
7051 *pos++ = 0x00;
7052 *pos++ = 0x01;
7053 /* Supported rates */
7054 *pos++ = 0x01;
7055 *pos++ = 0x08;
7056 *pos++ = 0x0c; /* 6 Mbps */
7057 *pos++ = 0x12; /* 9 Mbps */
7058 *pos++ = 0x18; /* 12 Mbps */
7059 *pos++ = 0x24; /* 18 Mbps */
7060 *pos++ = 0x30; /* 24 Mbps */
7061 *pos++ = 0x48; /* 36 Mbps */
7062 *pos++ = 0x60; /* 48 Mbps */
7063 *pos++ = 0x6c; /* 54 Mbps */
7064 /* TODO: Extended Supported Rates */
7065 /* TODO: HT Capabilities */
7066 break;
7067 }
7068 }
7069
7070 s = open_monitor("sigmadut");
7071 if (s < 0) {
7072 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7073 "monitor socket");
7074 return 0;
7075 }
7076
7077 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
7078 if (res < 0) {
7079 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7080 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307081 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007082 return 0;
7083 }
7084 if (res < pos - buf) {
7085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
7086 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307087 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007088 return 0;
7089 }
7090
7091 close(s);
7092
7093 return 1;
7094#else /* __linux__ */
7095 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
7096 "yet supported");
7097 return 0;
7098#endif /* __linux__ */
7099}
7100
7101
7102static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
7103 struct sigma_conn *conn,
7104 struct sigma_cmd *cmd)
7105{
7106 const char *intf = get_param(cmd, "Interface");
7107 const char *sta, *val;
7108 unsigned char addr[ETH_ALEN];
7109 char buf[100];
7110
7111 sta = get_param(cmd, "peer");
7112 if (sta == NULL)
7113 sta = get_param(cmd, "station");
7114 if (sta == NULL) {
7115 send_resp(dut, conn, SIGMA_ERROR,
7116 "ErrorCode,Missing peer address");
7117 return 0;
7118 }
7119 if (hwaddr_aton(sta, addr) < 0) {
7120 send_resp(dut, conn, SIGMA_ERROR,
7121 "ErrorCode,Invalid peer address");
7122 return 0;
7123 }
7124
7125 val = get_param(cmd, "type");
7126 if (val == NULL)
7127 return -1;
7128
7129 if (strcasecmp(val, "DISCOVERY") == 0) {
7130 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
7131 if (wpa_command(intf, buf) < 0) {
7132 send_resp(dut, conn, SIGMA_ERROR,
7133 "ErrorCode,Failed to send TDLS discovery");
7134 return 0;
7135 }
7136 return 1;
7137 }
7138
7139 if (strcasecmp(val, "SETUP") == 0) {
7140 int status = 0, timeout = 0;
7141
7142 val = get_param(cmd, "Status");
7143 if (val)
7144 status = atoi(val);
7145
7146 val = get_param(cmd, "Timeout");
7147 if (val)
7148 timeout = atoi(val);
7149
7150 if (status != 0 && status != 37) {
7151 send_resp(dut, conn, SIGMA_ERROR,
7152 "ErrorCode,Unsupported status value");
7153 return 0;
7154 }
7155
7156 if (timeout != 0 && timeout != 301) {
7157 send_resp(dut, conn, SIGMA_ERROR,
7158 "ErrorCode,Unsupported timeout value");
7159 return 0;
7160 }
7161
7162 if (status && timeout) {
7163 send_resp(dut, conn, SIGMA_ERROR,
7164 "ErrorCode,Unsupported timeout+status "
7165 "combination");
7166 return 0;
7167 }
7168
7169 if (status == 37 &&
7170 wpa_command(intf, "SET tdls_testing 0x200")) {
7171 send_resp(dut, conn, SIGMA_ERROR,
7172 "ErrorCode,Failed to enable "
7173 "decline setup response test mode");
7174 return 0;
7175 }
7176
7177 if (timeout == 301) {
7178 int res;
7179 if (dut->no_tpk_expiration)
7180 res = wpa_command(intf,
7181 "SET tdls_testing 0x108");
7182 else
7183 res = wpa_command(intf,
7184 "SET tdls_testing 0x8");
7185 if (res) {
7186 send_resp(dut, conn, SIGMA_ERROR,
7187 "ErrorCode,Failed to set short TPK "
7188 "lifetime");
7189 return 0;
7190 }
7191 }
7192
7193 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
7194 if (wpa_command(intf, buf) < 0) {
7195 send_resp(dut, conn, SIGMA_ERROR,
7196 "ErrorCode,Failed to send TDLS setup");
7197 return 0;
7198 }
7199 return 1;
7200 }
7201
7202 if (strcasecmp(val, "TEARDOWN") == 0) {
7203 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
7204 if (wpa_command(intf, buf) < 0) {
7205 send_resp(dut, conn, SIGMA_ERROR,
7206 "ErrorCode,Failed to send TDLS teardown");
7207 return 0;
7208 }
7209 return 1;
7210 }
7211
7212 send_resp(dut, conn, SIGMA_ERROR,
7213 "ErrorCode,Unsupported TDLS frame");
7214 return 0;
7215}
7216
7217
7218static int sta_ap_known(const char *ifname, const char *bssid)
7219{
7220 char buf[4096];
7221
7222 snprintf(buf, sizeof(buf), "BSS %s", bssid);
7223 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
7224 return 0;
7225 if (strncmp(buf, "id=", 3) != 0)
7226 return 0;
7227 return 1;
7228}
7229
7230
7231static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
7232 const char *bssid)
7233{
7234 int res;
7235 struct wpa_ctrl *ctrl;
7236 char buf[256];
7237
7238 if (sta_ap_known(ifname, bssid))
7239 return 0;
7240 sigma_dut_print(dut, DUT_MSG_DEBUG,
7241 "AP not in BSS table - start scan");
7242
7243 ctrl = open_wpa_mon(ifname);
7244 if (ctrl == NULL) {
7245 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7246 "wpa_supplicant monitor connection");
7247 return -1;
7248 }
7249
7250 if (wpa_command(ifname, "SCAN") < 0) {
7251 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
7252 wpa_ctrl_detach(ctrl);
7253 wpa_ctrl_close(ctrl);
7254 return -1;
7255 }
7256
7257 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7258 buf, sizeof(buf));
7259
7260 wpa_ctrl_detach(ctrl);
7261 wpa_ctrl_close(ctrl);
7262
7263 if (res < 0) {
7264 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
7265 return -1;
7266 }
7267
7268 if (sta_ap_known(ifname, bssid))
7269 return 0;
7270 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
7271 return -1;
7272}
7273
7274
7275static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
7276 struct sigma_conn *conn,
7277 struct sigma_cmd *cmd,
7278 const char *intf)
7279{
7280 char buf[200];
7281
7282 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
7283 if (system(buf) != 0) {
7284 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
7285 "ndsend");
7286 return 0;
7287 }
7288
7289 return 1;
7290}
7291
7292
7293static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
7294 struct sigma_conn *conn,
7295 struct sigma_cmd *cmd,
7296 const char *intf)
7297{
7298 char buf[200];
7299 const char *ip = get_param(cmd, "SenderIP");
7300
Peng Xu26b356d2017-10-04 17:58:16 -07007301 if (!ip)
7302 return 0;
7303
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007304 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
7305 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7306 if (system(buf) == 0) {
7307 sigma_dut_print(dut, DUT_MSG_INFO,
7308 "Neighbor Solicitation got a response "
7309 "for %s@%s", ip, intf);
7310 }
7311
7312 return 1;
7313}
7314
7315
7316static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
7317 struct sigma_conn *conn,
7318 struct sigma_cmd *cmd,
7319 const char *ifname)
7320{
7321 char buf[200];
7322 const char *ip = get_param(cmd, "SenderIP");
7323
7324 if (ip == NULL) {
7325 send_resp(dut, conn, SIGMA_ERROR,
7326 "ErrorCode,Missing SenderIP parameter");
7327 return 0;
7328 }
7329 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
7330 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7331 if (system(buf) != 0) {
7332 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
7333 "for %s@%s", ip, ifname);
7334 }
7335
7336 return 1;
7337}
7338
7339
7340static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
7341 struct sigma_conn *conn,
7342 struct sigma_cmd *cmd,
7343 const char *ifname)
7344{
7345 char buf[200];
7346 char ip[16];
7347 int s;
Peng Xub3756882017-10-04 14:39:09 -07007348 struct ifreq ifr;
7349 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007350
7351 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07007352 if (s < 0) {
7353 perror("socket");
7354 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007355 }
7356
Peng Xub3756882017-10-04 14:39:09 -07007357 memset(&ifr, 0, sizeof(ifr));
7358 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7359 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
7360 sigma_dut_print(dut, DUT_MSG_INFO,
7361 "Failed to get %s IP address: %s",
7362 ifname, strerror(errno));
7363 close(s);
7364 return -1;
7365 }
7366 close(s);
7367
7368 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
7369 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
7370
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007371 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
7372 ip);
7373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7374 if (system(buf) != 0) {
7375 }
7376
7377 return 1;
7378}
7379
7380
7381static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
7382 struct sigma_conn *conn,
7383 struct sigma_cmd *cmd,
7384 const char *ifname)
7385{
7386 char buf[200], addr[20];
7387 char dst[ETH_ALEN], src[ETH_ALEN];
7388 short ethtype = htons(ETH_P_ARP);
7389 char *pos;
7390 int s, res;
7391 const char *val;
7392 struct sockaddr_in taddr;
7393
7394 val = get_param(cmd, "dest");
7395 if (val)
7396 hwaddr_aton(val, (unsigned char *) dst);
7397
7398 val = get_param(cmd, "DestIP");
7399 if (val)
7400 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007401 else
7402 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007403
7404 if (get_wpa_status(get_station_ifname(), "address", addr,
7405 sizeof(addr)) < 0)
7406 return -2;
7407 hwaddr_aton(addr, (unsigned char *) src);
7408
7409 pos = buf;
7410 *pos++ = 0x00;
7411 *pos++ = 0x01;
7412 *pos++ = 0x08;
7413 *pos++ = 0x00;
7414 *pos++ = 0x06;
7415 *pos++ = 0x04;
7416 *pos++ = 0x00;
7417 *pos++ = 0x02;
7418 memcpy(pos, src, ETH_ALEN);
7419 pos += ETH_ALEN;
7420 memcpy(pos, &taddr.sin_addr, 4);
7421 pos += 4;
7422 memcpy(pos, dst, ETH_ALEN);
7423 pos += ETH_ALEN;
7424 memcpy(pos, &taddr.sin_addr, 4);
7425 pos += 4;
7426
7427 s = open_monitor(get_station_ifname());
7428 if (s < 0) {
7429 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7430 "monitor socket");
7431 return 0;
7432 }
7433
7434 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7435 if (res < 0) {
7436 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7437 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307438 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 return 0;
7440 }
7441
7442 close(s);
7443
7444 return 1;
7445}
7446
7447
7448static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7449 struct sigma_conn *conn,
7450 struct sigma_cmd *cmd,
7451 const char *intf, const char *dest)
7452{
7453 char buf[100];
7454
7455 if (if_nametoindex("sigmadut") == 0) {
7456 snprintf(buf, sizeof(buf),
7457 "iw dev %s interface add sigmadut type monitor",
7458 get_station_ifname());
7459 if (system(buf) != 0 ||
7460 if_nametoindex("sigmadut") == 0) {
7461 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7462 "monitor interface with '%s'", buf);
7463 return -2;
7464 }
7465 }
7466
7467 if (system("ifconfig sigmadut up") != 0) {
7468 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7469 "monitor interface up");
7470 return -2;
7471 }
7472
7473 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7474}
7475
7476
7477static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7478 struct sigma_conn *conn,
7479 struct sigma_cmd *cmd)
7480{
7481 const char *intf = get_param(cmd, "Interface");
7482 const char *dest = get_param(cmd, "Dest");
7483 const char *type = get_param(cmd, "FrameName");
7484 const char *val;
7485 char buf[200], *pos, *end;
7486 int count, count2;
7487
7488 if (type == NULL)
7489 type = get_param(cmd, "Type");
7490
7491 if (intf == NULL || dest == NULL || type == NULL)
7492 return -1;
7493
7494 if (strcasecmp(type, "NeighAdv") == 0)
7495 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7496
7497 if (strcasecmp(type, "NeighSolicitReq") == 0)
7498 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7499
7500 if (strcasecmp(type, "ARPProbe") == 0)
7501 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7502
7503 if (strcasecmp(type, "ARPAnnounce") == 0)
7504 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7505
7506 if (strcasecmp(type, "ARPReply") == 0)
7507 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7508
7509 if (strcasecmp(type, "DLS-request") == 0 ||
7510 strcasecmp(type, "DLSrequest") == 0)
7511 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7512 dest);
7513
7514 if (strcasecmp(type, "ANQPQuery") != 0 &&
7515 strcasecmp(type, "Query") != 0) {
7516 send_resp(dut, conn, SIGMA_ERROR,
7517 "ErrorCode,Unsupported HS 2.0 send frame type");
7518 return 0;
7519 }
7520
7521 if (sta_scan_ap(dut, intf, dest) < 0) {
7522 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7523 "the requested AP");
7524 return 0;
7525 }
7526
7527 pos = buf;
7528 end = buf + sizeof(buf);
7529 count = 0;
7530 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7531
7532 val = get_param(cmd, "ANQP_CAP_LIST");
7533 if (val && atoi(val)) {
7534 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7535 count++;
7536 }
7537
7538 val = get_param(cmd, "VENUE_NAME");
7539 if (val && atoi(val)) {
7540 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7541 count++;
7542 }
7543
7544 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7545 if (val && atoi(val)) {
7546 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7547 count++;
7548 }
7549
7550 val = get_param(cmd, "ROAMING_CONS");
7551 if (val && atoi(val)) {
7552 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7553 count++;
7554 }
7555
7556 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7557 if (val && atoi(val)) {
7558 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7559 count++;
7560 }
7561
7562 val = get_param(cmd, "NAI_REALM_LIST");
7563 if (val && atoi(val)) {
7564 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7565 count++;
7566 }
7567
7568 val = get_param(cmd, "3GPP_INFO");
7569 if (val && atoi(val)) {
7570 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7571 count++;
7572 }
7573
7574 val = get_param(cmd, "DOMAIN_LIST");
7575 if (val && atoi(val)) {
7576 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7577 count++;
7578 }
7579
7580 if (count && wpa_command(intf, buf)) {
7581 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7582 return 0;
7583 }
7584
7585 pos = buf;
7586 end = buf + sizeof(buf);
7587 count2 = 0;
7588 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7589
7590 val = get_param(cmd, "HS_CAP_LIST");
7591 if (val && atoi(val)) {
7592 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7593 count2++;
7594 }
7595
7596 val = get_param(cmd, "OPER_NAME");
7597 if (val && atoi(val)) {
7598 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7599 count2++;
7600 }
7601
7602 val = get_param(cmd, "WAN_METRICS");
7603 if (!val)
7604 val = get_param(cmd, "WAN_MAT");
7605 if (!val)
7606 val = get_param(cmd, "WAN_MET");
7607 if (val && atoi(val)) {
7608 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7609 count2++;
7610 }
7611
7612 val = get_param(cmd, "CONNECTION_CAPABILITY");
7613 if (val && atoi(val)) {
7614 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7615 count2++;
7616 }
7617
7618 val = get_param(cmd, "OP_CLASS");
7619 if (val && atoi(val)) {
7620 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7621 count2++;
7622 }
7623
7624 val = get_param(cmd, "OSU_PROVIDER_LIST");
7625 if (val && atoi(val)) {
7626 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7627 count2++;
7628 }
7629
7630 if (count && count2) {
7631 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7632 "second query");
7633 sleep(1);
7634 }
7635
7636 if (count2 && wpa_command(intf, buf)) {
7637 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7638 "failed");
7639 return 0;
7640 }
7641
7642 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7643 if (val) {
7644 if (count || count2) {
7645 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7646 "sending out second query");
7647 sleep(1);
7648 }
7649
7650 if (strcmp(val, "1") == 0)
7651 val = "mail.example.com";
7652 snprintf(buf, end - pos,
7653 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7654 dest, val);
7655 if (wpa_command(intf, buf)) {
7656 send_resp(dut, conn, SIGMA_ERROR,
7657 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7658 "failed");
7659 return 0;
7660 }
7661 }
7662
7663 val = get_param(cmd, "ICON_REQUEST");
7664 if (val) {
7665 if (count || count2) {
7666 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7667 "sending out second query");
7668 sleep(1);
7669 }
7670
7671 snprintf(buf, end - pos,
7672 "HS20_ICON_REQUEST %s %s", dest, val);
7673 if (wpa_command(intf, buf)) {
7674 send_resp(dut, conn, SIGMA_ERROR,
7675 "ErrorCode,HS20_ICON_REQUEST failed");
7676 return 0;
7677 }
7678 }
7679
7680 return 1;
7681}
7682
7683
7684static int ath_sta_send_frame_vht(struct sigma_dut *dut,
7685 struct sigma_conn *conn,
7686 struct sigma_cmd *cmd)
7687{
7688 const char *val;
7689 char *ifname;
7690 char buf[100];
7691 int chwidth, nss;
7692
7693 val = get_param(cmd, "framename");
7694 if (!val)
7695 return -1;
7696 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
7697
7698 /* Command sequence to generate Op mode notification */
7699 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
7700 ifname = get_station_ifname();
7701
7702 /* Disable STBC */
7703 snprintf(buf, sizeof(buf),
7704 "iwpriv %s tx_stbc 0", ifname);
7705 if (system(buf) != 0) {
7706 sigma_dut_print(dut, DUT_MSG_ERROR,
7707 "iwpriv tx_stbc 0 failed!");
7708 }
7709
7710 /* Extract Channel width */
7711 val = get_param(cmd, "Channel_width");
7712 if (val) {
7713 switch (atoi(val)) {
7714 case 20:
7715 chwidth = 0;
7716 break;
7717 case 40:
7718 chwidth = 1;
7719 break;
7720 case 80:
7721 chwidth = 2;
7722 break;
7723 case 160:
7724 chwidth = 3;
7725 break;
7726 default:
7727 chwidth = 2;
7728 break;
7729 }
7730
7731 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7732 ifname, chwidth);
7733 if (system(buf) != 0) {
7734 sigma_dut_print(dut, DUT_MSG_ERROR,
7735 "iwpriv chwidth failed!");
7736 }
7737 }
7738
7739 /* Extract NSS */
7740 val = get_param(cmd, "NSS");
7741 if (val) {
7742 switch (atoi(val)) {
7743 case 1:
7744 nss = 1;
7745 break;
7746 case 2:
7747 nss = 3;
7748 break;
7749 case 3:
7750 nss = 7;
7751 break;
7752 default:
7753 /* We do not support NSS > 3 */
7754 nss = 3;
7755 break;
7756 }
7757 snprintf(buf, sizeof(buf),
7758 "iwpriv %s rxchainmask %d", ifname, nss);
7759 if (system(buf) != 0) {
7760 sigma_dut_print(dut, DUT_MSG_ERROR,
7761 "iwpriv rxchainmask failed!");
7762 }
7763 }
7764
7765 /* Opmode notify */
7766 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
7767 if (system(buf) != 0) {
7768 sigma_dut_print(dut, DUT_MSG_ERROR,
7769 "iwpriv opmode_notify failed!");
7770 } else {
7771 sigma_dut_print(dut, DUT_MSG_INFO,
7772 "Sent out the notify frame!");
7773 }
7774 }
7775
7776 return 1;
7777}
7778
7779
7780static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
7781 struct sigma_conn *conn,
7782 struct sigma_cmd *cmd)
7783{
7784 switch (get_driver_type()) {
7785 case DRIVER_ATHEROS:
7786 return ath_sta_send_frame_vht(dut, conn, cmd);
7787 default:
7788 send_resp(dut, conn, SIGMA_ERROR,
7789 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
7790 return 0;
7791 }
7792}
7793
7794
Lior David0fe101e2017-03-09 16:09:50 +02007795#ifdef __linux__
7796int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7797 struct sigma_cmd *cmd)
7798{
7799 const char *frame_name = get_param(cmd, "framename");
7800 const char *mac = get_param(cmd, "dest_mac");
7801
7802 if (!frame_name || !mac) {
7803 sigma_dut_print(dut, DUT_MSG_ERROR,
7804 "framename and dest_mac must be provided");
7805 return -1;
7806 }
7807
7808 if (strcasecmp(frame_name, "brp") == 0) {
7809 const char *l_rx = get_param(cmd, "L-RX");
7810 int l_rx_i;
7811
7812 if (!l_rx) {
7813 sigma_dut_print(dut, DUT_MSG_ERROR,
7814 "L-RX must be provided");
7815 return -1;
7816 }
7817 l_rx_i = atoi(l_rx);
7818
7819 sigma_dut_print(dut, DUT_MSG_INFO,
7820 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
7821 mac, l_rx);
7822 if (l_rx_i != 16) {
7823 sigma_dut_print(dut, DUT_MSG_ERROR,
7824 "unsupported L-RX: %s", l_rx);
7825 return -1;
7826 }
7827
7828 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
7829 return -1;
7830 } else if (strcasecmp(frame_name, "ssw") == 0) {
7831 sigma_dut_print(dut, DUT_MSG_INFO,
7832 "dev_send_frame: SLS, dest_mac %s", mac);
7833 if (wil6210_send_sls(dut, mac))
7834 return -1;
7835 } else {
7836 sigma_dut_print(dut, DUT_MSG_ERROR,
7837 "unsupported frame type: %s", frame_name);
7838 return -1;
7839 }
7840
7841 return 1;
7842}
7843#endif /* __linux__ */
7844
7845
7846static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
7847 struct sigma_conn *conn,
7848 struct sigma_cmd *cmd)
7849{
7850 switch (get_driver_type()) {
7851#ifdef __linux__
7852 case DRIVER_WIL6210:
7853 return wil6210_send_frame_60g(dut, conn, cmd);
7854#endif /* __linux__ */
7855 default:
7856 send_resp(dut, conn, SIGMA_ERROR,
7857 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7858 return 0;
7859 }
7860}
7861
7862
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307863static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
7864 const char *intf, struct sigma_cmd *cmd)
7865{
7866 const char *val, *addr;
7867 char buf[100];
7868
7869 addr = get_param(cmd, "DestMac");
7870 if (!addr) {
7871 send_resp(dut, conn, SIGMA_INVALID,
7872 "ErrorCode,AP MAC address is missing");
7873 return 0;
7874 }
7875
7876 val = get_param(cmd, "ANQPQuery_ID");
7877 if (!val) {
7878 send_resp(dut, conn, SIGMA_INVALID,
7879 "ErrorCode,Missing ANQPQuery_ID");
7880 return 0;
7881 }
7882
7883 if (strcasecmp(val, "NeighborReportReq") == 0) {
7884 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
7885 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
7886 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
7887 } else {
7888 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
7889 val);
7890 send_resp(dut, conn, SIGMA_INVALID,
7891 "ErrorCode,Invalid ANQPQuery_ID");
7892 return 0;
7893 }
7894
Ashwini Patild174f2c2017-04-13 16:49:46 +05307895 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
7896 * (Address3 = Wildcard BSSID when sent to not-associated AP;
7897 * if associated, AP BSSID).
7898 */
7899 if (wpa_command(intf, "SET gas_address3 1") < 0) {
7900 send_resp(dut, conn, SIGMA_ERROR,
7901 "ErrorCode,Failed to set gas_address3");
7902 return 0;
7903 }
7904
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307905 if (wpa_command(intf, buf) < 0) {
7906 send_resp(dut, conn, SIGMA_ERROR,
7907 "ErrorCode,Failed to send ANQP query");
7908 return 0;
7909 }
7910
7911 return 1;
7912}
7913
7914
7915static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
7916 struct sigma_conn *conn,
7917 const char *intf,
7918 struct sigma_cmd *cmd)
7919{
7920 const char *val = get_param(cmd, "FrameName");
7921
7922 if (val && strcasecmp(val, "ANQPQuery") == 0)
7923 return mbo_send_anqp_query(dut, conn, intf, cmd);
7924
7925 return 2;
7926}
7927
7928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007929int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7930 struct sigma_cmd *cmd)
7931{
7932 const char *intf = get_param(cmd, "Interface");
7933 const char *val;
7934 enum send_frame_type frame;
7935 enum send_frame_protection protected;
7936 char buf[100];
7937 unsigned char addr[ETH_ALEN];
7938 int res;
7939
7940 val = get_param(cmd, "program");
7941 if (val == NULL)
7942 val = get_param(cmd, "frame");
7943 if (val && strcasecmp(val, "TDLS") == 0)
7944 return cmd_sta_send_frame_tdls(dut, conn, cmd);
7945 if (val && (strcasecmp(val, "HS2") == 0 ||
7946 strcasecmp(val, "HS2-R2") == 0))
7947 return cmd_sta_send_frame_hs2(dut, conn, cmd);
7948 if (val && strcasecmp(val, "VHT") == 0)
7949 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007950 if (val && strcasecmp(val, "LOC") == 0)
7951 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007952 if (val && strcasecmp(val, "60GHz") == 0)
7953 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307954 if (val && strcasecmp(val, "MBO") == 0) {
7955 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
7956 if (res != 2)
7957 return res;
7958 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007959
7960 val = get_param(cmd, "TD_DISC");
7961 if (val) {
7962 if (hwaddr_aton(val, addr) < 0)
7963 return -1;
7964 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
7965 if (wpa_command(intf, buf) < 0) {
7966 send_resp(dut, conn, SIGMA_ERROR,
7967 "ErrorCode,Failed to send TDLS discovery");
7968 return 0;
7969 }
7970 return 1;
7971 }
7972
7973 val = get_param(cmd, "TD_Setup");
7974 if (val) {
7975 if (hwaddr_aton(val, addr) < 0)
7976 return -1;
7977 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
7978 if (wpa_command(intf, buf) < 0) {
7979 send_resp(dut, conn, SIGMA_ERROR,
7980 "ErrorCode,Failed to start TDLS setup");
7981 return 0;
7982 }
7983 return 1;
7984 }
7985
7986 val = get_param(cmd, "TD_TearDown");
7987 if (val) {
7988 if (hwaddr_aton(val, addr) < 0)
7989 return -1;
7990 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
7991 if (wpa_command(intf, buf) < 0) {
7992 send_resp(dut, conn, SIGMA_ERROR,
7993 "ErrorCode,Failed to tear down TDLS link");
7994 return 0;
7995 }
7996 return 1;
7997 }
7998
7999 val = get_param(cmd, "TD_ChannelSwitch");
8000 if (val) {
8001 /* TODO */
8002 send_resp(dut, conn, SIGMA_ERROR,
8003 "ErrorCode,TD_ChannelSwitch not yet supported");
8004 return 0;
8005 }
8006
8007 val = get_param(cmd, "TD_NF");
8008 if (val) {
8009 /* TODO */
8010 send_resp(dut, conn, SIGMA_ERROR,
8011 "ErrorCode,TD_NF not yet supported");
8012 return 0;
8013 }
8014
8015 val = get_param(cmd, "PMFFrameType");
8016 if (val == NULL)
8017 val = get_param(cmd, "FrameName");
8018 if (val == NULL)
8019 val = get_param(cmd, "Type");
8020 if (val == NULL)
8021 return -1;
8022 if (strcasecmp(val, "disassoc") == 0)
8023 frame = DISASSOC;
8024 else if (strcasecmp(val, "deauth") == 0)
8025 frame = DEAUTH;
8026 else if (strcasecmp(val, "saquery") == 0)
8027 frame = SAQUERY;
8028 else if (strcasecmp(val, "auth") == 0)
8029 frame = AUTH;
8030 else if (strcasecmp(val, "assocreq") == 0)
8031 frame = ASSOCREQ;
8032 else if (strcasecmp(val, "reassocreq") == 0)
8033 frame = REASSOCREQ;
8034 else if (strcasecmp(val, "neigreq") == 0) {
8035 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
8036
8037 val = get_param(cmd, "ssid");
8038 if (val == NULL)
8039 return -1;
8040
8041 res = send_neighbor_request(dut, intf, val);
8042 if (res) {
8043 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8044 "Failed to send neighbor report request");
8045 return 0;
8046 }
8047
8048 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05308049 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
8050 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008051 sigma_dut_print(dut, DUT_MSG_DEBUG,
8052 "Got Transition Management Query");
8053
Ashwini Patil5acd7382017-04-13 15:55:04 +05308054 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008055 if (res) {
8056 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8057 "Failed to send Transition Management Query");
8058 return 0;
8059 }
8060
8061 return 1;
8062 } else {
8063 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8064 "PMFFrameType");
8065 return 0;
8066 }
8067
8068 val = get_param(cmd, "PMFProtected");
8069 if (val == NULL)
8070 val = get_param(cmd, "Protected");
8071 if (val == NULL)
8072 return -1;
8073 if (strcasecmp(val, "Correct-key") == 0 ||
8074 strcasecmp(val, "CorrectKey") == 0)
8075 protected = CORRECT_KEY;
8076 else if (strcasecmp(val, "IncorrectKey") == 0)
8077 protected = INCORRECT_KEY;
8078 else if (strcasecmp(val, "Unprotected") == 0)
8079 protected = UNPROTECTED;
8080 else {
8081 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8082 "PMFProtected");
8083 return 0;
8084 }
8085
8086 if (protected != UNPROTECTED &&
8087 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
8088 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
8089 "PMFProtected for auth/assocreq/reassocreq");
8090 return 0;
8091 }
8092
8093 if (if_nametoindex("sigmadut") == 0) {
8094 snprintf(buf, sizeof(buf),
8095 "iw dev %s interface add sigmadut type monitor",
8096 get_station_ifname());
8097 if (system(buf) != 0 ||
8098 if_nametoindex("sigmadut") == 0) {
8099 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8100 "monitor interface with '%s'", buf);
8101 return -2;
8102 }
8103 }
8104
8105 if (system("ifconfig sigmadut up") != 0) {
8106 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8107 "monitor interface up");
8108 return -2;
8109 }
8110
8111 return sta_inject_frame(dut, conn, frame, protected, NULL);
8112}
8113
8114
8115static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
8116 struct sigma_conn *conn,
8117 struct sigma_cmd *cmd,
8118 const char *ifname)
8119{
8120 char buf[200];
8121 const char *val;
8122
8123 val = get_param(cmd, "ClearARP");
8124 if (val && atoi(val) == 1) {
8125 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
8126 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8127 if (system(buf) != 0) {
8128 send_resp(dut, conn, SIGMA_ERROR,
8129 "errorCode,Failed to clear ARP cache");
8130 return 0;
8131 }
8132 }
8133
8134 return 1;
8135}
8136
8137
8138int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
8139 struct sigma_cmd *cmd)
8140{
8141 const char *intf = get_param(cmd, "Interface");
8142 const char *val;
8143
8144 if (intf == NULL)
8145 return -1;
8146
8147 val = get_param(cmd, "program");
8148 if (val && (strcasecmp(val, "HS2") == 0 ||
8149 strcasecmp(val, "HS2-R2") == 0))
8150 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
8151
8152 return -1;
8153}
8154
8155
8156static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
8157 struct sigma_cmd *cmd)
8158{
8159 const char *intf = get_param(cmd, "Interface");
8160 const char *mac = get_param(cmd, "MAC");
8161
8162 if (intf == NULL || mac == NULL)
8163 return -1;
8164
8165 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
8166 "interface %s to %s", intf, mac);
8167
8168 if (dut->set_macaddr) {
8169 char buf[128];
8170 int res;
8171 if (strcasecmp(mac, "default") == 0) {
8172 res = snprintf(buf, sizeof(buf), "%s",
8173 dut->set_macaddr);
8174 dut->tmp_mac_addr = 0;
8175 } else {
8176 res = snprintf(buf, sizeof(buf), "%s %s",
8177 dut->set_macaddr, mac);
8178 dut->tmp_mac_addr = 1;
8179 }
8180 if (res < 0 || res >= (int) sizeof(buf))
8181 return -1;
8182 if (system(buf) != 0) {
8183 send_resp(dut, conn, SIGMA_ERROR,
8184 "errorCode,Failed to set MAC "
8185 "address");
8186 return 0;
8187 }
8188 return 1;
8189 }
8190
8191 if (strcasecmp(mac, "default") == 0)
8192 return 1;
8193
8194 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8195 "command");
8196 return 0;
8197}
8198
8199
8200static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
8201 struct sigma_conn *conn, const char *intf,
8202 int val)
8203{
8204 char buf[200];
8205 int res;
8206
8207 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
8208 intf, val);
8209 if (res < 0 || res >= (int) sizeof(buf))
8210 return -1;
8211 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8212 if (system(buf) != 0) {
8213 send_resp(dut, conn, SIGMA_ERROR,
8214 "errorCode,Failed to configure offchannel mode");
8215 return 0;
8216 }
8217
8218 return 1;
8219}
8220
8221
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008222static int off_chan_val(enum sec_ch_offset off)
8223{
8224 switch (off) {
8225 case SEC_CH_NO:
8226 return 0;
8227 case SEC_CH_40ABOVE:
8228 return 40;
8229 case SEC_CH_40BELOW:
8230 return -40;
8231 }
8232
8233 return 0;
8234}
8235
8236
8237static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
8238 const char *intf, int off_ch_num,
8239 enum sec_ch_offset sec)
8240{
8241 char buf[200];
8242 int res;
8243
8244 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
8245 intf, off_ch_num);
8246 if (res < 0 || res >= (int) sizeof(buf))
8247 return -1;
8248 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8249 if (system(buf) != 0) {
8250 send_resp(dut, conn, SIGMA_ERROR,
8251 "errorCode,Failed to set offchan");
8252 return 0;
8253 }
8254
8255 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
8256 intf, off_chan_val(sec));
8257 if (res < 0 || res >= (int) sizeof(buf))
8258 return -1;
8259 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8260 if (system(buf) != 0) {
8261 send_resp(dut, conn, SIGMA_ERROR,
8262 "errorCode,Failed to set sec chan offset");
8263 return 0;
8264 }
8265
8266 return 1;
8267}
8268
8269
8270static int tdls_set_offchannel_offset(struct sigma_dut *dut,
8271 struct sigma_conn *conn,
8272 const char *intf, int off_ch_num,
8273 enum sec_ch_offset sec)
8274{
8275 char buf[200];
8276 int res;
8277
8278 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
8279 off_ch_num);
8280 if (res < 0 || res >= (int) sizeof(buf))
8281 return -1;
8282 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8283
8284 if (wpa_command(intf, buf) < 0) {
8285 send_resp(dut, conn, SIGMA_ERROR,
8286 "ErrorCode,Failed to set offchan");
8287 return 0;
8288 }
8289 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
8290 off_chan_val(sec));
8291 if (res < 0 || res >= (int) sizeof(buf))
8292 return -1;
8293
8294 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8295
8296 if (wpa_command(intf, buf) < 0) {
8297 send_resp(dut, conn, SIGMA_ERROR,
8298 "ErrorCode,Failed to set sec chan offset");
8299 return 0;
8300 }
8301
8302 return 1;
8303}
8304
8305
8306static int tdls_set_offchannel_mode(struct sigma_dut *dut,
8307 struct sigma_conn *conn,
8308 const char *intf, int val)
8309{
8310 char buf[200];
8311 int res;
8312
8313 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
8314 val);
8315 if (res < 0 || res >= (int) sizeof(buf))
8316 return -1;
8317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8318
8319 if (wpa_command(intf, buf) < 0) {
8320 send_resp(dut, conn, SIGMA_ERROR,
8321 "ErrorCode,Failed to configure offchannel mode");
8322 return 0;
8323 }
8324
8325 return 1;
8326}
8327
8328
8329static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
8330 struct sigma_conn *conn,
8331 struct sigma_cmd *cmd)
8332{
8333 const char *val;
8334 enum {
8335 CHSM_NOT_SET,
8336 CHSM_ENABLE,
8337 CHSM_DISABLE,
8338 CHSM_REJREQ,
8339 CHSM_UNSOLRESP
8340 } chsm = CHSM_NOT_SET;
8341 int off_ch_num = -1;
8342 enum sec_ch_offset sec_ch = SEC_CH_NO;
8343 int res;
8344
8345 val = get_param(cmd, "Uapsd");
8346 if (val) {
8347 char buf[100];
8348 if (strcasecmp(val, "Enable") == 0)
8349 snprintf(buf, sizeof(buf), "SET ps 99");
8350 else if (strcasecmp(val, "Disable") == 0)
8351 snprintf(buf, sizeof(buf), "SET ps 98");
8352 else {
8353 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8354 "Unsupported uapsd parameter value");
8355 return 0;
8356 }
8357 if (wpa_command(intf, buf)) {
8358 send_resp(dut, conn, SIGMA_ERROR,
8359 "ErrorCode,Failed to change U-APSD "
8360 "powersave mode");
8361 return 0;
8362 }
8363 }
8364
8365 val = get_param(cmd, "TPKTIMER");
8366 if (val && strcasecmp(val, "DISABLE") == 0) {
8367 if (wpa_command(intf, "SET tdls_testing 0x100")) {
8368 send_resp(dut, conn, SIGMA_ERROR,
8369 "ErrorCode,Failed to enable no TPK "
8370 "expiration test mode");
8371 return 0;
8372 }
8373 dut->no_tpk_expiration = 1;
8374 }
8375
8376 val = get_param(cmd, "ChSwitchMode");
8377 if (val) {
8378 if (strcasecmp(val, "Enable") == 0 ||
8379 strcasecmp(val, "Initiate") == 0)
8380 chsm = CHSM_ENABLE;
8381 else if (strcasecmp(val, "Disable") == 0 ||
8382 strcasecmp(val, "passive") == 0)
8383 chsm = CHSM_DISABLE;
8384 else if (strcasecmp(val, "RejReq") == 0)
8385 chsm = CHSM_REJREQ;
8386 else if (strcasecmp(val, "UnSolResp") == 0)
8387 chsm = CHSM_UNSOLRESP;
8388 else {
8389 send_resp(dut, conn, SIGMA_ERROR,
8390 "ErrorCode,Unknown ChSwitchMode value");
8391 return 0;
8392 }
8393 }
8394
8395 val = get_param(cmd, "OffChNum");
8396 if (val) {
8397 off_ch_num = atoi(val);
8398 if (off_ch_num == 0) {
8399 send_resp(dut, conn, SIGMA_ERROR,
8400 "ErrorCode,Invalid OffChNum");
8401 return 0;
8402 }
8403 }
8404
8405 val = get_param(cmd, "SecChOffset");
8406 if (val) {
8407 if (strcmp(val, "20") == 0)
8408 sec_ch = SEC_CH_NO;
8409 else if (strcasecmp(val, "40above") == 0)
8410 sec_ch = SEC_CH_40ABOVE;
8411 else if (strcasecmp(val, "40below") == 0)
8412 sec_ch = SEC_CH_40BELOW;
8413 else {
8414 send_resp(dut, conn, SIGMA_ERROR,
8415 "ErrorCode,Unknown SecChOffset value");
8416 return 0;
8417 }
8418 }
8419
8420 if (chsm == CHSM_NOT_SET) {
8421 /* no offchannel changes requested */
8422 return 1;
8423 }
8424
8425 if (strcmp(intf, get_main_ifname()) != 0 &&
8426 strcmp(intf, get_station_ifname()) != 0) {
8427 send_resp(dut, conn, SIGMA_ERROR,
8428 "ErrorCode,Unknown interface");
8429 return 0;
8430 }
8431
8432 switch (chsm) {
8433 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008434 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008435 break;
8436 case CHSM_ENABLE:
8437 if (off_ch_num < 0) {
8438 send_resp(dut, conn, SIGMA_ERROR,
8439 "ErrorCode,Missing OffChNum argument");
8440 return 0;
8441 }
8442 if (wifi_chip_type == DRIVER_WCN) {
8443 res = tdls_set_offchannel_offset(dut, conn, intf,
8444 off_ch_num, sec_ch);
8445 } else {
8446 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8447 sec_ch);
8448 }
8449 if (res != 1)
8450 return res;
8451 if (wifi_chip_type == DRIVER_WCN)
8452 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8453 else
8454 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8455 break;
8456 case CHSM_DISABLE:
8457 if (wifi_chip_type == DRIVER_WCN)
8458 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8459 else
8460 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8461 break;
8462 case CHSM_REJREQ:
8463 if (wifi_chip_type == DRIVER_WCN)
8464 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8465 else
8466 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8467 break;
8468 case CHSM_UNSOLRESP:
8469 if (off_ch_num < 0) {
8470 send_resp(dut, conn, SIGMA_ERROR,
8471 "ErrorCode,Missing OffChNum argument");
8472 return 0;
8473 }
8474 if (wifi_chip_type == DRIVER_WCN) {
8475 res = tdls_set_offchannel_offset(dut, conn, intf,
8476 off_ch_num, sec_ch);
8477 } else {
8478 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8479 sec_ch);
8480 }
8481 if (res != 1)
8482 return res;
8483 if (wifi_chip_type == DRIVER_WCN)
8484 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8485 else
8486 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8487 break;
8488 }
8489
8490 return res;
8491}
8492
8493
8494static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8495 struct sigma_conn *conn,
8496 struct sigma_cmd *cmd)
8497{
8498 const char *val;
8499 char *token, *result;
8500
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008501 novap_reset(dut, intf);
8502
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008503 val = get_param(cmd, "nss_mcs_opt");
8504 if (val) {
8505 /* String (nss_operating_mode; mcs_operating_mode) */
8506 int nss, mcs;
8507 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308508 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008509
8510 token = strdup(val);
8511 if (!token)
8512 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308513 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308514 if (!result) {
8515 sigma_dut_print(dut, DUT_MSG_ERROR,
8516 "VHT NSS not specified");
8517 goto failed;
8518 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008519 if (strcasecmp(result, "def") != 0) {
8520 nss = atoi(result);
8521 if (nss == 4)
8522 ath_disable_txbf(dut, intf);
8523 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8524 intf, nss);
8525 if (system(buf) != 0) {
8526 sigma_dut_print(dut, DUT_MSG_ERROR,
8527 "iwpriv nss failed");
8528 goto failed;
8529 }
8530 }
8531
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308532 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308533 if (!result) {
8534 sigma_dut_print(dut, DUT_MSG_ERROR,
8535 "VHT MCS not specified");
8536 goto failed;
8537 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008538 if (strcasecmp(result, "def") == 0) {
8539 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8540 intf);
8541 if (system(buf) != 0) {
8542 sigma_dut_print(dut, DUT_MSG_ERROR,
8543 "iwpriv set11NRates failed");
8544 goto failed;
8545 }
8546
8547 } else {
8548 mcs = atoi(result);
8549 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8550 intf, mcs);
8551 if (system(buf) != 0) {
8552 sigma_dut_print(dut, DUT_MSG_ERROR,
8553 "iwpriv vhtmcs failed");
8554 goto failed;
8555 }
8556 }
8557 /* Channel width gets messed up, fix this */
8558 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8559 intf, dut->chwidth);
8560 if (system(buf) != 0) {
8561 sigma_dut_print(dut, DUT_MSG_ERROR,
8562 "iwpriv chwidth failed");
8563 }
8564 }
8565
8566 return 1;
8567failed:
8568 free(token);
8569 return 0;
8570}
8571
8572
8573static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8574 struct sigma_conn *conn,
8575 struct sigma_cmd *cmd)
8576{
8577 switch (get_driver_type()) {
8578 case DRIVER_ATHEROS:
8579 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8580 default:
8581 send_resp(dut, conn, SIGMA_ERROR,
8582 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8583 return 0;
8584 }
8585}
8586
8587
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008588static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8589 struct sigma_conn *conn,
8590 struct sigma_cmd *cmd)
8591{
8592 const char *val;
8593 char *token = NULL, *result;
8594 char buf[60];
8595
8596 val = get_param(cmd, "nss_mcs_opt");
8597 if (val) {
8598 /* String (nss_operating_mode; mcs_operating_mode) */
8599 int nss, mcs, ratecode;
8600 char *saveptr;
8601
8602 token = strdup(val);
8603 if (!token)
8604 return -2;
8605
8606 result = strtok_r(token, ";", &saveptr);
8607 if (!result) {
8608 sigma_dut_print(dut, DUT_MSG_ERROR,
8609 "HE NSS not specified");
8610 goto failed;
8611 }
8612 nss = 1;
8613 if (strcasecmp(result, "def") != 0)
8614 nss = atoi(result);
8615
8616 result = strtok_r(NULL, ";", &saveptr);
8617 if (!result) {
8618 sigma_dut_print(dut, DUT_MSG_ERROR,
8619 "HE MCS not specified");
8620 goto failed;
8621 }
8622 mcs = 7;
8623 if (strcasecmp(result, "def") != 0)
8624 mcs = atoi(result);
8625
8626 ratecode = 0x400; /* for nss:1 MCS 0 */
8627 if (nss == 2) {
8628 ratecode = 0x420; /* for nss:2 MCS 0 */
8629 } else if (nss > 2) {
8630 sigma_dut_print(dut, DUT_MSG_ERROR,
8631 "HE NSS %d not supported", nss);
8632 goto failed;
8633 }
8634
8635 /* Add the MCS to the ratecode */
8636 if (mcs >= 0 && mcs <= 11) {
8637 ratecode += mcs;
8638 } else {
8639 sigma_dut_print(dut, DUT_MSG_ERROR,
8640 "HE MCS %d not supported", mcs);
8641 goto failed;
8642 }
8643 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8644 intf, ratecode);
8645 if (system(buf) != 0) {
8646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "iwpriv setting of 11ax rates failed");
8648 goto failed;
8649 }
8650 free(token);
8651 }
8652
8653 val = get_param(cmd, "GI");
8654 if (val) {
8655 if (strcmp(val, "0.8") == 0) {
8656 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8657 } else if (strcmp(val, "1.6") == 0) {
8658 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8659 } else if (strcmp(val, "3.2") == 0) {
8660 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8661 } else {
8662 send_resp(dut, conn, SIGMA_ERROR,
8663 "errorCode,GI value not supported");
8664 return 0;
8665 }
8666 if (system(buf) != 0) {
8667 send_resp(dut, conn, SIGMA_ERROR,
8668 "errorCode,Failed to set shortgi");
8669 return 0;
8670 }
8671 }
8672
8673 return 1;
8674
8675failed:
8676 free(token);
8677 return -2;
8678}
8679
8680
8681static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8682 struct sigma_conn *conn,
8683 struct sigma_cmd *cmd)
8684{
8685 switch (get_driver_type()) {
8686 case DRIVER_WCN:
8687 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
8688 default:
8689 send_resp(dut, conn, SIGMA_ERROR,
8690 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
8691 return 0;
8692 }
8693}
8694
8695
Ashwini Patil5acd7382017-04-13 15:55:04 +05308696static int btm_query_candidate_list(struct sigma_dut *dut,
8697 struct sigma_conn *conn,
8698 struct sigma_cmd *cmd)
8699{
8700 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
8701 int len, ret;
8702 char buf[10];
8703
8704 /*
8705 * Neighbor Report elements format:
8706 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
8707 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
8708 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
8709 */
8710
8711 bssid = get_param(cmd, "Nebor_BSSID");
8712 if (!bssid) {
8713 send_resp(dut, conn, SIGMA_INVALID,
8714 "errorCode,Nebor_BSSID is missing");
8715 return 0;
8716 }
8717
8718 info = get_param(cmd, "Nebor_Bssid_Info");
8719 if (!info) {
8720 sigma_dut_print(dut, DUT_MSG_INFO,
8721 "Using default value for Nebor_Bssid_Info: %s",
8722 DEFAULT_NEIGHBOR_BSSID_INFO);
8723 info = DEFAULT_NEIGHBOR_BSSID_INFO;
8724 }
8725
8726 op_class = get_param(cmd, "Nebor_Op_Class");
8727 if (!op_class) {
8728 send_resp(dut, conn, SIGMA_INVALID,
8729 "errorCode,Nebor_Op_Class is missing");
8730 return 0;
8731 }
8732
8733 ch = get_param(cmd, "Nebor_Op_Ch");
8734 if (!ch) {
8735 send_resp(dut, conn, SIGMA_INVALID,
8736 "errorCode,Nebor_Op_Ch is missing");
8737 return 0;
8738 }
8739
8740 phy_type = get_param(cmd, "Nebor_Phy_Type");
8741 if (!phy_type) {
8742 sigma_dut_print(dut, DUT_MSG_INFO,
8743 "Using default value for Nebor_Phy_Type: %s",
8744 DEFAULT_NEIGHBOR_PHY_TYPE);
8745 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
8746 }
8747
8748 /* Parse optional subelements */
8749 buf[0] = '\0';
8750 pref = get_param(cmd, "Nebor_Pref");
8751 if (pref) {
8752 /* hexdump for preferrence subelement */
8753 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
8754 if (ret < 0 || ret >= (int) sizeof(buf)) {
8755 sigma_dut_print(dut, DUT_MSG_ERROR,
8756 "snprintf failed for optional subelement ret: %d",
8757 ret);
8758 send_resp(dut, conn, SIGMA_ERROR,
8759 "errorCode,snprintf failed for subelement");
8760 return 0;
8761 }
8762 }
8763
8764 if (!dut->btm_query_cand_list) {
8765 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
8766 if (!dut->btm_query_cand_list) {
8767 send_resp(dut, conn, SIGMA_ERROR,
8768 "errorCode,Failed to allocate memory for btm_query_cand_list");
8769 return 0;
8770 }
8771 }
8772
8773 len = strlen(dut->btm_query_cand_list);
8774 ret = snprintf(dut->btm_query_cand_list + len,
8775 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
8776 bssid, info, op_class, ch, phy_type, buf);
8777 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
8778 sigma_dut_print(dut, DUT_MSG_ERROR,
8779 "snprintf failed for neighbor report list ret: %d",
8780 ret);
8781 send_resp(dut, conn, SIGMA_ERROR,
8782 "errorCode,snprintf failed for neighbor report");
8783 free(dut->btm_query_cand_list);
8784 dut->btm_query_cand_list = NULL;
8785 return 0;
8786 }
8787
8788 return 1;
8789}
8790
8791
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008792static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8793 struct sigma_cmd *cmd)
8794{
8795 const char *intf = get_param(cmd, "Interface");
8796 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308797 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798
8799 if (intf == NULL || prog == NULL)
8800 return -1;
8801
Ashwini Patil5acd7382017-04-13 15:55:04 +05308802 /* BSS Transition candidate list for BTM query */
8803 val = get_param(cmd, "Nebor_BSSID");
8804 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
8805 return 0;
8806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008807 if (strcasecmp(prog, "TDLS") == 0)
8808 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
8809
8810 if (strcasecmp(prog, "VHT") == 0)
8811 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
8812
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008813 if (strcasecmp(prog, "HE") == 0)
8814 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
8815
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308816 if (strcasecmp(prog, "MBO") == 0) {
8817 val = get_param(cmd, "Cellular_Data_Cap");
8818 if (val &&
8819 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
8820 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05308821
8822 val = get_param(cmd, "Ch_Pref");
8823 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
8824 return 0;
8825
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308826 return 1;
8827 }
8828
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008829 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
8830 return 0;
8831}
8832
8833
8834static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
8835 struct sigma_cmd *cmd)
8836{
8837 const char *intf = get_param(cmd, "Interface");
8838 const char *mode = get_param(cmd, "Mode");
8839 int res;
8840
8841 if (intf == NULL || mode == NULL)
8842 return -1;
8843
8844 if (strcasecmp(mode, "On") == 0)
8845 res = wpa_command(intf, "SET radio_disabled 0");
8846 else if (strcasecmp(mode, "Off") == 0)
8847 res = wpa_command(intf, "SET radio_disabled 1");
8848 else
8849 return -1;
8850
8851 if (res) {
8852 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8853 "radio mode");
8854 return 0;
8855 }
8856
8857 return 1;
8858}
8859
8860
8861static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
8862 struct sigma_cmd *cmd)
8863{
8864 const char *intf = get_param(cmd, "Interface");
8865 const char *mode = get_param(cmd, "Mode");
8866 int res;
8867
8868 if (intf == NULL || mode == NULL)
8869 return -1;
8870
8871 if (strcasecmp(mode, "On") == 0)
8872 res = set_ps(intf, dut, 1);
8873 else if (strcasecmp(mode, "Off") == 0)
8874 res = set_ps(intf, dut, 0);
8875 else
8876 return -1;
8877
8878 if (res) {
8879 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8880 "power save mode");
8881 return 0;
8882 }
8883
8884 return 1;
8885}
8886
8887
8888static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
8889 struct sigma_cmd *cmd)
8890{
8891 const char *intf = get_param(cmd, "Interface");
8892 const char *val, *bssid;
8893 int res;
8894 char *buf;
8895 size_t buf_len;
8896
8897 val = get_param(cmd, "BSSID_FILTER");
8898 if (val == NULL)
8899 return -1;
8900
8901 bssid = get_param(cmd, "BSSID_List");
8902 if (atoi(val) == 0 || bssid == NULL) {
8903 /* Disable BSSID filter */
8904 if (wpa_command(intf, "SET bssid_filter ")) {
8905 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
8906 "to disable BSSID filter");
8907 return 0;
8908 }
8909
8910 return 1;
8911 }
8912
8913 buf_len = 100 + strlen(bssid);
8914 buf = malloc(buf_len);
8915 if (buf == NULL)
8916 return -1;
8917
8918 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
8919 res = wpa_command(intf, buf);
8920 free(buf);
8921 if (res) {
8922 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
8923 "BSSID filter");
8924 return 0;
8925 }
8926
8927 return 1;
8928}
8929
8930
8931static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
8932 struct sigma_cmd *cmd)
8933{
8934 const char *intf = get_param(cmd, "Interface");
8935 const char *val;
8936
8937 /* TODO: ARP */
8938
8939 val = get_param(cmd, "HS2_CACHE_PROFILE");
8940 if (val && strcasecmp(val, "All") == 0)
8941 hs2_clear_credentials(intf);
8942
8943 return 1;
8944}
8945
8946
8947static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
8948 struct sigma_cmd *cmd)
8949{
8950 const char *intf = get_param(cmd, "Interface");
8951 const char *key_type = get_param(cmd, "KeyType");
8952 char buf[100], resp[200];
8953
8954 if (key_type == NULL)
8955 return -1;
8956
8957 if (strcasecmp(key_type, "GTK") == 0) {
8958 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
8959 strncmp(buf, "FAIL", 4) == 0) {
8960 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8961 "not fetch current GTK");
8962 return 0;
8963 }
8964 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
8965 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8966 return 0;
8967 } else {
8968 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8969 "KeyType");
8970 return 0;
8971 }
8972
8973 return 1;
8974}
8975
8976
8977static int hs2_set_policy(struct sigma_dut *dut)
8978{
8979#ifdef ANDROID
8980 system("ip rule del prio 23000");
8981 if (system("ip rule add from all lookup main prio 23000") != 0) {
8982 sigma_dut_print(dut, DUT_MSG_ERROR,
8983 "Failed to run:ip rule add from all lookup main prio");
8984 return -1;
8985 }
8986 if (system("ip route flush cache") != 0) {
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "Failed to run ip route flush cache");
8989 return -1;
8990 }
8991 return 1;
8992#else /* ANDROID */
8993 return 0;
8994#endif /* ANDROID */
8995}
8996
8997
8998static int cmd_sta_hs2_associate(struct sigma_dut *dut,
8999 struct sigma_conn *conn,
9000 struct sigma_cmd *cmd)
9001{
9002 const char *intf = get_param(cmd, "Interface");
9003 const char *val = get_param(cmd, "Ignore_blacklist");
9004 struct wpa_ctrl *ctrl;
9005 int res;
9006 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
9007 int tries = 0;
9008 int ignore_blacklist = 0;
9009 const char *events[] = {
9010 "CTRL-EVENT-CONNECTED",
9011 "INTERWORKING-BLACKLISTED",
9012 "INTERWORKING-NO-MATCH",
9013 NULL
9014 };
9015
9016 start_sta_mode(dut);
9017
9018 blacklisted[0] = '\0';
9019 if (val && atoi(val))
9020 ignore_blacklist = 1;
9021
9022try_again:
9023 ctrl = open_wpa_mon(intf);
9024 if (ctrl == NULL) {
9025 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9026 "wpa_supplicant monitor connection");
9027 return -2;
9028 }
9029
9030 tries++;
9031 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
9032 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
9033 "Interworking connection");
9034 wpa_ctrl_detach(ctrl);
9035 wpa_ctrl_close(ctrl);
9036 return 0;
9037 }
9038
9039 buf[0] = '\0';
9040 while (1) {
9041 char *pos;
9042 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9043 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
9044 if (!pos)
9045 break;
9046 pos += 25;
9047 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
9048 pos);
9049 if (!blacklisted[0])
9050 memcpy(blacklisted, pos, strlen(pos) + 1);
9051 }
9052
9053 if (ignore_blacklist && blacklisted[0]) {
9054 char *end;
9055 end = strchr(blacklisted, ' ');
9056 if (end)
9057 *end = '\0';
9058 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
9059 blacklisted);
9060 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
9061 blacklisted);
9062 if (wpa_command(intf, buf)) {
9063 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
9064 wpa_ctrl_detach(ctrl);
9065 wpa_ctrl_close(ctrl);
9066 return 0;
9067 }
9068 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9069 buf, sizeof(buf));
9070 }
9071
9072 wpa_ctrl_detach(ctrl);
9073 wpa_ctrl_close(ctrl);
9074
9075 if (res < 0) {
9076 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
9077 "connect");
9078 return 0;
9079 }
9080
9081 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
9082 strstr(buf, "INTERWORKING-BLACKLISTED")) {
9083 if (tries < 2) {
9084 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
9085 goto try_again;
9086 }
9087 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
9088 "matching credentials found");
9089 return 0;
9090 }
9091
9092 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9093 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9094 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
9095 "get current BSSID/SSID");
9096 return 0;
9097 }
9098
9099 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
9100 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9101 hs2_set_policy(dut);
9102 return 0;
9103}
9104
9105
9106static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
9107 struct sigma_conn *conn,
9108 const char *ifname,
9109 struct sigma_cmd *cmd)
9110{
9111 const char *val;
9112 int id;
9113
9114 id = add_cred(ifname);
9115 if (id < 0)
9116 return -2;
9117 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9118
9119 val = get_param(cmd, "prefer");
9120 if (val && atoi(val) > 0)
9121 set_cred(ifname, id, "priority", "1");
9122
9123 val = get_param(cmd, "REALM");
9124 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9125 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9126 "realm");
9127 return 0;
9128 }
9129
9130 val = get_param(cmd, "HOME_FQDN");
9131 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9132 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9133 "home_fqdn");
9134 return 0;
9135 }
9136
9137 val = get_param(cmd, "Username");
9138 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9139 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9140 "username");
9141 return 0;
9142 }
9143
9144 val = get_param(cmd, "Password");
9145 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
9146 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9147 "password");
9148 return 0;
9149 }
9150
9151 val = get_param(cmd, "ROOT_CA");
9152 if (val) {
9153 char fname[200];
9154 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9155#ifdef __linux__
9156 if (!file_exists(fname)) {
9157 char msg[300];
9158 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9159 "file (%s) not found", fname);
9160 send_resp(dut, conn, SIGMA_ERROR, msg);
9161 return 0;
9162 }
9163#endif /* __linux__ */
9164 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9165 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9166 "not set root CA");
9167 return 0;
9168 }
9169 }
9170
9171 return 1;
9172}
9173
9174
9175static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
9176{
9177 FILE *in, *out;
9178 char buf[500];
9179 int found = 0;
9180
9181 in = fopen("devdetail.xml", "r");
9182 if (in == NULL)
9183 return -1;
9184 out = fopen("devdetail.xml.tmp", "w");
9185 if (out == NULL) {
9186 fclose(in);
9187 return -1;
9188 }
9189
9190 while (fgets(buf, sizeof(buf), in)) {
9191 char *pos = strstr(buf, "<IMSI>");
9192 if (pos) {
9193 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
9194 imsi);
9195 pos += 6;
9196 *pos = '\0';
9197 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
9198 found++;
9199 } else {
9200 fprintf(out, "%s", buf);
9201 }
9202 }
9203
9204 fclose(out);
9205 fclose(in);
9206 if (found)
9207 rename("devdetail.xml.tmp", "devdetail.xml");
9208 else
9209 unlink("devdetail.xml.tmp");
9210
9211 return 0;
9212}
9213
9214
9215static int sta_add_credential_sim(struct sigma_dut *dut,
9216 struct sigma_conn *conn,
9217 const char *ifname, struct sigma_cmd *cmd)
9218{
9219 const char *val, *imsi = NULL;
9220 int id;
9221 char buf[200];
9222 int res;
9223 const char *pos;
9224 size_t mnc_len;
9225 char plmn_mcc[4];
9226 char plmn_mnc[4];
9227
9228 id = add_cred(ifname);
9229 if (id < 0)
9230 return -2;
9231 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9232
9233 val = get_param(cmd, "prefer");
9234 if (val && atoi(val) > 0)
9235 set_cred(ifname, id, "priority", "1");
9236
9237 val = get_param(cmd, "PLMN_MCC");
9238 if (val == NULL) {
9239 send_resp(dut, conn, SIGMA_ERROR,
9240 "errorCode,Missing PLMN_MCC");
9241 return 0;
9242 }
9243 if (strlen(val) != 3) {
9244 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
9245 return 0;
9246 }
9247 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
9248
9249 val = get_param(cmd, "PLMN_MNC");
9250 if (val == NULL) {
9251 send_resp(dut, conn, SIGMA_ERROR,
9252 "errorCode,Missing PLMN_MNC");
9253 return 0;
9254 }
9255 if (strlen(val) != 2 && strlen(val) != 3) {
9256 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
9257 return 0;
9258 }
9259 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
9260
9261 val = get_param(cmd, "IMSI");
9262 if (val == NULL) {
9263 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
9264 "IMSI");
9265 return 0;
9266 }
9267
9268 imsi = pos = val;
9269
9270 if (strncmp(plmn_mcc, pos, 3) != 0) {
9271 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
9272 return 0;
9273 }
9274 pos += 3;
9275
9276 mnc_len = strlen(plmn_mnc);
9277 if (mnc_len < 2) {
9278 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
9279 return 0;
9280 }
9281
9282 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
9283 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
9284 return 0;
9285 }
9286 pos += mnc_len;
9287
9288 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
9289 if (res < 0 || res >= (int) sizeof(buf))
9290 return -1;
9291 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
9292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9293 "not set IMSI");
9294 return 0;
9295 }
9296
9297 val = get_param(cmd, "Password");
9298 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
9299 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9300 "not set password");
9301 return 0;
9302 }
9303
9304 if (dut->program == PROGRAM_HS2_R2) {
9305 /*
9306 * Set provisioning_sp for the test cases where SIM/USIM
9307 * provisioning is used.
9308 */
9309 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
9310 "wi-fi.org") < 0) {
9311 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9312 "not set provisioning_sp");
9313 return 0;
9314 }
9315
9316 update_devdetail_imsi(dut, imsi);
9317 }
9318
9319 return 1;
9320}
9321
9322
9323static int sta_add_credential_cert(struct sigma_dut *dut,
9324 struct sigma_conn *conn,
9325 const char *ifname,
9326 struct sigma_cmd *cmd)
9327{
9328 const char *val;
9329 int id;
9330
9331 id = add_cred(ifname);
9332 if (id < 0)
9333 return -2;
9334 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9335
9336 val = get_param(cmd, "prefer");
9337 if (val && atoi(val) > 0)
9338 set_cred(ifname, id, "priority", "1");
9339
9340 val = get_param(cmd, "REALM");
9341 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9342 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9343 "realm");
9344 return 0;
9345 }
9346
9347 val = get_param(cmd, "HOME_FQDN");
9348 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9350 "home_fqdn");
9351 return 0;
9352 }
9353
9354 val = get_param(cmd, "Username");
9355 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9356 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9357 "username");
9358 return 0;
9359 }
9360
9361 val = get_param(cmd, "clientCertificate");
9362 if (val) {
9363 char fname[200];
9364 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9365#ifdef __linux__
9366 if (!file_exists(fname)) {
9367 char msg[300];
9368 snprintf(msg, sizeof(msg),
9369 "ErrorCode,clientCertificate "
9370 "file (%s) not found", fname);
9371 send_resp(dut, conn, SIGMA_ERROR, msg);
9372 return 0;
9373 }
9374#endif /* __linux__ */
9375 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
9376 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9377 "not set client_cert");
9378 return 0;
9379 }
9380 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
9381 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9382 "not set private_key");
9383 return 0;
9384 }
9385 }
9386
9387 val = get_param(cmd, "ROOT_CA");
9388 if (val) {
9389 char fname[200];
9390 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9391#ifdef __linux__
9392 if (!file_exists(fname)) {
9393 char msg[300];
9394 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9395 "file (%s) not found", fname);
9396 send_resp(dut, conn, SIGMA_ERROR, msg);
9397 return 0;
9398 }
9399#endif /* __linux__ */
9400 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9402 "not set root CA");
9403 return 0;
9404 }
9405 }
9406
9407 return 1;
9408}
9409
9410
9411static int cmd_sta_add_credential(struct sigma_dut *dut,
9412 struct sigma_conn *conn,
9413 struct sigma_cmd *cmd)
9414{
9415 const char *intf = get_param(cmd, "Interface");
9416 const char *type;
9417
9418 start_sta_mode(dut);
9419
9420 type = get_param(cmd, "Type");
9421 if (!type)
9422 return -1;
9423
9424 if (strcasecmp(type, "uname_pwd") == 0)
9425 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9426
9427 if (strcasecmp(type, "sim") == 0)
9428 return sta_add_credential_sim(dut, conn, intf, cmd);
9429
9430 if (strcasecmp(type, "cert") == 0)
9431 return sta_add_credential_cert(dut, conn, intf, cmd);
9432
9433 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9434 "type");
9435 return 0;
9436}
9437
9438
9439static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9440 struct sigma_cmd *cmd)
9441{
9442 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309443 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009444 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309445 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009446 int res;
9447
9448 val = get_param(cmd, "HESSID");
9449 if (val) {
9450 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9451 if (res < 0 || res >= (int) sizeof(buf))
9452 return -1;
9453 wpa_command(intf, buf);
9454 }
9455
9456 val = get_param(cmd, "ACCS_NET_TYPE");
9457 if (val) {
9458 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9459 val);
9460 if (res < 0 || res >= (int) sizeof(buf))
9461 return -1;
9462 wpa_command(intf, buf);
9463 }
9464
vamsi krishna89ad8c62017-09-19 12:51:18 +05309465 bssid = get_param(cmd, "Bssid");
9466 ssid = get_param(cmd, "Ssid");
9467
9468 if (ssid) {
9469 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9470 send_resp(dut, conn, SIGMA_ERROR,
9471 "ErrorCode,Too long SSID");
9472 return 0;
9473 }
9474 ascii2hexstr(ssid, ssid_hex);
9475 }
9476
9477 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9478 bssid ? " bssid=": "",
9479 bssid ? bssid : "",
9480 ssid ? " ssid " : "",
9481 ssid ? ssid_hex : "");
9482 if (res < 0 || res >= (int) sizeof(buf))
9483 return -1;
9484
9485 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009486 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9487 "scan");
9488 return 0;
9489 }
9490
9491 return 1;
9492}
9493
9494
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009495static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9496 struct sigma_cmd *cmd)
9497{
9498 const char *intf = get_param(cmd, "Interface");
9499 const char *bssid;
9500 char buf[4096], *pos;
9501 int freq, chan;
9502 char *ssid;
9503 char resp[100];
9504 int res;
9505 struct wpa_ctrl *ctrl;
9506
9507 bssid = get_param(cmd, "BSSID");
9508 if (!bssid) {
9509 send_resp(dut, conn, SIGMA_INVALID,
9510 "errorCode,BSSID argument is missing");
9511 return 0;
9512 }
9513
9514 ctrl = open_wpa_mon(intf);
9515 if (!ctrl) {
9516 sigma_dut_print(dut, DUT_MSG_ERROR,
9517 "Failed to open wpa_supplicant monitor connection");
9518 return -1;
9519 }
9520
9521 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9522 send_resp(dut, conn, SIGMA_ERROR,
9523 "errorCode,Could not start scan");
9524 wpa_ctrl_detach(ctrl);
9525 wpa_ctrl_close(ctrl);
9526 return 0;
9527 }
9528
9529 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9530 buf, sizeof(buf));
9531
9532 wpa_ctrl_detach(ctrl);
9533 wpa_ctrl_close(ctrl);
9534
9535 if (res < 0) {
9536 send_resp(dut, conn, SIGMA_ERROR,
9537 "errorCode,Scan did not complete");
9538 return 0;
9539 }
9540
9541 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9542 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9543 strncmp(buf, "id=", 3) != 0) {
9544 send_resp(dut, conn, SIGMA_ERROR,
9545 "errorCode,Specified BSSID not found");
9546 return 0;
9547 }
9548
9549 pos = strstr(buf, "\nfreq=");
9550 if (!pos) {
9551 send_resp(dut, conn, SIGMA_ERROR,
9552 "errorCode,Channel not found");
9553 return 0;
9554 }
9555 freq = atoi(pos + 6);
9556 chan = freq_to_channel(freq);
9557
9558 pos = strstr(buf, "\nssid=");
9559 if (!pos) {
9560 send_resp(dut, conn, SIGMA_ERROR,
9561 "errorCode,SSID not found");
9562 return 0;
9563 }
9564 ssid = pos + 6;
9565 pos = strchr(ssid, '\n');
9566 if (pos)
9567 *pos = '\0';
9568 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9569 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9570 return 0;
9571}
9572
9573
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009574static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9575 struct sigma_cmd *cmd)
9576{
9577#ifdef __linux__
9578 struct timeval tv;
9579 struct tm tm;
9580 time_t t;
9581 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309582 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009583
9584 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9585
9586 memset(&tm, 0, sizeof(tm));
9587 val = get_param(cmd, "seconds");
9588 if (val)
9589 tm.tm_sec = atoi(val);
9590 val = get_param(cmd, "minutes");
9591 if (val)
9592 tm.tm_min = atoi(val);
9593 val = get_param(cmd, "hours");
9594 if (val)
9595 tm.tm_hour = atoi(val);
9596 val = get_param(cmd, "date");
9597 if (val)
9598 tm.tm_mday = atoi(val);
9599 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309600 if (val) {
9601 v = atoi(val);
9602 if (v < 1 || v > 12) {
9603 send_resp(dut, conn, SIGMA_INVALID,
9604 "errorCode,Invalid month");
9605 return 0;
9606 }
9607 tm.tm_mon = v - 1;
9608 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009609 val = get_param(cmd, "year");
9610 if (val) {
9611 int year = atoi(val);
9612#ifdef ANDROID
9613 if (year > 2035)
9614 year = 2035; /* years beyond 2035 not supported */
9615#endif /* ANDROID */
9616 tm.tm_year = year - 1900;
9617 }
9618 t = mktime(&tm);
9619 if (t == (time_t) -1) {
9620 send_resp(dut, conn, SIGMA_ERROR,
9621 "errorCode,Invalid date or time");
9622 return 0;
9623 }
9624
9625 memset(&tv, 0, sizeof(tv));
9626 tv.tv_sec = t;
9627
9628 if (settimeofday(&tv, NULL) < 0) {
9629 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9630 strerror(errno));
9631 send_resp(dut, conn, SIGMA_ERROR,
9632 "errorCode,Failed to set time");
9633 return 0;
9634 }
9635
9636 return 1;
9637#endif /* __linux__ */
9638
9639 return -1;
9640}
9641
9642
9643static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9644 struct sigma_cmd *cmd)
9645{
9646 const char *intf = get_param(cmd, "Interface");
9647 const char *name, *val;
9648 int prod_ess_assoc = 1;
9649 char buf[200], bssid[100], ssid[100];
9650 int res;
9651 struct wpa_ctrl *ctrl;
9652
9653 name = get_param(cmd, "osuFriendlyName");
9654
9655 val = get_param(cmd, "ProdESSAssoc");
9656 if (val)
9657 prod_ess_assoc = atoi(val);
9658
9659 kill_dhcp_client(dut, intf);
9660 if (start_dhcp_client(dut, intf) < 0)
9661 return -2;
9662
9663 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9664 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9665 res = snprintf(buf, sizeof(buf),
9666 "%s %s%s%s signup osu-ca.pem",
9667 prod_ess_assoc ? "" : "-N",
9668 name ? "-O'" : "", name ? name : "",
9669 name ? "'" : "");
9670
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309671 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009672 if (run_hs20_osu(dut, buf) < 0) {
9673 FILE *f;
9674
9675 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9676
9677 f = fopen("hs20-osu-client.res", "r");
9678 if (f) {
9679 char resp[400], res[300], *pos;
9680 if (!fgets(res, sizeof(res), f))
9681 res[0] = '\0';
9682 pos = strchr(res, '\n');
9683 if (pos)
9684 *pos = '\0';
9685 fclose(f);
9686 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
9687 res);
9688 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
9689 if (system(resp) != 0) {
9690 }
9691 snprintf(resp, sizeof(resp),
9692 "SSID,,BSSID,,failureReason,%s", res);
9693 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9694 return 0;
9695 }
9696
9697 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9698 return 0;
9699 }
9700
9701 if (!prod_ess_assoc)
9702 goto report;
9703
9704 ctrl = open_wpa_mon(intf);
9705 if (ctrl == NULL) {
9706 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9707 "wpa_supplicant monitor connection");
9708 return -1;
9709 }
9710
9711 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9712 buf, sizeof(buf));
9713
9714 wpa_ctrl_detach(ctrl);
9715 wpa_ctrl_close(ctrl);
9716
9717 if (res < 0) {
9718 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
9719 "network after OSU");
9720 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9721 return 0;
9722 }
9723
9724report:
9725 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9726 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9727 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
9728 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9729 return 0;
9730 }
9731
9732 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
9733 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009734 return 0;
9735}
9736
9737
9738static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
9739 struct sigma_cmd *cmd)
9740{
9741 const char *val;
9742 int timeout = 120;
9743
9744 val = get_param(cmd, "PolicyUpdate");
9745 if (val == NULL || atoi(val) == 0)
9746 return 1; /* No operation requested */
9747
9748 val = get_param(cmd, "Timeout");
9749 if (val)
9750 timeout = atoi(val);
9751
9752 if (timeout) {
9753 /* TODO: time out the command and return
9754 * PolicyUpdateStatus,TIMEOUT if needed. */
9755 }
9756
9757 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
9758 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9759 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
9760 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
9761 return 0;
9762 }
9763
9764 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
9765 return 0;
9766}
9767
9768
9769static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
9770 struct sigma_cmd *cmd)
9771{
9772 struct wpa_ctrl *ctrl;
9773 const char *intf = get_param(cmd, "Interface");
9774 const char *bssid = get_param(cmd, "Bssid");
9775 const char *ssid = get_param(cmd, "SSID");
9776 const char *security = get_param(cmd, "Security");
9777 const char *passphrase = get_param(cmd, "Passphrase");
9778 const char *pin = get_param(cmd, "PIN");
9779 char buf[1000];
9780 char ssid_hex[200], passphrase_hex[200];
9781 const char *keymgmt, *cipher;
9782
9783 if (intf == NULL)
9784 intf = get_main_ifname();
9785
9786 if (!bssid) {
9787 send_resp(dut, conn, SIGMA_ERROR,
9788 "ErrorCode,Missing Bssid argument");
9789 return 0;
9790 }
9791
9792 if (!ssid) {
9793 send_resp(dut, conn, SIGMA_ERROR,
9794 "ErrorCode,Missing SSID argument");
9795 return 0;
9796 }
9797
9798 if (!security) {
9799 send_resp(dut, conn, SIGMA_ERROR,
9800 "ErrorCode,Missing Security argument");
9801 return 0;
9802 }
9803
9804 if (!passphrase) {
9805 send_resp(dut, conn, SIGMA_ERROR,
9806 "ErrorCode,Missing Passphrase argument");
9807 return 0;
9808 }
9809
9810 if (!pin) {
9811 send_resp(dut, conn, SIGMA_ERROR,
9812 "ErrorCode,Missing PIN argument");
9813 return 0;
9814 }
9815
vamsi krishna8c9c1562017-05-12 15:51:46 +05309816 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
9817 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009818 send_resp(dut, conn, SIGMA_ERROR,
9819 "ErrorCode,Too long SSID/passphrase");
9820 return 0;
9821 }
9822
9823 ctrl = open_wpa_mon(intf);
9824 if (ctrl == NULL) {
9825 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9826 "wpa_supplicant monitor connection");
9827 return -2;
9828 }
9829
9830 if (strcasecmp(security, "wpa2-psk") == 0) {
9831 keymgmt = "WPA2PSK";
9832 cipher = "CCMP";
9833 } else {
9834 wpa_ctrl_detach(ctrl);
9835 wpa_ctrl_close(ctrl);
9836 send_resp(dut, conn, SIGMA_ERROR,
9837 "ErrorCode,Unsupported Security value");
9838 return 0;
9839 }
9840
9841 ascii2hexstr(ssid, ssid_hex);
9842 ascii2hexstr(passphrase, passphrase_hex);
9843 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
9844 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
9845
9846 if (wpa_command(intf, buf) < 0) {
9847 wpa_ctrl_detach(ctrl);
9848 wpa_ctrl_close(ctrl);
9849 send_resp(dut, conn, SIGMA_ERROR,
9850 "ErrorCode,Failed to start registrar");
9851 return 0;
9852 }
9853
9854 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
9855 dut->er_oper_performed = 1;
9856
9857 return wps_connection_event(dut, conn, ctrl, intf, 0);
9858}
9859
9860
9861static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
9862 struct sigma_conn *conn,
9863 struct sigma_cmd *cmd)
9864{
9865 struct wpa_ctrl *ctrl;
9866 const char *intf = get_param(cmd, "Interface");
9867 const char *bssid = get_param(cmd, "Bssid");
9868 char buf[100];
9869
9870 if (!bssid) {
9871 send_resp(dut, conn, SIGMA_ERROR,
9872 "ErrorCode,Missing Bssid argument");
9873 return 0;
9874 }
9875
9876 ctrl = open_wpa_mon(intf);
9877 if (ctrl == NULL) {
9878 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9879 "wpa_supplicant monitor connection");
9880 return -2;
9881 }
9882
9883 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
9884
9885 if (wpa_command(intf, buf) < 0) {
9886 wpa_ctrl_detach(ctrl);
9887 wpa_ctrl_close(ctrl);
9888 send_resp(dut, conn, SIGMA_ERROR,
9889 "ErrorCode,Failed to start registrar");
9890 return 0;
9891 }
9892
9893 return wps_connection_event(dut, conn, ctrl, intf, 0);
9894}
9895
9896
vamsi krishna9b144002017-09-20 13:28:13 +05309897static int cmd_start_wps_registration(struct sigma_dut *dut,
9898 struct sigma_conn *conn,
9899 struct sigma_cmd *cmd)
9900{
9901 struct wpa_ctrl *ctrl;
9902 const char *intf = get_param(cmd, "Interface");
9903 const char *role, *method;
9904 int res;
9905 char buf[256];
9906 const char *events[] = {
9907 "CTRL-EVENT-CONNECTED",
9908 "WPS-OVERLAP-DETECTED",
9909 "WPS-TIMEOUT",
9910 "WPS-FAIL",
9911 NULL
9912 };
9913
9914 ctrl = open_wpa_mon(intf);
9915 if (!ctrl) {
9916 sigma_dut_print(dut, DUT_MSG_ERROR,
9917 "Failed to open wpa_supplicant monitor connection");
9918 return -2;
9919 }
9920
9921 role = get_param(cmd, "WpsRole");
9922 if (!role) {
9923 send_resp(dut, conn, SIGMA_INVALID,
9924 "ErrorCode,WpsRole not provided");
9925 goto fail;
9926 }
9927
9928 if (strcasecmp(role, "Enrollee") == 0) {
9929 method = get_param(cmd, "WpsConfigMethod");
9930 if (!method) {
9931 send_resp(dut, conn, SIGMA_INVALID,
9932 "ErrorCode,WpsConfigMethod not provided");
9933 goto fail;
9934 }
9935 if (strcasecmp(method, "PBC") == 0) {
9936 if (wpa_command(intf, "WPS_PBC") < 0) {
9937 send_resp(dut, conn, SIGMA_ERROR,
9938 "ErrorCode,Failed to enable PBC");
9939 goto fail;
9940 }
9941 } else {
9942 /* TODO: PIN method */
9943 send_resp(dut, conn, SIGMA_ERROR,
9944 "ErrorCode,Unsupported WpsConfigMethod value");
9945 goto fail;
9946 }
9947 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9948 if (res < 0) {
9949 send_resp(dut, conn, SIGMA_ERROR,
9950 "ErrorCode,WPS connection did not complete");
9951 goto fail;
9952 }
9953 if (strstr(buf, "WPS-TIMEOUT")) {
9954 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
9955 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
9956 send_resp(dut, conn, SIGMA_ERROR,
9957 "ErrorCode,OverlapSession");
9958 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
9959 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
9960 } else {
9961 send_resp(dut, conn, SIGMA_ERROR,
9962 "ErrorCode,WPS operation failed");
9963 }
9964 } else {
9965 /* TODO: Registrar role */
9966 send_resp(dut, conn, SIGMA_ERROR,
9967 "ErrorCode,Unsupported WpsRole value");
9968 }
9969
9970fail:
9971 wpa_ctrl_detach(ctrl);
9972 wpa_ctrl_close(ctrl);
9973 return 0;
9974}
9975
9976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009977static int req_intf(struct sigma_cmd *cmd)
9978{
9979 return get_param(cmd, "interface") == NULL ? -1 : 0;
9980}
9981
9982
9983void sta_register_cmds(void)
9984{
9985 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
9986 cmd_sta_get_ip_config);
9987 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
9988 cmd_sta_set_ip_config);
9989 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
9990 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
9991 cmd_sta_get_mac_address);
9992 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
9993 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
9994 cmd_sta_verify_ip_connection);
9995 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
9996 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
9997 cmd_sta_set_encryption);
9998 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
9999 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
10000 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
10001 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
10002 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
10003 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
10004 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
10005 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
10006 cmd_sta_set_eapakaprime);
10007 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
10008 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
10009 /* TODO: sta_set_ibss */
10010 /* TODO: sta_set_mode */
10011 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
10012 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
10013 /* TODO: sta_up_load */
10014 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
10015 cmd_sta_preset_testparameters);
10016 /* TODO: sta_set_system */
10017 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
10018 /* TODO: sta_set_rifs_test */
10019 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
10020 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
10021 /* TODO: sta_send_coexist_mgmt */
10022 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
10023 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
10024 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
10025 sigma_dut_reg_cmd("sta_reset_default", req_intf,
10026 cmd_sta_reset_default);
10027 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
10028 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
10029 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
10030 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
10031 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
10032 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
10033 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
10034 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
10035 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
10036 cmd_sta_hs2_associate);
10037 sigma_dut_reg_cmd("sta_add_credential", req_intf,
10038 cmd_sta_add_credential);
10039 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020010040 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010041 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
10042 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
10043 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
10044 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
10045 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
10046 cmd_sta_wps_connect_pw_token);
10047 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
10048 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
10049 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053010050 sigma_dut_reg_cmd("start_wps_registration", req_intf,
10051 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010052}