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