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