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