blob: 7ec8e1dfa5e97ecb027ac98901f9bdf321ad4778 [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
3268static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3269 const char *val)
3270{
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
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003621static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3622 struct sigma_conn *conn,
3623 struct sigma_cmd *cmd)
3624{
3625 const char *intf = get_param(cmd, "Interface");
3626 const char *val;
3627
3628 val = get_param(cmd, "Program");
Peng Xue9fa7952017-05-09 15:59:49 -07003629 if (val && strcasecmp(val, "HS2-R2") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003630 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3631 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003632
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003633 if (val && strcasecmp(val, "LOC") == 0)
3634 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3635
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003636#ifdef ANDROID_NAN
3637 if (val && strcasecmp(val, "NAN") == 0)
3638 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3639#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003640#ifdef MIRACAST
3641 if (val && (strcasecmp(val, "WFD") == 0 ||
3642 strcasecmp(val, "DisplayR2") == 0))
3643 return miracast_preset_testparameters(dut, conn, cmd);
3644#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003645
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303646 if (val && strcasecmp(val, "MBO") == 0) {
3647 val = get_param(cmd, "Cellular_Data_Cap");
3648 if (val &&
3649 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3650 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303651
3652 val = get_param(cmd, "Ch_Pref");
3653 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3654 return 0;
3655
Ashwini Patilc63161e2017-04-13 16:30:23 +05303656 val = get_param(cmd, "BSS_Transition");
3657 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3658 return 0;
3659
Ashwini Patila75de5a2017-04-13 16:35:05 +05303660 val = get_param(cmd, "Assoc_Disallow");
3661 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3662 return 0;
3663
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303664 val = get_param(cmd, "Roaming");
3665 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3666 return 0;
3667
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303668 return 1;
3669 }
3670
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303671 if (val && strcasecmp(val, "OCE") == 0)
3672 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3673
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003674#if 0
3675 val = get_param(cmd, "Supplicant");
3676 if (val && strcasecmp(val, "Default") != 0) {
3677 send_resp(dut, conn, SIGMA_ERROR,
3678 "ErrorCode,Only default(Vendor) supplicant "
3679 "supported");
3680 return 0;
3681 }
3682#endif
3683
3684 val = get_param(cmd, "RTS");
3685 if (val) {
3686 switch (get_driver_type()) {
3687 case DRIVER_ATHEROS:
3688 ath_sta_set_rts(dut, intf, val);
3689 break;
3690 default:
3691#if 0
3692 send_resp(dut, conn, SIGMA_ERROR,
3693 "ErrorCode,Setting RTS not supported");
3694 return 0;
3695#else
3696 sigma_dut_print(dut, DUT_MSG_DEBUG,
3697 "Setting RTS not supported");
3698 break;
3699#endif
3700 }
3701 }
3702
3703#if 0
3704 val = get_param(cmd, "FRGMNT");
3705 if (val) {
3706 /* TODO */
3707 send_resp(dut, conn, SIGMA_ERROR,
3708 "ErrorCode,Setting FRGMNT not supported");
3709 return 0;
3710 }
3711#endif
3712
3713#if 0
3714 val = get_param(cmd, "Preamble");
3715 if (val) {
3716 /* TODO: Long/Short */
3717 send_resp(dut, conn, SIGMA_ERROR,
3718 "ErrorCode,Setting Preamble not supported");
3719 return 0;
3720 }
3721#endif
3722
3723 val = get_param(cmd, "Mode");
3724 if (val) {
3725 if (strcmp(val, "11b") == 0 ||
3726 strcmp(val, "11g") == 0 ||
3727 strcmp(val, "11a") == 0 ||
3728 strcmp(val, "11n") == 0 ||
3729 strcmp(val, "11ng") == 0 ||
3730 strcmp(val, "11nl") == 0 ||
3731 strcmp(val, "11nl(nabg)") == 0 ||
3732 strcmp(val, "AC") == 0 ||
3733 strcmp(val, "11AC") == 0 ||
3734 strcmp(val, "11ac") == 0 ||
3735 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003736 strcmp(val, "11an") == 0 ||
3737 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003738 /* STA supports all modes by default */
3739 } else {
3740 send_resp(dut, conn, SIGMA_ERROR,
3741 "ErrorCode,Setting Mode not supported");
3742 return 0;
3743 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003744
3745 /* Change the mode only in case of testbed for HE program
3746 * and for 11a and 11g modes only. */
3747 if (dut->program == PROGRAM_HE &&
3748 dut->device_type == STA_testbed) {
3749 int phymode;
3750 char buf[60];
3751
3752 if (strcmp(val, "11a") == 0) {
3753 phymode = 1;
3754 } else if (strcmp (val, "11g") == 0) {
3755 phymode = 3;
3756 } else {
3757 sigma_dut_print(dut, DUT_MSG_DEBUG,
3758 "Ignoring mode change for mode: %s",
3759 val);
3760 phymode = -1;
3761 }
3762 if (phymode != -1) {
3763 snprintf(buf, sizeof(buf),
3764 "iwpriv %s setphymode %d",
3765 intf, phymode);
3766 if (system(buf) != 0) {
3767 sigma_dut_print(dut, DUT_MSG_ERROR,
3768 "iwpriv setting of phymode failed");
3769 }
3770 }
3771 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003772 }
3773
3774 val = get_param(cmd, "wmm");
3775 if (val) {
3776 switch (get_driver_type()) {
3777 case DRIVER_ATHEROS:
3778 ath_sta_set_wmm(dut, intf, val);
3779 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003780 case DRIVER_WCN:
3781 wcn_sta_set_wmm(dut, intf, val);
3782 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003783 default:
3784 sigma_dut_print(dut, DUT_MSG_DEBUG,
3785 "Setting wmm not supported");
3786 break;
3787 }
3788 }
3789
3790 val = get_param(cmd, "Powersave");
3791 if (val) {
3792 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3793 if (wpa_command(get_station_ifname(),
3794 "P2P_SET ps 0") < 0)
3795 return -2;
3796 /* Make sure test modes are disabled */
3797 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3798 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3799 } else if (strcmp(val, "1") == 0 ||
3800 strcasecmp(val, "PSPoll") == 0 ||
3801 strcasecmp(val, "on") == 0) {
3802 /* Disable default power save mode */
3803 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3804 /* Enable PS-Poll test mode */
3805 if (wpa_command(get_station_ifname(),
3806 "P2P_SET ps 97") < 0 ||
3807 wpa_command(get_station_ifname(),
3808 "P2P_SET ps 99") < 0)
3809 return -2;
3810 } else if (strcmp(val, "2") == 0 ||
3811 strcasecmp(val, "Fast") == 0) {
3812 /* TODO */
3813 send_resp(dut, conn, SIGMA_ERROR,
3814 "ErrorCode,Powersave=Fast not supported");
3815 return 0;
3816 } else if (strcmp(val, "3") == 0 ||
3817 strcasecmp(val, "PSNonPoll") == 0) {
3818 /* Make sure test modes are disabled */
3819 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3820 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3821
3822 /* Enable default power save mode */
3823 if (wpa_command(get_station_ifname(),
3824 "P2P_SET ps 1") < 0)
3825 return -2;
3826 } else
3827 return -1;
3828 }
3829
3830 val = get_param(cmd, "NoAck");
3831 if (val) {
3832 switch (get_driver_type()) {
3833 case DRIVER_ATHEROS:
3834 ath_sta_set_noack(dut, intf, val);
3835 break;
3836 default:
3837 send_resp(dut, conn, SIGMA_ERROR,
3838 "ErrorCode,Setting NoAck not supported");
3839 return 0;
3840 }
3841 }
3842
3843 val = get_param(cmd, "IgnoreChswitchProhibit");
3844 if (val) {
3845 /* TODO: Enabled/disabled */
3846 if (strcasecmp(val, "Enabled") == 0) {
3847 send_resp(dut, conn, SIGMA_ERROR,
3848 "ErrorCode,Enabling IgnoreChswitchProhibit "
3849 "not supported");
3850 return 0;
3851 }
3852 }
3853
3854 val = get_param(cmd, "TDLS");
3855 if (val) {
3856 if (strcasecmp(val, "Disabled") == 0) {
3857 if (wpa_command(intf, "SET tdls_disabled 1")) {
3858 send_resp(dut, conn, SIGMA_ERROR,
3859 "ErrorCode,Failed to disable TDLS");
3860 return 0;
3861 }
3862 } else if (strcasecmp(val, "Enabled") == 0) {
3863 if (wpa_command(intf, "SET tdls_disabled 0")) {
3864 send_resp(dut, conn, SIGMA_ERROR,
3865 "ErrorCode,Failed to enable TDLS");
3866 return 0;
3867 }
3868 } else {
3869 send_resp(dut, conn, SIGMA_ERROR,
3870 "ErrorCode,Unsupported TDLS value");
3871 return 0;
3872 }
3873 }
3874
3875 val = get_param(cmd, "TDLSmode");
3876 if (val) {
3877 if (strcasecmp(val, "Default") == 0) {
3878 wpa_command(intf, "SET tdls_testing 0");
3879 } else if (strcasecmp(val, "APProhibit") == 0) {
3880 if (wpa_command(intf, "SET tdls_testing 0x400")) {
3881 send_resp(dut, conn, SIGMA_ERROR,
3882 "ErrorCode,Failed to enable ignore "
3883 "APProhibit TDLS mode");
3884 return 0;
3885 }
3886 } else if (strcasecmp(val, "HiLoMac") == 0) {
3887 /* STA should respond with TDLS setup req for a TDLS
3888 * setup req */
3889 if (wpa_command(intf, "SET tdls_testing 0x80")) {
3890 send_resp(dut, conn, SIGMA_ERROR,
3891 "ErrorCode,Failed to enable HiLoMac "
3892 "TDLS mode");
3893 return 0;
3894 }
3895 } else if (strcasecmp(val, "WeakSecurity") == 0) {
3896 /*
3897 * Since all security modes are enabled by default when
3898 * Sigma control is used, there is no need to do
3899 * anything here.
3900 */
3901 } else if (strcasecmp(val, "ExistLink") == 0) {
3902 /*
3903 * Since we allow new TDLS Setup Request even if there
3904 * is an existing link, nothing needs to be done for
3905 * this.
3906 */
3907 } else {
3908 /* TODO:
3909 * ExistLink: STA should send TDLS setup req even if
3910 * direct link already exists
3911 */
3912 send_resp(dut, conn, SIGMA_ERROR,
3913 "ErrorCode,Unsupported TDLSmode value");
3914 return 0;
3915 }
3916 }
3917
3918 val = get_param(cmd, "FakePubKey");
3919 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
3920 send_resp(dut, conn, SIGMA_ERROR,
3921 "ErrorCode,Failed to enable FakePubKey");
3922 return 0;
3923 }
3924
3925 return 1;
3926}
3927
3928
3929static const char * ath_get_radio_name(const char *radio_name)
3930{
3931 if (radio_name == NULL)
3932 return "wifi0";
3933 if (strcmp(radio_name, "wifi1") == 0)
3934 return "wifi1";
3935 if (strcmp(radio_name, "wifi2") == 0)
3936 return "wifi2";
3937 return "wifi0";
3938}
3939
3940
3941static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
3942 const char *val)
3943{
3944 char buf[60];
3945 unsigned int vht_mcsmap = 0;
3946 int txchainmask = 0;
3947 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3948
3949 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3950 if (dut->testbed_flag_txsp == 1) {
3951 vht_mcsmap = 0xfffc;
3952 dut->testbed_flag_txsp = 0;
3953 } else {
3954 vht_mcsmap = 0xfffe;
3955 }
3956 txchainmask = 1;
3957 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3958 if (dut->testbed_flag_txsp == 1) {
3959 vht_mcsmap = 0xfff0;
3960 dut->testbed_flag_txsp = 0;
3961 } else {
3962 vht_mcsmap = 0xfffa;
3963 }
3964 txchainmask = 3;
3965 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3966 if (dut->testbed_flag_txsp == 1) {
3967 vht_mcsmap = 0xffc0;
3968 dut->testbed_flag_txsp = 0;
3969 } else {
3970 vht_mcsmap = 0xffea;
3971 }
3972 txchainmask = 7;
3973 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3974 if (dut->testbed_flag_txsp == 1) {
3975 vht_mcsmap = 0xff00;
3976 dut->testbed_flag_txsp = 0;
3977 } else {
3978 vht_mcsmap = 0xffaa;
3979 }
3980 txchainmask = 15;
3981 } else {
3982 if (dut->testbed_flag_txsp == 1) {
3983 vht_mcsmap = 0xffc0;
3984 dut->testbed_flag_txsp = 0;
3985 } else {
3986 vht_mcsmap = 0xffea;
3987 }
3988 }
3989
3990 if (txchainmask) {
3991 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
3992 basedev, txchainmask);
3993 if (system(buf) != 0) {
3994 sigma_dut_print(dut, DUT_MSG_ERROR,
3995 "iwpriv txchainmask failed");
3996 }
3997 }
3998
3999 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4000 intf, vht_mcsmap);
4001 if (system(buf) != 0) {
4002 sigma_dut_print(dut, DUT_MSG_ERROR,
4003 "iwpriv %s vht_mcsmap 0x%04x failed",
4004 intf, vht_mcsmap);
4005 }
4006}
4007
4008
4009static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4010 const char *val)
4011{
4012 char buf[60];
4013 unsigned int vht_mcsmap = 0;
4014 int rxchainmask = 0;
4015 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4016
4017 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4018 if (dut->testbed_flag_rxsp == 1) {
4019 vht_mcsmap = 0xfffc;
4020 dut->testbed_flag_rxsp = 0;
4021 } else {
4022 vht_mcsmap = 0xfffe;
4023 }
4024 rxchainmask = 1;
4025 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4026 if (dut->testbed_flag_rxsp == 1) {
4027 vht_mcsmap = 0xfff0;
4028 dut->testbed_flag_rxsp = 0;
4029 } else {
4030 vht_mcsmap = 0xfffa;
4031 }
4032 rxchainmask = 3;
4033 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4034 if (dut->testbed_flag_rxsp == 1) {
4035 vht_mcsmap = 0xffc0;
4036 dut->testbed_flag_rxsp = 0;
4037 } else {
4038 vht_mcsmap = 0xffea;
4039 }
4040 rxchainmask = 7;
4041 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4042 if (dut->testbed_flag_rxsp == 1) {
4043 vht_mcsmap = 0xff00;
4044 dut->testbed_flag_rxsp = 0;
4045 } else {
4046 vht_mcsmap = 0xffaa;
4047 }
4048 rxchainmask = 15;
4049 } else {
4050 if (dut->testbed_flag_rxsp == 1) {
4051 vht_mcsmap = 0xffc0;
4052 dut->testbed_flag_rxsp = 0;
4053 } else {
4054 vht_mcsmap = 0xffea;
4055 }
4056 }
4057
4058 if (rxchainmask) {
4059 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4060 basedev, rxchainmask);
4061 if (system(buf) != 0) {
4062 sigma_dut_print(dut, DUT_MSG_ERROR,
4063 "iwpriv rxchainmask failed");
4064 }
4065 }
4066
4067 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4068 intf, vht_mcsmap);
4069 if (system(buf) != 0) {
4070 sigma_dut_print(dut, DUT_MSG_ERROR,
4071 "iwpriv %s vht_mcsmap 0x%04x",
4072 intf, vht_mcsmap);
4073 }
4074}
4075
4076
4077void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4078{
4079 if (strcasecmp(val, "enable") == 0) {
4080 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4081 != 0) {
4082 sigma_dut_print(dut, DUT_MSG_ERROR,
4083 "Disable BB_VHTSIGB_CRC_CALC failed");
4084 }
4085
4086 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4087 != 0) {
4088 sigma_dut_print(dut, DUT_MSG_ERROR,
4089 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4090 }
4091 } else {
4092 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4093 != 0) {
4094 sigma_dut_print(dut, DUT_MSG_ERROR,
4095 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4096 }
4097
4098 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4099 != 0) {
4100 sigma_dut_print(dut, DUT_MSG_ERROR,
4101 "Enable BB_VHTSIGB_CRC_CALC failed");
4102 }
4103 }
4104}
4105
4106
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004107static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4108 const char *val)
4109{
4110 char buf[60];
4111
4112 if (strcmp(val, "20") == 0) {
4113 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4114 dut->chwidth = 0;
4115 } else if (strcmp(val, "40") == 0) {
4116 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4117 dut->chwidth = 1;
4118 } else if (strcmp(val, "80") == 0) {
4119 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4120 dut->chwidth = 2;
4121 } else if (strcmp(val, "Auto") == 0) {
4122 buf[0] = '\0';
4123 } else {
4124 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4125 val);
4126 return -1;
4127 }
4128
4129 if (buf[0] != '\0' && system(buf) != 0) {
4130 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4131 return -1;
4132 }
4133
4134 return 0;
4135}
4136
4137
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004138static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4139 const char *intf, int addbareject)
4140{
4141#ifdef NL80211_SUPPORT
4142 struct nl_msg *msg;
4143 int ret = 0;
4144 struct nlattr *params;
4145 int ifindex;
4146
4147 ifindex = if_nametoindex(intf);
4148 if (ifindex == 0) {
4149 sigma_dut_print(dut, DUT_MSG_ERROR,
4150 "%s: Index for interface %s failed",
4151 __func__, intf);
4152 return -1;
4153 }
4154
4155 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4156 NL80211_CMD_VENDOR)) ||
4157 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4158 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4159 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4160 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4161 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4162 nla_put_u8(msg,
4163 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4164 !addbareject)) {
4165 sigma_dut_print(dut, DUT_MSG_ERROR,
4166 "%s: err in adding vendor_cmd and vendor_data",
4167 __func__);
4168 nlmsg_free(msg);
4169 return -1;
4170 }
4171 nla_nest_end(msg, params);
4172
4173 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4174 if (ret) {
4175 sigma_dut_print(dut, DUT_MSG_ERROR,
4176 "%s: err in send_and_recv_msgs, ret=%d",
4177 __func__, ret);
4178 }
4179 return ret;
4180#else /* NL80211_SUPPORT */
4181 sigma_dut_print(dut, DUT_MSG_ERROR,
4182 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4183 return -1;
4184#endif /* NL80211_SUPPORT */
4185}
4186
4187
4188static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4189 int addbareject)
4190{
4191 int ret;
4192
4193 switch (get_driver_type()) {
4194 case DRIVER_WCN:
4195 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4196 if (ret) {
4197 sigma_dut_print(dut, DUT_MSG_ERROR,
4198 "nlvendor_sta_set_addba_reject failed, ret:%d",
4199 ret);
4200 return ret;
4201 }
4202 break;
4203 default:
4204 sigma_dut_print(dut, DUT_MSG_ERROR,
4205 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4206 ret = -1;
4207 break;
4208 }
4209
4210 return ret;
4211}
4212
4213
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004214static int nlvendor_disable_addba(struct sigma_dut *dut, const char *intf)
4215{
4216#ifdef NL80211_SUPPORT
4217 struct nl_msg *msg;
4218 int ret = 0;
4219 struct nlattr *params;
4220 int ifindex;
4221
4222 ifindex = if_nametoindex(intf);
4223 if (ifindex == 0) {
4224 sigma_dut_print(dut, DUT_MSG_ERROR,
4225 "%s: Index for interface %s failed",
4226 __func__, intf);
4227 return -1;
4228 }
4229
4230 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4231 NL80211_CMD_VENDOR)) ||
4232 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4233 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4234 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4235 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4236 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4237 nla_put_u8(msg,
4238 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
4239 0)) {
4240 sigma_dut_print(dut, DUT_MSG_ERROR,
4241 "%s: err in adding vendor_cmd and vendor_data",
4242 __func__);
4243 nlmsg_free(msg);
4244 return -1;
4245 }
4246 nla_nest_end(msg, params);
4247
4248 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4249 if (ret) {
4250 sigma_dut_print(dut, DUT_MSG_ERROR,
4251 "%s: err in send_and_recv_msgs, ret=%d",
4252 __func__, ret);
4253 }
4254 return ret;
4255#else /* NL80211_SUPPORT */
4256 sigma_dut_print(dut, DUT_MSG_ERROR,
4257 "Disable addba not possible without NL80211_SUPPORT defined");
4258 return -1;
4259#endif /* NL80211_SUPPORT */
4260}
4261
4262
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004263static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4264 struct sigma_conn *conn,
4265 struct sigma_cmd *cmd)
4266{
4267 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004268 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004269 char buf[30];
4270
4271 val = get_param(cmd, "40_INTOLERANT");
4272 if (val) {
4273 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4274 /* TODO: iwpriv ht40intol through wpa_supplicant */
4275 send_resp(dut, conn, SIGMA_ERROR,
4276 "ErrorCode,40_INTOLERANT not supported");
4277 return 0;
4278 }
4279 }
4280
4281 val = get_param(cmd, "ADDBA_REJECT");
4282 if (val) {
4283 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4284 /* reject any ADDBA with status "decline" */
4285 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004286 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004287 } else {
4288 /* accept ADDBA */
4289 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004290 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004291 }
4292 }
4293
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004294 if (addbareject >= 0 &&
4295 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4296 send_resp(dut, conn, SIGMA_ERROR,
4297 "ErrorCode,set addba_reject failed");
4298 return 0;
4299 }
4300
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004301 val = get_param(cmd, "AMPDU");
4302 if (val) {
4303 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4304 /* enable AMPDU Aggregation */
4305 if (ampdu == 0) {
4306 send_resp(dut, conn, SIGMA_ERROR,
4307 "ErrorCode,Mismatch in "
4308 "addba_reject/ampdu - "
4309 "not supported");
4310 return 0;
4311 }
4312 ampdu = 1;
4313 } else {
4314 /* disable AMPDU Aggregation */
4315 if (ampdu == 1) {
4316 send_resp(dut, conn, SIGMA_ERROR,
4317 "ErrorCode,Mismatch in "
4318 "addba_reject/ampdu - "
4319 "not supported");
4320 return 0;
4321 }
4322 ampdu = 0;
4323 }
4324 }
4325
4326 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004327 int ret;
4328
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004329 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4330 ampdu ? "Enabling" : "Disabling");
4331 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004332 if (wpa_command(intf, buf) < 0 &&
4333 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004334 send_resp(dut, conn, SIGMA_ERROR,
4335 "ErrorCode,set aggr failed");
4336 return 0;
4337 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004338
4339 if (ampdu == 0) {
4340 /* Disable sending of addba using nl vendor command */
4341 ret = nlvendor_disable_addba(dut, intf);
4342 if (ret) {
4343 sigma_dut_print(dut, DUT_MSG_ERROR,
4344 "Failed to disable addba, ret:%d",
4345 ret);
4346 }
4347 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004348 }
4349
4350 val = get_param(cmd, "AMSDU");
4351 if (val) {
4352 switch (get_driver_type()) {
4353 case DRIVER_ATHEROS:
4354 ath_sta_set_amsdu(dut, intf, val);
4355 break;
4356 default:
4357 if (strcmp(val, "1") == 0 ||
4358 strcasecmp(val, "Enable") == 0) {
4359 /* Enable AMSDU Aggregation */
4360 send_resp(dut, conn, SIGMA_ERROR,
4361 "ErrorCode,AMSDU aggregation not supported");
4362 return 0;
4363 }
4364 break;
4365 }
4366 }
4367
4368 val = get_param(cmd, "STBC_RX");
4369 if (val) {
4370 switch (get_driver_type()) {
4371 case DRIVER_ATHEROS:
4372 ath_sta_set_stbc(dut, intf, val);
4373 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304374 case DRIVER_WCN:
4375 wcn_sta_set_stbc(dut, intf, val);
4376 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 default:
4378 send_resp(dut, conn, SIGMA_ERROR,
4379 "ErrorCode,STBC_RX not supported");
4380 return 0;
4381 }
4382 }
4383
4384 val = get_param(cmd, "WIDTH");
4385 if (val) {
4386 switch (get_driver_type()) {
4387 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004388 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004389 send_resp(dut, conn, SIGMA_ERROR,
4390 "ErrorCode,Failed to set WIDTH");
4391 return 0;
4392 }
4393 break;
4394 case DRIVER_ATHEROS:
4395 if (ath_set_width(dut, conn, intf, val) < 0)
4396 return 0;
4397 break;
4398 default:
4399 sigma_dut_print(dut, DUT_MSG_ERROR,
4400 "Setting WIDTH not supported");
4401 break;
4402 }
4403 }
4404
4405 val = get_param(cmd, "SMPS");
4406 if (val) {
4407 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4408 send_resp(dut, conn, SIGMA_ERROR,
4409 "ErrorCode,SMPS not supported");
4410 return 0;
4411 }
4412
4413 val = get_param(cmd, "TXSP_STREAM");
4414 if (val) {
4415 switch (get_driver_type()) {
4416 case DRIVER_WCN:
4417 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4418 send_resp(dut, conn, SIGMA_ERROR,
4419 "ErrorCode,Failed to set TXSP_STREAM");
4420 return 0;
4421 }
4422 break;
4423 case DRIVER_ATHEROS:
4424 ath_sta_set_txsp_stream(dut, intf, val);
4425 break;
4426 default:
4427 sigma_dut_print(dut, DUT_MSG_ERROR,
4428 "Setting TXSP_STREAM not supported");
4429 break;
4430 }
4431 }
4432
4433 val = get_param(cmd, "RXSP_STREAM");
4434 if (val) {
4435 switch (get_driver_type()) {
4436 case DRIVER_WCN:
4437 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4438 send_resp(dut, conn, SIGMA_ERROR,
4439 "ErrorCode,Failed to set RXSP_STREAM");
4440 return 0;
4441 }
4442 break;
4443 case DRIVER_ATHEROS:
4444 ath_sta_set_rxsp_stream(dut, intf, val);
4445 break;
4446 default:
4447 sigma_dut_print(dut, DUT_MSG_ERROR,
4448 "Setting RXSP_STREAM not supported");
4449 break;
4450 }
4451 }
4452
4453 val = get_param(cmd, "DYN_BW_SGNL");
4454 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004455 switch (get_driver_type()) {
4456 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004457 if (strcasecmp(val, "enable") == 0) {
4458 snprintf(buf, sizeof(buf),
4459 "iwpriv %s cwmenable 1", intf);
4460 if (system(buf) != 0) {
4461 sigma_dut_print(dut, DUT_MSG_ERROR,
4462 "iwpriv cwmenable 1 failed");
4463 return 0;
4464 }
4465 } else if (strcasecmp(val, "disable") == 0) {
4466 snprintf(buf, sizeof(buf),
4467 "iwpriv %s cwmenable 0", intf);
4468 if (system(buf) != 0) {
4469 sigma_dut_print(dut, DUT_MSG_ERROR,
4470 "iwpriv cwmenable 0 failed");
4471 return 0;
4472 }
4473 } else {
4474 sigma_dut_print(dut, DUT_MSG_ERROR,
4475 "Unsupported DYN_BW_SGL");
4476 }
4477
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004478 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4479 if (system(buf) != 0) {
4480 sigma_dut_print(dut, DUT_MSG_ERROR,
4481 "Failed to set cts_cbw in DYN_BW_SGNL");
4482 return 0;
4483 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004484 break;
4485 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004486 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004487 ath_config_dyn_bw_sig(dut, intf, val);
4488 break;
4489 default:
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Failed to set DYN_BW_SGNL");
4492 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004493 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004494 }
4495
4496 val = get_param(cmd, "RTS_FORCE");
4497 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004498 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004499 if (strcasecmp(val, "Enable") == 0) {
4500 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004501 if (system(buf) != 0) {
4502 sigma_dut_print(dut, DUT_MSG_ERROR,
4503 "Failed to set RTS_FORCE 64");
4504 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004505 snprintf(buf, sizeof(buf),
4506 "wifitool %s beeliner_fw_test 100 1", intf);
4507 if (system(buf) != 0) {
4508 sigma_dut_print(dut, DUT_MSG_ERROR,
4509 "wifitool beeliner_fw_test 100 1 failed");
4510 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004511 } else if (strcasecmp(val, "Disable") == 0) {
4512 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4513 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004514 if (system(buf) != 0) {
4515 sigma_dut_print(dut, DUT_MSG_ERROR,
4516 "Failed to set RTS_FORCE 2347");
4517 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004518 } else {
4519 send_resp(dut, conn, SIGMA_ERROR,
4520 "ErrorCode,RTS_FORCE value not supported");
4521 return 0;
4522 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004523 }
4524
4525 val = get_param(cmd, "CTS_WIDTH");
4526 if (val) {
4527 switch (get_driver_type()) {
4528 case DRIVER_WCN:
4529 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4530 send_resp(dut, conn, SIGMA_ERROR,
4531 "ErrorCode,Failed to set CTS_WIDTH");
4532 return 0;
4533 }
4534 break;
4535 case DRIVER_ATHEROS:
4536 ath_set_cts_width(dut, intf, val);
4537 break;
4538 default:
4539 sigma_dut_print(dut, DUT_MSG_ERROR,
4540 "Setting CTS_WIDTH not supported");
4541 break;
4542 }
4543 }
4544
4545 val = get_param(cmd, "BW_SGNL");
4546 if (val) {
4547 if (strcasecmp(val, "Enable") == 0) {
4548 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4549 intf);
4550 } else if (strcasecmp(val, "Disable") == 0) {
4551 /* TODO: Disable */
4552 buf[0] = '\0';
4553 } else {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,BW_SGNL value not supported");
4556 return 0;
4557 }
4558
4559 if (buf[0] != '\0' && system(buf) != 0) {
4560 sigma_dut_print(dut, DUT_MSG_ERROR,
4561 "Failed to set BW_SGNL");
4562 }
4563 }
4564
4565 val = get_param(cmd, "Band");
4566 if (val) {
4567 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4568 /* STA supports all bands by default */
4569 } else {
4570 send_resp(dut, conn, SIGMA_ERROR,
4571 "ErrorCode,Unsupported Band");
4572 return 0;
4573 }
4574 }
4575
4576 val = get_param(cmd, "zero_crc");
4577 if (val) {
4578 switch (get_driver_type()) {
4579 case DRIVER_ATHEROS:
4580 ath_set_zero_crc(dut, val);
4581 break;
4582 default:
4583 break;
4584 }
4585 }
4586
4587 return 1;
4588}
4589
4590
4591static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4592 struct sigma_cmd *cmd)
4593{
4594 const char *val;
4595 char buf[100];
4596
4597 val = get_param(cmd, "MSDUSize");
4598 if (val) {
4599 int mtu;
4600
4601 dut->amsdu_size = atoi(val);
4602 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4603 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4604 sigma_dut_print(dut, DUT_MSG_ERROR,
4605 "MSDUSize %d is above max %d or below min %d",
4606 dut->amsdu_size,
4607 IEEE80211_MAX_DATA_LEN_DMG,
4608 IEEE80211_SNAP_LEN_DMG);
4609 dut->amsdu_size = 0;
4610 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4611 }
4612
4613 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4614 sigma_dut_print(dut, DUT_MSG_DEBUG,
4615 "Setting amsdu_size to %d", mtu);
4616 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4617 get_station_ifname(), mtu);
4618
4619 if (system(buf) != 0) {
4620 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4621 buf);
4622 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4623 }
4624 }
4625
4626 val = get_param(cmd, "BAckRcvBuf");
4627 if (val) {
4628 dut->back_rcv_buf = atoi(val);
4629 if (dut->back_rcv_buf == 0) {
4630 sigma_dut_print(dut, DUT_MSG_ERROR,
4631 "Failed to convert %s or value is 0",
4632 val);
4633 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4634 }
4635
4636 sigma_dut_print(dut, DUT_MSG_DEBUG,
4637 "Setting BAckRcvBuf to %s", val);
4638 }
4639
4640 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4641}
4642
4643
4644static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4645 struct sigma_cmd *cmd)
4646{
4647 int net_id;
4648 char *ifname;
4649 const char *val;
4650 char buf[100];
4651
4652 dut->mode = SIGMA_MODE_STATION;
4653 ifname = get_main_ifname();
4654 if (wpa_command(ifname, "PING") != 0) {
4655 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4656 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4657 }
4658
4659 wpa_command(ifname, "FLUSH");
4660 net_id = add_network_common(dut, conn, ifname, cmd);
4661 if (net_id < 0) {
4662 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4663 return net_id;
4664 }
4665
4666 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4667 if (set_network(ifname, net_id, "mode", "2") < 0) {
4668 sigma_dut_print(dut, DUT_MSG_ERROR,
4669 "Failed to set supplicant network mode");
4670 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4671 }
4672
4673 sigma_dut_print(dut, DUT_MSG_DEBUG,
4674 "Supplicant set network with mode 2");
4675
4676 val = get_param(cmd, "Security");
4677 if (val && strcasecmp(val, "OPEN") == 0) {
4678 dut->ap_key_mgmt = AP_OPEN;
4679 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4680 sigma_dut_print(dut, DUT_MSG_ERROR,
4681 "Failed to set supplicant to %s security",
4682 val);
4683 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4684 }
4685 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4686 dut->ap_key_mgmt = AP_WPA2_PSK;
4687 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4688 sigma_dut_print(dut, DUT_MSG_ERROR,
4689 "Failed to set supplicant to %s security",
4690 val);
4691 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4692 }
4693
4694 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "Failed to set supplicant to proto RSN");
4697 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4698 }
4699 } else if (val) {
4700 sigma_dut_print(dut, DUT_MSG_ERROR,
4701 "Requested Security %s is not supported on 60GHz",
4702 val);
4703 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4704 }
4705
4706 val = get_param(cmd, "Encrypt");
4707 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4708 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4709 sigma_dut_print(dut, DUT_MSG_ERROR,
4710 "Failed to set supplicant to pairwise GCMP");
4711 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4712 }
4713 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4714 sigma_dut_print(dut, DUT_MSG_ERROR,
4715 "Failed to set supplicant to group GCMP");
4716 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4717 }
4718 } else if (val) {
4719 sigma_dut_print(dut, DUT_MSG_ERROR,
4720 "Requested Encrypt %s is not supported on 60 GHz",
4721 val);
4722 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4723 }
4724
4725 val = get_param(cmd, "PSK");
4726 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4727 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4728 val);
4729 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4730 }
4731
4732 /* Convert 60G channel to freq */
4733 switch (dut->ap_channel) {
4734 case 1:
4735 val = "58320";
4736 break;
4737 case 2:
4738 val = "60480";
4739 break;
4740 case 3:
4741 val = "62640";
4742 break;
4743 default:
4744 sigma_dut_print(dut, DUT_MSG_ERROR,
4745 "Failed to configure channel %d. Not supported",
4746 dut->ap_channel);
4747 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4748 }
4749
4750 if (set_network(ifname, net_id, "frequency", val) < 0) {
4751 sigma_dut_print(dut, DUT_MSG_ERROR,
4752 "Failed to set supplicant network frequency");
4753 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4754 }
4755
4756 sigma_dut_print(dut, DUT_MSG_DEBUG,
4757 "Supplicant set network with frequency");
4758
4759 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4760 if (wpa_command(ifname, buf) < 0) {
4761 sigma_dut_print(dut, DUT_MSG_INFO,
4762 "Failed to select network id %d on %s",
4763 net_id, ifname);
4764 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4765 }
4766
4767 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4768
4769 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4770}
4771
4772
Lior David67543f52017-01-03 19:04:22 +02004773static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4774{
4775 char buf[128], fname[128];
4776 FILE *f;
4777
4778 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4779 sigma_dut_print(dut, DUT_MSG_ERROR,
4780 "failed to get wil6210 debugfs dir");
4781 return -1;
4782 }
4783
4784 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4785 f = fopen(fname, "w");
4786 if (!f) {
4787 sigma_dut_print(dut, DUT_MSG_ERROR,
4788 "failed to open: %s", fname);
4789 return -1;
4790 }
4791
4792 fprintf(f, "%d\n", abft_len);
4793 fclose(f);
4794
4795 return 0;
4796}
4797
4798
4799static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4800 int abft_len)
4801{
4802 switch (get_driver_type()) {
4803 case DRIVER_WIL6210:
4804 return wil6210_set_abft_len(dut, abft_len);
4805 default:
4806 sigma_dut_print(dut, DUT_MSG_ERROR,
4807 "set abft_len not supported");
4808 return -1;
4809 }
4810}
4811
4812
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004813static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4814 struct sigma_cmd *cmd)
4815{
4816 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004817 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004818
4819 if (dut->dev_role != DEVROLE_PCP) {
4820 send_resp(dut, conn, SIGMA_INVALID,
4821 "ErrorCode,Invalid DevRole");
4822 return 0;
4823 }
4824
4825 val = get_param(cmd, "SSID");
4826 if (val) {
4827 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4828 send_resp(dut, conn, SIGMA_INVALID,
4829 "ErrorCode,Invalid SSID");
4830 return -1;
4831 }
4832
Peng Xub8fc5cc2017-05-10 17:27:28 -07004833 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004834 }
4835
4836 val = get_param(cmd, "CHANNEL");
4837 if (val) {
4838 const char *pos;
4839
4840 dut->ap_channel = atoi(val);
4841 pos = strchr(val, ';');
4842 if (pos) {
4843 pos++;
4844 dut->ap_channel_1 = atoi(pos);
4845 }
4846 }
4847
4848 switch (dut->ap_channel) {
4849 case 1:
4850 case 2:
4851 case 3:
4852 break;
4853 default:
4854 sigma_dut_print(dut, DUT_MSG_ERROR,
4855 "Channel %d is not supported", dut->ap_channel);
4856 send_resp(dut, conn, SIGMA_ERROR,
4857 "Requested channel is not supported");
4858 return -1;
4859 }
4860
4861 val = get_param(cmd, "BCNINT");
4862 if (val)
4863 dut->ap_bcnint = atoi(val);
4864
4865
4866 val = get_param(cmd, "ExtSchIE");
4867 if (val) {
4868 send_resp(dut, conn, SIGMA_ERROR,
4869 "ErrorCode,ExtSchIE is not supported yet");
4870 return -1;
4871 }
4872
4873 val = get_param(cmd, "AllocType");
4874 if (val) {
4875 send_resp(dut, conn, SIGMA_ERROR,
4876 "ErrorCode,AllocType is not supported yet");
4877 return -1;
4878 }
4879
4880 val = get_param(cmd, "PercentBI");
4881 if (val) {
4882 send_resp(dut, conn, SIGMA_ERROR,
4883 "ErrorCode,PercentBI is not supported yet");
4884 return -1;
4885 }
4886
4887 val = get_param(cmd, "CBAPOnly");
4888 if (val) {
4889 send_resp(dut, conn, SIGMA_ERROR,
4890 "ErrorCode,CBAPOnly is not supported yet");
4891 return -1;
4892 }
4893
4894 val = get_param(cmd, "AMPDU");
4895 if (val) {
4896 if (strcasecmp(val, "Enable") == 0)
4897 dut->ap_ampdu = 1;
4898 else if (strcasecmp(val, "Disable") == 0)
4899 dut->ap_ampdu = 2;
4900 else {
4901 send_resp(dut, conn, SIGMA_ERROR,
4902 "ErrorCode,AMPDU value is not Enable nor Disabled");
4903 return -1;
4904 }
4905 }
4906
4907 val = get_param(cmd, "AMSDU");
4908 if (val) {
4909 if (strcasecmp(val, "Enable") == 0)
4910 dut->ap_amsdu = 1;
4911 else if (strcasecmp(val, "Disable") == 0)
4912 dut->ap_amsdu = 2;
4913 }
4914
4915 val = get_param(cmd, "NumMSDU");
4916 if (val) {
4917 send_resp(dut, conn, SIGMA_ERROR,
4918 "ErrorCode, NumMSDU is not supported yet");
4919 return -1;
4920 }
4921
4922 val = get_param(cmd, "ABFTLRang");
4923 if (val) {
4924 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004925 "ABFTLRang parameter %s", val);
4926 if (strcmp(val, "Gt1") == 0)
4927 abft_len = 2; /* 2 slots in this case */
4928 }
4929
4930 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4931 send_resp(dut, conn, SIGMA_ERROR,
4932 "ErrorCode, Can't set ABFT length");
4933 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004934 }
4935
4936 if (sta_pcp_start(dut, conn, cmd) < 0) {
4937 send_resp(dut, conn, SIGMA_ERROR,
4938 "ErrorCode, Can't start PCP role");
4939 return -1;
4940 }
4941
4942 return sta_set_60g_common(dut, conn, cmd);
4943}
4944
4945
4946static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
4947 struct sigma_cmd *cmd)
4948{
4949 const char *val = get_param(cmd, "DiscoveryMode");
4950
4951 if (dut->dev_role != DEVROLE_STA) {
4952 send_resp(dut, conn, SIGMA_INVALID,
4953 "ErrorCode,Invalid DevRole");
4954 return 0;
4955 }
4956
4957 if (val) {
4958 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
4959 /* Ignore Discovery mode till Driver expose API. */
4960#if 0
4961 if (strcasecmp(val, "1") == 0) {
4962 send_resp(dut, conn, SIGMA_INVALID,
4963 "ErrorCode,DiscoveryMode 1 not supported");
4964 return 0;
4965 }
4966
4967 if (strcasecmp(val, "0") == 0) {
4968 /* OK */
4969 } else {
4970 send_resp(dut, conn, SIGMA_INVALID,
4971 "ErrorCode,DiscoveryMode not supported");
4972 return 0;
4973 }
4974#endif
4975 }
4976
4977 if (start_sta_mode(dut) != 0)
4978 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4979 return sta_set_60g_common(dut, conn, cmd);
4980}
4981
4982
4983static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
4984 struct sigma_cmd *cmd)
4985{
4986 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02004987 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05304988
Jouni Malinened77e672018-01-10 16:45:13 +02004989 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08004990 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02004991 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05304992 wpa_command(intf, "DISCONNECT");
4993 return 1;
4994 }
4995
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004996 disconnect_station(dut);
4997 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
4998 * due to cached results. */
4999 wpa_command(intf, "SET ignore_old_scan_res 1");
5000 wpa_command(intf, "BSS_FLUSH");
5001 return 1;
5002}
5003
5004
5005static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5006 struct sigma_cmd *cmd)
5007{
5008 const char *intf = get_param(cmd, "Interface");
5009 const char *bssid = get_param(cmd, "bssid");
5010 const char *val = get_param(cmd, "CHANNEL");
5011 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305012 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305013 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005014 int res;
5015 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305016 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305017 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005018
5019 if (bssid == NULL) {
5020 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5021 "argument");
5022 return 0;
5023 }
5024
5025 if (val)
5026 chan = atoi(val);
5027
5028 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5029 /* The current network may be from sta_associate or
5030 * sta_hs2_associate
5031 */
5032 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5033 0 ||
5034 set_network(intf, 0, "bssid", bssid) < 0)
5035 return -2;
5036 }
5037
5038 ctrl = open_wpa_mon(intf);
5039 if (ctrl == NULL) {
5040 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5041 "wpa_supplicant monitor connection");
5042 return -1;
5043 }
5044
Sunil Duttd30ce092018-01-11 23:56:29 +05305045 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5046 sizeof(result)) < 0 ||
5047 strncmp(result, "COMPLETED", 9) != 0) {
5048 sigma_dut_print(dut, DUT_MSG_DEBUG,
5049 "sta_reassoc: Not connected");
5050 fastreassoc = 0;
5051 }
5052
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305053 if (dut->rsne_override) {
5054#ifdef NL80211_SUPPORT
5055 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5056 sta_config_rsnie(dut, 1);
5057 dut->config_rsnie = 1;
5058 }
5059#endif /* NL80211_SUPPORT */
5060 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5061 dut->rsne_override);
5062 if (wpa_command(intf, buf) < 0) {
5063 send_resp(dut, conn, SIGMA_ERROR,
5064 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5065 return 0;
5066 }
5067 }
5068
Sunil Duttd30ce092018-01-11 23:56:29 +05305069 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005070#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305071 if (chan) {
5072 unsigned int freq;
5073
5074 freq = channel_to_freq(chan);
5075 if (!freq) {
5076 sigma_dut_print(dut, DUT_MSG_ERROR,
5077 "Invalid channel number provided: %d",
5078 chan);
5079 send_resp(dut, conn, SIGMA_INVALID,
5080 "ErrorCode,Invalid channel number");
5081 goto close_mon_conn;
5082 }
5083 res = snprintf(buf, sizeof(buf),
5084 "SCAN TYPE=ONLY freq=%d", freq);
5085 } else {
5086 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5087 }
5088 if (res < 0 || res >= (int) sizeof(buf)) {
5089 send_resp(dut, conn, SIGMA_ERROR,
5090 "ErrorCode,snprintf failed");
5091 goto close_mon_conn;
5092 }
5093 if (wpa_command(intf, buf) < 0) {
5094 sigma_dut_print(dut, DUT_MSG_INFO,
5095 "Failed to start scan");
5096 send_resp(dut, conn, SIGMA_ERROR,
5097 "ErrorCode,scan failed");
5098 goto close_mon_conn;
5099 }
5100
5101 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5102 buf, sizeof(buf));
5103 if (res < 0) {
5104 sigma_dut_print(dut, DUT_MSG_INFO,
5105 "Scan did not complete");
5106 send_resp(dut, conn, SIGMA_ERROR,
5107 "ErrorCode,scan did not complete");
5108 goto close_mon_conn;
5109 }
5110
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005111 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5112 < 0) {
5113 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5114 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305115 status = -2;
5116 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117 }
5118 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5119 bssid, chan);
5120 if (res > 0 && res < (int) sizeof(buf))
5121 res = wpa_command(intf, buf);
5122
5123 if (res < 0 || res >= (int) sizeof(buf)) {
5124 send_resp(dut, conn, SIGMA_ERROR,
5125 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305126 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005127 }
5128#else /* ANDROID */
5129 sigma_dut_print(dut, DUT_MSG_DEBUG,
5130 "Reassoc using iwpriv - skip chan=%d info",
5131 chan);
5132 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5133 if (system(buf) != 0) {
5134 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305135 status = -2;
5136 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005137 }
5138#endif /* ANDROID */
5139 sigma_dut_print(dut, DUT_MSG_INFO,
5140 "sta_reassoc: Run %s successful", buf);
5141 } else if (wpa_command(intf, "REASSOCIATE")) {
5142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5143 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305144 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005145 }
5146
5147 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5148 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305149 if (res < 0) {
5150 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5151 status = -1;
5152 goto close_mon_conn;
5153 }
5154 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155
Ashwini Patil467efef2017-05-25 12:18:27 +05305156close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005157 wpa_ctrl_detach(ctrl);
5158 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305159 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005160}
5161
5162
5163static void hs2_clear_credentials(const char *intf)
5164{
5165 wpa_command(intf, "REMOVE_CRED all");
5166}
5167
5168
Lior Davidcc88b562017-01-03 18:52:09 +02005169#ifdef __linux__
5170static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5171 unsigned int *aid)
5172{
Lior David0fe101e2017-03-09 16:09:50 +02005173 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005174
Lior David0fe101e2017-03-09 16:09:50 +02005175 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005176}
5177#endif /* __linux__ */
5178
5179
5180static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5181 unsigned int *aid)
5182{
5183 switch (get_driver_type()) {
5184#ifdef __linux__
5185 case DRIVER_WIL6210:
5186 return wil6210_get_aid(dut, bssid, aid);
5187#endif /* __linux__ */
5188 default:
5189 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5190 return -1;
5191 }
5192}
5193
5194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005195static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5196 struct sigma_cmd *cmd)
5197{
5198 char buf[MAX_CMD_LEN];
5199 char bss_list[MAX_CMD_LEN];
5200 const char *parameter = get_param(cmd, "Parameter");
5201
5202 if (parameter == NULL)
5203 return -1;
5204
Lior Davidcc88b562017-01-03 18:52:09 +02005205 if (strcasecmp(parameter, "AID") == 0) {
5206 unsigned int aid = 0;
5207 char bssid[20];
5208
5209 if (get_wpa_status(get_station_ifname(), "bssid",
5210 bssid, sizeof(bssid)) < 0) {
5211 sigma_dut_print(dut, DUT_MSG_ERROR,
5212 "could not get bssid");
5213 return -2;
5214 }
5215
5216 if (sta_get_aid_60g(dut, bssid, &aid))
5217 return -2;
5218
5219 snprintf(buf, sizeof(buf), "aid,%d", aid);
5220 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5221 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5222 return 0;
5223 }
5224
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005225 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5226 char *bss_line;
5227 char *bss_id = NULL;
5228 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305229 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005230
5231 if (ifname == NULL) {
5232 sigma_dut_print(dut, DUT_MSG_INFO,
5233 "For get DiscoveredDevList need Interface name.");
5234 return -1;
5235 }
5236
5237 /*
5238 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5239 * of BSSIDs in "bssid=<BSSID>\n"
5240 */
5241 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5242 bss_list,
5243 sizeof(bss_list)) < 0) {
5244 sigma_dut_print(dut, DUT_MSG_ERROR,
5245 "Failed to get bss list");
5246 return -1;
5247 }
5248
5249 sigma_dut_print(dut, DUT_MSG_DEBUG,
5250 "bss list for ifname:%s is:%s",
5251 ifname, bss_list);
5252
5253 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305254 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005255 while (bss_line) {
5256 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5257 bss_id) {
5258 int len;
5259
5260 len = snprintf(buf + strlen(buf),
5261 sizeof(buf) - strlen(buf),
5262 ",%s", bss_id);
5263 free(bss_id);
5264 bss_id = NULL;
5265 if (len < 0) {
5266 sigma_dut_print(dut,
5267 DUT_MSG_ERROR,
5268 "Failed to read BSSID");
5269 send_resp(dut, conn, SIGMA_ERROR,
5270 "ErrorCode,Failed to read BSS ID");
5271 return 0;
5272 }
5273
5274 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5275 sigma_dut_print(dut,
5276 DUT_MSG_ERROR,
5277 "Response buf too small for list");
5278 send_resp(dut, conn,
5279 SIGMA_ERROR,
5280 "ErrorCode,Response buf too small for list");
5281 return 0;
5282 }
5283 }
5284
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305285 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005286 }
5287
5288 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5289 buf);
5290 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5291 return 0;
5292 }
5293
5294 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5295 return 0;
5296}
5297
5298
5299static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5300 struct sigma_cmd *cmd)
5301{
5302 const char *program = get_param(cmd, "Program");
5303
5304 if (program == NULL)
5305 return -1;
5306
5307 if (strcasecmp(program, "P2PNFC") == 0)
5308 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5309
5310 if (strcasecmp(program, "60ghz") == 0)
5311 return sta_get_parameter_60g(dut, conn, cmd);
5312
5313#ifdef ANDROID_NAN
5314 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005315 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005316#endif /* ANDROID_NAN */
5317
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005318#ifdef MIRACAST
5319 if (strcasecmp(program, "WFD") == 0 ||
5320 strcasecmp(program, "DisplayR2") == 0)
5321 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5322#endif /* MIRACAST */
5323
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005324 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5325 return 0;
5326}
5327
5328
5329static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5330 const char *type)
5331{
5332 char buf[100];
5333
5334 if (dut->program == PROGRAM_VHT) {
5335 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5336 if (system(buf) != 0) {
5337 sigma_dut_print(dut, DUT_MSG_ERROR,
5338 "iwpriv %s chwidth failed", intf);
5339 }
5340
5341 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5342 if (system(buf) != 0) {
5343 sigma_dut_print(dut, DUT_MSG_ERROR,
5344 "iwpriv %s mode 11ACVHT80 failed",
5345 intf);
5346 }
5347
5348 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5349 if (system(buf) != 0) {
5350 sigma_dut_print(dut, DUT_MSG_ERROR,
5351 "iwpriv %s vhtmcs -1 failed", intf);
5352 }
5353 }
5354
5355 if (dut->program == PROGRAM_HT) {
5356 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5357 if (system(buf) != 0) {
5358 sigma_dut_print(dut, DUT_MSG_ERROR,
5359 "iwpriv %s chwidth failed", intf);
5360 }
5361
5362 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5363 if (system(buf) != 0) {
5364 sigma_dut_print(dut, DUT_MSG_ERROR,
5365 "iwpriv %s mode 11naht40 failed",
5366 intf);
5367 }
5368
5369 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5370 if (system(buf) != 0) {
5371 sigma_dut_print(dut, DUT_MSG_ERROR,
5372 "iwpriv set11NRates failed");
5373 }
5374 }
5375
5376 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5377 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5378 if (system(buf) != 0) {
5379 sigma_dut_print(dut, DUT_MSG_ERROR,
5380 "disabling powersave failed");
5381 }
5382
5383 /* Reset CTS width */
5384 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5385 intf);
5386 if (system(buf) != 0) {
5387 sigma_dut_print(dut, DUT_MSG_ERROR,
5388 "wifitool %s beeliner_fw_test 54 0 failed",
5389 intf);
5390 }
5391
5392 /* Enable Dynamic Bandwidth signalling by default */
5393 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5394 if (system(buf) != 0) {
5395 sigma_dut_print(dut, DUT_MSG_ERROR,
5396 "iwpriv %s cwmenable 1 failed", intf);
5397 }
5398
5399 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5400 if (system(buf) != 0) {
5401 sigma_dut_print(dut, DUT_MSG_ERROR,
5402 "iwpriv rts failed");
5403 }
5404 }
5405
5406 if (type && strcasecmp(type, "Testbed") == 0) {
5407 dut->testbed_flag_txsp = 1;
5408 dut->testbed_flag_rxsp = 1;
5409 /* STA has to set spatial stream to 2 per Appendix H */
5410 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5411 if (system(buf) != 0) {
5412 sigma_dut_print(dut, DUT_MSG_ERROR,
5413 "iwpriv vht_mcsmap failed");
5414 }
5415
5416 /* Disable LDPC per Appendix H */
5417 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5418 if (system(buf) != 0) {
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "iwpriv %s ldpc 0 failed", intf);
5421 }
5422
5423 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5424 if (system(buf) != 0) {
5425 sigma_dut_print(dut, DUT_MSG_ERROR,
5426 "iwpriv amsdu failed");
5427 }
5428
5429 /* TODO: Disable STBC 2x1 transmit and receive */
5430 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5431 if (system(buf) != 0) {
5432 sigma_dut_print(dut, DUT_MSG_ERROR,
5433 "Disable tx_stbc 0 failed");
5434 }
5435
5436 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5437 if (system(buf) != 0) {
5438 sigma_dut_print(dut, DUT_MSG_ERROR,
5439 "Disable rx_stbc 0 failed");
5440 }
5441
5442 /* STA has to disable Short GI per Appendix H */
5443 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5444 if (system(buf) != 0) {
5445 sigma_dut_print(dut, DUT_MSG_ERROR,
5446 "iwpriv %s shortgi 0 failed", intf);
5447 }
5448 }
5449
5450 if (type && strcasecmp(type, "DUT") == 0) {
5451 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5452 if (system(buf) != 0) {
5453 sigma_dut_print(dut, DUT_MSG_ERROR,
5454 "iwpriv %s nss 3 failed", intf);
5455 }
5456
5457 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5458 if (system(buf) != 0) {
5459 sigma_dut_print(dut, DUT_MSG_ERROR,
5460 "iwpriv %s shortgi 1 failed", intf);
5461 }
5462 }
5463}
5464
5465
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005466#ifdef NL80211_SUPPORT
5467static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5468 enum he_mcs_config mcs)
5469{
5470 struct nl_msg *msg;
5471 int ret = 0;
5472 struct nlattr *params;
5473 int ifindex;
5474
5475 ifindex = if_nametoindex(intf);
5476 if (ifindex == 0) {
5477 sigma_dut_print(dut, DUT_MSG_ERROR,
5478 "%s: Index for interface %s failed",
5479 __func__, intf);
5480 return -1;
5481 }
5482
5483 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5484 NL80211_CMD_VENDOR)) ||
5485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5486 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5487 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5488 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5489 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5490 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5491 mcs)) {
5492 sigma_dut_print(dut, DUT_MSG_ERROR,
5493 "%s: err in adding vendor_cmd and vendor_data",
5494 __func__);
5495 nlmsg_free(msg);
5496 return -1;
5497 }
5498 nla_nest_end(msg, params);
5499
5500 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5501 if (ret) {
5502 sigma_dut_print(dut, DUT_MSG_ERROR,
5503 "%s: err in send_and_recv_msgs, ret=%d",
5504 __func__, ret);
5505 }
5506 return ret;
5507}
5508#endif /* NL80211_SUPPORT */
5509
5510
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005511static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
5512 const char *type)
5513{
5514 char buf[60];
5515
5516 if (dut->program == PROGRAM_HE) {
5517 /* resetting phymode to auto in case of HE program */
5518 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
5519 if (system(buf) != 0) {
5520 sigma_dut_print(dut, DUT_MSG_ERROR,
5521 "iwpriv %s setphymode failed", intf);
5522 }
5523
5524 /* remove all network profiles */
5525 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005526
5527 /* Set nss to 1 and MCS 0-7 in case of testbed */
5528 if (type && strcasecmp(type, "Testbed") == 0) {
5529#ifdef NL80211_SUPPORT
5530 int ret;
5531#endif /* NL80211_SUPPORT */
5532
5533 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
5534 if (system(buf) != 0) {
5535 sigma_dut_print(dut, DUT_MSG_ERROR,
5536 "iwpriv %s nss failed", intf);
5537 }
5538
5539#ifdef NL80211_SUPPORT
5540 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
5541 if (ret) {
5542 sigma_dut_print(dut, DUT_MSG_ERROR,
5543 "Setting of MCS failed, ret:%d",
5544 ret);
5545 }
5546#endif /* NL80211_SUPPORT */
5547 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005548 }
5549}
5550
5551
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005552static int cmd_sta_reset_default(struct sigma_dut *dut,
5553 struct sigma_conn *conn,
5554 struct sigma_cmd *cmd)
5555{
5556 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
5557 struct sigma_cmd *cmd);
5558 const char *intf = get_param(cmd, "Interface");
5559 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005560 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05305561 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005562
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005563 if (!program)
5564 program = get_param(cmd, "prog");
5565 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005566 dut->device_type = STA_unknown;
5567 type = get_param(cmd, "type");
5568 if (type && strcasecmp(type, "Testbed") == 0)
5569 dut->device_type = STA_testbed;
5570 if (type && strcasecmp(type, "DUT") == 0)
5571 dut->device_type = STA_dut;
5572
5573 if (dut->program == PROGRAM_TDLS) {
5574 /* Clear TDLS testing mode */
5575 wpa_command(intf, "SET tdls_disabled 0");
5576 wpa_command(intf, "SET tdls_testing 0");
5577 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05305578 if (get_driver_type() == DRIVER_WCN) {
5579 /* Enable the WCN driver in TDLS Explicit trigger mode
5580 */
5581 wpa_command(intf, "SET tdls_external_control 0");
5582 wpa_command(intf, "SET tdls_trigger_control 0");
5583 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584 }
5585
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005586#ifdef MIRACAST
5587 if (dut->program == PROGRAM_WFD ||
5588 dut->program == PROGRAM_DISPLAYR2)
5589 miracast_sta_reset_default(dut, conn, cmd);
5590#endif /* MIRACAST */
5591
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005592 switch (get_driver_type()) {
5593 case DRIVER_ATHEROS:
5594 sta_reset_default_ath(dut, intf, type);
5595 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08005596 case DRIVER_WCN:
5597 sta_reset_default_wcn(dut, intf, type);
5598 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005599 default:
5600 break;
5601 }
5602
5603#ifdef ANDROID_NAN
5604 if (dut->program == PROGRAM_NAN)
5605 nan_cmd_sta_reset_default(dut, conn, cmd);
5606#endif /* ANDROID_NAN */
5607
5608 if (dut->program == PROGRAM_HS2_R2) {
5609 unlink("SP/wi-fi.org/pps.xml");
5610 if (system("rm -r SP/*") != 0) {
5611 }
5612 unlink("next-client-cert.pem");
5613 unlink("next-client-key.pem");
5614 }
5615
5616 if (dut->program == PROGRAM_60GHZ) {
5617 const char *dev_role = get_param(cmd, "DevRole");
5618
5619 if (!dev_role) {
5620 send_resp(dut, conn, SIGMA_ERROR,
5621 "errorCode,Missing DevRole argument");
5622 return 0;
5623 }
5624
5625 if (strcasecmp(dev_role, "STA") == 0)
5626 dut->dev_role = DEVROLE_STA;
5627 else if (strcasecmp(dev_role, "PCP") == 0)
5628 dut->dev_role = DEVROLE_PCP;
5629 else {
5630 send_resp(dut, conn, SIGMA_ERROR,
5631 "errorCode,Unknown DevRole");
5632 return 0;
5633 }
5634
5635 if (dut->device_type == STA_unknown) {
5636 sigma_dut_print(dut, DUT_MSG_ERROR,
5637 "Device type is not STA testbed or DUT");
5638 send_resp(dut, conn, SIGMA_ERROR,
5639 "errorCode,Unknown device type");
5640 return 0;
5641 }
5642 }
5643
5644 wpa_command(intf, "WPS_ER_STOP");
5645 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05305646 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005647 wpa_command(intf, "SET radio_disabled 0");
5648
5649 if (dut->tmp_mac_addr && dut->set_macaddr) {
5650 dut->tmp_mac_addr = 0;
5651 if (system(dut->set_macaddr) != 0) {
5652 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
5653 "temporary MAC address");
5654 }
5655 }
5656
5657 set_ps(intf, dut, 0);
5658
5659 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
5660 wpa_command(intf, "SET interworking 1");
5661 wpa_command(intf, "SET hs20 1");
5662 }
5663
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08005664 if (dut->program == PROGRAM_HS2_R2 ||
5665 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005666 wpa_command(intf, "SET pmf 1");
5667 } else {
5668 wpa_command(intf, "SET pmf 0");
5669 }
5670
5671 hs2_clear_credentials(intf);
5672 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
5673 wpa_command(intf, "SET access_network_type 15");
5674
5675 static_ip_file(0, NULL, NULL, NULL);
5676 kill_dhcp_client(dut, intf);
5677 clear_ip_addr(dut, intf);
5678
5679 dut->er_oper_performed = 0;
5680 dut->er_oper_bssid[0] = '\0';
5681
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07005682 if (dut->program == PROGRAM_LOC) {
5683 /* Disable Interworking by default */
5684 wpa_command(get_station_ifname(), "SET interworking 0");
5685 }
5686
Ashwini Patil00402582017-04-13 12:29:39 +05305687 if (dut->program == PROGRAM_MBO) {
5688 free(dut->non_pref_ch_list);
5689 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05305690 free(dut->btm_query_cand_list);
5691 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05305692 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05305693 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05305694 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305695 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05305696 }
5697
Jouni Malinen3c367e82017-06-23 17:01:47 +03005698 free(dut->rsne_override);
5699 dut->rsne_override = NULL;
5700
Jouni Malinen68143132017-09-02 02:34:08 +03005701 free(dut->sae_commit_override);
5702 dut->sae_commit_override = NULL;
5703
Jouni Malinend86e5822017-08-29 03:55:32 +03005704 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02005705 free(dut->dpp_peer_uri);
5706 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02005707 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02005708 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03005709
Jouni Malinenfac9cad2017-10-10 18:35:55 +03005710 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
5711
vamsi krishnaa2799492017-12-05 14:28:01 +05305712 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305713 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05305714 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05305715 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
5716 dut->fils_hlp = 0;
5717#ifdef ANDROID
5718 hlp_thread_cleanup(dut);
5719#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05305720 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305721
Sunil Dutt076081f2018-02-05 19:45:50 +05305722#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05305723 if (get_driver_type() == DRIVER_WCN &&
5724 dut->config_rsnie == 1) {
5725 dut->config_rsnie = 0;
5726 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05305727 }
5728#endif /* NL80211_SUPPORT */
5729
Sunil Duttfebf8a82018-02-09 18:50:13 +05305730 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
5731 dut->dev_role = DEVROLE_STA_CFON;
5732 return sta_cfon_reset_default(dut, conn, cmd);
5733 }
5734
5735 if (dut->program != PROGRAM_VHT)
5736 return cmd_sta_p2p_reset(dut, conn, cmd);
5737
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08005738 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005739}
5740
5741
5742static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
5743 struct sigma_cmd *cmd)
5744{
5745 const char *program = get_param(cmd, "Program");
5746
5747 if (program == NULL)
5748 return -1;
5749#ifdef ANDROID_NAN
5750 if (strcasecmp(program, "NAN") == 0)
5751 return nan_cmd_sta_get_events(dut, conn, cmd);
5752#endif /* ANDROID_NAN */
5753 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5754 return 0;
5755}
5756
5757
5758static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
5759 struct sigma_cmd *cmd)
5760{
5761 const char *program = get_param(cmd, "Prog");
5762
5763 if (program == NULL)
5764 return -1;
5765#ifdef ANDROID_NAN
5766 if (strcasecmp(program, "NAN") == 0)
5767 return nan_cmd_sta_exec_action(dut, conn, cmd);
5768#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005769 if (strcasecmp(program, "Loc") == 0)
5770 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005771 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5772 return 0;
5773}
5774
5775
5776static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
5777 struct sigma_cmd *cmd)
5778{
5779 const char *intf = get_param(cmd, "Interface");
5780 const char *val, *mcs32, *rate;
5781
5782 val = get_param(cmd, "GREENFIELD");
5783 if (val) {
5784 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5785 /* Enable GD */
5786 send_resp(dut, conn, SIGMA_ERROR,
5787 "ErrorCode,GF not supported");
5788 return 0;
5789 }
5790 }
5791
5792 val = get_param(cmd, "SGI20");
5793 if (val) {
5794 switch (get_driver_type()) {
5795 case DRIVER_ATHEROS:
5796 ath_sta_set_sgi(dut, intf, val);
5797 break;
5798 default:
5799 send_resp(dut, conn, SIGMA_ERROR,
5800 "ErrorCode,SGI20 not supported");
5801 return 0;
5802 }
5803 }
5804
5805 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
5806 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
5807 if (mcs32 && rate) {
5808 /* TODO */
5809 send_resp(dut, conn, SIGMA_ERROR,
5810 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
5811 return 0;
5812 } else if (mcs32 && !rate) {
5813 /* TODO */
5814 send_resp(dut, conn, SIGMA_ERROR,
5815 "ErrorCode,MCS32 not supported");
5816 return 0;
5817 } else if (!mcs32 && rate) {
5818 switch (get_driver_type()) {
5819 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005820 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005821 ath_sta_set_11nrates(dut, intf, rate);
5822 break;
5823 default:
5824 send_resp(dut, conn, SIGMA_ERROR,
5825 "ErrorCode,MCS32_FIXEDRATE not supported");
5826 return 0;
5827 }
5828 }
5829
5830 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5831}
5832
5833
5834static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
5835 struct sigma_conn *conn,
5836 struct sigma_cmd *cmd)
5837{
5838 const char *intf = get_param(cmd, "Interface");
5839 const char *val;
5840 char buf[30];
5841 int tkip = -1;
5842 int wep = -1;
5843
5844 val = get_param(cmd, "SGI80");
5845 if (val) {
5846 int sgi80;
5847
5848 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5849 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
5850 if (system(buf) != 0) {
5851 sigma_dut_print(dut, DUT_MSG_ERROR,
5852 "iwpriv shortgi failed");
5853 }
5854 }
5855
5856 val = get_param(cmd, "TxBF");
5857 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5858 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
5859 if (system(buf) != 0) {
5860 sigma_dut_print(dut, DUT_MSG_ERROR,
5861 "iwpriv vhtsubfee failed");
5862 }
5863 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
5864 if (system(buf) != 0) {
5865 sigma_dut_print(dut, DUT_MSG_ERROR,
5866 "iwpriv vhtsubfer failed");
5867 }
5868 }
5869
5870 val = get_param(cmd, "MU_TxBF");
5871 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5872 switch (get_driver_type()) {
5873 case DRIVER_ATHEROS:
5874 ath_sta_set_txsp_stream(dut, intf, "1SS");
5875 ath_sta_set_rxsp_stream(dut, intf, "1SS");
5876 case DRIVER_WCN:
5877 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
5878 send_resp(dut, conn, SIGMA_ERROR,
5879 "ErrorCode,Failed to set RX/TXSP_STREAM");
5880 return 0;
5881 }
5882 default:
5883 sigma_dut_print(dut, DUT_MSG_ERROR,
5884 "Setting SP_STREAM not supported");
5885 break;
5886 }
5887 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
5888 if (system(buf) != 0) {
5889 sigma_dut_print(dut, DUT_MSG_ERROR,
5890 "iwpriv vhtmubfee failed");
5891 }
5892 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
5893 if (system(buf) != 0) {
5894 sigma_dut_print(dut, DUT_MSG_ERROR,
5895 "iwpriv vhtmubfer failed");
5896 }
5897 }
5898
5899 val = get_param(cmd, "LDPC");
5900 if (val) {
5901 int ldpc;
5902
5903 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5904 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
5905 if (system(buf) != 0) {
5906 sigma_dut_print(dut, DUT_MSG_ERROR,
5907 "iwpriv ldpc failed");
5908 }
5909 }
5910
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08005911 val = get_param(cmd, "BCC");
5912 if (val) {
5913 int bcc;
5914
5915 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5916 /* use LDPC iwpriv itself to set bcc coding, bcc coding
5917 * is mutually exclusive to bcc */
5918 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
5919 if (system(buf) != 0) {
5920 sigma_dut_print(dut, DUT_MSG_ERROR,
5921 "Enabling/Disabling of BCC failed");
5922 }
5923 }
5924
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005925 val = get_param(cmd, "opt_md_notif_ie");
5926 if (val) {
5927 char *result = NULL;
5928 char delim[] = ";";
5929 char token[30];
5930 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305931 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005932
Peng Xub8fc5cc2017-05-10 17:27:28 -07005933 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305934 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005935
5936 /* Extract the NSS information */
5937 if (result) {
5938 value = atoi(result);
5939 switch (value) {
5940 case 1:
5941 config_val = 1;
5942 break;
5943 case 2:
5944 config_val = 3;
5945 break;
5946 case 3:
5947 config_val = 7;
5948 break;
5949 case 4:
5950 config_val = 15;
5951 break;
5952 default:
5953 config_val = 3;
5954 break;
5955 }
5956
5957 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
5958 intf, config_val);
5959 if (system(buf) != 0) {
5960 sigma_dut_print(dut, DUT_MSG_ERROR,
5961 "iwpriv rxchainmask failed");
5962 }
5963
5964 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
5965 intf, config_val);
5966 if (system(buf) != 0) {
5967 sigma_dut_print(dut, DUT_MSG_ERROR,
5968 "iwpriv txchainmask failed");
5969 }
5970 }
5971
5972 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305973 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005974 if (result) {
5975 value = atoi(result);
5976 switch (value) {
5977 case 20:
5978 config_val = 0;
5979 break;
5980 case 40:
5981 config_val = 1;
5982 break;
5983 case 80:
5984 config_val = 2;
5985 break;
5986 case 160:
5987 config_val = 3;
5988 break;
5989 default:
5990 config_val = 2;
5991 break;
5992 }
5993
5994 dut->chwidth = config_val;
5995
5996 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5997 intf, config_val);
5998 if (system(buf) != 0) {
5999 sigma_dut_print(dut, DUT_MSG_ERROR,
6000 "iwpriv chwidth failed");
6001 }
6002 }
6003
6004 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
6005 if (system(buf) != 0) {
6006 sigma_dut_print(dut, DUT_MSG_ERROR,
6007 "iwpriv opmode_notify failed");
6008 }
6009 }
6010
6011 val = get_param(cmd, "nss_mcs_cap");
6012 if (val) {
6013 int nss, mcs;
6014 char token[20];
6015 char *result = NULL;
6016 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306017 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006018
Peng Xub8fc5cc2017-05-10 17:27:28 -07006019 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306020 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306021 if (!result) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "VHT NSS not specified");
6024 return 0;
6025 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006026 nss = atoi(result);
6027
6028 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
6029 if (system(buf) != 0) {
6030 sigma_dut_print(dut, DUT_MSG_ERROR,
6031 "iwpriv nss failed");
6032 }
6033
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306034 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006035 if (result == NULL) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "VHTMCS NOT SPECIFIED!");
6038 return 0;
6039 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306040 result = strtok_r(result, "-", &saveptr);
6041 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05306042 if (!result) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "VHT MCS not specified");
6045 return 0;
6046 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006047 mcs = atoi(result);
6048
6049 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
6050 if (system(buf) != 0) {
6051 sigma_dut_print(dut, DUT_MSG_ERROR,
6052 "iwpriv mcs failed");
6053 }
6054
6055 switch (nss) {
6056 case 1:
6057 switch (mcs) {
6058 case 7:
6059 vht_mcsmap = 0xfffc;
6060 break;
6061 case 8:
6062 vht_mcsmap = 0xfffd;
6063 break;
6064 case 9:
6065 vht_mcsmap = 0xfffe;
6066 break;
6067 default:
6068 vht_mcsmap = 0xfffe;
6069 break;
6070 }
6071 break;
6072 case 2:
6073 switch (mcs) {
6074 case 7:
6075 vht_mcsmap = 0xfff0;
6076 break;
6077 case 8:
6078 vht_mcsmap = 0xfff5;
6079 break;
6080 case 9:
6081 vht_mcsmap = 0xfffa;
6082 break;
6083 default:
6084 vht_mcsmap = 0xfffa;
6085 break;
6086 }
6087 break;
6088 case 3:
6089 switch (mcs) {
6090 case 7:
6091 vht_mcsmap = 0xffc0;
6092 break;
6093 case 8:
6094 vht_mcsmap = 0xffd5;
6095 break;
6096 case 9:
6097 vht_mcsmap = 0xffea;
6098 break;
6099 default:
6100 vht_mcsmap = 0xffea;
6101 break;
6102 }
6103 break;
6104 default:
6105 vht_mcsmap = 0xffea;
6106 break;
6107 }
6108 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
6109 intf, vht_mcsmap);
6110 if (system(buf) != 0) {
6111 sigma_dut_print(dut, DUT_MSG_ERROR,
6112 "iwpriv vht_mcsmap failed");
6113 }
6114 }
6115
6116 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
6117
6118 val = get_param(cmd, "Vht_tkip");
6119 if (val)
6120 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6121
6122 val = get_param(cmd, "Vht_wep");
6123 if (val)
6124 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6125
6126 if (tkip != -1 || wep != -1) {
6127 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
6128 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
6129 intf);
6130 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
6131 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
6132 intf);
6133 } else {
6134 sigma_dut_print(dut, DUT_MSG_ERROR,
6135 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
6136 return 0;
6137 }
6138
6139 if (system(buf) != 0) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR,
6141 "iwpriv htweptkip failed");
6142 }
6143 }
6144
6145 val = get_param(cmd, "txBandwidth");
6146 if (val) {
6147 switch (get_driver_type()) {
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006148 case DRIVER_WCN:
6149 if (wcn_sta_set_width(dut, intf, val) < 0) {
6150 send_resp(dut, conn, SIGMA_ERROR,
6151 "ErrorCode,Failed to set txBandwidth");
6152 return 0;
6153 }
6154 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006155 case DRIVER_ATHEROS:
6156 if (ath_set_width(dut, conn, intf, val) < 0) {
6157 send_resp(dut, conn, SIGMA_ERROR,
6158 "ErrorCode,Failed to set txBandwidth");
6159 return 0;
6160 }
6161 break;
6162 default:
6163 sigma_dut_print(dut, DUT_MSG_ERROR,
6164 "Setting txBandwidth not supported");
6165 break;
6166 }
6167 }
6168
6169 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6170}
6171
6172
6173static int sta_set_wireless_60g(struct sigma_dut *dut,
6174 struct sigma_conn *conn,
6175 struct sigma_cmd *cmd)
6176{
6177 const char *dev_role = get_param(cmd, "DevRole");
6178
6179 if (!dev_role) {
6180 send_resp(dut, conn, SIGMA_INVALID,
6181 "ErrorCode,DevRole not specified");
6182 return 0;
6183 }
6184
6185 if (strcasecmp(dev_role, "PCP") == 0)
6186 return sta_set_60g_pcp(dut, conn, cmd);
6187 if (strcasecmp(dev_role, "STA") == 0)
6188 return sta_set_60g_sta(dut, conn, cmd);
6189 send_resp(dut, conn, SIGMA_INVALID,
6190 "ErrorCode,DevRole not supported");
6191 return 0;
6192}
6193
6194
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306195static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
6196 struct sigma_cmd *cmd)
6197{
6198 int status;
6199 const char *intf = get_param(cmd, "Interface");
6200 const char *val = get_param(cmd, "DevRole");
6201
6202 if (val && strcasecmp(val, "STA-CFON") == 0) {
6203 status = sta_cfon_set_wireless(dut, conn, cmd);
6204 if (status)
6205 return status;
6206 }
6207 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6208}
6209
6210
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
6212 struct sigma_cmd *cmd)
6213{
6214 const char *val;
6215
6216 val = get_param(cmd, "Program");
6217 if (val) {
6218 if (strcasecmp(val, "11n") == 0)
6219 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08006220 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006221 return cmd_sta_set_wireless_vht(dut, conn, cmd);
6222 if (strcasecmp(val, "60ghz") == 0)
6223 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306224 if (strcasecmp(val, "OCE") == 0)
6225 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006226 send_resp(dut, conn, SIGMA_ERROR,
6227 "ErrorCode,Program value not supported");
6228 } else {
6229 send_resp(dut, conn, SIGMA_ERROR,
6230 "ErrorCode,Program argument not available");
6231 }
6232
6233 return 0;
6234}
6235
6236
6237static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
6238 int tid)
6239{
6240 char buf[100];
6241 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
6242
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05306243 if (tid < 0 ||
6244 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
6245 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
6246 return;
6247 }
6248
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006249 /*
6250 * Two ways to ensure that addba request with a
6251 * non zero TID could be sent out. EV 117296
6252 */
6253 snprintf(buf, sizeof(buf),
6254 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
6255 tid);
6256 if (system(buf) != 0) {
6257 sigma_dut_print(dut, DUT_MSG_ERROR,
6258 "Ping did not send out");
6259 }
6260
6261 snprintf(buf, sizeof(buf),
6262 "iwconfig %s | grep Access | awk '{print $6}' > %s",
6263 intf, VI_QOS_TMP_FILE);
6264 if (system(buf) != 0)
6265 return;
6266
6267 snprintf(buf, sizeof(buf),
6268 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
6269 intf, VI_QOS_TMP_FILE);
6270 if (system(buf) != 0)
6271 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
6272
6273 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
6274 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
6275 if (system(buf) != 0) {
6276 sigma_dut_print(dut, DUT_MSG_ERROR,
6277 "VI_QOS_TEMP_FILE generation error failed");
6278 }
6279 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6280 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6281 if (system(buf) != 0) {
6282 sigma_dut_print(dut, DUT_MSG_ERROR,
6283 "VI_QOS_FILE generation failed");
6284 }
6285
6286 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
6287 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
6288 if (system(buf) != 0) {
6289 sigma_dut_print(dut, DUT_MSG_ERROR,
6290 "VI_QOS_FILE generation failed");
6291 }
6292
6293 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
6294 if (system(buf) != 0) {
6295 }
6296}
6297
6298
6299static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6300 struct sigma_cmd *cmd)
6301{
6302 const char *intf = get_param(cmd, "Interface");
6303 const char *val;
6304 int tid = 0;
6305 char buf[100];
6306
6307 val = get_param(cmd, "TID");
6308 if (val) {
6309 tid = atoi(val);
6310 if (tid)
6311 ath_sta_inject_frame(dut, intf, tid);
6312 }
6313
6314 /* Command sequence for ADDBA request on Peregrine based devices */
6315 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
6316 if (system(buf) != 0) {
6317 sigma_dut_print(dut, DUT_MSG_ERROR,
6318 "iwpriv setaddbaoper failed");
6319 }
6320
6321 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
6322 if (system(buf) != 0) {
6323 sigma_dut_print(dut, DUT_MSG_ERROR,
6324 "wifitool senddelba failed");
6325 }
6326
6327 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
6328 if (system(buf) != 0) {
6329 sigma_dut_print(dut, DUT_MSG_ERROR,
6330 "wifitool sendaddba failed");
6331 }
6332
6333 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
6334
6335 return 1;
6336}
6337
6338
Lior David9981b512017-01-20 13:16:40 +02006339#ifdef __linux__
6340
6341static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
6342 int agg_size)
6343{
6344 char dir[128], buf[128];
6345 FILE *f;
6346 regex_t re;
6347 regmatch_t m[2];
6348 int rc, ret = -1, vring_id, found;
6349
6350 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
6351 sigma_dut_print(dut, DUT_MSG_ERROR,
6352 "failed to get wil6210 debugfs dir");
6353 return -1;
6354 }
6355
6356 snprintf(buf, sizeof(buf), "%s/vrings", dir);
6357 f = fopen(buf, "r");
6358 if (!f) {
6359 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
6360 return -1;
6361 }
6362
6363 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
6364 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
6365 goto out;
6366 }
6367
6368 /* find TX VRING for the mac address */
6369 found = 0;
6370 while (fgets(buf, sizeof(buf), f)) {
6371 if (strcasestr(buf, dest_mac)) {
6372 found = 1;
6373 break;
6374 }
6375 }
6376
6377 if (!found) {
6378 sigma_dut_print(dut, DUT_MSG_ERROR,
6379 "no TX VRING for %s", dest_mac);
6380 goto out;
6381 }
6382
6383 /* extract VRING ID, "VRING tx_<id> = {" */
6384 if (!fgets(buf, sizeof(buf), f)) {
6385 sigma_dut_print(dut, DUT_MSG_ERROR,
6386 "no VRING start line for %s", dest_mac);
6387 goto out;
6388 }
6389
6390 rc = regexec(&re, buf, 2, m, 0);
6391 regfree(&re);
6392 if (rc || m[1].rm_so < 0) {
6393 sigma_dut_print(dut, DUT_MSG_ERROR,
6394 "no VRING TX ID for %s", dest_mac);
6395 goto out;
6396 }
6397 buf[m[1].rm_eo] = 0;
6398 vring_id = atoi(&buf[m[1].rm_so]);
6399
6400 /* send the addba command */
6401 fclose(f);
6402 snprintf(buf, sizeof(buf), "%s/back", dir);
6403 f = fopen(buf, "w");
6404 if (!f) {
6405 sigma_dut_print(dut, DUT_MSG_ERROR,
6406 "failed to open: %s", buf);
6407 return -1;
6408 }
6409
6410 fprintf(f, "add %d %d\n", vring_id, agg_size);
6411
6412 ret = 0;
6413
6414out:
6415 fclose(f);
6416
6417 return ret;
6418}
6419
6420
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006421static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6422 struct sigma_cmd *cmd)
6423{
6424 const char *val;
6425 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006426
6427 val = get_param(cmd, "TID");
6428 if (val) {
6429 tid = atoi(val);
6430 if (tid != 0) {
6431 sigma_dut_print(dut, DUT_MSG_ERROR,
6432 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
6433 tid);
6434 }
6435 }
6436
6437 val = get_param(cmd, "Dest_mac");
6438 if (!val) {
6439 sigma_dut_print(dut, DUT_MSG_ERROR,
6440 "Currently not supporting addba for 60G without Dest_mac");
6441 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
6442 }
6443
Lior David9981b512017-01-20 13:16:40 +02006444 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006445 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006446
6447 return 1;
6448}
6449
Lior David9981b512017-01-20 13:16:40 +02006450#endif /* __linux__ */
6451
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006452
6453static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
6454 struct sigma_cmd *cmd)
6455{
6456 switch (get_driver_type()) {
6457 case DRIVER_ATHEROS:
6458 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006459#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006460 case DRIVER_WIL6210:
6461 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02006462#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006463 default:
6464 /*
6465 * There is no driver specific implementation for other drivers.
6466 * Ignore the command and report COMPLETE since the following
6467 * throughput test operation will end up sending ADDBA anyway.
6468 */
6469 return 1;
6470 }
6471}
6472
6473
6474int inject_eth_frame(int s, const void *data, size_t len,
6475 unsigned short ethtype, char *dst, char *src)
6476{
6477 struct iovec iov[4] = {
6478 {
6479 .iov_base = dst,
6480 .iov_len = ETH_ALEN,
6481 },
6482 {
6483 .iov_base = src,
6484 .iov_len = ETH_ALEN,
6485 },
6486 {
6487 .iov_base = &ethtype,
6488 .iov_len = sizeof(unsigned short),
6489 },
6490 {
6491 .iov_base = (void *) data,
6492 .iov_len = len,
6493 }
6494 };
6495 struct msghdr msg = {
6496 .msg_name = NULL,
6497 .msg_namelen = 0,
6498 .msg_iov = iov,
6499 .msg_iovlen = 4,
6500 .msg_control = NULL,
6501 .msg_controllen = 0,
6502 .msg_flags = 0,
6503 };
6504
6505 return sendmsg(s, &msg, 0);
6506}
6507
6508#if defined(__linux__) || defined(__QNXNTO__)
6509
6510int inject_frame(int s, const void *data, size_t len, int encrypt)
6511{
6512#define IEEE80211_RADIOTAP_F_WEP 0x04
6513#define IEEE80211_RADIOTAP_F_FRAG 0x08
6514 unsigned char rtap_hdr[] = {
6515 0x00, 0x00, /* radiotap version */
6516 0x0e, 0x00, /* radiotap length */
6517 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6518 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
6519 0x00, /* padding */
6520 0x00, 0x00, /* RX and TX flags to indicate that */
6521 0x00, 0x00, /* this is the injected frame directly */
6522 };
6523 struct iovec iov[2] = {
6524 {
6525 .iov_base = &rtap_hdr,
6526 .iov_len = sizeof(rtap_hdr),
6527 },
6528 {
6529 .iov_base = (void *) data,
6530 .iov_len = len,
6531 }
6532 };
6533 struct msghdr msg = {
6534 .msg_name = NULL,
6535 .msg_namelen = 0,
6536 .msg_iov = iov,
6537 .msg_iovlen = 2,
6538 .msg_control = NULL,
6539 .msg_controllen = 0,
6540 .msg_flags = 0,
6541 };
6542
6543 if (encrypt)
6544 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
6545
6546 return sendmsg(s, &msg, 0);
6547}
6548
6549
6550int open_monitor(const char *ifname)
6551{
6552#ifdef __QNXNTO__
6553 struct sockaddr_dl ll;
6554 int s;
6555
6556 memset(&ll, 0, sizeof(ll));
6557 ll.sdl_family = AF_LINK;
6558 ll.sdl_index = if_nametoindex(ifname);
6559 if (ll.sdl_index == 0) {
6560 perror("if_nametoindex");
6561 return -1;
6562 }
6563 s = socket(PF_INET, SOCK_RAW, 0);
6564#else /* __QNXNTO__ */
6565 struct sockaddr_ll ll;
6566 int s;
6567
6568 memset(&ll, 0, sizeof(ll));
6569 ll.sll_family = AF_PACKET;
6570 ll.sll_ifindex = if_nametoindex(ifname);
6571 if (ll.sll_ifindex == 0) {
6572 perror("if_nametoindex");
6573 return -1;
6574 }
6575 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
6576#endif /* __QNXNTO__ */
6577 if (s < 0) {
6578 perror("socket[PF_PACKET,SOCK_RAW]");
6579 return -1;
6580 }
6581
6582 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
6583 perror("monitor socket bind");
6584 close(s);
6585 return -1;
6586 }
6587
6588 return s;
6589}
6590
6591
6592static int hex2num(char c)
6593{
6594 if (c >= '0' && c <= '9')
6595 return c - '0';
6596 if (c >= 'a' && c <= 'f')
6597 return c - 'a' + 10;
6598 if (c >= 'A' && c <= 'F')
6599 return c - 'A' + 10;
6600 return -1;
6601}
6602
6603
6604int hwaddr_aton(const char *txt, unsigned char *addr)
6605{
6606 int i;
6607
6608 for (i = 0; i < 6; i++) {
6609 int a, b;
6610
6611 a = hex2num(*txt++);
6612 if (a < 0)
6613 return -1;
6614 b = hex2num(*txt++);
6615 if (b < 0)
6616 return -1;
6617 *addr++ = (a << 4) | b;
6618 if (i < 5 && *txt++ != ':')
6619 return -1;
6620 }
6621
6622 return 0;
6623}
6624
6625#endif /* defined(__linux__) || defined(__QNXNTO__) */
6626
6627enum send_frame_type {
6628 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
6629};
6630enum send_frame_protection {
6631 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6632};
6633
6634
6635static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6636 enum send_frame_type frame,
6637 enum send_frame_protection protected,
6638 const char *dest)
6639{
6640#ifdef __linux__
6641 unsigned char buf[1000], *pos;
6642 int s, res;
6643 char bssid[20], addr[20];
6644 char result[32], ssid[100];
6645 size_t ssid_len;
6646
6647 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6648 sizeof(result)) < 0 ||
6649 strncmp(result, "COMPLETED", 9) != 0) {
6650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
6651 return 0;
6652 }
6653
6654 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
6655 < 0) {
6656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6657 "current BSSID");
6658 return 0;
6659 }
6660
6661 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
6662 < 0) {
6663 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6664 "own MAC address");
6665 return 0;
6666 }
6667
6668 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
6669 < 0) {
6670 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
6671 "current SSID");
6672 return 0;
6673 }
6674 ssid_len = strlen(ssid);
6675
6676 pos = buf;
6677
6678 /* Frame Control */
6679 switch (frame) {
6680 case DISASSOC:
6681 *pos++ = 0xa0;
6682 break;
6683 case DEAUTH:
6684 *pos++ = 0xc0;
6685 break;
6686 case SAQUERY:
6687 *pos++ = 0xd0;
6688 break;
6689 case AUTH:
6690 *pos++ = 0xb0;
6691 break;
6692 case ASSOCREQ:
6693 *pos++ = 0x00;
6694 break;
6695 case REASSOCREQ:
6696 *pos++ = 0x20;
6697 break;
6698 case DLS_REQ:
6699 *pos++ = 0xd0;
6700 break;
6701 }
6702
6703 if (protected == INCORRECT_KEY)
6704 *pos++ = 0x40; /* Set Protected field to 1 */
6705 else
6706 *pos++ = 0x00;
6707
6708 /* Duration */
6709 *pos++ = 0x00;
6710 *pos++ = 0x00;
6711
6712 /* addr1 = DA (current AP) */
6713 hwaddr_aton(bssid, pos);
6714 pos += 6;
6715 /* addr2 = SA (own address) */
6716 hwaddr_aton(addr, pos);
6717 pos += 6;
6718 /* addr3 = BSSID (current AP) */
6719 hwaddr_aton(bssid, pos);
6720 pos += 6;
6721
6722 /* Seq# (to be filled by driver/mac80211) */
6723 *pos++ = 0x00;
6724 *pos++ = 0x00;
6725
6726 if (protected == INCORRECT_KEY) {
6727 /* CCMP parameters */
6728 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
6729 pos += 8;
6730 }
6731
6732 if (protected == INCORRECT_KEY) {
6733 switch (frame) {
6734 case DEAUTH:
6735 /* Reason code (encrypted) */
6736 memcpy(pos, "\xa7\x39", 2);
6737 pos += 2;
6738 break;
6739 case DISASSOC:
6740 /* Reason code (encrypted) */
6741 memcpy(pos, "\xa7\x39", 2);
6742 pos += 2;
6743 break;
6744 case SAQUERY:
6745 /* Category|Action|TransID (encrypted) */
6746 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
6747 pos += 4;
6748 break;
6749 default:
6750 return -1;
6751 }
6752
6753 /* CCMP MIC */
6754 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
6755 pos += 8;
6756 } else {
6757 switch (frame) {
6758 case DEAUTH:
6759 /* reason code = 8 */
6760 *pos++ = 0x08;
6761 *pos++ = 0x00;
6762 break;
6763 case DISASSOC:
6764 /* reason code = 8 */
6765 *pos++ = 0x08;
6766 *pos++ = 0x00;
6767 break;
6768 case SAQUERY:
6769 /* Category - SA Query */
6770 *pos++ = 0x08;
6771 /* SA query Action - Request */
6772 *pos++ = 0x00;
6773 /* Transaction ID */
6774 *pos++ = 0x12;
6775 *pos++ = 0x34;
6776 break;
6777 case AUTH:
6778 /* Auth Alg (Open) */
6779 *pos++ = 0x00;
6780 *pos++ = 0x00;
6781 /* Seq# */
6782 *pos++ = 0x01;
6783 *pos++ = 0x00;
6784 /* Status code */
6785 *pos++ = 0x00;
6786 *pos++ = 0x00;
6787 break;
6788 case ASSOCREQ:
6789 /* Capability Information */
6790 *pos++ = 0x31;
6791 *pos++ = 0x04;
6792 /* Listen Interval */
6793 *pos++ = 0x0a;
6794 *pos++ = 0x00;
6795 /* SSID */
6796 *pos++ = 0x00;
6797 *pos++ = ssid_len;
6798 memcpy(pos, ssid, ssid_len);
6799 pos += ssid_len;
6800 /* Supported Rates */
6801 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6802 10);
6803 pos += 10;
6804 /* Extended Supported Rates */
6805 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6806 pos += 6;
6807 /* RSN */
6808 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6809 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6810 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6811 pos += 28;
6812 break;
6813 case REASSOCREQ:
6814 /* Capability Information */
6815 *pos++ = 0x31;
6816 *pos++ = 0x04;
6817 /* Listen Interval */
6818 *pos++ = 0x0a;
6819 *pos++ = 0x00;
6820 /* Current AP */
6821 hwaddr_aton(bssid, pos);
6822 pos += 6;
6823 /* SSID */
6824 *pos++ = 0x00;
6825 *pos++ = ssid_len;
6826 memcpy(pos, ssid, ssid_len);
6827 pos += ssid_len;
6828 /* Supported Rates */
6829 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
6830 10);
6831 pos += 10;
6832 /* Extended Supported Rates */
6833 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
6834 pos += 6;
6835 /* RSN */
6836 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
6837 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
6838 "\x00\x00\x00\x00\x0f\xac\x06", 28);
6839 pos += 28;
6840 break;
6841 case DLS_REQ:
6842 /* Category - DLS */
6843 *pos++ = 0x02;
6844 /* DLS Action - Request */
6845 *pos++ = 0x00;
6846 /* Destination MACAddress */
6847 if (dest)
6848 hwaddr_aton(dest, pos);
6849 else
6850 memset(pos, 0, 6);
6851 pos += 6;
6852 /* Source MACAddress */
6853 hwaddr_aton(addr, pos);
6854 pos += 6;
6855 /* Capability Information */
6856 *pos++ = 0x10; /* Privacy */
6857 *pos++ = 0x06; /* QoS */
6858 /* DLS Timeout Value */
6859 *pos++ = 0x00;
6860 *pos++ = 0x01;
6861 /* Supported rates */
6862 *pos++ = 0x01;
6863 *pos++ = 0x08;
6864 *pos++ = 0x0c; /* 6 Mbps */
6865 *pos++ = 0x12; /* 9 Mbps */
6866 *pos++ = 0x18; /* 12 Mbps */
6867 *pos++ = 0x24; /* 18 Mbps */
6868 *pos++ = 0x30; /* 24 Mbps */
6869 *pos++ = 0x48; /* 36 Mbps */
6870 *pos++ = 0x60; /* 48 Mbps */
6871 *pos++ = 0x6c; /* 54 Mbps */
6872 /* TODO: Extended Supported Rates */
6873 /* TODO: HT Capabilities */
6874 break;
6875 }
6876 }
6877
6878 s = open_monitor("sigmadut");
6879 if (s < 0) {
6880 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6881 "monitor socket");
6882 return 0;
6883 }
6884
6885 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
6886 if (res < 0) {
6887 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6888 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306889 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006890 return 0;
6891 }
6892 if (res < pos - buf) {
6893 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
6894 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306895 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006896 return 0;
6897 }
6898
6899 close(s);
6900
6901 return 1;
6902#else /* __linux__ */
6903 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
6904 "yet supported");
6905 return 0;
6906#endif /* __linux__ */
6907}
6908
6909
6910static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
6911 struct sigma_conn *conn,
6912 struct sigma_cmd *cmd)
6913{
6914 const char *intf = get_param(cmd, "Interface");
6915 const char *sta, *val;
6916 unsigned char addr[ETH_ALEN];
6917 char buf[100];
6918
6919 sta = get_param(cmd, "peer");
6920 if (sta == NULL)
6921 sta = get_param(cmd, "station");
6922 if (sta == NULL) {
6923 send_resp(dut, conn, SIGMA_ERROR,
6924 "ErrorCode,Missing peer address");
6925 return 0;
6926 }
6927 if (hwaddr_aton(sta, addr) < 0) {
6928 send_resp(dut, conn, SIGMA_ERROR,
6929 "ErrorCode,Invalid peer address");
6930 return 0;
6931 }
6932
6933 val = get_param(cmd, "type");
6934 if (val == NULL)
6935 return -1;
6936
6937 if (strcasecmp(val, "DISCOVERY") == 0) {
6938 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
6939 if (wpa_command(intf, buf) < 0) {
6940 send_resp(dut, conn, SIGMA_ERROR,
6941 "ErrorCode,Failed to send TDLS discovery");
6942 return 0;
6943 }
6944 return 1;
6945 }
6946
6947 if (strcasecmp(val, "SETUP") == 0) {
6948 int status = 0, timeout = 0;
6949
6950 val = get_param(cmd, "Status");
6951 if (val)
6952 status = atoi(val);
6953
6954 val = get_param(cmd, "Timeout");
6955 if (val)
6956 timeout = atoi(val);
6957
6958 if (status != 0 && status != 37) {
6959 send_resp(dut, conn, SIGMA_ERROR,
6960 "ErrorCode,Unsupported status value");
6961 return 0;
6962 }
6963
6964 if (timeout != 0 && timeout != 301) {
6965 send_resp(dut, conn, SIGMA_ERROR,
6966 "ErrorCode,Unsupported timeout value");
6967 return 0;
6968 }
6969
6970 if (status && timeout) {
6971 send_resp(dut, conn, SIGMA_ERROR,
6972 "ErrorCode,Unsupported timeout+status "
6973 "combination");
6974 return 0;
6975 }
6976
6977 if (status == 37 &&
6978 wpa_command(intf, "SET tdls_testing 0x200")) {
6979 send_resp(dut, conn, SIGMA_ERROR,
6980 "ErrorCode,Failed to enable "
6981 "decline setup response test mode");
6982 return 0;
6983 }
6984
6985 if (timeout == 301) {
6986 int res;
6987 if (dut->no_tpk_expiration)
6988 res = wpa_command(intf,
6989 "SET tdls_testing 0x108");
6990 else
6991 res = wpa_command(intf,
6992 "SET tdls_testing 0x8");
6993 if (res) {
6994 send_resp(dut, conn, SIGMA_ERROR,
6995 "ErrorCode,Failed to set short TPK "
6996 "lifetime");
6997 return 0;
6998 }
6999 }
7000
7001 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
7002 if (wpa_command(intf, buf) < 0) {
7003 send_resp(dut, conn, SIGMA_ERROR,
7004 "ErrorCode,Failed to send TDLS setup");
7005 return 0;
7006 }
7007 return 1;
7008 }
7009
7010 if (strcasecmp(val, "TEARDOWN") == 0) {
7011 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
7012 if (wpa_command(intf, buf) < 0) {
7013 send_resp(dut, conn, SIGMA_ERROR,
7014 "ErrorCode,Failed to send TDLS teardown");
7015 return 0;
7016 }
7017 return 1;
7018 }
7019
7020 send_resp(dut, conn, SIGMA_ERROR,
7021 "ErrorCode,Unsupported TDLS frame");
7022 return 0;
7023}
7024
7025
7026static int sta_ap_known(const char *ifname, const char *bssid)
7027{
7028 char buf[4096];
7029
7030 snprintf(buf, sizeof(buf), "BSS %s", bssid);
7031 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
7032 return 0;
7033 if (strncmp(buf, "id=", 3) != 0)
7034 return 0;
7035 return 1;
7036}
7037
7038
7039static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
7040 const char *bssid)
7041{
7042 int res;
7043 struct wpa_ctrl *ctrl;
7044 char buf[256];
7045
7046 if (sta_ap_known(ifname, bssid))
7047 return 0;
7048 sigma_dut_print(dut, DUT_MSG_DEBUG,
7049 "AP not in BSS table - start scan");
7050
7051 ctrl = open_wpa_mon(ifname);
7052 if (ctrl == NULL) {
7053 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7054 "wpa_supplicant monitor connection");
7055 return -1;
7056 }
7057
7058 if (wpa_command(ifname, "SCAN") < 0) {
7059 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
7060 wpa_ctrl_detach(ctrl);
7061 wpa_ctrl_close(ctrl);
7062 return -1;
7063 }
7064
7065 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
7066 buf, sizeof(buf));
7067
7068 wpa_ctrl_detach(ctrl);
7069 wpa_ctrl_close(ctrl);
7070
7071 if (res < 0) {
7072 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
7073 return -1;
7074 }
7075
7076 if (sta_ap_known(ifname, bssid))
7077 return 0;
7078 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
7079 return -1;
7080}
7081
7082
7083static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
7084 struct sigma_conn *conn,
7085 struct sigma_cmd *cmd,
7086 const char *intf)
7087{
7088 char buf[200];
7089
7090 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
7091 if (system(buf) != 0) {
7092 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
7093 "ndsend");
7094 return 0;
7095 }
7096
7097 return 1;
7098}
7099
7100
7101static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
7102 struct sigma_conn *conn,
7103 struct sigma_cmd *cmd,
7104 const char *intf)
7105{
7106 char buf[200];
7107 const char *ip = get_param(cmd, "SenderIP");
7108
Peng Xu26b356d2017-10-04 17:58:16 -07007109 if (!ip)
7110 return 0;
7111
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007112 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
7113 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7114 if (system(buf) == 0) {
7115 sigma_dut_print(dut, DUT_MSG_INFO,
7116 "Neighbor Solicitation got a response "
7117 "for %s@%s", ip, intf);
7118 }
7119
7120 return 1;
7121}
7122
7123
7124static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
7125 struct sigma_conn *conn,
7126 struct sigma_cmd *cmd,
7127 const char *ifname)
7128{
7129 char buf[200];
7130 const char *ip = get_param(cmd, "SenderIP");
7131
7132 if (ip == NULL) {
7133 send_resp(dut, conn, SIGMA_ERROR,
7134 "ErrorCode,Missing SenderIP parameter");
7135 return 0;
7136 }
7137 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
7138 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7139 if (system(buf) != 0) {
7140 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
7141 "for %s@%s", ip, ifname);
7142 }
7143
7144 return 1;
7145}
7146
7147
7148static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
7149 struct sigma_conn *conn,
7150 struct sigma_cmd *cmd,
7151 const char *ifname)
7152{
7153 char buf[200];
7154 char ip[16];
7155 int s;
Peng Xub3756882017-10-04 14:39:09 -07007156 struct ifreq ifr;
7157 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007158
7159 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07007160 if (s < 0) {
7161 perror("socket");
7162 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007163 }
7164
Peng Xub3756882017-10-04 14:39:09 -07007165 memset(&ifr, 0, sizeof(ifr));
7166 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
7167 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
7168 sigma_dut_print(dut, DUT_MSG_INFO,
7169 "Failed to get %s IP address: %s",
7170 ifname, strerror(errno));
7171 close(s);
7172 return -1;
7173 }
7174 close(s);
7175
7176 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
7177 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
7178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007179 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
7180 ip);
7181 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7182 if (system(buf) != 0) {
7183 }
7184
7185 return 1;
7186}
7187
7188
7189static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
7190 struct sigma_conn *conn,
7191 struct sigma_cmd *cmd,
7192 const char *ifname)
7193{
7194 char buf[200], addr[20];
7195 char dst[ETH_ALEN], src[ETH_ALEN];
7196 short ethtype = htons(ETH_P_ARP);
7197 char *pos;
7198 int s, res;
7199 const char *val;
7200 struct sockaddr_in taddr;
7201
7202 val = get_param(cmd, "dest");
7203 if (val)
7204 hwaddr_aton(val, (unsigned char *) dst);
7205
7206 val = get_param(cmd, "DestIP");
7207 if (val)
7208 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07007209 else
7210 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007211
7212 if (get_wpa_status(get_station_ifname(), "address", addr,
7213 sizeof(addr)) < 0)
7214 return -2;
7215 hwaddr_aton(addr, (unsigned char *) src);
7216
7217 pos = buf;
7218 *pos++ = 0x00;
7219 *pos++ = 0x01;
7220 *pos++ = 0x08;
7221 *pos++ = 0x00;
7222 *pos++ = 0x06;
7223 *pos++ = 0x04;
7224 *pos++ = 0x00;
7225 *pos++ = 0x02;
7226 memcpy(pos, src, ETH_ALEN);
7227 pos += ETH_ALEN;
7228 memcpy(pos, &taddr.sin_addr, 4);
7229 pos += 4;
7230 memcpy(pos, dst, ETH_ALEN);
7231 pos += ETH_ALEN;
7232 memcpy(pos, &taddr.sin_addr, 4);
7233 pos += 4;
7234
7235 s = open_monitor(get_station_ifname());
7236 if (s < 0) {
7237 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7238 "monitor socket");
7239 return 0;
7240 }
7241
7242 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
7243 if (res < 0) {
7244 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7245 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307246 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007247 return 0;
7248 }
7249
7250 close(s);
7251
7252 return 1;
7253}
7254
7255
7256static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
7257 struct sigma_conn *conn,
7258 struct sigma_cmd *cmd,
7259 const char *intf, const char *dest)
7260{
7261 char buf[100];
7262
7263 if (if_nametoindex("sigmadut") == 0) {
7264 snprintf(buf, sizeof(buf),
7265 "iw dev %s interface add sigmadut type monitor",
7266 get_station_ifname());
7267 if (system(buf) != 0 ||
7268 if_nametoindex("sigmadut") == 0) {
7269 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7270 "monitor interface with '%s'", buf);
7271 return -2;
7272 }
7273 }
7274
7275 if (system("ifconfig sigmadut up") != 0) {
7276 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7277 "monitor interface up");
7278 return -2;
7279 }
7280
7281 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
7282}
7283
7284
7285static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
7286 struct sigma_conn *conn,
7287 struct sigma_cmd *cmd)
7288{
7289 const char *intf = get_param(cmd, "Interface");
7290 const char *dest = get_param(cmd, "Dest");
7291 const char *type = get_param(cmd, "FrameName");
7292 const char *val;
7293 char buf[200], *pos, *end;
7294 int count, count2;
7295
7296 if (type == NULL)
7297 type = get_param(cmd, "Type");
7298
7299 if (intf == NULL || dest == NULL || type == NULL)
7300 return -1;
7301
7302 if (strcasecmp(type, "NeighAdv") == 0)
7303 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
7304
7305 if (strcasecmp(type, "NeighSolicitReq") == 0)
7306 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
7307
7308 if (strcasecmp(type, "ARPProbe") == 0)
7309 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
7310
7311 if (strcasecmp(type, "ARPAnnounce") == 0)
7312 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
7313
7314 if (strcasecmp(type, "ARPReply") == 0)
7315 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
7316
7317 if (strcasecmp(type, "DLS-request") == 0 ||
7318 strcasecmp(type, "DLSrequest") == 0)
7319 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
7320 dest);
7321
7322 if (strcasecmp(type, "ANQPQuery") != 0 &&
7323 strcasecmp(type, "Query") != 0) {
7324 send_resp(dut, conn, SIGMA_ERROR,
7325 "ErrorCode,Unsupported HS 2.0 send frame type");
7326 return 0;
7327 }
7328
7329 if (sta_scan_ap(dut, intf, dest) < 0) {
7330 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
7331 "the requested AP");
7332 return 0;
7333 }
7334
7335 pos = buf;
7336 end = buf + sizeof(buf);
7337 count = 0;
7338 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
7339
7340 val = get_param(cmd, "ANQP_CAP_LIST");
7341 if (val && atoi(val)) {
7342 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
7343 count++;
7344 }
7345
7346 val = get_param(cmd, "VENUE_NAME");
7347 if (val && atoi(val)) {
7348 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
7349 count++;
7350 }
7351
7352 val = get_param(cmd, "NETWORK_AUTH_TYPE");
7353 if (val && atoi(val)) {
7354 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
7355 count++;
7356 }
7357
7358 val = get_param(cmd, "ROAMING_CONS");
7359 if (val && atoi(val)) {
7360 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
7361 count++;
7362 }
7363
7364 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
7365 if (val && atoi(val)) {
7366 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
7367 count++;
7368 }
7369
7370 val = get_param(cmd, "NAI_REALM_LIST");
7371 if (val && atoi(val)) {
7372 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
7373 count++;
7374 }
7375
7376 val = get_param(cmd, "3GPP_INFO");
7377 if (val && atoi(val)) {
7378 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
7379 count++;
7380 }
7381
7382 val = get_param(cmd, "DOMAIN_LIST");
7383 if (val && atoi(val)) {
7384 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
7385 count++;
7386 }
7387
7388 if (count && wpa_command(intf, buf)) {
7389 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
7390 return 0;
7391 }
7392
7393 pos = buf;
7394 end = buf + sizeof(buf);
7395 count2 = 0;
7396 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
7397
7398 val = get_param(cmd, "HS_CAP_LIST");
7399 if (val && atoi(val)) {
7400 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
7401 count2++;
7402 }
7403
7404 val = get_param(cmd, "OPER_NAME");
7405 if (val && atoi(val)) {
7406 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
7407 count2++;
7408 }
7409
7410 val = get_param(cmd, "WAN_METRICS");
7411 if (!val)
7412 val = get_param(cmd, "WAN_MAT");
7413 if (!val)
7414 val = get_param(cmd, "WAN_MET");
7415 if (val && atoi(val)) {
7416 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
7417 count2++;
7418 }
7419
7420 val = get_param(cmd, "CONNECTION_CAPABILITY");
7421 if (val && atoi(val)) {
7422 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
7423 count2++;
7424 }
7425
7426 val = get_param(cmd, "OP_CLASS");
7427 if (val && atoi(val)) {
7428 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
7429 count2++;
7430 }
7431
7432 val = get_param(cmd, "OSU_PROVIDER_LIST");
7433 if (val && atoi(val)) {
7434 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
7435 count2++;
7436 }
7437
7438 if (count && count2) {
7439 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
7440 "second query");
7441 sleep(1);
7442 }
7443
7444 if (count2 && wpa_command(intf, buf)) {
7445 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
7446 "failed");
7447 return 0;
7448 }
7449
7450 val = get_param(cmd, "NAI_HOME_REALM_LIST");
7451 if (val) {
7452 if (count || count2) {
7453 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7454 "sending out second query");
7455 sleep(1);
7456 }
7457
7458 if (strcmp(val, "1") == 0)
7459 val = "mail.example.com";
7460 snprintf(buf, end - pos,
7461 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
7462 dest, val);
7463 if (wpa_command(intf, buf)) {
7464 send_resp(dut, conn, SIGMA_ERROR,
7465 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
7466 "failed");
7467 return 0;
7468 }
7469 }
7470
7471 val = get_param(cmd, "ICON_REQUEST");
7472 if (val) {
7473 if (count || count2) {
7474 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
7475 "sending out second query");
7476 sleep(1);
7477 }
7478
7479 snprintf(buf, end - pos,
7480 "HS20_ICON_REQUEST %s %s", dest, val);
7481 if (wpa_command(intf, buf)) {
7482 send_resp(dut, conn, SIGMA_ERROR,
7483 "ErrorCode,HS20_ICON_REQUEST failed");
7484 return 0;
7485 }
7486 }
7487
7488 return 1;
7489}
7490
7491
7492static int ath_sta_send_frame_vht(struct sigma_dut *dut,
7493 struct sigma_conn *conn,
7494 struct sigma_cmd *cmd)
7495{
7496 const char *val;
7497 char *ifname;
7498 char buf[100];
7499 int chwidth, nss;
7500
7501 val = get_param(cmd, "framename");
7502 if (!val)
7503 return -1;
7504 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
7505
7506 /* Command sequence to generate Op mode notification */
7507 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
7508 ifname = get_station_ifname();
7509
7510 /* Disable STBC */
7511 snprintf(buf, sizeof(buf),
7512 "iwpriv %s tx_stbc 0", ifname);
7513 if (system(buf) != 0) {
7514 sigma_dut_print(dut, DUT_MSG_ERROR,
7515 "iwpriv tx_stbc 0 failed!");
7516 }
7517
7518 /* Extract Channel width */
7519 val = get_param(cmd, "Channel_width");
7520 if (val) {
7521 switch (atoi(val)) {
7522 case 20:
7523 chwidth = 0;
7524 break;
7525 case 40:
7526 chwidth = 1;
7527 break;
7528 case 80:
7529 chwidth = 2;
7530 break;
7531 case 160:
7532 chwidth = 3;
7533 break;
7534 default:
7535 chwidth = 2;
7536 break;
7537 }
7538
7539 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7540 ifname, chwidth);
7541 if (system(buf) != 0) {
7542 sigma_dut_print(dut, DUT_MSG_ERROR,
7543 "iwpriv chwidth failed!");
7544 }
7545 }
7546
7547 /* Extract NSS */
7548 val = get_param(cmd, "NSS");
7549 if (val) {
7550 switch (atoi(val)) {
7551 case 1:
7552 nss = 1;
7553 break;
7554 case 2:
7555 nss = 3;
7556 break;
7557 case 3:
7558 nss = 7;
7559 break;
7560 default:
7561 /* We do not support NSS > 3 */
7562 nss = 3;
7563 break;
7564 }
7565 snprintf(buf, sizeof(buf),
7566 "iwpriv %s rxchainmask %d", ifname, nss);
7567 if (system(buf) != 0) {
7568 sigma_dut_print(dut, DUT_MSG_ERROR,
7569 "iwpriv rxchainmask failed!");
7570 }
7571 }
7572
7573 /* Opmode notify */
7574 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
7575 if (system(buf) != 0) {
7576 sigma_dut_print(dut, DUT_MSG_ERROR,
7577 "iwpriv opmode_notify failed!");
7578 } else {
7579 sigma_dut_print(dut, DUT_MSG_INFO,
7580 "Sent out the notify frame!");
7581 }
7582 }
7583
7584 return 1;
7585}
7586
7587
7588static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
7589 struct sigma_conn *conn,
7590 struct sigma_cmd *cmd)
7591{
7592 switch (get_driver_type()) {
7593 case DRIVER_ATHEROS:
7594 return ath_sta_send_frame_vht(dut, conn, cmd);
7595 default:
7596 send_resp(dut, conn, SIGMA_ERROR,
7597 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
7598 return 0;
7599 }
7600}
7601
7602
Lior David0fe101e2017-03-09 16:09:50 +02007603#ifdef __linux__
7604int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7605 struct sigma_cmd *cmd)
7606{
7607 const char *frame_name = get_param(cmd, "framename");
7608 const char *mac = get_param(cmd, "dest_mac");
7609
7610 if (!frame_name || !mac) {
7611 sigma_dut_print(dut, DUT_MSG_ERROR,
7612 "framename and dest_mac must be provided");
7613 return -1;
7614 }
7615
7616 if (strcasecmp(frame_name, "brp") == 0) {
7617 const char *l_rx = get_param(cmd, "L-RX");
7618 int l_rx_i;
7619
7620 if (!l_rx) {
7621 sigma_dut_print(dut, DUT_MSG_ERROR,
7622 "L-RX must be provided");
7623 return -1;
7624 }
7625 l_rx_i = atoi(l_rx);
7626
7627 sigma_dut_print(dut, DUT_MSG_INFO,
7628 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
7629 mac, l_rx);
7630 if (l_rx_i != 16) {
7631 sigma_dut_print(dut, DUT_MSG_ERROR,
7632 "unsupported L-RX: %s", l_rx);
7633 return -1;
7634 }
7635
7636 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
7637 return -1;
7638 } else if (strcasecmp(frame_name, "ssw") == 0) {
7639 sigma_dut_print(dut, DUT_MSG_INFO,
7640 "dev_send_frame: SLS, dest_mac %s", mac);
7641 if (wil6210_send_sls(dut, mac))
7642 return -1;
7643 } else {
7644 sigma_dut_print(dut, DUT_MSG_ERROR,
7645 "unsupported frame type: %s", frame_name);
7646 return -1;
7647 }
7648
7649 return 1;
7650}
7651#endif /* __linux__ */
7652
7653
7654static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
7655 struct sigma_conn *conn,
7656 struct sigma_cmd *cmd)
7657{
7658 switch (get_driver_type()) {
7659#ifdef __linux__
7660 case DRIVER_WIL6210:
7661 return wil6210_send_frame_60g(dut, conn, cmd);
7662#endif /* __linux__ */
7663 default:
7664 send_resp(dut, conn, SIGMA_ERROR,
7665 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7666 return 0;
7667 }
7668}
7669
7670
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307671static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
7672 const char *intf, struct sigma_cmd *cmd)
7673{
7674 const char *val, *addr;
7675 char buf[100];
7676
7677 addr = get_param(cmd, "DestMac");
7678 if (!addr) {
7679 send_resp(dut, conn, SIGMA_INVALID,
7680 "ErrorCode,AP MAC address is missing");
7681 return 0;
7682 }
7683
7684 val = get_param(cmd, "ANQPQuery_ID");
7685 if (!val) {
7686 send_resp(dut, conn, SIGMA_INVALID,
7687 "ErrorCode,Missing ANQPQuery_ID");
7688 return 0;
7689 }
7690
7691 if (strcasecmp(val, "NeighborReportReq") == 0) {
7692 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
7693 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
7694 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
7695 } else {
7696 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
7697 val);
7698 send_resp(dut, conn, SIGMA_INVALID,
7699 "ErrorCode,Invalid ANQPQuery_ID");
7700 return 0;
7701 }
7702
Ashwini Patild174f2c2017-04-13 16:49:46 +05307703 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
7704 * (Address3 = Wildcard BSSID when sent to not-associated AP;
7705 * if associated, AP BSSID).
7706 */
7707 if (wpa_command(intf, "SET gas_address3 1") < 0) {
7708 send_resp(dut, conn, SIGMA_ERROR,
7709 "ErrorCode,Failed to set gas_address3");
7710 return 0;
7711 }
7712
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307713 if (wpa_command(intf, buf) < 0) {
7714 send_resp(dut, conn, SIGMA_ERROR,
7715 "ErrorCode,Failed to send ANQP query");
7716 return 0;
7717 }
7718
7719 return 1;
7720}
7721
7722
7723static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
7724 struct sigma_conn *conn,
7725 const char *intf,
7726 struct sigma_cmd *cmd)
7727{
7728 const char *val = get_param(cmd, "FrameName");
7729
7730 if (val && strcasecmp(val, "ANQPQuery") == 0)
7731 return mbo_send_anqp_query(dut, conn, intf, cmd);
7732
7733 return 2;
7734}
7735
7736
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007737int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7738 struct sigma_cmd *cmd)
7739{
7740 const char *intf = get_param(cmd, "Interface");
7741 const char *val;
7742 enum send_frame_type frame;
7743 enum send_frame_protection protected;
7744 char buf[100];
7745 unsigned char addr[ETH_ALEN];
7746 int res;
7747
7748 val = get_param(cmd, "program");
7749 if (val == NULL)
7750 val = get_param(cmd, "frame");
7751 if (val && strcasecmp(val, "TDLS") == 0)
7752 return cmd_sta_send_frame_tdls(dut, conn, cmd);
7753 if (val && (strcasecmp(val, "HS2") == 0 ||
7754 strcasecmp(val, "HS2-R2") == 0))
7755 return cmd_sta_send_frame_hs2(dut, conn, cmd);
7756 if (val && strcasecmp(val, "VHT") == 0)
7757 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007758 if (val && strcasecmp(val, "LOC") == 0)
7759 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007760 if (val && strcasecmp(val, "60GHz") == 0)
7761 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05307762 if (val && strcasecmp(val, "MBO") == 0) {
7763 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
7764 if (res != 2)
7765 return res;
7766 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007767
7768 val = get_param(cmd, "TD_DISC");
7769 if (val) {
7770 if (hwaddr_aton(val, addr) < 0)
7771 return -1;
7772 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
7773 if (wpa_command(intf, buf) < 0) {
7774 send_resp(dut, conn, SIGMA_ERROR,
7775 "ErrorCode,Failed to send TDLS discovery");
7776 return 0;
7777 }
7778 return 1;
7779 }
7780
7781 val = get_param(cmd, "TD_Setup");
7782 if (val) {
7783 if (hwaddr_aton(val, addr) < 0)
7784 return -1;
7785 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
7786 if (wpa_command(intf, buf) < 0) {
7787 send_resp(dut, conn, SIGMA_ERROR,
7788 "ErrorCode,Failed to start TDLS setup");
7789 return 0;
7790 }
7791 return 1;
7792 }
7793
7794 val = get_param(cmd, "TD_TearDown");
7795 if (val) {
7796 if (hwaddr_aton(val, addr) < 0)
7797 return -1;
7798 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
7799 if (wpa_command(intf, buf) < 0) {
7800 send_resp(dut, conn, SIGMA_ERROR,
7801 "ErrorCode,Failed to tear down TDLS link");
7802 return 0;
7803 }
7804 return 1;
7805 }
7806
7807 val = get_param(cmd, "TD_ChannelSwitch");
7808 if (val) {
7809 /* TODO */
7810 send_resp(dut, conn, SIGMA_ERROR,
7811 "ErrorCode,TD_ChannelSwitch not yet supported");
7812 return 0;
7813 }
7814
7815 val = get_param(cmd, "TD_NF");
7816 if (val) {
7817 /* TODO */
7818 send_resp(dut, conn, SIGMA_ERROR,
7819 "ErrorCode,TD_NF not yet supported");
7820 return 0;
7821 }
7822
7823 val = get_param(cmd, "PMFFrameType");
7824 if (val == NULL)
7825 val = get_param(cmd, "FrameName");
7826 if (val == NULL)
7827 val = get_param(cmd, "Type");
7828 if (val == NULL)
7829 return -1;
7830 if (strcasecmp(val, "disassoc") == 0)
7831 frame = DISASSOC;
7832 else if (strcasecmp(val, "deauth") == 0)
7833 frame = DEAUTH;
7834 else if (strcasecmp(val, "saquery") == 0)
7835 frame = SAQUERY;
7836 else if (strcasecmp(val, "auth") == 0)
7837 frame = AUTH;
7838 else if (strcasecmp(val, "assocreq") == 0)
7839 frame = ASSOCREQ;
7840 else if (strcasecmp(val, "reassocreq") == 0)
7841 frame = REASSOCREQ;
7842 else if (strcasecmp(val, "neigreq") == 0) {
7843 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
7844
7845 val = get_param(cmd, "ssid");
7846 if (val == NULL)
7847 return -1;
7848
7849 res = send_neighbor_request(dut, intf, val);
7850 if (res) {
7851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7852 "Failed to send neighbor report request");
7853 return 0;
7854 }
7855
7856 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307857 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
7858 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007859 sigma_dut_print(dut, DUT_MSG_DEBUG,
7860 "Got Transition Management Query");
7861
Ashwini Patil5acd7382017-04-13 15:55:04 +05307862 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007863 if (res) {
7864 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7865 "Failed to send Transition Management Query");
7866 return 0;
7867 }
7868
7869 return 1;
7870 } else {
7871 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7872 "PMFFrameType");
7873 return 0;
7874 }
7875
7876 val = get_param(cmd, "PMFProtected");
7877 if (val == NULL)
7878 val = get_param(cmd, "Protected");
7879 if (val == NULL)
7880 return -1;
7881 if (strcasecmp(val, "Correct-key") == 0 ||
7882 strcasecmp(val, "CorrectKey") == 0)
7883 protected = CORRECT_KEY;
7884 else if (strcasecmp(val, "IncorrectKey") == 0)
7885 protected = INCORRECT_KEY;
7886 else if (strcasecmp(val, "Unprotected") == 0)
7887 protected = UNPROTECTED;
7888 else {
7889 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7890 "PMFProtected");
7891 return 0;
7892 }
7893
7894 if (protected != UNPROTECTED &&
7895 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
7896 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
7897 "PMFProtected for auth/assocreq/reassocreq");
7898 return 0;
7899 }
7900
7901 if (if_nametoindex("sigmadut") == 0) {
7902 snprintf(buf, sizeof(buf),
7903 "iw dev %s interface add sigmadut type monitor",
7904 get_station_ifname());
7905 if (system(buf) != 0 ||
7906 if_nametoindex("sigmadut") == 0) {
7907 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7908 "monitor interface with '%s'", buf);
7909 return -2;
7910 }
7911 }
7912
7913 if (system("ifconfig sigmadut up") != 0) {
7914 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7915 "monitor interface up");
7916 return -2;
7917 }
7918
7919 return sta_inject_frame(dut, conn, frame, protected, NULL);
7920}
7921
7922
7923static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
7924 struct sigma_conn *conn,
7925 struct sigma_cmd *cmd,
7926 const char *ifname)
7927{
7928 char buf[200];
7929 const char *val;
7930
7931 val = get_param(cmd, "ClearARP");
7932 if (val && atoi(val) == 1) {
7933 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
7934 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7935 if (system(buf) != 0) {
7936 send_resp(dut, conn, SIGMA_ERROR,
7937 "errorCode,Failed to clear ARP cache");
7938 return 0;
7939 }
7940 }
7941
7942 return 1;
7943}
7944
7945
7946int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
7947 struct sigma_cmd *cmd)
7948{
7949 const char *intf = get_param(cmd, "Interface");
7950 const char *val;
7951
7952 if (intf == NULL)
7953 return -1;
7954
7955 val = get_param(cmd, "program");
7956 if (val && (strcasecmp(val, "HS2") == 0 ||
7957 strcasecmp(val, "HS2-R2") == 0))
7958 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
7959
7960 return -1;
7961}
7962
7963
7964static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
7965 struct sigma_cmd *cmd)
7966{
7967 const char *intf = get_param(cmd, "Interface");
7968 const char *mac = get_param(cmd, "MAC");
7969
7970 if (intf == NULL || mac == NULL)
7971 return -1;
7972
7973 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
7974 "interface %s to %s", intf, mac);
7975
7976 if (dut->set_macaddr) {
7977 char buf[128];
7978 int res;
7979 if (strcasecmp(mac, "default") == 0) {
7980 res = snprintf(buf, sizeof(buf), "%s",
7981 dut->set_macaddr);
7982 dut->tmp_mac_addr = 0;
7983 } else {
7984 res = snprintf(buf, sizeof(buf), "%s %s",
7985 dut->set_macaddr, mac);
7986 dut->tmp_mac_addr = 1;
7987 }
7988 if (res < 0 || res >= (int) sizeof(buf))
7989 return -1;
7990 if (system(buf) != 0) {
7991 send_resp(dut, conn, SIGMA_ERROR,
7992 "errorCode,Failed to set MAC "
7993 "address");
7994 return 0;
7995 }
7996 return 1;
7997 }
7998
7999 if (strcasecmp(mac, "default") == 0)
8000 return 1;
8001
8002 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8003 "command");
8004 return 0;
8005}
8006
8007
8008static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
8009 struct sigma_conn *conn, const char *intf,
8010 int val)
8011{
8012 char buf[200];
8013 int res;
8014
8015 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
8016 intf, val);
8017 if (res < 0 || res >= (int) sizeof(buf))
8018 return -1;
8019 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8020 if (system(buf) != 0) {
8021 send_resp(dut, conn, SIGMA_ERROR,
8022 "errorCode,Failed to configure offchannel mode");
8023 return 0;
8024 }
8025
8026 return 1;
8027}
8028
8029
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008030static int off_chan_val(enum sec_ch_offset off)
8031{
8032 switch (off) {
8033 case SEC_CH_NO:
8034 return 0;
8035 case SEC_CH_40ABOVE:
8036 return 40;
8037 case SEC_CH_40BELOW:
8038 return -40;
8039 }
8040
8041 return 0;
8042}
8043
8044
8045static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
8046 const char *intf, int off_ch_num,
8047 enum sec_ch_offset sec)
8048{
8049 char buf[200];
8050 int res;
8051
8052 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
8053 intf, off_ch_num);
8054 if (res < 0 || res >= (int) sizeof(buf))
8055 return -1;
8056 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8057 if (system(buf) != 0) {
8058 send_resp(dut, conn, SIGMA_ERROR,
8059 "errorCode,Failed to set offchan");
8060 return 0;
8061 }
8062
8063 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
8064 intf, off_chan_val(sec));
8065 if (res < 0 || res >= (int) sizeof(buf))
8066 return -1;
8067 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8068 if (system(buf) != 0) {
8069 send_resp(dut, conn, SIGMA_ERROR,
8070 "errorCode,Failed to set sec chan offset");
8071 return 0;
8072 }
8073
8074 return 1;
8075}
8076
8077
8078static int tdls_set_offchannel_offset(struct sigma_dut *dut,
8079 struct sigma_conn *conn,
8080 const char *intf, int off_ch_num,
8081 enum sec_ch_offset sec)
8082{
8083 char buf[200];
8084 int res;
8085
8086 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
8087 off_ch_num);
8088 if (res < 0 || res >= (int) sizeof(buf))
8089 return -1;
8090 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8091
8092 if (wpa_command(intf, buf) < 0) {
8093 send_resp(dut, conn, SIGMA_ERROR,
8094 "ErrorCode,Failed to set offchan");
8095 return 0;
8096 }
8097 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
8098 off_chan_val(sec));
8099 if (res < 0 || res >= (int) sizeof(buf))
8100 return -1;
8101
8102 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8103
8104 if (wpa_command(intf, buf) < 0) {
8105 send_resp(dut, conn, SIGMA_ERROR,
8106 "ErrorCode,Failed to set sec chan offset");
8107 return 0;
8108 }
8109
8110 return 1;
8111}
8112
8113
8114static int tdls_set_offchannel_mode(struct sigma_dut *dut,
8115 struct sigma_conn *conn,
8116 const char *intf, int val)
8117{
8118 char buf[200];
8119 int res;
8120
8121 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
8122 val);
8123 if (res < 0 || res >= (int) sizeof(buf))
8124 return -1;
8125 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8126
8127 if (wpa_command(intf, buf) < 0) {
8128 send_resp(dut, conn, SIGMA_ERROR,
8129 "ErrorCode,Failed to configure offchannel mode");
8130 return 0;
8131 }
8132
8133 return 1;
8134}
8135
8136
8137static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
8138 struct sigma_conn *conn,
8139 struct sigma_cmd *cmd)
8140{
8141 const char *val;
8142 enum {
8143 CHSM_NOT_SET,
8144 CHSM_ENABLE,
8145 CHSM_DISABLE,
8146 CHSM_REJREQ,
8147 CHSM_UNSOLRESP
8148 } chsm = CHSM_NOT_SET;
8149 int off_ch_num = -1;
8150 enum sec_ch_offset sec_ch = SEC_CH_NO;
8151 int res;
8152
8153 val = get_param(cmd, "Uapsd");
8154 if (val) {
8155 char buf[100];
8156 if (strcasecmp(val, "Enable") == 0)
8157 snprintf(buf, sizeof(buf), "SET ps 99");
8158 else if (strcasecmp(val, "Disable") == 0)
8159 snprintf(buf, sizeof(buf), "SET ps 98");
8160 else {
8161 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
8162 "Unsupported uapsd parameter value");
8163 return 0;
8164 }
8165 if (wpa_command(intf, buf)) {
8166 send_resp(dut, conn, SIGMA_ERROR,
8167 "ErrorCode,Failed to change U-APSD "
8168 "powersave mode");
8169 return 0;
8170 }
8171 }
8172
8173 val = get_param(cmd, "TPKTIMER");
8174 if (val && strcasecmp(val, "DISABLE") == 0) {
8175 if (wpa_command(intf, "SET tdls_testing 0x100")) {
8176 send_resp(dut, conn, SIGMA_ERROR,
8177 "ErrorCode,Failed to enable no TPK "
8178 "expiration test mode");
8179 return 0;
8180 }
8181 dut->no_tpk_expiration = 1;
8182 }
8183
8184 val = get_param(cmd, "ChSwitchMode");
8185 if (val) {
8186 if (strcasecmp(val, "Enable") == 0 ||
8187 strcasecmp(val, "Initiate") == 0)
8188 chsm = CHSM_ENABLE;
8189 else if (strcasecmp(val, "Disable") == 0 ||
8190 strcasecmp(val, "passive") == 0)
8191 chsm = CHSM_DISABLE;
8192 else if (strcasecmp(val, "RejReq") == 0)
8193 chsm = CHSM_REJREQ;
8194 else if (strcasecmp(val, "UnSolResp") == 0)
8195 chsm = CHSM_UNSOLRESP;
8196 else {
8197 send_resp(dut, conn, SIGMA_ERROR,
8198 "ErrorCode,Unknown ChSwitchMode value");
8199 return 0;
8200 }
8201 }
8202
8203 val = get_param(cmd, "OffChNum");
8204 if (val) {
8205 off_ch_num = atoi(val);
8206 if (off_ch_num == 0) {
8207 send_resp(dut, conn, SIGMA_ERROR,
8208 "ErrorCode,Invalid OffChNum");
8209 return 0;
8210 }
8211 }
8212
8213 val = get_param(cmd, "SecChOffset");
8214 if (val) {
8215 if (strcmp(val, "20") == 0)
8216 sec_ch = SEC_CH_NO;
8217 else if (strcasecmp(val, "40above") == 0)
8218 sec_ch = SEC_CH_40ABOVE;
8219 else if (strcasecmp(val, "40below") == 0)
8220 sec_ch = SEC_CH_40BELOW;
8221 else {
8222 send_resp(dut, conn, SIGMA_ERROR,
8223 "ErrorCode,Unknown SecChOffset value");
8224 return 0;
8225 }
8226 }
8227
8228 if (chsm == CHSM_NOT_SET) {
8229 /* no offchannel changes requested */
8230 return 1;
8231 }
8232
8233 if (strcmp(intf, get_main_ifname()) != 0 &&
8234 strcmp(intf, get_station_ifname()) != 0) {
8235 send_resp(dut, conn, SIGMA_ERROR,
8236 "ErrorCode,Unknown interface");
8237 return 0;
8238 }
8239
8240 switch (chsm) {
8241 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03008242 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008243 break;
8244 case CHSM_ENABLE:
8245 if (off_ch_num < 0) {
8246 send_resp(dut, conn, SIGMA_ERROR,
8247 "ErrorCode,Missing OffChNum argument");
8248 return 0;
8249 }
8250 if (wifi_chip_type == DRIVER_WCN) {
8251 res = tdls_set_offchannel_offset(dut, conn, intf,
8252 off_ch_num, sec_ch);
8253 } else {
8254 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8255 sec_ch);
8256 }
8257 if (res != 1)
8258 return res;
8259 if (wifi_chip_type == DRIVER_WCN)
8260 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
8261 else
8262 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
8263 break;
8264 case CHSM_DISABLE:
8265 if (wifi_chip_type == DRIVER_WCN)
8266 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
8267 else
8268 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
8269 break;
8270 case CHSM_REJREQ:
8271 if (wifi_chip_type == DRIVER_WCN)
8272 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
8273 else
8274 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
8275 break;
8276 case CHSM_UNSOLRESP:
8277 if (off_ch_num < 0) {
8278 send_resp(dut, conn, SIGMA_ERROR,
8279 "ErrorCode,Missing OffChNum argument");
8280 return 0;
8281 }
8282 if (wifi_chip_type == DRIVER_WCN) {
8283 res = tdls_set_offchannel_offset(dut, conn, intf,
8284 off_ch_num, sec_ch);
8285 } else {
8286 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
8287 sec_ch);
8288 }
8289 if (res != 1)
8290 return res;
8291 if (wifi_chip_type == DRIVER_WCN)
8292 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
8293 else
8294 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
8295 break;
8296 }
8297
8298 return res;
8299}
8300
8301
8302static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8303 struct sigma_conn *conn,
8304 struct sigma_cmd *cmd)
8305{
8306 const char *val;
8307 char *token, *result;
8308
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008309 novap_reset(dut, intf);
8310
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008311 val = get_param(cmd, "nss_mcs_opt");
8312 if (val) {
8313 /* String (nss_operating_mode; mcs_operating_mode) */
8314 int nss, mcs;
8315 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308316 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008317
8318 token = strdup(val);
8319 if (!token)
8320 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308321 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308322 if (!result) {
8323 sigma_dut_print(dut, DUT_MSG_ERROR,
8324 "VHT NSS not specified");
8325 goto failed;
8326 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008327 if (strcasecmp(result, "def") != 0) {
8328 nss = atoi(result);
8329 if (nss == 4)
8330 ath_disable_txbf(dut, intf);
8331 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
8332 intf, nss);
8333 if (system(buf) != 0) {
8334 sigma_dut_print(dut, DUT_MSG_ERROR,
8335 "iwpriv nss failed");
8336 goto failed;
8337 }
8338 }
8339
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308340 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308341 if (!result) {
8342 sigma_dut_print(dut, DUT_MSG_ERROR,
8343 "VHT MCS not specified");
8344 goto failed;
8345 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008346 if (strcasecmp(result, "def") == 0) {
8347 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
8348 intf);
8349 if (system(buf) != 0) {
8350 sigma_dut_print(dut, DUT_MSG_ERROR,
8351 "iwpriv set11NRates failed");
8352 goto failed;
8353 }
8354
8355 } else {
8356 mcs = atoi(result);
8357 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
8358 intf, mcs);
8359 if (system(buf) != 0) {
8360 sigma_dut_print(dut, DUT_MSG_ERROR,
8361 "iwpriv vhtmcs failed");
8362 goto failed;
8363 }
8364 }
8365 /* Channel width gets messed up, fix this */
8366 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8367 intf, dut->chwidth);
8368 if (system(buf) != 0) {
8369 sigma_dut_print(dut, DUT_MSG_ERROR,
8370 "iwpriv chwidth failed");
8371 }
8372 }
8373
8374 return 1;
8375failed:
8376 free(token);
8377 return 0;
8378}
8379
8380
8381static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
8382 struct sigma_conn *conn,
8383 struct sigma_cmd *cmd)
8384{
8385 switch (get_driver_type()) {
8386 case DRIVER_ATHEROS:
8387 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
8388 default:
8389 send_resp(dut, conn, SIGMA_ERROR,
8390 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
8391 return 0;
8392 }
8393}
8394
8395
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008396static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8397 struct sigma_conn *conn,
8398 struct sigma_cmd *cmd)
8399{
8400 const char *val;
8401 char *token = NULL, *result;
8402 char buf[60];
8403
8404 val = get_param(cmd, "nss_mcs_opt");
8405 if (val) {
8406 /* String (nss_operating_mode; mcs_operating_mode) */
8407 int nss, mcs, ratecode;
8408 char *saveptr;
8409
8410 token = strdup(val);
8411 if (!token)
8412 return -2;
8413
8414 result = strtok_r(token, ";", &saveptr);
8415 if (!result) {
8416 sigma_dut_print(dut, DUT_MSG_ERROR,
8417 "HE NSS not specified");
8418 goto failed;
8419 }
8420 nss = 1;
8421 if (strcasecmp(result, "def") != 0)
8422 nss = atoi(result);
8423
8424 result = strtok_r(NULL, ";", &saveptr);
8425 if (!result) {
8426 sigma_dut_print(dut, DUT_MSG_ERROR,
8427 "HE MCS not specified");
8428 goto failed;
8429 }
8430 mcs = 7;
8431 if (strcasecmp(result, "def") != 0)
8432 mcs = atoi(result);
8433
8434 ratecode = 0x400; /* for nss:1 MCS 0 */
8435 if (nss == 2) {
8436 ratecode = 0x420; /* for nss:2 MCS 0 */
8437 } else if (nss > 2) {
8438 sigma_dut_print(dut, DUT_MSG_ERROR,
8439 "HE NSS %d not supported", nss);
8440 goto failed;
8441 }
8442
8443 /* Add the MCS to the ratecode */
8444 if (mcs >= 0 && mcs <= 11) {
8445 ratecode += mcs;
8446 } else {
8447 sigma_dut_print(dut, DUT_MSG_ERROR,
8448 "HE MCS %d not supported", mcs);
8449 goto failed;
8450 }
8451 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
8452 intf, ratecode);
8453 if (system(buf) != 0) {
8454 sigma_dut_print(dut, DUT_MSG_ERROR,
8455 "iwpriv setting of 11ax rates failed");
8456 goto failed;
8457 }
8458 free(token);
8459 }
8460
8461 val = get_param(cmd, "GI");
8462 if (val) {
8463 if (strcmp(val, "0.8") == 0) {
8464 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
8465 } else if (strcmp(val, "1.6") == 0) {
8466 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 2", intf);
8467 } else if (strcmp(val, "3.2") == 0) {
8468 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 3", intf);
8469 } else {
8470 send_resp(dut, conn, SIGMA_ERROR,
8471 "errorCode,GI value not supported");
8472 return 0;
8473 }
8474 if (system(buf) != 0) {
8475 send_resp(dut, conn, SIGMA_ERROR,
8476 "errorCode,Failed to set shortgi");
8477 return 0;
8478 }
8479 }
8480
8481 return 1;
8482
8483failed:
8484 free(token);
8485 return -2;
8486}
8487
8488
8489static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
8490 struct sigma_conn *conn,
8491 struct sigma_cmd *cmd)
8492{
8493 switch (get_driver_type()) {
8494 case DRIVER_WCN:
8495 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
8496 default:
8497 send_resp(dut, conn, SIGMA_ERROR,
8498 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
8499 return 0;
8500 }
8501}
8502
8503
Ashwini Patil5acd7382017-04-13 15:55:04 +05308504static int btm_query_candidate_list(struct sigma_dut *dut,
8505 struct sigma_conn *conn,
8506 struct sigma_cmd *cmd)
8507{
8508 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
8509 int len, ret;
8510 char buf[10];
8511
8512 /*
8513 * Neighbor Report elements format:
8514 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
8515 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
8516 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
8517 */
8518
8519 bssid = get_param(cmd, "Nebor_BSSID");
8520 if (!bssid) {
8521 send_resp(dut, conn, SIGMA_INVALID,
8522 "errorCode,Nebor_BSSID is missing");
8523 return 0;
8524 }
8525
8526 info = get_param(cmd, "Nebor_Bssid_Info");
8527 if (!info) {
8528 sigma_dut_print(dut, DUT_MSG_INFO,
8529 "Using default value for Nebor_Bssid_Info: %s",
8530 DEFAULT_NEIGHBOR_BSSID_INFO);
8531 info = DEFAULT_NEIGHBOR_BSSID_INFO;
8532 }
8533
8534 op_class = get_param(cmd, "Nebor_Op_Class");
8535 if (!op_class) {
8536 send_resp(dut, conn, SIGMA_INVALID,
8537 "errorCode,Nebor_Op_Class is missing");
8538 return 0;
8539 }
8540
8541 ch = get_param(cmd, "Nebor_Op_Ch");
8542 if (!ch) {
8543 send_resp(dut, conn, SIGMA_INVALID,
8544 "errorCode,Nebor_Op_Ch is missing");
8545 return 0;
8546 }
8547
8548 phy_type = get_param(cmd, "Nebor_Phy_Type");
8549 if (!phy_type) {
8550 sigma_dut_print(dut, DUT_MSG_INFO,
8551 "Using default value for Nebor_Phy_Type: %s",
8552 DEFAULT_NEIGHBOR_PHY_TYPE);
8553 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
8554 }
8555
8556 /* Parse optional subelements */
8557 buf[0] = '\0';
8558 pref = get_param(cmd, "Nebor_Pref");
8559 if (pref) {
8560 /* hexdump for preferrence subelement */
8561 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
8562 if (ret < 0 || ret >= (int) sizeof(buf)) {
8563 sigma_dut_print(dut, DUT_MSG_ERROR,
8564 "snprintf failed for optional subelement ret: %d",
8565 ret);
8566 send_resp(dut, conn, SIGMA_ERROR,
8567 "errorCode,snprintf failed for subelement");
8568 return 0;
8569 }
8570 }
8571
8572 if (!dut->btm_query_cand_list) {
8573 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
8574 if (!dut->btm_query_cand_list) {
8575 send_resp(dut, conn, SIGMA_ERROR,
8576 "errorCode,Failed to allocate memory for btm_query_cand_list");
8577 return 0;
8578 }
8579 }
8580
8581 len = strlen(dut->btm_query_cand_list);
8582 ret = snprintf(dut->btm_query_cand_list + len,
8583 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
8584 bssid, info, op_class, ch, phy_type, buf);
8585 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
8586 sigma_dut_print(dut, DUT_MSG_ERROR,
8587 "snprintf failed for neighbor report list ret: %d",
8588 ret);
8589 send_resp(dut, conn, SIGMA_ERROR,
8590 "errorCode,snprintf failed for neighbor report");
8591 free(dut->btm_query_cand_list);
8592 dut->btm_query_cand_list = NULL;
8593 return 0;
8594 }
8595
8596 return 1;
8597}
8598
8599
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008600static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8601 struct sigma_cmd *cmd)
8602{
8603 const char *intf = get_param(cmd, "Interface");
8604 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308605 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008606
8607 if (intf == NULL || prog == NULL)
8608 return -1;
8609
Ashwini Patil5acd7382017-04-13 15:55:04 +05308610 /* BSS Transition candidate list for BTM query */
8611 val = get_param(cmd, "Nebor_BSSID");
8612 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
8613 return 0;
8614
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008615 if (strcasecmp(prog, "TDLS") == 0)
8616 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
8617
8618 if (strcasecmp(prog, "VHT") == 0)
8619 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
8620
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08008621 if (strcasecmp(prog, "HE") == 0)
8622 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
8623
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308624 if (strcasecmp(prog, "MBO") == 0) {
8625 val = get_param(cmd, "Cellular_Data_Cap");
8626 if (val &&
8627 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
8628 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05308629
8630 val = get_param(cmd, "Ch_Pref");
8631 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
8632 return 0;
8633
Ashwini Patil68d02cd2017-01-10 15:39:16 +05308634 return 1;
8635 }
8636
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
8638 return 0;
8639}
8640
8641
8642static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
8643 struct sigma_cmd *cmd)
8644{
8645 const char *intf = get_param(cmd, "Interface");
8646 const char *mode = get_param(cmd, "Mode");
8647 int res;
8648
8649 if (intf == NULL || mode == NULL)
8650 return -1;
8651
8652 if (strcasecmp(mode, "On") == 0)
8653 res = wpa_command(intf, "SET radio_disabled 0");
8654 else if (strcasecmp(mode, "Off") == 0)
8655 res = wpa_command(intf, "SET radio_disabled 1");
8656 else
8657 return -1;
8658
8659 if (res) {
8660 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8661 "radio mode");
8662 return 0;
8663 }
8664
8665 return 1;
8666}
8667
8668
8669static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
8670 struct sigma_cmd *cmd)
8671{
8672 const char *intf = get_param(cmd, "Interface");
8673 const char *mode = get_param(cmd, "Mode");
8674 int res;
8675
8676 if (intf == NULL || mode == NULL)
8677 return -1;
8678
8679 if (strcasecmp(mode, "On") == 0)
8680 res = set_ps(intf, dut, 1);
8681 else if (strcasecmp(mode, "Off") == 0)
8682 res = set_ps(intf, dut, 0);
8683 else
8684 return -1;
8685
8686 if (res) {
8687 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
8688 "power save mode");
8689 return 0;
8690 }
8691
8692 return 1;
8693}
8694
8695
8696static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
8697 struct sigma_cmd *cmd)
8698{
8699 const char *intf = get_param(cmd, "Interface");
8700 const char *val, *bssid;
8701 int res;
8702 char *buf;
8703 size_t buf_len;
8704
8705 val = get_param(cmd, "BSSID_FILTER");
8706 if (val == NULL)
8707 return -1;
8708
8709 bssid = get_param(cmd, "BSSID_List");
8710 if (atoi(val) == 0 || bssid == NULL) {
8711 /* Disable BSSID filter */
8712 if (wpa_command(intf, "SET bssid_filter ")) {
8713 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
8714 "to disable BSSID filter");
8715 return 0;
8716 }
8717
8718 return 1;
8719 }
8720
8721 buf_len = 100 + strlen(bssid);
8722 buf = malloc(buf_len);
8723 if (buf == NULL)
8724 return -1;
8725
8726 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
8727 res = wpa_command(intf, buf);
8728 free(buf);
8729 if (res) {
8730 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
8731 "BSSID filter");
8732 return 0;
8733 }
8734
8735 return 1;
8736}
8737
8738
8739static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
8740 struct sigma_cmd *cmd)
8741{
8742 const char *intf = get_param(cmd, "Interface");
8743 const char *val;
8744
8745 /* TODO: ARP */
8746
8747 val = get_param(cmd, "HS2_CACHE_PROFILE");
8748 if (val && strcasecmp(val, "All") == 0)
8749 hs2_clear_credentials(intf);
8750
8751 return 1;
8752}
8753
8754
8755static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
8756 struct sigma_cmd *cmd)
8757{
8758 const char *intf = get_param(cmd, "Interface");
8759 const char *key_type = get_param(cmd, "KeyType");
8760 char buf[100], resp[200];
8761
8762 if (key_type == NULL)
8763 return -1;
8764
8765 if (strcasecmp(key_type, "GTK") == 0) {
8766 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
8767 strncmp(buf, "FAIL", 4) == 0) {
8768 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8769 "not fetch current GTK");
8770 return 0;
8771 }
8772 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
8773 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8774 return 0;
8775 } else {
8776 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8777 "KeyType");
8778 return 0;
8779 }
8780
8781 return 1;
8782}
8783
8784
8785static int hs2_set_policy(struct sigma_dut *dut)
8786{
8787#ifdef ANDROID
8788 system("ip rule del prio 23000");
8789 if (system("ip rule add from all lookup main prio 23000") != 0) {
8790 sigma_dut_print(dut, DUT_MSG_ERROR,
8791 "Failed to run:ip rule add from all lookup main prio");
8792 return -1;
8793 }
8794 if (system("ip route flush cache") != 0) {
8795 sigma_dut_print(dut, DUT_MSG_ERROR,
8796 "Failed to run ip route flush cache");
8797 return -1;
8798 }
8799 return 1;
8800#else /* ANDROID */
8801 return 0;
8802#endif /* ANDROID */
8803}
8804
8805
8806static int cmd_sta_hs2_associate(struct sigma_dut *dut,
8807 struct sigma_conn *conn,
8808 struct sigma_cmd *cmd)
8809{
8810 const char *intf = get_param(cmd, "Interface");
8811 const char *val = get_param(cmd, "Ignore_blacklist");
8812 struct wpa_ctrl *ctrl;
8813 int res;
8814 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
8815 int tries = 0;
8816 int ignore_blacklist = 0;
8817 const char *events[] = {
8818 "CTRL-EVENT-CONNECTED",
8819 "INTERWORKING-BLACKLISTED",
8820 "INTERWORKING-NO-MATCH",
8821 NULL
8822 };
8823
8824 start_sta_mode(dut);
8825
8826 blacklisted[0] = '\0';
8827 if (val && atoi(val))
8828 ignore_blacklist = 1;
8829
8830try_again:
8831 ctrl = open_wpa_mon(intf);
8832 if (ctrl == NULL) {
8833 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8834 "wpa_supplicant monitor connection");
8835 return -2;
8836 }
8837
8838 tries++;
8839 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
8840 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
8841 "Interworking connection");
8842 wpa_ctrl_detach(ctrl);
8843 wpa_ctrl_close(ctrl);
8844 return 0;
8845 }
8846
8847 buf[0] = '\0';
8848 while (1) {
8849 char *pos;
8850 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
8851 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
8852 if (!pos)
8853 break;
8854 pos += 25;
8855 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
8856 pos);
8857 if (!blacklisted[0])
8858 memcpy(blacklisted, pos, strlen(pos) + 1);
8859 }
8860
8861 if (ignore_blacklist && blacklisted[0]) {
8862 char *end;
8863 end = strchr(blacklisted, ' ');
8864 if (end)
8865 *end = '\0';
8866 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
8867 blacklisted);
8868 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
8869 blacklisted);
8870 if (wpa_command(intf, buf)) {
8871 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
8872 wpa_ctrl_detach(ctrl);
8873 wpa_ctrl_close(ctrl);
8874 return 0;
8875 }
8876 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8877 buf, sizeof(buf));
8878 }
8879
8880 wpa_ctrl_detach(ctrl);
8881 wpa_ctrl_close(ctrl);
8882
8883 if (res < 0) {
8884 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8885 "connect");
8886 return 0;
8887 }
8888
8889 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
8890 strstr(buf, "INTERWORKING-BLACKLISTED")) {
8891 if (tries < 2) {
8892 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
8893 goto try_again;
8894 }
8895 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
8896 "matching credentials found");
8897 return 0;
8898 }
8899
8900 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8901 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8902 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
8903 "get current BSSID/SSID");
8904 return 0;
8905 }
8906
8907 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
8908 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8909 hs2_set_policy(dut);
8910 return 0;
8911}
8912
8913
8914static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
8915 struct sigma_conn *conn,
8916 const char *ifname,
8917 struct sigma_cmd *cmd)
8918{
8919 const char *val;
8920 int id;
8921
8922 id = add_cred(ifname);
8923 if (id < 0)
8924 return -2;
8925 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8926
8927 val = get_param(cmd, "prefer");
8928 if (val && atoi(val) > 0)
8929 set_cred(ifname, id, "priority", "1");
8930
8931 val = get_param(cmd, "REALM");
8932 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
8933 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8934 "realm");
8935 return 0;
8936 }
8937
8938 val = get_param(cmd, "HOME_FQDN");
8939 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
8940 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8941 "home_fqdn");
8942 return 0;
8943 }
8944
8945 val = get_param(cmd, "Username");
8946 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
8947 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8948 "username");
8949 return 0;
8950 }
8951
8952 val = get_param(cmd, "Password");
8953 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
8954 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8955 "password");
8956 return 0;
8957 }
8958
8959 val = get_param(cmd, "ROOT_CA");
8960 if (val) {
8961 char fname[200];
8962 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8963#ifdef __linux__
8964 if (!file_exists(fname)) {
8965 char msg[300];
8966 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
8967 "file (%s) not found", fname);
8968 send_resp(dut, conn, SIGMA_ERROR, msg);
8969 return 0;
8970 }
8971#endif /* __linux__ */
8972 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
8973 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8974 "not set root CA");
8975 return 0;
8976 }
8977 }
8978
8979 return 1;
8980}
8981
8982
8983static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
8984{
8985 FILE *in, *out;
8986 char buf[500];
8987 int found = 0;
8988
8989 in = fopen("devdetail.xml", "r");
8990 if (in == NULL)
8991 return -1;
8992 out = fopen("devdetail.xml.tmp", "w");
8993 if (out == NULL) {
8994 fclose(in);
8995 return -1;
8996 }
8997
8998 while (fgets(buf, sizeof(buf), in)) {
8999 char *pos = strstr(buf, "<IMSI>");
9000 if (pos) {
9001 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
9002 imsi);
9003 pos += 6;
9004 *pos = '\0';
9005 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
9006 found++;
9007 } else {
9008 fprintf(out, "%s", buf);
9009 }
9010 }
9011
9012 fclose(out);
9013 fclose(in);
9014 if (found)
9015 rename("devdetail.xml.tmp", "devdetail.xml");
9016 else
9017 unlink("devdetail.xml.tmp");
9018
9019 return 0;
9020}
9021
9022
9023static int sta_add_credential_sim(struct sigma_dut *dut,
9024 struct sigma_conn *conn,
9025 const char *ifname, struct sigma_cmd *cmd)
9026{
9027 const char *val, *imsi = NULL;
9028 int id;
9029 char buf[200];
9030 int res;
9031 const char *pos;
9032 size_t mnc_len;
9033 char plmn_mcc[4];
9034 char plmn_mnc[4];
9035
9036 id = add_cred(ifname);
9037 if (id < 0)
9038 return -2;
9039 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9040
9041 val = get_param(cmd, "prefer");
9042 if (val && atoi(val) > 0)
9043 set_cred(ifname, id, "priority", "1");
9044
9045 val = get_param(cmd, "PLMN_MCC");
9046 if (val == NULL) {
9047 send_resp(dut, conn, SIGMA_ERROR,
9048 "errorCode,Missing PLMN_MCC");
9049 return 0;
9050 }
9051 if (strlen(val) != 3) {
9052 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
9053 return 0;
9054 }
9055 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
9056
9057 val = get_param(cmd, "PLMN_MNC");
9058 if (val == NULL) {
9059 send_resp(dut, conn, SIGMA_ERROR,
9060 "errorCode,Missing PLMN_MNC");
9061 return 0;
9062 }
9063 if (strlen(val) != 2 && strlen(val) != 3) {
9064 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
9065 return 0;
9066 }
9067 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
9068
9069 val = get_param(cmd, "IMSI");
9070 if (val == NULL) {
9071 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
9072 "IMSI");
9073 return 0;
9074 }
9075
9076 imsi = pos = val;
9077
9078 if (strncmp(plmn_mcc, pos, 3) != 0) {
9079 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
9080 return 0;
9081 }
9082 pos += 3;
9083
9084 mnc_len = strlen(plmn_mnc);
9085 if (mnc_len < 2) {
9086 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
9087 return 0;
9088 }
9089
9090 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
9091 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
9092 return 0;
9093 }
9094 pos += mnc_len;
9095
9096 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
9097 if (res < 0 || res >= (int) sizeof(buf))
9098 return -1;
9099 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
9100 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9101 "not set IMSI");
9102 return 0;
9103 }
9104
9105 val = get_param(cmd, "Password");
9106 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
9107 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9108 "not set password");
9109 return 0;
9110 }
9111
9112 if (dut->program == PROGRAM_HS2_R2) {
9113 /*
9114 * Set provisioning_sp for the test cases where SIM/USIM
9115 * provisioning is used.
9116 */
9117 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
9118 "wi-fi.org") < 0) {
9119 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9120 "not set provisioning_sp");
9121 return 0;
9122 }
9123
9124 update_devdetail_imsi(dut, imsi);
9125 }
9126
9127 return 1;
9128}
9129
9130
9131static int sta_add_credential_cert(struct sigma_dut *dut,
9132 struct sigma_conn *conn,
9133 const char *ifname,
9134 struct sigma_cmd *cmd)
9135{
9136 const char *val;
9137 int id;
9138
9139 id = add_cred(ifname);
9140 if (id < 0)
9141 return -2;
9142 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
9143
9144 val = get_param(cmd, "prefer");
9145 if (val && atoi(val) > 0)
9146 set_cred(ifname, id, "priority", "1");
9147
9148 val = get_param(cmd, "REALM");
9149 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
9150 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9151 "realm");
9152 return 0;
9153 }
9154
9155 val = get_param(cmd, "HOME_FQDN");
9156 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
9157 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9158 "home_fqdn");
9159 return 0;
9160 }
9161
9162 val = get_param(cmd, "Username");
9163 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
9164 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
9165 "username");
9166 return 0;
9167 }
9168
9169 val = get_param(cmd, "clientCertificate");
9170 if (val) {
9171 char fname[200];
9172 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9173#ifdef __linux__
9174 if (!file_exists(fname)) {
9175 char msg[300];
9176 snprintf(msg, sizeof(msg),
9177 "ErrorCode,clientCertificate "
9178 "file (%s) not found", fname);
9179 send_resp(dut, conn, SIGMA_ERROR, msg);
9180 return 0;
9181 }
9182#endif /* __linux__ */
9183 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
9184 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9185 "not set client_cert");
9186 return 0;
9187 }
9188 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
9189 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9190 "not set private_key");
9191 return 0;
9192 }
9193 }
9194
9195 val = get_param(cmd, "ROOT_CA");
9196 if (val) {
9197 char fname[200];
9198 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
9199#ifdef __linux__
9200 if (!file_exists(fname)) {
9201 char msg[300];
9202 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
9203 "file (%s) not found", fname);
9204 send_resp(dut, conn, SIGMA_ERROR, msg);
9205 return 0;
9206 }
9207#endif /* __linux__ */
9208 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
9209 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
9210 "not set root CA");
9211 return 0;
9212 }
9213 }
9214
9215 return 1;
9216}
9217
9218
9219static int cmd_sta_add_credential(struct sigma_dut *dut,
9220 struct sigma_conn *conn,
9221 struct sigma_cmd *cmd)
9222{
9223 const char *intf = get_param(cmd, "Interface");
9224 const char *type;
9225
9226 start_sta_mode(dut);
9227
9228 type = get_param(cmd, "Type");
9229 if (!type)
9230 return -1;
9231
9232 if (strcasecmp(type, "uname_pwd") == 0)
9233 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
9234
9235 if (strcasecmp(type, "sim") == 0)
9236 return sta_add_credential_sim(dut, conn, intf, cmd);
9237
9238 if (strcasecmp(type, "cert") == 0)
9239 return sta_add_credential_cert(dut, conn, intf, cmd);
9240
9241 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
9242 "type");
9243 return 0;
9244}
9245
9246
9247static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
9248 struct sigma_cmd *cmd)
9249{
9250 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +05309251 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009252 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +05309253 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009254 int res;
9255
9256 val = get_param(cmd, "HESSID");
9257 if (val) {
9258 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
9259 if (res < 0 || res >= (int) sizeof(buf))
9260 return -1;
9261 wpa_command(intf, buf);
9262 }
9263
9264 val = get_param(cmd, "ACCS_NET_TYPE");
9265 if (val) {
9266 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
9267 val);
9268 if (res < 0 || res >= (int) sizeof(buf))
9269 return -1;
9270 wpa_command(intf, buf);
9271 }
9272
vamsi krishna89ad8c62017-09-19 12:51:18 +05309273 bssid = get_param(cmd, "Bssid");
9274 ssid = get_param(cmd, "Ssid");
9275
9276 if (ssid) {
9277 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
9278 send_resp(dut, conn, SIGMA_ERROR,
9279 "ErrorCode,Too long SSID");
9280 return 0;
9281 }
9282 ascii2hexstr(ssid, ssid_hex);
9283 }
9284
9285 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
9286 bssid ? " bssid=": "",
9287 bssid ? bssid : "",
9288 ssid ? " ssid " : "",
9289 ssid ? ssid_hex : "");
9290 if (res < 0 || res >= (int) sizeof(buf))
9291 return -1;
9292
9293 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009294 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
9295 "scan");
9296 return 0;
9297 }
9298
9299 return 1;
9300}
9301
9302
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009303static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
9304 struct sigma_cmd *cmd)
9305{
9306 const char *intf = get_param(cmd, "Interface");
9307 const char *bssid;
9308 char buf[4096], *pos;
9309 int freq, chan;
9310 char *ssid;
9311 char resp[100];
9312 int res;
9313 struct wpa_ctrl *ctrl;
9314
9315 bssid = get_param(cmd, "BSSID");
9316 if (!bssid) {
9317 send_resp(dut, conn, SIGMA_INVALID,
9318 "errorCode,BSSID argument is missing");
9319 return 0;
9320 }
9321
9322 ctrl = open_wpa_mon(intf);
9323 if (!ctrl) {
9324 sigma_dut_print(dut, DUT_MSG_ERROR,
9325 "Failed to open wpa_supplicant monitor connection");
9326 return -1;
9327 }
9328
9329 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
9330 send_resp(dut, conn, SIGMA_ERROR,
9331 "errorCode,Could not start scan");
9332 wpa_ctrl_detach(ctrl);
9333 wpa_ctrl_close(ctrl);
9334 return 0;
9335 }
9336
9337 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9338 buf, sizeof(buf));
9339
9340 wpa_ctrl_detach(ctrl);
9341 wpa_ctrl_close(ctrl);
9342
9343 if (res < 0) {
9344 send_resp(dut, conn, SIGMA_ERROR,
9345 "errorCode,Scan did not complete");
9346 return 0;
9347 }
9348
9349 snprintf(buf, sizeof(buf), "BSS %s", bssid);
9350 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
9351 strncmp(buf, "id=", 3) != 0) {
9352 send_resp(dut, conn, SIGMA_ERROR,
9353 "errorCode,Specified BSSID not found");
9354 return 0;
9355 }
9356
9357 pos = strstr(buf, "\nfreq=");
9358 if (!pos) {
9359 send_resp(dut, conn, SIGMA_ERROR,
9360 "errorCode,Channel not found");
9361 return 0;
9362 }
9363 freq = atoi(pos + 6);
9364 chan = freq_to_channel(freq);
9365
9366 pos = strstr(buf, "\nssid=");
9367 if (!pos) {
9368 send_resp(dut, conn, SIGMA_ERROR,
9369 "errorCode,SSID not found");
9370 return 0;
9371 }
9372 ssid = pos + 6;
9373 pos = strchr(ssid, '\n');
9374 if (pos)
9375 *pos = '\0';
9376 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
9377 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9378 return 0;
9379}
9380
9381
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009382static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
9383 struct sigma_cmd *cmd)
9384{
9385#ifdef __linux__
9386 struct timeval tv;
9387 struct tm tm;
9388 time_t t;
9389 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309390 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009391
9392 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
9393
9394 memset(&tm, 0, sizeof(tm));
9395 val = get_param(cmd, "seconds");
9396 if (val)
9397 tm.tm_sec = atoi(val);
9398 val = get_param(cmd, "minutes");
9399 if (val)
9400 tm.tm_min = atoi(val);
9401 val = get_param(cmd, "hours");
9402 if (val)
9403 tm.tm_hour = atoi(val);
9404 val = get_param(cmd, "date");
9405 if (val)
9406 tm.tm_mday = atoi(val);
9407 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05309408 if (val) {
9409 v = atoi(val);
9410 if (v < 1 || v > 12) {
9411 send_resp(dut, conn, SIGMA_INVALID,
9412 "errorCode,Invalid month");
9413 return 0;
9414 }
9415 tm.tm_mon = v - 1;
9416 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009417 val = get_param(cmd, "year");
9418 if (val) {
9419 int year = atoi(val);
9420#ifdef ANDROID
9421 if (year > 2035)
9422 year = 2035; /* years beyond 2035 not supported */
9423#endif /* ANDROID */
9424 tm.tm_year = year - 1900;
9425 }
9426 t = mktime(&tm);
9427 if (t == (time_t) -1) {
9428 send_resp(dut, conn, SIGMA_ERROR,
9429 "errorCode,Invalid date or time");
9430 return 0;
9431 }
9432
9433 memset(&tv, 0, sizeof(tv));
9434 tv.tv_sec = t;
9435
9436 if (settimeofday(&tv, NULL) < 0) {
9437 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
9438 strerror(errno));
9439 send_resp(dut, conn, SIGMA_ERROR,
9440 "errorCode,Failed to set time");
9441 return 0;
9442 }
9443
9444 return 1;
9445#endif /* __linux__ */
9446
9447 return -1;
9448}
9449
9450
9451static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
9452 struct sigma_cmd *cmd)
9453{
9454 const char *intf = get_param(cmd, "Interface");
9455 const char *name, *val;
9456 int prod_ess_assoc = 1;
9457 char buf[200], bssid[100], ssid[100];
9458 int res;
9459 struct wpa_ctrl *ctrl;
9460
9461 name = get_param(cmd, "osuFriendlyName");
9462
9463 val = get_param(cmd, "ProdESSAssoc");
9464 if (val)
9465 prod_ess_assoc = atoi(val);
9466
9467 kill_dhcp_client(dut, intf);
9468 if (start_dhcp_client(dut, intf) < 0)
9469 return -2;
9470
9471 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
9472 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9473 res = snprintf(buf, sizeof(buf),
9474 "%s %s%s%s signup osu-ca.pem",
9475 prod_ess_assoc ? "" : "-N",
9476 name ? "-O'" : "", name ? name : "",
9477 name ? "'" : "");
9478
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05309479 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009480 if (run_hs20_osu(dut, buf) < 0) {
9481 FILE *f;
9482
9483 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
9484
9485 f = fopen("hs20-osu-client.res", "r");
9486 if (f) {
9487 char resp[400], res[300], *pos;
9488 if (!fgets(res, sizeof(res), f))
9489 res[0] = '\0';
9490 pos = strchr(res, '\n');
9491 if (pos)
9492 *pos = '\0';
9493 fclose(f);
9494 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
9495 res);
9496 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
9497 if (system(resp) != 0) {
9498 }
9499 snprintf(resp, sizeof(resp),
9500 "SSID,,BSSID,,failureReason,%s", res);
9501 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9502 return 0;
9503 }
9504
9505 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9506 return 0;
9507 }
9508
9509 if (!prod_ess_assoc)
9510 goto report;
9511
9512 ctrl = open_wpa_mon(intf);
9513 if (ctrl == NULL) {
9514 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9515 "wpa_supplicant monitor connection");
9516 return -1;
9517 }
9518
9519 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
9520 buf, sizeof(buf));
9521
9522 wpa_ctrl_detach(ctrl);
9523 wpa_ctrl_close(ctrl);
9524
9525 if (res < 0) {
9526 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
9527 "network after OSU");
9528 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9529 return 0;
9530 }
9531
9532report:
9533 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
9534 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
9535 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
9536 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
9537 return 0;
9538 }
9539
9540 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
9541 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009542 return 0;
9543}
9544
9545
9546static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
9547 struct sigma_cmd *cmd)
9548{
9549 const char *val;
9550 int timeout = 120;
9551
9552 val = get_param(cmd, "PolicyUpdate");
9553 if (val == NULL || atoi(val) == 0)
9554 return 1; /* No operation requested */
9555
9556 val = get_param(cmd, "Timeout");
9557 if (val)
9558 timeout = atoi(val);
9559
9560 if (timeout) {
9561 /* TODO: time out the command and return
9562 * PolicyUpdateStatus,TIMEOUT if needed. */
9563 }
9564
9565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
9566 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
9567 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
9568 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
9569 return 0;
9570 }
9571
9572 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
9573 return 0;
9574}
9575
9576
9577static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
9578 struct sigma_cmd *cmd)
9579{
9580 struct wpa_ctrl *ctrl;
9581 const char *intf = get_param(cmd, "Interface");
9582 const char *bssid = get_param(cmd, "Bssid");
9583 const char *ssid = get_param(cmd, "SSID");
9584 const char *security = get_param(cmd, "Security");
9585 const char *passphrase = get_param(cmd, "Passphrase");
9586 const char *pin = get_param(cmd, "PIN");
9587 char buf[1000];
9588 char ssid_hex[200], passphrase_hex[200];
9589 const char *keymgmt, *cipher;
9590
9591 if (intf == NULL)
9592 intf = get_main_ifname();
9593
9594 if (!bssid) {
9595 send_resp(dut, conn, SIGMA_ERROR,
9596 "ErrorCode,Missing Bssid argument");
9597 return 0;
9598 }
9599
9600 if (!ssid) {
9601 send_resp(dut, conn, SIGMA_ERROR,
9602 "ErrorCode,Missing SSID argument");
9603 return 0;
9604 }
9605
9606 if (!security) {
9607 send_resp(dut, conn, SIGMA_ERROR,
9608 "ErrorCode,Missing Security argument");
9609 return 0;
9610 }
9611
9612 if (!passphrase) {
9613 send_resp(dut, conn, SIGMA_ERROR,
9614 "ErrorCode,Missing Passphrase argument");
9615 return 0;
9616 }
9617
9618 if (!pin) {
9619 send_resp(dut, conn, SIGMA_ERROR,
9620 "ErrorCode,Missing PIN argument");
9621 return 0;
9622 }
9623
vamsi krishna8c9c1562017-05-12 15:51:46 +05309624 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
9625 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009626 send_resp(dut, conn, SIGMA_ERROR,
9627 "ErrorCode,Too long SSID/passphrase");
9628 return 0;
9629 }
9630
9631 ctrl = open_wpa_mon(intf);
9632 if (ctrl == NULL) {
9633 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9634 "wpa_supplicant monitor connection");
9635 return -2;
9636 }
9637
9638 if (strcasecmp(security, "wpa2-psk") == 0) {
9639 keymgmt = "WPA2PSK";
9640 cipher = "CCMP";
9641 } else {
9642 wpa_ctrl_detach(ctrl);
9643 wpa_ctrl_close(ctrl);
9644 send_resp(dut, conn, SIGMA_ERROR,
9645 "ErrorCode,Unsupported Security value");
9646 return 0;
9647 }
9648
9649 ascii2hexstr(ssid, ssid_hex);
9650 ascii2hexstr(passphrase, passphrase_hex);
9651 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
9652 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
9653
9654 if (wpa_command(intf, buf) < 0) {
9655 wpa_ctrl_detach(ctrl);
9656 wpa_ctrl_close(ctrl);
9657 send_resp(dut, conn, SIGMA_ERROR,
9658 "ErrorCode,Failed to start registrar");
9659 return 0;
9660 }
9661
9662 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
9663 dut->er_oper_performed = 1;
9664
9665 return wps_connection_event(dut, conn, ctrl, intf, 0);
9666}
9667
9668
9669static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
9670 struct sigma_conn *conn,
9671 struct sigma_cmd *cmd)
9672{
9673 struct wpa_ctrl *ctrl;
9674 const char *intf = get_param(cmd, "Interface");
9675 const char *bssid = get_param(cmd, "Bssid");
9676 char buf[100];
9677
9678 if (!bssid) {
9679 send_resp(dut, conn, SIGMA_ERROR,
9680 "ErrorCode,Missing Bssid argument");
9681 return 0;
9682 }
9683
9684 ctrl = open_wpa_mon(intf);
9685 if (ctrl == NULL) {
9686 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9687 "wpa_supplicant monitor connection");
9688 return -2;
9689 }
9690
9691 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
9692
9693 if (wpa_command(intf, buf) < 0) {
9694 wpa_ctrl_detach(ctrl);
9695 wpa_ctrl_close(ctrl);
9696 send_resp(dut, conn, SIGMA_ERROR,
9697 "ErrorCode,Failed to start registrar");
9698 return 0;
9699 }
9700
9701 return wps_connection_event(dut, conn, ctrl, intf, 0);
9702}
9703
9704
vamsi krishna9b144002017-09-20 13:28:13 +05309705static int cmd_start_wps_registration(struct sigma_dut *dut,
9706 struct sigma_conn *conn,
9707 struct sigma_cmd *cmd)
9708{
9709 struct wpa_ctrl *ctrl;
9710 const char *intf = get_param(cmd, "Interface");
9711 const char *role, *method;
9712 int res;
9713 char buf[256];
9714 const char *events[] = {
9715 "CTRL-EVENT-CONNECTED",
9716 "WPS-OVERLAP-DETECTED",
9717 "WPS-TIMEOUT",
9718 "WPS-FAIL",
9719 NULL
9720 };
9721
9722 ctrl = open_wpa_mon(intf);
9723 if (!ctrl) {
9724 sigma_dut_print(dut, DUT_MSG_ERROR,
9725 "Failed to open wpa_supplicant monitor connection");
9726 return -2;
9727 }
9728
9729 role = get_param(cmd, "WpsRole");
9730 if (!role) {
9731 send_resp(dut, conn, SIGMA_INVALID,
9732 "ErrorCode,WpsRole not provided");
9733 goto fail;
9734 }
9735
9736 if (strcasecmp(role, "Enrollee") == 0) {
9737 method = get_param(cmd, "WpsConfigMethod");
9738 if (!method) {
9739 send_resp(dut, conn, SIGMA_INVALID,
9740 "ErrorCode,WpsConfigMethod not provided");
9741 goto fail;
9742 }
9743 if (strcasecmp(method, "PBC") == 0) {
9744 if (wpa_command(intf, "WPS_PBC") < 0) {
9745 send_resp(dut, conn, SIGMA_ERROR,
9746 "ErrorCode,Failed to enable PBC");
9747 goto fail;
9748 }
9749 } else {
9750 /* TODO: PIN method */
9751 send_resp(dut, conn, SIGMA_ERROR,
9752 "ErrorCode,Unsupported WpsConfigMethod value");
9753 goto fail;
9754 }
9755 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
9756 if (res < 0) {
9757 send_resp(dut, conn, SIGMA_ERROR,
9758 "ErrorCode,WPS connection did not complete");
9759 goto fail;
9760 }
9761 if (strstr(buf, "WPS-TIMEOUT")) {
9762 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
9763 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
9764 send_resp(dut, conn, SIGMA_ERROR,
9765 "ErrorCode,OverlapSession");
9766 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
9767 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
9768 } else {
9769 send_resp(dut, conn, SIGMA_ERROR,
9770 "ErrorCode,WPS operation failed");
9771 }
9772 } else {
9773 /* TODO: Registrar role */
9774 send_resp(dut, conn, SIGMA_ERROR,
9775 "ErrorCode,Unsupported WpsRole value");
9776 }
9777
9778fail:
9779 wpa_ctrl_detach(ctrl);
9780 wpa_ctrl_close(ctrl);
9781 return 0;
9782}
9783
9784
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009785static int req_intf(struct sigma_cmd *cmd)
9786{
9787 return get_param(cmd, "interface") == NULL ? -1 : 0;
9788}
9789
9790
9791void sta_register_cmds(void)
9792{
9793 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
9794 cmd_sta_get_ip_config);
9795 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
9796 cmd_sta_set_ip_config);
9797 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
9798 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
9799 cmd_sta_get_mac_address);
9800 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
9801 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
9802 cmd_sta_verify_ip_connection);
9803 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
9804 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
9805 cmd_sta_set_encryption);
9806 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
9807 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
9808 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
9809 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
9810 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
9811 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
9812 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
9813 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
9814 cmd_sta_set_eapakaprime);
9815 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
9816 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
9817 /* TODO: sta_set_ibss */
9818 /* TODO: sta_set_mode */
9819 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
9820 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
9821 /* TODO: sta_up_load */
9822 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
9823 cmd_sta_preset_testparameters);
9824 /* TODO: sta_set_system */
9825 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
9826 /* TODO: sta_set_rifs_test */
9827 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
9828 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
9829 /* TODO: sta_send_coexist_mgmt */
9830 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
9831 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
9832 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
9833 sigma_dut_reg_cmd("sta_reset_default", req_intf,
9834 cmd_sta_reset_default);
9835 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
9836 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
9837 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
9838 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
9839 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
9840 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
9841 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
9842 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
9843 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
9844 cmd_sta_hs2_associate);
9845 sigma_dut_reg_cmd("sta_add_credential", req_intf,
9846 cmd_sta_add_credential);
9847 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +02009848 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009849 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
9850 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
9851 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
9852 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
9853 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
9854 cmd_sta_wps_connect_pw_token);
9855 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
9856 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
9857 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +05309858 sigma_dut_reg_cmd("start_wps_registration", req_intf,
9859 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009860}