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