blob: 5743273f1cbfd0b3ac79ee3457313807a7d24f1c [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
3388 if (strcmp(val, "1SS") == 0) {
3389 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
3390 } else if (strcmp(val, "2SS") == 0) {
3391 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 Subramanyam58f2a6e2018-01-31 03:36:00 -08005579static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5580 const char *type)
5581{
5582 char buf[60];
5583
5584 if (dut->program == PROGRAM_HE) {
5585 /* resetting phymode to auto in case of HE program */
5586 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5587 if (system(buf) != 0) {
5588 sigma_dut_print(dut, DUT_MSG_ERROR,
5589 "iwpriv %s setphymode failed", intf);
5590 }
5591
5592 /* remove all network profiles */
5593 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005594
5595 /* Set nss to 1 and MCS 0-7 in case of testbed */
5596 if (type && strcasecmp(type, "Testbed") == 0) {
5597#ifdef NL80211_SUPPORT
5598 int ret;
5599#endif /* NL80211_SUPPORT */
5600
5601 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5602 if (system(buf) != 0) {
5603 sigma_dut_print(dut, DUT_MSG_ERROR,
5604 "iwpriv %s nss failed", intf);
5605 }
5606
5607#ifdef NL80211_SUPPORT
5608 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5609 if (ret) {
5610 sigma_dut_print(dut, DUT_MSG_ERROR,
5611 "Setting of MCS failed, ret:%d",
5612 ret);
5613 }
5614#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08005615
5616 /* Disable STBC as default */
5617 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005618
5619 /* Disable AMSDU as default */
5620 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08005621
5622#ifdef NL80211_SUPPORT
5623 /* HE fragmentation default off */
5624 if (sta_set_he_fragmentation(dut, intf,
5625 HE_FRAG_DISABLE)) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR,
5627 "Setting of HE fragmentation failed");
5628 }
5629#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005630 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005631 }
5632}
5633
5634
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005635static int cmd_sta_reset_default(struct sigma_dut *dut,
5636 struct sigma_conn *conn,
5637 struct sigma_cmd *cmd)
5638{
5639 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5640 struct sigma_cmd *cmd);
5641 const char *intf = get_param(cmd, "Interface");
5642 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005643 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305644 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005645
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005646 if (!program)
5647 program = get_param(cmd, "prog");
5648 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005649 dut->device_type = STA_unknown;
5650 type = get_param(cmd, "type");
5651 if (type && strcasecmp(type, "Testbed") == 0)
5652 dut->device_type = STA_testbed;
5653 if (type && strcasecmp(type, "DUT") == 0)
5654 dut->device_type = STA_dut;
5655
5656 if (dut->program == PROGRAM_TDLS) {
5657 /* Clear TDLS testing mode */
5658 wpa_command(intf, "SET tdls_disabled 0");
5659 wpa_command(intf, "SET tdls_testing 0");
5660 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305661 if (get_driver_type() == DRIVER_WCN) {
5662 /* Enable the WCN driver in TDLS Explicit trigger mode
5663 */
5664 wpa_command(intf, "SET tdls_external_control 0");
5665 wpa_command(intf, "SET tdls_trigger_control 0");
5666 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005667 }
5668
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005669#ifdef MIRACAST
5670 if (dut->program == PROGRAM_WFD ||
5671 dut->program == PROGRAM_DISPLAYR2)
5672 miracast_sta_reset_default(dut, conn, cmd);
5673#endif /* MIRACAST */
5674
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005675 switch (get_driver_type()) {
5676 case DRIVER_ATHEROS:
5677 sta_reset_default_ath(dut, intf, type);
5678 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005679 case DRIVER_WCN:
5680 sta_reset_default_wcn(dut, intf, type);
5681 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005682 default:
5683 break;
5684 }
5685
5686#ifdef ANDROID_NAN
5687 if (dut->program == PROGRAM_NAN)
5688 nan_cmd_sta_reset_default(dut, conn, cmd);
5689#endif /* ANDROID_NAN */
5690
5691 if (dut->program == PROGRAM_HS2_R2) {
5692 unlink("SP/wi-fi.org/pps.xml");
5693 if (system("rm -r SP/*") != 0) {
5694 }
5695 unlink("next-client-cert.pem");
5696 unlink("next-client-key.pem");
5697 }
5698
5699 if (dut->program == PROGRAM_60GHZ) {
5700 const char *dev_role = get_param(cmd, "DevRole");
5701
5702 if (!dev_role) {
5703 send_resp(dut, conn, SIGMA_ERROR,
5704 "errorCode,Missing DevRole argument");
5705 return 0;
5706 }
5707
5708 if (strcasecmp(dev_role, "STA") == 0)
5709 dut->dev_role = DEVROLE_STA;
5710 else if (strcasecmp(dev_role, "PCP") == 0)
5711 dut->dev_role = DEVROLE_PCP;
5712 else {
5713 send_resp(dut, conn, SIGMA_ERROR,
5714 "errorCode,Unknown DevRole");
5715 return 0;
5716 }
5717
5718 if (dut->device_type == STA_unknown) {
5719 sigma_dut_print(dut, DUT_MSG_ERROR,
5720 "Device type is not STA testbed or DUT");
5721 send_resp(dut, conn, SIGMA_ERROR,
5722 "errorCode,Unknown device type");
5723 return 0;
5724 }
5725 }
5726
5727 wpa_command(intf, "WPS_ER_STOP");
5728 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305729 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005730 wpa_command(intf, "SET radio_disabled 0");
5731
5732 if (dut->tmp_mac_addr && dut->set_macaddr) {
5733 dut->tmp_mac_addr = 0;
5734 if (system(dut->set_macaddr) != 0) {
5735 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5736 "temporary MAC address");
5737 }
5738 }
5739
5740 set_ps(intf, dut, 0);
5741
5742 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5743 wpa_command(intf, "SET interworking 1");
5744 wpa_command(intf, "SET hs20 1");
5745 }
5746
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08005747 if (dut->program == PROGRAM_HS2_R2 ||
5748 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005749 wpa_command(intf, "SET pmf 1");
5750 } else {
5751 wpa_command(intf, "SET pmf 0");
5752 }
5753
5754 hs2_clear_credentials(intf);
5755 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
5756 wpa_command(intf, "SET access_network_type 15");
5757
5758 static_ip_file(0, NULL, NULL, NULL);
5759 kill_dhcp_client(dut, intf);
5760 clear_ip_addr(dut, intf);
5761
5762 dut->er_oper_performed = 0;
5763 dut->er_oper_bssid[0] = '\0';
5764
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07005765 if (dut->program == PROGRAM_LOC) {
5766 /* Disable Interworking by default */
5767 wpa_command(get_station_ifname(), "SET interworking 0");
5768 }
5769
Ashwini Patil00402582017-04-13 12:29:39 +05305770 if (dut->program == PROGRAM_MBO) {
5771 free(dut->non_pref_ch_list);
5772 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05305773 free(dut->btm_query_cand_list);
5774 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05305775 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05305776 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05305777 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305778 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05305779 }
5780
Jouni Malinen3c367e82017-06-23 17:01:47 +03005781 free(dut->rsne_override);
5782 dut->rsne_override = NULL;
5783
Jouni Malinen68143132017-09-02 02:34:08 +03005784 free(dut->sae_commit_override);
5785 dut->sae_commit_override = NULL;
5786
Jouni Malinend86e5822017-08-29 03:55:32 +03005787 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02005788 free(dut->dpp_peer_uri);
5789 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02005790 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02005791 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03005792
Jouni Malinenfac9cad2017-10-10 18:35:55 +03005793 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
5794
vamsi krishnaa2799492017-12-05 14:28:01 +05305795 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305796 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05305797 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305798 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
5799 dut->fils_hlp = 0;
5800#ifdef ANDROID
5801 hlp_thread_cleanup(dut);
5802#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05305803 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305804
Sunil Dutt076081f2018-02-05 19:45:50 +05305805#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05305806 if (get_driver_type() == DRIVER_WCN &&
5807 dut->config_rsnie == 1) {
5808 dut->config_rsnie = 0;
5809 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05305810 }
5811#endif /* NL80211_SUPPORT */
5812
Sunil Duttfebf8a82018-02-09 18:50:13 +05305813 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
5814 dut->dev_role = DEVROLE_STA_CFON;
5815 return sta_cfon_reset_default(dut, conn, cmd);
5816 }
5817
5818 if (dut->program != PROGRAM_VHT)
5819 return cmd_sta_p2p_reset(dut, conn, cmd);
5820
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08005821 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005822}
5823
5824
5825static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
5826 struct sigma_cmd *cmd)
5827{
5828 const char *program = get_param(cmd, "Program");
5829
5830 if (program == NULL)
5831 return -1;
5832#ifdef ANDROID_NAN
5833 if (strcasecmp(program, "NAN") == 0)
5834 return nan_cmd_sta_get_events(dut, conn, cmd);
5835#endif /* ANDROID_NAN */
5836 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5837 return 0;
5838}
5839
5840
5841static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
5842 struct sigma_cmd *cmd)
5843{
5844 const char *program = get_param(cmd, "Prog");
5845
5846 if (program == NULL)
5847 return -1;
5848#ifdef ANDROID_NAN
5849 if (strcasecmp(program, "NAN") == 0)
5850 return nan_cmd_sta_exec_action(dut, conn, cmd);
5851#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005852 if (strcasecmp(program, "Loc") == 0)
5853 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005854 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5855 return 0;
5856}
5857
5858
5859static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
5860 struct sigma_cmd *cmd)
5861{
5862 const char *intf = get_param(cmd, "Interface");
5863 const char *val, *mcs32, *rate;
5864
5865 val = get_param(cmd, "GREENFIELD");
5866 if (val) {
5867 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5868 /* Enable GD */
5869 send_resp(dut, conn, SIGMA_ERROR,
5870 "ErrorCode,GF not supported");
5871 return 0;
5872 }
5873 }
5874
5875 val = get_param(cmd, "SGI20");
5876 if (val) {
5877 switch (get_driver_type()) {
5878 case DRIVER_ATHEROS:
5879 ath_sta_set_sgi(dut, intf, val);
5880 break;
5881 default:
5882 send_resp(dut, conn, SIGMA_ERROR,
5883 "ErrorCode,SGI20 not supported");
5884 return 0;
5885 }
5886 }
5887
5888 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
5889 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
5890 if (mcs32 && rate) {
5891 /* TODO */
5892 send_resp(dut, conn, SIGMA_ERROR,
5893 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
5894 return 0;
5895 } else if (mcs32 && !rate) {
5896 /* TODO */
5897 send_resp(dut, conn, SIGMA_ERROR,
5898 "ErrorCode,MCS32 not supported");
5899 return 0;
5900 } else if (!mcs32 && rate) {
5901 switch (get_driver_type()) {
5902 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005903 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005904 ath_sta_set_11nrates(dut, intf, rate);
5905 break;
5906 default:
5907 send_resp(dut, conn, SIGMA_ERROR,
5908 "ErrorCode,MCS32_FIXEDRATE not supported");
5909 return 0;
5910 }
5911 }
5912
5913 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5914}
5915
5916
5917static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
5918 struct sigma_conn *conn,
5919 struct sigma_cmd *cmd)
5920{
5921 const char *intf = get_param(cmd, "Interface");
5922 const char *val;
5923 char buf[30];
5924 int tkip = -1;
5925 int wep = -1;
5926
5927 val = get_param(cmd, "SGI80");
5928 if (val) {
5929 int sgi80;
5930
5931 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5932 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
5933 if (system(buf) != 0) {
5934 sigma_dut_print(dut, DUT_MSG_ERROR,
5935 "iwpriv shortgi failed");
5936 }
5937 }
5938
5939 val = get_param(cmd, "TxBF");
5940 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5941 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
5942 if (system(buf) != 0) {
5943 sigma_dut_print(dut, DUT_MSG_ERROR,
5944 "iwpriv vhtsubfee failed");
5945 }
5946 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
5947 if (system(buf) != 0) {
5948 sigma_dut_print(dut, DUT_MSG_ERROR,
5949 "iwpriv vhtsubfer failed");
5950 }
5951 }
5952
5953 val = get_param(cmd, "MU_TxBF");
5954 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5955 switch (get_driver_type()) {
5956 case DRIVER_ATHEROS:
5957 ath_sta_set_txsp_stream(dut, intf, "1SS");
5958 ath_sta_set_rxsp_stream(dut, intf, "1SS");
5959 case DRIVER_WCN:
5960 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
5961 send_resp(dut, conn, SIGMA_ERROR,
5962 "ErrorCode,Failed to set RX/TXSP_STREAM");
5963 return 0;
5964 }
5965 default:
5966 sigma_dut_print(dut, DUT_MSG_ERROR,
5967 "Setting SP_STREAM not supported");
5968 break;
5969 }
5970 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
5971 if (system(buf) != 0) {
5972 sigma_dut_print(dut, DUT_MSG_ERROR,
5973 "iwpriv vhtmubfee failed");
5974 }
5975 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
5976 if (system(buf) != 0) {
5977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "iwpriv vhtmubfer failed");
5979 }
5980 }
5981
5982 val = get_param(cmd, "LDPC");
5983 if (val) {
5984 int ldpc;
5985
5986 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5987 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
5988 if (system(buf) != 0) {
5989 sigma_dut_print(dut, DUT_MSG_ERROR,
5990 "iwpriv ldpc failed");
5991 }
5992 }
5993
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08005994 val = get_param(cmd, "BCC");
5995 if (val) {
5996 int bcc;
5997
5998 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5999 /* use LDPC iwpriv itself to set bcc coding, bcc coding
6000 * is mutually exclusive to bcc */
6001 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
6002 if (system(buf) != 0) {
6003 sigma_dut_print(dut, DUT_MSG_ERROR,
6004 "Enabling/Disabling of BCC failed");
6005 }
6006 }
6007
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006008 val = get_param(cmd, "opt_md_notif_ie");
6009 if (val) {
6010 char *result = NULL;
6011 char delim[] = ";";
6012 char token[30];
6013 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306014 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006015
Peng Xub8fc5cc2017-05-10 17:27:28 -07006016 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306017 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006018
6019 /* Extract the NSS information */
6020 if (result) {
6021 value = atoi(result);
6022 switch (value) {
6023 case 1:
6024 config_val = 1;
6025 break;
6026 case 2:
6027 config_val = 3;
6028 break;
6029 case 3:
6030 config_val = 7;
6031 break;
6032 case 4:
6033 config_val = 15;
6034 break;
6035 default:
6036 config_val = 3;
6037 break;
6038 }
6039
6040 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
6041 intf, config_val);
6042 if (system(buf) != 0) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "iwpriv rxchainmask failed");
6045 }
6046
6047 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
6048 intf, config_val);
6049 if (system(buf) != 0) {
6050 sigma_dut_print(dut, DUT_MSG_ERROR,
6051 "iwpriv txchainmask failed");
6052 }
6053 }
6054
6055 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306056 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006057 if (result) {
6058 value = atoi(result);
6059 switch (value) {
6060 case 20:
6061 config_val = 0;
6062 break;
6063 case 40:
6064 config_val = 1;
6065 break;
6066 case 80:
6067 config_val = 2;
6068 break;
6069 case 160:
6070 config_val = 3;
6071 break;
6072 default:
6073 config_val = 2;
6074 break;
6075 }
6076
6077 dut->chwidth = config_val;
6078
6079 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6080 intf, config_val);
6081 if (system(buf) != 0) {
6082 sigma_dut_print(dut, DUT_MSG_ERROR,
6083 "iwpriv chwidth failed");
6084 }
6085 }
6086
6087 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
6088 if (system(buf) != 0) {
6089 sigma_dut_print(dut, DUT_MSG_ERROR,
6090 "iwpriv opmode_notify failed");
6091 }
6092 }
6093
6094 val = get_param(cmd, "nss_mcs_cap");
6095 if (val) {
6096 int nss, mcs;
6097 char token[20];
6098 char *result = NULL;
6099 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306100 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006101
Peng Xub8fc5cc2017-05-10 17:27:28 -07006102 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306103 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306104 if (!result) {
6105 sigma_dut_print(dut, DUT_MSG_ERROR,
6106 "VHT NSS not specified");
6107 return 0;
6108 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006109 nss = atoi(result);
6110
6111 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
6112 if (system(buf) != 0) {
6113 sigma_dut_print(dut, DUT_MSG_ERROR,
6114 "iwpriv nss failed");
6115 }
6116
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306117 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006118 if (result == NULL) {
6119 sigma_dut_print(dut, DUT_MSG_ERROR,
6120 "VHTMCS NOT SPECIFIED!");
6121 return 0;
6122 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306123 result = strtok_r(result, "-", &saveptr);
6124 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306125 if (!result) {
6126 sigma_dut_print(dut, DUT_MSG_ERROR,
6127 "VHT MCS not specified");
6128 return 0;
6129 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130 mcs = atoi(result);
6131
6132 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
6133 if (system(buf) != 0) {
6134 sigma_dut_print(dut, DUT_MSG_ERROR,
6135 "iwpriv mcs failed");
6136 }
6137
6138 switch (nss) {
6139 case 1:
6140 switch (mcs) {
6141 case 7:
6142 vht_mcsmap = 0xfffc;
6143 break;
6144 case 8:
6145 vht_mcsmap = 0xfffd;
6146 break;
6147 case 9:
6148 vht_mcsmap = 0xfffe;
6149 break;
6150 default:
6151 vht_mcsmap = 0xfffe;
6152 break;
6153 }
6154 break;
6155 case 2:
6156 switch (mcs) {
6157 case 7:
6158 vht_mcsmap = 0xfff0;
6159 break;
6160 case 8:
6161 vht_mcsmap = 0xfff5;
6162 break;
6163 case 9:
6164 vht_mcsmap = 0xfffa;
6165 break;
6166 default:
6167 vht_mcsmap = 0xfffa;
6168 break;
6169 }
6170 break;
6171 case 3:
6172 switch (mcs) {
6173 case 7:
6174 vht_mcsmap = 0xffc0;
6175 break;
6176 case 8:
6177 vht_mcsmap = 0xffd5;
6178 break;
6179 case 9:
6180 vht_mcsmap = 0xffea;
6181 break;
6182 default:
6183 vht_mcsmap = 0xffea;
6184 break;
6185 }
6186 break;
6187 default:
6188 vht_mcsmap = 0xffea;
6189 break;
6190 }
6191 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
6192 intf, vht_mcsmap);
6193 if (system(buf) != 0) {
6194 sigma_dut_print(dut, DUT_MSG_ERROR,
6195 "iwpriv vht_mcsmap failed");
6196 }
6197 }
6198
6199 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
6200
6201 val = get_param(cmd, "Vht_tkip");
6202 if (val)
6203 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6204
6205 val = get_param(cmd, "Vht_wep");
6206 if (val)
6207 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6208
6209 if (tkip != -1 || wep != -1) {
6210 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
6211 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
6212 intf);
6213 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
6214 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
6215 intf);
6216 } else {
6217 sigma_dut_print(dut, DUT_MSG_ERROR,
6218 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
6219 return 0;
6220 }
6221
6222 if (system(buf) != 0) {
6223 sigma_dut_print(dut, DUT_MSG_ERROR,
6224 "iwpriv htweptkip failed");
6225 }
6226 }
6227
6228 val = get_param(cmd, "txBandwidth");
6229 if (val) {
6230 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006231 case DRIVER_WCN:
6232 if (wcn_sta_set_width(dut, intf, val) < 0) {
6233 send_resp(dut, conn, SIGMA_ERROR,
6234 "ErrorCode,Failed to set txBandwidth");
6235 return 0;
6236 }
6237 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006238 case DRIVER_ATHEROS:
6239 if (ath_set_width(dut, conn, intf, val) < 0) {
6240 send_resp(dut, conn, SIGMA_ERROR,
6241 "ErrorCode,Failed to set txBandwidth");
6242 return 0;
6243 }
6244 break;
6245 default:
6246 sigma_dut_print(dut, DUT_MSG_ERROR,
6247 "Setting txBandwidth not supported");
6248 break;
6249 }
6250 }
6251
6252 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6253}
6254
6255
6256static int sta_set_wireless_60g(struct sigma_dut *dut,
6257 struct sigma_conn *conn,
6258 struct sigma_cmd *cmd)
6259{
6260 const char *dev_role = get_param(cmd, "DevRole");
6261
6262 if (!dev_role) {
6263 send_resp(dut, conn, SIGMA_INVALID,
6264 "ErrorCode,DevRole not specified");
6265 return 0;
6266 }
6267
6268 if (strcasecmp(dev_role, "PCP") == 0)
6269 return sta_set_60g_pcp(dut, conn, cmd);
6270 if (strcasecmp(dev_role, "STA") == 0)
6271 return sta_set_60g_sta(dut, conn, cmd);
6272 send_resp(dut, conn, SIGMA_INVALID,
6273 "ErrorCode,DevRole not supported");
6274 return 0;
6275}
6276
6277
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306278static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
6279 struct sigma_cmd *cmd)
6280{
6281 int status;
6282 const char *intf = get_param(cmd, "Interface");
6283 const char *val = get_param(cmd, "DevRole");
6284
6285 if (val && strcasecmp(val, "STA-CFON") == 0) {
6286 status = sta_cfon_set_wireless(dut, conn, cmd);
6287 if (status)
6288 return status;
6289 }
6290 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6291}
6292
6293
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006294static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6295 struct sigma_cmd *cmd)
6296{
6297 const char *val;
6298
6299 val = get_param(cmd, "Program");
6300 if (val) {
6301 if (strcasecmp(val, "11n") == 0)
6302 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006303 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006304 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6305 if (strcasecmp(val, "60ghz") == 0)
6306 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306307 if (strcasecmp(val, "OCE") == 0)
6308 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309 send_resp(dut, conn, SIGMA_ERROR,
6310 "ErrorCode,Program value not supported");
6311 } else {
6312 send_resp(dut, conn, SIGMA_ERROR,
6313 "ErrorCode,Program argument not available");
6314 }
6315
6316 return 0;
6317}
6318
6319
6320static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6321 int tid)
6322{
6323 char buf[100];
6324 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6325
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306326 if (tid < 0 ||
6327 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6328 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6329 return;
6330 }
6331
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006332 /*
6333 * Two ways to ensure that addba request with a
6334 * non zero TID could be sent out. EV 117296
6335 */
6336 snprintf(buf, sizeof(buf),
6337 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6338 tid);
6339 if (system(buf) != 0) {
6340 sigma_dut_print(dut, DUT_MSG_ERROR,
6341 "Ping did not send out");
6342 }
6343
6344 snprintf(buf, sizeof(buf),
6345 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6346 intf, VI_QOS_TMP_FILE);
6347 if (system(buf) != 0)
6348 return;
6349
6350 snprintf(buf, sizeof(buf),
6351 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6352 intf, VI_QOS_TMP_FILE);
6353 if (system(buf) != 0)
6354 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6355
6356 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6357 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6358 if (system(buf) != 0) {
6359 sigma_dut_print(dut, DUT_MSG_ERROR,
6360 "VI_QOS_TEMP_FILE generation error failed");
6361 }
6362 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6363 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6364 if (system(buf) != 0) {
6365 sigma_dut_print(dut, DUT_MSG_ERROR,
6366 "VI_QOS_FILE generation failed");
6367 }
6368
6369 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6370 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6371 if (system(buf) != 0) {
6372 sigma_dut_print(dut, DUT_MSG_ERROR,
6373 "VI_QOS_FILE generation failed");
6374 }
6375
6376 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6377 if (system(buf) != 0) {
6378 }
6379}
6380
6381
6382static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6383 struct sigma_cmd *cmd)
6384{
6385 const char *intf = get_param(cmd, "Interface");
6386 const char *val;
6387 int tid = 0;
6388 char buf[100];
6389
6390 val = get_param(cmd, "TID");
6391 if (val) {
6392 tid = atoi(val);
6393 if (tid)
6394 ath_sta_inject_frame(dut, intf, tid);
6395 }
6396
6397 /* Command sequence for ADDBA request on Peregrine based devices */
6398 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6399 if (system(buf) != 0) {
6400 sigma_dut_print(dut, DUT_MSG_ERROR,
6401 "iwpriv setaddbaoper failed");
6402 }
6403
6404 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6405 if (system(buf) != 0) {
6406 sigma_dut_print(dut, DUT_MSG_ERROR,
6407 "wifitool senddelba failed");
6408 }
6409
6410 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6411 if (system(buf) != 0) {
6412 sigma_dut_print(dut, DUT_MSG_ERROR,
6413 "wifitool sendaddba failed");
6414 }
6415
6416 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6417
6418 return 1;
6419}
6420
6421
Lior David9981b512017-01-20 13:16:40 +02006422#ifdef __linux__
6423
6424static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6425 int agg_size)
6426{
6427 char dir[128], buf[128];
6428 FILE *f;
6429 regex_t re;
6430 regmatch_t m[2];
6431 int rc, ret = -1, vring_id, found;
6432
6433 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6434 sigma_dut_print(dut, DUT_MSG_ERROR,
6435 "failed to get wil6210 debugfs dir");
6436 return -1;
6437 }
6438
6439 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6440 f = fopen(buf, "r");
6441 if (!f) {
6442 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6443 return -1;
6444 }
6445
6446 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6447 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6448 goto out;
6449 }
6450
6451 /* find TX VRING for the mac address */
6452 found = 0;
6453 while (fgets(buf, sizeof(buf), f)) {
6454 if (strcasestr(buf, dest_mac)) {
6455 found = 1;
6456 break;
6457 }
6458 }
6459
6460 if (!found) {
6461 sigma_dut_print(dut, DUT_MSG_ERROR,
6462 "no TX VRING for %s", dest_mac);
6463 goto out;
6464 }
6465
6466 /* extract VRING ID, "VRING tx_<id> = {" */
6467 if (!fgets(buf, sizeof(buf), f)) {
6468 sigma_dut_print(dut, DUT_MSG_ERROR,
6469 "no VRING start line for %s", dest_mac);
6470 goto out;
6471 }
6472
6473 rc = regexec(&re, buf, 2, m, 0);
6474 regfree(&re);
6475 if (rc || m[1].rm_so < 0) {
6476 sigma_dut_print(dut, DUT_MSG_ERROR,
6477 "no VRING TX ID for %s", dest_mac);
6478 goto out;
6479 }
6480 buf[m[1].rm_eo] = 0;
6481 vring_id = atoi(&buf[m[1].rm_so]);
6482
6483 /* send the addba command */
6484 fclose(f);
6485 snprintf(buf, sizeof(buf), "%s/back", dir);
6486 f = fopen(buf, "w");
6487 if (!f) {
6488 sigma_dut_print(dut, DUT_MSG_ERROR,
6489 "failed to open: %s", buf);
6490 return -1;
6491 }
6492
6493 fprintf(f, "add %d %d\n", vring_id, agg_size);
6494
6495 ret = 0;
6496
6497out:
6498 fclose(f);
6499
6500 return ret;
6501}
6502
6503
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6505 struct sigma_cmd *cmd)
6506{
6507 const char *val;
6508 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006509
6510 val = get_param(cmd, "TID");
6511 if (val) {
6512 tid = atoi(val);
6513 if (tid != 0) {
6514 sigma_dut_print(dut, DUT_MSG_ERROR,
6515 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6516 tid);
6517 }
6518 }
6519
6520 val = get_param(cmd, "Dest_mac");
6521 if (!val) {
6522 sigma_dut_print(dut, DUT_MSG_ERROR,
6523 "Currently not supporting addba for 60G without Dest_mac");
6524 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6525 }
6526
Lior David9981b512017-01-20 13:16:40 +02006527 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006528 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006529
6530 return 1;
6531}
6532
Lior David9981b512017-01-20 13:16:40 +02006533#endif /* __linux__ */
6534
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006535
6536static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6537 struct sigma_cmd *cmd)
6538{
6539 switch (get_driver_type()) {
6540 case DRIVER_ATHEROS:
6541 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006542#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006543 case DRIVER_WIL6210:
6544 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006545#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546 default:
6547 /*
6548 * There is no driver specific implementation for other drivers.
6549 * Ignore the command and report COMPLETE since the following
6550 * throughput test operation will end up sending ADDBA anyway.
6551 */
6552 return 1;
6553 }
6554}
6555
6556
6557int inject_eth_frame(int s, const void *data, size_t len,
6558 unsigned short ethtype, char *dst, char *src)
6559{
6560 struct iovec iov[4] = {
6561 {
6562 .iov_base = dst,
6563 .iov_len = ETH_ALEN,
6564 },
6565 {
6566 .iov_base = src,
6567 .iov_len = ETH_ALEN,
6568 },
6569 {
6570 .iov_base = &ethtype,
6571 .iov_len = sizeof(unsigned short),
6572 },
6573 {
6574 .iov_base = (void *) data,
6575 .iov_len = len,
6576 }
6577 };
6578 struct msghdr msg = {
6579 .msg_name = NULL,
6580 .msg_namelen = 0,
6581 .msg_iov = iov,
6582 .msg_iovlen = 4,
6583 .msg_control = NULL,
6584 .msg_controllen = 0,
6585 .msg_flags = 0,
6586 };
6587
6588 return sendmsg(s, &msg, 0);
6589}
6590
6591#if defined(__linux__) || defined(__QNXNTO__)
6592
6593int inject_frame(int s, const void *data, size_t len, int encrypt)
6594{
6595#define IEEE80211_RADIOTAP_F_WEP 0x04
6596#define IEEE80211_RADIOTAP_F_FRAG 0x08
6597 unsigned char rtap_hdr[] = {
6598 0x00, 0x00, /* radiotap version */
6599 0x0e, 0x00, /* radiotap length */
6600 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6601 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
6602 0x00, /* padding */
6603 0x00, 0x00, /* RX and TX flags to indicate that */
6604 0x00, 0x00, /* this is the injected frame directly */
6605 };
6606 struct iovec iov[2] = {
6607 {
6608 .iov_base = &rtap_hdr,
6609 .iov_len = sizeof(rtap_hdr),
6610 },
6611 {
6612 .iov_base = (void *) data,
6613 .iov_len = len,
6614 }
6615 };
6616 struct msghdr msg = {
6617 .msg_name = NULL,
6618 .msg_namelen = 0,
6619 .msg_iov = iov,
6620 .msg_iovlen = 2,
6621 .msg_control = NULL,
6622 .msg_controllen = 0,
6623 .msg_flags = 0,
6624 };
6625
6626 if (encrypt)
6627 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
6628
6629 return sendmsg(s, &msg, 0);
6630}
6631
6632
6633int open_monitor(const char *ifname)
6634{
6635#ifdef __QNXNTO__
6636 struct sockaddr_dl ll;
6637 int s;
6638
6639 memset(&ll, 0, sizeof(ll));
6640 ll.sdl_family = AF_LINK;
6641 ll.sdl_index = if_nametoindex(ifname);
6642 if (ll.sdl_index == 0) {
6643 perror("if_nametoindex");
6644 return -1;
6645 }
6646 s = socket(PF_INET, SOCK_RAW, 0);
6647#else /* __QNXNTO__ */
6648 struct sockaddr_ll ll;
6649 int s;
6650
6651 memset(&ll, 0, sizeof(ll));
6652 ll.sll_family = AF_PACKET;
6653 ll.sll_ifindex = if_nametoindex(ifname);
6654 if (ll.sll_ifindex == 0) {
6655 perror("if_nametoindex");
6656 return -1;
6657 }
6658 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
6659#endif /* __QNXNTO__ */
6660 if (s < 0) {
6661 perror("socket[PF_PACKET,SOCK_RAW]");
6662 return -1;
6663 }
6664
6665 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
6666 perror("monitor socket bind");
6667 close(s);
6668 return -1;
6669 }
6670
6671 return s;
6672}
6673
6674
6675static int hex2num(char c)
6676{
6677 if (c >= '0' && c <= '9')
6678 return c - '0';
6679 if (c >= 'a' && c <= 'f')
6680 return c - 'a' + 10;
6681 if (c >= 'A' && c <= 'F')
6682 return c - 'A' + 10;
6683 return -1;
6684}
6685
6686
6687int hwaddr_aton(const char *txt, unsigned char *addr)
6688{
6689 int i;
6690
6691 for (i = 0; i < 6; i++) {
6692 int a, b;
6693
6694 a = hex2num(*txt++);
6695 if (a < 0)
6696 return -1;
6697 b = hex2num(*txt++);
6698 if (b < 0)
6699 return -1;
6700 *addr++ = (a << 4) | b;
6701 if (i < 5 && *txt++ != ':')
6702 return -1;
6703 }
6704
6705 return 0;
6706}
6707
6708#endif /* defined(__linux__) || defined(__QNXNTO__) */
6709
6710enum send_frame_type {
6711 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
6712};
6713enum send_frame_protection {
6714 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6715};
6716
6717
6718static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6719 enum send_frame_type frame,
6720 enum send_frame_protection protected,
6721 const char *dest)
6722{
6723#ifdef __linux__
6724 unsigned char buf[1000], *pos;
6725 int s, res;
6726 char bssid[20], addr[20];
6727 char result[32], ssid[100];
6728 size_t ssid_len;
6729
6730 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6731 sizeof(result)) < 0 ||
6732 strncmp(result, "COMPLETED", 9) != 0) {
6733 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
6734 return 0;
6735 }
6736
6737 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
6738 < 0) {
6739 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6740 "current BSSID");
6741 return 0;
6742 }
6743
6744 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
6745 < 0) {
6746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6747 "own MAC address");
6748 return 0;
6749 }
6750
6751 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
6752 < 0) {
6753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6754 "current SSID");
6755 return 0;
6756 }
6757 ssid_len = strlen(ssid);
6758
6759 pos = buf;
6760
6761 /* Frame Control */
6762 switch (frame) {
6763 case DISASSOC:
6764 *pos++ = 0xa0;
6765 break;
6766 case DEAUTH:
6767 *pos++ = 0xc0;
6768 break;
6769 case SAQUERY:
6770 *pos++ = 0xd0;
6771 break;
6772 case AUTH:
6773 *pos++ = 0xb0;
6774 break;
6775 case ASSOCREQ:
6776 *pos++ = 0x00;
6777 break;
6778 case REASSOCREQ:
6779 *pos++ = 0x20;
6780 break;
6781 case DLS_REQ:
6782 *pos++ = 0xd0;
6783 break;
6784 }
6785
6786 if (protected == INCORRECT_KEY)
6787 *pos++ = 0x40; /* Set Protected field to 1 */
6788 else
6789 *pos++ = 0x00;
6790
6791 /* Duration */
6792 *pos++ = 0x00;
6793 *pos++ = 0x00;
6794
6795 /* addr1 = DA (current AP) */
6796 hwaddr_aton(bssid, pos);
6797 pos += 6;
6798 /* addr2 = SA (own address) */
6799 hwaddr_aton(addr, pos);
6800 pos += 6;
6801 /* addr3 = BSSID (current AP) */
6802 hwaddr_aton(bssid, pos);
6803 pos += 6;
6804
6805 /* Seq# (to be filled by driver/mac80211) */
6806 *pos++ = 0x00;
6807 *pos++ = 0x00;
6808
6809 if (protected == INCORRECT_KEY) {
6810 /* CCMP parameters */
6811 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6812 pos += 8;
6813 }
6814
6815 if (protected == INCORRECT_KEY) {
6816 switch (frame) {
6817 case DEAUTH:
6818 /* Reason code (encrypted) */
6819 memcpy(pos, "\xa7\x39", 2);
6820 pos += 2;
6821 break;
6822 case DISASSOC:
6823 /* Reason code (encrypted) */
6824 memcpy(pos, "\xa7\x39", 2);
6825 pos += 2;
6826 break;
6827 case SAQUERY:
6828 /* Category|Action|TransID (encrypted) */
6829 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6830 pos += 4;
6831 break;
6832 default:
6833 return -1;
6834 }
6835
6836 /* CCMP MIC */
6837 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6838 pos += 8;
6839 } else {
6840 switch (frame) {
6841 case DEAUTH:
6842 /* reason code = 8 */
6843 *pos++ = 0x08;
6844 *pos++ = 0x00;
6845 break;
6846 case DISASSOC:
6847 /* reason code = 8 */
6848 *pos++ = 0x08;
6849 *pos++ = 0x00;
6850 break;
6851 case SAQUERY:
6852 /* Category - SA Query */
6853 *pos++ = 0x08;
6854 /* SA query Action - Request */
6855 *pos++ = 0x00;
6856 /* Transaction ID */
6857 *pos++ = 0x12;
6858 *pos++ = 0x34;
6859 break;
6860 case AUTH:
6861 /* Auth Alg (Open) */
6862 *pos++ = 0x00;
6863 *pos++ = 0x00;
6864 /* Seq# */
6865 *pos++ = 0x01;
6866 *pos++ = 0x00;
6867 /* Status code */
6868 *pos++ = 0x00;
6869 *pos++ = 0x00;
6870 break;
6871 case ASSOCREQ:
6872 /* Capability Information */
6873 *pos++ = 0x31;
6874 *pos++ = 0x04;
6875 /* Listen Interval */
6876 *pos++ = 0x0a;
6877 *pos++ = 0x00;
6878 /* SSID */
6879 *pos++ = 0x00;
6880 *pos++ = ssid_len;
6881 memcpy(pos, ssid, ssid_len);
6882 pos += ssid_len;
6883 /* Supported Rates */
6884 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6885 10);
6886 pos += 10;
6887 /* Extended Supported Rates */
6888 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6889 pos += 6;
6890 /* RSN */
6891 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6892 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6893 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6894 pos += 28;
6895 break;
6896 case REASSOCREQ:
6897 /* Capability Information */
6898 *pos++ = 0x31;
6899 *pos++ = 0x04;
6900 /* Listen Interval */
6901 *pos++ = 0x0a;
6902 *pos++ = 0x00;
6903 /* Current AP */
6904 hwaddr_aton(bssid, pos);
6905 pos += 6;
6906 /* SSID */
6907 *pos++ = 0x00;
6908 *pos++ = ssid_len;
6909 memcpy(pos, ssid, ssid_len);
6910 pos += ssid_len;
6911 /* Supported Rates */
6912 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6913 10);
6914 pos += 10;
6915 /* Extended Supported Rates */
6916 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6917 pos += 6;
6918 /* RSN */
6919 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6920 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6921 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6922 pos += 28;
6923 break;
6924 case DLS_REQ:
6925 /* Category - DLS */
6926 *pos++ = 0x02;
6927 /* DLS Action - Request */
6928 *pos++ = 0x00;
6929 /* Destination MACAddress */
6930 if (dest)
6931 hwaddr_aton(dest, pos);
6932 else
6933 memset(pos, 0, 6);
6934 pos += 6;
6935 /* Source MACAddress */
6936 hwaddr_aton(addr, pos);
6937 pos += 6;
6938 /* Capability Information */
6939 *pos++ = 0x10; /* Privacy */
6940 *pos++ = 0x06; /* QoS */
6941 /* DLS Timeout Value */
6942 *pos++ = 0x00;
6943 *pos++ = 0x01;
6944 /* Supported rates */
6945 *pos++ = 0x01;
6946 *pos++ = 0x08;
6947 *pos++ = 0x0c; /* 6 Mbps */
6948 *pos++ = 0x12; /* 9 Mbps */
6949 *pos++ = 0x18; /* 12 Mbps */
6950 *pos++ = 0x24; /* 18 Mbps */
6951 *pos++ = 0x30; /* 24 Mbps */
6952 *pos++ = 0x48; /* 36 Mbps */
6953 *pos++ = 0x60; /* 48 Mbps */
6954 *pos++ = 0x6c; /* 54 Mbps */
6955 /* TODO: Extended Supported Rates */
6956 /* TODO: HT Capabilities */
6957 break;
6958 }
6959 }
6960
6961 s = open_monitor("sigmadut");
6962 if (s < 0) {
6963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6964 "monitor socket");
6965 return 0;
6966 }
6967
6968 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
6969 if (res < 0) {
6970 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6971 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306972 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006973 return 0;
6974 }
6975 if (res < pos - buf) {
6976 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
6977 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306978 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006979 return 0;
6980 }
6981
6982 close(s);
6983
6984 return 1;
6985#else /* __linux__ */
6986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
6987 "yet supported");
6988 return 0;
6989#endif /* __linux__ */
6990}
6991
6992
6993static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
6994 struct sigma_conn *conn,
6995 struct sigma_cmd *cmd)
6996{
6997 const char *intf = get_param(cmd, "Interface");
6998 const char *sta, *val;
6999 unsigned char addr[ETH_ALEN];
7000 char buf[100];
7001
7002 sta = get_param(cmd, "peer");
7003 if (sta == NULL)
7004 sta = get_param(cmd, "station");
7005 if (sta == NULL) {
7006 send_resp(dut, conn, SIGMA_ERROR,
7007 "ErrorCode,Missing peer address");
7008 return 0;
7009 }
7010 if (hwaddr_aton(sta, addr) < 0) {
7011 send_resp(dut, conn, SIGMA_ERROR,
7012 "ErrorCode,Invalid peer address");
7013 return 0;
7014 }
7015
7016 val = get_param(cmd, "type");
7017 if (val == NULL)
7018 return -1;
7019
7020 if (strcasecmp(val, "DISCOVERY") == 0) {
7021 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
7022 if (wpa_command(intf, buf) < 0) {
7023 send_resp(dut, conn, SIGMA_ERROR,
7024 "ErrorCode,Failed to send TDLS discovery");
7025 return 0;
7026 }
7027 return 1;
7028 }
7029
7030 if (strcasecmp(val, "SETUP") == 0) {
7031 int status = 0, timeout = 0;
7032
7033 val = get_param(cmd, "Status");
7034 if (val)
7035 status = atoi(val);
7036
7037 val = get_param(cmd, "Timeout");
7038 if (val)
7039 timeout = atoi(val);
7040
7041 if (status != 0 && status != 37) {
7042 send_resp(dut, conn, SIGMA_ERROR,
7043 "ErrorCode,Unsupported status value");
7044 return 0;
7045 }
7046
7047 if (timeout != 0 && timeout != 301) {
7048 send_resp(dut, conn, SIGMA_ERROR,
7049 "ErrorCode,Unsupported timeout value");
7050 return 0;
7051 }
7052
7053 if (status && timeout) {
7054 send_resp(dut, conn, SIGMA_ERROR,
7055 "ErrorCode,Unsupported timeout+status "
7056 "combination");
7057 return 0;
7058 }
7059
7060 if (status == 37 &&
7061 wpa_command(intf, "SET tdls_testing 0x200")) {
7062 send_resp(dut, conn, SIGMA_ERROR,
7063 "ErrorCode,Failed to enable "
7064 "decline setup response test mode");
7065 return 0;
7066 }
7067
7068 if (timeout == 301) {
7069 int res;
7070 if (dut->no_tpk_expiration)
7071 res = wpa_command(intf,
7072 "SET tdls_testing 0x108");
7073 else
7074 res = wpa_command(intf,
7075 "SET tdls_testing 0x8");
7076 if (res) {
7077 send_resp(dut, conn, SIGMA_ERROR,
7078 "ErrorCode,Failed to set short TPK "
7079 "lifetime");
7080 return 0;
7081 }
7082 }
7083
7084 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
7085 if (wpa_command(intf, buf) < 0) {
7086 send_resp(dut, conn, SIGMA_ERROR,
7087 "ErrorCode,Failed to send TDLS setup");
7088 return 0;
7089 }
7090 return 1;
7091 }
7092
7093 if (strcasecmp(val, "TEARDOWN") == 0) {
7094 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
7095 if (wpa_command(intf, buf) < 0) {
7096 send_resp(dut, conn, SIGMA_ERROR,
7097 "ErrorCode,Failed to send TDLS teardown");
7098 return 0;
7099 }
7100 return 1;
7101 }
7102
7103 send_resp(dut, conn, SIGMA_ERROR,
7104 "ErrorCode,Unsupported TDLS frame");
7105 return 0;
7106}
7107
7108
7109static int sta_ap_known(const char *ifname, const char *bssid)
7110{
7111 char buf[4096];
7112
7113 snprintf(buf, sizeof(buf), "BSS %s", bssid);
7114 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
7115 return 0;
7116 if (strncmp(buf, "id=", 3) != 0)
7117 return 0;
7118 return 1;
7119}
7120
7121
7122static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
7123 const char *bssid)
7124{
7125 int res;
7126 struct wpa_ctrl *ctrl;
7127 char buf[256];
7128
7129 if (sta_ap_known(ifname, bssid))
7130 return 0;
7131 sigma_dut_print(dut, DUT_MSG_DEBUG,
7132 "AP not in BSS table - start scan");
7133
7134 ctrl = open_wpa_mon(ifname);
7135 if (ctrl == NULL) {
7136 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7137 "wpa_supplicant monitor connection");
7138 return -1;
7139 }
7140
7141 if (wpa_command(ifname, "SCAN") < 0) {
7142 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
7143 wpa_ctrl_detach(ctrl);
7144 wpa_ctrl_close(ctrl);
7145 return -1;
7146 }
7147
7148 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7149 buf, sizeof(buf));
7150
7151 wpa_ctrl_detach(ctrl);
7152 wpa_ctrl_close(ctrl);
7153
7154 if (res < 0) {
7155 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
7156 return -1;
7157 }
7158
7159 if (sta_ap_known(ifname, bssid))
7160 return 0;
7161 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
7162 return -1;
7163}
7164
7165
7166static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
7167 struct sigma_conn *conn,
7168 struct sigma_cmd *cmd,
7169 const char *intf)
7170{
7171 char buf[200];
7172
7173 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
7174 if (system(buf) != 0) {
7175 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
7176 "ndsend");
7177 return 0;
7178 }
7179
7180 return 1;
7181}
7182
7183
7184static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
7185 struct sigma_conn *conn,
7186 struct sigma_cmd *cmd,
7187 const char *intf)
7188{
7189 char buf[200];
7190 const char *ip = get_param(cmd, "SenderIP");
7191
Peng Xu26b356d2017-10-04 17:58:16 -07007192 if (!ip)
7193 return 0;
7194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007195 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
7196 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7197 if (system(buf) == 0) {
7198 sigma_dut_print(dut, DUT_MSG_INFO,
7199 "Neighbor Solicitation got a response "
7200 "for %s@%s", ip, intf);
7201 }
7202
7203 return 1;
7204}
7205
7206
7207static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
7208 struct sigma_conn *conn,
7209 struct sigma_cmd *cmd,
7210 const char *ifname)
7211{
7212 char buf[200];
7213 const char *ip = get_param(cmd, "SenderIP");
7214
7215 if (ip == NULL) {
7216 send_resp(dut, conn, SIGMA_ERROR,
7217 "ErrorCode,Missing SenderIP parameter");
7218 return 0;
7219 }
7220 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
7221 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7222 if (system(buf) != 0) {
7223 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
7224 "for %s@%s", ip, ifname);
7225 }
7226
7227 return 1;
7228}
7229
7230
7231static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
7232 struct sigma_conn *conn,
7233 struct sigma_cmd *cmd,
7234 const char *ifname)
7235{
7236 char buf[200];
7237 char ip[16];
7238 int s;
Peng Xub3756882017-10-04 14:39:09 -07007239 struct ifreq ifr;
7240 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007241
7242 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07007243 if (s < 0) {
7244 perror("socket");
7245 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007246 }
7247
Peng Xub3756882017-10-04 14:39:09 -07007248 memset(&ifr, 0, sizeof(ifr));
7249 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7250 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
7251 sigma_dut_print(dut, DUT_MSG_INFO,
7252 "Failed to get %s IP address: %s",
7253 ifname, strerror(errno));
7254 close(s);
7255 return -1;
7256 }
7257 close(s);
7258
7259 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
7260 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
7261
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007262 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
7263 ip);
7264 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7265 if (system(buf) != 0) {
7266 }
7267
7268 return 1;
7269}
7270
7271
7272static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
7273 struct sigma_conn *conn,
7274 struct sigma_cmd *cmd,
7275 const char *ifname)
7276{
7277 char buf[200], addr[20];
7278 char dst[ETH_ALEN], src[ETH_ALEN];
7279 short ethtype = htons(ETH_P_ARP);
7280 char *pos;
7281 int s, res;
7282 const char *val;
7283 struct sockaddr_in taddr;
7284
7285 val = get_param(cmd, "dest");
7286 if (val)
7287 hwaddr_aton(val, (unsigned char *) dst);
7288
7289 val = get_param(cmd, "DestIP");
7290 if (val)
7291 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007292 else
7293 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007294
7295 if (get_wpa_status(get_station_ifname(), "address", addr,
7296 sizeof(addr)) < 0)
7297 return -2;
7298 hwaddr_aton(addr, (unsigned char *) src);
7299
7300 pos = buf;
7301 *pos++ = 0x00;
7302 *pos++ = 0x01;
7303 *pos++ = 0x08;
7304 *pos++ = 0x00;
7305 *pos++ = 0x06;
7306 *pos++ = 0x04;
7307 *pos++ = 0x00;
7308 *pos++ = 0x02;
7309 memcpy(pos, src, ETH_ALEN);
7310 pos += ETH_ALEN;
7311 memcpy(pos, &taddr.sin_addr, 4);
7312 pos += 4;
7313 memcpy(pos, dst, ETH_ALEN);
7314 pos += ETH_ALEN;
7315 memcpy(pos, &taddr.sin_addr, 4);
7316 pos += 4;
7317
7318 s = open_monitor(get_station_ifname());
7319 if (s < 0) {
7320 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7321 "monitor socket");
7322 return 0;
7323 }
7324
7325 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7326 if (res < 0) {
7327 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7328 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307329 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007330 return 0;
7331 }
7332
7333 close(s);
7334
7335 return 1;
7336}
7337
7338
7339static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7340 struct sigma_conn *conn,
7341 struct sigma_cmd *cmd,
7342 const char *intf, const char *dest)
7343{
7344 char buf[100];
7345
7346 if (if_nametoindex("sigmadut") == 0) {
7347 snprintf(buf, sizeof(buf),
7348 "iw dev %s interface add sigmadut type monitor",
7349 get_station_ifname());
7350 if (system(buf) != 0 ||
7351 if_nametoindex("sigmadut") == 0) {
7352 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7353 "monitor interface with '%s'", buf);
7354 return -2;
7355 }
7356 }
7357
7358 if (system("ifconfig sigmadut up") != 0) {
7359 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7360 "monitor interface up");
7361 return -2;
7362 }
7363
7364 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7365}
7366
7367
7368static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7369 struct sigma_conn *conn,
7370 struct sigma_cmd *cmd)
7371{
7372 const char *intf = get_param(cmd, "Interface");
7373 const char *dest = get_param(cmd, "Dest");
7374 const char *type = get_param(cmd, "FrameName");
7375 const char *val;
7376 char buf[200], *pos, *end;
7377 int count, count2;
7378
7379 if (type == NULL)
7380 type = get_param(cmd, "Type");
7381
7382 if (intf == NULL || dest == NULL || type == NULL)
7383 return -1;
7384
7385 if (strcasecmp(type, "NeighAdv") == 0)
7386 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7387
7388 if (strcasecmp(type, "NeighSolicitReq") == 0)
7389 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7390
7391 if (strcasecmp(type, "ARPProbe") == 0)
7392 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7393
7394 if (strcasecmp(type, "ARPAnnounce") == 0)
7395 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7396
7397 if (strcasecmp(type, "ARPReply") == 0)
7398 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7399
7400 if (strcasecmp(type, "DLS-request") == 0 ||
7401 strcasecmp(type, "DLSrequest") == 0)
7402 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7403 dest);
7404
7405 if (strcasecmp(type, "ANQPQuery") != 0 &&
7406 strcasecmp(type, "Query") != 0) {
7407 send_resp(dut, conn, SIGMA_ERROR,
7408 "ErrorCode,Unsupported HS 2.0 send frame type");
7409 return 0;
7410 }
7411
7412 if (sta_scan_ap(dut, intf, dest) < 0) {
7413 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7414 "the requested AP");
7415 return 0;
7416 }
7417
7418 pos = buf;
7419 end = buf + sizeof(buf);
7420 count = 0;
7421 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7422
7423 val = get_param(cmd, "ANQP_CAP_LIST");
7424 if (val && atoi(val)) {
7425 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7426 count++;
7427 }
7428
7429 val = get_param(cmd, "VENUE_NAME");
7430 if (val && atoi(val)) {
7431 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7432 count++;
7433 }
7434
7435 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7436 if (val && atoi(val)) {
7437 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7438 count++;
7439 }
7440
7441 val = get_param(cmd, "ROAMING_CONS");
7442 if (val && atoi(val)) {
7443 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7444 count++;
7445 }
7446
7447 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7448 if (val && atoi(val)) {
7449 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7450 count++;
7451 }
7452
7453 val = get_param(cmd, "NAI_REALM_LIST");
7454 if (val && atoi(val)) {
7455 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7456 count++;
7457 }
7458
7459 val = get_param(cmd, "3GPP_INFO");
7460 if (val && atoi(val)) {
7461 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7462 count++;
7463 }
7464
7465 val = get_param(cmd, "DOMAIN_LIST");
7466 if (val && atoi(val)) {
7467 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7468 count++;
7469 }
7470
7471 if (count && wpa_command(intf, buf)) {
7472 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7473 return 0;
7474 }
7475
7476 pos = buf;
7477 end = buf + sizeof(buf);
7478 count2 = 0;
7479 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7480
7481 val = get_param(cmd, "HS_CAP_LIST");
7482 if (val && atoi(val)) {
7483 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7484 count2++;
7485 }
7486
7487 val = get_param(cmd, "OPER_NAME");
7488 if (val && atoi(val)) {
7489 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7490 count2++;
7491 }
7492
7493 val = get_param(cmd, "WAN_METRICS");
7494 if (!val)
7495 val = get_param(cmd, "WAN_MAT");
7496 if (!val)
7497 val = get_param(cmd, "WAN_MET");
7498 if (val && atoi(val)) {
7499 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7500 count2++;
7501 }
7502
7503 val = get_param(cmd, "CONNECTION_CAPABILITY");
7504 if (val && atoi(val)) {
7505 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7506 count2++;
7507 }
7508
7509 val = get_param(cmd, "OP_CLASS");
7510 if (val && atoi(val)) {
7511 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7512 count2++;
7513 }
7514
7515 val = get_param(cmd, "OSU_PROVIDER_LIST");
7516 if (val && atoi(val)) {
7517 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7518 count2++;
7519 }
7520
7521 if (count && count2) {
7522 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7523 "second query");
7524 sleep(1);
7525 }
7526
7527 if (count2 && wpa_command(intf, buf)) {
7528 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7529 "failed");
7530 return 0;
7531 }
7532
7533 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7534 if (val) {
7535 if (count || count2) {
7536 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7537 "sending out second query");
7538 sleep(1);
7539 }
7540
7541 if (strcmp(val, "1") == 0)
7542 val = "mail.example.com";
7543 snprintf(buf, end - pos,
7544 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7545 dest, val);
7546 if (wpa_command(intf, buf)) {
7547 send_resp(dut, conn, SIGMA_ERROR,
7548 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7549 "failed");
7550 return 0;
7551 }
7552 }
7553
7554 val = get_param(cmd, "ICON_REQUEST");
7555 if (val) {
7556 if (count || count2) {
7557 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7558 "sending out second query");
7559 sleep(1);
7560 }
7561
7562 snprintf(buf, end - pos,
7563 "HS20_ICON_REQUEST %s %s", dest, val);
7564 if (wpa_command(intf, buf)) {
7565 send_resp(dut, conn, SIGMA_ERROR,
7566 "ErrorCode,HS20_ICON_REQUEST failed");
7567 return 0;
7568 }
7569 }
7570
7571 return 1;
7572}
7573
7574
7575static int ath_sta_send_frame_vht(struct sigma_dut *dut,
7576 struct sigma_conn *conn,
7577 struct sigma_cmd *cmd)
7578{
7579 const char *val;
7580 char *ifname;
7581 char buf[100];
7582 int chwidth, nss;
7583
7584 val = get_param(cmd, "framename");
7585 if (!val)
7586 return -1;
7587 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
7588
7589 /* Command sequence to generate Op mode notification */
7590 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
7591 ifname = get_station_ifname();
7592
7593 /* Disable STBC */
7594 snprintf(buf, sizeof(buf),
7595 "iwpriv %s tx_stbc 0", ifname);
7596 if (system(buf) != 0) {
7597 sigma_dut_print(dut, DUT_MSG_ERROR,
7598 "iwpriv tx_stbc 0 failed!");
7599 }
7600
7601 /* Extract Channel width */
7602 val = get_param(cmd, "Channel_width");
7603 if (val) {
7604 switch (atoi(val)) {
7605 case 20:
7606 chwidth = 0;
7607 break;
7608 case 40:
7609 chwidth = 1;
7610 break;
7611 case 80:
7612 chwidth = 2;
7613 break;
7614 case 160:
7615 chwidth = 3;
7616 break;
7617 default:
7618 chwidth = 2;
7619 break;
7620 }
7621
7622 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7623 ifname, chwidth);
7624 if (system(buf) != 0) {
7625 sigma_dut_print(dut, DUT_MSG_ERROR,
7626 "iwpriv chwidth failed!");
7627 }
7628 }
7629
7630 /* Extract NSS */
7631 val = get_param(cmd, "NSS");
7632 if (val) {
7633 switch (atoi(val)) {
7634 case 1:
7635 nss = 1;
7636 break;
7637 case 2:
7638 nss = 3;
7639 break;
7640 case 3:
7641 nss = 7;
7642 break;
7643 default:
7644 /* We do not support NSS > 3 */
7645 nss = 3;
7646 break;
7647 }
7648 snprintf(buf, sizeof(buf),
7649 "iwpriv %s rxchainmask %d", ifname, nss);
7650 if (system(buf) != 0) {
7651 sigma_dut_print(dut, DUT_MSG_ERROR,
7652 "iwpriv rxchainmask failed!");
7653 }
7654 }
7655
7656 /* Opmode notify */
7657 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
7658 if (system(buf) != 0) {
7659 sigma_dut_print(dut, DUT_MSG_ERROR,
7660 "iwpriv opmode_notify failed!");
7661 } else {
7662 sigma_dut_print(dut, DUT_MSG_INFO,
7663 "Sent out the notify frame!");
7664 }
7665 }
7666
7667 return 1;
7668}
7669
7670
7671static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
7672 struct sigma_conn *conn,
7673 struct sigma_cmd *cmd)
7674{
7675 switch (get_driver_type()) {
7676 case DRIVER_ATHEROS:
7677 return ath_sta_send_frame_vht(dut, conn, cmd);
7678 default:
7679 send_resp(dut, conn, SIGMA_ERROR,
7680 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
7681 return 0;
7682 }
7683}
7684
7685
Lior David0fe101e2017-03-09 16:09:50 +02007686#ifdef __linux__
7687int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7688 struct sigma_cmd *cmd)
7689{
7690 const char *frame_name = get_param(cmd, "framename");
7691 const char *mac = get_param(cmd, "dest_mac");
7692
7693 if (!frame_name || !mac) {
7694 sigma_dut_print(dut, DUT_MSG_ERROR,
7695 "framename and dest_mac must be provided");
7696 return -1;
7697 }
7698
7699 if (strcasecmp(frame_name, "brp") == 0) {
7700 const char *l_rx = get_param(cmd, "L-RX");
7701 int l_rx_i;
7702
7703 if (!l_rx) {
7704 sigma_dut_print(dut, DUT_MSG_ERROR,
7705 "L-RX must be provided");
7706 return -1;
7707 }
7708 l_rx_i = atoi(l_rx);
7709
7710 sigma_dut_print(dut, DUT_MSG_INFO,
7711 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
7712 mac, l_rx);
7713 if (l_rx_i != 16) {
7714 sigma_dut_print(dut, DUT_MSG_ERROR,
7715 "unsupported L-RX: %s", l_rx);
7716 return -1;
7717 }
7718
7719 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
7720 return -1;
7721 } else if (strcasecmp(frame_name, "ssw") == 0) {
7722 sigma_dut_print(dut, DUT_MSG_INFO,
7723 "dev_send_frame: SLS, dest_mac %s", mac);
7724 if (wil6210_send_sls(dut, mac))
7725 return -1;
7726 } else {
7727 sigma_dut_print(dut, DUT_MSG_ERROR,
7728 "unsupported frame type: %s", frame_name);
7729 return -1;
7730 }
7731
7732 return 1;
7733}
7734#endif /* __linux__ */
7735
7736
7737static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
7738 struct sigma_conn *conn,
7739 struct sigma_cmd *cmd)
7740{
7741 switch (get_driver_type()) {
7742#ifdef __linux__
7743 case DRIVER_WIL6210:
7744 return wil6210_send_frame_60g(dut, conn, cmd);
7745#endif /* __linux__ */
7746 default:
7747 send_resp(dut, conn, SIGMA_ERROR,
7748 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7749 return 0;
7750 }
7751}
7752
7753
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307754static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
7755 const char *intf, struct sigma_cmd *cmd)
7756{
7757 const char *val, *addr;
7758 char buf[100];
7759
7760 addr = get_param(cmd, "DestMac");
7761 if (!addr) {
7762 send_resp(dut, conn, SIGMA_INVALID,
7763 "ErrorCode,AP MAC address is missing");
7764 return 0;
7765 }
7766
7767 val = get_param(cmd, "ANQPQuery_ID");
7768 if (!val) {
7769 send_resp(dut, conn, SIGMA_INVALID,
7770 "ErrorCode,Missing ANQPQuery_ID");
7771 return 0;
7772 }
7773
7774 if (strcasecmp(val, "NeighborReportReq") == 0) {
7775 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
7776 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
7777 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
7778 } else {
7779 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
7780 val);
7781 send_resp(dut, conn, SIGMA_INVALID,
7782 "ErrorCode,Invalid ANQPQuery_ID");
7783 return 0;
7784 }
7785
Ashwini Patild174f2c2017-04-13 16:49:46 +05307786 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
7787 * (Address3 = Wildcard BSSID when sent to not-associated AP;
7788 * if associated, AP BSSID).
7789 */
7790 if (wpa_command(intf, "SET gas_address3 1") < 0) {
7791 send_resp(dut, conn, SIGMA_ERROR,
7792 "ErrorCode,Failed to set gas_address3");
7793 return 0;
7794 }
7795
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307796 if (wpa_command(intf, buf) < 0) {
7797 send_resp(dut, conn, SIGMA_ERROR,
7798 "ErrorCode,Failed to send ANQP query");
7799 return 0;
7800 }
7801
7802 return 1;
7803}
7804
7805
7806static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
7807 struct sigma_conn *conn,
7808 const char *intf,
7809 struct sigma_cmd *cmd)
7810{
7811 const char *val = get_param(cmd, "FrameName");
7812
7813 if (val && strcasecmp(val, "ANQPQuery") == 0)
7814 return mbo_send_anqp_query(dut, conn, intf, cmd);
7815
7816 return 2;
7817}
7818
7819
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007820int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7821 struct sigma_cmd *cmd)
7822{
7823 const char *intf = get_param(cmd, "Interface");
7824 const char *val;
7825 enum send_frame_type frame;
7826 enum send_frame_protection protected;
7827 char buf[100];
7828 unsigned char addr[ETH_ALEN];
7829 int res;
7830
7831 val = get_param(cmd, "program");
7832 if (val == NULL)
7833 val = get_param(cmd, "frame");
7834 if (val && strcasecmp(val, "TDLS") == 0)
7835 return cmd_sta_send_frame_tdls(dut, conn, cmd);
7836 if (val && (strcasecmp(val, "HS2") == 0 ||
7837 strcasecmp(val, "HS2-R2") == 0))
7838 return cmd_sta_send_frame_hs2(dut, conn, cmd);
7839 if (val && strcasecmp(val, "VHT") == 0)
7840 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007841 if (val && strcasecmp(val, "LOC") == 0)
7842 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007843 if (val && strcasecmp(val, "60GHz") == 0)
7844 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307845 if (val && strcasecmp(val, "MBO") == 0) {
7846 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
7847 if (res != 2)
7848 return res;
7849 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007850
7851 val = get_param(cmd, "TD_DISC");
7852 if (val) {
7853 if (hwaddr_aton(val, addr) < 0)
7854 return -1;
7855 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
7856 if (wpa_command(intf, buf) < 0) {
7857 send_resp(dut, conn, SIGMA_ERROR,
7858 "ErrorCode,Failed to send TDLS discovery");
7859 return 0;
7860 }
7861 return 1;
7862 }
7863
7864 val = get_param(cmd, "TD_Setup");
7865 if (val) {
7866 if (hwaddr_aton(val, addr) < 0)
7867 return -1;
7868 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
7869 if (wpa_command(intf, buf) < 0) {
7870 send_resp(dut, conn, SIGMA_ERROR,
7871 "ErrorCode,Failed to start TDLS setup");
7872 return 0;
7873 }
7874 return 1;
7875 }
7876
7877 val = get_param(cmd, "TD_TearDown");
7878 if (val) {
7879 if (hwaddr_aton(val, addr) < 0)
7880 return -1;
7881 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
7882 if (wpa_command(intf, buf) < 0) {
7883 send_resp(dut, conn, SIGMA_ERROR,
7884 "ErrorCode,Failed to tear down TDLS link");
7885 return 0;
7886 }
7887 return 1;
7888 }
7889
7890 val = get_param(cmd, "TD_ChannelSwitch");
7891 if (val) {
7892 /* TODO */
7893 send_resp(dut, conn, SIGMA_ERROR,
7894 "ErrorCode,TD_ChannelSwitch not yet supported");
7895 return 0;
7896 }
7897
7898 val = get_param(cmd, "TD_NF");
7899 if (val) {
7900 /* TODO */
7901 send_resp(dut, conn, SIGMA_ERROR,
7902 "ErrorCode,TD_NF not yet supported");
7903 return 0;
7904 }
7905
7906 val = get_param(cmd, "PMFFrameType");
7907 if (val == NULL)
7908 val = get_param(cmd, "FrameName");
7909 if (val == NULL)
7910 val = get_param(cmd, "Type");
7911 if (val == NULL)
7912 return -1;
7913 if (strcasecmp(val, "disassoc") == 0)
7914 frame = DISASSOC;
7915 else if (strcasecmp(val, "deauth") == 0)
7916 frame = DEAUTH;
7917 else if (strcasecmp(val, "saquery") == 0)
7918 frame = SAQUERY;
7919 else if (strcasecmp(val, "auth") == 0)
7920 frame = AUTH;
7921 else if (strcasecmp(val, "assocreq") == 0)
7922 frame = ASSOCREQ;
7923 else if (strcasecmp(val, "reassocreq") == 0)
7924 frame = REASSOCREQ;
7925 else if (strcasecmp(val, "neigreq") == 0) {
7926 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
7927
7928 val = get_param(cmd, "ssid");
7929 if (val == NULL)
7930 return -1;
7931
7932 res = send_neighbor_request(dut, intf, val);
7933 if (res) {
7934 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7935 "Failed to send neighbor report request");
7936 return 0;
7937 }
7938
7939 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307940 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
7941 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007942 sigma_dut_print(dut, DUT_MSG_DEBUG,
7943 "Got Transition Management Query");
7944
Ashwini Patil5acd7382017-04-13 15:55:04 +05307945 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007946 if (res) {
7947 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7948 "Failed to send Transition Management Query");
7949 return 0;
7950 }
7951
7952 return 1;
7953 } else {
7954 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7955 "PMFFrameType");
7956 return 0;
7957 }
7958
7959 val = get_param(cmd, "PMFProtected");
7960 if (val == NULL)
7961 val = get_param(cmd, "Protected");
7962 if (val == NULL)
7963 return -1;
7964 if (strcasecmp(val, "Correct-key") == 0 ||
7965 strcasecmp(val, "CorrectKey") == 0)
7966 protected = CORRECT_KEY;
7967 else if (strcasecmp(val, "IncorrectKey") == 0)
7968 protected = INCORRECT_KEY;
7969 else if (strcasecmp(val, "Unprotected") == 0)
7970 protected = UNPROTECTED;
7971 else {
7972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7973 "PMFProtected");
7974 return 0;
7975 }
7976
7977 if (protected != UNPROTECTED &&
7978 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
7979 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
7980 "PMFProtected for auth/assocreq/reassocreq");
7981 return 0;
7982 }
7983
7984 if (if_nametoindex("sigmadut") == 0) {
7985 snprintf(buf, sizeof(buf),
7986 "iw dev %s interface add sigmadut type monitor",
7987 get_station_ifname());
7988 if (system(buf) != 0 ||
7989 if_nametoindex("sigmadut") == 0) {
7990 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7991 "monitor interface with '%s'", buf);
7992 return -2;
7993 }
7994 }
7995
7996 if (system("ifconfig sigmadut up") != 0) {
7997 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7998 "monitor interface up");
7999 return -2;
8000 }
8001
8002 return sta_inject_frame(dut, conn, frame, protected, NULL);
8003}
8004
8005
8006static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
8007 struct sigma_conn *conn,
8008 struct sigma_cmd *cmd,
8009 const char *ifname)
8010{
8011 char buf[200];
8012 const char *val;
8013
8014 val = get_param(cmd, "ClearARP");
8015 if (val && atoi(val) == 1) {
8016 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
8017 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8018 if (system(buf) != 0) {
8019 send_resp(dut, conn, SIGMA_ERROR,
8020 "errorCode,Failed to clear ARP cache");
8021 return 0;
8022 }
8023 }
8024
8025 return 1;
8026}
8027
8028
8029int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
8030 struct sigma_cmd *cmd)
8031{
8032 const char *intf = get_param(cmd, "Interface");
8033 const char *val;
8034
8035 if (intf == NULL)
8036 return -1;
8037
8038 val = get_param(cmd, "program");
8039 if (val && (strcasecmp(val, "HS2") == 0 ||
8040 strcasecmp(val, "HS2-R2") == 0))
8041 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
8042
8043 return -1;
8044}
8045
8046
8047static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
8048 struct sigma_cmd *cmd)
8049{
8050 const char *intf = get_param(cmd, "Interface");
8051 const char *mac = get_param(cmd, "MAC");
8052
8053 if (intf == NULL || mac == NULL)
8054 return -1;
8055
8056 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
8057 "interface %s to %s", intf, mac);
8058
8059 if (dut->set_macaddr) {
8060 char buf[128];
8061 int res;
8062 if (strcasecmp(mac, "default") == 0) {
8063 res = snprintf(buf, sizeof(buf), "%s",
8064 dut->set_macaddr);
8065 dut->tmp_mac_addr = 0;
8066 } else {
8067 res = snprintf(buf, sizeof(buf), "%s %s",
8068 dut->set_macaddr, mac);
8069 dut->tmp_mac_addr = 1;
8070 }
8071 if (res < 0 || res >= (int) sizeof(buf))
8072 return -1;
8073 if (system(buf) != 0) {
8074 send_resp(dut, conn, SIGMA_ERROR,
8075 "errorCode,Failed to set MAC "
8076 "address");
8077 return 0;
8078 }
8079 return 1;
8080 }
8081
8082 if (strcasecmp(mac, "default") == 0)
8083 return 1;
8084
8085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8086 "command");
8087 return 0;
8088}
8089
8090
8091static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
8092 struct sigma_conn *conn, const char *intf,
8093 int val)
8094{
8095 char buf[200];
8096 int res;
8097
8098 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
8099 intf, val);
8100 if (res < 0 || res >= (int) sizeof(buf))
8101 return -1;
8102 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8103 if (system(buf) != 0) {
8104 send_resp(dut, conn, SIGMA_ERROR,
8105 "errorCode,Failed to configure offchannel mode");
8106 return 0;
8107 }
8108
8109 return 1;
8110}
8111
8112
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008113static int off_chan_val(enum sec_ch_offset off)
8114{
8115 switch (off) {
8116 case SEC_CH_NO:
8117 return 0;
8118 case SEC_CH_40ABOVE:
8119 return 40;
8120 case SEC_CH_40BELOW:
8121 return -40;
8122 }
8123
8124 return 0;
8125}
8126
8127
8128static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
8129 const char *intf, int off_ch_num,
8130 enum sec_ch_offset sec)
8131{
8132 char buf[200];
8133 int res;
8134
8135 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
8136 intf, off_ch_num);
8137 if (res < 0 || res >= (int) sizeof(buf))
8138 return -1;
8139 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8140 if (system(buf) != 0) {
8141 send_resp(dut, conn, SIGMA_ERROR,
8142 "errorCode,Failed to set offchan");
8143 return 0;
8144 }
8145
8146 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
8147 intf, off_chan_val(sec));
8148 if (res < 0 || res >= (int) sizeof(buf))
8149 return -1;
8150 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8151 if (system(buf) != 0) {
8152 send_resp(dut, conn, SIGMA_ERROR,
8153 "errorCode,Failed to set sec chan offset");
8154 return 0;
8155 }
8156
8157 return 1;
8158}
8159
8160
8161static int tdls_set_offchannel_offset(struct sigma_dut *dut,
8162 struct sigma_conn *conn,
8163 const char *intf, int off_ch_num,
8164 enum sec_ch_offset sec)
8165{
8166 char buf[200];
8167 int res;
8168
8169 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
8170 off_ch_num);
8171 if (res < 0 || res >= (int) sizeof(buf))
8172 return -1;
8173 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8174
8175 if (wpa_command(intf, buf) < 0) {
8176 send_resp(dut, conn, SIGMA_ERROR,
8177 "ErrorCode,Failed to set offchan");
8178 return 0;
8179 }
8180 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
8181 off_chan_val(sec));
8182 if (res < 0 || res >= (int) sizeof(buf))
8183 return -1;
8184
8185 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8186
8187 if (wpa_command(intf, buf) < 0) {
8188 send_resp(dut, conn, SIGMA_ERROR,
8189 "ErrorCode,Failed to set sec chan offset");
8190 return 0;
8191 }
8192
8193 return 1;
8194}
8195
8196
8197static int tdls_set_offchannel_mode(struct sigma_dut *dut,
8198 struct sigma_conn *conn,
8199 const char *intf, int val)
8200{
8201 char buf[200];
8202 int res;
8203
8204 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
8205 val);
8206 if (res < 0 || res >= (int) sizeof(buf))
8207 return -1;
8208 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8209
8210 if (wpa_command(intf, buf) < 0) {
8211 send_resp(dut, conn, SIGMA_ERROR,
8212 "ErrorCode,Failed to configure offchannel mode");
8213 return 0;
8214 }
8215
8216 return 1;
8217}
8218
8219
8220static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
8221 struct sigma_conn *conn,
8222 struct sigma_cmd *cmd)
8223{
8224 const char *val;
8225 enum {
8226 CHSM_NOT_SET,
8227 CHSM_ENABLE,
8228 CHSM_DISABLE,
8229 CHSM_REJREQ,
8230 CHSM_UNSOLRESP
8231 } chsm = CHSM_NOT_SET;
8232 int off_ch_num = -1;
8233 enum sec_ch_offset sec_ch = SEC_CH_NO;
8234 int res;
8235
8236 val = get_param(cmd, "Uapsd");
8237 if (val) {
8238 char buf[100];
8239 if (strcasecmp(val, "Enable") == 0)
8240 snprintf(buf, sizeof(buf), "SET ps 99");
8241 else if (strcasecmp(val, "Disable") == 0)
8242 snprintf(buf, sizeof(buf), "SET ps 98");
8243 else {
8244 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8245 "Unsupported uapsd parameter value");
8246 return 0;
8247 }
8248 if (wpa_command(intf, buf)) {
8249 send_resp(dut, conn, SIGMA_ERROR,
8250 "ErrorCode,Failed to change U-APSD "
8251 "powersave mode");
8252 return 0;
8253 }
8254 }
8255
8256 val = get_param(cmd, "TPKTIMER");
8257 if (val && strcasecmp(val, "DISABLE") == 0) {
8258 if (wpa_command(intf, "SET tdls_testing 0x100")) {
8259 send_resp(dut, conn, SIGMA_ERROR,
8260 "ErrorCode,Failed to enable no TPK "
8261 "expiration test mode");
8262 return 0;
8263 }
8264 dut->no_tpk_expiration = 1;
8265 }
8266
8267 val = get_param(cmd, "ChSwitchMode");
8268 if (val) {
8269 if (strcasecmp(val, "Enable") == 0 ||
8270 strcasecmp(val, "Initiate") == 0)
8271 chsm = CHSM_ENABLE;
8272 else if (strcasecmp(val, "Disable") == 0 ||
8273 strcasecmp(val, "passive") == 0)
8274 chsm = CHSM_DISABLE;
8275 else if (strcasecmp(val, "RejReq") == 0)
8276 chsm = CHSM_REJREQ;
8277 else if (strcasecmp(val, "UnSolResp") == 0)
8278 chsm = CHSM_UNSOLRESP;
8279 else {
8280 send_resp(dut, conn, SIGMA_ERROR,
8281 "ErrorCode,Unknown ChSwitchMode value");
8282 return 0;
8283 }
8284 }
8285
8286 val = get_param(cmd, "OffChNum");
8287 if (val) {
8288 off_ch_num = atoi(val);
8289 if (off_ch_num == 0) {
8290 send_resp(dut, conn, SIGMA_ERROR,
8291 "ErrorCode,Invalid OffChNum");
8292 return 0;
8293 }
8294 }
8295
8296 val = get_param(cmd, "SecChOffset");
8297 if (val) {
8298 if (strcmp(val, "20") == 0)
8299 sec_ch = SEC_CH_NO;
8300 else if (strcasecmp(val, "40above") == 0)
8301 sec_ch = SEC_CH_40ABOVE;
8302 else if (strcasecmp(val, "40below") == 0)
8303 sec_ch = SEC_CH_40BELOW;
8304 else {
8305 send_resp(dut, conn, SIGMA_ERROR,
8306 "ErrorCode,Unknown SecChOffset value");
8307 return 0;
8308 }
8309 }
8310
8311 if (chsm == CHSM_NOT_SET) {
8312 /* no offchannel changes requested */
8313 return 1;
8314 }
8315
8316 if (strcmp(intf, get_main_ifname()) != 0 &&
8317 strcmp(intf, get_station_ifname()) != 0) {
8318 send_resp(dut, conn, SIGMA_ERROR,
8319 "ErrorCode,Unknown interface");
8320 return 0;
8321 }
8322
8323 switch (chsm) {
8324 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008325 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008326 break;
8327 case CHSM_ENABLE:
8328 if (off_ch_num < 0) {
8329 send_resp(dut, conn, SIGMA_ERROR,
8330 "ErrorCode,Missing OffChNum argument");
8331 return 0;
8332 }
8333 if (wifi_chip_type == DRIVER_WCN) {
8334 res = tdls_set_offchannel_offset(dut, conn, intf,
8335 off_ch_num, sec_ch);
8336 } else {
8337 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8338 sec_ch);
8339 }
8340 if (res != 1)
8341 return res;
8342 if (wifi_chip_type == DRIVER_WCN)
8343 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8344 else
8345 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8346 break;
8347 case CHSM_DISABLE:
8348 if (wifi_chip_type == DRIVER_WCN)
8349 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8350 else
8351 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8352 break;
8353 case CHSM_REJREQ:
8354 if (wifi_chip_type == DRIVER_WCN)
8355 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8356 else
8357 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8358 break;
8359 case CHSM_UNSOLRESP:
8360 if (off_ch_num < 0) {
8361 send_resp(dut, conn, SIGMA_ERROR,
8362 "ErrorCode,Missing OffChNum argument");
8363 return 0;
8364 }
8365 if (wifi_chip_type == DRIVER_WCN) {
8366 res = tdls_set_offchannel_offset(dut, conn, intf,
8367 off_ch_num, sec_ch);
8368 } else {
8369 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8370 sec_ch);
8371 }
8372 if (res != 1)
8373 return res;
8374 if (wifi_chip_type == DRIVER_WCN)
8375 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8376 else
8377 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8378 break;
8379 }
8380
8381 return res;
8382}
8383
8384
8385static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8386 struct sigma_conn *conn,
8387 struct sigma_cmd *cmd)
8388{
8389 const char *val;
8390 char *token, *result;
8391
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008392 novap_reset(dut, intf);
8393
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008394 val = get_param(cmd, "nss_mcs_opt");
8395 if (val) {
8396 /* String (nss_operating_mode; mcs_operating_mode) */
8397 int nss, mcs;
8398 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308399 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008400
8401 token = strdup(val);
8402 if (!token)
8403 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308404 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308405 if (!result) {
8406 sigma_dut_print(dut, DUT_MSG_ERROR,
8407 "VHT NSS not specified");
8408 goto failed;
8409 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008410 if (strcasecmp(result, "def") != 0) {
8411 nss = atoi(result);
8412 if (nss == 4)
8413 ath_disable_txbf(dut, intf);
8414 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8415 intf, nss);
8416 if (system(buf) != 0) {
8417 sigma_dut_print(dut, DUT_MSG_ERROR,
8418 "iwpriv nss failed");
8419 goto failed;
8420 }
8421 }
8422
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308423 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308424 if (!result) {
8425 sigma_dut_print(dut, DUT_MSG_ERROR,
8426 "VHT MCS not specified");
8427 goto failed;
8428 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008429 if (strcasecmp(result, "def") == 0) {
8430 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8431 intf);
8432 if (system(buf) != 0) {
8433 sigma_dut_print(dut, DUT_MSG_ERROR,
8434 "iwpriv set11NRates failed");
8435 goto failed;
8436 }
8437
8438 } else {
8439 mcs = atoi(result);
8440 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8441 intf, mcs);
8442 if (system(buf) != 0) {
8443 sigma_dut_print(dut, DUT_MSG_ERROR,
8444 "iwpriv vhtmcs failed");
8445 goto failed;
8446 }
8447 }
8448 /* Channel width gets messed up, fix this */
8449 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8450 intf, dut->chwidth);
8451 if (system(buf) != 0) {
8452 sigma_dut_print(dut, DUT_MSG_ERROR,
8453 "iwpriv chwidth failed");
8454 }
8455 }
8456
8457 return 1;
8458failed:
8459 free(token);
8460 return 0;
8461}
8462
8463
8464static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8465 struct sigma_conn *conn,
8466 struct sigma_cmd *cmd)
8467{
8468 switch (get_driver_type()) {
8469 case DRIVER_ATHEROS:
8470 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8471 default:
8472 send_resp(dut, conn, SIGMA_ERROR,
8473 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8474 return 0;
8475 }
8476}
8477
8478
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008479static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8480 struct sigma_conn *conn,
8481 struct sigma_cmd *cmd)
8482{
8483 const char *val;
8484 char *token = NULL, *result;
8485 char buf[60];
8486
8487 val = get_param(cmd, "nss_mcs_opt");
8488 if (val) {
8489 /* String (nss_operating_mode; mcs_operating_mode) */
8490 int nss, mcs, ratecode;
8491 char *saveptr;
8492
8493 token = strdup(val);
8494 if (!token)
8495 return -2;
8496
8497 result = strtok_r(token, ";", &saveptr);
8498 if (!result) {
8499 sigma_dut_print(dut, DUT_MSG_ERROR,
8500 "HE NSS not specified");
8501 goto failed;
8502 }
8503 nss = 1;
8504 if (strcasecmp(result, "def") != 0)
8505 nss = atoi(result);
8506
8507 result = strtok_r(NULL, ";", &saveptr);
8508 if (!result) {
8509 sigma_dut_print(dut, DUT_MSG_ERROR,
8510 "HE MCS not specified");
8511 goto failed;
8512 }
8513 mcs = 7;
8514 if (strcasecmp(result, "def") != 0)
8515 mcs = atoi(result);
8516
8517 ratecode = 0x400; /* for nss:1 MCS 0 */
8518 if (nss == 2) {
8519 ratecode = 0x420; /* for nss:2 MCS 0 */
8520 } else if (nss > 2) {
8521 sigma_dut_print(dut, DUT_MSG_ERROR,
8522 "HE NSS %d not supported", nss);
8523 goto failed;
8524 }
8525
8526 /* Add the MCS to the ratecode */
8527 if (mcs >= 0 && mcs <= 11) {
8528 ratecode += mcs;
8529 } else {
8530 sigma_dut_print(dut, DUT_MSG_ERROR,
8531 "HE MCS %d not supported", mcs);
8532 goto failed;
8533 }
8534 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8535 intf, ratecode);
8536 if (system(buf) != 0) {
8537 sigma_dut_print(dut, DUT_MSG_ERROR,
8538 "iwpriv setting of 11ax rates failed");
8539 goto failed;
8540 }
8541 free(token);
8542 }
8543
8544 val = get_param(cmd, "GI");
8545 if (val) {
8546 if (strcmp(val, "0.8") == 0) {
8547 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8548 } else if (strcmp(val, "1.6") == 0) {
8549 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8550 } else if (strcmp(val, "3.2") == 0) {
8551 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8552 } else {
8553 send_resp(dut, conn, SIGMA_ERROR,
8554 "errorCode,GI value not supported");
8555 return 0;
8556 }
8557 if (system(buf) != 0) {
8558 send_resp(dut, conn, SIGMA_ERROR,
8559 "errorCode,Failed to set shortgi");
8560 return 0;
8561 }
8562 }
8563
8564 return 1;
8565
8566failed:
8567 free(token);
8568 return -2;
8569}
8570
8571
8572static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8573 struct sigma_conn *conn,
8574 struct sigma_cmd *cmd)
8575{
8576 switch (get_driver_type()) {
8577 case DRIVER_WCN:
8578 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
8579 default:
8580 send_resp(dut, conn, SIGMA_ERROR,
8581 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
8582 return 0;
8583 }
8584}
8585
8586
Ashwini Patil5acd7382017-04-13 15:55:04 +05308587static int btm_query_candidate_list(struct sigma_dut *dut,
8588 struct sigma_conn *conn,
8589 struct sigma_cmd *cmd)
8590{
8591 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
8592 int len, ret;
8593 char buf[10];
8594
8595 /*
8596 * Neighbor Report elements format:
8597 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
8598 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
8599 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
8600 */
8601
8602 bssid = get_param(cmd, "Nebor_BSSID");
8603 if (!bssid) {
8604 send_resp(dut, conn, SIGMA_INVALID,
8605 "errorCode,Nebor_BSSID is missing");
8606 return 0;
8607 }
8608
8609 info = get_param(cmd, "Nebor_Bssid_Info");
8610 if (!info) {
8611 sigma_dut_print(dut, DUT_MSG_INFO,
8612 "Using default value for Nebor_Bssid_Info: %s",
8613 DEFAULT_NEIGHBOR_BSSID_INFO);
8614 info = DEFAULT_NEIGHBOR_BSSID_INFO;
8615 }
8616
8617 op_class = get_param(cmd, "Nebor_Op_Class");
8618 if (!op_class) {
8619 send_resp(dut, conn, SIGMA_INVALID,
8620 "errorCode,Nebor_Op_Class is missing");
8621 return 0;
8622 }
8623
8624 ch = get_param(cmd, "Nebor_Op_Ch");
8625 if (!ch) {
8626 send_resp(dut, conn, SIGMA_INVALID,
8627 "errorCode,Nebor_Op_Ch is missing");
8628 return 0;
8629 }
8630
8631 phy_type = get_param(cmd, "Nebor_Phy_Type");
8632 if (!phy_type) {
8633 sigma_dut_print(dut, DUT_MSG_INFO,
8634 "Using default value for Nebor_Phy_Type: %s",
8635 DEFAULT_NEIGHBOR_PHY_TYPE);
8636 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
8637 }
8638
8639 /* Parse optional subelements */
8640 buf[0] = '\0';
8641 pref = get_param(cmd, "Nebor_Pref");
8642 if (pref) {
8643 /* hexdump for preferrence subelement */
8644 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
8645 if (ret < 0 || ret >= (int) sizeof(buf)) {
8646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "snprintf failed for optional subelement ret: %d",
8648 ret);
8649 send_resp(dut, conn, SIGMA_ERROR,
8650 "errorCode,snprintf failed for subelement");
8651 return 0;
8652 }
8653 }
8654
8655 if (!dut->btm_query_cand_list) {
8656 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
8657 if (!dut->btm_query_cand_list) {
8658 send_resp(dut, conn, SIGMA_ERROR,
8659 "errorCode,Failed to allocate memory for btm_query_cand_list");
8660 return 0;
8661 }
8662 }
8663
8664 len = strlen(dut->btm_query_cand_list);
8665 ret = snprintf(dut->btm_query_cand_list + len,
8666 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
8667 bssid, info, op_class, ch, phy_type, buf);
8668 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
8669 sigma_dut_print(dut, DUT_MSG_ERROR,
8670 "snprintf failed for neighbor report list ret: %d",
8671 ret);
8672 send_resp(dut, conn, SIGMA_ERROR,
8673 "errorCode,snprintf failed for neighbor report");
8674 free(dut->btm_query_cand_list);
8675 dut->btm_query_cand_list = NULL;
8676 return 0;
8677 }
8678
8679 return 1;
8680}
8681
8682
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008683static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8684 struct sigma_cmd *cmd)
8685{
8686 const char *intf = get_param(cmd, "Interface");
8687 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308688 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008689
8690 if (intf == NULL || prog == NULL)
8691 return -1;
8692
Ashwini Patil5acd7382017-04-13 15:55:04 +05308693 /* BSS Transition candidate list for BTM query */
8694 val = get_param(cmd, "Nebor_BSSID");
8695 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
8696 return 0;
8697
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008698 if (strcasecmp(prog, "TDLS") == 0)
8699 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
8700
8701 if (strcasecmp(prog, "VHT") == 0)
8702 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
8703
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008704 if (strcasecmp(prog, "HE") == 0)
8705 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
8706
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308707 if (strcasecmp(prog, "MBO") == 0) {
8708 val = get_param(cmd, "Cellular_Data_Cap");
8709 if (val &&
8710 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
8711 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05308712
8713 val = get_param(cmd, "Ch_Pref");
8714 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
8715 return 0;
8716
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308717 return 1;
8718 }
8719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
8721 return 0;
8722}
8723
8724
8725static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
8726 struct sigma_cmd *cmd)
8727{
8728 const char *intf = get_param(cmd, "Interface");
8729 const char *mode = get_param(cmd, "Mode");
8730 int res;
8731
8732 if (intf == NULL || mode == NULL)
8733 return -1;
8734
8735 if (strcasecmp(mode, "On") == 0)
8736 res = wpa_command(intf, "SET radio_disabled 0");
8737 else if (strcasecmp(mode, "Off") == 0)
8738 res = wpa_command(intf, "SET radio_disabled 1");
8739 else
8740 return -1;
8741
8742 if (res) {
8743 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8744 "radio mode");
8745 return 0;
8746 }
8747
8748 return 1;
8749}
8750
8751
8752static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
8753 struct sigma_cmd *cmd)
8754{
8755 const char *intf = get_param(cmd, "Interface");
8756 const char *mode = get_param(cmd, "Mode");
8757 int res;
8758
8759 if (intf == NULL || mode == NULL)
8760 return -1;
8761
8762 if (strcasecmp(mode, "On") == 0)
8763 res = set_ps(intf, dut, 1);
8764 else if (strcasecmp(mode, "Off") == 0)
8765 res = set_ps(intf, dut, 0);
8766 else
8767 return -1;
8768
8769 if (res) {
8770 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8771 "power save mode");
8772 return 0;
8773 }
8774
8775 return 1;
8776}
8777
8778
8779static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
8780 struct sigma_cmd *cmd)
8781{
8782 const char *intf = get_param(cmd, "Interface");
8783 const char *val, *bssid;
8784 int res;
8785 char *buf;
8786 size_t buf_len;
8787
8788 val = get_param(cmd, "BSSID_FILTER");
8789 if (val == NULL)
8790 return -1;
8791
8792 bssid = get_param(cmd, "BSSID_List");
8793 if (atoi(val) == 0 || bssid == NULL) {
8794 /* Disable BSSID filter */
8795 if (wpa_command(intf, "SET bssid_filter ")) {
8796 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
8797 "to disable BSSID filter");
8798 return 0;
8799 }
8800
8801 return 1;
8802 }
8803
8804 buf_len = 100 + strlen(bssid);
8805 buf = malloc(buf_len);
8806 if (buf == NULL)
8807 return -1;
8808
8809 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
8810 res = wpa_command(intf, buf);
8811 free(buf);
8812 if (res) {
8813 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
8814 "BSSID filter");
8815 return 0;
8816 }
8817
8818 return 1;
8819}
8820
8821
8822static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
8823 struct sigma_cmd *cmd)
8824{
8825 const char *intf = get_param(cmd, "Interface");
8826 const char *val;
8827
8828 /* TODO: ARP */
8829
8830 val = get_param(cmd, "HS2_CACHE_PROFILE");
8831 if (val && strcasecmp(val, "All") == 0)
8832 hs2_clear_credentials(intf);
8833
8834 return 1;
8835}
8836
8837
8838static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
8839 struct sigma_cmd *cmd)
8840{
8841 const char *intf = get_param(cmd, "Interface");
8842 const char *key_type = get_param(cmd, "KeyType");
8843 char buf[100], resp[200];
8844
8845 if (key_type == NULL)
8846 return -1;
8847
8848 if (strcasecmp(key_type, "GTK") == 0) {
8849 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
8850 strncmp(buf, "FAIL", 4) == 0) {
8851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8852 "not fetch current GTK");
8853 return 0;
8854 }
8855 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
8856 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8857 return 0;
8858 } else {
8859 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8860 "KeyType");
8861 return 0;
8862 }
8863
8864 return 1;
8865}
8866
8867
8868static int hs2_set_policy(struct sigma_dut *dut)
8869{
8870#ifdef ANDROID
8871 system("ip rule del prio 23000");
8872 if (system("ip rule add from all lookup main prio 23000") != 0) {
8873 sigma_dut_print(dut, DUT_MSG_ERROR,
8874 "Failed to run:ip rule add from all lookup main prio");
8875 return -1;
8876 }
8877 if (system("ip route flush cache") != 0) {
8878 sigma_dut_print(dut, DUT_MSG_ERROR,
8879 "Failed to run ip route flush cache");
8880 return -1;
8881 }
8882 return 1;
8883#else /* ANDROID */
8884 return 0;
8885#endif /* ANDROID */
8886}
8887
8888
8889static int cmd_sta_hs2_associate(struct sigma_dut *dut,
8890 struct sigma_conn *conn,
8891 struct sigma_cmd *cmd)
8892{
8893 const char *intf = get_param(cmd, "Interface");
8894 const char *val = get_param(cmd, "Ignore_blacklist");
8895 struct wpa_ctrl *ctrl;
8896 int res;
8897 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
8898 int tries = 0;
8899 int ignore_blacklist = 0;
8900 const char *events[] = {
8901 "CTRL-EVENT-CONNECTED",
8902 "INTERWORKING-BLACKLISTED",
8903 "INTERWORKING-NO-MATCH",
8904 NULL
8905 };
8906
8907 start_sta_mode(dut);
8908
8909 blacklisted[0] = '\0';
8910 if (val && atoi(val))
8911 ignore_blacklist = 1;
8912
8913try_again:
8914 ctrl = open_wpa_mon(intf);
8915 if (ctrl == NULL) {
8916 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8917 "wpa_supplicant monitor connection");
8918 return -2;
8919 }
8920
8921 tries++;
8922 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
8923 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
8924 "Interworking connection");
8925 wpa_ctrl_detach(ctrl);
8926 wpa_ctrl_close(ctrl);
8927 return 0;
8928 }
8929
8930 buf[0] = '\0';
8931 while (1) {
8932 char *pos;
8933 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
8934 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
8935 if (!pos)
8936 break;
8937 pos += 25;
8938 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
8939 pos);
8940 if (!blacklisted[0])
8941 memcpy(blacklisted, pos, strlen(pos) + 1);
8942 }
8943
8944 if (ignore_blacklist && blacklisted[0]) {
8945 char *end;
8946 end = strchr(blacklisted, ' ');
8947 if (end)
8948 *end = '\0';
8949 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
8950 blacklisted);
8951 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
8952 blacklisted);
8953 if (wpa_command(intf, buf)) {
8954 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
8955 wpa_ctrl_detach(ctrl);
8956 wpa_ctrl_close(ctrl);
8957 return 0;
8958 }
8959 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8960 buf, sizeof(buf));
8961 }
8962
8963 wpa_ctrl_detach(ctrl);
8964 wpa_ctrl_close(ctrl);
8965
8966 if (res < 0) {
8967 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8968 "connect");
8969 return 0;
8970 }
8971
8972 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
8973 strstr(buf, "INTERWORKING-BLACKLISTED")) {
8974 if (tries < 2) {
8975 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
8976 goto try_again;
8977 }
8978 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
8979 "matching credentials found");
8980 return 0;
8981 }
8982
8983 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8984 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8985 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8986 "get current BSSID/SSID");
8987 return 0;
8988 }
8989
8990 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
8991 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8992 hs2_set_policy(dut);
8993 return 0;
8994}
8995
8996
8997static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
8998 struct sigma_conn *conn,
8999 const char *ifname,
9000 struct sigma_cmd *cmd)
9001{
9002 const char *val;
9003 int id;
9004
9005 id = add_cred(ifname);
9006 if (id < 0)
9007 return -2;
9008 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9009
9010 val = get_param(cmd, "prefer");
9011 if (val && atoi(val) > 0)
9012 set_cred(ifname, id, "priority", "1");
9013
9014 val = get_param(cmd, "REALM");
9015 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9016 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9017 "realm");
9018 return 0;
9019 }
9020
9021 val = get_param(cmd, "HOME_FQDN");
9022 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9023 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9024 "home_fqdn");
9025 return 0;
9026 }
9027
9028 val = get_param(cmd, "Username");
9029 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9030 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9031 "username");
9032 return 0;
9033 }
9034
9035 val = get_param(cmd, "Password");
9036 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
9037 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9038 "password");
9039 return 0;
9040 }
9041
9042 val = get_param(cmd, "ROOT_CA");
9043 if (val) {
9044 char fname[200];
9045 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9046#ifdef __linux__
9047 if (!file_exists(fname)) {
9048 char msg[300];
9049 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9050 "file (%s) not found", fname);
9051 send_resp(dut, conn, SIGMA_ERROR, msg);
9052 return 0;
9053 }
9054#endif /* __linux__ */
9055 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9056 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9057 "not set root CA");
9058 return 0;
9059 }
9060 }
9061
9062 return 1;
9063}
9064
9065
9066static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
9067{
9068 FILE *in, *out;
9069 char buf[500];
9070 int found = 0;
9071
9072 in = fopen("devdetail.xml", "r");
9073 if (in == NULL)
9074 return -1;
9075 out = fopen("devdetail.xml.tmp", "w");
9076 if (out == NULL) {
9077 fclose(in);
9078 return -1;
9079 }
9080
9081 while (fgets(buf, sizeof(buf), in)) {
9082 char *pos = strstr(buf, "<IMSI>");
9083 if (pos) {
9084 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
9085 imsi);
9086 pos += 6;
9087 *pos = '\0';
9088 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
9089 found++;
9090 } else {
9091 fprintf(out, "%s", buf);
9092 }
9093 }
9094
9095 fclose(out);
9096 fclose(in);
9097 if (found)
9098 rename("devdetail.xml.tmp", "devdetail.xml");
9099 else
9100 unlink("devdetail.xml.tmp");
9101
9102 return 0;
9103}
9104
9105
9106static int sta_add_credential_sim(struct sigma_dut *dut,
9107 struct sigma_conn *conn,
9108 const char *ifname, struct sigma_cmd *cmd)
9109{
9110 const char *val, *imsi = NULL;
9111 int id;
9112 char buf[200];
9113 int res;
9114 const char *pos;
9115 size_t mnc_len;
9116 char plmn_mcc[4];
9117 char plmn_mnc[4];
9118
9119 id = add_cred(ifname);
9120 if (id < 0)
9121 return -2;
9122 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9123
9124 val = get_param(cmd, "prefer");
9125 if (val && atoi(val) > 0)
9126 set_cred(ifname, id, "priority", "1");
9127
9128 val = get_param(cmd, "PLMN_MCC");
9129 if (val == NULL) {
9130 send_resp(dut, conn, SIGMA_ERROR,
9131 "errorCode,Missing PLMN_MCC");
9132 return 0;
9133 }
9134 if (strlen(val) != 3) {
9135 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
9136 return 0;
9137 }
9138 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
9139
9140 val = get_param(cmd, "PLMN_MNC");
9141 if (val == NULL) {
9142 send_resp(dut, conn, SIGMA_ERROR,
9143 "errorCode,Missing PLMN_MNC");
9144 return 0;
9145 }
9146 if (strlen(val) != 2 && strlen(val) != 3) {
9147 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
9148 return 0;
9149 }
9150 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
9151
9152 val = get_param(cmd, "IMSI");
9153 if (val == NULL) {
9154 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
9155 "IMSI");
9156 return 0;
9157 }
9158
9159 imsi = pos = val;
9160
9161 if (strncmp(plmn_mcc, pos, 3) != 0) {
9162 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
9163 return 0;
9164 }
9165 pos += 3;
9166
9167 mnc_len = strlen(plmn_mnc);
9168 if (mnc_len < 2) {
9169 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
9170 return 0;
9171 }
9172
9173 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
9174 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
9175 return 0;
9176 }
9177 pos += mnc_len;
9178
9179 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
9180 if (res < 0 || res >= (int) sizeof(buf))
9181 return -1;
9182 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
9183 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9184 "not set IMSI");
9185 return 0;
9186 }
9187
9188 val = get_param(cmd, "Password");
9189 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
9190 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9191 "not set password");
9192 return 0;
9193 }
9194
9195 if (dut->program == PROGRAM_HS2_R2) {
9196 /*
9197 * Set provisioning_sp for the test cases where SIM/USIM
9198 * provisioning is used.
9199 */
9200 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
9201 "wi-fi.org") < 0) {
9202 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9203 "not set provisioning_sp");
9204 return 0;
9205 }
9206
9207 update_devdetail_imsi(dut, imsi);
9208 }
9209
9210 return 1;
9211}
9212
9213
9214static int sta_add_credential_cert(struct sigma_dut *dut,
9215 struct sigma_conn *conn,
9216 const char *ifname,
9217 struct sigma_cmd *cmd)
9218{
9219 const char *val;
9220 int id;
9221
9222 id = add_cred(ifname);
9223 if (id < 0)
9224 return -2;
9225 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9226
9227 val = get_param(cmd, "prefer");
9228 if (val && atoi(val) > 0)
9229 set_cred(ifname, id, "priority", "1");
9230
9231 val = get_param(cmd, "REALM");
9232 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9233 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9234 "realm");
9235 return 0;
9236 }
9237
9238 val = get_param(cmd, "HOME_FQDN");
9239 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9240 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9241 "home_fqdn");
9242 return 0;
9243 }
9244
9245 val = get_param(cmd, "Username");
9246 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9247 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9248 "username");
9249 return 0;
9250 }
9251
9252 val = get_param(cmd, "clientCertificate");
9253 if (val) {
9254 char fname[200];
9255 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9256#ifdef __linux__
9257 if (!file_exists(fname)) {
9258 char msg[300];
9259 snprintf(msg, sizeof(msg),
9260 "ErrorCode,clientCertificate "
9261 "file (%s) not found", fname);
9262 send_resp(dut, conn, SIGMA_ERROR, msg);
9263 return 0;
9264 }
9265#endif /* __linux__ */
9266 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
9267 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9268 "not set client_cert");
9269 return 0;
9270 }
9271 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
9272 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9273 "not set private_key");
9274 return 0;
9275 }
9276 }
9277
9278 val = get_param(cmd, "ROOT_CA");
9279 if (val) {
9280 char fname[200];
9281 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9282#ifdef __linux__
9283 if (!file_exists(fname)) {
9284 char msg[300];
9285 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9286 "file (%s) not found", fname);
9287 send_resp(dut, conn, SIGMA_ERROR, msg);
9288 return 0;
9289 }
9290#endif /* __linux__ */
9291 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9293 "not set root CA");
9294 return 0;
9295 }
9296 }
9297
9298 return 1;
9299}
9300
9301
9302static int cmd_sta_add_credential(struct sigma_dut *dut,
9303 struct sigma_conn *conn,
9304 struct sigma_cmd *cmd)
9305{
9306 const char *intf = get_param(cmd, "Interface");
9307 const char *type;
9308
9309 start_sta_mode(dut);
9310
9311 type = get_param(cmd, "Type");
9312 if (!type)
9313 return -1;
9314
9315 if (strcasecmp(type, "uname_pwd") == 0)
9316 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9317
9318 if (strcasecmp(type, "sim") == 0)
9319 return sta_add_credential_sim(dut, conn, intf, cmd);
9320
9321 if (strcasecmp(type, "cert") == 0)
9322 return sta_add_credential_cert(dut, conn, intf, cmd);
9323
9324 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9325 "type");
9326 return 0;
9327}
9328
9329
9330static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9331 struct sigma_cmd *cmd)
9332{
9333 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309334 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009335 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309336 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009337 int res;
9338
9339 val = get_param(cmd, "HESSID");
9340 if (val) {
9341 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9342 if (res < 0 || res >= (int) sizeof(buf))
9343 return -1;
9344 wpa_command(intf, buf);
9345 }
9346
9347 val = get_param(cmd, "ACCS_NET_TYPE");
9348 if (val) {
9349 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9350 val);
9351 if (res < 0 || res >= (int) sizeof(buf))
9352 return -1;
9353 wpa_command(intf, buf);
9354 }
9355
vamsi krishna89ad8c62017-09-19 12:51:18 +05309356 bssid = get_param(cmd, "Bssid");
9357 ssid = get_param(cmd, "Ssid");
9358
9359 if (ssid) {
9360 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9361 send_resp(dut, conn, SIGMA_ERROR,
9362 "ErrorCode,Too long SSID");
9363 return 0;
9364 }
9365 ascii2hexstr(ssid, ssid_hex);
9366 }
9367
9368 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9369 bssid ? " bssid=": "",
9370 bssid ? bssid : "",
9371 ssid ? " ssid " : "",
9372 ssid ? ssid_hex : "");
9373 if (res < 0 || res >= (int) sizeof(buf))
9374 return -1;
9375
9376 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009377 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9378 "scan");
9379 return 0;
9380 }
9381
9382 return 1;
9383}
9384
9385
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009386static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9387 struct sigma_cmd *cmd)
9388{
9389 const char *intf = get_param(cmd, "Interface");
9390 const char *bssid;
9391 char buf[4096], *pos;
9392 int freq, chan;
9393 char *ssid;
9394 char resp[100];
9395 int res;
9396 struct wpa_ctrl *ctrl;
9397
9398 bssid = get_param(cmd, "BSSID");
9399 if (!bssid) {
9400 send_resp(dut, conn, SIGMA_INVALID,
9401 "errorCode,BSSID argument is missing");
9402 return 0;
9403 }
9404
9405 ctrl = open_wpa_mon(intf);
9406 if (!ctrl) {
9407 sigma_dut_print(dut, DUT_MSG_ERROR,
9408 "Failed to open wpa_supplicant monitor connection");
9409 return -1;
9410 }
9411
9412 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9413 send_resp(dut, conn, SIGMA_ERROR,
9414 "errorCode,Could not start scan");
9415 wpa_ctrl_detach(ctrl);
9416 wpa_ctrl_close(ctrl);
9417 return 0;
9418 }
9419
9420 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9421 buf, sizeof(buf));
9422
9423 wpa_ctrl_detach(ctrl);
9424 wpa_ctrl_close(ctrl);
9425
9426 if (res < 0) {
9427 send_resp(dut, conn, SIGMA_ERROR,
9428 "errorCode,Scan did not complete");
9429 return 0;
9430 }
9431
9432 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9433 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9434 strncmp(buf, "id=", 3) != 0) {
9435 send_resp(dut, conn, SIGMA_ERROR,
9436 "errorCode,Specified BSSID not found");
9437 return 0;
9438 }
9439
9440 pos = strstr(buf, "\nfreq=");
9441 if (!pos) {
9442 send_resp(dut, conn, SIGMA_ERROR,
9443 "errorCode,Channel not found");
9444 return 0;
9445 }
9446 freq = atoi(pos + 6);
9447 chan = freq_to_channel(freq);
9448
9449 pos = strstr(buf, "\nssid=");
9450 if (!pos) {
9451 send_resp(dut, conn, SIGMA_ERROR,
9452 "errorCode,SSID not found");
9453 return 0;
9454 }
9455 ssid = pos + 6;
9456 pos = strchr(ssid, '\n');
9457 if (pos)
9458 *pos = '\0';
9459 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9460 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9461 return 0;
9462}
9463
9464
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009465static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9466 struct sigma_cmd *cmd)
9467{
9468#ifdef __linux__
9469 struct timeval tv;
9470 struct tm tm;
9471 time_t t;
9472 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309473 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009474
9475 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9476
9477 memset(&tm, 0, sizeof(tm));
9478 val = get_param(cmd, "seconds");
9479 if (val)
9480 tm.tm_sec = atoi(val);
9481 val = get_param(cmd, "minutes");
9482 if (val)
9483 tm.tm_min = atoi(val);
9484 val = get_param(cmd, "hours");
9485 if (val)
9486 tm.tm_hour = atoi(val);
9487 val = get_param(cmd, "date");
9488 if (val)
9489 tm.tm_mday = atoi(val);
9490 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309491 if (val) {
9492 v = atoi(val);
9493 if (v < 1 || v > 12) {
9494 send_resp(dut, conn, SIGMA_INVALID,
9495 "errorCode,Invalid month");
9496 return 0;
9497 }
9498 tm.tm_mon = v - 1;
9499 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009500 val = get_param(cmd, "year");
9501 if (val) {
9502 int year = atoi(val);
9503#ifdef ANDROID
9504 if (year > 2035)
9505 year = 2035; /* years beyond 2035 not supported */
9506#endif /* ANDROID */
9507 tm.tm_year = year - 1900;
9508 }
9509 t = mktime(&tm);
9510 if (t == (time_t) -1) {
9511 send_resp(dut, conn, SIGMA_ERROR,
9512 "errorCode,Invalid date or time");
9513 return 0;
9514 }
9515
9516 memset(&tv, 0, sizeof(tv));
9517 tv.tv_sec = t;
9518
9519 if (settimeofday(&tv, NULL) < 0) {
9520 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9521 strerror(errno));
9522 send_resp(dut, conn, SIGMA_ERROR,
9523 "errorCode,Failed to set time");
9524 return 0;
9525 }
9526
9527 return 1;
9528#endif /* __linux__ */
9529
9530 return -1;
9531}
9532
9533
9534static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9535 struct sigma_cmd *cmd)
9536{
9537 const char *intf = get_param(cmd, "Interface");
9538 const char *name, *val;
9539 int prod_ess_assoc = 1;
9540 char buf[200], bssid[100], ssid[100];
9541 int res;
9542 struct wpa_ctrl *ctrl;
9543
9544 name = get_param(cmd, "osuFriendlyName");
9545
9546 val = get_param(cmd, "ProdESSAssoc");
9547 if (val)
9548 prod_ess_assoc = atoi(val);
9549
9550 kill_dhcp_client(dut, intf);
9551 if (start_dhcp_client(dut, intf) < 0)
9552 return -2;
9553
9554 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9555 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9556 res = snprintf(buf, sizeof(buf),
9557 "%s %s%s%s signup osu-ca.pem",
9558 prod_ess_assoc ? "" : "-N",
9559 name ? "-O'" : "", name ? name : "",
9560 name ? "'" : "");
9561
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309562 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009563 if (run_hs20_osu(dut, buf) < 0) {
9564 FILE *f;
9565
9566 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9567
9568 f = fopen("hs20-osu-client.res", "r");
9569 if (f) {
9570 char resp[400], res[300], *pos;
9571 if (!fgets(res, sizeof(res), f))
9572 res[0] = '\0';
9573 pos = strchr(res, '\n');
9574 if (pos)
9575 *pos = '\0';
9576 fclose(f);
9577 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
9578 res);
9579 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
9580 if (system(resp) != 0) {
9581 }
9582 snprintf(resp, sizeof(resp),
9583 "SSID,,BSSID,,failureReason,%s", res);
9584 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9585 return 0;
9586 }
9587
9588 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9589 return 0;
9590 }
9591
9592 if (!prod_ess_assoc)
9593 goto report;
9594
9595 ctrl = open_wpa_mon(intf);
9596 if (ctrl == NULL) {
9597 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9598 "wpa_supplicant monitor connection");
9599 return -1;
9600 }
9601
9602 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9603 buf, sizeof(buf));
9604
9605 wpa_ctrl_detach(ctrl);
9606 wpa_ctrl_close(ctrl);
9607
9608 if (res < 0) {
9609 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
9610 "network after OSU");
9611 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9612 return 0;
9613 }
9614
9615report:
9616 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9617 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9618 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
9619 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9620 return 0;
9621 }
9622
9623 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
9624 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009625 return 0;
9626}
9627
9628
9629static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
9630 struct sigma_cmd *cmd)
9631{
9632 const char *val;
9633 int timeout = 120;
9634
9635 val = get_param(cmd, "PolicyUpdate");
9636 if (val == NULL || atoi(val) == 0)
9637 return 1; /* No operation requested */
9638
9639 val = get_param(cmd, "Timeout");
9640 if (val)
9641 timeout = atoi(val);
9642
9643 if (timeout) {
9644 /* TODO: time out the command and return
9645 * PolicyUpdateStatus,TIMEOUT if needed. */
9646 }
9647
9648 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
9649 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9650 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
9651 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
9652 return 0;
9653 }
9654
9655 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
9656 return 0;
9657}
9658
9659
9660static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
9661 struct sigma_cmd *cmd)
9662{
9663 struct wpa_ctrl *ctrl;
9664 const char *intf = get_param(cmd, "Interface");
9665 const char *bssid = get_param(cmd, "Bssid");
9666 const char *ssid = get_param(cmd, "SSID");
9667 const char *security = get_param(cmd, "Security");
9668 const char *passphrase = get_param(cmd, "Passphrase");
9669 const char *pin = get_param(cmd, "PIN");
9670 char buf[1000];
9671 char ssid_hex[200], passphrase_hex[200];
9672 const char *keymgmt, *cipher;
9673
9674 if (intf == NULL)
9675 intf = get_main_ifname();
9676
9677 if (!bssid) {
9678 send_resp(dut, conn, SIGMA_ERROR,
9679 "ErrorCode,Missing Bssid argument");
9680 return 0;
9681 }
9682
9683 if (!ssid) {
9684 send_resp(dut, conn, SIGMA_ERROR,
9685 "ErrorCode,Missing SSID argument");
9686 return 0;
9687 }
9688
9689 if (!security) {
9690 send_resp(dut, conn, SIGMA_ERROR,
9691 "ErrorCode,Missing Security argument");
9692 return 0;
9693 }
9694
9695 if (!passphrase) {
9696 send_resp(dut, conn, SIGMA_ERROR,
9697 "ErrorCode,Missing Passphrase argument");
9698 return 0;
9699 }
9700
9701 if (!pin) {
9702 send_resp(dut, conn, SIGMA_ERROR,
9703 "ErrorCode,Missing PIN argument");
9704 return 0;
9705 }
9706
vamsi krishna8c9c1562017-05-12 15:51:46 +05309707 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
9708 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009709 send_resp(dut, conn, SIGMA_ERROR,
9710 "ErrorCode,Too long SSID/passphrase");
9711 return 0;
9712 }
9713
9714 ctrl = open_wpa_mon(intf);
9715 if (ctrl == NULL) {
9716 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9717 "wpa_supplicant monitor connection");
9718 return -2;
9719 }
9720
9721 if (strcasecmp(security, "wpa2-psk") == 0) {
9722 keymgmt = "WPA2PSK";
9723 cipher = "CCMP";
9724 } else {
9725 wpa_ctrl_detach(ctrl);
9726 wpa_ctrl_close(ctrl);
9727 send_resp(dut, conn, SIGMA_ERROR,
9728 "ErrorCode,Unsupported Security value");
9729 return 0;
9730 }
9731
9732 ascii2hexstr(ssid, ssid_hex);
9733 ascii2hexstr(passphrase, passphrase_hex);
9734 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
9735 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
9736
9737 if (wpa_command(intf, buf) < 0) {
9738 wpa_ctrl_detach(ctrl);
9739 wpa_ctrl_close(ctrl);
9740 send_resp(dut, conn, SIGMA_ERROR,
9741 "ErrorCode,Failed to start registrar");
9742 return 0;
9743 }
9744
9745 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
9746 dut->er_oper_performed = 1;
9747
9748 return wps_connection_event(dut, conn, ctrl, intf, 0);
9749}
9750
9751
9752static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
9753 struct sigma_conn *conn,
9754 struct sigma_cmd *cmd)
9755{
9756 struct wpa_ctrl *ctrl;
9757 const char *intf = get_param(cmd, "Interface");
9758 const char *bssid = get_param(cmd, "Bssid");
9759 char buf[100];
9760
9761 if (!bssid) {
9762 send_resp(dut, conn, SIGMA_ERROR,
9763 "ErrorCode,Missing Bssid argument");
9764 return 0;
9765 }
9766
9767 ctrl = open_wpa_mon(intf);
9768 if (ctrl == NULL) {
9769 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9770 "wpa_supplicant monitor connection");
9771 return -2;
9772 }
9773
9774 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
9775
9776 if (wpa_command(intf, buf) < 0) {
9777 wpa_ctrl_detach(ctrl);
9778 wpa_ctrl_close(ctrl);
9779 send_resp(dut, conn, SIGMA_ERROR,
9780 "ErrorCode,Failed to start registrar");
9781 return 0;
9782 }
9783
9784 return wps_connection_event(dut, conn, ctrl, intf, 0);
9785}
9786
9787
vamsi krishna9b144002017-09-20 13:28:13 +05309788static int cmd_start_wps_registration(struct sigma_dut *dut,
9789 struct sigma_conn *conn,
9790 struct sigma_cmd *cmd)
9791{
9792 struct wpa_ctrl *ctrl;
9793 const char *intf = get_param(cmd, "Interface");
9794 const char *role, *method;
9795 int res;
9796 char buf[256];
9797 const char *events[] = {
9798 "CTRL-EVENT-CONNECTED",
9799 "WPS-OVERLAP-DETECTED",
9800 "WPS-TIMEOUT",
9801 "WPS-FAIL",
9802 NULL
9803 };
9804
9805 ctrl = open_wpa_mon(intf);
9806 if (!ctrl) {
9807 sigma_dut_print(dut, DUT_MSG_ERROR,
9808 "Failed to open wpa_supplicant monitor connection");
9809 return -2;
9810 }
9811
9812 role = get_param(cmd, "WpsRole");
9813 if (!role) {
9814 send_resp(dut, conn, SIGMA_INVALID,
9815 "ErrorCode,WpsRole not provided");
9816 goto fail;
9817 }
9818
9819 if (strcasecmp(role, "Enrollee") == 0) {
9820 method = get_param(cmd, "WpsConfigMethod");
9821 if (!method) {
9822 send_resp(dut, conn, SIGMA_INVALID,
9823 "ErrorCode,WpsConfigMethod not provided");
9824 goto fail;
9825 }
9826 if (strcasecmp(method, "PBC") == 0) {
9827 if (wpa_command(intf, "WPS_PBC") < 0) {
9828 send_resp(dut, conn, SIGMA_ERROR,
9829 "ErrorCode,Failed to enable PBC");
9830 goto fail;
9831 }
9832 } else {
9833 /* TODO: PIN method */
9834 send_resp(dut, conn, SIGMA_ERROR,
9835 "ErrorCode,Unsupported WpsConfigMethod value");
9836 goto fail;
9837 }
9838 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9839 if (res < 0) {
9840 send_resp(dut, conn, SIGMA_ERROR,
9841 "ErrorCode,WPS connection did not complete");
9842 goto fail;
9843 }
9844 if (strstr(buf, "WPS-TIMEOUT")) {
9845 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
9846 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
9847 send_resp(dut, conn, SIGMA_ERROR,
9848 "ErrorCode,OverlapSession");
9849 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
9850 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
9851 } else {
9852 send_resp(dut, conn, SIGMA_ERROR,
9853 "ErrorCode,WPS operation failed");
9854 }
9855 } else {
9856 /* TODO: Registrar role */
9857 send_resp(dut, conn, SIGMA_ERROR,
9858 "ErrorCode,Unsupported WpsRole value");
9859 }
9860
9861fail:
9862 wpa_ctrl_detach(ctrl);
9863 wpa_ctrl_close(ctrl);
9864 return 0;
9865}
9866
9867
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009868static int req_intf(struct sigma_cmd *cmd)
9869{
9870 return get_param(cmd, "interface") == NULL ? -1 : 0;
9871}
9872
9873
9874void sta_register_cmds(void)
9875{
9876 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
9877 cmd_sta_get_ip_config);
9878 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
9879 cmd_sta_set_ip_config);
9880 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
9881 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
9882 cmd_sta_get_mac_address);
9883 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
9884 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
9885 cmd_sta_verify_ip_connection);
9886 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
9887 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
9888 cmd_sta_set_encryption);
9889 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
9890 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
9891 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
9892 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
9893 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
9894 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
9895 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
9896 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
9897 cmd_sta_set_eapakaprime);
9898 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
9899 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
9900 /* TODO: sta_set_ibss */
9901 /* TODO: sta_set_mode */
9902 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
9903 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
9904 /* TODO: sta_up_load */
9905 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
9906 cmd_sta_preset_testparameters);
9907 /* TODO: sta_set_system */
9908 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
9909 /* TODO: sta_set_rifs_test */
9910 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
9911 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
9912 /* TODO: sta_send_coexist_mgmt */
9913 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
9914 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
9915 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
9916 sigma_dut_reg_cmd("sta_reset_default", req_intf,
9917 cmd_sta_reset_default);
9918 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
9919 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
9920 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
9921 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
9922 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
9923 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
9924 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
9925 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
9926 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
9927 cmd_sta_hs2_associate);
9928 sigma_dut_reg_cmd("sta_add_credential", req_intf,
9929 cmd_sta_add_credential);
9930 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009931 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009932 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
9933 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
9934 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
9935 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
9936 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
9937 cmd_sta_wps_connect_pw_token);
9938 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
9939 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
9940 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +05309941 sigma_dut_reg_cmd("start_wps_registration", req_intf,
9942 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009943}