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