blob: ddc15d7bd56a3e7cfb66d8135155d4ae26ac2f99 [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/stat.h>
12#include <sys/wait.h>
13#include <sys/utsname.h>
14#include <sys/ioctl.h>
15#ifdef __linux__
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070016#include <limits.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020017#include <dirent.h>
18#include <string.h>
19#include <sys/types.h>
20#include <unistd.h>
21#endif /* __linux__ */
22#ifdef __QNXNTO__
23#include <ifaddrs.h>
24#include <net/if_dl.h>
25#endif /* __QNXNTO__ */
26#include "wpa_helpers.h"
27#ifdef ANDROID
28#include <hardware_legacy/wifi.h>
Veerendranath Jakkamd7e00082018-04-25 19:46:01 +053029#include <grp.h>
30#include <pwd.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020031#endif /* ANDROID */
32
33/* Temporary files for ap_send_addba_req */
34#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
35#define VI_QOS_FILE "/tmp/vi-qos.txt"
36#define VI_QOS_REFFILE "/etc/vi-qos.txt"
37
38/* Configuration file name on Android */
39#ifndef ANDROID_CONFIG_FILE
40#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
41#endif /* ANDROID_CONFIG_FILE */
42/* Maximum length of the line in the configuration file */
43#define MAX_CONF_LINE_LEN (156)
44
Jouni Malinend6bf1b42017-06-23 17:51:01 +030045#ifndef SIGMA_DUT_HOSTAPD_PID_FILE
46#define SIGMA_DUT_HOSTAPD_PID_FILE "/tmp/sigma_dut-ap-hostapd.pid"
47#endif /* SIGMA_DUT_HOSTAPD_PID_FILE */
48
Jouni Malinencd4e3c32015-10-29 12:39:56 +020049/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
50#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
51#define ANQP_VENUE_NAME_1_CHI "P\"\x63\x68\x69\x3a\x57\x69\x2d\x46\x69\xe8\x81\x94\xe7\x9b\x9f\xe5\xae\x9e\xe9\xaa\x8c\xe5\xae\xa4\\n\xe4\xba\x8c\xe4\xb9\x9d\xe5\x85\xab\xe4\xb9\x9d\xe5\xb9\xb4\xe5\xba\x93\xe6\x9f\x8f\xe8\xb7\xaf\\n\xe5\x9c\xa3\xe5\x85\x8b\xe6\x8b\x89\xe6\x8b\x89\x2c\x20\xe5\x8a\xa0\xe5\x88\xa9\xe7\xa6\x8f\xe5\xb0\xbc\xe4\xba\x9a\x39\x35\x30\x35\x31\x2c\x20\xe7\xbe\x8e\xe5\x9b\xbd\""
52#define ANQP_IP_ADDR_TYPE_1 "060101000c"
53#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
54#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
55#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
56#define QOS_MAP_SET_1 "53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255"
57#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
58
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030059#define ADV_OF_CHARGE_1 \
Jouni Malinen3001b432018-05-03 18:18:15 +030060"bc01000000d200454e475553443c3f786d6c2076657273696f6e3d22312e30222065" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030061"6e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f77" \
62"77772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f" \
63"74302f76312e302f616f637069223e3c4465736372697074696f6e3e57692d46692061636365" \
64"737320666f72203120686f75722c207768696c6520796f752077616974206174207468652067" \
Jouni Malinen3001b432018-05-03 18:18:15 +030065"6174652c2024302e39393c2f4465736372697074696f6e3e3c2f506c616e3ee3004652414341" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030066"443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f" \
67"3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f72672f737065" \
68"63696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f637069223e3c" \
Jouni Malinen3001b432018-05-03 18:18:15 +030069"4465736372697074696f6e3e416363c3a8732057692d46692070656e64616e74203120686575" \
70"72652c2070656e64616e742071756520766f757320617474656e64657a20c3a0206c6120706f" \
71"7274652c20302c393920243c2f4465736372697074696f6e3e3c2f506c616e3ea101010000c7" \
72"00454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d2255" \
73"54462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f" \
74"72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f" \
75"637069223e3c4465736372697074696f6e3e446f776e6c6f616420766964656f7320666f7220" \
76"796f757220666c696768742c2024322e393920666f7220313047423c2f446573637269707469" \
77"6f6e3e3c2f506c616e3ed3004652414341443c3f786d6c2076657273696f6e3d22312e302220" \
78"656e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f" \
79"7777772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f743264" \
80"6f74302f76312e302f616f637069223e3c4465736372697074696f6e3e54c3a96cc3a9636861" \
81"7267657a2064657320766964c3a96f7320706f757220766f74726520766f6c2c20322c393920" \
82"2420706f757220313020476f3c2f4465736372697074696f6e3e3c2f506c616e3ee40003002b" \
83"736572766963652d70726f76696465722e636f6d3b66656465726174696f6e2e6578616d706c" \
84"652e636f6db400454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64" \
85"696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77" \
86"692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76" \
87"312e302f616f637069223e3c4465736372697074696f6e3e46726565207769746820796f7572" \
88"20737562736372697074696f6e213c2f4465736372697074696f6e3e3c2f506c616e3e"
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030089
Jouni Malinencd4e3c32015-10-29 12:39:56 +020090extern char *sigma_main_ifname;
91extern char *sigma_wpas_ctrl;
92extern char *sigma_hapd_ctrl;
93extern char *ap_inet_addr;
94extern char *ap_inet_mask;
95extern char *sigma_radio_ifname[];
96
Jouni Malinencd4e3c32015-10-29 12:39:56 +020097static int ath_ap_start_hostapd(struct sigma_dut *dut);
98static void ath_ap_set_params(struct sigma_dut *dut);
99static int kill_process(struct sigma_dut *dut, char *proc_name,
100 unsigned char is_proc_instance_one, int sig);
101
102
Jouni Malinen6be21c82018-08-01 18:47:24 +0300103static int ap_ft_enabled(struct sigma_dut *dut)
104{
105 return dut->ap_ft_oa == 1 ||
106 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
107 dut->ap_key_mgmt == AP_WPA2_FT_PSK ||
108 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP;
109}
110
111
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200112static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
113 struct sigma_cmd *cmd)
114{
115 /* const char *name = get_param(cmd, "NAME"); */
116 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
117 return 0;
118}
119
120
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300121static void kill_hostapd_process_pid(struct sigma_dut *dut)
122{
123 FILE *f;
124 int pid, res;
125 char path[100];
126 int count;
127
128 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
129 if (!f)
130 return;
131 res = fscanf(f, "%d", &pid);
132 fclose(f);
133 if (res != 1)
134 return;
135 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
136 kill(pid, SIGTERM);
137 snprintf(path, sizeof(path), "/proc/%d", pid);
138 for (count = 0; count < 20 && file_exists(path); count++)
139 usleep(100000);
140}
141
142
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300143int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200144{
145#ifndef __QNXNTO__
146 struct ifreq ifr;
147 int s;
148
149 s = socket(AF_INET, SOCK_DGRAM, 0);
150 if (s < 0)
151 return -1;
152 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700153 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200154 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
155 perror("ioctl");
156 close(s);
157 return -1;
158 }
159 close(s);
160 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
161#else /* __QNXNTO__ */
162 struct ifaddrs *ifaddrshead = NULL;
163 int found = 0;
164 struct ifaddrs *temp_ifap = NULL;
165 struct sockaddr_dl *sdl = NULL;
166
167 if (getifaddrs(&ifaddrshead) != 0) {
168 perror("getifaddrs failed");
169 return -1;
170 }
171
172 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
173 ifaddrshead = ifaddrshead->ifa_next) {
174 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
175 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
176 found = 1;
177 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
178 if (sdl)
179 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
180 }
181 }
182
183 if (temp_ifap)
184 freeifaddrs(temp_ifap);
185
186 if (!found) {
187 perror("Failed to get the interface");
188 return -1;
189 }
190#endif /* __QNXNTO__ */
191 return 0;
192}
193
194
195static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
196 const char *val)
197{
198 char buf[60];
199
200 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
201 ifname, atoi(val));
202 if (system(buf) != 0) {
203 sigma_dut_print(dut, DUT_MSG_ERROR,
204 "wifitool ap_group_id failed");
205 }
206}
207
208
209void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
210 const char *val)
211{
212 char buf[60];
213
214 /* TODO: Enable support for other values */
215 if (strcasecmp(val, "40") == 0) {
216 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
217 ifname);
218 if (system(buf) != 0) {
219 sigma_dut_print(dut, DUT_MSG_ERROR,
220 "wifitool cts_width failed");
221 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800222 snprintf(buf, sizeof(buf),
223 "athdiag --set --address=0x10024 --val=0xd90b8a14");
224 if (system(buf) != 0) {
225 sigma_dut_print(dut, DUT_MSG_ERROR,
226 "disabling phy restart failed");
227 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200228 } else {
229 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
230 }
231}
232
233
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800234void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
235 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200236{
237 char buf[60];
238
239 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200240 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200241 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
242 if (system(buf) != 0) {
243 sigma_dut_print(dut, DUT_MSG_ERROR,
244 "iwpriv cwmenable 1 failed");
245 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800246 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
247 ifname);
248 if (system(buf) != 0) {
249 sigma_dut_print(dut, DUT_MSG_ERROR,
250 "disabling RTS from rate control logic failed");
251 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200252 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200253 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200254 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
255 if (system(buf) != 0) {
256 sigma_dut_print(dut, DUT_MSG_ERROR,
257 "iwpriv cwmenable 0 failed");
258 }
259 } else {
260 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
261 }
262}
263
264
265static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
266 const char *val)
267{
268 char buf[60];
269
270 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200271 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200272 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
273 if (system(buf) != 0) {
274 sigma_dut_print(dut, DUT_MSG_ERROR,
275 "iwconfig rts 64 failed");
276 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800277 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
278 ifname);
279 if (system(buf) != 0) {
280 sigma_dut_print(dut, DUT_MSG_ERROR,
281 "wifitool beeliner_fw_test 100 1 failed");
282 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200283 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200284 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200285 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
286 if (system(buf) != 0) {
287 sigma_dut_print(dut, DUT_MSG_ERROR,
288 "iwpriv rts 2347 failed");
289 }
290 } else {
291 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
292 }
293}
294
295
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800296static void ath_radio(struct sigma_dut *dut, const char *val)
297{
298 if (strcasecmp(val, "on") == 0) {
299 if (dut->ap_interface_5g == 1) {
300 run_system(dut, "uci set wireless.wifi0.disabled=0");
301 } else if (dut->ap_interface_2g == 1) {
302 run_system(dut, "uci set wireless.wifi1.disabled=0");
303 } else {
304 run_system(dut, "uci set wireless.wifi0.disabled=0");
305 run_system(dut, "uci set wireless.wifi1.disabled=0");
306 }
307 run_system(dut, "uci commit");
308 run_system(dut, "wifi down");
309 run_system(dut, "wifi up");
310 } else if (strcasecmp(val, "off") == 0) {
311 if (dut->ap_interface_5g == 1) {
312 run_system(dut, "uci set wireless.wifi0.disabled=1");
313 } else if (dut->ap_interface_2g == 1) {
314 run_system(dut, "uci set wireless.wifi1.disabled=1");
315 } else {
316 run_system(dut, "uci set wireless.wifi0.disabled=1");
317 run_system(dut, "uci set wireless.wifi1.disabled=1");
318 }
319 run_system(dut, "uci commit");
320 run_system(dut, "wifi down");
321 run_system(dut, "wifi up");
322 }
323}
324
325
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800326static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
327 const char *val)
328{
329 char buf[60];
330
331 if (strcasecmp(val, "disable") == 0) {
332 snprintf(buf, sizeof(buf), "iwpriv %s stealthdown 1", ifname);
333 if (system(buf) != 0) {
334 sigma_dut_print(dut, DUT_MSG_ERROR,
335 "disable deauthdisassoctx failed");
336 }
337 }
338}
339
340
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800341static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
342 const char *val)
343{
344 char buf[60];
345
346 if (strcasecmp(val, "high") == 0)
347 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
348 else if (strcasecmp(val, "low") == 0)
349 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
350 else
351 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
352
353 if (system(buf) != 0)
354 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
355}
356
357
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200358static enum ap_mode get_mode(const char *str)
359{
360 if (strcasecmp(str, "11a") == 0)
361 return AP_11a;
362 else if (strcasecmp(str, "11g") == 0)
363 return AP_11g;
364 else if (strcasecmp(str, "11b") == 0)
365 return AP_11b;
366 else if (strcasecmp(str, "11na") == 0)
367 return AP_11na;
368 else if (strcasecmp(str, "11ng") == 0)
369 return AP_11ng;
370 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
371 return AP_11ac;
372 else
373 return AP_inval;
374}
375
376
377static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
378{
379 char command[1000];
380 const char *bin;
381 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700382 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200383
384 if (file_exists("hostapd_cli"))
385 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300386 else if (file_exists("../../hostapd/hostapd_cli"))
387 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200388 else
389 bin = "hostapd_cli";
390
391 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700392 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200393
394 if (sigma_radio_ifname[0] &&
395 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700396 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200397 else if (sigma_radio_ifname[0] &&
398 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700399 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200400 }
401
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700402 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200403 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700404 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405 else
406 snprintf(command, sizeof(command), "%s %s", bin, buf);
407 return run_system(dut, command);
408}
409
410
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700411static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
412 struct sigma_cmd *cmd)
413{
414 FILE *f;
415 int i;
416
417 f = fopen("/tmp/lci_cfg.txt", "w");
418 if (!f) {
419 sigma_dut_print(dut, DUT_MSG_ERROR,
420 "Failed to open /tmp/lci_cfg.txt");
421 return -1;
422 }
423
424 for (i = 2; i < cmd->count; i++)
425 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
426 fprintf(f, "\n");
427 fclose(f);
428
429 return 0;
430}
431
432
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200433static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
434 struct sigma_cmd *cmd)
435{
436 /* const char *name = get_param(cmd, "NAME"); */
437 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200438 const char *val;
439 unsigned int wlan_tag = 1;
440 char *ifname = get_main_ifname();
441
442 val = get_param(cmd, "WLAN_TAG");
443 if (val) {
444 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700445 if (wlan_tag < 1 || wlan_tag > 3) {
446 /*
447 * The only valid WLAN Tags as of now as per the latest
448 * WFA scripts are 1, 2, and 3.
449 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200450 send_resp(dut, conn, SIGMA_INVALID,
451 "errorCode,Invalid WLAN_TAG");
452 return 0;
453 }
454 }
455
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800456 val = get_param(cmd, "Interface");
457 if (val) {
458 if (strcasecmp(val, "5G") == 0)
459 dut->ap_interface_5g = 1;
460 else
461 dut->ap_interface_2g = 1;
462
463 if (dut->ap_interface_5g && dut->ap_interface_2g)
464 dut->ap_is_dual = 1;
465 }
466
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200467 val = get_param(cmd, "CountryCode");
468 if (val) {
469 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
470 return -1;
471 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
472 "%s", val);
473 }
474
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530475 val = get_param(cmd, "regulatory_mode");
476 if (val) {
477 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
478 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
479 }
480
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200481 val = get_param(cmd, "SSID");
482 if (val) {
483 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
484 return -1;
485
486 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700487 /*
488 * If tag is not specified, it is deemed to be 1.
489 * Hence tag of 1 is a special case and the values
490 * corresponding to wlan-tag=1 are stored separately
491 * from the values corresponding tags 2 and 3.
492 * This approach minimises the changes to existing code
493 * since most of the sigma_dut code does not deal with
494 * WLAN-TAG CAPI variable.
495 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200496 snprintf(dut->ap_ssid,
497 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700498 } else {
499 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
500 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
501 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200502 }
503 }
504
505 val = get_param(cmd, "CHANNEL");
506 if (val) {
507 const char *pos;
508 dut->ap_channel = atoi(val);
509 pos = strchr(val, ';');
510 if (pos) {
511 pos++;
512 dut->ap_channel_1 = atoi(pos);
513 }
514 }
515
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530516 /* Overwrite the AP channel with DFS channel if configured */
517 val = get_param(cmd, "dfs_chan");
518 if (val) {
519 dut->ap_channel = atoi(val);
520 }
521
522 val = get_param(cmd, "dfs_mode");
523 if (val) {
524 if (strcasecmp(val, "Enable") == 0)
525 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
526 else if (strcasecmp(val, "Disable") == 0)
527 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
528 else
529 sigma_dut_print(dut, DUT_MSG_ERROR,
530 "Unsupported dfs_mode value: %s", val);
531 }
532
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200533 val = get_param(cmd, "MODE");
534 if (val) {
535 char *str, *pos;
536
537 str = strdup(val);
538 if (str == NULL)
539 return -1;
540 pos = strchr(str, ';');
541 if (pos)
542 *pos++ = '\0';
543
544 dut->ap_is_dual = 0;
545 dut->ap_mode = get_mode(str);
546 if (dut->ap_mode == AP_inval) {
547 send_resp(dut, conn, SIGMA_INVALID,
548 "errorCode,Unsupported MODE");
549 free(str);
550 return 0;
551 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800552 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200553 dut->ap_chwidth = AP_80;
554
555 if (pos) {
556 dut->ap_mode_1 = get_mode(pos);
557 if (dut->ap_mode_1 == AP_inval) {
558 send_resp(dut, conn, SIGMA_INVALID,
559 "errorCode,Unsupported MODE");
560 free(str);
561 return 0;
562 }
563 if (dut->ap_mode_1 == AP_11ac)
564 dut->ap_chwidth_1 = AP_80;
565 dut->ap_is_dual = 1;
566 }
567
568 free(str);
569 } else if (dut->ap_mode == AP_inval) {
570 if (dut->ap_channel <= 11)
571 dut->ap_mode = AP_11ng;
572 else if (dut->program == PROGRAM_VHT)
573 dut->ap_mode = AP_11ac;
574 else
575 dut->ap_mode = AP_11na;
576 }
577
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530578 val = get_param(cmd, "WME");
579 if (val) {
580 if (strcasecmp(val, "on") == 0)
581 dut->ap_wme = AP_WME_ON;
582 else if (strcasecmp(val, "off") == 0)
583 dut->ap_wme = AP_WME_OFF;
584 else
585 sigma_dut_print(dut, DUT_MSG_ERROR,
586 "Unsupported WME value: %s", val);
587 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200588
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530589 val = get_param(cmd, "WMMPS");
590 if (val) {
591 if (strcasecmp(val, "on") == 0)
592 dut->ap_wmmps = AP_WMMPS_ON;
593 else if (strcasecmp(val, "off") == 0)
594 dut->ap_wmmps = AP_WMMPS_OFF;
595 else
596 sigma_dut_print(dut, DUT_MSG_ERROR,
597 "Unsupported WMMPS value: %s", val);
598 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200599
600 val = get_param(cmd, "RTS");
601 if (val)
602 dut->ap_rts = atoi(val);
603
604 val = get_param(cmd, "FRGMNT");
605 if (val)
606 dut->ap_frgmnt = atoi(val);
607
608 /* TODO: PWRSAVE */
609
610 val = get_param(cmd, "BCNINT");
611 if (val)
612 dut->ap_bcnint = atoi(val);
613
614 val = get_param(cmd, "RADIO");
615 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530616 enum driver_type drv = get_driver_type();
617
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200618 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800619 if (drv == DRIVER_OPENWRT)
620 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200621 if (drv == DRIVER_ATHEROS)
622 ath_ap_start_hostapd(dut);
623 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
624 return 0;
625 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530626 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800627 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300628 } else if (dut->use_hostapd_pid_file) {
629 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530630 } else if (kill_process(dut, "(hostapd)", 1,
631 SIGTERM) == 0 ||
632 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200633 sigma_dut_print(dut, DUT_MSG_INFO,
634 "Killed hostapd on radio,off");
635 }
636 } else {
637 send_resp(dut, conn, SIGMA_INVALID,
638 "errorCode,Unsupported RADIO value");
639 return 0;
640 }
641 }
642
643 val = get_param(cmd, "P2PMgmtBit");
644 if (val)
645 dut->ap_p2p_mgmt = atoi(val);
646
647 /* TODO: ChannelUsage */
648
649 /* TODO: 40_INTOLERANT */
650
651 val = get_param(cmd, "ADDBA_REJECT");
652 if (val) {
653 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200654 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200655 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200656 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200657 }
658
659 val = get_param(cmd, "AMPDU");
660 if (val) {
661 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200662 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200663 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200664 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200665 }
666
667 val = get_param(cmd, "AMPDU_EXP");
668 if (val)
669 dut->ap_ampdu_exp = atoi(val);
670
671 val = get_param(cmd, "AMSDU");
672 if (val) {
673 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200674 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200675 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200676 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200677 }
678
679 val = get_param(cmd, "NoAck");
680 if (val) {
681 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200682 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200683 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200684 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200685 }
686
687 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200688 /* TODO: MCS_32 */
689
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530690 val = get_param(cmd, "OFFSET");
691 if (val) {
692 if (strcasecmp(val, "Above") == 0)
693 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
694 else if (strcasecmp(val, "Below") == 0)
695 dut->ap_chwidth_offset = SEC_CH_40BELOW;
696 }
697
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200698 val = get_param(cmd, "MCS_FIXEDRATE");
699 if (val) {
700 dut->ap_fixed_rate = 1;
701 dut->ap_mcs = atoi(val);
702 }
703
704 val = get_param(cmd, "SPATIAL_RX_STREAM");
705 if (val) {
706 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
707 dut->ap_rx_streams = 1;
708 if (dut->device_type == AP_testbed)
709 dut->ap_vhtmcs_map = 0xfffc;
710 } else if (strcasecmp(val, "2SS") == 0 ||
711 strcasecmp(val, "2") == 0) {
712 dut->ap_rx_streams = 2;
713 if (dut->device_type == AP_testbed)
714 dut->ap_vhtmcs_map = 0xfff0;
715 } else if (strcasecmp(val, "3SS") == 0 ||
716 strcasecmp(val, "3") == 0) {
717 dut->ap_rx_streams = 3;
718 if (dut->device_type == AP_testbed)
719 dut->ap_vhtmcs_map = 0xffc0;
720 } else if (strcasecmp(val, "4SS") == 0 ||
721 strcasecmp(val, "4") == 0) {
722 dut->ap_rx_streams = 4;
723 }
724 }
725
726 val = get_param(cmd, "SPATIAL_TX_STREAM");
727 if (val) {
728 if (strcasecmp(val, "1SS") == 0 ||
729 strcasecmp(val, "1") == 0) {
730 dut->ap_tx_streams = 1;
731 if (dut->device_type == AP_testbed)
732 dut->ap_vhtmcs_map = 0xfffc;
733 } else if (strcasecmp(val, "2SS") == 0 ||
734 strcasecmp(val, "2") == 0) {
735 dut->ap_tx_streams = 2;
736 if (dut->device_type == AP_testbed)
737 dut->ap_vhtmcs_map = 0xfff0;
738 } else if (strcasecmp(val, "3SS") == 0 ||
739 strcasecmp(val, "3") == 0) {
740 dut->ap_tx_streams = 3;
741 if (dut->device_type == AP_testbed)
742 dut->ap_vhtmcs_map = 0xffc0;
743 } else if (strcasecmp(val, "4SS") == 0 ||
744 strcasecmp(val, "4") == 0) {
745 dut->ap_tx_streams = 4;
746 }
747 }
748
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700749 val = get_param(cmd, "BSS_max_idle");
750 if (val) {
751 if (strncasecmp(val, "Enable", 7) == 0) {
752 dut->wnm_bss_max_feature = VALUE_ENABLED;
753 } else if (strncasecmp(val, "Disable", 8) == 0) {
754 dut->wnm_bss_max_feature = VALUE_DISABLED;
755 } else {
756 send_resp(dut, conn, SIGMA_ERROR,
757 "errorCode,Invalid value for BSS_max_Feature");
758 return 0;
759 }
760 }
761
762 val = get_param(cmd, "BSS_Idle_Protection_options");
763 if (val) {
764 int protection = (int) strtol(val, (char **) NULL, 10);
765
766 if (protection != 1 && protection != 0) {
767 send_resp(dut, conn, SIGMA_ERROR,
768 "errorCode,Invalid value for BSS_Idle_Protection_options");
769 return 0;
770 }
771 dut->wnm_bss_max_protection = protection ?
772 VALUE_ENABLED : VALUE_DISABLED;
773 }
774
775 val = get_param(cmd, "BSS_max_Idle_period");
776 if (val) {
777 int idle_time = (int) strtol(val, (char **) NULL, 10);
778
779 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
780 send_resp(dut, conn, SIGMA_ERROR,
781 "errorCode,Invalid value for BSS_max_Idle_period");
782 return 0;
783 }
784 dut->wnm_bss_max_idle_time = idle_time;
785 }
786
787 val = get_param(cmd, "PROXY_ARP");
788 if (val)
789 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
790
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200791 val = get_param(cmd, "nss_mcs_cap");
792 if (val) {
793 int nss, mcs;
794 char token[20];
795 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530796 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200797
798 if (strlen(val) >= sizeof(token))
799 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300800 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530801 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530802 if (!result) {
803 sigma_dut_print(dut, DUT_MSG_ERROR,
804 "VHT NSS not specified");
805 return 0;
806 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200807 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530808 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200809 if (result == NULL) {
810 sigma_dut_print(dut, DUT_MSG_ERROR,
811 "VHTMCS NOT SPECIFIED!");
812 return 0;
813 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530814 result = strtok_r(result, "-", &saveptr);
815 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530816 if (!result) {
817 sigma_dut_print(dut, DUT_MSG_ERROR,
818 "VHT MCS not specified");
819 return 0;
820 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200821 mcs = atoi(result);
822 switch (nss) {
823 case 1:
824 switch (mcs) {
825 case 7:
826 dut->ap_vhtmcs_map = 0xfffc;
827 break;
828 case 8:
829 dut->ap_vhtmcs_map = 0xfffd;
830 break;
831 case 9:
832 dut->ap_vhtmcs_map = 0xfffe;
833 break;
834 default:
835 dut->ap_vhtmcs_map = 0xfffe;
836 break;
837 }
838 break;
839 case 2:
840 switch (mcs) {
841 case 7:
842 dut->ap_vhtmcs_map = 0xfff0;
843 break;
844 case 8:
845 dut->ap_vhtmcs_map = 0xfff5;
846 break;
847 case 9:
848 dut->ap_vhtmcs_map = 0xfffa;
849 break;
850 default:
851 dut->ap_vhtmcs_map = 0xfffa;
852 break;
853 }
854 break;
855 case 3:
856 switch (mcs) {
857 case 7:
858 dut->ap_vhtmcs_map = 0xffc0;
859 break;
860 case 8:
861 dut->ap_vhtmcs_map = 0xffd5;
862 break;
863 case 9:
864 dut->ap_vhtmcs_map = 0xffea;
865 break;
866 default:
867 dut->ap_vhtmcs_map = 0xffea;
868 break;
869 }
870 break;
871 default:
872 dut->ap_vhtmcs_map = 0xffea;
873 break;
874 }
875 }
876
877 /* TODO: MPDU_MIN_START_SPACING */
878 /* TODO: RIFS_TEST */
879 /* TODO: SGI20 */
880
881 val = get_param(cmd, "STBC_TX");
882 if (val)
883 dut->ap_tx_stbc = atoi(val);
884
885 val = get_param(cmd, "WIDTH");
886 if (val) {
887 if (strcasecmp(val, "20") == 0)
888 dut->ap_chwidth = AP_20;
889 else if (strcasecmp(val, "40") == 0)
890 dut->ap_chwidth = AP_40;
891 else if (strcasecmp(val, "80") == 0)
892 dut->ap_chwidth = AP_80;
893 else if (strcasecmp(val, "160") == 0)
894 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800895 else if (strcasecmp(val, "80plus80") == 0) {
896 dut->ap_80plus80 = 1;
897 dut->ap_chwidth = AP_80_80;
898 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200899 dut->ap_chwidth = AP_AUTO;
900 else {
901 send_resp(dut, conn, SIGMA_INVALID,
902 "errorCode,Unsupported WIDTH");
903 return 0;
904 }
905 }
906
907 /* TODO: WIDTH_SCAN */
908
909 val = get_param(cmd, "TDLSProhibit");
910 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
911 val = get_param(cmd, "TDLSChswitchProhibit");
912 dut->ap_tdls_prohibit_chswitch =
913 val && strcasecmp(val, "Enabled") == 0;
914 val = get_param(cmd, "HS2");
915 if (val && wlan_tag == 1)
916 dut->ap_hs2 = atoi(val);
917 val = get_param(cmd, "P2P_CROSS_CONNECT");
918 if (val)
919 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
920
921 val = get_param(cmd, "FakePubKey");
922 dut->ap_fake_pkhash = val && atoi(val);
923
924 val = get_param(cmd, "vht_tkip");
925 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
926 val = get_param(cmd, "vht_wep");
927 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
928
929 val = get_param(cmd, "Protect_mode");
930 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
931
932 val = get_param(cmd, "DYN_BW_SGNL");
933 if (val) {
934 switch (get_driver_type()) {
935 case DRIVER_OPENWRT:
936 switch (get_openwrt_driver_type()) {
937 case OPENWRT_DRIVER_ATHEROS:
938 ath_config_dyn_bw_sig(dut, ifname, val);
939 break;
940 default:
941 send_resp(dut, conn, SIGMA_ERROR,
942 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
943 return 0;
944 }
945 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +0530946 case DRIVER_WCN:
947 case DRIVER_LINUX_WCN:
948 ath_config_dyn_bw_sig(dut, ifname, val);
949 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200950 default:
951 sigma_dut_print(dut, DUT_MSG_ERROR,
952 "Unsupported DYN_BW_SGL with the current driver");
953 break;
954 }
955 }
956
957 val = get_param(cmd, "SGI80");
958 if (val) {
959 if (strcasecmp(val, "enable") == 0)
960 dut->ap_sgi80 = 1;
961 else if (strcasecmp(val, "disable") == 0)
962 dut->ap_sgi80 = 0;
963 else {
964 send_resp(dut, conn, SIGMA_INVALID,
965 "errorCode,Unsupported SGI80");
966 return 0;
967 }
968 }
969
970 val = get_param(cmd, "LDPC");
971 if (val) {
972 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200973 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200974 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200975 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200976 else {
977 send_resp(dut, conn, SIGMA_INVALID,
978 "errorCode,Unsupported LDPC");
979 return 0;
980 }
981 }
982
983 val = get_param(cmd, "BW_SGNL");
984 if (val) {
985 /*
986 * With dynamic bandwidth signaling enabled we should see
987 * RTS if the threshold is met.
988 */
989 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200990 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200991 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200992 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200993 } else {
994 send_resp(dut, conn, SIGMA_INVALID,
995 "errorCode,Unsupported BW_SGNL");
996 return 0;
997 }
998 }
999
1000 val = get_param(cmd, "RTS_FORCE");
1001 if (val) {
1002 switch (get_driver_type()) {
1003 case DRIVER_OPENWRT:
1004 switch (get_openwrt_driver_type()) {
1005 case OPENWRT_DRIVER_ATHEROS:
1006 ath_config_rts_force(dut, ifname, val);
1007 break;
1008 default:
1009 send_resp(dut, conn, SIGMA_ERROR,
1010 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
1011 return 0;
1012 }
1013 break;
1014 default:
1015 sigma_dut_print(dut, DUT_MSG_ERROR,
1016 "Unsupported RTS_FORCE with the current driver");
1017 break;
1018 }
1019 }
1020
1021 val = get_param(cmd, "Zero_crc");
1022 if (val) {
1023 switch (get_driver_type()) {
1024 case DRIVER_ATHEROS:
1025 ath_set_zero_crc(dut, val);
1026 break;
1027 case DRIVER_OPENWRT:
1028 switch (get_openwrt_driver_type()) {
1029 case OPENWRT_DRIVER_ATHEROS:
1030 ath_set_zero_crc(dut, val);
1031 break;
1032 default:
1033 send_resp(dut, conn, SIGMA_ERROR,
1034 "errorCode,Unsupported zero_crc with the current driver");
1035 return 0;
1036 }
1037 break;
1038 default:
1039 send_resp(dut, conn, SIGMA_ERROR,
1040 "errorCode,Unsupported zero_crc with the current driver");
1041 return 0;
1042 }
1043 }
1044
1045 val = get_param(cmd, "TxBF");
1046 if (val)
1047 dut->ap_txBF = strcasecmp(val, "enable") == 0;
1048
1049 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301050 if (val) {
1051 if (strcasecmp(val, "enable") == 0) {
1052 dut->ap_txBF = 1;
1053 dut->ap_mu_txBF = 1;
1054 } else if (strcasecmp(val, "disable") == 0) {
1055 dut->ap_txBF = 0;
1056 dut->ap_mu_txBF = 0;
1057 } else {
1058 sigma_dut_print(dut, DUT_MSG_ERROR,
1059 "Unsupported MU_TxBF");
1060 }
1061 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001062
1063 /* UNSUPPORTED: tx_lgi_rate */
1064
1065 val = get_param(cmd, "wpsnfc");
1066 if (val)
1067 dut->ap_wpsnfc = atoi(val);
1068
1069 val = get_param(cmd, "GROUP_ID");
1070 if (val) {
1071 switch (get_driver_type()) {
1072 case DRIVER_OPENWRT:
1073 switch (get_openwrt_driver_type()) {
1074 case OPENWRT_DRIVER_ATHEROS:
1075 ath_ap_set_group_id(dut, ifname, val);
1076 break;
1077 default:
1078 send_resp(dut, conn, SIGMA_ERROR,
1079 "errorCode,Unsupported group_id with the current driver");
1080 return 0;
1081 }
1082 break;
1083 default:
1084 send_resp(dut, conn, SIGMA_ERROR,
1085 "errorCode,Unsupported group_id with the current driver");
1086 return 0;
1087 }
1088 }
1089
1090 val = get_param(cmd, "CTS_WIDTH");
1091 if (val) {
1092 switch (get_driver_type()) {
1093 case DRIVER_OPENWRT:
1094 switch (get_openwrt_driver_type()) {
1095 case OPENWRT_DRIVER_ATHEROS:
1096 ath_set_cts_width(dut, ifname, val);
1097 break;
1098 default:
1099 send_resp(dut, conn, SIGMA_ERROR,
1100 "errorCode,Unsupported cts_width with the current driver");
1101 return 0;
1102 }
1103 break;
1104 default:
1105 send_resp(dut, conn, SIGMA_ERROR,
1106 "errorCode,Unsupported cts_width with the current driver");
1107 return 0;
1108 }
1109 }
1110
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001111 val = get_param(cmd, "MU_NDPA_FrameFormat");
1112 if (val)
1113 dut->ap_ndpa_frame = atoi(val);
1114
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001115 val = get_param(cmd, "interworking");
1116 if (val && strcmp(val, "1") == 0)
1117 dut->ap_interworking = 1;
1118
1119 val = get_param(cmd, "GAS_CB_DELAY");
1120 if (val)
1121 dut->ap_gas_cb_delay = atoi(val);
1122
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001123 val = get_param(cmd, "LCI");
1124 if (val) {
1125 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1126 return -1;
1127 dut->ap_lci = 1;
1128 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1129 ath_set_lci_config(dut, val, cmd);
1130 }
1131
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001132 val = get_param(cmd, "InfoZ");
1133 if (val) {
1134 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1135 return -1;
1136 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1137 }
1138
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001139 val = get_param(cmd, "LocCivicAddr");
1140 if (val) {
1141 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1142 return -1;
1143 dut->ap_lcr = 1;
1144 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1145 if (dut->ap_lci == 0)
1146 ath_set_lci_config(dut, val, cmd);
1147 }
1148
1149 val = get_param(cmd, "NeighAPBSSID");
1150 if (val) {
1151 if (dut->ap_neighap < 3) {
1152 if (parse_mac_address(
1153 dut, val,
1154 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1155 send_resp(dut, conn, SIGMA_INVALID,
1156 "Failed to parse MAC address");
1157 return 0;
1158 }
1159 dut->ap_neighap++;
1160 if (dut->ap_lci == 1)
1161 dut->ap_scan = 1;
1162 }
1163 }
1164
1165 val = get_param(cmd, "OpChannel");
1166 if (val) {
1167 if (dut->ap_opchannel < 3) {
1168 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1169 dut->ap_opchannel++;
1170 }
1171 }
1172
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001173 val = get_param(cmd, "URI-FQDNdescriptor");
1174 if (val) {
1175 if (strcasecmp(val, "HELD") == 0) {
1176 dut->ap_fqdn_held = 1;
1177 } else if (strcasecmp(val, "SUPL") == 0) {
1178 dut->ap_fqdn_supl = 1;
1179 } else {
1180 send_resp(dut, conn, SIGMA_INVALID,
1181 "errorCode,Unsupported URI-FQDNdescriptor");
1182 return 0;
1183 }
1184 }
1185
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001186 val = get_param(cmd, "Reg_Domain");
1187 if (val) {
1188 if (strcasecmp(val, "Local") == 0) {
1189 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1190 } else if (strcasecmp(val, "Global") == 0) {
1191 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1192 } else {
1193 send_resp(dut, conn, SIGMA_ERROR,
1194 "errorCode,Wrong value for Reg_Domain");
1195 return 0;
1196 }
1197 }
1198
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001199 val = get_param(cmd, "NAME");
1200 if (val) {
1201 if (strcasecmp(val, "ap1mbo") == 0)
1202 dut->ap_name = 1;
1203 else if (strcasecmp(val, "ap2mbo") == 0)
1204 dut->ap_name = 2;
1205 else
1206 dut->ap_name = 0;
1207 }
1208
1209 val = get_param(cmd, "FT_OA");
1210 if (val) {
1211 if (strcasecmp(val, "Enable") == 0) {
1212 dut->ap_ft_oa = 1;
1213 } else if (strcasecmp(val, "Disable") == 0) {
1214 dut->ap_ft_oa = 0;
1215 } else {
1216 send_resp(dut, conn, SIGMA_ERROR,
1217 "errorCode,Wrong value for FT_OA");
1218 return 0;
1219 }
1220 }
1221
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001222 val = get_param(cmd, "Cellular_Cap_Pref");
1223 if (val)
1224 dut->ap_cell_cap_pref = atoi(val);
1225
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001226 val = get_param(cmd, "DOMAIN");
1227 if (val) {
1228 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1229 send_resp(dut, conn, SIGMA_ERROR,
1230 "errorCode,Too long DOMAIN");
1231 return 0;
1232 }
1233 snprintf(dut->ap_mobility_domain,
1234 sizeof(dut->ap_mobility_domain), "%s", val);
1235 }
1236
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001237 val = get_param(cmd, "ft_bss_list");
1238 if (val) {
1239 char *mac_str;
1240 int i;
1241 char *saveptr;
1242 char *mac_list_str;
1243
1244 mac_list_str = strdup(val);
1245 if (!mac_list_str)
1246 return -1;
1247 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1248 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1249 if (parse_mac_address(dut, mac_str,
1250 dut->ft_bss_mac_list[i]) < 0) {
1251 sigma_dut_print(dut, DUT_MSG_ERROR,
1252 "MAC Address not in proper format");
1253 break;
1254 }
1255 dut->ft_bss_mac_cnt++;
1256 mac_str = strtok_r(NULL, " ", &saveptr);
1257 }
1258 sigma_dut_print(dut, DUT_MSG_DEBUG,
1259 "Storing the following FT BSS MAC List");
1260 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1261 sigma_dut_print(dut, DUT_MSG_DEBUG,
1262 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1263 i,
1264 dut->ft_bss_mac_list[i][0],
1265 dut->ft_bss_mac_list[i][1],
1266 dut->ft_bss_mac_list[i][2],
1267 dut->ft_bss_mac_list[i][3],
1268 dut->ft_bss_mac_list[i][4],
1269 dut->ft_bss_mac_list[i][5]);
1270 }
1271 free(mac_list_str);
1272 }
1273
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001274 val = get_param(cmd, "OCESupport");
1275 if (val) {
1276 if (strcasecmp(val, "enable") == 0) {
1277 dut->ap_oce = VALUE_ENABLED;
1278 } else if (strcasecmp(val, "disable") == 0) {
1279 dut->ap_oce = VALUE_DISABLED;
1280 dut->ap_filsdscv = VALUE_DISABLED;
1281 } else {
1282 send_resp(dut, conn, SIGMA_INVALID,
1283 "errorCode,Unsupported OCE");
1284 return 0;
1285 }
1286 }
1287
1288 val = get_param(cmd, "FILSDscvInterval");
1289 if (val)
1290 dut->ap_fils_dscv_int = atoi(val);
1291
1292 val = get_param(cmd, "BroadcastSSID");
1293 if (val) {
1294 if (strcasecmp(val, "enable") == 0) {
1295 dut->ap_broadcast_ssid = VALUE_ENABLED;
1296 } else if (strcasecmp(val, "disable") == 0) {
1297 dut->ap_broadcast_ssid = VALUE_DISABLED;
1298 } else {
1299 send_resp(dut, conn, SIGMA_INVALID,
1300 "errorCode,Unsupported hidden SSID");
1301 return 0;
1302 }
1303 }
1304
1305 val = get_param(cmd, "FILSDscv");
1306 if (val) {
1307 if (strcasecmp(val, "enable") == 0) {
1308 dut->ap_filsdscv = VALUE_ENABLED;
1309 } else if (strcasecmp(val, "disable") == 0) {
1310 dut->ap_filsdscv = VALUE_DISABLED;
1311 } else {
1312 send_resp(dut, conn, SIGMA_INVALID,
1313 "errorCode,Unsupported FILSDscv");
1314 return 0;
1315 }
1316 }
1317
1318 val = get_param(cmd, "FILSHLP");
1319 if (val) {
1320 if (strcasecmp(val, "enable") == 0) {
1321 dut->ap_filshlp = VALUE_ENABLED;
1322 } else if (strcasecmp(val, "disable") == 0) {
1323 dut->ap_filshlp = VALUE_DISABLED;
1324 } else {
1325 send_resp(dut, conn, SIGMA_INVALID,
1326 "errorCode,Unsupported FILSHLP");
1327 return 0;
1328 }
1329 }
1330
1331 val = get_param(cmd, "NAIRealm");
1332 if (val) {
1333 dut->ap_nairealm_int = 1;
1334 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
1335 return -1;
1336 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1337 }
1338
1339 val = get_param(cmd, "DeauthDisassocTx");
1340 if (val) {
1341 if (strcasecmp(val, "disable") == 0) {
1342 deauth_disassoc(dut, ifname, val);
1343 } else {
1344 send_resp(dut, conn, SIGMA_INVALID,
1345 "errorCode,Unsupported DeauthDisassocTx");
1346 return 0;
1347 }
1348 }
1349
1350 val = get_param(cmd, "RNR");
1351 if (val) {
1352 if (strcasecmp(val, "enable") == 0) {
1353 dut->ap_rnr = VALUE_ENABLED;
1354 } else if (strcasecmp(val, "disable") == 0) {
1355 dut->ap_rnr = VALUE_DISABLED;
1356 } else {
1357 send_resp(dut, conn, SIGMA_INVALID,
1358 "errorCode,Unsupported RNR");
1359 return 0;
1360 }
1361 }
1362
1363 val = get_param(cmd, "BLEChannelUtil");
1364 if (val)
1365 dut->ap_blechanutil = atoi(val);
1366
1367 val = get_param(cmd, "BLEAvailAdminCap");
1368 if (val)
1369 dut->ap_ble_admit_cap = atoi(val);
1370
1371 val = get_param(cmd, "DataPPDUDuration");
1372 if (val)
1373 dut->ap_datappdudura = atoi(val);
1374
1375 val = get_param(cmd, "AirTimeFract");
1376 if (val)
1377 dut->ap_airtimefract = atoi(val);
1378
1379 val = get_param(cmd, "dhcpServIPADDR");
1380 if (val) {
1381 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
1382 return -1;
1383 snprintf(dut->ap_dhcpserv_ipaddr,
1384 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1385 dut->ap_dhcp_stop = 1;
1386 }
1387
1388 val = get_param(cmd, "ESP_IE");
1389 if (val) {
1390 if (strcasecmp(val, "enable") == 0) {
1391 dut->ap_esp = VALUE_ENABLED;
1392 } else if (strcasecmp(val, "disable") == 0) {
1393 dut->ap_esp = VALUE_DISABLED;
1394 } else {
1395 send_resp(dut, conn, SIGMA_INVALID,
1396 "errorCode,Unsupported ESP_IE");
1397 return 0;
1398 }
1399 }
1400
1401 val = get_param(cmd, "BAWinSize");
1402 if (val)
1403 dut->ap_bawinsize = atoi(val);
1404
1405 val = get_param(cmd, "BLEStaCount");
1406 if (val)
1407 dut->ap_blestacnt = atoi(val);
1408
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001409 val = get_param(cmd, "PPDUTxType");
1410 if (val) {
1411 if (strcasecmp(val, "MU") == 0) {
1412 dut->ap_he_ppdu = PPDU_MU;
1413 } else {
1414 send_resp(dut, conn, SIGMA_INVALID,
1415 "errorCode,Unsupported PPDUTxType");
1416 return 0;
1417 }
1418 }
1419
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001420 return 1;
1421}
1422
1423
1424static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1425{
1426 char buf[256];
1427 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1428
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301429 if (tid < 0 ||
1430 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1431 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1432 return;
1433 }
1434
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435 snprintf(buf, sizeof(buf),
1436 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1437 ifname, VI_QOS_TMP_FILE);
1438 if (system(buf) != 0)
1439 return;
1440
1441 snprintf(buf, sizeof(buf),
1442 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1443 ifname, VI_QOS_TMP_FILE);
1444 if (system(buf) != 0)
1445 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1446
1447 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1448 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1449 if (system(buf) != 0) {
1450 sigma_dut_print(dut, DUT_MSG_ERROR,
1451 "Output redirection to VI_QOS_TMP_FILE failed");
1452 }
1453
1454 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1455 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1456 if (system(buf) != 0) {
1457 sigma_dut_print(dut, DUT_MSG_ERROR,
1458 "Append TID to VI_QOS_FILE failed ");
1459 }
1460
1461 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1462 if (system(buf) != 0)
1463 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1464}
1465
1466
1467static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1468 struct sigma_cmd *cmd)
1469{
1470 const char *val;
1471 char *ifname;
1472 char buf[256];
1473 int tid = 0;
1474
1475 ifname = get_main_ifname();
1476 val = get_param(cmd, "TID");
1477 if (val) {
1478 tid = atoi(val);
1479 if (tid)
1480 ath_inject_frame(dut, ifname, tid);
1481 }
1482
1483 /* NOTE: This is the command sequence on Peregrine for ADDBA */
1484 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
1485 if (system(buf) != 0) {
1486 sigma_dut_print(dut, DUT_MSG_ERROR,
1487 "iwpriv setaddbaoper failed");
1488 }
1489
1490 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1491 ifname, tid);
1492 if (system(buf) != 0) {
1493 sigma_dut_print(dut, DUT_MSG_ERROR,
1494 "wifitool senddelba failed");
1495 }
1496
1497 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1498 ifname, tid);
1499 if (system(buf) != 0) {
1500 sigma_dut_print(dut, DUT_MSG_ERROR,
1501 "wifitool sendaddba failed");
1502 }
1503
1504 return 1;
1505}
1506
1507
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301508static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1509 const char *sta_mac,
1510 const char *dir_path)
1511{
1512 DIR *dir;
1513 struct dirent *entry;
1514 char buf[128], path[128];
1515 int ret = 0;
1516
1517 dir = opendir(dir_path);
1518 if (!dir)
1519 return 0;
1520
1521 while ((entry = readdir(dir))) {
1522 ret = 1;
1523
1524 if (strcmp(entry->d_name, ".") == 0 ||
1525 strcmp(entry->d_name, "..") == 0)
1526 continue;
1527
1528 snprintf(path, sizeof(path) - 1, "%s/%s",
1529 dir_path, entry->d_name);
1530 path[sizeof(path) - 1] = 0;
1531
1532 if (strcmp(entry->d_name, sta_mac) == 0) {
1533 snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode",
1534 path);
1535 if (system(buf) != 0) {
1536 sigma_dut_print(dut, DUT_MSG_ERROR,
1537 "Failed to set aggr mode for ath10k");
1538 }
1539
1540 snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba",
1541 tid, path);
1542 if (system(buf) != 0) {
1543 sigma_dut_print(dut, DUT_MSG_ERROR,
1544 "Failed to set addbareq for ath10k");
1545 }
1546
1547 break;
1548 }
1549
1550 /* Recursively search subdirectories */
1551 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1552 }
1553
1554 closedir(dir);
1555
1556 return ret;
1557}
1558
1559
1560static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1561 struct sigma_cmd *cmd)
1562{
1563 const char *val;
1564 int tid = 0;
1565
1566 val = get_param(cmd, "TID");
1567 if (val)
1568 tid = atoi(val);
1569
1570 val = get_param(cmd, "sta_mac_address");
1571 if (!val) {
1572 sigma_dut_print(dut, DUT_MSG_ERROR,
1573 "Failed to parse station MAC address");
1574 return 0;
1575 }
1576
1577 return ath10k_debug_enable_addba_req(dut, tid, val,
1578 "/sys/kernel/debug/ieee80211");
1579}
1580
1581
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1583 struct sigma_cmd *cmd)
1584{
1585 /* const char *name = get_param(cmd, "NAME"); */
1586 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301587 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001588
1589 switch (get_driver_type()) {
1590 case DRIVER_ATHEROS:
1591 return ath_ap_send_addba_req(dut, conn, cmd);
1592 case DRIVER_OPENWRT:
1593 switch (get_openwrt_driver_type()) {
1594 case OPENWRT_DRIVER_ATHEROS:
1595 return ath_ap_send_addba_req(dut, conn, cmd);
1596 default:
1597 send_resp(dut, conn, SIGMA_ERROR,
1598 "errorCode,ap_send_addba_req not supported with this driver");
1599 return 0;
1600 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301601 case DRIVER_WCN:
1602 case DRIVER_LINUX_WCN:
1603 /* AP automatically sends ADDBA request after association. */
1604 sigma_dut_print(dut, DUT_MSG_INFO,
1605 "ap_send_addba_req command ignored");
1606 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301607 case DRIVER_MAC80211:
1608 if (stat("/sys/module/ath10k_core", &s) == 0)
1609 return ath10k_ap_send_addba_req(dut, cmd);
1610 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001611 default:
1612 send_resp(dut, conn, SIGMA_ERROR,
1613 "errorCode,ap_send_addba_req not supported with this driver");
1614 return 0;
1615 }
1616}
1617
1618
1619static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1620 struct sigma_cmd *cmd)
1621{
1622 /* const char *name = get_param(cmd, "NAME"); */
1623 const char *val;
1624 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301625 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001626
1627 val = get_param(cmd, "WLAN_TAG");
1628 if (val)
1629 wlan_tag = atoi(val);
1630
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301631 security = get_param(cmd, "Security");
1632
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001633 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001634 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301635 if (!val)
1636 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001637 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001638 if (strcasecmp(val, "NONE") == 0) {
1639 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1640 } else if (strcasecmp(val, "OSEN") == 0 &&
1641 wlan_tag == 2) {
1642 /*
1643 * OSEN only supported on WLAN_TAG = 2 for now
1644 */
1645 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301646 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1647 (security &&
1648 strcasecmp(security, "PSK") == 0 &&
1649 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001650 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1651 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02001652 } else if (strcasecmp(val, "OWE") == 0 &&
1653 wlan_tag == 2) {
1654 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1655 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001656 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001657 send_resp(dut, conn, SIGMA_INVALID,
1658 "errorCode,Unsupported KEYMGNT");
1659 return 0;
1660 }
1661 return 1;
1662 }
1663 }
1664
1665 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301666 if (!val)
1667 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001668 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301669 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1670 (security && strcasecmp(security, "PSK") == 0 &&
1671 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001672 dut->ap_key_mgmt = AP_WPA2_PSK;
1673 dut->ap_cipher = AP_CCMP;
1674 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1675 strcasecmp(val, "WPA2-Ent") == 0) {
1676 dut->ap_key_mgmt = AP_WPA2_EAP;
1677 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001678 } else if (strcasecmp(val, "SuiteB") == 0) {
1679 dut->ap_key_mgmt = AP_SUITEB;
1680 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02001681 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001682 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1683 dut->ap_key_mgmt = AP_WPA_PSK;
1684 dut->ap_cipher = AP_TKIP;
1685 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1686 strcasecmp(val, "WPA-Ent") == 0) {
1687 dut->ap_key_mgmt = AP_WPA_EAP;
1688 dut->ap_cipher = AP_TKIP;
1689 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1690 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1691 dut->ap_cipher = AP_CCMP_TKIP;
1692 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1693 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1694 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02001695 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
1696 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03001697 dut->ap_key_mgmt = AP_WPA2_SAE;
1698 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001699 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03001700 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1701 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1702 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001703 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001704 } else if (strcasecmp(val, "OWE") == 0) {
1705 dut->ap_key_mgmt = AP_WPA2_OWE;
1706 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001707 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03001708 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
1709 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
1710 dut->ap_cipher = AP_CCMP;
1711 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03001712 } else if (strcasecmp(val, "OSEN") == 0) {
1713 dut->ap_key_mgmt = AP_OSEN;
1714 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03001715 } else if (strcasecmp(val, "FT-EAP") == 0) {
1716 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
1717 dut->ap_cipher = AP_CCMP;
1718 dut->ap_pmf = AP_PMF_OPTIONAL;
1719 } else if (strcasecmp(val, "FT-PSK") == 0) {
1720 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
1721 dut->ap_cipher = AP_CCMP;
1722 dut->ap_pmf = AP_PMF_OPTIONAL;
1723 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
1724 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
1725 dut->ap_cipher = AP_CCMP;
1726 dut->ap_pmf = AP_PMF_OPTIONAL;
1727 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
1728 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
1729 dut->ap_cipher = AP_CCMP;
1730 dut->ap_pmf = AP_PMF_OPTIONAL;
1731 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
1732 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
1733 dut->ap_cipher = AP_CCMP;
1734 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001735 } else if (strcasecmp(val, "NONE") == 0) {
1736 dut->ap_key_mgmt = AP_OPEN;
1737 dut->ap_cipher = AP_PLAIN;
1738 } else {
1739 send_resp(dut, conn, SIGMA_INVALID,
1740 "errorCode,Unsupported KEYMGNT");
1741 return 0;
1742 }
1743 }
1744
Jouni Malinen30824df2017-08-22 21:21:38 +03001745 val = get_param(cmd, "ECGroupID");
1746 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001747 free(dut->ap_sae_groups);
1748 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001749 }
1750
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001751 val = get_param(cmd, "AntiCloggingThreshold");
1752 if (val)
1753 dut->sae_anti_clogging_threshold = atoi(val);
1754
Jouni Malinenb347db02017-09-02 01:36:03 +03001755 val = get_param(cmd, "Reflection");
1756 if (val)
1757 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1758
Jouni Malinen68143132017-09-02 02:34:08 +03001759 val = get_param(cmd, "InvalidSAEElement");
1760 if (val) {
1761 free(dut->sae_commit_override);
1762 dut->sae_commit_override = strdup(val);
1763 }
1764
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001765 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301766 if (!val)
1767 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001768 if (val) {
1769 if (strcasecmp(val, "WEP") == 0) {
1770 dut->ap_cipher = AP_WEP;
1771 } else if (strcasecmp(val, "TKIP") == 0) {
1772 dut->ap_cipher = AP_TKIP;
1773 } else if (strcasecmp(val, "AES") == 0 ||
1774 strcasecmp(val, "AES-CCMP") == 0) {
1775 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001776 } else if (strcasecmp(val, "AES-GCMP") == 0) {
1777 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001778 } else {
1779 send_resp(dut, conn, SIGMA_INVALID,
1780 "errorCode,Unsupported ENCRYPT");
1781 return 0;
1782 }
1783 }
1784
Jouni Malinen3d633da2017-09-14 22:19:21 +03001785 val = get_param(cmd, "PairwiseCipher");
1786 if (val) {
1787 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1788 dut->ap_cipher = AP_GCMP_256;
1789 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1790 dut->ap_cipher = AP_CCMP_256;
1791 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1792 dut->ap_cipher = AP_GCMP_128;
1793 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1794 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02001795 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
1796 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
1797 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001798 } else {
1799 send_resp(dut, conn, SIGMA_INVALID,
1800 "errorCode,Unsupported PairwiseCipher");
1801 return 0;
1802 }
1803 }
1804
Jouni Malinen2ba24492017-11-17 12:43:59 +02001805 val = get_param(cmd, "GroupCipher");
1806 if (val) {
1807 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1808 dut->ap_group_cipher = AP_GCMP_256;
1809 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1810 dut->ap_group_cipher = AP_CCMP_256;
1811 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1812 dut->ap_group_cipher = AP_GCMP_128;
1813 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1814 dut->ap_group_cipher = AP_CCMP;
1815 } else {
1816 send_resp(dut, conn, SIGMA_INVALID,
1817 "errorCode,Unsupported GroupCipher");
1818 return 0;
1819 }
1820 }
1821
Jouni Malinen3d633da2017-09-14 22:19:21 +03001822 val = get_param(cmd, "GroupMgntCipher");
1823 if (val) {
1824 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1825 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
1826 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1827 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
1828 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1829 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
1830 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1831 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
1832 } else {
1833 send_resp(dut, conn, SIGMA_INVALID,
1834 "errorCode,Unsupported GroupMgntCipher");
1835 return 0;
1836 }
1837 }
1838
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001839 val = get_param(cmd, "WEPKEY");
1840 if (val) {
1841 size_t len;
1842 if (dut->ap_cipher != AP_WEP) {
1843 send_resp(dut, conn, SIGMA_INVALID,
1844 "errorCode,Unexpected WEPKEY without WEP "
1845 "configuration");
1846 return 0;
1847 }
1848 len = strlen(val);
1849 if (len != 10 && len != 26) {
1850 send_resp(dut, conn, SIGMA_INVALID,
1851 "errorCode,Unexpected WEPKEY length");
1852 return 0;
1853 }
1854 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1855 }
1856
1857 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301858 if (!val)
1859 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001860 if (val) {
Jouni Malinen2126f422017-10-11 23:24:33 +03001861 if (dut->ap_key_mgmt != AP_WPA2_SAE && strlen(val) > 64)
1862 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001863 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1864 return -1;
1865 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1866 "%s", val);
1867 }
1868
Jouni Malinen63370622017-11-18 17:47:13 +02001869 val = get_param(cmd, "PSKHEX");
1870 if (val) {
1871 if (strlen(val) != 64)
1872 return -1;
1873 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
1874 }
1875
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301876 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
1877 dut->ap_pmf = AP_PMF_OPTIONAL;
1878
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001879 val = get_param(cmd, "PMF");
1880 if (val) {
1881 if (strcasecmp(val, "Disabled") == 0) {
1882 dut->ap_pmf = AP_PMF_DISABLED;
1883 } else if (strcasecmp(val, "Optional") == 0) {
1884 dut->ap_pmf = AP_PMF_OPTIONAL;
1885 } else if (strcasecmp(val, "Required") == 0) {
1886 dut->ap_pmf = AP_PMF_REQUIRED;
1887 } else {
1888 send_resp(dut, conn, SIGMA_INVALID,
1889 "errorCode,Unsupported PMF");
1890 return 0;
1891 }
1892 }
1893
1894 if (dut->ap_key_mgmt == AP_OPEN) {
1895 dut->ap_hs2 = 0;
1896 dut->ap_pmf = AP_PMF_DISABLED;
1897 }
1898
1899 dut->ap_add_sha256 = 0;
1900 val = get_param(cmd, "SHA256AD");
1901 if (val == NULL)
1902 val = get_param(cmd, "SHA256");
1903 if (val) {
1904 if (strcasecmp(val, "Disabled") == 0) {
1905 } else if (strcasecmp(val, "Enabled") == 0) {
1906 dut->ap_add_sha256 = 1;
1907 } else {
1908 send_resp(dut, conn, SIGMA_INVALID,
1909 "errorCode,Unsupported PMF");
1910 return 0;
1911 }
1912 }
1913
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301914 val = get_param(cmd, "PreAuthentication");
1915 if (val) {
1916 if (strcasecmp(val, "disabled") == 0) {
1917 dut->ap_rsn_preauth = 0;
1918 } else if (strcasecmp(val, "enabled") == 0) {
1919 dut->ap_rsn_preauth = 1;
1920 } else {
1921 send_resp(dut, conn, SIGMA_INVALID,
1922 "errorCode,Unsupported PreAuthentication value");
1923 return 0;
1924 }
1925 }
1926
priyadharshini gowthamande81f392017-12-28 15:28:49 -08001927 val = get_param(cmd, "AKMSuiteType");
1928 if (val) {
1929 unsigned int akmsuitetype = 0;
1930
1931 dut->ap_akm = 1;
1932 akmsuitetype = atoi(val);
1933 if (akmsuitetype == 14) {
1934 dut->ap_add_sha256 = 1;
1935 } else if (akmsuitetype == 15) {
1936 dut->ap_add_sha384 = 1;
1937 } else {
1938 send_resp(dut, conn, SIGMA_INVALID,
1939 "errorCode,Unsupported AKMSuitetype");
1940 return 0;
1941 }
1942 }
1943
1944 val = get_param(cmd, "PMKSACaching");
1945 if (val) {
1946 dut->ap_pmksa = 1;
1947 if (strcasecmp(val, "disabled") == 0) {
1948 dut->ap_pmksa_caching = 1;
1949 } else if (strcasecmp(val, "enabled") == 0) {
1950 dut->ap_pmksa_caching = 0;
1951 } else {
1952 send_resp(dut, conn, SIGMA_INVALID,
1953 "errorCode,Unsupported PMKSACaching value");
1954 return 0;
1955 }
1956 }
1957
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001958 return 1;
1959}
1960
1961
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301962int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
1963 struct sigma_cmd *cmd)
1964{
1965 int status;
1966
1967 status = cmd_ap_set_wireless(dut, conn, cmd);
1968 if (status != 1)
1969 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301970 status = cmd_ap_set_security(dut, conn, cmd);
1971 if (status != 1)
1972 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301973 return cmd_ap_config_commit(dut, conn, cmd);
1974}
1975
1976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001977static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
1978 struct sigma_cmd *cmd)
1979{
1980 /* const char *name = get_param(cmd, "NAME"); */
1981 const char *val;
1982 unsigned int wlan_tag = 1, radius_port = 0;
1983 char *radius_ipaddr = NULL, *radius_password = NULL;
1984
1985 val = get_param(cmd, "WLAN_TAG");
1986 if (val) {
1987 wlan_tag = atoi(val);
1988 if (wlan_tag != 1 && wlan_tag != 2) {
1989 send_resp(dut, conn, SIGMA_INVALID,
1990 "errorCode,Invalid WLAN_TAG");
1991 return 0;
1992 }
1993 }
1994
1995 val = get_param(cmd, "PORT");
1996 if (val)
1997 radius_port = atoi(val);
1998
1999 if (wlan_tag == 1) {
2000 if (radius_port)
2001 dut->ap_radius_port = radius_port;
2002 radius_ipaddr = dut->ap_radius_ipaddr;
2003 radius_password = dut->ap_radius_password;
2004 } else if (wlan_tag == 2) {
2005 if (radius_port)
2006 dut->ap2_radius_port = radius_port;
2007 radius_ipaddr = dut->ap2_radius_ipaddr;
2008 radius_password = dut->ap2_radius_password;
2009 }
2010
2011 val = get_param(cmd, "IPADDR");
2012 if (val) {
2013 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2014 return -1;
2015 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2016 "%s", val);
2017 }
2018
2019 val = get_param(cmd, "PASSWORD");
2020 if (val) {
2021 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2022 return -1;
2023 snprintf(radius_password,
2024 sizeof(dut->ap_radius_password), "%s", val);
2025 }
2026
2027 return 1;
2028}
2029
2030
2031static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2032 const char *key, const char *val)
2033{
2034 char buf[100];
2035
2036 if (val == NULL) {
2037 snprintf(buf, sizeof(buf),
2038 "uci delete wireless.wifi%d.%s", id, key);
2039 run_system(dut, buf);
2040 return;
2041 }
2042
2043 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2044 id, key, val);
2045 run_system(dut, buf);
2046}
2047
2048
2049static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2050 const char *key, const char *val)
2051{
2052 char buf[256];
2053
2054 if (val == NULL) {
2055 snprintf(buf, sizeof(buf),
2056 "uci del_list wireless.wifi%d.%s", id, key);
2057 run_system(dut, buf);
2058 return;
2059 }
2060
2061 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2062 id, key, val);
2063 run_system(dut, buf);
2064}
2065
2066
2067static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2068 const char *val)
2069{
2070 char buf[256];
2071
2072 if (val == NULL) {
2073 snprintf(buf, sizeof(buf),
2074 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2075 run_system(dut, buf);
2076 return;
2077 }
2078
2079 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2080 id, key, val);
2081 run_system(dut, buf);
2082}
2083
2084
2085static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2086 const char *key, const char *val)
2087{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002088 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002089
2090 if (val == NULL) {
2091 snprintf(buf, sizeof(buf),
2092 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2093 run_system(dut, buf);
2094 return;
2095 }
2096
2097 snprintf(buf, sizeof(buf),
2098 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2099 id, key, val);
2100 run_system(dut, buf);
2101}
2102
2103
2104static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2105 const char *val)
2106{
2107 char buf[256];
2108
2109 if (val == NULL) {
2110 snprintf(buf, sizeof(buf),
2111 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2112 run_system(dut, buf);
2113 return;
2114 }
2115
2116 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
2117 run_system(dut, buf);
2118 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2119 id, key, val);
2120 run_system(dut, buf);
2121 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2122 id, "network", "lan");
2123 run_system(dut, buf);
2124 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2125 id, "mode", "ap");
2126 run_system(dut, buf);
2127 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2128 id, "encryption", "none");
2129 run_system(dut, buf);
2130}
2131
2132
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002133#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002134static void owrt_ap_config_radio(struct sigma_dut *dut)
2135{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002136 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002137 int radio_count, radio_no;
2138 char buf[64];
2139
2140 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2141 radio_count++) {
2142 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2143 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2144 if (!sigma_radio_ifname[radio_no] ||
2145 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2146 continue;
2147 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2148 owrt_ap_set_vap(dut, radio_count, "device", buf);
2149 radio_id[radio_no] = radio_count;
2150 }
2151 }
2152
2153 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2154 switch (dut->ap_mode) {
2155 case AP_11g:
2156 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2157 break;
2158 case AP_11b:
2159 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2160 break;
2161 case AP_11ng:
2162 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2163 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2164 break;
2165 case AP_11a:
2166 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2167 break;
2168 case AP_11na:
2169 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2170 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2171 break;
2172 case AP_11ac:
2173 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2174 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2175 break;
2176 case AP_inval:
2177 sigma_dut_print(dut, DUT_MSG_ERROR,
2178 "MODE NOT SPECIFIED!");
2179 return;
2180 default:
2181 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2182 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2183 break;
2184 }
2185
2186 if (dut->ap_is_dual) {
2187 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2188 switch (dut->ap_mode_1) {
2189 case AP_11g:
2190 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2191 break;
2192 case AP_11b:
2193 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2194 break;
2195 case AP_11ng:
2196 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2197 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2198 break;
2199 case AP_11a:
2200 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2201 break;
2202 case AP_11na:
2203 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2204 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2205 break;
2206 case AP_11ac:
2207 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2208 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2209 break;
2210 case AP_inval:
2211 sigma_dut_print(dut, DUT_MSG_ERROR,
2212 "MODE NOT SPECIFIED!");
2213 return;
2214 default:
2215 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2216 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2217 break;
2218 }
2219
2220 }
2221
2222 /* Channel */
2223 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2224 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2225
2226 switch (dut->ap_chwidth) {
2227 case AP_20:
2228 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2229 break;
2230 case AP_40:
2231 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2232 break;
2233 case AP_80:
2234 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2235 break;
2236 case AP_160:
2237 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2238 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002239 case AP_80_80:
2240 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2241 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002242 case AP_AUTO:
2243 default:
2244 break;
2245 }
2246
2247 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2248 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2249 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2250 }
2251
2252 if (dut->ap_is_dual) {
2253 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2254 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2255 }
2256
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002257 /* Country Code */
2258 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2259 const char *country;
2260
2261 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2262 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002263 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002264 if (dut->ap_is_dual)
2265 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002266 } else if (dut->ap_countrycode[0]) {
2267 owrt_ap_set_radio(dut, radio_id[0], "country",
2268 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002269 }
2270
2271 if (dut->ap_disable_protection == 1) {
2272 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2273 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2274 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2275 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2276 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002277
2278 if (dut->ap_oce == VALUE_ENABLED &&
2279 get_driver_type() == DRIVER_OPENWRT)
2280 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002281}
2282
2283
2284static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2285{
2286 char buf[256];
2287
2288 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2289 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2290 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2291 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2292
2293 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2294 "'eng:Wi-Fi Alliance'");
2295
2296 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2297 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2298
2299 if (dut->ap_wan_metrics == 1)
2300 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2301 "'01:2500:384:0:0:10'");
2302 else if (dut->ap_wan_metrics == 1)
2303 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2304 "'01:1500:384:20:20:10'");
2305 else if (dut->ap_wan_metrics == 2)
2306 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2307 "'01:1500:384:20:20:10'");
2308 else if (dut->ap_wan_metrics == 3)
2309 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2310 "'01:2000:1000:20:20:10'");
2311 else if (dut->ap_wan_metrics == 4)
2312 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2313 "'01:8000:1000:20:20:10'");
2314 else if (dut->ap_wan_metrics == 5)
2315 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2316 "'01:9000:5000:20:20:10'");
2317
2318 if (dut->ap_conn_capab == 1) {
2319 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2320 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2321 "'6:20:1'");
2322 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2323 "'6:22:0'");
2324 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2325 "'6:80:1'");
2326 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2327 "'6:443:1'");
2328 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2329 "'6:1723:0'");
2330 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2331 "'6:5060:0'");
2332 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2333 "'17:500:1'");
2334 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2335 "'17:5060:0'");
2336 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2337 "'17:4500:1'");
2338 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2339 "'50:0:1'");
2340 } else if (dut->ap_conn_capab == 2) {
2341 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2342 "'6:80:1'");
2343 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2344 "'6:443:1'");
2345 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2346 "'17:5060:1'");
2347 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2348 "'6:5060:1'");
2349 } else if (dut->ap_conn_capab == 3) {
2350 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2351 "'6:80:1'");
2352 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2353 "'6:443:1'");
2354 }
2355
2356 if (dut->ap_oper_class == 1)
2357 snprintf(buf, sizeof(buf), "%s", "51");
2358 else if (dut->ap_oper_class == 2)
2359 snprintf(buf, sizeof(buf), "%s", "73");
2360 else if (dut->ap_oper_class == 3)
2361 snprintf(buf, sizeof(buf), "%s", "5173");
2362
2363 if (dut->ap_oper_class)
2364 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2365
2366 if (dut->ap_osu_provider_list) {
2367 char *osu_friendly_name = NULL;
2368 char *osu_icon = NULL;
2369 char *osu_ssid = NULL;
2370 char *osu_nai = NULL;
2371 char *osu_service_desc = NULL;
2372 char *hs20_icon_filename = NULL;
2373 char hs20_icon[150];
2374 int osu_method;
2375
2376 hs20_icon_filename = "icon_red_zxx.png";
2377 if (dut->ap_osu_icon_tag == 2)
2378 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2379 snprintf(hs20_icon, sizeof(hs20_icon),
2380 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2381 hs20_icon_filename);
2382 osu_icon = "icon_red_zxx.png";
2383 osu_ssid = "OSU";
2384 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2385 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2386 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2387 dut->ap_osu_method[0];
2388
2389 if (strlen(dut->ap_osu_server_uri[0]))
2390 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2391 dut->ap_osu_server_uri[0]);
2392 else
2393 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2394 "'https://osu-server.r2-testbed.wi-fi.org/'");
2395 switch (dut->ap_osu_provider_list) {
2396 case 1:
2397 case 101:
2398 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2399 "'eng:SP Red Test Only'");
2400 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2401 "'eng:Free service for test purpose'");
2402 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2403 hs20_icon);
2404
2405 hs20_icon_filename = "icon_red_eng.png";
2406 if (dut->ap_osu_icon_tag == 2)
2407 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2408
2409 snprintf(hs20_icon, sizeof(hs20_icon),
2410 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2411 hs20_icon_filename);
2412 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2413 "icon_red_eng.png");
2414 break;
2415 case 2:
2416 case 102:
2417 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2418 "'eng:Wireless Broadband Alliance'");
2419 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2420 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002421 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002422 if (dut->ap_osu_icon_tag == 2)
2423 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2424
2425 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002426 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002427 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002428 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002429 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2430 break;
2431 case 3:
2432 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03002433 osu_friendly_name = "'spa:SP Red Test Only'";
2434 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002435 break;
2436 case 4:
2437 case 104:
2438 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002439 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002440 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2441 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002442 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002443 if (dut->ap_osu_icon_tag == 2)
2444 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2445
2446 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002447 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002448 hs20_icon_filename);
2449 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2450 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002451 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002452
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002453 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002454 if (dut->ap_osu_icon_tag == 2)
2455 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2456
2457 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002458 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002460 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002461 break;
2462 case 5:
2463 case 105:
2464 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002465 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002466 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2467 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002468 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002469
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002470 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002471 if (dut->ap_osu_icon_tag == 2)
2472 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2473
2474 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002475 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002476 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002477 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002478 break;
2479 case 6:
2480 case 106:
2481 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2482 "'eng:SP Green Test Only'");
2483 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2484 "'kor:SP 초록 테스트 전용'");
2485
2486 hs20_icon_filename = "icon_green_zxx.png";
2487 if (dut->ap_osu_icon_tag == 2)
2488 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2489
2490 snprintf(hs20_icon, sizeof(hs20_icon),
2491 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2492 hs20_icon_filename);
2493 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2494 hs20_icon);
2495
2496 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2497 "'icon_green_zxx.png'");
2498 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2499 dut->ap_osu_method[0];
2500
2501 snprintf(buf, sizeof(buf), "%d", osu_method);
2502 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2503
2504 if (strlen(dut->ap_osu_server_uri[1]))
2505 owrt_ap_set_list_vap(dut, vap_id,
2506 "osu_server_uri",
2507 dut->ap_osu_server_uri[1]);
2508 else
2509 owrt_ap_set_list_vap(dut, vap_id,
2510 "osu_server_uri",
2511 "'https://osu-server.r2-testbed.wi-fi.org/'");
2512
2513 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2514 "'eng:SP Orange Test Only'");
2515
2516 hs20_icon_filename = "icon_orange_zxx.png";
2517 if (dut->ap_osu_icon_tag == 2)
2518 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2519
2520 snprintf(hs20_icon, sizeof(hs20_icon),
2521 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2522 hs20_icon_filename);
2523
2524 osu_icon = "icon_orange_zxx.png";
2525 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2526 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2527 dut->ap_osu_method[1];
2528 osu_service_desc = NULL;
2529 break;
2530 case 7:
2531 case 107:
2532 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002533 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002534 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2535 "'eng:Free service for test purpose'");
2536
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002537 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002538 if (dut->ap_osu_icon_tag == 2)
2539 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2540
2541 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002542 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002543 hs20_icon_filename);
2544 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2545 hs20_icon);
2546
2547 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002548 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002549 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002550
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002551 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002552 if (dut->ap_osu_icon_tag == 2)
2553 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2554
2555 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002556 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002557 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002558 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002559 break;
2560 case 8:
2561 case 108:
2562 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2563 "'eng:SP Red Test Only'");
2564 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2565 "'eng:Free service for test purpose'");
2566 osu_ssid = "OSU-Encrypted";
2567 osu_nai = "'anonymous@hotspot.net'";
2568 break;
2569 case 9:
2570 case 109:
2571 osu_ssid = "OSU-OSEN";
2572 osu_nai = "'test-anonymous@wi-fi.org'";
2573 osu_friendly_name = "'eng:SP Orange Test Only'";
2574 hs20_icon_filename = "icon_orange_zxx.png";
2575 if (dut->ap_osu_icon_tag == 2)
2576 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2577
2578 snprintf(hs20_icon, sizeof(hs20_icon),
2579 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2580 hs20_icon_filename);
2581 osu_icon = "icon_orange_zxx.png";
2582 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2583 dut->ap_osu_method[0];
2584 osu_service_desc = NULL;
2585 break;
2586 default:
2587 break;
2588 }
2589
2590 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03002591 if (dut->ap_tag_ssid[0][0] &&
2592 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002593 dut->ap_osu_ssid) != 0 &&
2594 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002595 sigma_dut_print(dut, DUT_MSG_ERROR,
2596 "OSU_SSID and WLAN_TAG2 SSID differ");
2597 return -2;
2598 }
2599
2600 snprintf(buf, sizeof(buf), "'\"%s\"'",
2601 dut->ap_osu_ssid);
2602 } else {
2603 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2604 }
2605
2606 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2607
2608
2609 if (osu_friendly_name)
2610 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2611 osu_friendly_name);
2612 if (osu_service_desc)
2613 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2614 osu_service_desc);
2615 if (osu_nai)
2616 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2617
2618 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2619
2620 if (osu_icon)
2621 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2622 osu_icon);
2623
2624 if (dut->ap_osu_provider_list > 100) {
2625 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2626 "0");
2627 } else {
2628 snprintf(buf, sizeof(buf), "%d", osu_method);
2629 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2630 buf);
2631 }
2632 }
2633
2634 return 0;
2635}
2636
2637
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002638static void set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2639 char *anqp_string, size_t str_size)
2640{
2641 unsigned char bssid[ETH_ALEN];
2642 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2643 int preference = 0xff;
2644
2645 get_hwaddr(ifname, bssid);
2646 snprintf(anqp_string, str_size,
2647 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2648 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2649 preference,
2650 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2651 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2652 preference - 1);
2653}
2654
2655
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002656static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2657 size_t str_size, int wlan_tag)
2658{
Jouni Malinenf8984642017-10-12 00:02:37 +03002659 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002660 enum driver_type drv;
2661
2662 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002663 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2664 ifname = dut->hostapd_ifname;
2665 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002666 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2667 dut->ap_mode == AP_11ac) &&
2668 if_nametoindex("ath1") > 0)
2669 ifname = "ath1";
2670 else
2671 ifname = "ath0";
2672 } else if (drv == DRIVER_OPENWRT) {
2673 if (sigma_radio_ifname[0] &&
2674 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2675 ifname = "ath2";
2676 else if (sigma_radio_ifname[0] &&
2677 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2678 ifname = "ath1";
2679 else
2680 ifname = "ath0";
2681 } else {
2682 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2683 dut->ap_mode == AP_11ac) &&
2684 if_nametoindex("wlan1") > 0)
2685 ifname = "wlan1";
2686 else
2687 ifname = "wlan0";
2688 }
2689
2690 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2691 /* Handle tagged-ifname only on OPENWRT for now */
2692 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Jouni Malinenf8984642017-10-12 00:02:37 +03002693 } else if (drv == DRIVER_MAC80211 && wlan_tag == 2) {
2694 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002695 } else {
2696 snprintf(ifname_str, str_size, "%s", ifname);
2697 }
2698}
2699
2700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002701static int owrt_ap_config_vap(struct sigma_dut *dut)
2702{
2703 char buf[256], *temp;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002704 int vap_id = 0, vap_count, i, j;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002705 const char *ifname;
2706 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002707
priyadharshini gowthaman73561262018-02-20 13:24:59 -08002708 if (sigma_radio_ifname[0] &&
2709 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2710 ifname = "ath2";
2711 else if (sigma_radio_ifname[0] &&
2712 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2713 ifname = "ath1";
2714 else
2715 ifname = "ath0";
2716
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002717 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002718 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002719
2720 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2721 if (sigma_radio_ifname[vap_id] &&
2722 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2723 break;
2724 }
2725 if (vap_id == MAX_RADIO)
2726 continue;
2727
2728 /* Single VAP configuration */
2729 if (!dut->ap_is_dual)
2730 vap_id = vap_count;
2731
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002732 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2733 /*
2734 * We keep a separate array of ap_tag_ssid and
2735 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2736 * So j=0 => WLAN_TAG = 2
2737 */
2738 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002739
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002740 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
2741 (dut->ap_interface_5g || dut->ap_interface_2g)) {
2742 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
2743 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
2744 "%s-owe", dut->ap_ssid);
2745 }
2746
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002747 if (dut->ap_tag_ssid[j][0] == '\0')
2748 continue;
2749
2750 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2751 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2752 "device", buf);
2753 /* SSID */
2754 snprintf(buf, sizeof(buf), "\"%s\"",
2755 dut->ap_tag_ssid[j]);
2756 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2757 "ssid", buf);
2758
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002759 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
2760 dut->ap_tag_ssid[0][0] &&
2761 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
2762 /* OWE transition mode */
2763 snprintf(buf, sizeof(buf), "%s", ifname);
2764 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2765 "owe_transition_ifname", buf);
2766 }
2767
2768 if (dut->ap_key_mgmt == AP_OPEN &&
2769 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2770 /* OWE transition mode */
2771 snprintf(buf, sizeof(buf), "%s", ifname);
2772 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2773 "owe_transition_ifname", buf);
2774 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2775 "hidden", "1");
2776 }
2777
Jouni Malinen6be21c82018-08-01 18:47:24 +03002778 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002779 unsigned char self_mac[ETH_ALEN];
2780 char mac_str[20];
2781
2782 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2783 "mobility_domain",
2784 dut->ap_mobility_domain);
2785 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2786 "ft_over_ds", "0");
2787 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2788 "ieee80211r", "1");
2789 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2790 "nasid", "nas1.example.com");
2791 get_hwaddr(sigma_radio_ifname[0], self_mac);
2792 snprintf(mac_str, sizeof(mac_str),
2793 "%02x:%02x:%02x:%02x:%02x:%02x",
2794 self_mac[0], self_mac[1], self_mac[2],
2795 self_mac[3], self_mac[4], self_mac[5]);
2796 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2797 "ap_macaddr", mac_str);
2798 snprintf(mac_str, sizeof(mac_str),
2799 "%02x%02x%02x%02x%02x%02x",
2800 self_mac[0], self_mac[1], self_mac[2],
2801 self_mac[3], self_mac[4], self_mac[5]);
2802 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2803 "r1_key_holder", mac_str);
2804 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2805 "ft_psk_generate_local", "1");
2806 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2807 "kh_key_hex",
2808 "000102030405060708090a0b0c0d0e0f");
2809 snprintf(mac_str, sizeof(mac_str),
2810 "%02x:%02x:%02x:%02x:%02x:%02x",
2811 dut->ft_bss_mac_list[0][0],
2812 dut->ft_bss_mac_list[0][1],
2813 dut->ft_bss_mac_list[0][2],
2814 dut->ft_bss_mac_list[0][3],
2815 dut->ft_bss_mac_list[0][4],
2816 dut->ft_bss_mac_list[0][5]);
2817 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2818 "ap2_macaddr", mac_str);
2819 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2820 "ap2_r1_key_holder", mac_str);
2821 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2822 "nasid2", "nas2.example.com");
2823 }
2824
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002825 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
2826 wlan_tag == 2) {
2827 /* Only supported for WLAN_TAG=2 */
2828 owrt_ap_set_vap(dut, vap_count + 1, "osen",
2829 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002830 snprintf(buf, sizeof(buf), "wpa2");
2831 owrt_ap_set_vap(dut, vap_count + 1,
2832 "encryption", buf);
2833 snprintf(buf, sizeof(buf), "%s",
2834 dut->ap2_radius_ipaddr);
2835 owrt_ap_set_vap(dut, vap_count + 1,
2836 "auth_server", buf);
2837 snprintf(buf, sizeof(buf), "%d",
2838 dut->ap2_radius_port);
2839 owrt_ap_set_vap(dut, vap_count + 1,
2840 "auth_port", buf);
2841 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002842 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002843 owrt_ap_set_vap(dut, vap_count + 1,
2844 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002845 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
2846 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2847 "encryption", "psk2+ccmp");
2848 snprintf(buf, sizeof(buf), "\"%s\"",
2849 dut->ap_passphrase);
2850 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2851 "key", buf);
2852 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002853 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002854 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002855 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2856 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2857 "owe", "1");
2858 snprintf(buf, sizeof(buf), "ccmp");
2859 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2860 "encryption", buf);
2861 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2862 "ieee80211w", "2");
2863 if (dut->ap_sae_groups) {
2864 snprintf(buf, sizeof(buf), "\'%s\'",
2865 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07002866 owrt_ap_set_list_vap(dut, vap_count +
2867 (wlan_tag - 1),
2868 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002869 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002870 }
2871 }
2872
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002873 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002874 if (dut->program == PROGRAM_MBO &&
2875 get_driver_type() == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002876 unsigned char self_mac[ETH_ALEN];
2877 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002878 char anqp_string[200];
2879
2880 set_anqp_elem_value(dut, sigma_radio_ifname[0],
2881 anqp_string, sizeof(anqp_string));
2882 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
2883 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002884
Jouni Malinen6be21c82018-08-01 18:47:24 +03002885 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002886 owrt_ap_set_vap(dut, vap_count,
2887 "mobility_domain",
2888 dut->ap_mobility_domain);
2889 owrt_ap_set_vap(dut, vap_count,
2890 "ft_over_ds", "0");
2891 owrt_ap_set_vap(dut, vap_count,
2892 "ieee80211r", "1");
2893 owrt_ap_set_vap(dut, vap_count,
2894 "nasid", "nas1.example.com");
2895 get_hwaddr(sigma_radio_ifname[0], self_mac);
2896 snprintf(mac_str, sizeof(mac_str),
2897 "%02x:%02x:%02x:%02x:%02x:%02x",
2898 self_mac[0], self_mac[1], self_mac[2],
2899 self_mac[3], self_mac[4], self_mac[5]);
2900 owrt_ap_set_vap(dut, vap_count,
2901 "ap_macaddr", mac_str);
2902 snprintf(mac_str, sizeof(mac_str),
2903 "%02x%02x%02x%02x%02x%02x",
2904 self_mac[0], self_mac[1], self_mac[2],
2905 self_mac[3], self_mac[4], self_mac[5]);
2906 owrt_ap_set_vap(dut, vap_count,
2907 "r1_key_holder", mac_str);
2908 owrt_ap_set_vap(dut, vap_count,
2909 "ft_psk_generate_local", "1");
2910 owrt_ap_set_vap(dut, vap_count,
2911 "kh_key_hex",
2912 "000102030405060708090a0b0c0d0e0f");
2913 snprintf(mac_str, sizeof(mac_str),
2914 "%02x:%02x:%02x:%02x:%02x:%02x",
2915 dut->ft_bss_mac_list[0][0],
2916 dut->ft_bss_mac_list[0][1],
2917 dut->ft_bss_mac_list[0][2],
2918 dut->ft_bss_mac_list[0][3],
2919 dut->ft_bss_mac_list[0][4],
2920 dut->ft_bss_mac_list[0][5]);
2921 owrt_ap_set_vap(dut, vap_count,
2922 "ap2_macaddr", mac_str);
2923 owrt_ap_set_vap(dut, vap_count,
2924 "ap2_r1_key_holder", mac_str);
2925 owrt_ap_set_vap(dut, vap_count,
2926 "nasid2", "nas2.example.com");
2927 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002928 }
2929
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002930 if (dut->ap_oce == VALUE_ENABLED &&
2931 get_driver_type() == DRIVER_OPENWRT) {
2932 owrt_ap_set_vap(dut, vap_id, "oce", "1");
2933 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2934 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
2935
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002936 if (dut->ap_80plus80 == 1)
2937 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
2938
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002939 if (dut->ap_akm == 1) {
2940 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
2941 "3600");
2942 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
2943 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
2944 "1");
2945 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
2946 "1234");
2947 owrt_ap_set_vap(dut, vap_id,
2948 "erp_send_reauth_start", "1");
2949 }
2950
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002951 if (dut->ap_filshlp == VALUE_ENABLED) {
2952 struct ifreq ifr;
2953 char *ifname;
2954 int s;
2955 struct sockaddr_in *ipaddr;
2956
2957 s = socket(AF_INET, SOCK_DGRAM, 0);
2958 if (s < 0) {
2959 sigma_dut_print(dut, DUT_MSG_ERROR,
2960 "Failed to open socket");
2961 return -1;
2962 }
2963 ifr.ifr_addr.sa_family = AF_INET;
2964
2965 memset(&ifr, 0, sizeof(ifr));
2966 ifname = "br-lan";
2967 strlcpy(ifr.ifr_name, ifname,
2968 sizeof(ifr.ifr_name));
2969 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2970 perror("ioctl");
2971 close(s);
2972 return -1;
2973 }
2974
2975 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
2976 snprintf(buf, sizeof(buf), "%s",
2977 inet_ntoa(ipaddr->sin_addr));
2978 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
2979 buf);
2980 snprintf(buf, sizeof(buf), "%s",
2981 dut->ap_dhcpserv_ipaddr);
2982 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
2983 buf);
2984 owrt_ap_set_vap(dut, vap_id,
2985 "dhcp_rapid_commit_proxy", "1");
2986 owrt_ap_set_vap(dut, vap_id,
2987 "fils_hlp_wait_time", "300");
2988 }
2989
2990 if (dut->ap_filsdscv == VALUE_ENABLED) {
2991 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
2992 "1");
2993 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
2994 "20");
2995 }
2996 }
2997
2998 if (dut->ap_filsdscv == VALUE_DISABLED) {
2999 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3000 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3001 }
3002
3003 if (dut->ap_oce == VALUE_DISABLED &&
3004 get_driver_type() == DRIVER_OPENWRT) {
3005 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3006 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3007 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3008
3009 if (dut->ap_filsdscv == VALUE_DISABLED) {
3010 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3011 "0");
3012 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3013 "0");
3014 }
3015
3016 if (dut->device_type == AP_testbed)
3017 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3018 }
3019
3020 /* NAIRealm */
3021 if (dut->ap_nairealm_int == 1) {
3022 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3023 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3024 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3025 }
3026
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027 /* SSID */
3028 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3029 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3030
3031 /* Encryption */
3032 switch (dut->ap_key_mgmt) {
3033 case AP_OPEN:
3034 if (dut->ap_cipher == AP_WEP) {
3035 owrt_ap_set_vap(dut, vap_count, "encryption",
3036 "wep-mixed");
3037 owrt_ap_set_vap(dut, vap_count, "key",
3038 dut->ap_wepkey);
3039 } else {
3040 owrt_ap_set_vap(dut, vap_count, "encryption",
3041 "none");
3042 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003043 if (dut->ap_key_mgmt == AP_OPEN &&
3044 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3045 /* OWE transition mode */
3046 snprintf(ifname2, sizeof(ifname2), "%s1",
3047 ifname);
3048 owrt_ap_set_vap(dut, vap_count,
3049 "owe_transition_ifname",
3050 ifname2);
3051 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003052 break;
3053 case AP_WPA2_PSK:
3054 case AP_WPA2_PSK_MIXED:
3055 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003056 case AP_WPA2_SAE:
3057 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003058 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3059 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003060 snprintf(buf, sizeof(buf), "psk2");
3061 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3062 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003063 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3064 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003065 } else {
3066 snprintf(buf, sizeof(buf), "psk");
3067 }
3068
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003069 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3070 if (dut->ap_cipher == AP_CCMP_TKIP)
3071 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3072 else if (dut->ap_cipher == AP_TKIP)
3073 strlcat(buf, "+tkip", sizeof(buf));
3074 else
3075 strlcat(buf, "+ccmp", sizeof(buf));
3076 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003077
3078 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003079
3080 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3081 snprintf(buf, sizeof(buf), "\"%s\"",
3082 dut->ap_psk);
3083 owrt_ap_set_vap(dut, vap_count, "key", buf);
3084 } else {
3085 snprintf(buf, sizeof(buf), "\"%s\"",
3086 dut->ap_passphrase);
3087 owrt_ap_set_vap(dut, vap_count, "key", buf);
3088 }
3089
3090 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3091 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3092 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3093 else
3094 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3095
3096 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3097 snprintf(buf, sizeof(buf), "%s",
3098 dut->ap_passphrase);
3099 owrt_ap_set_vap(dut, vap_count, "sae_password",
3100 buf);
3101 } else {
3102 snprintf(buf, sizeof(buf), "%s",
3103 dut->ap_passphrase);
3104 owrt_ap_set_vap(dut, vap_count,
3105 "wpa_passphrase", buf);
3106 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003107 break;
3108 case AP_WPA2_EAP:
3109 case AP_WPA2_EAP_MIXED:
3110 case AP_WPA_EAP:
3111 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3112 snprintf(buf, sizeof(buf), "wpa2");
3113 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3114 snprintf(buf, sizeof(buf), "wpa-mixed");
3115 } else {
3116 snprintf(buf, sizeof(buf), "wpa");
3117 }
3118
Peng Xu591be452017-05-10 17:27:28 -07003119 if (dut->ap_cipher == AP_CCMP_TKIP)
3120 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3121 else if (dut->ap_cipher == AP_TKIP)
3122 strlcat(buf, "+tkip", sizeof(buf));
3123 else
3124 strlcat(buf, "+ccmp", sizeof(buf));
3125
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003126 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3127 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3128 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3129 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3130 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3131 snprintf(buf, sizeof(buf), "%s",
3132 dut->ap_radius_password);
3133 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3134 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003135 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003136 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003137 case AP_WPA2_FT_EAP:
3138 case AP_WPA2_FT_PSK:
3139 case AP_WPA2_EAP_SHA256:
3140 case AP_WPA2_PSK_SHA256:
3141 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003142 /* TODO */
3143 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003144 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003145 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3146 snprintf(buf, sizeof(buf), "gcmp");
3147 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3148 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3149 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3150 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3151 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3152 snprintf(buf, sizeof(buf), "%s",
3153 dut->ap_radius_password);
3154 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3155 snprintf(buf, sizeof(buf), "%d",
3156 dut->ap_group_mgmt_cipher);
3157 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3158 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003159 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003160 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003161 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3162 snprintf(buf, sizeof(buf), "ccmp");
3163 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3164 if (dut->ap_sae_groups) {
3165 snprintf(buf, sizeof(buf), "\'%s\'",
3166 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003167 owrt_ap_set_list_vap(dut, vap_count,
3168 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003169 }
3170
3171 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3172 dut->ap_tag_ssid[0][0] &&
3173 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3174 /* OWE transition mode */
3175 snprintf(ifname2, sizeof(ifname2), "%s1",
3176 ifname);
3177 owrt_ap_set_vap(dut, vap_count,
3178 "owe_transition_ifname",
3179 ifname2);
3180 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3181 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003182 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003183 }
3184
3185 if (!dut->ap_is_dual)
3186 break;
3187 }
3188
3189 if (dut->ap_is_dual)
3190 return 1;
3191
3192 /* PMF */
3193 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3194 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3195
3196 /* Add SHA256 */
3197 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3198 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3199
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003200 /* Add SHA384 for akmsuitetype 15 */
3201 if (dut->ap_akm == 1) {
3202 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3203 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3204 }
3205
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303206 /* Enable RSN preauthentication, if asked to */
3207 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3208 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3209
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003210 /* Hotspot 2.0 */
3211 if (dut->ap_hs2) {
3212 int ret;
3213
3214 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3215 if (ret)
3216 return ret;
3217 }
3218
3219 /* Interworking */
3220 if (dut->ap_interworking) {
3221 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3222 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3223 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3224 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3225 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3226 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3227 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3228 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3229 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3230 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3231
3232 if (dut->ap_gas_cb_delay > 0) {
3233 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3234 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3235 }
3236
3237 if (dut->ap_roaming_cons[0]) {
3238 char *rcons, *temp_ptr;
3239
3240 rcons = strdup(dut->ap_roaming_cons);
3241 if (rcons == NULL)
3242 return 0;
3243
3244 temp_ptr = strchr(rcons, ';');
3245
3246 if (temp_ptr)
3247 *temp_ptr++ = '\0';
3248
3249 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3250 rcons);
3251
3252 if (temp_ptr)
3253 owrt_ap_set_list_vap(dut, vap_id,
3254 "roaming_consortium",
3255 temp_ptr);
3256
3257 free(rcons);
3258 }
3259 }
3260
3261 if (dut->ap_venue_name) {
3262 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3263 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3264 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3265 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3266 }
3267
3268 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003269 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3270 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003271 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003272 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003273 }
3274
3275 if (dut->ap_nai_realm_list == 1) {
3276 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3277 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3278 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3279 "'0,wi-fi.org;example.com,13[5:6]'");
3280
3281 } else if (dut->ap_nai_realm_list == 2) {
3282 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3283 "'0,wi-fi.org,21[2:4][5:7]'");
3284 } else if (dut->ap_nai_realm_list == 3) {
3285 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3286 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3287 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3288 "'0,wi-fi.org;example.com,13[5:6]'");
3289 } else if (dut->ap_nai_realm_list == 4) {
3290 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3291 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3292 } else if (dut->ap_nai_realm_list == 5) {
3293 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3294 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3295 } else if (dut->ap_nai_realm_list == 6) {
3296 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3297 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3298 } else if (dut->ap_nai_realm_list == 7) {
3299 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3300 "'0,wi-fi.org,13[5:6]'");
3301 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3302 "'0,wi-fi.org,21[2:4][5:7]'");
3303 }
3304
3305 if (dut->ap_domain_name_list[0])
3306 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3307 dut->ap_domain_name_list);
3308
3309 if (dut->ap_ip_addr_type_avail)
3310 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3311 "'0c'");
3312
3313 temp = buf;
3314
3315 *temp++ = '\'';
3316
3317 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3318 if (i)
3319 *temp++ = ';';
3320
3321 snprintf(temp,
3322 sizeof(dut->ap_plmn_mcc[i]) +
3323 sizeof(dut->ap_plmn_mnc[i]) + 1,
3324 "%s,%s",
3325 dut->ap_plmn_mcc[i],
3326 dut->ap_plmn_mnc[i]);
3327
3328 temp += strlen(dut->ap_plmn_mcc[i]) +
3329 strlen(dut->ap_plmn_mnc[i]) + 1;
3330 }
3331
3332 *temp++ = '\'';
3333 *temp++ = '\0';
3334
3335 if (i)
3336 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3337
3338 if (dut->ap_qos_map_set == 1)
3339 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3340 else if (dut->ap_qos_map_set == 2)
3341 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3342
3343 /* Proxy-ARP */
3344 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3345 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3346
3347 /* DGAF */
3348 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3349 /* parse to hostapd */
3350 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3351 /* parse to wifi driver */
3352 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3353
3354 /* HCBSSLoad */
3355 if (dut->ap_bss_load) {
3356 unsigned int bssload = 0;
3357
3358 if (dut->ap_bss_load == 1) {
3359 /* STA count: 1, CU: 50, AAC: 65535 */
3360 bssload = 0x0132ffff;
3361 } else if (dut->ap_bss_load == 2) {
3362 /* STA count: 1, CU: 200, AAC: 65535 */
3363 bssload = 0x01c8ffff;
3364 } else if (dut->ap_bss_load == 3) {
3365 /* STA count: 1, CU: 75, AAC: 65535 */
3366 bssload = 0x014bffff;
3367 }
3368
3369 snprintf(buf, sizeof(buf), "%d", bssload);
3370 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3371 }
3372
3373 /* L2TIF */
3374 if (dut->ap_l2tif)
3375 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3376
3377 if (dut->ap_disable_protection == 1)
3378 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3379
Sunil Dutt77b213d2017-09-14 18:24:40 +03003380 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003381 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3382 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
3383 }
3384
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05303385 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003386 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003387
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303388 if (dut->ap_tx_stbc) {
3389 /* STBC and beamforming are mutually exclusive features */
3390 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3391 }
3392
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303393 /* enable dfsmode */
3394 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3395 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3396
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003397 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3398 char anqpval[1024];
3399
3400 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3401
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003402 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303403 snprintf(anqpval, sizeof(anqpval),
3404 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003405 dut->ap_val_lci, dut->ap_infoz);
3406 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3407 }
3408
3409 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303410 snprintf(anqpval, sizeof(anqpval),
3411 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003412 dut->ap_val_lcr);
3413 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3414 }
3415
3416 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
3417 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3418 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
3419 }
3420
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003421 if (dut->program == PROGRAM_MBO) {
3422 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3423 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3424 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07003425 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003426
3427 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3428 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07003429 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3430 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003431 }
3432
Jouni Malinen6be21c82018-08-01 18:47:24 +03003433 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003434 unsigned char self_mac[ETH_ALEN];
3435 char mac_str[20];
3436
3437 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
3438 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
3439 get_hwaddr(sigma_radio_ifname[0], self_mac);
3440 snprintf(mac_str, sizeof(mac_str),
3441 "%02x:%02x:%02x:%02x:%02x:%02x",
3442 self_mac[0], self_mac[1], self_mac[2],
3443 self_mac[3], self_mac[4], self_mac[5]);
3444 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003445 snprintf(mac_str, sizeof(mac_str),
3446 "%02x:%02x:%02x:%02x:%02x:%02x",
3447 self_mac[0], self_mac[1], self_mac[2],
3448 self_mac[3], self_mac[4], self_mac[5]);
3449 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003450 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
3451 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
3452 "000102030405060708090a0b0c0d0e0f");
3453 snprintf(mac_str, sizeof(mac_str),
3454 "%02x:%02x:%02x:%02x:%02x:%02x",
3455 dut->ft_bss_mac_list[0][0],
3456 dut->ft_bss_mac_list[0][1],
3457 dut->ft_bss_mac_list[0][2],
3458 dut->ft_bss_mac_list[0][3],
3459 dut->ft_bss_mac_list[0][4],
3460 dut->ft_bss_mac_list[0][5]);
3461 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003462 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
3463 dut->ap_mobility_domain);
3464 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003465 }
3466
Jouni Malinen6be21c82018-08-01 18:47:24 +03003467 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
3468 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003469 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
3470 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003471 }
3472
Jouni Malinen6be21c82018-08-01 18:47:24 +03003473 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003474 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
3475 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003476 }
3477
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003478 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
3479 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
3480
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003481 /* Enable/disable PMKSA caching, if asked to */
3482 if (dut->ap_pmksa == 1) {
3483 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
3484 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
3485 }
3486
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003487 if (dut->rsne_override) {
3488 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
3489 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
3490 }
3491
3492 if (dut->sae_commit_override) {
3493 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
3494 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
3495 }
3496
3497 if (dut->ap_sae_groups) {
3498 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003499 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003500 }
3501
3502 if (dut->sae_anti_clogging_threshold >= 0) {
3503 snprintf(buf, sizeof(buf), "%d",
3504 dut->sae_anti_clogging_threshold);
3505 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
3506 buf);
3507 }
3508
3509 if (dut->sae_reflection)
3510 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
3511
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003512 return 1;
3513}
3514
3515
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003516static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
3517{
3518 char anqpval[1024];
3519 unsigned char addr[6];
3520 unsigned char addr2[6];
3521 struct ifreq ifr;
3522 char *ifname;
3523 int s;
3524 int vap_id = 0;
3525
3526 s = socket(AF_INET, SOCK_DGRAM, 0);
3527 if (s < 0) {
3528 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
3529 return -1;
3530 }
3531
3532 memset(&ifr, 0, sizeof(ifr));
3533 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003534 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003535 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3536 perror("ioctl");
3537 close(s);
3538 return -1;
3539 }
3540 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
3541
3542 memset(&ifr, 0, sizeof(ifr));
3543 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003544 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003545 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3546 perror("ioctl");
3547 close(s);
3548 return -1;
3549 }
3550 close(s);
3551 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
3552
3553 snprintf(anqpval, sizeof(anqpval),
3554 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
3555 dut->ap_val_lci, dut->ap_infoz,
3556 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
3557 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
3558
3559 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3560 return 0;
3561}
3562
3563
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003564static int owrt_ap_post_config_commit(struct sigma_dut *dut,
3565 struct sigma_conn *conn,
3566 struct sigma_cmd *cmd)
3567{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003568 int ap_security = 0;
3569 int i;
3570
3571 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
3572 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
3573 ap_security = 1;
3574 }
3575 if (dut->ap_key_mgmt != AP_OPEN)
3576 ap_security = 1;
3577 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003578 /* allow some time for hostapd to start before returning
3579 * success */
3580 usleep(500000);
3581
3582 if (run_hostapd_cli(dut, "ping") != 0) {
3583 send_resp(dut, conn, SIGMA_ERROR,
3584 "errorCode,Failed to talk to hostapd");
3585 return 0;
3586 }
3587 }
3588
3589 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
3590 ath_ap_set_params(dut);
3591
3592 /* Send response */
3593 return 1;
3594}
3595
3596
3597static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
3598 struct sigma_conn *conn,
3599 struct sigma_cmd *cmd)
3600{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08003601 if (dut->program == PROGRAM_DPP &&
3602 get_driver_type() == DRIVER_OPENWRT) {
3603 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
3604 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
3605 }
3606
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003607 /* Stop the AP */
3608 run_system(dut, "wifi down");
3609
3610 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05303611 run_system(dut, "rm -rf /etc/config/wireless");
3612 switch (get_openwrt_driver_type()) {
3613 case OPENWRT_DRIVER_ATHEROS:
3614 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
3615 break;
3616 default:
3617 run_system(dut, "wifi detect > /etc/config/wireless");
3618 break;
3619 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620
3621 /* Configure Radio & VAP, commit the config */
3622 owrt_ap_config_radio(dut);
3623 owrt_ap_config_vap(dut);
3624 run_system(dut, "uci commit");
3625
3626 /* Start AP */
3627 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003628 if (dut->program != PROGRAM_MBO &&
3629 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003630 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003631 /*
3632 * MBO has a different ANQP element value which is set in
3633 * owrt_ap_config_vap().
3634 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003635 owrt_ap_config_vap_anqp(dut);
3636 run_system(dut, "uci commit");
3637 run_system(dut, "wifi");
3638 }
3639
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003640 return owrt_ap_post_config_commit(dut, conn, cmd);
3641}
3642
3643
3644static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
3645{
3646 unsigned char bssid[6];
3647 char buf[100];
3648 char *ifname, *radio_name;
3649 int vap_id = 0;
3650
3651 if (sigma_radio_ifname[0] &&
3652 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3653 ifname = "ath2";
3654 radio_name = "wifi2";
3655 vap_id = 2;
3656 } else if (sigma_radio_ifname[0] &&
3657 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3658 ifname = "ath1";
3659 radio_name = "wifi1";
3660 vap_id = 1;
3661 } else {
3662 ifname = "ath0";
3663 radio_name = "wifi0";
3664 vap_id = 0;
3665 }
3666
3667 if (!get_hwaddr(ifname, bssid)) {
3668 snprintf(buf, sizeof(buf), "%s", bssid);
3669 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3670 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3671 "%02x:%02x:%02x:%02x:%02x:%02x",
3672 bssid[0], bssid[1], bssid[2], bssid[3],
3673 bssid[4], bssid[5]);
3674 } else {
3675 if (!get_hwaddr(radio_name, bssid)) {
3676 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3677 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3678 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3679 "%02x:%02x:%02x:%02x:%02x:%02x",
3680 bssid[0], bssid[1], bssid[2], bssid[3],
3681 bssid[4], bssid[5]);
3682 } else {
3683 /* Select & enable/disable radios */
3684 if (sigma_radio_ifname[0] &&
3685 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3686 /* We want to use wifi2 */
3687 owrt_ap_set_radio(dut, 0, "disabled", "1");
3688 owrt_ap_set_radio(dut, 1, "disabled", "1");
3689 owrt_ap_set_radio(dut, 2, "disabled", "0");
3690 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
3691 } else if (sigma_radio_ifname[0] &&
3692 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3693 /* We want to use wifi1 */
3694 owrt_ap_set_radio(dut, 0, "disabled", "1");
3695 owrt_ap_set_radio(dut, 1, "disabled", "0");
3696 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
3697 } else {
3698 /* We want to use wifi0 */
3699 owrt_ap_set_radio(dut, 0, "disabled", "0");
3700 owrt_ap_set_radio(dut, 1, "disabled", "1");
3701 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
3702 }
3703
3704 run_system(dut, "uci commit");
3705 run_system(dut, "wifi up");
3706
3707 if (!get_hwaddr(radio_name, bssid)) {
3708 snprintf(buf, sizeof(buf), "%s",
3709 dut->ap_hessid);
3710 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3711 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3712 "%02x:%02x:%02x:%02x:%02x:%02x",
3713 bssid[0], bssid[1], bssid[2], bssid[3],
3714 bssid[4], bssid[5]);
3715 }
3716 }
3717 }
3718}
3719
3720
3721static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
3722 struct sigma_cmd *cmd)
3723{
3724 switch (get_driver_type()) {
3725 case DRIVER_ATHEROS:
3726 run_system(dut, "apdown");
3727 sleep(1);
3728 run_system(dut, "reboot");
3729 break;
3730 case DRIVER_OPENWRT:
3731 run_system(dut, "wifi down");
3732 sleep(1);
3733 run_system(dut, "reboot");
3734 break;
3735 default:
3736 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
3737 break;
3738 }
3739
3740 return 1;
3741}
3742
3743
3744int ascii2hexstr(const char *str, char *hex)
3745{
3746 int i, length;
3747
3748 length = strlen(str);
3749
3750 for (i = 0; i < length; i++)
3751 snprintf(hex + i * 2, 3, "%X", str[i]);
3752
3753 hex[length * 2] = '\0';
3754 return 1;
3755}
3756
3757
3758static int kill_process(struct sigma_dut *dut, char *proc_name,
3759 unsigned char is_proc_instance_one, int sig)
3760{
3761#ifdef __linux__
3762 struct dirent *dp, *dp_in;
3763 const char *direc = "/proc/";
3764 char buf[100];
3765 DIR *dir = opendir(direc);
3766 DIR *dir_in;
3767 FILE *fp;
3768 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303769 char *saveptr;
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303770 int ret = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003771
3772 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303773 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003774
3775 while ((dp = readdir(dir)) != NULL) {
3776 if (dp->d_type != DT_DIR)
3777 continue;
3778
3779 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
3780 dir_in = opendir(buf);
3781 if (dir_in == NULL)
3782 continue;
3783 dp_in = readdir(dir_in);
3784 closedir(dir_in);
3785 if (dp_in == NULL)
3786 continue;
3787 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
3788 fp = fopen(buf, "r");
3789 if (fp == NULL)
3790 continue;
3791 if (fgets(buf, 100, fp) == NULL)
3792 buf[0] = '\0';
3793 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303794 pid = strtok_r(buf, " ", &saveptr);
3795 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003796 if (pid && temp &&
3797 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
3798 sigma_dut_print(dut, DUT_MSG_INFO,
3799 "killing %s process with PID %s",
3800 proc_name, pid);
3801 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
3802 atoi(pid));
3803 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303804 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003805 if (is_proc_instance_one)
3806 break;
3807 }
3808 }
3809
3810 closedir(dir);
3811
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303812 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003813#else /* __linux__ */
3814 return -1;
3815#endif /* __linux__ */
3816}
3817
3818
3819static int run_ndc(struct sigma_dut *dut, char *buf)
3820{
3821 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
3822 sleep(2);
3823 return run_system(dut, buf);
3824}
3825
3826
3827static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
3828 const char *field, const char *value)
3829{
3830 FILE *fcfg, *ftmp;
3831 char buf[MAX_CONF_LINE_LEN + 1];
3832 int len, found = 0, res;
3833
3834 /* Open the configuration file */
3835 fcfg = fopen(pfile, "r");
3836 if (!fcfg) {
3837 sigma_dut_print(dut, DUT_MSG_ERROR,
3838 "Failed to open hostapd conf file");
3839 return -1;
3840 }
3841
3842 snprintf(buf, sizeof(buf), "%s~", pfile);
3843 /* Open a temporary file */
3844 ftmp = fopen(buf, "w+");
3845 if (!ftmp) {
3846 fclose(fcfg);
3847 sigma_dut_print(dut, DUT_MSG_ERROR,
3848 "Failed to open temp buf");
3849 return -1;
3850 }
3851
3852 /* Read the values from the configuration file */
3853 len = strlen(field);
3854 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
3855 char *pline = buf;
3856
3857 /* commented line */
3858 if (buf[0] == '#')
3859 pline++;
3860
3861 /* Identify the configuration parameter to be updated */
3862 if (!found && strncmp(pline, field, len) == 0 &&
3863 pline[len] == '=') {
3864 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
3865 found = 1;
3866 sigma_dut_print(dut, DUT_MSG_INFO,
3867 "Updated hostapd conf file");
3868 }
3869
3870 fprintf(ftmp, "%s", buf);
3871 }
3872
3873 if (!found) {
3874 /* Configuration line not found */
3875 /* Add the new line at the end of file */
3876 fprintf(ftmp, "%s=%s\n", field, value);
3877 sigma_dut_print(dut, DUT_MSG_INFO,
3878 "Adding a new line in hostapd conf file");
3879 }
3880
3881 fclose(fcfg);
3882 fclose(ftmp);
3883
3884 snprintf(buf, sizeof(buf), "%s~", pfile);
3885
3886 /* Restore the updated configuration file */
3887 res = rename(buf, pfile);
3888
3889 /* Remove the temporary file. Ignore the return value */
3890 unlink(buf);
3891
3892 /* chmod is needed because open() may not set permissions properly
3893 * depending on the current umask */
3894 if (chmod(pfile, 0660) < 0) {
3895 unlink(pfile);
3896 sigma_dut_print(dut, DUT_MSG_ERROR,
3897 "Error changing permissions");
3898 return -1;
3899 }
3900
3901 if (res < 0) {
3902 sigma_dut_print(dut, DUT_MSG_ERROR,
3903 "Error restoring conf file");
3904 return -1;
3905 }
3906
3907 return 0;
3908}
3909
3910
3911static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
3912 struct sigma_conn *conn,
3913 struct sigma_cmd *cmd)
3914{
3915 char buf[100];
3916 struct stat s;
3917 int num_tries = 0, ret;
3918
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303919 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
3920 system("killall netd") == 0) {
3921 /* Avoid Error: Error connecting (Connection refused)
3922 * Wait some time to allow netd to reinitialize.
3923 */
3924 usleep(1500000);
3925 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003926
3927 while (num_tries < 10) {
3928 ret = run_ndc(dut, "ndc softap stopap");
3929 num_tries++;
3930 if (WIFEXITED(ret))
3931 ret = WEXITSTATUS(ret);
3932 /* On success, NDC exits with 0 */
3933 if (ret == 0)
3934 break;
3935 sigma_dut_print(dut, DUT_MSG_INFO,
3936 "Try No. %d: ndc softap stopap failed, exit code %d",
3937 num_tries, ret);
3938 }
3939
3940 if (ret != 0)
3941 sigma_dut_print(dut, DUT_MSG_ERROR,
3942 "ndc softap stopap command failed for 10 times - giving up");
3943
3944#ifdef ANDROID
3945 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05303946 system("rmmod -f wlan");
3947 usleep(500000);
3948 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003949#else /* ANDROID */
3950 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
3951 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
3952#endif /* ANDROID */
3953
3954 switch (dut->ap_mode) {
3955 case AP_11g:
3956 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
3957 break;
3958 case AP_11b:
3959 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
3960 break;
3961 case AP_11ng:
3962 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3963 break;
3964 case AP_11a:
3965 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
3966 break;
3967 case AP_11na:
3968 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3969 break;
3970 case AP_11ac:
3971 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
3972 break;
3973 default:
3974 break;
3975 }
3976
3977 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
3978 dut->ap_channel);
3979 run_ndc(dut, buf);
3980
3981 /*
3982 * ndc doesn't support double quotes as SSID string, so re-write
3983 * hostapd configuration file to update SSID.
3984 */
3985 if (dut->ap_ssid[0] != '\0')
3986 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
3987
3988 switch (dut->ap_key_mgmt) {
3989 case AP_OPEN:
3990 if (dut->ap_cipher == AP_WEP) {
3991 run_ndc(dut, "ndc softap qccmd set security_mode=1");
3992 snprintf(buf, sizeof(buf),
3993 "ndc softap qccmd set wep_key0=%s",
3994 dut->ap_wepkey);
3995 run_ndc(dut, buf);
3996 } else {
3997 run_ndc(dut, "ndc softap qccmd set security_mode=0");
3998 }
3999 break;
4000 case AP_WPA2_PSK:
4001 case AP_WPA2_PSK_MIXED:
4002 case AP_WPA_PSK:
4003 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4004 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4005 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4006 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4007 else
4008 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4009
4010 /*
4011 * ndc doesn't support some special characters as passphrase,
4012 * so re-write hostapd configuration file to update Passphrase.
4013 */
4014 if (dut->ap_passphrase[0] != '\0')
4015 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4016 "wpa_passphrase", dut->ap_passphrase);
4017
4018 if (dut->ap_cipher == AP_CCMP_TKIP)
4019 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4020 "TKIP CCMP");
4021 else if (dut->ap_cipher == AP_TKIP)
4022 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4023 "TKIP");
4024 else
4025 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4026 "CCMP &");
4027 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004028 case AP_WPA2_SAE:
4029 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004030 case AP_WPA2_EAP:
4031 case AP_WPA2_EAP_MIXED:
4032 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004033 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004034 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004035 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004036 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004037 case AP_WPA2_FT_EAP:
4038 case AP_WPA2_FT_PSK:
4039 case AP_WPA2_EAP_SHA256:
4040 case AP_WPA2_PSK_SHA256:
4041 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004042 /* Not supported */
4043 break;
4044 }
4045
4046 switch (dut->ap_pmf) {
4047 case AP_PMF_DISABLED:
4048 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4049 break;
4050 case AP_PMF_OPTIONAL:
4051 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4052 if (dut->ap_add_sha256)
4053 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4054 else
4055 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4056 break;
4057 case AP_PMF_REQUIRED:
4058 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4059 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4060 break;
4061 }
4062
4063 if (dut->ap_countrycode[0]) {
4064 snprintf(buf, sizeof(buf),
4065 "ndc softap qccmd set country_code=%s",
4066 dut->ap_countrycode);
4067 run_ndc(dut, buf);
4068 }
4069
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304070 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4071 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4072
4073 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4074 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4075
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004076 run_ndc(dut, "ndc softap startap");
4077
4078 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
4079 num_tries = 0;
4080 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4081 run_ndc(dut, "ndc softap stopap");
4082 run_ndc(dut, "ndc softap startap");
4083 num_tries++;
4084 }
4085
4086 if (num_tries == 10) {
4087 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4088 "iface %s :: reboot the APDUT", buf);
4089 return ret;
4090 }
4091
4092 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4093 ap_inet_addr, ap_inet_mask);
4094 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
4095 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
4096 if (system(buf) != 0) {
4097 sigma_dut_print(dut, DUT_MSG_ERROR,
4098 "Failed to intialize the interface");
4099 return -1;
4100 }
4101
4102 return 1;
4103}
4104
4105
4106static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4107{
4108 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4109 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4110
4111 if (dut->ap_oper_name) {
4112 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4113 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4114 }
4115
4116 if (dut->ap_wan_metrics == 1)
4117 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4118 else if (dut->ap_wan_metrics == 2)
4119 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4120 else if (dut->ap_wan_metrics == 3)
4121 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4122 else if (dut->ap_wan_metrics == 4)
4123 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4124 else if (dut->ap_wan_metrics == 5)
4125 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4126
4127 if (dut->ap_conn_capab == 1) {
4128 fprintf(f, "hs20_conn_capab=1:0:0\n");
4129 fprintf(f, "hs20_conn_capab=6:20:1\n");
4130 fprintf(f, "hs20_conn_capab=6:22:0\n");
4131 fprintf(f, "hs20_conn_capab=6:80:1\n");
4132 fprintf(f, "hs20_conn_capab=6:443:1\n");
4133 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4134 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4135 fprintf(f, "hs20_conn_capab=17:500:1\n");
4136 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4137 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4138 fprintf(f, "hs20_conn_capab=50:0:1\n");
4139 } else if (dut->ap_conn_capab == 2) {
4140 fprintf(f, "hs20_conn_capab=6:80:1\n");
4141 fprintf(f, "hs20_conn_capab=6:443:1\n");
4142 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4143 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4144 } else if (dut->ap_conn_capab == 3) {
4145 fprintf(f, "hs20_conn_capab=6:80:1\n");
4146 fprintf(f, "hs20_conn_capab=6:443:1\n");
4147 } else if (dut->ap_conn_capab == 4) {
4148 fprintf(f, "hs20_conn_capab=6:80:1\n");
4149 fprintf(f, "hs20_conn_capab=6:443:1\n");
4150 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4151 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4152 }
4153
4154 if (dut->ap_oper_class == 1)
4155 fprintf(f, "hs20_operating_class=51\n");
4156 else if (dut->ap_oper_class == 2)
4157 fprintf(f, "hs20_operating_class=73\n");
4158 else if (dut->ap_oper_class == 3)
4159 fprintf(f, "hs20_operating_class=5173\n");
4160
4161 if (dut->ap_osu_provider_list) {
4162 char *osu_friendly_name = NULL;
4163 char *osu_icon = NULL;
4164 char *osu_ssid = NULL;
4165 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004166 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004167 char *osu_service_desc = NULL;
4168 char *hs20_icon_filename = NULL;
4169 char hs20_icon[150];
4170 int osu_method;
4171
4172 hs20_icon_filename = "icon_red_zxx.png";
4173 if (dut->ap_osu_icon_tag == 2)
4174 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4175 snprintf(hs20_icon, sizeof(hs20_icon),
4176 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4177 hs20_icon_filename);
4178 osu_icon = "icon_red_zxx.png";
4179 osu_ssid = "OSU";
4180 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4181 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4182 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4183
4184 if (strlen(dut->ap_osu_server_uri[0]))
4185 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4186 else
4187 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4188
4189 switch (dut->ap_osu_provider_list) {
4190 case 1:
4191 case 101:
4192 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4193 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4194 hs20_icon_filename = "icon_red_eng.png";
4195 if (dut->ap_osu_icon_tag == 2)
4196 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4197 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4198 hs20_icon_filename);
4199 fprintf(f, "osu_icon=icon_red_eng.png\n");
4200 break;
4201 case 2:
4202 case 102:
4203 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4204 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4205 hs20_icon_filename = "icon_orange_zxx.png";
4206 if (dut->ap_osu_icon_tag == 2)
4207 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4208 snprintf(hs20_icon, sizeof(hs20_icon),
4209 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4210 hs20_icon_filename);
4211 osu_icon = "icon_orange_zxx.png";
4212 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4213 break;
4214 case 3:
4215 case 103:
4216 osu_friendly_name = "spa:SP Red Test Only";
4217 osu_service_desc = "spa:Free service for test purpose";
4218 break;
4219 case 4:
4220 case 104:
4221 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4222 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4223 hs20_icon_filename = "icon_orange_eng.png";
4224 if (dut->ap_osu_icon_tag == 2)
4225 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4226 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4227 hs20_icon_filename);
4228 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4229 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4230
4231 hs20_icon_filename = "icon_orange_zxx.png";
4232 if (dut->ap_osu_icon_tag == 2)
4233 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4234 snprintf(hs20_icon, sizeof(hs20_icon),
4235 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4236 hs20_icon_filename);
4237 osu_icon = "icon_orange_zxx.png";
4238 break;
4239 case 5:
4240 case 105:
4241 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4242 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4243 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4244 hs20_icon_filename = "icon_orange_zxx.png";
4245 if (dut->ap_osu_icon_tag == 2)
4246 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4247 snprintf(hs20_icon, sizeof(hs20_icon),
4248 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4249 hs20_icon_filename);
4250 osu_icon = "icon_orange_zxx.png";
4251 break;
4252 case 6:
4253 case 106:
4254 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4255 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4256 hs20_icon_filename = "icon_green_zxx.png";
4257 if (dut->ap_osu_icon_tag == 2)
4258 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4259 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4260 hs20_icon_filename);
4261 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4262 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4263 fprintf(f, "osu_method_list=%d\n", osu_method);
4264
4265 if (strlen(dut->ap_osu_server_uri[1]))
4266 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4267 else
4268 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4269 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4270 hs20_icon_filename = "icon_orange_zxx.png";
4271 if (dut->ap_osu_icon_tag == 2)
4272 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4273 snprintf(hs20_icon, sizeof(hs20_icon),
4274 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4275 hs20_icon_filename);
4276 osu_icon = "icon_orange_zxx.png";
4277 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4278 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4279 osu_service_desc = NULL;
4280 break;
4281 case 7:
4282 case 107:
4283 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4284 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4285 hs20_icon_filename = "icon_green_eng.png";
4286 if (dut->ap_osu_icon_tag == 2)
4287 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4288 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4289 hs20_icon_filename);
4290 fprintf(f, "osu_icon=icon_green_eng.png\n");
4291 osu_friendly_name = "kor:SP 초록 테스트 전용";
4292
4293 hs20_icon_filename = "icon_green_zxx.png";
4294 if (dut->ap_osu_icon_tag == 2)
4295 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4296 snprintf(hs20_icon, sizeof(hs20_icon),
4297 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4298 hs20_icon_filename);
4299 osu_icon = "icon_green_zxx.png";
4300 break;
4301 case 8:
4302 case 108:
4303 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4304 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4305 osu_ssid = "OSU-Encrypted";
4306 osu_nai = "anonymous@hotspot.net";
4307 break;
4308 case 9:
4309 case 109:
4310 osu_ssid = "OSU-OSEN";
4311 osu_nai = "test-anonymous@wi-fi.org";
4312 osu_friendly_name = "eng:SP Orange Test Only";
4313 hs20_icon_filename = "icon_orange_zxx.png";
4314 if (dut->ap_osu_icon_tag == 2)
4315 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4316 snprintf(hs20_icon, sizeof(hs20_icon),
4317 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4318 hs20_icon_filename);
4319 osu_icon = "icon_orange_zxx.png";
4320 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4321 osu_service_desc = NULL;
4322 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004323 case 10:
4324 case 110:
4325 /* OSU Provider #1 */
4326 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4327 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
4328 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
4329 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
4330 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
4331 1 : dut->ap_osu_method[0];
4332 fprintf(f, "osu_method_list=%d\n", osu_method);
4333 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
4334 switch (dut->ap_osu_provider_nai_list) {
4335 case 3:
4336 fprintf(f,
4337 "osu_nai2=test-anonymous@wi-fi.org\n");
4338 break;
4339 case 4:
4340 fprintf(f, "osu_nai2=random@hotspot.net\n");
4341 break;
4342 }
4343
4344 /* OSU Provider #2 */
4345 /* SP Red from defaults */
4346 if (strlen(dut->ap_osu_server_uri[1]))
4347 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4348 else
4349 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4350 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4351 snprintf(hs20_icon, sizeof(hs20_icon),
4352 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
4353 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
4354 1 : dut->ap_osu_method[1];
4355 osu_service_desc = NULL;
4356 osu_nai = "anonymous@hotspot.net";
4357 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004358 default:
4359 break;
4360 }
4361
Jouni Malinen93a837f2018-11-01 17:09:22 +02004362 switch (dut->ap_osu_provider_nai_list) {
4363 case 1:
4364 osu_nai2 = "anonymous@hotspot.net";
4365 break;
4366 case 2:
4367 osu_nai2 = "test-anonymous@wi-fi.org";
4368 break;
4369 case 3:
4370 /* OSU Provider NAI #1 written above */
4371 /* OSU Provider NAI #2 */
4372 osu_nai2 = "anonymous@hotspot.net";
4373 break;
4374 case 4:
4375 /* OSU Provider NAI #1 written above */
4376 /* OSU Provider NAI #2 */
4377 osu_nai2 = "anonymous@hotspot.net";
4378 break;
4379 }
4380
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004381 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03004382 if (dut->ap_tag_ssid[0][0] &&
4383 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004384 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004385 sigma_dut_print(dut, DUT_MSG_ERROR,
4386 "OSU_SSID and "
4387 "WLAN_TAG2 SSID differ");
4388 return -2;
4389 }
4390 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
4391 } else
4392 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
4393
4394
4395 if (osu_friendly_name)
4396 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
4397
4398 if (osu_service_desc)
4399 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
4400
4401 if (osu_nai)
4402 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02004403 if (osu_nai2)
4404 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405
4406 fprintf(f, "hs20_icon=%s\n", hs20_icon);
4407
4408 if (osu_icon)
4409 fprintf(f, "osu_icon=%s\n", osu_icon);
4410
4411 if (dut->ap_osu_provider_list > 100)
4412 fprintf(f, "osu_method_list=0\n");
4413 else
4414 fprintf(f, "osu_method_list=%d\n", osu_method);
4415 }
4416
Jouni Malinen54a89b02018-05-01 00:16:26 +03004417 switch (dut->ap_venue_url) {
4418 case 1:
4419 fprintf(f,
4420 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4421 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
4422 break;
4423 case 2:
4424 fprintf(f,
4425 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4426 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4427 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4428 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4429 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4430 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4431 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4432 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4433 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4434 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4435 );
4436 break;
4437 }
4438
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03004439 switch (dut->ap_advice_of_charge) {
4440 case 1:
4441 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
4442 break;
4443 }
4444
Jouni Malinenac104532018-05-01 00:27:37 +03004445 switch (dut->ap_oper_icon_metadata) {
4446 case 1:
4447 fprintf(f,
4448 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
4449 "operator_icon=icon_red_eng.png\n");
4450 break;
4451 }
4452
Jouni Malinenac367142018-05-01 00:32:24 +03004453 switch (dut->ap_tnc_file_name) {
4454 case 1:
4455 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
4456 break;
4457 }
4458
4459 if (dut->ap_tnc_time_stamp)
4460 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
4461
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004462 return 0;
4463}
4464
4465
4466static void write_ap_roaming_cons(FILE *f, const char *list)
4467{
4468 char *buf, *pos, *end;
4469
4470 if (list == NULL || list[0] == '\0')
4471 return;
4472
4473 buf = strdup(list);
4474 if (buf == NULL)
4475 return;
4476
4477 pos = buf;
4478 while (pos && *pos) {
4479 end = strchr(pos, ';');
4480 if (end)
4481 *end++ = '\0';
4482 fprintf(f, "roaming_consortium=%s\n", pos);
4483 pos = end;
4484 }
4485
4486 free(buf);
4487}
4488
4489
4490static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
4491{
4492 int i;
4493 char buf[100], *temp;
4494
4495 if (dut->ap_gas_cb_delay > 0)
4496 fprintf(f, "gas_comeback_delay=%d\n",
4497 dut->ap_gas_cb_delay);
4498
4499 fprintf(f, "interworking=1\n"
4500 "access_network_type=%d\n"
4501 "internet=%d\n"
4502 "asra=0\n"
4503 "esr=0\n"
4504 "uesa=0\n"
4505 "venue_group=%d\n"
4506 "venue_type=%d\n",
4507 dut->ap_access_net_type,
4508 dut->ap_internet,
4509 dut->ap_venue_group,
4510 dut->ap_venue_type);
4511 if (dut->ap_hessid[0])
4512 fprintf(f, "hessid=%s\n", dut->ap_hessid);
4513
4514 write_ap_roaming_cons(f, dut->ap_roaming_cons);
4515
4516 if (dut->ap_venue_name) {
4517 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
4518 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
4519 }
4520
4521 if (dut->ap_net_auth_type == 1)
4522 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
4523 else if (dut->ap_net_auth_type == 2)
4524 fprintf(f, "network_auth_type=01\n");
4525
4526 if (dut->ap_nai_realm_list == 1) {
4527 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
4528 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4529 } else if (dut->ap_nai_realm_list == 2) {
4530 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4531 } else if (dut->ap_nai_realm_list == 3) {
4532 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
4533 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4534 } else if (dut->ap_nai_realm_list == 4) {
4535 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
4536 } else if (dut->ap_nai_realm_list == 5) {
4537 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
4538 } else if (dut->ap_nai_realm_list == 6) {
4539 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
4540 } else if (dut->ap_nai_realm_list == 7) {
4541 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
4542 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4543 }
4544
4545 if (dut->ap_domain_name_list[0]) {
4546 fprintf(f, "domain_name=%s\n",
4547 dut->ap_domain_name_list);
4548 }
4549
4550 if (dut->ap_ip_addr_type_avail == 1) {
4551 fprintf(f, "ipaddr_type_availability=0c\n");
4552 }
4553
4554 temp = buf;
4555 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
4556 i++) {
4557 if (i)
4558 *temp++ = ';';
4559
4560 snprintf(temp,
4561 sizeof(dut->ap_plmn_mcc[i]) +
4562 sizeof(dut->ap_plmn_mnc[i]) + 1,
4563 "%s,%s",
4564 dut->ap_plmn_mcc[i],
4565 dut->ap_plmn_mnc[i]);
4566
4567 temp += strlen(dut->ap_plmn_mcc[i]) +
4568 strlen(dut->ap_plmn_mnc[i]) + 1;
4569 }
4570 if (i)
4571 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
4572
4573 if (dut->ap_qos_map_set == 1)
4574 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
4575 else if (dut->ap_qos_map_set == 2)
4576 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
4577
4578 return 0;
4579}
4580
4581
4582static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
4583{
4584 FILE *f;
4585
4586 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4587 system("killall hostapd") == 0) {
4588 int i;
4589
4590 /* Wait some time to allow hostapd to complete cleanup before
4591 * starting a new process */
4592 for (i = 0; i < 10; i++) {
4593 usleep(500000);
4594 if (system("pidof hostapd") != 0)
4595 break;
4596 }
4597 }
4598
4599 f = fopen("/tmp/secath0", "a");
4600 if (f == NULL)
4601 return -2;
4602
4603 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
4604 fclose(f);
4605 return -2;
4606 }
4607
4608 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4609 fclose(f);
4610 return -2;
4611 }
4612
4613 fflush(f);
4614 fclose(f);
4615 return ath_ap_start_hostapd(dut);
4616}
4617
4618
4619static int ath_ap_start_hostapd(struct sigma_dut *dut)
4620{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004621 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004622 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
4623 else
4624 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
4625
4626 return 0;
4627}
4628
4629
4630#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
4631
4632static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
4633{
4634 FILE *f;
4635 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
4636 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
4637 char buf[100];
4638 int i;
4639
4640 f = fopen("/root/anqpserver.conf", "w");
4641 if (f == NULL)
4642 return -1;
4643
4644 if (dut->ap_nai_realm_list == 1) {
4645 nai_realm = 1;
4646 fprintf(f, "dyn_nai_home_realm=encoding=00realm=mail.example.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=cisco.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=wi-fi.org;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=example.com;eap_method=0Dauth_id=05auth_val=06encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4647 } else if (dut->ap_nai_realm_list == 2) {
4648 nai_realm = 1;
4649 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4650 } else if (dut->ap_nai_realm_list == 3) {
4651 nai_realm = 1;
4652 fprintf(f, "dyn_nai_home_realm=encoding=00realm=cisco.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=wi-fi.org;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=example.com;eap_method=0Dauth_id=05auth_val=06encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4653 } else if (dut->ap_nai_realm_list == 4) {
4654 nai_realm = 1;
4655 fprintf(f, "dyn_nai_home_realm=encoding=00realm=mail.example.com;eap_method=15auth_id=02auth_val=04auth_id=05auth_val=07encoding=00realm=mail.example.com;eap_method=0Dauth_id=05auth_val=06\n");
4656 } else
4657 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
4658
4659 if (dut->ap_domain_name_list[0]) {
4660 char *next, *start, *dnbuf, *dn1, *anqp_dn;
4661 int len, dn_len_max;
4662 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304663 if (dnbuf == NULL) {
4664 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004665 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304666 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004667
4668 len = strlen(dnbuf);
4669 dn_len_max = 50 + len*2;
4670 anqp_dn = malloc(dn_len_max);
4671 if (anqp_dn == NULL) {
4672 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304673 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004674 return -1;
4675 }
4676 start = dnbuf;
4677 dn1 = anqp_dn;
4678 while (start && *start) {
4679 char *hexstr;
4680
4681 next = strchr(start, ',');
4682 if (next)
4683 *next++ = '\0';
4684
4685 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05304686 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004687 if (hexstr == NULL) {
4688 free(dnbuf);
4689 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304690 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004691 return -1;
4692 }
4693 ascii2hexstr(start, hexstr);
4694 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
4695 free(hexstr);
4696 dn1 += 2 + len * 2;
4697 dn_len_max -= 2 + len * 2;
4698 start = next;
4699 }
4700 free(dnbuf);
4701 if (dut->ap_gas_cb_delay) {
4702 fprintf(f, "dyn_domain_name=0c01%04x%s",
4703 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4704 domain_name = 1;
4705 } else
4706 fprintf(f, "domain_name=0c01%04x%s",
4707 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4708 free(anqp_dn);
4709 } else
4710 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
4711
4712 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
4713
4714 if (dut->ap_oper_name) {
4715 if (dut->ap_gas_cb_delay) {
4716 fprintf(f, "dyn_oper_friendly_name="
4717 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4718 oper_name = 1;
4719 } else
4720 fprintf(f, "oper_friendly_name="
4721 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4722 } else
4723 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
4724
4725 if (dut->ap_venue_name) {
4726 if (dut->ap_gas_cb_delay) {
4727 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
4728 venue_name = 1;
4729 } else
4730 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
4731 } else
4732 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
4733
4734 if (dut->ap_wan_metrics) {
4735 if (dut->ap_gas_cb_delay) {
4736 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
4737 wan_metrics = 1;
4738 } else
4739 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
4740 "\n");
4741 } else
4742 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
4743
4744 if (dut->ap_conn_capab) {
4745 if (dut->ap_gas_cb_delay) {
4746 fprintf(f, "dyn_conn_capability="
4747 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4748 conn_cap = 1;
4749 } else
4750 fprintf(f, "conn_capability="
4751 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4752 } else
4753 sigma_dut_print(dut, DUT_MSG_ERROR,
4754 "not setting conn_capability");
4755
4756 if (dut->ap_ip_addr_type_avail) {
4757 if (dut->ap_gas_cb_delay) {
4758 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
4759 "\n");
4760 ipaddr_avail = 1;
4761 } else
4762 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
4763 } else
4764 sigma_dut_print(dut, DUT_MSG_ERROR,
4765 "not setting ipaddr_type_avail");
4766
4767 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
4768 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
4769 dut->ap_plmn_mcc[i][1],
4770 dut->ap_plmn_mcc[i][0],
4771 dut->ap_plmn_mnc[i][2] == '\0' ?
4772 'f' : dut->ap_plmn_mnc[i][2],
4773 dut->ap_plmn_mcc[i][2],
4774 dut->ap_plmn_mnc[i][1],
4775 dut->ap_plmn_mnc[i][0]);
4776 }
4777 if (i) {
4778 uint16_t ie_len = (i * 3) + 5;
4779 if (dut->ap_gas_cb_delay) {
4780 fprintf(f, "dyn_cell_net=0801");
4781 cell_net = 1;
4782 } else
4783 fprintf(f, "cell_net=0801");
4784 fprintf(f, "%04x", LE16(ie_len));
4785 fprintf(f, "00"); /* version */
4786 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
4787 fprintf(f, "00"); /* plmn list */
4788 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
4789 fprintf(f, "%02x", i); /* number of plmns */
4790 fprintf(f, "%s\n", buf); /* plmns */
4791 } else
4792 sigma_dut_print(dut, DUT_MSG_ERROR,
4793 "not setting 3gpp_cellular_network");
4794
4795 if (nai_realm || domain_name || oper_name || venue_name ||
4796 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
4797 fprintf(f, "anqp_attach=");
4798 if (venue_name)
4799 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
4800 if (nai_realm)
4801 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
4802 if (cell_net)
4803 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
4804 if (domain_name)
4805 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
4806 if (oper_name)
4807 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
4808 if (wan_metrics)
4809 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
4810 if (conn_cap)
4811 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
4812 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
4813 fprintf(f, "\n");
4814 }
4815
4816 fclose(f);
4817
4818 run_system(dut, "anqpserver -i ath0 &");
4819 if (!dut->ap_anqpserver_on)
4820 run_system(dut, "killall anqpserver");
4821
4822 return 1;
4823}
4824
4825
4826static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
4827{
4828 char buf[100];
4829
4830 run_system(dut, "cfg -a AP_STARTMODE=standard");
4831
4832 if (sigma_radio_ifname[0] &&
4833 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4834 run_system(dut, "cfg -a AP_RADIO_ID=1");
4835 switch (dut->ap_mode) {
4836 case AP_11g:
4837 run_system(dut, "cfg -a AP_CHMODE_2=11G");
4838 break;
4839 case AP_11b:
4840 run_system(dut, "cfg -a AP_CHMODE_2=11B");
4841 break;
4842 case AP_11ng:
4843 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
4844 break;
4845 case AP_11a:
4846 run_system(dut, "cfg -a AP_CHMODE_2=11A");
4847 break;
4848 case AP_11na:
4849 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
4850 break;
4851 case AP_11ac:
4852 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4853 break;
4854 default:
4855 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4856 break;
4857 }
4858
4859 switch (dut->ap_rx_streams) {
4860 case 1:
4861 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
4862 break;
4863 case 2:
4864 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
4865 break;
4866 case 3:
4867 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
4868 break;
4869 }
4870
4871 switch (dut->ap_tx_streams) {
4872 case 1:
4873 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
4874 break;
4875 case 2:
4876 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
4877 break;
4878 case 3:
4879 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
4880 break;
4881 }
4882
4883 switch (dut->ap_chwidth) {
4884 case AP_20:
4885 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
4886 break;
4887 case AP_40:
4888 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
4889 break;
4890 case AP_80:
4891 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4892 break;
4893 case AP_160:
4894 case AP_AUTO:
4895 default:
4896 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4897 break;
4898 }
4899
4900 if (dut->ap_tx_stbc) {
4901 run_system(dut, "cfg -a TX_STBC_2=1");
4902 }
4903
4904 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
4905 dut->ap_channel);
4906
4907 if (dut->ap_is_dual) {
4908 switch (dut->ap_mode_1) {
4909 case AP_11g:
4910 run_system(dut, "cfg -a AP_CHMODE=11G");
4911 break;
4912 case AP_11b:
4913 run_system(dut, "cfg -a AP_CHMODE=11B");
4914 break;
4915 case AP_11ng:
4916 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4917 break;
4918 case AP_11a:
4919 run_system(dut, "cfg -a AP_CHMODE=11A");
4920 break;
4921 case AP_11na:
4922 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4923 break;
4924 case AP_11ac:
4925 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4926 break;
4927 default:
4928 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4929 break;
4930 }
4931 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4932 dut->ap_channel_1);
4933 }
4934 run_system(dut, buf);
4935 } else {
4936 run_system(dut, "cfg -a AP_RADIO_ID=0");
4937 switch (dut->ap_mode) {
4938 case AP_11g:
4939 run_system(dut, "cfg -a AP_CHMODE=11G");
4940 break;
4941 case AP_11b:
4942 run_system(dut, "cfg -a AP_CHMODE=11B");
4943 break;
4944 case AP_11ng:
4945 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4946 break;
4947 case AP_11a:
4948 run_system(dut, "cfg -a AP_CHMODE=11A");
4949 break;
4950 case AP_11na:
4951 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4952 break;
4953 case AP_11ac:
4954 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4955 break;
4956 default:
4957 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4958 break;
4959 }
4960 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4961 dut->ap_channel);
4962 run_system(dut, buf);
4963 }
4964
4965 if (dut->ap_sgi80 == 1) {
4966 run_system(dut, "cfg -a SHORTGI=1");
4967 run_system(dut, "cfg -a SHORTGI_2=1");
4968 } else if (dut->ap_sgi80 == 0) {
4969 run_system(dut, "cfg -a SHORTGI=0");
4970 run_system(dut, "cfg -a SHORTGI_2=0");
4971 }
4972
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004973 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004974 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004975 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004976 run_system(dut, "cfg -a LDPC=0");
4977}
4978
4979
4980void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
4981{
4982 char buf[50];
4983
4984 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
4985 if (system(buf) != 0)
4986 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
4987
4988 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
4989 if (system(buf) != 0)
4990 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
4991
4992 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
4993 if (system(buf) != 0)
4994 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
4995
4996 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
4997 if (system(buf) != 0)
4998 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
4999}
5000
5001
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005002static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5003 const char *val)
5004{
5005 if (strcasecmp(val, "enable") == 0) {
5006 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 1", ifname);
5007 } else if (strcasecmp(val, "disable") == 0) {
5008 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 0", ifname);
5009 } else {
5010 sigma_dut_print(dut, DUT_MSG_ERROR,
5011 "Unsupported assoc_disallow");
5012 }
5013}
5014
5015
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005016static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5017{
5018 int i;
5019 int least_pref = 1 << 8;
5020 char ifname[20];
5021 uint8_t self_mac[ETH_ALEN];
5022 char buf[200];
5023 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5024
5025 get_if_name(dut, ifname, sizeof(ifname), 1);
5026 get_hwaddr(ifname, self_mac);
5027
5028 /* Clear off */
5029 snprintf(buf, sizeof(buf),
5030 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5031 ifname);
5032 run_system(dut, buf);
5033
5034 /* Find the least preference number */
5035 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5036 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5037
5038 ap_ne_class = 1;
5039 ap_ne_pref = 255;
5040 ap_ne_op_ch = 1;
5041 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5042 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5043 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5044 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5045 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5046 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5047
5048 if (ap_ne_pref < least_pref)
5049 least_pref = ap_ne_pref;
5050 snprintf(buf, sizeof(buf),
5051 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5052 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5053 mac_addr[3], mac_addr[4], mac_addr[5],
5054 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5055 run_system(dut, buf);
5056 }
5057
5058 /* Now add the self AP Address */
5059 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5060 if (dut->ap_channel <= 11)
5061 ap_ne_class = 81;
5062 else
5063 ap_ne_class = 115;
5064 } else {
5065 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5066 }
5067
5068 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5069 ap_ne_op_ch = dut->ap_channel;
5070 else
5071 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5072
5073 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5074 ap_ne_pref = least_pref - 1;
5075 else
5076 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5077
5078 snprintf(buf, sizeof(buf),
5079 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5080 ifname, self_mac[0], self_mac[1], self_mac[2],
5081 self_mac[3], self_mac[4], self_mac[5],
5082 ap_ne_pref,
5083 ap_ne_class,
5084 ap_ne_op_ch);
5085 run_system(dut, buf);
5086}
5087
5088
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005089static void ath_ap_set_params(struct sigma_dut *dut)
5090{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005091 const char *basedev = "wifi0";
5092 const char *basedev_radio = "wifi1";
5093 char *ifname = get_main_ifname();
5094 char *ifname_dual;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005095 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005096 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005097
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005098 if (sigma_radio_ifname[0])
5099 basedev = sigma_radio_ifname[0];
5100
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005101 if (dut->ap_is_dual == 1) {
5102 basedev = sigma_radio_ifname[0];
5103 basedev_radio = sigma_radio_ifname[1];
5104 if (sigma_radio_ifname[0] &&
5105 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5106 ifname = "ath0";
5107 ifname_dual = "ath1";
5108 } else {
5109 ifname = "ath1";
5110 ifname_dual = "ath0";
5111 }
5112 }
5113
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005114 if (dut->ap_countrycode[0]) {
5115 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
5116 basedev, dut->ap_countrycode);
5117 if (system(buf) != 0) {
5118 sigma_dut_print(dut, DUT_MSG_ERROR,
5119 "iwpriv setCountry failed");
5120 }
5121 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5122 }
5123
5124 for (i = 0; i < NUM_AP_AC; i++) {
5125 if (dut->ap_qos[i].ac) {
5126 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
5127 ifname, i, dut->ap_qos[i].cwmin);
5128 if (system(buf) != 0) {
5129 sigma_dut_print(dut, DUT_MSG_ERROR,
5130 "iwpriv cwmin failed");
5131 }
5132
5133 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
5134 ifname, i, dut->ap_qos[i].cwmax);
5135 if (system(buf) != 0) {
5136 sigma_dut_print(dut, DUT_MSG_ERROR,
5137 "iwpriv cwmax failed");
5138 }
5139
5140 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
5141 ifname, i, dut->ap_qos[i].aifs);
5142 if (system(buf) != 0) {
5143 sigma_dut_print(dut, DUT_MSG_ERROR,
5144 "iwpriv aifs failed");
5145 }
5146
5147 snprintf(buf, sizeof(buf),
5148 "iwpriv %s txoplimit %d 0 %d",
5149 ifname, i, dut->ap_qos[i].txop);
5150 if (system(buf) != 0) {
5151 sigma_dut_print(dut, DUT_MSG_ERROR,
5152 "iwpriv txoplimit failed");
5153 }
5154
5155 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
5156 ifname, i, dut->ap_qos[i].acm);
5157 if (system(buf) != 0) {
5158 sigma_dut_print(dut, DUT_MSG_ERROR,
5159 "iwpriv acm failed");
5160 }
5161 }
5162 }
5163
5164 for (i = 0; i < NUM_AP_AC; i++) {
5165 if (dut->ap_sta_qos[i].ac) {
5166 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
5167 ifname, i, dut->ap_sta_qos[i].cwmin);
5168 if (system(buf) != 0) {
5169 sigma_dut_print(dut, DUT_MSG_ERROR,
5170 "iwpriv cwmin failed");
5171 }
5172
5173 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
5174 ifname, i, dut->ap_sta_qos[i].cwmax);
5175 if (system(buf) != 0) {
5176 sigma_dut_print(dut, DUT_MSG_ERROR,
5177 "iwpriv cwmax failed");
5178 }
5179
5180 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
5181 ifname, i, dut->ap_sta_qos[i].aifs);
5182 if (system(buf) != 0) {
5183 sigma_dut_print(dut, DUT_MSG_ERROR,
5184 "iwpriv aifs failed");
5185 }
5186
5187 snprintf(buf, sizeof(buf),
5188 "iwpriv %s txoplimit %d 1 %d",
5189 ifname, i, dut->ap_sta_qos[i].txop);
5190 if (system(buf) != 0) {
5191 sigma_dut_print(dut, DUT_MSG_ERROR,
5192 "iwpriv txoplimit failed");
5193 }
5194
5195 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
5196 ifname, i, dut->ap_sta_qos[i].acm);
5197 if (system(buf) != 0) {
5198 sigma_dut_print(dut, DUT_MSG_ERROR,
5199 "iwpriv acm failed");
5200 }
5201 }
5202 }
5203
5204 if (dut->ap_disable_protection == 1) {
5205 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
5206 if (system(buf) != 0) {
5207 sigma_dut_print(dut, DUT_MSG_ERROR,
5208 "iwpriv enablertscts failed");
5209 }
5210 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5211 }
5212
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005213 if (dut->ap_ldpc == VALUE_ENABLED) {
Sarvepalli, Rajesh Babu580572a2016-11-29 22:07:14 +05305214 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 3", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005215 if (system(buf) != 0) {
5216 sigma_dut_print(dut, DUT_MSG_ERROR,
priyadharshini gowthaman15b299d2017-04-20 12:10:45 -07005217 "iwpriv ldpc 3 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005218 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005219 } else if (dut->ap_ldpc == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005220 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
5221 if (system(buf) != 0) {
5222 sigma_dut_print(dut, DUT_MSG_ERROR,
5223 "iwpriv ldpc 0 failed");
5224 }
5225 }
5226
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005227 if (dut->ap_ampdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005228 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
5229 if (system(buf) != 0) {
5230 sigma_dut_print(dut, DUT_MSG_ERROR,
5231 "iwpriv ampdu 1 failed");
5232 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005233 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005234 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
5235 if (system(buf) != 0) {
5236 sigma_dut_print(dut, DUT_MSG_ERROR,
5237 "iwpriv ampdu 0 failed");
5238 }
5239 }
5240
5241 if (dut->ap_ampdu_exp) {
5242 if (dut->program == PROGRAM_VHT) {
5243 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
5244 ifname, dut->ap_ampdu_exp);
5245 if (system(buf) != 0) {
5246 sigma_dut_print(dut, DUT_MSG_ERROR,
5247 "iwpriv vhtmaxampdu failed");
5248 }
5249 } else {
5250 /* 11N */
5251 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
5252 ifname, dut->ap_ampdu_exp);
5253 if (system(buf) != 0) {
5254 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
5255 }
5256 }
5257 }
5258
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005259 if (dut->ap_noack == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005260 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
5261 if (system(buf) != 0) {
5262 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
5263 }
5264 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
5265 if (system(buf) != 0) {
5266 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
5267 }
5268 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
5269 if (system(buf) != 0) {
5270 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
5271 }
5272 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
5273 if (system(buf) != 0) {
5274 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
5275 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005276 } else if (dut->ap_noack == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005277 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
5278 if (system(buf) != 0) {
5279 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
5280 }
5281 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
5282 if (system(buf) != 0) {
5283 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
5284 }
5285 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
5286 if (system(buf) != 0) {
5287 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
5288 }
5289 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
5290 if (system(buf) != 0) {
5291 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
5292 }
5293 }
5294
5295 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
5296 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5297 ifname, dut->ap_vhtmcs_map);
5298 if (system(buf) != 0) {
5299 sigma_dut_print(dut, DUT_MSG_ERROR,
5300 "iwpriv vht_mcsmap failed");
5301 }
5302 }
5303
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005304 if (dut->ap_amsdu == VALUE_ENABLED) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005305 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005306 if (system(buf) != 0) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005307 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005308 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005309 } else if (dut->ap_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005310 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
5311 if (system(buf) != 0) {
5312 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
5313 }
5314 }
5315
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005316 if (dut->ap_rx_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005317 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
5318 if (system(buf) != 0) {
5319 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
5320 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005321 } else if (dut->ap_rx_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005322 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
5323 if (system(buf) != 0) {
5324 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
5325 }
5326 }
5327
5328 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005329 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5330 dut->ap_ampdu == VALUE_DISABLED &&
5331 dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005332 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
5333 if (system(buf) != 0) {
5334 sigma_dut_print(dut, DUT_MSG_ERROR,
5335 "iwpriv setaddbaoper 1 failed");
5336 }
5337
5338 snprintf(buf, sizeof(buf),
5339 "wifitool %s senddelba 1 0 1 4", ifname);
5340 if (system(buf) != 0) {
5341 sigma_dut_print(dut, DUT_MSG_ERROR,
5342 "wifitool senddelba failed");
5343 }
5344
5345 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5346 ifname);
5347 if (system(buf) != 0) {
5348 sigma_dut_print(dut, DUT_MSG_ERROR,
5349 "wifitool sendsingleamsdu failed");
5350 }
5351
5352 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
5353 if (system(buf) != 0) {
5354 sigma_dut_print(dut, DUT_MSG_ERROR,
5355 "iwpriv amsdu failed");
5356 }
5357 }
5358
5359 if (dut->ap_mode == AP_11ac) {
5360 int chwidth, nss;
5361
5362 switch (dut->ap_chwidth) {
5363 case AP_20:
5364 chwidth = 0;
5365 break;
5366 case AP_40:
5367 chwidth = 1;
5368 break;
5369 case AP_80:
5370 chwidth = 2;
5371 break;
5372 case AP_160:
5373 chwidth = 3;
5374 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005375 case AP_80_80:
5376 chwidth = 3;
5377 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005378 default:
5379 chwidth = 0;
5380 break;
5381 }
5382
5383 switch (dut->ap_tx_streams) {
5384 case 1:
5385 nss = 1;
5386 break;
5387 case 2:
5388 nss = 2;
5389 break;
5390 case 3:
5391 nss = 3;
5392 break;
5393 case 4:
5394 nss = 4;
5395 break;
5396 default:
5397 nss = 3;
5398 break;
5399 }
5400
5401 if (dut->ap_fixed_rate) {
5402 if (nss == 4)
5403 ath_disable_txbf(dut, ifname);
5404
5405 /* Set the nss */
5406 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
5407 ifname, nss);
5408 if (system(buf) != 0) {
5409 sigma_dut_print(dut, DUT_MSG_ERROR,
5410 "iwpriv nss failed");
5411 }
5412
5413 /* Set the channel width */
5414 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5415 ifname, chwidth);
5416 if (system(buf) != 0) {
5417 sigma_dut_print(dut, DUT_MSG_ERROR,
5418 "iwpriv chwidth failed");
5419 }
5420
5421 /* Set the VHT MCS */
5422 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
5423 ifname, dut->ap_mcs);
5424 if (system(buf) != 0) {
5425 sigma_dut_print(dut, DUT_MSG_ERROR,
5426 "iwpriv vhtmcs failed");
5427 }
5428 }
5429 }
5430
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005431 if (dut->ap_dyn_bw_sig == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005432 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
5433 if (system(buf) != 0) {
5434 sigma_dut_print(dut, DUT_MSG_ERROR,
5435 "iwpriv cwmenable 1 failed");
5436 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005437 } else if (dut->ap_dyn_bw_sig == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005438 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
5439 if (system(buf) != 0) {
5440 sigma_dut_print(dut, DUT_MSG_ERROR,
5441 "iwpriv cwmenable 0 failed");
5442 }
5443 }
5444
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005445 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005446 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5447 if (system(buf) != 0) {
5448 sigma_dut_print(dut, DUT_MSG_ERROR,
5449 "iwconfig rts 64 failed");
5450 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005451 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005452 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5453 if (system(buf) != 0) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR,
5455 "iwpriv rts 2347 failed");
5456 }
5457 }
5458
5459 if (dut->ap_hs2) {
5460 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
5461 if (system(buf) != 0) {
5462 sigma_dut_print(dut, DUT_MSG_ERROR,
5463 "iwpriv qbssload failed");
5464 }
5465 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5466 }
5467
5468 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5469 unsigned int bssload = 0;
5470
5471 if (dut->ap_bss_load == 1) {
5472 /* STA count: 1, CU: 50, AAC: 65535 */
5473 bssload = 0x0132ffff;
5474 } else if (dut->ap_bss_load == 2) {
5475 /* STA count: 1, CU: 200, AAC: 65535 */
5476 bssload = 0x01c8ffff;
5477 } else if (dut->ap_bss_load == 3) {
5478 /* STA count: 1, CU: 75, AAC: 65535 */
5479 bssload = 0x014bffff;
5480 }
5481
5482 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
5483 ifname, bssload);
5484 if (system(buf) != 0) {
5485 sigma_dut_print(dut, DUT_MSG_ERROR,
5486 "iwpriv hcbssload failed");
5487 }
5488 } else if (dut->ap_bss_load == 0) {
5489 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5490 if (system(buf) != 0) {
5491 sigma_dut_print(dut, DUT_MSG_ERROR,
5492 "iwpriv qbssload failed");
5493 }
5494 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5495 }
5496
5497 if (dut->ap_dgaf_disable) {
5498 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
5499 if (system(buf) != 0) {
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "iwpriv dgaf_disable failed");
5502 }
5503 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
5504 }
5505
5506 if (dut->ap_l2tif) {
5507 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
5508 if (system(buf) != 0) {
5509 sigma_dut_print(dut, DUT_MSG_ERROR,
5510 "iwpriv l2tif failed");
5511 }
5512 snprintf(buf, sizeof(buf),
5513 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
5514 if (system(buf) != 0)
5515 sigma_dut_print(dut, DUT_MSG_ERROR,
5516 "l2tif br failed");
5517
5518 snprintf(buf, sizeof(buf),
5519 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
5520 if (system(buf) != 0)
5521 sigma_dut_print(dut, DUT_MSG_ERROR,
5522 "l2tif brif failed");
5523 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
5524 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005525
5526 if (dut->ap_ndpa_frame == 0) {
5527 snprintf(buf, sizeof(buf),
5528 "wifitool %s beeliner_fw_test 117 192", ifname);
5529 if (system(buf) != 0) {
5530 sigma_dut_print(dut, DUT_MSG_ERROR,
5531 "wifitool beeliner_fw_test 117 192 failed");
5532 }
5533 snprintf(buf, sizeof(buf),
5534 "wifitool %s beeliner_fw_test 118 192", ifname);
5535 if (system(buf) != 0) {
5536 sigma_dut_print(dut, DUT_MSG_ERROR,
5537 "wifitool beeliner_fw_test 117 192 failed");
5538 }
5539 } else if (dut->ap_ndpa_frame == 1) {
5540 /* Driver default - no changes needed */
5541 } else if (dut->ap_ndpa_frame == 2) {
5542 snprintf(buf, sizeof(buf),
5543 "wifitool %s beeliner_fw_test 115 1", ifname);
5544 if (system(buf) != 0) {
5545 sigma_dut_print(dut, DUT_MSG_ERROR,
5546 "wifitool beeliner_fw_test 117 192 failed");
5547 }
5548 snprintf(buf, sizeof(buf),
5549 "wifitool %s beeliner_fw_test 116 1", ifname);
5550 if (system(buf) != 0) {
5551 sigma_dut_print(dut, DUT_MSG_ERROR,
5552 "wifitool beeliner_fw_test 117 192 failed");
5553 }
5554 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005555
5556 if (dut->ap_rtt == 1) {
5557 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5558 run_system(dut, buf);
5559 }
5560
5561 if (dut->ap_lci == 1) {
5562 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5563 run_system(dut, buf);
5564 }
5565
5566 if (dut->ap_lcr == 1) {
5567 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5568 run_system(dut, buf);
5569 }
5570
5571 if (dut->ap_rrm == 1) {
5572 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5573 run_system(dut, buf);
5574 }
5575
5576 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
5577 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
5578 }
5579
5580 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
5581 FILE *f;
5582
5583 f = fopen("/tmp/nbr_report.txt", "w");
5584 if (!f) {
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "Failed to open /tmp/nbr_report.txt");
5587 return;
5588 }
5589
5590 fprintf(f,
5591 "ap_1 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x2a 0x00\n",
5592 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5593 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5594 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5595 dut->ap_val_opchannel[0]);
5596 fclose(f);
5597
5598 f = fopen("/tmp/ftmrr.txt", "w");
5599 if (!f) {
5600 sigma_dut_print(dut, DUT_MSG_ERROR,
5601 "Failed to open /tmp/ftmrr.txt");
5602 return;
5603 }
5604
5605 fprintf(f,
5606 "ap_1 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x2a 0x00\n",
5607 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5608 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5609 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5610 dut->ap_val_opchannel[0]);
5611 fclose(f);
5612 }
5613
5614 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
5615 FILE *f;
5616
5617 f = fopen("/tmp/nbr_report.txt", "a");
5618 if (!f) {
5619 sigma_dut_print(dut, DUT_MSG_ERROR,
5620 "Failed to open /tmp/nbr_report.txt");
5621 return;
5622 }
5623 fprintf(f,
5624 "ap_2 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x6a 0x00\n",
5625 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5626 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5627 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5628 dut->ap_val_opchannel[1]);
5629 fclose(f);
5630
5631 f = fopen("/tmp/ftmrr.txt", "a");
5632 if (!f) {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "Failed to open /tmp/ftmrr.txt");
5635 return;
5636 }
5637 fprintf(f,
5638 "ap_2 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x6a 0x00\n",
5639 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5640 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5641 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5642 dut->ap_val_opchannel[1]);
5643 fclose(f);
5644 }
5645
5646 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
5647 FILE *f;
5648
5649 f = fopen("/tmp/nbr_report.txt", "a");
5650 if (!f) {
5651 sigma_dut_print(dut, DUT_MSG_ERROR,
5652 "Failed to open /tmp/nbr_report.txt");
5653 return;
5654 }
5655
5656 fprintf(f,
5657 "ap_3 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x9b 0x00\n",
5658 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5659 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5660 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5661 dut->ap_val_opchannel[2]);
5662 fclose(f);
5663
5664 f = fopen("/tmp/ftmrr.txt", "a");
5665 if (!f) {
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "Failed to open /tmp/ftmrr.txt");
5668 return;
5669 }
5670
5671 fprintf(f,
5672 "ap_3 = 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x00 0x3c 0x00 0x00 0x80 0x%x 0x09 0x06 0x03 0x02 0x9b 0x00\n",
5673 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5674 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5675 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5676 dut->ap_val_opchannel[2]);
5677 fclose(f);
5678 }
5679
5680 if (dut->ap_neighap) {
5681 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5682 run_system(dut, buf);
5683 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5684 run_system(dut, buf);
5685 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5686 run_system(dut, buf);
5687 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5688 run_system(dut, buf);
5689 }
5690
5691 if (dut->ap_scan == 1) {
5692 snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600",
5693 ifname);
5694 run_system(dut, buf);
5695 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
5696 run_system(dut, buf);
5697 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07005698
5699 if (dut->ap_set_bssidpref) {
5700 snprintf(buf, sizeof(buf),
5701 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
5702 ifname);
5703 if (system(buf) != 0) {
5704 sigma_dut_print(dut, DUT_MSG_ERROR,
5705 "wifitool clear bssidpref failed");
5706 }
5707 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005708
5709 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
5710 int feature_enable;
5711
5712 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
5713 snprintf(buf, sizeof(buf), "iwpriv %s wnm %d",
5714 ifname, feature_enable);
5715 run_system(dut, buf);
5716 snprintf(buf, sizeof(buf), "iwpriv %s wnm_bss %d",
5717 ifname, feature_enable);
5718 run_system(dut, buf);
5719 if (feature_enable) {
5720 const char *extra = "";
5721
5722 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
5723 if (dut->wnm_bss_max_protection ==
5724 VALUE_ENABLED)
5725 extra = " 1";
5726 else
5727 extra = " 0";
5728 }
5729 snprintf(buf, sizeof(buf),
5730 "wlanconfig %s wnm setbssmax %d%s",
5731 ifname, dut->wnm_bss_max_idle_time, extra);
5732 run_system(dut, buf);
5733 }
5734 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005735
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005736 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005737 apply_mbo_pref_ap_list(dut);
5738
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005739 snprintf(buf, sizeof(buf), "iwpriv %s mbo_cel_pref %d",
5740 ifname, dut->ap_cell_cap_pref);
5741 run_system(dut, buf);
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07005742
5743 snprintf(buf, sizeof(buf), "iwpriv %s mbocap 0x40", ifname);
5744 run_system(dut, buf);
5745
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005746 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005747 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005748
5749 if (dut->ap_oce == VALUE_ENABLED) {
5750 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 1",
5751 ifname);
5752 run_system(dut, buf);
5753 }
5754
5755 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
5756 snprintf(buf, sizeof(buf), "iwpriv %s prb_rate 5500", ifname);
5757 run_system(dut, buf);
5758 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 5500",
5759 ifname);
5760 run_system(dut, buf);
5761 }
5762
5763 if (dut->ap_oce == VALUE_DISABLED) {
5764 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 0",
5765 ifname);
5766 run_system(dut, buf);
5767 }
5768
5769 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
5770 snprintf(buf, sizeof(buf), "iwpriv %s mgmt_rate 1000", ifname);
5771 run_system(dut, buf);
5772 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 1000",
5773 ifname);
5774 run_system(dut, buf);
5775 }
5776
5777 if (dut->ap_bcnint) {
5778 snprintf(buf, sizeof(buf), "iwpriv %s bintval %d", ifname,
5779 dut->ap_bcnint);
5780 run_system(dut, buf);
5781 }
5782
5783 if (dut->ap_filsdscv == VALUE_DISABLED) {
5784 snprintf(buf, sizeof(buf), "iwpriv %s enable_fils 0 0", ifname);
5785 run_system(dut, buf);
5786 }
5787
5788 if (dut->ap_filshlp == VALUE_ENABLED) {
5789 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 1", ifname);
5790 if (system(buf) != 0) {
5791 sigma_dut_print(dut, DUT_MSG_ERROR,
5792 "iwpriv filshlp enable failed");
5793 }
5794 } else if (dut->ap_filshlp == VALUE_DISABLED) {
5795 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 0", ifname);
5796 if (system(buf) != 0) {
5797 sigma_dut_print(dut, DUT_MSG_ERROR,
5798 "iwpriv filshlp disable failed");
5799 }
5800 }
5801
5802 /* When RNR is enabled, also enable apchannelreport, background scan */
5803 if (dut->ap_rnr == VALUE_ENABLED) {
5804 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1", ifname);
5805 run_system(dut, buf);
5806 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1", ifname);
5807 run_system(dut, buf);
5808 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1", ifname);
5809 run_system(dut, buf);
5810 snprintf(buf, sizeof(buf), "iwpriv %s acs_ctrlflags 0x4",
5811 basedev);
5812 run_system(dut, buf);
5813 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5814 basedev);
5815 run_system(dut, buf);
5816 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1", basedev);
5817 run_system(dut, buf);
5818 if (dut->ap_is_dual == 1) {
5819 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1",
5820 ifname_dual);
5821 run_system(dut, buf);
5822 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1",
5823 ifname_dual);
5824 run_system(dut, buf);
5825 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1",
5826 ifname_dual);
5827 run_system(dut, buf);
5828 snprintf(buf, sizeof(buf),
5829 "iwpriv %s acs_ctrlflags 0x4", basedev_radio);
5830 run_system(dut, buf);
5831 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5832 basedev_radio);
5833 run_system(dut, buf);
5834 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1",
5835 basedev_radio);
5836 run_system(dut, buf);
5837 }
5838 }
5839
5840 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
5841 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5842 run_system(dut, buf);
5843 snprintf(buf, sizeof(buf),
5844 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
5845 ifname, dut->ap_blestacnt & 0xFF,
5846 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5847 dut->ap_ble_admit_cap & 0xFF,
5848 dut->ap_ble_admit_cap >> 8);
5849 run_system(dut, buf);
5850 snprintf(buf, sizeof(buf),
5851 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
5852 ifname, dut->ap_blestacnt & 0xFF,
5853 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5854 dut->ap_ble_admit_cap & 0xFF,
5855 dut->ap_ble_admit_cap >> 8);
5856 run_system(dut, buf);
5857 }
5858
5859 if (dut->ap_esp == VALUE_ENABLED) {
5860 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 5", basedev);
5861 if (system(buf) != 0) {
5862 sigma_dut_print(dut, DUT_MSG_ERROR,
5863 "iwpriv esp enable failed");
5864 }
5865 } else if (dut->ap_esp == VALUE_DISABLED) {
5866 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 0", basedev);
5867 if (system(buf) != 0) {
5868 sigma_dut_print(dut, DUT_MSG_ERROR,
5869 "iwpriv esp disable failed");
5870 }
5871 }
5872
5873 if (dut->ap_datappdudura) {
5874 snprintf(buf, sizeof(buf), "iwpriv %s esp_ppdu_dur %d", basedev,
5875 dut->ap_datappdudura);
5876 run_system(dut, buf);
5877 }
5878
5879 if (dut->ap_airtimefract) {
5880 snprintf(buf, sizeof(buf), "iwpriv %s esp_airtime %d", basedev,
5881 dut->ap_airtimefract);
5882 run_system(dut, buf);
5883 }
5884
5885 if (dut->ap_dhcp_stop) {
5886 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
5887 run_system(dut, buf);
5888 }
5889
5890 if (dut->ap_bawinsize) {
5891 snprintf(buf, sizeof(buf), "iwpriv %s esp_ba_window %d",
5892 basedev, dut->ap_bawinsize);
5893 run_system(dut, buf);
5894 }
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005895
5896 if (dut->program == PROGRAM_DPP) {
5897 if (dut->ap_interface_2g == 1) {
5898 snprintf(buf, sizeof(buf),
5899 "iwpriv %s set_bcn_rate 5500", ifname);
5900 run_system(dut, buf);
5901 snprintf(buf, sizeof(buf),
5902 "iwpriv %s prb_rate 5500", ifname);
5903 run_system(dut, buf);
5904 snprintf(buf, sizeof(buf),
5905 "iwpriv %s mgmt_rate 5500", ifname);
5906 run_system(dut, buf);
5907 }
5908
5909 snprintf(buf, sizeof(buf), "iwpriv %s set_rxfilter 0xffffffff",
5910 basedev);
5911 run_system(dut, buf);
5912 dut->hostapd_running = 1;
5913 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07005914
5915 if (dut->ap_he_ppdu == PPDU_MU) {
5916 run_system_wrapper(
5917 dut, "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
5918 ifname);
5919 run_system_wrapper(
5920 dut, "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
5921 ifname);
5922 run_system_wrapper(dut,
5923 "wifitool %s setUnitTestCmd 0x47 2 8 0",
5924 ifname);
5925 run_system_wrapper(dut,
5926 "wifitool %s setUnitTestCmd 0x47 2 29 0",
5927 ifname);
5928 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929}
5930
5931
5932static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
5933 struct sigma_conn *conn,
5934 struct sigma_cmd *cmd)
5935{
5936 /* const char *name = get_param(cmd, "NAME"); */
5937 char buf[100];
5938 struct stat s;
5939 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
5940
5941 if (stat("/proc/athversion", &s) == 0) {
5942 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
5943 run_system(dut, "apdown");
5944 }
5945
5946 cmd_ath_ap_radio_config(dut);
5947
5948 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
5949 run_system(dut, buf);
5950
5951 switch (dut->ap_key_mgmt) {
5952 case AP_OPEN:
5953 if (dut->ap_cipher == AP_WEP) {
5954 run_system(dut, "cfg -a AP_SECMODE=WEP");
5955 run_system(dut, "cfg -a AP_SECFILE=NONE");
5956 /* shared auth mode not supported */
5957 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5958 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5959 snprintf(buf, sizeof(buf),
5960 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5961 dut->ap_wepkey);
5962 run_system(dut, buf);
5963 snprintf(buf, sizeof(buf),
5964 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5965 dut->ap_wepkey);
5966 run_system(dut, buf);
5967 } else {
5968 run_system(dut, "cfg -a AP_SECMODE=None");
5969 }
5970 break;
5971 case AP_WPA2_PSK:
5972 case AP_WPA2_PSK_MIXED:
5973 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005974 case AP_WPA2_SAE:
5975 case AP_WPA2_PSK_SAE:
5976 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5977 dut->ap_key_mgmt == AP_WPA2_SAE ||
5978 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005979 run_system(dut, "cfg -a AP_WPA=2");
5980 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5981 run_system(dut, "cfg -a AP_WPA=3");
5982 else
5983 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03005984 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005985 run_system(dut, "cfg -a AP_SECMODE=WPA");
5986 run_system(dut, "cfg -a AP_SECFILE=PSK");
5987 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
5988 dut->ap_passphrase);
5989 run_system(dut, buf);
5990 if (dut->ap_cipher == AP_CCMP_TKIP)
5991 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
5992 else if (dut->ap_cipher == AP_TKIP)
5993 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5994 else
5995 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5996 break;
5997 case AP_WPA2_EAP:
5998 case AP_WPA2_EAP_MIXED:
5999 case AP_WPA_EAP:
6000 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6001 run_system(dut, "cfg -a AP_WPA=2");
6002 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6003 run_system(dut, "cfg -a AP_WPA=3");
6004 else
6005 run_system(dut, "cfg -a AP_WPA=1");
6006 run_system(dut, "cfg -a AP_SECMODE=WPA");
6007 run_system(dut, "cfg -a AP_SECFILE=EAP");
6008 if (dut->ap_cipher == AP_CCMP_TKIP)
6009 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6010 else if (dut->ap_cipher == AP_TKIP)
6011 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6012 else
6013 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6014 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6015 dut->ap_radius_ipaddr);
6016 run_system(dut, buf);
6017 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6018 dut->ap_radius_port);
6019 run_system(dut, buf);
6020 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6021 dut->ap_radius_password);
6022 run_system(dut, buf);
6023 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006024 case AP_WPA2_EAP_OSEN:
6025 /* TODO */
6026 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6027 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006028 case AP_SUITEB:
6029 /* TODO */
6030 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6031 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006032 case AP_WPA2_OWE:
6033 /* TODO */
6034 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6035 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006036 case AP_WPA2_FT_EAP:
6037 case AP_WPA2_FT_PSK:
6038 case AP_WPA2_EAP_SHA256:
6039 case AP_WPA2_PSK_SHA256:
6040 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006041 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006042 /* TODO */
6043 send_resp(dut, conn, SIGMA_ERROR,
6044 "errorCode,Unsupported KeyMgnt value");
6045 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046 }
6047
6048 if (dut->ap_is_dual) {
6049 /* ath1 settings in case of dual */
6050 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6051 dut->ap_ssid);
6052 run_system(dut, buf);
6053
6054 switch (dut->ap_key_mgmt) {
6055 case AP_OPEN:
6056 if (dut->ap_cipher == AP_WEP) {
6057 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6058 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6059 /* shared auth mode not supported */
6060 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6061 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6062 snprintf(buf, sizeof(buf),
6063 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6064 dut->ap_wepkey);
6065 run_system(dut, buf);
6066 snprintf(buf, sizeof(buf),
6067 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6068 dut->ap_wepkey);
6069 run_system(dut, buf);
6070 } else {
6071 run_system(dut, "cfg -a AP_SECMODE_2=None");
6072 }
6073 break;
6074 case AP_WPA2_PSK:
6075 case AP_WPA2_PSK_MIXED:
6076 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006077 case AP_WPA2_SAE:
6078 case AP_WPA2_PSK_SAE:
6079 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6080 dut->ap_key_mgmt == AP_WPA2_SAE ||
6081 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006082 run_system(dut, "cfg -a AP_WPA_2=2");
6083 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6084 run_system(dut, "cfg -a AP_WPA_2=3");
6085 else
6086 run_system(dut, "cfg -a AP_WPA_2=1");
6087 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006088 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006089 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6090 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
6091 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
6092 dut->ap_passphrase);
6093 run_system(dut, buf);
6094 if (dut->ap_cipher == AP_CCMP_TKIP)
6095 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6096 else if (dut->ap_cipher == AP_TKIP)
6097 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6098 else
6099 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6100 break;
6101 case AP_WPA2_EAP:
6102 case AP_WPA2_EAP_MIXED:
6103 case AP_WPA_EAP:
6104 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6105 run_system(dut, "cfg -a AP_WPA_2=2");
6106 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6107 run_system(dut, "cfg -a AP_WPA_2=3");
6108 else
6109 run_system(dut, "cfg -a AP_WPA_2=1");
6110 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6111 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6112 if (dut->ap_cipher == AP_CCMP_TKIP)
6113 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6114 else if (dut->ap_cipher == AP_TKIP)
6115 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6116 else
6117 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6118
6119 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6120 dut->ap_radius_ipaddr);
6121 run_system(dut, buf);
6122 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6123 dut->ap_radius_port);
6124 run_system(dut, buf);
6125 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6126 dut->ap_radius_password);
6127 run_system(dut, buf);
6128 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006129 case AP_WPA2_EAP_OSEN:
6130 /* TODO */
6131 sigma_dut_print(dut, DUT_MSG_ERROR,
6132 "EAP+OSEN not supported");
6133 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006134 case AP_SUITEB:
6135 /* TODO */
6136 sigma_dut_print(dut, DUT_MSG_ERROR,
6137 "SuiteB not supported");
6138 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006139 case AP_WPA2_OWE:
6140 /* TODO */
6141 sigma_dut_print(dut, DUT_MSG_ERROR,
6142 "OWE not supported");
6143 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006144 case AP_WPA2_FT_EAP:
6145 case AP_WPA2_FT_PSK:
6146 case AP_WPA2_EAP_SHA256:
6147 case AP_WPA2_PSK_SHA256:
6148 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006149 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006150 /* TODO */
6151 send_resp(dut, conn, SIGMA_ERROR,
6152 "errorCode,Unsupported KeyMgnt value");
6153 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006154 }
6155
6156 /* wifi0 settings in case of dual */
6157 run_system(dut, "cfg -a AP_RADIO_ID=0");
6158 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6159 run_system(dut, "cfg -a AP_STARTMODE=dual");
6160 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6161 run_system(dut, "cfg -a TX_CHAINMASK=7");
6162 run_system(dut, "cfg -a RX_CHAINMASK=7");
6163 }
6164
6165 switch (dut->ap_pmf) {
6166 case AP_PMF_DISABLED:
6167 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6168 run_system(dut, buf);
6169 break;
6170 case AP_PMF_OPTIONAL:
6171 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6172 run_system(dut, buf);
6173 break;
6174 case AP_PMF_REQUIRED:
6175 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6176 run_system(dut, buf);
6177 break;
6178 }
6179 if (dut->ap_add_sha256) {
6180 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6181 run_system(dut, buf);
6182 } else {
6183 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6184 run_system(dut, buf);
6185 }
6186
6187 if (dut->ap_hs2)
6188 run_system(dut, "cfg -a AP_HOTSPOT=1");
6189 else
6190 run_system(dut, "cfg -r AP_HOTSPOT");
6191
6192 if (dut->ap_interworking) {
6193 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6194 dut->ap_access_net_type);
6195 run_system(dut, buf);
6196 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6197 dut->ap_internet);
6198 run_system(dut, buf);
6199 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6200 dut->ap_venue_group);
6201 run_system(dut, buf);
6202 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6203 dut->ap_venue_type);
6204 run_system(dut, buf);
6205 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6206 dut->ap_hessid);
6207 run_system(dut, buf);
6208
6209 if (dut->ap_roaming_cons[0]) {
6210 char *second, *rc;
6211 rc = strdup(dut->ap_roaming_cons);
6212 if (rc == NULL)
6213 return 0;
6214
6215 second = strchr(rc, ';');
6216 if (second)
6217 *second++ = '\0';
6218
6219 snprintf(buf, sizeof(buf),
6220 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6221 run_system(dut, buf);
6222
6223 if (second) {
6224 snprintf(buf, sizeof(buf),
6225 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6226 "=%s", second);
6227 run_system(dut, buf);
6228 }
6229 free(rc);
6230 } else {
6231 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6232 run_system(dut,
6233 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6234 }
6235 } else {
6236 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6237 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6238 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6239 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6240 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6241 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6242 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6243 }
6244
6245 if (dut->ap_proxy_arp)
6246 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6247 else
6248 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6249 if (dut->ap_dgaf_disable)
6250 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6251 else
6252 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6253
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006254 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006255 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006256 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 run_system(dut, buf);
6258
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006259 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006260 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6261 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6262
6263 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6264 dut->ap2_radius_ipaddr);
6265 run_system(dut, buf);
6266
6267 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6268 dut->ap2_radius_port);
6269 run_system(dut, buf);
6270
6271 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6272 dut->ap2_radius_password);
6273 run_system(dut, buf);
6274 } else {
6275 run_system(dut, "cfg -a AP_SECMODE_2=None");
6276 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
6277 run_system(dut, "cfg -r AP_AUTH_PORT_2");
6278 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
6279 }
6280
6281 run_system(dut, "cfg -a AP_STARTMODE=multi");
6282 }
6283
6284 run_system(dut, "cfg -c");
6285
6286 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
6287 if (system("apup") != 0) {
6288 /* to be debugged why apup returns error
6289 send_resp(dut, conn, SIGMA_ERROR,
6290 "errorCode,apup failed");
6291 return 0;
6292 */
6293 }
6294 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
6295
6296 if (dut->ap_key_mgmt != AP_OPEN) {
6297 int res;
6298 /* allow some time for hostapd to start before returning
6299 * success */
6300 usleep(500000);
6301 if (run_hostapd_cli(dut, "ping") != 0) {
6302 send_resp(dut, conn, SIGMA_ERROR,
6303 "errorCode,Failed to talk to hostapd");
6304 return 0;
6305 }
6306
6307 if (dut->ap_hs2 && !dut->ap_anqpserver) {
6308 /* the cfg app doesn't like ";" in the variables */
6309 res = ath_ap_append_hostapd_conf(dut);
6310 if (res < 0)
6311 return res;
6312
6313 /* wait for hostapd to be ready */
6314 usleep(500000);
6315 if (run_hostapd_cli(dut, "ping") != 0) {
6316 send_resp(dut, conn, SIGMA_ERROR,
6317 "errorCode,Failed to talk to "
6318 "hostapd");
6319 return 0;
6320 }
6321 }
6322 }
6323
6324 ath_ap_set_params(dut);
6325
6326 if (dut->ap_anqpserver)
6327 return cmd_ath_ap_anqpserver_start(dut);
6328
6329 if (dut->ap2_proxy_arp)
6330 run_system(dut, "iwpriv ath1 proxy_arp 1");
6331
6332 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
6333 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
6334 if (system(buf) != 0) {
6335 sigma_dut_print(dut, DUT_MSG_ERROR,
6336 "iwpriv htweptkip failed");
6337 }
6338 }
6339
6340 return 1;
6341}
6342
6343
6344static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
6345 const char *ifname)
6346{
6347 char buf[200];
6348
6349 if (!chain || !ifname)
6350 return -2;
6351
6352 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6353 if (system(buf) != 0) {
6354 sigma_dut_print(dut, DUT_MSG_ERROR,
6355 "Failed to set ebtables rules, RULE-1, %s",
6356 chain);
6357 return -2;
6358 }
6359
6360 snprintf(buf, sizeof(buf),
6361 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6362 chain, ifname);
6363 if (system(buf) != 0) {
6364 sigma_dut_print(dut, DUT_MSG_ERROR,
6365 "Failed to set ebtables rules, RULE-2, %s",
6366 chain);
6367 return -2;
6368 }
6369
6370 snprintf(buf, sizeof(buf),
6371 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
6372 chain, ifname);
6373 if (system(buf) != 0) {
6374 sigma_dut_print(dut, DUT_MSG_ERROR,
6375 "Failed to set ebtables rules, RULE-3, %s",
6376 chain);
6377 return -2;
6378 }
6379
6380 snprintf(buf, sizeof(buf),
6381 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
6382 chain, ifname);
6383 if (system(buf) != 0) {
6384 sigma_dut_print(dut, DUT_MSG_ERROR,
6385 "Failed to set ebtables rules, RULE-4, %s",
6386 chain);
6387 return -2;
6388 }
6389
6390 return 0;
6391}
6392
6393
6394static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
6395 const char *chain,
6396 const char *ifname)
6397{
6398 char buf[200];
6399
6400 if (!chain || !ifname)
6401 return -2;
6402
6403 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6404 if (system(buf) != 0) {
6405 sigma_dut_print(dut, DUT_MSG_ERROR,
6406 "Failed to set ebtables rules, RULE-5, %s",
6407 chain);
6408 return -2;
6409 }
6410
6411 snprintf(buf, sizeof(buf),
6412 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6413 chain, ifname);
6414 if (system(buf) != 0) {
6415 sigma_dut_print(dut, DUT_MSG_ERROR,
6416 "Failed to set ebtables rules, RULE-6, %s",
6417 chain);
6418 return -2;
6419 }
6420
6421 snprintf(buf, sizeof(buf),
6422 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
6423 chain, ifname);
6424 if (system(buf) != 0) {
6425 sigma_dut_print(dut, DUT_MSG_ERROR,
6426 "Failed to set ebtables rules, RULE-7, %s",
6427 chain);
6428 return -2;
6429 }
6430
6431 snprintf(buf, sizeof(buf),
6432 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
6433 chain, ifname);
6434 if (system(buf) != 0) {
6435 sigma_dut_print(dut, DUT_MSG_ERROR,
6436 "Failed to set ebtables rules, RULE-8, %s",
6437 chain);
6438 return -2;
6439 }
6440
6441 return 0;
6442}
6443
6444
Jouni Malinendbbc2c42018-11-14 23:55:41 +02006445static void set_ebtables_forward_drop(struct sigma_dut *dut,
6446 const char *ifname, const char *ifname2)
6447{
6448 char buf[128];
6449
6450 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6451 ifname, ifname2);
6452 if (system(buf) != 0)
6453 sigma_dut_print(dut, DUT_MSG_ERROR,
6454 "Failed to set ebtables rule");
6455
6456 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6457 ifname2, ifname);
6458 if (system(buf) != 0)
6459 sigma_dut_print(dut, DUT_MSG_ERROR,
6460 "Failed to set ebtables rule");
6461}
6462
6463
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006464static int check_channel(int channel)
6465{
6466 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
6467 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
6468 161, 165 };
6469 int num_chan = sizeof(channel_list) / sizeof(int);
6470 int i;
6471
6472 for (i = 0; i < num_chan; i++) {
6473 if (channel == channel_list[i])
6474 return i;
6475 }
6476
6477 return -1;
6478}
6479
6480
6481static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
6482{
6483 int ch_base;
6484 int period;
6485
6486 if (check_channel(channel) < 0)
6487 return -1;
6488
6489 if (channel >= 36 && channel <= 64)
6490 ch_base = 36;
6491 else if (channel >= 100 && channel <= 144)
6492 ch_base = 100;
6493 else
6494 ch_base = 149;
6495
6496 period = channel % ch_base * 5 / chwidth;
6497 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
6498}
6499
6500
6501static int is_ht40plus_chan(int chan)
6502{
6503 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
6504 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
6505 chan == 132 || chan == 149 || chan == 157;
6506}
6507
6508
6509static int is_ht40minus_chan(int chan)
6510{
6511 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
6512 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
6513 chan == 136 || chan == 153 || chan == 161;
6514}
6515
6516
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05306517static int get_5g_channel_freq(int chan)
6518{
6519 return 5000 + chan * 5;
6520}
6521
6522
Jouni Malinen3d633da2017-09-14 22:19:21 +03006523static const char * hostapd_cipher_name(enum ap_cipher cipher)
6524{
6525 switch (cipher) {
6526 case AP_CCMP:
6527 return "CCMP";
6528 case AP_TKIP:
6529 return "TKIP";
6530 case AP_CCMP_TKIP:
6531 return "CCMP TKIP";
6532 case AP_GCMP_256:
6533 return "GCMP-256";
6534 case AP_GCMP_128:
6535 return "GCMP";
6536 case AP_CCMP_256:
6537 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02006538 case AP_CCMP_128_GCMP_256:
6539 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006540 default:
6541 return "UNKNOWN";
6542 }
6543}
6544
6545
6546static const char *
6547hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
6548{
6549 switch (cipher) {
6550 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03006551 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006552 case AP_BIP_CMAC_256:
6553 return "BIP-CMAC-256";
6554 case AP_BIP_GMAC_128:
6555 return "BIP-GMAC-128";
6556 case AP_BIP_CMAC_128:
6557 return "AES-128-CMAC";
6558 default:
6559 return "UNKNOWN";
6560 }
6561}
6562
6563
Jouni Malinena326d7b2017-09-04 13:46:02 +03006564int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
6565 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006566{
6567 /* const char *name = get_param(cmd, "NAME"); */
6568 FILE *f;
6569 const char *ifname;
6570 char buf[500];
6571 char path[100];
6572 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03006573 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05306574#ifdef ANDROID
6575 struct group *gr;
6576#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006577
6578 drv = get_driver_type();
6579
6580 if (dut->mode == SIGMA_MODE_STATION) {
6581 stop_sta_mode(dut);
6582 sleep(1);
6583 }
6584
6585 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
6586 snprintf(buf, sizeof(buf), "ifconfig %s down",
6587 dut->sniffer_ifname);
6588 if (system(buf) != 0) {
6589 sigma_dut_print(dut, DUT_MSG_INFO,
6590 "Failed to run '%s'", buf);
6591 }
6592 snprintf(buf, sizeof(buf), "iw dev %s set type station",
6593 dut->sniffer_ifname);
6594 if (system(buf) != 0) {
6595 sigma_dut_print(dut, DUT_MSG_INFO,
6596 "Failed to run '%s'", buf);
6597 }
6598 }
6599
6600 dut->mode = SIGMA_MODE_AP;
6601
6602 if (drv == DRIVER_ATHEROS)
6603 return cmd_ath_ap_config_commit(dut, conn, cmd);
6604 if (drv == DRIVER_WCN)
6605 return cmd_wcn_ap_config_commit(dut, conn, cmd);
6606 if (drv == DRIVER_OPENWRT)
6607 return cmd_owrt_ap_config_commit(dut, conn, cmd);
6608
6609 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
6610 if (f == NULL) {
6611 sigma_dut_print(dut, DUT_MSG_ERROR,
6612 "%s: Failed to open sigma_dut-ap.conf",
6613 __func__);
6614 return -2;
6615 }
6616 switch (dut->ap_mode) {
6617 case AP_11g:
6618 case AP_11b:
6619 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306620 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
6621 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
6622 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006623 ifname = sigma_main_ifname;
6624 fprintf(f, "hw_mode=g\n");
6625 break;
6626 case AP_11a:
6627 case AP_11na:
6628 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306629 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006630 if (sigma_main_ifname)
6631 ifname = sigma_main_ifname;
6632 else
6633 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306634 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006635 if (if_nametoindex("wlan1") > 0)
6636 ifname = "wlan1";
6637 else
6638 ifname = "wlan0";
6639 } else {
6640 ifname = get_main_ifname();
6641 }
6642 fprintf(f, "hw_mode=a\n");
6643 break;
6644 default:
6645 fclose(f);
6646 return -1;
6647 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006648 if (dut->hostapd_ifname)
6649 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006650
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306651 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006652 fprintf(f, "driver=nl80211\n");
6653
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306654 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6655 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006656 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05306657 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
6658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006659 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306660 if (dut->ap_mode == AP_11ng &&
6661 (dut->ap_chwidth == AP_40 ||
6662 (dut->ap_chwidth == AP_AUTO &&
6663 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006664 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306665 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006666 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306667 ht40minus = 1;
6668 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006669 }
6670
6671 /* configure ht_capab based on channel width */
6672 if (dut->ap_mode == AP_11na &&
6673 (dut->ap_chwidth == AP_40 ||
6674 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306675 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006676 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306677 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006678 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306679 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006680 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306681
6682 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306683 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306684
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306685 /* Overwrite the ht_capab with offset value if configured */
6686 if (dut->ap_chwidth == AP_40 &&
6687 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
6688 ht40plus = 1;
6689 ht40minus = 0;
6690 } else if (dut->ap_chwidth == AP_40 &&
6691 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
6692 ht40minus = 1;
6693 ht40plus = 0;
6694 }
6695
Tamizh chelvam431c6002017-03-07 17:07:16 +05306696 fprintf(f, "ht_capab=%s%s%s\n",
6697 ht40plus ? "[HT40+]" : "",
6698 ht40minus ? "[HT40-]" : "",
6699 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006700 }
6701
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306702 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6703 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006704 dut->ap_mode == AP_11ac) {
6705 fprintf(f, "ieee80211ac=1\n"
6706 "ieee80211n=1\n"
6707 "ht_capab=[HT40+]\n");
6708 }
6709
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306710 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6711 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006712 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
6713 if (dut->ap_countrycode[0]) {
6714 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
6715 fprintf(f, "ieee80211d=1\n");
6716 fprintf(f, "ieee80211h=1\n");
6717 }
6718 }
6719
6720 fprintf(f, "interface=%s\n", ifname);
6721 if (dut->bridge)
6722 fprintf(f, "bridge=%s\n", dut->bridge);
6723 fprintf(f, "channel=%d\n", dut->ap_channel);
6724
6725 if (sigma_hapd_ctrl)
6726 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
6727 else
6728 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
6729
6730 if (dut->ap_ssid[0])
6731 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6732 else
6733 fprintf(f, "ssid=QCA AP OOB\n");
6734 if (dut->ap_bcnint)
6735 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
6736
6737 switch (dut->ap_key_mgmt) {
6738 case AP_OPEN:
6739 if (dut->ap_cipher == AP_WEP)
6740 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
6741 break;
6742 case AP_WPA2_PSK:
6743 case AP_WPA2_PSK_MIXED:
6744 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006745 case AP_WPA2_SAE:
6746 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006747 case AP_WPA2_PSK_SHA256:
6748 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006749 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6750 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006751 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
6752 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
6753 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006754 fprintf(f, "wpa=2\n");
6755 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6756 fprintf(f, "wpa=3\n");
6757 else
6758 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03006759 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6760 key_mgmt = "SAE";
6761 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6762 key_mgmt = "WPA-PSK SAE";
6763 else
6764 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006765 switch (dut->ap_pmf) {
6766 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006767 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006768 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6769 break;
6770 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03006771 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006772 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6773 break;
6774 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006775 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6776 key_mgmt = "SAE";
6777 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6778 key_mgmt = "WPA-PSK-SHA256 SAE";
6779 else
6780 key_mgmt = "WPA-PSK-SHA256";
6781 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006782 break;
6783 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03006784 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
6785 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
6786 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
6787 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02006788 fprintf(f, "wpa_pairwise=%s\n",
6789 hostapd_cipher_name(dut->ap_cipher));
6790 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6791 fprintf(f, "group_cipher=%s\n",
6792 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03006793 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6794 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02006795 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
6796 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03006797 else
6798 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006799 break;
6800 case AP_WPA2_EAP:
6801 case AP_WPA2_EAP_MIXED:
6802 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006803 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006804 case AP_WPA2_EAP_SHA256:
6805 case AP_WPA2_FT_EAP:
6806 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006807 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006808 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006809 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
6810 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
6811 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
6812 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006813 fprintf(f, "wpa=2\n");
6814 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6815 fprintf(f, "wpa=3\n");
6816 else
6817 fprintf(f, "wpa=1\n");
6818 switch (dut->ap_pmf) {
6819 case AP_PMF_DISABLED:
6820 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
6821 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
6822 break;
6823 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006824 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
6825 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
6826 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6827 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828 break;
6829 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006830 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
6831 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6832 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006833 break;
6834 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03006835 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
6836 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
6837 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
6838 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
6839 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
6840 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02006841 fprintf(f, "wpa_pairwise=%s\n",
6842 hostapd_cipher_name(dut->ap_cipher));
6843 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6844 fprintf(f, "group_cipher=%s\n",
6845 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006846 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6847 if (dut->ap_radius_port)
6848 fprintf(f, "auth_server_port=%d\n",
6849 dut->ap_radius_port);
6850 fprintf(f, "auth_server_shared_secret=%s\n",
6851 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03006852 if (dut->program == PROGRAM_HS2_R3) {
6853 fprintf(f, "radius_das_port=3799\n");
6854 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
6855 dut->ap_radius_password);
6856 fprintf(f, "radius_das_require_event_timestamp=1\n");
6857 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006858 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006859 case AP_SUITEB:
6860 fprintf(f, "ieee8021x=1\n");
6861 fprintf(f, "wpa=2\n");
6862 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03006863 fprintf(f, "wpa_pairwise=%s\n",
6864 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02006865 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6866 fprintf(f, "group_cipher=%s\n",
6867 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03006868 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
6869 fprintf(f, "group_mgmt_cipher=%s\n",
6870 hostapd_group_mgmt_cipher_name(
6871 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03006872 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6873 if (dut->ap_radius_port)
6874 fprintf(f, "auth_server_port=%d\n",
6875 dut->ap_radius_port);
6876 fprintf(f, "auth_server_shared_secret=%s\n",
6877 dut->ap_radius_password);
6878 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006879 case AP_WPA2_OWE:
6880 fprintf(f, "wpa=2\n");
6881 fprintf(f, "wpa_key_mgmt=OWE\n");
6882 fprintf(f, "rsn_pairwise=%s\n",
6883 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03006884 if (dut->ap_sae_groups)
6885 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03006886 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03006887 case AP_OSEN:
6888 fprintf(f, "osen=1\n");
6889 fprintf(f, "disable_dgaf=1\n");
6890 fprintf(f, "wpa_pairwise=%s\n",
6891 hostapd_cipher_name(dut->ap_cipher));
6892 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6893 fprintf(f, "group_cipher=%s\n",
6894 hostapd_cipher_name(dut->ap_group_cipher));
6895 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6896 if (dut->ap_radius_port)
6897 fprintf(f, "auth_server_port=%d\n",
6898 dut->ap_radius_port);
6899 fprintf(f, "auth_server_shared_secret=%s\n",
6900 dut->ap_radius_password);
6901 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006902 }
6903
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05306904 if (dut->ap_rsn_preauth)
6905 fprintf(f, "rsn_preauth=1\n");
6906
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006907 switch (dut->ap_pmf) {
6908 case AP_PMF_DISABLED:
6909 break;
6910 case AP_PMF_OPTIONAL:
6911 fprintf(f, "ieee80211w=1\n");
Jouni Malinen1287cd72018-01-04 17:08:01 +02006912 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6913 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006914 break;
6915 case AP_PMF_REQUIRED:
6916 fprintf(f, "ieee80211w=2\n");
6917 break;
6918 }
6919
Jouni Malinen6be21c82018-08-01 18:47:24 +03006920 if (ap_ft_enabled(dut)) {
6921 unsigned char own_addr[ETH_ALEN];
6922
6923 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
6924 fprintf(f, "ft_over_ds=0\n");
6925 fprintf(f, "nas_identifier=nas1.example.com\n");
6926 if (get_hwaddr(ifname, own_addr) < 0) {
6927 memset(own_addr, 0, ETH_ALEN);
6928 own_addr[0] = 0x02;
6929 }
6930 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
6931 own_addr[0], own_addr[1], own_addr[2],
6932 own_addr[3], own_addr[4], own_addr[5]);
6933 fprintf(f, "ft_psk_generate_local=1\n");
6934 fprintf(f, "pmk_r1_push=0\n");
6935 fprintf(f,
6936 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
6937 fprintf(f,
6938 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
6939 }
6940
Jouni Malinen3c367e82017-06-23 17:01:47 +03006941 if (dut->rsne_override)
6942 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
6943
Jouni Malinen68143132017-09-02 02:34:08 +03006944 if (dut->sae_commit_override)
6945 fprintf(f, "sae_commit_override=%s\n",
6946 dut->sae_commit_override);
6947
Jouni Malinened670f42017-08-31 01:39:28 +03006948 if (dut->ap_sae_groups)
6949 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03006950
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006951 if (dut->sae_anti_clogging_threshold >= 0)
6952 fprintf(f, "sae_anti_clogging_threshold=%d\n",
6953 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03006954 if (dut->sae_reflection)
6955 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006956
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006957 if (dut->ap_p2p_mgmt)
6958 fprintf(f, "manage_p2p=1\n");
6959
6960 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
6961 fprintf(f, "tdls_prohibit=1\n");
6962 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
6963 fprintf(f, "tdls_prohibit_chan_switch=1\n");
6964 if (dut->ap_p2p_cross_connect >= 0) {
6965 fprintf(f, "manage_p2p=1\n"
6966 "allow_cross_connection=%d\n",
6967 dut->ap_p2p_cross_connect);
6968 }
6969
Jouni Malinen4d479c92018-11-06 00:43:36 +02006970 if (dut->ap_l2tif || dut->ap_proxy_arp ||
6971 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006972 if (!dut->bridge) {
6973 sigma_dut_print(dut, DUT_MSG_ERROR,
6974 "Bridge must be configured. Run with -b <brname>.");
6975 fclose(f);
6976 return -2;
6977 }
6978 fprintf(f, "ap_isolate=1\n");
6979 }
6980
6981 if (dut->ap_proxy_arp)
6982 fprintf(f, "proxy_arp=1\n");
6983
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306984 if (dut->ap_wme)
6985 fprintf(f, "wmm_enabled=1\n");
6986
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306987 if (dut->ap_wmmps == AP_WMMPS_ON)
6988 fprintf(f, "uapsd_advertisement_enabled=1\n");
6989
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006990 if (dut->ap_hs2) {
6991 if (dut->ap_bss_load) {
6992 char *bss_load;
6993
6994 switch (dut->ap_bss_load) {
6995 case -1:
6996 bss_load = "bss_load_update_period=10";
6997 break;
6998 case 1:
6999 /* STA count: 1, CU: 50, AAC: 65535 */
7000 bss_load = "bss_load_test=1:50:65535";
7001 break;
7002 case 2:
7003 /* STA count: 1, CU: 200, AAC: 65535 */
7004 bss_load = "bss_load_test=1:200:65535";
7005 break;
7006 case 3:
7007 /* STA count: 1, CU: 75, AAC: 65535 */
7008 bss_load = "bss_load_test=1:75:65535";
7009 break;
7010 default:
7011 bss_load = NULL;
7012 break;
7013 }
7014
7015 if (!bss_load) {
7016 fclose(f);
7017 return -2;
7018 }
7019 fprintf(f, "%s\n", bss_load);
7020 }
7021
7022 if (append_hostapd_conf_hs2(dut, f)) {
7023 fclose(f);
7024 return -2;
7025 }
7026 }
7027
7028 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
7029 fclose(f);
7030 return -2;
7031 }
7032
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007033 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007034 unsigned char bssid[6];
7035 char ifname2[50];
7036
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307037 if (get_hwaddr(ifname, bssid)) {
7038 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007039 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307040 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03007041 if (bssid[0] & 0x02)
7042 bssid[5] ^= 0x01;
7043 else
7044 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007045
7046 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03007047 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007048 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007049 if (dut->bridge)
7050 fprintf(f, "bridge=%s\n", dut->bridge);
7051 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7052 bssid[0], bssid[1], bssid[2], bssid[3],
7053 bssid[4], bssid[5]);
7054
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007055 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007056 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05307057 /* Disable DGAF for OSEN BSS */
7058 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007059 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007060 if (strlen(dut->ap2_radius_ipaddr))
7061 fprintf(f, "auth_server_addr=%s\n",
7062 dut->ap2_radius_ipaddr);
7063 if (dut->ap2_radius_port)
7064 fprintf(f, "auth_server_port=%d\n",
7065 dut->ap2_radius_port);
7066 if (strlen(dut->ap2_radius_password))
7067 fprintf(f, "auth_server_shared_secret=%s\n",
7068 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007069
7070 set_ebtables_forward_drop(dut, ifname, ifname2);
7071 } else if (dut->ap2_osu) {
7072 fprintf(f, "ap_isolate=1\n");
7073 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007074 }
7075
7076 if (dut->ap2_proxy_arp) {
7077 if (!dut->bridge) {
7078 sigma_dut_print(dut, DUT_MSG_ERROR,
7079 "Bridge must be configured. Run with -b <brname>.");
7080 fclose(f);
7081 return -2;
7082 }
7083 fprintf(f, "ap_isolate=1\n");
7084 fprintf(f, "proxy_arp=1\n");
7085
7086 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
7087 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
7088 fclose(f);
7089 return -2;
7090 }
7091
7092 }
7093 }
7094
7095 if (dut->program == PROGRAM_WPS) {
7096 fprintf(f, "eap_server=1\n"
7097 "wps_state=1\n"
7098 "device_name=QCA AP\n"
7099 "manufacturer=QCA\n"
7100 "device_type=6-0050F204-1\n"
7101 "config_methods=label virtual_display "
7102 "virtual_push_button keypad%s\n"
7103 "ap_pin=12345670\n"
7104 "friendly_name=QCA Access Point\n"
7105 "upnp_iface=%s\n",
7106 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
7107 dut->bridge ? dut->bridge : ifname);
7108 }
7109
7110 if (dut->program == PROGRAM_VHT) {
7111 int vht_oper_centr_freq_idx;
7112
7113 if (check_channel(dut->ap_channel) < 0) {
7114 send_resp(dut, conn, SIGMA_INVALID,
7115 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307116 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007117 return 0;
7118 }
7119
7120 switch (dut->ap_chwidth) {
7121 case AP_20:
7122 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7123 vht_oper_centr_freq_idx =
7124 get_oper_centr_freq_seq_idx(20,
7125 dut->ap_channel);
7126 break;
7127 case AP_40:
7128 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7129 vht_oper_centr_freq_idx =
7130 get_oper_centr_freq_seq_idx(40,
7131 dut->ap_channel);
7132 break;
7133 case AP_80:
7134 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
7135 vht_oper_centr_freq_idx =
7136 get_oper_centr_freq_seq_idx(80,
7137 dut->ap_channel);
7138 break;
7139 case AP_160:
7140 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
7141 vht_oper_centr_freq_idx =
7142 get_oper_centr_freq_seq_idx(160,
7143 dut->ap_channel);
7144 break;
7145 default:
7146 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
7147 vht_oper_centr_freq_idx =
7148 get_oper_centr_freq_seq_idx(80,
7149 dut->ap_channel);
7150 break;
7151 }
7152 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
7153 vht_oper_centr_freq_idx);
7154 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
7155
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007156 if (dut->ap_sgi80 || dut->ap_txBF ||
7157 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307158 dut->ap_tx_stbc || dut->ap_mu_txBF) {
7159 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007160 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05307161 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05307162 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007163 (dut->ap_ldpc == VALUE_ENABLED) ?
7164 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307165 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
7166 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007167 }
7168 }
7169
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007170 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
7171 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
7172 /* OWE transition mode */
7173 unsigned char bssid[6];
7174 char ifname2[50];
7175 unsigned long val;
7176 FILE *f2;
7177
7178 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7179
7180 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7181 val = 0x12345678; /* default to something */
7182 f2 = fopen("/dev/urandom", "r");
7183 if (f2) {
7184 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7185 sigma_dut_print(dut, DUT_MSG_ERROR,
7186 "Could not read /dev/urandom");
7187 }
7188 fclose(f2);
7189 }
7190 fprintf(f, "ssid=owe-%lx\n", val);
7191
7192 if (get_hwaddr(ifname, bssid)) {
7193 fclose(f);
7194 return -2;
7195 }
7196 if (bssid[0] & 0x02)
7197 bssid[5] ^= 0x01;
7198 else
7199 bssid[0] |= 0x02;
7200
7201 fprintf(f, "bss=%s\n", ifname2);
7202 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7203 if (dut->bridge)
7204 fprintf(f, "bridge=%s\n", dut->bridge);
7205 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7206 bssid[0], bssid[1], bssid[2], bssid[3],
7207 bssid[4], bssid[5]);
7208 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7209 }
7210
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007211 if (dut->ap_key_mgmt == AP_OPEN &&
7212 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
7213 /* OWE transition mode */
7214 unsigned char bssid[6];
7215 char ifname2[50];
7216 unsigned long val;
7217 FILE *f2;
7218
7219 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7220
7221 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7222 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7223
7224 if (get_hwaddr(ifname, bssid)) {
7225 fclose(f);
7226 return -2;
7227 }
7228 if (bssid[0] & 0x02)
7229 bssid[5] ^= 0x01;
7230 else
7231 bssid[0] |= 0x02;
7232
7233 fprintf(f, "bss=%s\n", ifname2);
7234 val = 0x12345678; /* default to something */
7235 f2 = fopen("/dev/urandom", "r");
7236 if (f2) {
7237 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7238 sigma_dut_print(dut, DUT_MSG_ERROR,
7239 "Could not read /dev/urandom");
7240 }
7241 fclose(f2);
7242 }
7243 fprintf(f, "ssid=owe-%lx\n", val);
7244 if (dut->bridge)
7245 fprintf(f, "bridge=%s\n", dut->bridge);
7246 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7247 bssid[0], bssid[1], bssid[2], bssid[3],
7248 bssid[4], bssid[5]);
7249 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7250 fprintf(f, "wpa=2\n");
7251 fprintf(f, "wpa_key_mgmt=OWE\n");
7252 fprintf(f, "rsn_pairwise=CCMP\n");
7253 fprintf(f, "ieee80211w=2\n");
7254 if (dut->ap_sae_groups)
7255 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
7256 }
7257
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307258 if (dut->program == PROGRAM_OCE) {
7259 fprintf(f, "oce=%d\n",
7260 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
7261 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007262 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007263 if (dut->use_hostapd_pid_file)
7264 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007265#ifdef __QNXNTO__
7266 if (system("slay hostapd") == 0)
7267#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007268 if (!dut->use_hostapd_pid_file &&
7269 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7270 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007271#endif /* __QNXNTO__ */
7272 {
7273 int i;
7274 /* Wait some time to allow hostapd to complete cleanup before
7275 * starting a new process */
7276 for (i = 0; i < 10; i++) {
7277 usleep(500000);
7278#ifdef __QNXNTO__
7279 if (system("pidin | grep hostapd") != 0)
7280 break;
7281#else /* __QNXNTO__ */
7282 if (system("pidof hostapd") != 0)
7283 break;
7284#endif /* __QNXNTO__ */
7285 }
7286 }
Jouni Malinend86e5822017-08-29 03:55:32 +03007287 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007288
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307289#ifdef ANDROID
7290 /* Set proper conf file permissions so that hostapd process
7291 * can access it.
7292 */
7293 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
7294 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
7295 sigma_dut_print(dut, DUT_MSG_ERROR,
7296 "Error changing permissions");
7297
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307298 gr = getgrnam("wifi");
7299 if (!gr ||
7300 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307301 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
7302#endif /* ANDROID */
7303
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007304 if (drv == DRIVER_QNXNTO) {
7305 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05307306 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007307 "/sigma_dut-ap.conf",
7308 dut->hostapd_debug_log ? "-ddKt -f " : "",
7309 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007310 dut->hostapd_entropy_log ? " -e" : "",
7311 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
7312 "");
7313 } else {
7314 /*
7315 * It looks like a monitor interface can cause some issues for
7316 * beaconing, so remove it (if injection was used) before
7317 * starting hostapd.
7318 */
7319 if (if_nametoindex("sigmadut") > 0 &&
7320 system("iw dev sigmadut del") != 0)
7321 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7322 "monitor interface");
7323
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007324 snprintf(path, sizeof(path), "%shostapd",
7325 file_exists("hostapd") ? "./" : "");
7326 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007327 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007328 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007329 dut->hostapd_debug_log ? " -ddKt -f" : "",
7330 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
7331 dut->hostapd_entropy_log ? " -e" : "",
7332 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007333 "",
7334 dut->use_hostapd_pid_file ?
7335 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007336 }
7337
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007338 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007339 if (system(buf) != 0) {
7340 send_resp(dut, conn, SIGMA_ERROR,
7341 "errorCode,Failed to start hostapd");
7342 return 0;
7343 }
7344
7345 /* allow some time for hostapd to start before returning success */
7346 usleep(500000);
7347 if (run_hostapd_cli(dut, "ping") != 0) {
7348 send_resp(dut, conn, SIGMA_ERROR,
7349 "errorCode,Failed to talk to hostapd");
7350 return 0;
7351 }
7352
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05307353 if (drv == DRIVER_LINUX_WCN) {
7354 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
7355 ap_inet_addr, ap_inet_mask);
7356 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
7357 ifname, ap_inet_addr, ap_inet_mask);
7358 if (system(buf) != 0) {
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "Failed to initialize the interface");
7361 return -1;
7362 }
7363 }
7364
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007365 if (dut->ap_l2tif) {
7366 snprintf(path, sizeof(path),
7367 "/sys/class/net/%s/brport/hairpin_mode",
7368 ifname);
7369 if (!file_exists(path)) {
7370 sigma_dut_print(dut, DUT_MSG_ERROR,
7371 "%s must be binded to the bridge for L2TIF",
7372 ifname);
7373 return -2;
7374 }
7375
7376 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
7377 if (system(buf) != 0) {
7378 sigma_dut_print(dut, DUT_MSG_ERROR,
7379 "Failed to enable hairpin_mode for L2TIF");
7380 return -2;
7381 }
7382
7383 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
7384 if (system(buf) != 0) {
7385 sigma_dut_print(dut, DUT_MSG_ERROR,
7386 "Failed to set ebtables rules, RULE-9");
7387 return -2;
7388 }
7389
7390 snprintf(buf, sizeof(buf),
7391 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
7392 ifname);
7393 if (system(buf) != 0) {
7394 sigma_dut_print(dut, DUT_MSG_ERROR,
7395 "Failed to set ebtables rules, RULE-11");
7396 return -2;
7397 }
7398 }
7399
7400 if (dut->ap_proxy_arp) {
7401 if (dut->ap_dgaf_disable) {
7402 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
7403 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
7404 return -2;
7405 } else {
7406 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
7407 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
7408 return -2;
7409 }
7410
7411 /* For 4.5-(c) */
7412 snprintf(buf, sizeof(buf),
7413 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
7414 ifname);
7415 if (system(buf) != 0) {
7416 sigma_dut_print(dut, DUT_MSG_ERROR,
7417 "Failed to set ebtables rules, RULE-10");
7418 return -2;
7419 }
7420 }
7421
7422 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
7423 /* Drop TDLS frames */
7424 snprintf(buf, sizeof(buf),
7425 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
7426 if (system(buf) != 0) {
7427 sigma_dut_print(dut, DUT_MSG_ERROR,
7428 "Failed to set ebtables rules, RULE-13");
7429 return -2;
7430 }
7431 }
7432
7433 if (dut->ap_fake_pkhash &&
7434 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
7435 send_resp(dut, conn, SIGMA_ERROR,
7436 "errorCode,Could not enable FakePubKey");
7437 return 0;
7438 }
7439
Jouni Malinend86e5822017-08-29 03:55:32 +03007440 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007441 return 1;
7442}
7443
7444
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307445static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
7446 struct qos_params *qos, const char *cwmin,
7447 const char *cwmax, const char *aifs,
7448 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007449{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307450 int val;
7451
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007452 if (cwmin) {
7453 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307454 val = atoi(cwmin);
7455 if (val < 0 || val > 15) {
7456 send_resp(dut, conn, SIGMA_INVALID,
7457 "errorCode,Invalid cwMin");
7458 return 0;
7459 }
7460 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007461 }
7462
7463 if (cwmax) {
7464 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307465 val = atoi(cwmax);
7466 if (val < 0 || val > 15) {
7467 send_resp(dut, conn, SIGMA_INVALID,
7468 "errorCode,Invalid cwMax");
7469 return 0;
7470 }
7471 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007472 }
7473
7474 if (aifs) {
7475 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307476 val = atoi(aifs);
7477 if (val < 1 || val > 255) {
7478 send_resp(dut, conn, SIGMA_INVALID,
7479 "errorCode,Invalid AIFS");
7480 return 0;
7481 }
7482 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007483 }
7484
7485 if (txop) {
7486 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307487 val = atoi(txop);
7488 if (val < 0 || val > 0xffff) {
7489 send_resp(dut, conn, SIGMA_INVALID,
7490 "errorCode,Invalid txop");
7491 return 0;
7492 }
7493 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007494 }
7495
7496 if (acm) {
7497 qos->ac = 1;
7498 qos->acm = strcasecmp(acm, "on") == 0;
7499 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307500
7501 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007502}
7503
7504
7505static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
7506 struct sigma_cmd *cmd)
7507{
7508 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307509 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
7510 get_param(cmd, "cwmin_VO"),
7511 get_param(cmd, "cwmax_VO"),
7512 get_param(cmd, "AIFS_VO"),
7513 get_param(cmd, "TXOP_VO"),
7514 get_param(cmd, "ACM_VO")) ||
7515 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
7516 get_param(cmd, "cwmin_VI"),
7517 get_param(cmd, "cwmax_VI"),
7518 get_param(cmd, "AIFS_VI"),
7519 get_param(cmd, "TXOP_VI"),
7520 get_param(cmd, "ACM_VI")) ||
7521 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
7522 get_param(cmd, "cwmin_BE"),
7523 get_param(cmd, "cwmax_BE"),
7524 get_param(cmd, "AIFS_BE"),
7525 get_param(cmd, "TXOP_BE"),
7526 get_param(cmd, "ACM_BE")) ||
7527 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
7528 get_param(cmd, "cwmin_BK"),
7529 get_param(cmd, "cwmax_BK"),
7530 get_param(cmd, "AIFS_BK"),
7531 get_param(cmd, "TXOP_BK"),
7532 get_param(cmd, "ACM_BK")))
7533 return 0;
7534
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007535 return 1;
7536}
7537
7538
7539static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
7540 struct sigma_cmd *cmd)
7541{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307542 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
7543 get_param(cmd, "cwmin_VO"),
7544 get_param(cmd, "cwmax_VO"),
7545 get_param(cmd, "AIFS_VO"),
7546 get_param(cmd, "TXOP_VO"),
7547 get_param(cmd, "ACM_VO")) ||
7548 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
7549 get_param(cmd, "cwmin_VI"),
7550 get_param(cmd, "cwmax_VI"),
7551 get_param(cmd, "AIFS_VI"),
7552 get_param(cmd, "TXOP_VI"),
7553 get_param(cmd, "ACM_VI")) ||
7554 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
7555 get_param(cmd, "cwmin_BE"),
7556 get_param(cmd, "cwmax_BE"),
7557 get_param(cmd, "AIFS_BE"),
7558 get_param(cmd, "TXOP_BE"),
7559 get_param(cmd, "ACM_BE")) ||
7560 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
7561 get_param(cmd, "cwmin_BK"),
7562 get_param(cmd, "cwmax_BK"),
7563 get_param(cmd, "AIFS_BK"),
7564 get_param(cmd, "TXOP_BK"),
7565 get_param(cmd, "ACM_BK")))
7566 return 0;
7567
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007568 return 1;
7569}
7570
7571
7572static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
7573{
7574 unsigned char bssid[6];
7575 char buf[100];
7576 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
7577 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
7578 run_system(dut, "cfg -a AP_SECMODE=WPA");
7579 run_system(dut, "cfg -a AP_SECFILE=EAP");
7580 run_system(dut, "cfg -a AP_WPA=2");
7581 run_system(dut, "cfg -a AP_CYPHER=CCMP");
7582 run_system(dut, "cfg -a AP_HOTSPOT=1");
7583 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
7584 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
7585 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
7586 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
7587 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
7588 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
7589 if (!get_hwaddr("ath0", bssid)) {
7590 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7591 "%02x:%02x:%02x:%02x:%02x:%02x",
7592 bssid[0], bssid[1], bssid[2], bssid[3],
7593 bssid[4], bssid[5]);
7594 run_system(dut, buf);
7595 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7596 "%02x:%02x:%02x:%02x:%02x:%02x",
7597 bssid[0], bssid[1], bssid[2], bssid[3],
7598 bssid[4], bssid[5]);
7599 } else {
7600 if (!get_hwaddr("wifi0", bssid)) {
7601 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7602 "%02x:%02x:%02x:%02x:%02x:%02x",
7603 bssid[0], bssid[1], bssid[2], bssid[3],
7604 bssid[4], bssid[5]);
7605 run_system(dut, buf);
7606 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7607 "%02x:%02x:%02x:%02x:%02x:%02x",
7608 bssid[0], bssid[1], bssid[2], bssid[3],
7609 bssid[4], bssid[5]);
7610 } else {
7611 /* load the driver and try again */
7612 run_system(dut, "/etc/rc.d/rc.wlan up");
7613
7614 if (!get_hwaddr("wifi0", bssid)) {
7615 snprintf(buf, sizeof(buf),
7616 "cfg -a AP_HOTSPOT_HESSID="
7617 "%02x:%02x:%02x:%02x:%02x:%02x",
7618 bssid[0], bssid[1], bssid[2],
7619 bssid[3], bssid[4], bssid[5]);
7620 run_system(dut, buf);
7621 snprintf(dut->ap_hessid,
7622 sizeof(dut->ap_hessid),
7623 "%02x:%02x:%02x:%02x:%02x:%02x",
7624 bssid[0], bssid[1], bssid[2],
7625 bssid[3], bssid[4], bssid[5]);
7626 }
7627 }
7628 }
7629
7630 run_system(dut, "cfg -r AP_SSID_2");
7631 run_system(dut, "cfg -c");
7632 /* run_system(dut, "cfg -s"); */
7633}
7634
7635
7636static void ath_reset_vht_defaults(struct sigma_dut *dut)
7637{
7638 run_system(dut, "cfg -x");
7639 run_system(dut, "cfg -a AP_RADIO_ID=1");
7640 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
7641 run_system(dut, "cfg -a AP_STARTMODE=standard");
7642 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
7643 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
7644 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
7645 run_system(dut, "cfg -a ATH_countrycode=0x348");
7646 /* NOTE: For Beeliner we have to turn off MU-MIMO */
7647 if (system("rm /tmp/secath*") != 0) {
7648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "Failed to remove secath file");
7650 }
7651}
7652
7653
7654static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
7655 struct sigma_cmd *cmd)
7656{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307657 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307658 enum driver_type drv;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007659 int i;
7660
7661 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
7662 /*
7663 * Reset all tagged SSIDs to NULL-string and all key management
7664 * to open.
7665 */
7666 dut->ap_tag_ssid[i][0] = '\0';
7667 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
7668 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007669
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307670 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307671
7672 program = get_param(cmd, "program");
7673 if (!program)
7674 program = get_param(cmd, "prog");
7675 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007676 dut->device_type = AP_unknown;
7677 type = get_param(cmd, "type");
7678 if (type && strcasecmp(type, "Testbed") == 0)
7679 dut->device_type = AP_testbed;
7680 if (type && strcasecmp(type, "DUT") == 0)
7681 dut->device_type = AP_dut;
7682
7683 dut->ap_rts = 0;
7684 dut->ap_frgmnt = 0;
7685 dut->ap_bcnint = 0;
7686 dut->ap_key_mgmt = AP_OPEN;
7687 dut->ap_ssid[0] = '\0';
7688 dut->ap_fake_pkhash = 0;
7689 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
7690 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007691 dut->ap_addba_reject = VALUE_NOT_SET;
7692 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007693 dut->ap_is_dual = 0;
7694 dut->ap_mode = AP_inval;
7695 dut->ap_mode_1 = AP_inval;
7696
7697 dut->ap_allow_vht_wep = 0;
7698 dut->ap_allow_vht_tkip = 0;
7699 dut->ap_disable_protection = 0;
7700 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007701 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
7702 dut->ap_ldpc = VALUE_NOT_SET;
7703 dut->ap_sig_rts = VALUE_NOT_SET;
7704 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007705 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05307706 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007707 dut->ap_chwidth = AP_AUTO;
7708
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05307709 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007710 dut->ap_wpsnfc = 0;
7711 dut->ap_bss_load = -1;
7712 dut->ap_p2p_cross_connect = -1;
7713
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307714 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
7715 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307716 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307717
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007718 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007719 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08007720 dut->ap_interface_5g = 0;
7721 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08007722 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007723
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307724 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307725 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307726 dut->ap_wmmps = AP_WMMPS_ON;
7727 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307728 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307729 dut->ap_wmmps = AP_WMMPS_OFF;
7730 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307731
Jouni Malinen54a89b02018-05-01 00:16:26 +03007732 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03007733 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03007734 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03007735 dut->ap_tnc_file_name = 0;
7736 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03007737
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007738 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007739 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007740 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007741 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007742
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007743 if (drv == DRIVER_ATHEROS)
7744 cmd_ath_ap_hs2_reset(dut);
7745 else if (drv == DRIVER_OPENWRT)
7746 cmd_owrt_ap_hs2_reset(dut);
7747
7748 dut->ap_interworking = 1;
7749 dut->ap_access_net_type = 2;
7750 dut->ap_internet = 0;
7751 dut->ap_venue_group = 2;
7752 dut->ap_venue_type = 8;
7753 dut->ap_domain_name_list[0] = '\0';
7754 dut->ap_hs2 = 1;
7755 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
7756 "506f9a;001bc504bd");
7757 dut->ap_l2tif = 0;
7758 dut->ap_proxy_arp = 0;
7759 if (dut->bridge) {
7760 char buf[50];
7761
7762 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
7763 dut->bridge);
7764 if (system(buf) != 0) {
7765 sigma_dut_print(dut, DUT_MSG_DEBUG,
7766 "%s ip neigh table flushing failed",
7767 dut->bridge);
7768 }
7769
7770 snprintf(buf, sizeof(buf), "ebtables -F");
7771 if (system(buf) != 0) {
7772 sigma_dut_print(dut, DUT_MSG_DEBUG,
7773 "%s ebtables flushing failed",
7774 dut->bridge);
7775 }
7776 }
7777 dut->ap_dgaf_disable = 0;
7778 dut->ap_p2p_cross_connect = 0;
7779 dut->ap_gas_cb_delay = 0;
7780 dut->ap_nai_realm_list = 0;
7781 dut->ap_oper_name = 0;
7782 dut->ap_venue_name = 0;
7783 for (i = 0; i < 10; i++) {
7784 dut->ap_plmn_mcc[i][0] = '\0';
7785 dut->ap_plmn_mnc[i][0] = '\0';
7786 }
7787 dut->ap_wan_metrics = 0;
7788 dut->ap_conn_capab = 0;
7789 dut->ap_ip_addr_type_avail = 0;
7790 dut->ap_net_auth_type = 0;
7791 dut->ap_oper_class = 0;
7792 dut->ap_pmf = 0;
7793 dut->ap_add_sha256 = 0;
7794 }
7795
Jouni Malinenba630452018-06-22 11:49:59 +03007796 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
7797 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007798 int i;
7799 const char hessid[] = "50:6f:9a:00:11:22";
7800
7801 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
7802 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007803 dut->ap_pmf = 1;
7804 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02007805 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007806 for (i = 0; i < 10; i++) {
7807 dut->ap_osu_server_uri[i][0] = '\0';
7808 dut->ap_osu_method[i] = 0xFF;
7809 }
7810 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007811 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007812 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007813 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007814 dut->ap_osu_icon_tag = 0;
7815 }
7816
7817 if (dut->program == PROGRAM_VHT) {
7818 /* Set up the defaults */
7819 dut->ap_mode = AP_11ac;
7820 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007821 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08007822 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007823 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007824 dut->ap_amsdu = VALUE_DISABLED;
7825 dut->ap_ldpc = VALUE_DISABLED;
7826 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007827 dut->ap_sgi80 = 0;
7828 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007829 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307830 /*
7831 * As LDPC is optional, don't enable this by default
7832 * for LINUX-WCN driver. The ap_set_wireless command
7833 * can be used to enable LDPC, when needed.
7834 */
7835 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007836 dut->ap_ldpc = VALUE_ENABLED;
7837 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007838 dut->ap_sgi80 = 1;
7839 }
7840 dut->ap_fixed_rate = 0;
7841 dut->ap_rx_streams = 3;
7842 dut->ap_tx_streams = 3;
7843 dut->ap_vhtmcs_map = 0;
7844 dut->ap_chwidth = AP_80;
7845 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007846 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05307847 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
7848 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007849 if (get_driver_type() == DRIVER_ATHEROS)
7850 ath_reset_vht_defaults(dut);
7851 }
7852
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007853 if (dut->program == PROGRAM_IOTLP) {
7854 dut->wnm_bss_max_feature = VALUE_DISABLED;
7855 dut->wnm_bss_max_idle_time = 0;
7856 dut->wnm_bss_max_protection = VALUE_NOT_SET;
7857 dut->ap_proxy_arp = 1;
7858 } else {
7859 /*
7860 * Do not touch the BSS-MAX Idle time feature
7861 * if the program is not IOTLP.
7862 */
7863 dut->wnm_bss_max_feature = VALUE_NOT_SET;
7864 dut->wnm_bss_max_idle_time = 0;
7865 dut->wnm_bss_max_protection = VALUE_NOT_SET;
7866 }
7867
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007868 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07007869 dut->ap_rrm = 1;
7870 dut->ap_rtt = 1;
7871 dut->ap_lci = 0;
7872 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07007873 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07007874 dut->ap_lcr = 0;
7875 dut->ap_val_lcr[0] = '\0';
7876 dut->ap_neighap = 0;
7877 dut->ap_opchannel = 0;
7878 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07007879 dut->ap_fqdn_held = 0;
7880 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07007881 dut->ap_interworking = 0;
7882 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007883 dut->ap_msnt_type = 0;
7884 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007885 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07007886 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07007887 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007888
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007889 if (dut->program == PROGRAM_MBO) {
7890 dut->ap_mbo = 1;
7891 dut->ap_interworking = 1;
7892 dut->ap_ne_class = 0;
7893 dut->ap_ne_op_ch = 0;
7894 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007895 dut->ap_btmreq_disassoc_imnt = 0;
7896 dut->ap_btmreq_term_bit = 0;
7897 dut->ap_disassoc_timer = 0;
7898 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07007899 dut->ap_channel = 36;
7900 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07007901 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07007902 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007903 dut->mbo_self_ap_tuple.ap_ne_class = -1;
7904 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
7905 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08007906 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08007907 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007908 }
7909
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08007910 if (dut->program == PROGRAM_OCE) {
7911 if (dut->ap_dhcp_stop)
7912 run_system(dut, "/etc/init.d/dnsmasq start");
7913
7914 dut->ap_dhcp_stop = 0;
7915 dut->ap_oce = VALUE_ENABLED;
7916 dut->ap_broadcast_ssid = VALUE_ENABLED;
7917 dut->ap_fils_dscv_int = 20;
7918 dut->ap_filsdscv = VALUE_ENABLED;
7919 dut->ap_filshlp = VALUE_DISABLED;
7920 dut->ap_rnr = VALUE_DISABLED;
7921 dut->ap_nairealm[0] = '\0';
7922 dut->ap_nairealm_int = 0;
7923 dut->ap_blechanutil = 0;
7924 dut->ap_ble_admit_cap = 0;
7925 dut->ap_esp = VALUE_ENABLED;
7926 dut->ap_datappdudura = 0;
7927 dut->ap_airtimefract = 0;
7928 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08007929 dut->ap_ul_availcap = 0;
7930 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08007931 dut->ap_akm = 0;
7932 dut->ap_add_sha256 = 0;
7933 dut->ap_add_sha384 = 0;
7934 dut->ap_pmksa = 0;
7935 dut->ap_pmksa_caching = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08007936 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08007937 }
7938
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07007939 dut->ap_he_ppdu = PPDU_NOT_SET;
7940
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08007941 dut->ap_oper_chn = 0;
7942
Jouni Malinen3c367e82017-06-23 17:01:47 +03007943 free(dut->rsne_override);
7944 dut->rsne_override = NULL;
7945
Jouni Malinen68143132017-09-02 02:34:08 +03007946 free(dut->sae_commit_override);
7947 dut->sae_commit_override = NULL;
7948
Jouni Malinened670f42017-08-31 01:39:28 +03007949 free(dut->ap_sae_groups);
7950 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03007951
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007952 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03007953 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007954
Jouni Malinen3d633da2017-09-14 22:19:21 +03007955 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02007956 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03007957 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02007958 dut->ap_passphrase[0] = '\0';
7959 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03007960
Jouni Malinend86e5822017-08-29 03:55:32 +03007961 dut->dpp_conf_id = -1;
7962
7963 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08007964
7965 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
7966 return 1;
7967
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007968 if (dut->use_hostapd_pid_file) {
7969 kill_hostapd_process_pid(dut);
7970 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7971 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007972 int i;
7973 /* Wait some time to allow hostapd to complete cleanup before
7974 * starting a new process */
7975 for (i = 0; i < 10; i++) {
7976 usleep(500000);
7977 if (system("pidof hostapd") != 0)
7978 break;
7979 }
7980 }
7981
7982 if (if_nametoindex("sigmadut") > 0 &&
7983 system("iw dev sigmadut del") != 0)
7984 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7985 "monitor interface");
7986
7987 return 1;
7988}
7989
7990
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307991int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
7992 struct sigma_cmd *cmd)
7993{
7994 return cmd_ap_reset_default(dut, conn, cmd);
7995}
7996
7997
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007998static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
7999 struct sigma_cmd *cmd)
8000{
8001 /* const char *name = get_param(cmd, "NAME"); */
8002 struct stat s;
8003 char resp[200];
8004 FILE *f;
8005 enum driver_type drv = get_driver_type();
8006
8007 switch (drv) {
8008 case DRIVER_ATHEROS: {
8009 /* Atheros AP */
8010 struct utsname uts;
8011 char *version, athver[100];
8012
8013 if (stat("/proc/athversion", &s) != 0) {
8014 if (system("/etc/rc.d/rc.wlan up") != 0) {
8015 }
8016 }
8017
8018 athver[0] = '\0';
8019 f = fopen("/proc/athversion", "r");
8020 if (f) {
8021 if (fgets(athver, sizeof(athver), f)) {
8022 char *pos = strchr(athver, '\n');
8023 if (pos)
8024 *pos = '\0';
8025 }
8026 fclose(f);
8027 }
8028
8029 if (uname(&uts) == 0)
8030 version = uts.release;
8031 else
8032 version = "Unknown";
8033
8034 if (if_nametoindex("ath1") > 0)
8035 snprintf(resp, sizeof(resp), "interface,ath0_24G "
8036 "ath1_5G,agent,1.0,version,%s/drv:%s",
8037 version, athver);
8038 else
8039 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
8040 "agent,1.0,version,%s/drv:%s",
8041 version, athver);
8042
8043 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8044 return 0;
8045 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05308046 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008047 case DRIVER_MAC80211: {
8048 struct utsname uts;
8049 char *version;
8050
8051 if (uname(&uts) == 0)
8052 version = uts.release;
8053 else
8054 version = "Unknown";
8055
8056 if (if_nametoindex("wlan1") > 0)
8057 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
8058 "wlan1_5G,agent,1.0,version,%s", version);
8059 else
8060 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
8061 "agent,1.0,version,%s", version);
8062
8063 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8064 return 0;
8065 }
8066 case DRIVER_QNXNTO: {
8067 struct utsname uts;
8068 char *version;
8069
8070 if (uname(&uts) == 0)
8071 version = uts.release;
8072 else
8073 version = "Unknown";
8074 snprintf(resp, sizeof(resp),
8075 "interface,%s_any,agent,1.0,version,%s",
8076 sigma_main_ifname ? sigma_main_ifname : "NA",
8077 version);
8078 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8079 return 0;
8080 }
8081 case DRIVER_OPENWRT: {
8082 switch (get_openwrt_driver_type()) {
8083 case OPENWRT_DRIVER_ATHEROS: {
8084 struct utsname uts;
8085 char *version;
8086
8087 if (uname(&uts) == 0)
8088 version = uts.release;
8089 else
8090 version = "Unknown";
8091
8092 if (if_nametoindex("ath1") > 0)
8093 snprintf(resp, sizeof(resp),
8094 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
8095 version);
8096 else
8097 snprintf(resp, sizeof(resp),
8098 "interface,ath0_any,agent,1.0,version,%s",
8099 version);
8100
8101 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8102 return 0;
8103 }
8104 default:
8105 send_resp(dut, conn, SIGMA_ERROR,
8106 "errorCode,Unsupported openwrt driver");
8107 return 0;
8108 }
8109 }
8110 default:
8111 send_resp(dut, conn, SIGMA_ERROR,
8112 "errorCode,Unsupported driver");
8113 return 0;
8114 }
8115}
8116
8117
8118static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
8119 struct sigma_cmd *cmd)
8120{
8121 /* const char *name = get_param(cmd, "NAME"); */
8122 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8123 const char *val;
8124 char buf[100];
8125
8126 val = get_param(cmd, "MinorCode");
8127 if (val) {
8128 /* TODO: add support for P2P minor code */
8129 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
8130 "yet supported");
8131 return 0;
8132 }
8133
8134 val = get_param(cmd, "STA_MAC_ADDRESS");
8135 if (val == NULL)
8136 return -1;
8137 snprintf(buf, sizeof(buf), "deauth %s", val);
8138 if (run_hostapd_cli(dut, buf) != 0)
8139 return -2;
8140
8141 return 1;
8142}
8143
8144
8145#ifdef __linux__
8146int inject_frame(int s, const void *data, size_t len, int encrypt);
8147int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008148#endif /* __linux__ */
8149
8150enum send_frame_type {
8151 DISASSOC, DEAUTH, SAQUERY
8152};
8153enum send_frame_protection {
8154 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8155};
8156
8157
8158static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8159 enum send_frame_type frame,
8160 enum send_frame_protection protected,
8161 const char *sta_addr)
8162{
8163#ifdef __linux__
8164 unsigned char buf[1000], *pos;
8165 int s, res;
8166 unsigned char addr_sta[6], addr_own[6];
8167 char *ifname;
8168 char cbuf[100];
8169 struct ifreq ifr;
8170
8171 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
8172 dut->ap_mode == AP_11ac) &&
8173 if_nametoindex("wlan1") > 0)
8174 ifname = "wlan1";
8175 else
8176 ifname = "wlan0";
8177
8178 if (hwaddr_aton(sta_addr, addr_sta) < 0)
8179 return -1;
8180
8181 s = socket(AF_INET, SOCK_DGRAM, 0);
8182 if (s < 0)
8183 return -1;
8184 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07008185 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008186 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
8187 perror("ioctl");
8188 close(s);
8189 return -1;
8190 }
8191 close(s);
8192 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
8193
8194 if (if_nametoindex("sigmadut") == 0) {
8195 snprintf(cbuf, sizeof(cbuf),
8196 "iw dev %s interface add sigmadut type monitor",
8197 ifname);
8198 if (system(cbuf) != 0 ||
8199 if_nametoindex("sigmadut") == 0) {
8200 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8201 "monitor interface with '%s'", cbuf);
8202 return -2;
8203 }
8204 }
8205
8206 if (system("ifconfig sigmadut up") != 0) {
8207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8208 "monitor interface up");
8209 return -2;
8210 }
8211
8212 pos = buf;
8213
8214 /* Frame Control */
8215 switch (frame) {
8216 case DISASSOC:
8217 *pos++ = 0xa0;
8218 break;
8219 case DEAUTH:
8220 *pos++ = 0xc0;
8221 break;
8222 case SAQUERY:
8223 *pos++ = 0xd0;
8224 break;
8225 }
8226
8227 if (protected == INCORRECT_KEY)
8228 *pos++ = 0x40; /* Set Protected field to 1 */
8229 else
8230 *pos++ = 0x00;
8231
8232 /* Duration */
8233 *pos++ = 0x00;
8234 *pos++ = 0x00;
8235
8236 /* addr1 = DA (station) */
8237 memcpy(pos, addr_sta, 6);
8238 pos += 6;
8239 /* addr2 = SA (own address) */
8240 memcpy(pos, addr_own, 6);
8241 pos += 6;
8242 /* addr3 = BSSID (own address) */
8243 memcpy(pos, addr_own, 6);
8244 pos += 6;
8245
8246 /* Seq# (to be filled by driver/mac80211) */
8247 *pos++ = 0x00;
8248 *pos++ = 0x00;
8249
8250 if (protected == INCORRECT_KEY) {
8251 /* CCMP parameters */
8252 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8253 pos += 8;
8254 }
8255
8256 if (protected == INCORRECT_KEY) {
8257 switch (frame) {
8258 case DEAUTH:
8259 /* Reason code (encrypted) */
8260 memcpy(pos, "\xa7\x39", 2);
8261 pos += 2;
8262 break;
8263 case DISASSOC:
8264 /* Reason code (encrypted) */
8265 memcpy(pos, "\xa7\x39", 2);
8266 pos += 2;
8267 break;
8268 case SAQUERY:
8269 /* Category|Action|TransID (encrypted) */
8270 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8271 pos += 4;
8272 break;
8273 default:
8274 return -1;
8275 }
8276
8277 /* CCMP MIC */
8278 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8279 pos += 8;
8280 } else {
8281 switch (frame) {
8282 case DEAUTH:
8283 /* reason code = 8 */
8284 *pos++ = 0x08;
8285 *pos++ = 0x00;
8286 break;
8287 case DISASSOC:
8288 /* reason code = 8 */
8289 *pos++ = 0x08;
8290 *pos++ = 0x00;
8291 break;
8292 case SAQUERY:
8293 /* Category - SA Query */
8294 *pos++ = 0x08;
8295 /* SA query Action - Request */
8296 *pos++ = 0x00;
8297 /* Transaction ID */
8298 *pos++ = 0x12;
8299 *pos++ = 0x34;
8300 break;
8301 }
8302 }
8303
8304 s = open_monitor("sigmadut");
8305 if (s < 0) {
8306 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8307 "monitor socket");
8308 return 0;
8309 }
8310
8311 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8312 if (res < 0) {
8313 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8314 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308315 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008316 return 0;
8317 }
8318 if (res < pos - buf) {
8319 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8320 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308321 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008322 return 0;
8323 }
8324
8325 close(s);
8326
8327 return 1;
8328#else /* __linux__ */
8329 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
8330 "yet supported");
8331 return 0;
8332#endif /* __linux__ */
8333}
8334
8335
8336int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8337 struct sigma_cmd *cmd)
8338{
8339 const char *val, *dest;
8340 char buf[100];
8341
8342 val = get_param(cmd, "FrameName");
8343 if (val == NULL)
8344 return -1;
8345
8346 if (strcasecmp(val, "QoSMapConfigure") == 0) {
8347 dest = get_param(cmd, "Dest");
8348 if (!dest)
8349 return -1;
8350
8351 val = get_param(cmd, "QoS_MAP_SET");
8352 if (val) {
8353 dut->ap_qos_map_set = atoi(val);
8354 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8355 dut->ap_qos_map_set);
8356 }
8357
8358 if (dut->ap_qos_map_set == 1)
8359 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8360 else if (dut->ap_qos_map_set == 2)
8361 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8362
8363 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8364 if (run_hostapd_cli(dut, buf) != 0)
8365 return -1;
8366 }
8367
8368 return 1;
8369}
8370
8371
8372static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8373 struct sigma_cmd *cmd)
8374{
8375 const char *val;
8376 char *ifname;
8377 char buf[100];
8378 int chwidth, nss;
8379
8380 val = get_param(cmd, "FrameName");
8381 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
8382 send_resp(dut, conn, SIGMA_ERROR,
8383 "errorCode,Unsupported FrameName");
8384 return 0;
8385 }
8386
8387 /*
8388 * Sequence of commands for Opmode notification on
8389 * Peregrine based products
8390 */
8391 ifname = get_main_ifname();
8392
8393 /* Disable STBC */
8394 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
8395 if (system(buf) != 0) {
8396 sigma_dut_print(dut, DUT_MSG_ERROR,
8397 "iwpriv tx_stbc 0 failed!");
8398 }
8399
8400 /* Check whether optional arg channel width was passed */
8401 val = get_param(cmd, "Channel_width");
8402 if (val) {
8403 switch (atoi(val)) {
8404 case 20:
8405 chwidth = 0;
8406 break;
8407 case 40:
8408 chwidth = 1;
8409 break;
8410 case 80:
8411 chwidth = 2;
8412 break;
8413 case 160:
8414 chwidth = 3;
8415 break;
8416 default:
8417 chwidth = 2;
8418 break;
8419 }
8420 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8421 ifname, chwidth);
8422 if (system(buf) != 0) {
8423 sigma_dut_print(dut, DUT_MSG_ERROR,
8424 "iwpriv chwidth failed!");
8425 }
8426 }
8427
8428 /* Check whether optional arg NSS was passed */
8429 val = get_param(cmd, "NSS");
8430 if (val) {
8431 /* Convert nss to chainmask */
8432 switch (atoi(val)) {
8433 case 1:
8434 nss = 1;
8435 break;
8436 case 2:
8437 nss = 3;
8438 break;
8439 case 3:
8440 nss = 7;
8441 break;
8442 default:
8443 /* We do not support NSS > 3 */
8444 nss = 3;
8445 break;
8446 }
8447 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
8448 ifname, nss);
8449 if (system(buf) != 0) {
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "iwpriv rxchainmask failed!");
8452 }
8453 }
8454
8455 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03008456 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008457 if (system(buf) != 0) {
8458 sigma_dut_print(dut, DUT_MSG_ERROR,
8459 "iwpriv opmode_notify failed!");
8460 }
8461
8462 return 1;
8463}
8464
8465
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008466static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8467 struct sigma_cmd *cmd)
8468{
8469 const char *val;
8470 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008471 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008472
8473 val = get_param(cmd, "MsntType");
8474 if (val) {
8475 if (dut->ap_msnt_type == 0)
8476 dut->ap_msnt_type = atoi(val);
8477
8478 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
8479 dut->ap_msnt_type = atoi(val);
8480 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008481 val = get_param(cmd, "RandInterval");
8482 if (val)
8483 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008484 f = fopen("/tmp/ftmrr.txt", "a");
8485 if (!f) {
8486 sigma_dut_print(dut, DUT_MSG_ERROR,
8487 "Failed to open /tmp/ftmrr.txt");
8488 return -1;
8489 }
8490
8491 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008492 fprintf(f, "meas_type = 0x10\nrand_inter = 0x%x\nmin_ap_count = 0x%s\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0xf\nmeas_req_mode = 0x00\n",
8493 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008494 fclose(f);
8495 dut->ap_msnt_type = 5;
8496 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8497 }
8498 } else if (dut->ap_msnt_type == 5) {
8499 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8500 } else if (dut->ap_msnt_type == 2) {
8501 f = fopen("/tmp/wru.txt", "w");
8502 if (!f) {
8503 sigma_dut_print(dut, DUT_MSG_ERROR,
8504 "Failed to open /tmp/wru.txt");
8505 return -1;
8506 }
8507
8508 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
8509 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
8510 fclose(f);
8511 run_system(dut, "wpc -w /tmp/wru.txt");
8512 }
8513 }
8514 return 1;
8515}
8516
8517
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008518/*
8519 * The following functions parse_send_frame_params_int(),
8520 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
8521 * are used by ath_ap_send_frame_bcn_rpt_req().
8522 * Beacon Report Request is a frame used as part of the MBO program.
8523 * The command for sending beacon report has a lot of
8524 * arguments and having these functions reduces code size.
8525 *
8526 */
8527static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
8528 struct sigma_dut *dut,
8529 char *buf, size_t buf_size)
8530{
8531 const char *str_val;
8532 int int_val;
8533 char temp[100];
8534
8535 str_val = get_param(cmd, param);
8536 if (!str_val) {
8537 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8538 return -1;
8539 }
8540 int_val = atoi(str_val);
8541 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07008542 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008543 return 0;
8544}
8545
8546
8547static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
8548 struct sigma_dut *dut,
8549 char *buf, size_t buf_size)
8550{
8551 const char *str_val;
8552 char temp[100];
8553
8554 str_val = get_param(cmd, param);
8555 if (!str_val) {
8556 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8557 return -1;
8558 }
8559 snprintf(temp, sizeof(temp), " %s", str_val);
8560 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07008561 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008562 return 0;
8563}
8564
8565
8566static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
8567 struct sigma_dut *dut,
8568 char *buf, size_t buf_size)
8569{
8570 const char *str_val;
8571 unsigned char mac[6];
8572 char temp[100];
8573
8574 str_val = get_param(cmd, param);
8575 if (!str_val) {
8576 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8577 return -1;
8578 }
8579
8580 if (parse_mac_address(dut, str_val, mac) < 0) {
8581 sigma_dut_print(dut, DUT_MSG_ERROR,
8582 "MAC Address not in proper format");
8583 return -1;
8584 }
8585 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
8586 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07008587 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008588 return 0;
8589}
8590
8591
8592static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
8593 char *buf, size_t buf_size)
8594{
8595 const char *str_val;
8596 char *value = " 1";
8597
8598 str_val = get_param(cmd, param);
8599 if (!str_val || str_val[0] == '\0')
8600 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07008601 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008602
8603}
8604
8605
8606/*
8607 * wifitool athN sendbcnrpt
8608 * <STA MAC - Plugs in from Dest_MAC>
8609 * <regclass - Plugs in from RegClass - int>
8610 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
8611 * <rand_ivl - Plugs in from RandInt - string>
8612 * <duration - Plugs in from MeaDur - integer>
8613 * <mode - Plugs in from MeaMode - string>
8614 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
8615 * <rep_cond - Plugs in from RptCond - integer>
8616 * <rpt_detail - Plugs in from RptDet - integer>
8617 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
8618 * <chanrpt_mode - Plugs in from APChanRpt - integer>
8619 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
8620 * [AP channel numbers]
8621 */
8622static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
8623 struct sigma_cmd *cmd,
8624 const char *ifname)
8625{
8626 char buf[100];
8627 int rpt_det;
8628 const char *str_val;
8629 const char *mea_mode;
8630
8631 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
8632
8633 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
8634 return -1;
8635 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
8636 return -1;
8637 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
8638 return -1;
8639 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
8640 return -1;
8641 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
8642 return -1;
8643
8644 str_val = get_param(cmd, "MeaMode");
8645 if (!str_val) {
8646 sigma_dut_print(dut, DUT_MSG_ERROR,
8647 "MeaMode parameter not present in send bcn-rpt-req");
8648 return -1;
8649 }
8650 if (strcasecmp(str_val, "passive") == 0) {
8651 mea_mode = " 0";
8652 } else if (strcasecmp(str_val, "active") == 0) {
8653 mea_mode = " 1";
8654 } else if (strcasecmp(str_val, "table") == 0) {
8655 mea_mode = " 2";
8656 } else {
8657 sigma_dut_print(dut, DUT_MSG_ERROR,
8658 "MEA-MODE Value not correctly given");
8659 return -1;
8660 }
Peng Xu591be452017-05-10 17:27:28 -07008661 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008662
8663 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
8664
8665 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
8666 return -1;
8667
8668 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
8669 return -1;
8670 str_val = get_param(cmd, "RptDet");
8671 rpt_det = str_val ? atoi(str_val) : 0;
8672
8673 if (rpt_det)
8674 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
8675 else
Peng Xu591be452017-05-10 17:27:28 -07008676 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008677
8678 if (rpt_det)
8679 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
8680 sizeof(buf));
8681 else
Peng Xu591be452017-05-10 17:27:28 -07008682 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008683
8684 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
8685 return -1;
8686
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008687 str_val = get_param(cmd, "APChanRpt");
8688 if (str_val) {
8689 const char *pos;
8690 int ap_chanrpt;
8691 int ap_chanrpt_2 = 0;
8692 char chanrpt[100];
8693
8694 ap_chanrpt = atoi(str_val);
8695 pos = strchr(str_val, '_');
8696 if (pos) {
8697 pos++;
8698 ap_chanrpt_2 = atoi(pos);
8699 }
8700 if (ap_chanrpt) {
8701 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
8702 strlcat(buf, chanrpt, sizeof(buf));
8703 }
8704 if (ap_chanrpt_2) {
8705 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
8706 strlcat(buf, chanrpt, sizeof(buf));
8707 }
8708 }
8709
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008710 run_system(dut, buf);
8711 return 0;
8712}
8713
8714
8715static void inform_and_sleep(struct sigma_dut *dut, int seconds)
8716{
8717 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
8718 sleep(seconds);
8719 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
8720 seconds);
8721}
8722
8723
8724static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
8725 struct sigma_cmd *cmd, const char *ifname)
8726{
8727 unsigned char mac_addr[ETH_ALEN];
8728 int disassoc_timer;
8729 char buf[100];
8730 const char *val;
8731 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008732
8733 val = get_param(cmd, "Dest_MAC");
8734 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
8735 sigma_dut_print(dut, DUT_MSG_ERROR,
8736 "MAC Address not in proper format");
8737 return -1;
8738 }
8739
8740 val = get_param(cmd, "Disassoc_Timer");
8741 if (val)
8742 disassoc_timer = atoi(val);
8743 else
8744 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02008745 if (disassoc_timer < 0) {
8746 sigma_dut_print(dut, DUT_MSG_ERROR,
8747 "Invalid Disassoc_Timer value %d",
8748 disassoc_timer);
8749 return -1;
8750 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008751
8752 val = get_param(cmd, "Cand_List");
8753 if (val && val[0])
8754 cand_list = atoi(val);
8755
8756 val = get_param(cmd, "BTMQuery_Reason_Code");
8757 if (val) {
8758 snprintf(buf, sizeof(buf), "iwpriv %s mbo_trans_rs %s",
8759 ifname, val);
8760 run_system(dut, buf);
8761 }
8762
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008763 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay) {
8764 snprintf(buf, sizeof(buf), "iwpriv %s mbo_asoc_ret 1", ifname);
8765 run_system(dut, buf);
8766 }
8767
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008768 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008769 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008770 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
8771 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
8772 dut->ap_btmreq_disassoc_imnt,
8773 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008774 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008775 dut->ap_btmreq_bss_term_dur);
8776 run_system(dut, buf);
8777
8778 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008779 if (dut->ap_btmreq_bss_term_tsf >= 2)
8780 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008781 run_system_wrapper(
8782 dut, "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8783 ifname,
8784 mac_addr[0], mac_addr[1], mac_addr[2],
8785 mac_addr[3], mac_addr[4], mac_addr[5]);
8786 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008787 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008788 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008789 run_system_wrapper(dut, "ifconfig %s up", ifname);
8790 } else if (dut->ap_btmreq_disassoc_imnt) {
8791 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
8792 run_system_wrapper(dut,
8793 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8794 ifname,
8795 mac_addr[0], mac_addr[1], mac_addr[2],
8796 mac_addr[3], mac_addr[4], mac_addr[5]);
8797 }
8798 return 0;
8799}
8800
8801
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008802static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
8803 struct sigma_cmd *cmd, const char *ifname)
8804{
8805 unsigned char mac_addr[ETH_ALEN];
8806 const char *val;
8807
8808 val = get_param(cmd, "Dest_MAC");
8809 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
8810 sigma_dut_print(dut, DUT_MSG_ERROR,
8811 "MAC Address not in proper format");
8812 return -1;
8813 }
8814
8815 run_system_wrapper(dut,
8816 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8817 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
8818 mac_addr[3], mac_addr[4], mac_addr[5]);
8819 return 0;
8820}
8821
8822
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008823static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
8824 struct sigma_cmd *cmd)
8825{
8826 const char *val;
8827 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008828
8829 ifname = get_main_ifname();
8830
8831 val = get_param(cmd, "FrameName");
8832 if (!val)
8833 return -1;
8834
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008835 if (strcasecmp(val, "BTMReq") == 0)
8836 ath_ap_send_frame_btm_req(dut, cmd, ifname);
8837 else if (strcasecmp(val, "BcnRptReq") == 0)
8838 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008839 else if (strcasecmp(val, "disassoc") == 0)
8840 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008841 else
8842 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008843
8844 return 1;
8845}
8846
8847
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008848static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8849 struct sigma_cmd *cmd)
8850{
8851 switch (get_driver_type()) {
8852 case DRIVER_ATHEROS:
8853 return ath_ap_send_frame_vht(dut, conn, cmd);
8854 break;
8855 case DRIVER_OPENWRT:
8856 switch (get_openwrt_driver_type()) {
8857 case OPENWRT_DRIVER_ATHEROS:
8858 return ath_ap_send_frame_vht(dut, conn, cmd);
8859 default:
8860 send_resp(dut, conn, SIGMA_ERROR,
8861 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
8862 return 0;
8863 }
8864 default:
8865 send_resp(dut, conn, SIGMA_ERROR,
8866 "errorCode,Unsupported ap_send_frame with the current driver");
8867 return 0;
8868 }
8869}
8870
8871
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008872static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8873 struct sigma_cmd *cmd)
8874{
8875 switch (get_driver_type()) {
8876 case DRIVER_ATHEROS:
8877 return ath_ap_send_frame_loc(dut, conn, cmd);
8878 case DRIVER_OPENWRT:
8879 switch (get_openwrt_driver_type()) {
8880 case OPENWRT_DRIVER_ATHEROS:
8881 return ath_ap_send_frame_loc(dut, conn, cmd);
8882 default:
8883 send_resp(dut, conn, SIGMA_ERROR,
8884 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
8885 return 0;
8886 }
8887 default:
8888 send_resp(dut, conn, SIGMA_ERROR,
8889 "errorCode,Unsupported ap_send_frame_loc with the current driver");
8890 return 0;
8891 }
8892}
8893
8894
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008895static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
8896 struct sigma_cmd *cmd)
8897{
8898 switch (get_driver_type()) {
8899 case DRIVER_ATHEROS:
8900 return ath_ap_send_frame_mbo(dut, conn, cmd);
8901 case DRIVER_OPENWRT:
8902 switch (get_openwrt_driver_type()) {
8903 case OPENWRT_DRIVER_ATHEROS:
8904 return ath_ap_send_frame_mbo(dut, conn, cmd);
8905 default:
8906 send_resp(dut, conn, SIGMA_ERROR,
8907 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
8908 return 0;
8909 }
8910 default:
8911 send_resp(dut, conn, SIGMA_ERROR,
8912 "errorCode,Unsupported ap_send_frame with the current driver");
8913 return 0;
8914 }
8915}
8916
8917
Lior David0fe101e2017-03-09 16:09:50 +02008918static int ap_send_frame_60g(struct sigma_dut *dut,
8919 struct sigma_conn *conn,
8920 struct sigma_cmd *cmd)
8921{
8922 switch (get_driver_type()) {
8923#ifdef __linux__
8924 case DRIVER_WIL6210:
8925 return wil6210_send_frame_60g(dut, conn, cmd);
8926#endif /* __linux__ */
8927 default:
8928 send_resp(dut, conn, SIGMA_ERROR,
8929 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
8930 return 0;
8931 }
8932}
8933
8934
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008935int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8936 struct sigma_cmd *cmd)
8937{
8938 /* const char *name = get_param(cmd, "NAME"); */
8939 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8940 const char *val;
8941 enum send_frame_type frame;
8942 enum send_frame_protection protected;
8943 char buf[100];
8944
8945 val = get_param(cmd, "Program");
8946 if (val) {
8947 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008948 strcasecmp(val, "HS2-R2") == 0 ||
8949 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008950 return ap_send_frame_hs2(dut, conn, cmd);
8951 if (strcasecmp(val, "VHT") == 0)
8952 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008953 if (strcasecmp(val, "LOC") == 0)
8954 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008955 if (strcasecmp(val, "MBO") == 0)
8956 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02008957 if (strcasecmp(val, "60GHz") == 0)
8958 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008959 }
8960
8961 val = get_param(cmd, "PMFFrameType");
8962 if (val == NULL)
8963 val = get_param(cmd, "FrameName");
8964 if (val == NULL)
8965 val = get_param(cmd, "Type");
8966 if (val == NULL)
8967 return -1;
8968 if (strcasecmp(val, "disassoc") == 0)
8969 frame = DISASSOC;
8970 else if (strcasecmp(val, "deauth") == 0)
8971 frame = DEAUTH;
8972 else if (strcasecmp(val, "saquery") == 0)
8973 frame = SAQUERY;
8974 else {
8975 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8976 "PMFFrameType");
8977 return 0;
8978 }
8979
8980 val = get_param(cmd, "PMFProtected");
8981 if (val == NULL)
8982 val = get_param(cmd, "Protected");
8983 if (val == NULL)
8984 return -1;
8985 if (strcasecmp(val, "Correct-key") == 0 ||
8986 strcasecmp(val, "CorrectKey") == 0)
8987 protected = CORRECT_KEY;
8988 else if (strcasecmp(val, "IncorrectKey") == 0)
8989 protected = INCORRECT_KEY;
8990 else if (strcasecmp(val, "Unprotected") == 0)
8991 protected = UNPROTECTED;
8992 else {
8993 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8994 "PMFProtected");
8995 return 0;
8996 }
8997
8998 val = get_param(cmd, "stationID");
8999 if (val == NULL)
9000 return -1;
9001
9002 if (protected == INCORRECT_KEY ||
9003 (protected == UNPROTECTED && frame == SAQUERY))
9004 return ap_inject_frame(dut, conn, frame, protected, val);
9005
9006 switch (frame) {
9007 case DISASSOC:
9008 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
9009 val, protected == CORRECT_KEY);
9010 break;
9011 case DEAUTH:
9012 snprintf(buf, sizeof(buf), "deauth %s test=%d",
9013 val, protected == CORRECT_KEY);
9014 break;
9015 case SAQUERY:
9016 snprintf(buf, sizeof(buf), "sa_query %s", val);
9017 break;
9018 }
9019
9020 if (run_hostapd_cli(dut, buf) != 0)
9021 return -2;
9022
9023 return 1;
9024}
9025
9026
9027static int cmd_ap_get_mac_address(struct sigma_dut *dut,
9028 struct sigma_conn *conn,
9029 struct sigma_cmd *cmd)
9030{
9031#if defined( __linux__)
9032 /* const char *name = get_param(cmd, "NAME"); */
9033 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03009034 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009035 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009036 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009037 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009038 int s, wlan_tag = 1;
9039 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009040
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009041 val = get_param(cmd, "WLAN_TAG");
9042 if (val) {
9043 wlan_tag = atoi(val);
9044 if (wlan_tag < 1 || wlan_tag > 3) {
9045 /*
9046 * The only valid WLAN Tags as of now as per the latest
9047 * WFA scripts are 1, 2, and 3.
9048 */
Jouni Malinenf8984642017-10-12 00:02:37 +03009049 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009050 "errorCode,Unsupported WLAN_TAG");
9051 return 0;
9052 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009053 }
9054
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009055 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
9056
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009057 s = socket(AF_INET, SOCK_DGRAM, 0);
9058 if (s < 0)
9059 return -1;
9060 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009061 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009062 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9063 perror("ioctl");
9064 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03009065 snprintf(resp, sizeof(resp),
9066 "errorCode,Could not find interface %s", ifname);
9067 send_resp(dut, conn, SIGMA_ERROR, resp);
9068 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009069 }
9070 close(s);
9071 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
9072
9073 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9074 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9075 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9076 return 0;
9077#elif defined( __QNXNTO__)
9078 char resp[50];
9079 unsigned char addr[6];
9080
9081 if (!sigma_main_ifname) {
9082 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
9083 return 0;
9084 }
9085
9086 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
9087 send_resp(dut, conn, SIGMA_ERROR,
9088 "errorCode,Failed to get address");
9089 return 0;
9090 }
9091 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9092 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9093 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9094 return 0;
9095#else /* __linux__ */
9096 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
9097 "yet supported");
9098 return 0;
9099#endif /* __linux__ */
9100}
9101
9102
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309103int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
9104 struct sigma_cmd *cmd)
9105{
9106 return cmd_ap_get_mac_address(dut, conn, cmd);
9107}
9108
9109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009110static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
9111 struct sigma_cmd *cmd)
9112{
9113 /*
9114 * Ignore the command since the parameters are already handled through
9115 * ap_set_security.
9116 */
9117
9118 return 1;
9119}
9120
9121
9122static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
9123 struct sigma_cmd *cmd)
9124{
9125 /* const char *name = get_param(cmd, "NAME"); */
9126 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9127 const char *val, *dest;
9128 char *pos, buf[100];
9129 int i, wlan_tag = 1;
9130
9131 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
9132 "following parameters");
9133 for (i = 0; i < cmd->count; i++) {
9134 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
9135 (cmd->values[i] ? cmd->values[i] : "NULL"));
9136 }
9137
9138 val = get_param(cmd, "ICMPv4_ECHO");
9139 if (val && atoi(val)) {
9140 snprintf(buf, sizeof(buf), "ebtables -F");
9141 if (system(buf) != 0) {
9142 sigma_dut_print(dut, DUT_MSG_ERROR,
9143 "Failed to set ebtables rules, RULE-12");
9144 }
9145 return 1;
9146 }
9147
9148 val = get_param(cmd, "WLAN_TAG");
9149 if (val) {
9150 wlan_tag = atoi(val);
9151 if (wlan_tag != 1 && wlan_tag != 2) {
9152 send_resp(dut, conn, SIGMA_INVALID,
9153 "errorCode,Invalid WLAN_TAG");
9154 return 0;
9155 }
9156 }
9157
9158 if (wlan_tag == 2) {
9159 val = get_param(cmd, "PROXY_ARP");
9160 if (val)
9161 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02009162
9163 val = get_param(cmd, "OSU");
9164 if (val)
9165 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009166 return 1;
9167 }
9168
9169 dest = get_param(cmd, "STA_MAC");
9170 if (dest) {
9171 /* This is a special/ugly way of using this command.
9172 * If "Dest" MAC is included, assume that this command
9173 * is being issued after ap_config_commit for dynamically
9174 * setting the QoS Map Set.
9175 */
9176 val = get_param(cmd, "QoS_MAP_SET");
9177 if (val) {
9178 dut->ap_qos_map_set = atoi(val);
9179 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9180 dut->ap_qos_map_set);
9181 }
9182
9183 if (dut->ap_qos_map_set == 1)
9184 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9185 else if (dut->ap_qos_map_set == 2)
9186 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9187
9188 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9189 if (run_hostapd_cli(dut, buf) != 0)
9190 return -1;
9191 }
9192
9193 val = get_param(cmd, "DGAF_DISABLE");
9194 if (val)
9195 dut->ap_dgaf_disable = atoi(val);
9196
9197 dut->ap_interworking = 1;
9198
9199 val = get_param(cmd, "INTERWORKING");
9200 if (val == NULL)
9201 val = get_param(cmd, "INTERNETWORKING");
9202 if (val != NULL && atoi(val) == 0) {
9203 dut->ap_interworking = 0;
9204 dut->ap_hs2 = 0;
9205 return 1;
9206 }
9207
9208 val = get_param(cmd, "ACCS_NET_TYPE");
9209 if (val) {
9210 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
9211 strcasecmp(val, "Chargable_Public_Network") == 0 ||
9212 strcasecmp(val, "Chargable Public Network") == 0)
9213 dut->ap_access_net_type = 2;
9214 else
9215 dut->ap_access_net_type = atoi(val);
9216 }
9217
9218 val = get_param(cmd, "INTERNET");
9219 if (val)
9220 dut->ap_internet = atoi(val);
9221
9222 val = get_param(cmd, "VENUE_GRP");
9223 if (val) {
9224 if (strcasecmp(val, "Business") == 0)
9225 dut->ap_venue_group = 2;
9226 else
9227 dut->ap_venue_group = atoi(val);
9228 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9229 dut->ap_venue_name);
9230 }
9231
9232 val = get_param(cmd, "VENUE_TYPE");
9233 if (val) {
9234 if (strcasecmp(val, "R&D") == 0)
9235 dut->ap_venue_type = 8;
9236 else
9237 dut->ap_venue_type = atoi(val);
9238 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
9239 dut->ap_venue_type);
9240 }
9241
9242 val = get_param(cmd, "HESSID");
9243 if (val) {
9244 if (strlen(val) >= sizeof(dut->ap_hessid)) {
9245 send_resp(dut, conn, SIGMA_ERROR,
9246 "errorCode,Invalid HESSID");
9247 return 0;
9248 }
9249 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
9250 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
9251 dut->ap_hessid);
9252 }
9253
9254 val = get_param(cmd, "ROAMING_CONS");
9255 if (val) {
9256 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
9257 send_resp(dut, conn, SIGMA_ERROR,
9258 "errorCode,Invalid ROAMING_CONS");
9259 return 0;
9260 }
9261 if (strcasecmp(val, "Disabled") == 0) {
9262 dut->ap_roaming_cons[0] = '\0';
9263 } else {
9264 snprintf(dut->ap_roaming_cons,
9265 sizeof(dut->ap_roaming_cons), "%s", val);
9266 }
9267 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
9268 dut->ap_roaming_cons);
9269 }
9270
9271 val = get_param(cmd, "ANQP");
9272 if (val)
9273 dut->ap_anqpserver_on = atoi(val);
9274
9275 val = get_param(cmd, "NAI_REALM_LIST");
9276 if (val) {
9277 dut->ap_nai_realm_list = atoi(val);
9278 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
9279 dut->ap_nai_realm_list);
9280 }
9281
9282 val = get_param(cmd, "3GPP_INFO");
9283 if (val) {
9284 /* What kind of encoding format is used?! */
9285 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
9286 "not yet supported (contents not fully defined)");
9287 return 0;
9288 }
9289
9290 val = get_param(cmd, "DOMAIN_LIST");
9291 if (val) {
9292 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
9293 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
9294 "DOMAIN_LIST");
9295 return 0;
9296 }
9297 snprintf(dut->ap_domain_name_list,
9298 sizeof(dut->ap_domain_name_list), "%s", val);
9299 pos = dut->ap_domain_name_list;
9300 while (*pos) {
9301 if (*pos == ';')
9302 *pos = ',';
9303 pos++;
9304 }
9305 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
9306 dut->ap_domain_name_list);
9307 }
9308
9309 val = get_param(cmd, "OPER_NAME");
9310 if (val) {
9311 dut->ap_oper_name = atoi(val);
9312 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
9313 dut->ap_oper_name);
9314 }
9315
9316 val = get_param(cmd, "VENUE_NAME");
9317 if (val) {
9318 dut->ap_venue_name = atoi(val);
9319 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9320 dut->ap_venue_name);
9321 }
9322
9323 val = get_param(cmd, "GAS_CB_DELAY");
9324 if (val) {
9325 dut->ap_gas_cb_delay = atoi(val);
9326 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
9327 dut->ap_gas_cb_delay);
9328 }
9329
9330 val = get_param(cmd, "MIH");
9331 if (val && atoi(val) > 0) {
9332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
9333 "supported");
9334 return 0;
9335 }
9336
9337 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
9338 if (val) {
9339 dut->ap_l2tif = atoi(val);
9340 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
9341 dut->ap_l2tif);
9342 }
9343
9344 val = get_param(cmd, "BCST_UNCST");
9345 if (val) {
9346 send_resp(dut, conn, SIGMA_ERROR,
9347 "errorCode,BCST_UNCST not yet supported");
9348 return 0;
9349 }
9350
9351 val = get_param(cmd, "PLMN_MCC");
9352 if (val) {
9353 char mcc[100], *start, *end;
9354 int i = 0;
9355 if (strlen(val) >= sizeof(mcc)) {
9356 send_resp(dut, conn, SIGMA_ERROR,
9357 "errorCode,PLMN_MCC too long");
9358 return 0;
9359 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009360 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009361 start = mcc;
9362 while ((end = strchr(start, ';'))) {
9363 /* process all except the last */
9364 *end = '\0';
9365 if (strlen(start) != 3) {
9366 send_resp(dut, conn, SIGMA_ERROR,
9367 "errorCode,Invalid PLMN_MCC");
9368 return 0;
9369 }
9370 snprintf(dut->ap_plmn_mcc[i],
9371 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9372 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9373 dut->ap_plmn_mcc[i]);
9374 i++;
9375 start = end + 1;
9376 *end = ';';
9377 }
9378 if (strlen(start) != 3) {
9379 send_resp(dut, conn, SIGMA_ERROR,
9380 "errorCode,Invalid PLMN_MCC");
9381 return 0;
9382 }
9383 /* process last or only one */
9384 snprintf(dut->ap_plmn_mcc[i],
9385 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9386 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9387 dut->ap_plmn_mcc[i]);
9388 }
9389
9390 val = get_param(cmd, "PLMN_MNC");
9391 if (val) {
9392 char mnc[100], *start, *end;
9393 int i = 0;
9394 if (strlen(val) >= sizeof(mnc)) {
9395 send_resp(dut, conn, SIGMA_ERROR,
9396 "errorCode,PLMN_MNC too long");
9397 return 0;
9398 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009399 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009400 start = mnc;
9401 while ((end = strchr(start, ';'))) {
9402 *end = '\0';
9403 if (strlen(start) != 2 && strlen(start) != 3) {
9404 send_resp(dut, conn, SIGMA_ERROR,
9405 "errorCode,Invalid PLMN_MNC");
9406 return 0;
9407 }
9408 snprintf(dut->ap_plmn_mnc[i],
9409 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9410 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9411 dut->ap_plmn_mnc[i]);
9412 i++;
9413 start = end + 1;
9414 *end = ';';
9415 }
9416 if (strlen(start) != 2 && strlen(start) != 3) {
9417 send_resp(dut, conn, SIGMA_ERROR,
9418 "errorCode,Invalid PLMN_MNC");
9419 return 0;
9420 }
9421 snprintf(dut->ap_plmn_mnc[i],
9422 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9423 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9424 dut->ap_plmn_mnc[i]);
9425 }
9426
9427 val = get_param(cmd, "PROXY_ARP");
9428 if (val) {
9429 dut->ap_proxy_arp = atoi(val);
9430 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
9431 dut->ap_proxy_arp);
9432 }
9433
9434 val = get_param(cmd, "WAN_METRICS");
9435 if (val) {
9436 dut->ap_wan_metrics = atoi(val);
9437 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
9438 dut->ap_wan_metrics);
9439 }
9440
9441 val = get_param(cmd, "CONN_CAP");
9442 if (val) {
9443 dut->ap_conn_capab = atoi(val);
9444 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
9445 dut->ap_conn_capab);
9446 }
9447
9448 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
9449 if (val) {
9450 dut->ap_ip_addr_type_avail = atoi(val);
9451 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
9452 dut->ap_ip_addr_type_avail);
9453 }
9454
9455 val = get_param(cmd, "NET_AUTH_TYPE");
9456 if (val) {
9457 dut->ap_net_auth_type = atoi(val);
9458 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
9459 dut->ap_net_auth_type);
9460 }
9461
9462 val = get_param(cmd, "OP_CLASS");
9463 if (val == NULL)
9464 val = get_param(cmd, "OPER_CLASS");
9465 if (val) {
9466 dut->ap_oper_class = atoi(val);
9467 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
9468 dut->ap_oper_class);
9469 }
9470
9471 val = get_param(cmd, "OSU_PROVIDER_LIST");
9472 if (val) {
9473 dut->ap_osu_provider_list = atoi(val);
9474 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
9475 dut->ap_osu_provider_list);
9476 }
9477
Jouni Malinen93a837f2018-11-01 17:09:22 +02009478 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
9479 if (val) {
9480 dut->ap_osu_provider_nai_list = atoi(val);
9481 sigma_dut_print(dut, DUT_MSG_INFO,
9482 "ap_osu_provider_nai_list %d",
9483 dut->ap_osu_provider_nai_list);
9484 }
9485
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009486 val = get_param(cmd, "OSU_SERVER_URI");
9487 if (val) {
9488 i = 0;
9489 do {
9490 int len;
9491 const char *uri = val;
9492 val = strchr(val, ' ');
9493 len = val ? (val++ - uri) : (int) strlen(uri);
9494 if (len > 0 && len < 256) {
9495 memcpy(dut->ap_osu_server_uri[i], uri, len);
9496 dut->ap_osu_server_uri[i][len] = '\0';
9497 sigma_dut_print(dut, DUT_MSG_INFO,
9498 "ap_osu_server_uri[%d] %s", i,
9499 dut->ap_osu_server_uri[i]);
9500 }
9501 } while (val && ++i < 10);
9502 }
9503
9504 val = get_param(cmd, "OSU_METHOD");
9505 if (val) {
9506 i = 0;
9507 do {
9508 int len;
9509 const char *method = val;
9510 val = strchr(val, ' ');
9511 len = val ? (val++ - method) : (int) strlen(method);
9512 if (len > 0) {
9513 if (strncasecmp(method, "SOAP", len) == 0)
9514 dut->ap_osu_method[i] = 1;
9515 else if (strncasecmp(method, "OMADM", len) == 0)
9516 dut->ap_osu_method[i] = 0;
9517 else
9518 return -2;
9519 }
9520 } while (val && ++i < 10);
9521 }
9522
9523 val = get_param(cmd, "OSU_SSID");
9524 if (val) {
9525 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -07009526 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009527 sizeof(dut->ap_osu_ssid));
9528 sigma_dut_print(dut, DUT_MSG_INFO,
9529 "ap_osu_ssid %s",
9530 dut->ap_osu_ssid);
9531 }
9532 }
9533
9534 val = get_param(cmd, "OSU_ICON_TAG");
9535 if (val)
9536 dut->ap_osu_icon_tag = atoi(val);
9537
9538 val = get_param(cmd, "QoS_MAP_SET");
9539 if (val) {
9540 dut->ap_qos_map_set = atoi(val);
9541 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9542 dut->ap_qos_map_set);
9543 }
9544
9545 val = get_param(cmd, "BSS_LOAD");
9546 if (val) {
9547 dut->ap_bss_load = atoi(val);
9548 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
9549 dut->ap_bss_load);
9550 }
9551
Jouni Malinen54a89b02018-05-01 00:16:26 +03009552 val = get_param(cmd, "Venue_URL");
9553 if (val)
9554 dut->ap_venue_url = atoi(val);
9555
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03009556 val = get_param(cmd, "Advice_of_Charge");
9557 if (val)
9558 dut->ap_advice_of_charge = atoi(val);
9559
Jouni Malinenac104532018-05-01 00:27:37 +03009560 val = get_param(cmd, "Operator_Icon_Metadata");
9561 if (val)
9562 dut->ap_oper_icon_metadata = atoi(val);
9563
Jouni Malinenac367142018-05-01 00:32:24 +03009564 val = get_param(cmd, "TnC_File_Name");
9565 if (val)
9566 dut->ap_tnc_file_name = atoi(val);
9567
9568 val = get_param(cmd, "TnC_File_Time_Stamp");
9569 if (val)
9570 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
9571
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009572 return 1;
9573}
9574
9575
9576void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
9577{
9578 char buf[100];
9579
9580 if (!file_exists("nfc-status"))
9581 return;
9582
9583 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
9584 run_system(dut, buf);
9585}
9586
9587
9588static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
9589 const char *info)
9590{
9591 int res;
9592
9593 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
9594 printf("%s\n\n", info);
9595
9596 nfc_status(dut, "START", info);
9597 res = run_system(dut, cmd);
9598 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
9599 if (res) {
9600 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
9601 cmd, res);
9602 return res;
9603 }
9604
9605 return 0;
9606}
9607
9608
9609static int ap_nfc_write_config_token(struct sigma_dut *dut,
9610 struct sigma_conn *conn,
9611 struct sigma_cmd *cmd)
9612{
9613 int res;
9614 char buf[300];
9615
9616 run_system(dut, "killall wps-ap-nfc.py");
9617 unlink("nfc-success");
9618 snprintf(buf, sizeof(buf),
9619 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
9620 dut->summary_log ? "--summary " : "",
9621 dut->summary_log ? dut->summary_log : "");
9622 res = run_nfc_command(dut, buf,
9623 "Touch NFC Tag to write WPS configuration token");
9624 if (res || !file_exists("nfc-success")) {
9625 send_resp(dut, conn, SIGMA_ERROR,
9626 "ErrorCode,Failed to write tag");
9627 return 0;
9628 }
9629
9630 return 1;
9631}
9632
9633
9634static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
9635 struct sigma_conn *conn,
9636 struct sigma_cmd *cmd)
9637{
9638 int res;
9639 char buf[300];
9640
9641 run_system(dut, "killall wps-ap-nfc.py");
9642
9643 unlink("nfc-success");
9644 snprintf(buf, sizeof(buf),
9645 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9646 dut->summary_log ? "--summary " : "",
9647 dut->summary_log ? dut->summary_log : "");
9648 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
9649 if (res || !file_exists("nfc-success")) {
9650 send_resp(dut, conn, SIGMA_ERROR,
9651 "ErrorCode,Failed to read tag");
9652 return 0;
9653 }
9654
9655 return 1;
9656}
9657
9658
9659static int ap_nfc_write_password_token(struct sigma_dut *dut,
9660 struct sigma_conn *conn,
9661 struct sigma_cmd *cmd)
9662{
9663 int res;
9664 char buf[300];
9665
9666 run_system(dut, "killall wps-ap-nfc.py");
9667 unlink("nfc-success");
9668 snprintf(buf, sizeof(buf),
9669 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
9670 dut->summary_log ? "--summary " : "",
9671 dut->summary_log ? dut->summary_log : "");
9672 res = run_nfc_command(dut, buf,
9673 "Touch NFC Tag to write WPS password token");
9674 if (res || !file_exists("nfc-success")) {
9675 send_resp(dut, conn, SIGMA_ERROR,
9676 "ErrorCode,Failed to write tag");
9677 return 0;
9678 }
9679
9680 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
9681 send_resp(dut, conn, SIGMA_ERROR,
9682 "ErrorCode,Failed to enable NFC password token");
9683 return 0;
9684 }
9685
9686 return 1;
9687}
9688
9689
9690static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
9691 struct sigma_conn *conn,
9692 struct sigma_cmd *cmd)
9693{
9694 int res;
9695 char buf[300];
9696
9697 run_system(dut, "killall wps-ap-nfc.py");
9698 unlink("nfc-success");
9699 snprintf(buf, sizeof(buf),
9700 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9701 dut->summary_log ? "--summary " : "",
9702 dut->summary_log ? dut->summary_log : "");
9703 res = run_nfc_command(dut, buf,
9704 "Touch NFC Device to respond to WPS connection handover");
9705 if (res) {
9706 send_resp(dut, conn, SIGMA_ERROR,
9707 "ErrorCode,Failed to enable NFC for connection "
9708 "handover");
9709 return 0;
9710 }
9711 if (!file_exists("nfc-success")) {
9712 send_resp(dut, conn, SIGMA_ERROR,
9713 "ErrorCode,Failed to complete NFC connection handover");
9714 return 0;
9715 }
9716
9717 return 1;
9718}
9719
9720
9721static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
9722 struct sigma_cmd *cmd)
9723{
9724 /* const char *name = get_param(cmd, "Name"); */
9725 /* const char *intf = get_param(cmd, "Interface"); */
9726 const char *oper = get_param(cmd, "Operation");
9727
9728 if (oper == NULL)
9729 return -1;
9730
9731 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
9732 return ap_nfc_write_config_token(dut, conn, cmd);
9733 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
9734 return ap_nfc_write_password_token(dut, conn, cmd);
9735 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
9736 return ap_nfc_wps_read_passwd(dut, conn, cmd);
9737 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
9738 return ap_nfc_wps_connection_handover(dut, conn, cmd);
9739
9740 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
9741 return 0;
9742}
9743
9744
9745static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
9746 struct sigma_cmd *cmd)
9747{
9748 char *pin = "12345670"; /* TODO: use random PIN */
9749 char resp[100];
9750
9751 snprintf(resp, sizeof(resp), "PIN,%s", pin);
9752 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9753
9754 return 0;
9755}
9756
9757
9758static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
9759 const char *val)
9760{
9761 char *token, *result;
9762 int nss = 0, chwidth = 0;
9763 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309764 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009765
9766 /*
9767 * The following commands should be invoked to generate
9768 * VHT op mode notification
9769 */
9770
9771 /* Extract the NSS info */
9772 token = strdup(val);
9773 if (!token)
9774 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309775 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009776 if (result) {
9777 int count = atoi(result);
9778
9779 /* We do not support NSS > 3 */
9780 if (count < 0 || count > 3) {
9781 free(token);
9782 return -1;
9783 }
9784
9785 /* Convert nss to chainmask */
9786 while (count--)
9787 nss = (nss << 1) | 1;
9788
9789 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
9790 ifname, nss);
9791 if (system(buf) != 0) {
9792 sigma_dut_print(dut, DUT_MSG_ERROR,
9793 "iwpriv wifi1 rxchainmask failed!");
9794 }
9795 }
9796
9797 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309798 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009799 if (result) {
9800 switch (atoi(result)) {
9801 case 20:
9802 chwidth = 0;
9803 break;
9804 case 40:
9805 chwidth = 1;
9806 break;
9807 case 80:
9808 chwidth = 2;
9809 break;
9810 case 160:
9811 chwidth = 3;
9812 break;
9813 default:
9814 chwidth = 2;
9815 break;
9816 }
9817 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9818 ifname, chwidth);
9819 if (system(buf) != 0) {
9820 sigma_dut_print(dut, DUT_MSG_ERROR,
9821 "iwpriv chwidth failed!");
9822 }
9823 }
9824
9825 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03009826 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009827 if (system(buf) != 0) {
9828 sigma_dut_print(dut, DUT_MSG_ERROR,
9829 "iwpriv opmode_notify failed!");
9830 }
9831 free(token);
9832
9833 return 0;
9834}
9835
9836
9837static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
9838 const char *val)
9839{
9840 /* String (nss_operating_mode; mcs_operating_mode) */
9841 int nss, mcs;
9842 char *token, *result;
9843 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309844 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009845
9846 token = strdup(val);
9847 if (!token)
9848 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309849 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309850 if (!result) {
9851 sigma_dut_print(dut, DUT_MSG_ERROR,
9852 "VHT NSS not specified");
9853 goto end;
9854 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009855 if (strcasecmp(result, "def") != 0) {
9856 nss = atoi(result);
9857
9858 if (nss == 4)
9859 ath_disable_txbf(dut, ifname);
9860
9861 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
9862 if (system(buf) != 0) {
9863 sigma_dut_print(dut, DUT_MSG_ERROR,
9864 "iwpriv nss failed");
9865 }
9866 } else {
9867 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
9868 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
9869 if (system(buf) != 0) {
9870 sigma_dut_print(dut, DUT_MSG_ERROR,
9871 "iwpriv nss failed");
9872 }
9873 }
9874 }
9875
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309876 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309877 if (!result) {
9878 sigma_dut_print(dut, DUT_MSG_ERROR,
9879 "VHT MCS not specified");
9880 goto end;
9881 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009882 if (strcasecmp(result, "def") == 0) {
9883 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
9884 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
9885 ifname);
9886 if (system(buf) != 0) {
9887 sigma_dut_print(dut, DUT_MSG_ERROR,
9888 "iwpriv vhtmcs failed");
9889 }
9890 } else {
9891 snprintf(buf, sizeof(buf),
9892 "iwpriv %s set11NRates 0", ifname);
9893 if (system(buf) != 0) {
9894 sigma_dut_print(dut, DUT_MSG_ERROR,
9895 "iwpriv set11NRates failed");
9896 }
9897 }
9898 } else {
9899 mcs = atoi(result);
9900 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
9901 if (system(buf) != 0) {
9902 sigma_dut_print(dut, DUT_MSG_ERROR,
9903 "iwpriv vhtmcs failed");
9904 }
9905 }
9906
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309907end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009908 free(token);
9909 return 0;
9910}
9911
9912
9913static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
9914 const char *val)
9915{
9916 char *token, *result;
9917 int channel = 36;
9918 int chwidth = 80;
9919 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309920 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009921
9922 /* Extract the channel info */
9923 token = strdup(val);
9924 if (!token)
9925 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309926 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009927 if (result)
9928 channel = atoi(result);
9929
9930 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309931 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009932 if (result)
9933 chwidth = atoi(result);
9934
9935 /* Issue the channel switch command */
9936 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
9937 ifname, channel, chwidth);
9938 if (system(buf) != 0) {
9939 sigma_dut_print(dut, DUT_MSG_ERROR,
9940 "iwpriv doth_ch_chwidth failed!");
9941 }
9942
9943 free(token);
9944 return 0;
9945}
9946
9947
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009948static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
9949 const char *val)
9950{
9951 char buf[80];
9952 unsigned char mac_addr[6];
9953
9954 if (parse_mac_address(dut, val, mac_addr) < 0)
9955 return -1;
9956
9957 snprintf(buf, sizeof(buf),
9958 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
9959 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
9960 run_system(dut, buf);
9961
9962 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
9963 ifname, mac_addr[4], mac_addr[5]);
9964 run_system(dut, buf);
9965
9966 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
9967 run_system(dut, buf);
9968
9969 return 0;
9970}
9971
9972
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009973void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08009974{
9975 char buf[60];
9976
9977 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
9978 if (system(buf) != 0) {
9979 sigma_dut_print(dut, DUT_MSG_ERROR,
9980 "disabling novap reset failed");
9981 }
9982}
9983
9984
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009985struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
9986 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009987{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009988 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009989
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009990 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
9991 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
9992 ETH_ALEN) == 0)
9993 return &dut->mbo_pref_aps[i];
9994 }
9995 return NULL;
9996}
9997
9998
9999static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
10000 int ap_ne_class, int ap_ne_op_ch,
10001 int ap_ne_pref)
10002{
10003 struct mbo_pref_ap *entry;
10004 uint8_t self_mac[ETH_ALEN];
10005 char ifname[50];
10006
10007 get_if_name(dut, ifname, sizeof(ifname), 1);
10008 get_hwaddr(ifname, self_mac);
10009
10010 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
10011 entry = &dut->mbo_self_ap_tuple;
10012 else
10013 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
10014
10015 if (!entry) {
10016 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
10017 sigma_dut_print(dut, DUT_MSG_ERROR,
10018 "Nebor AP List is full. Not adding");
10019 return;
10020 }
10021 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
10022 dut->mbo_pref_ap_cnt++;
10023 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
10024 entry->ap_ne_class = -1;
10025 entry->ap_ne_op_ch = -1;
10026 entry->ap_ne_pref = -1;
10027 }
10028 if (ap_ne_class != -1)
10029 entry->ap_ne_class = ap_ne_class;
10030 if (ap_ne_op_ch != -1)
10031 entry->ap_ne_op_ch = ap_ne_op_ch;
10032 if (ap_ne_pref != -1)
10033 entry->ap_ne_pref = ap_ne_pref;
10034}
10035
10036
10037static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
10038 struct sigma_cmd *cmd)
10039{
10040 unsigned char mac_addr[ETH_ALEN];
10041 const char *val;
10042 /*
10043 * -1 is invalid value for the following
10044 * to differentiate between unset and set values
10045 * -1 => implies not set by CAPI
10046 */
10047 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
10048 int list_offset = dut->mbo_pref_ap_cnt;
10049
10050 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
10051 sigma_dut_print(dut, DUT_MSG_ERROR,
10052 "AP Pref Entry list is full");
10053 return -1;
10054 }
10055
10056 val = get_param(cmd, "Nebor_Op_Class");
10057 if (val)
10058 ap_ne_class = atoi(val);
10059
10060 val = get_param(cmd, "Nebor_Op_Ch");
10061 if (val)
10062 ap_ne_op_ch = atoi(val);
10063
10064 val = get_param(cmd, "Nebor_Pref");
10065 if (val)
10066 ap_ne_pref = atoi(val);
10067
10068 val = get_param(cmd, "Nebor_BSSID");
10069 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010070 return -1;
10071
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010072 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
10073 ap_ne_pref);
10074 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010075 return 0;
10076}
10077
10078
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010079static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10080 struct sigma_cmd *cmd)
10081{
10082 const char *val;
10083 char *ifname;
10084
10085 ifname = get_main_ifname();
10086
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010087 /* Disable vap reset between the commands */
10088 novap_reset(dut, ifname);
10089
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010090 val = get_param(cmd, "Opt_md_notif_ie");
10091 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
10092 return -1;
10093
10094 /* TODO: Optional arguments */
10095
10096 val = get_param(cmd, "nss_mcs_opt");
10097 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
10098 return -1;
10099
10100 val = get_param(cmd, "chnum_band");
10101 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
10102 return -1;
10103
10104 val = get_param(cmd, "RTS_FORCE");
10105 if (val)
10106 ath_config_rts_force(dut, ifname, val);
10107
10108 val = get_param(cmd, "DYN_BW_SGNL");
10109 if (val)
10110 ath_config_dyn_bw_sig(dut, ifname, val);
10111
10112 val = get_param(cmd, "CTS_WIDTH");
10113 if (val)
10114 ath_set_cts_width(dut, ifname, val);
10115
10116 val = get_param(cmd, "Ndpa_stainfo_mac");
10117 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
10118 return -1;
10119
10120 val = get_param(cmd, "txBandwidth");
10121 if (val && ath_set_width(dut, conn, ifname, val) < 0)
10122 return -1;
10123
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010124 val = get_param(cmd, "Assoc_Disallow");
10125 if (val)
10126 ath_set_assoc_disallow(dut, ifname, val);
10127
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010128
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010129 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010130 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010131 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010132 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010133 dut->ap_disassoc_timer = 1000;
10134 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010135
10136 val = get_param(cmd, "BTMReq_Term_Bit");
10137 if (val)
10138 dut->ap_btmreq_term_bit = atoi(val);
10139
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010140 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010141 if (val) {
10142 dut->ap_assoc_delay = 1;
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010143 run_system_wrapper(dut, "iwpriv %s mbo_asoc_ret %s",
10144 ifname, val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010145 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010146
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010147 val = get_param(cmd, "Disassoc_Timer");
10148 if (val)
10149 dut->ap_disassoc_timer = atoi(val);
10150
10151 val = get_param(cmd, "BSS_Term_Duration");
10152 if (val)
10153 dut->ap_btmreq_bss_term_dur = atoi(val);
10154
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080010155 val = get_param(cmd, "BSS_Term_TSF");
10156 if (val)
10157 dut->ap_btmreq_bss_term_tsf = atoi(val);
10158
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010159 val = get_param(cmd, "TxPower");
10160 if (val)
10161 ath_set_txpower(dut, ifname, val);
10162
10163 val = get_param(cmd, "DownlinkAvailCap");
10164 if (val)
10165 dut->ap_dl_availcap = atoi(val);
10166
10167 val = get_param(cmd, "UplinkAvailCap");
10168 if (val) {
10169 dut->ap_ul_availcap = atoi(val);
10170 run_system_wrapper(dut, "iwpriv %s oce_wan_mtr %d %d", ifname,
10171 dut->ap_dl_availcap, dut->ap_ul_availcap);
10172 }
10173
10174 val = get_param(cmd, "RSSIthreshold");
10175 if (val) {
10176 int rssithreshold;
10177
10178 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
10179 rssithreshold = atoi(val);
10180 run_system_wrapper(dut, "iwpriv %s oce_asoc_rssi %d", ifname,
10181 rssithreshold);
10182 }
10183
10184 val = get_param(cmd, "RetryDelay");
10185 if (val) {
10186 int retrydelay;
10187
10188 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
10189 retrydelay = atoi(val);
10190 run_system_wrapper(dut, "iwpriv %s oce_asoc_dly %d", ifname,
10191 retrydelay);
10192 }
10193
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010194 return 1;
10195}
10196
10197
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010198static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10199 const char *val)
10200{
10201 char *token, *result;
10202 int channel = 36;
10203 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010204 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010205
10206 /* Extract the channel info */
10207 token = strdup(val);
10208 if (!token)
10209 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010210 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010211 if (result)
10212 channel = atoi(result);
10213
10214 /* Issue the channel switch command */
10215 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
10216 ifname, channel);
10217 if (system(buf) != 0) {
10218 sigma_dut_print(dut, DUT_MSG_ERROR,
10219 "iwpriv setChanChange failed!");
10220 }
10221
10222 free(token);
10223 return 0;
10224}
10225
10226
10227static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10228 struct sigma_cmd *cmd)
10229{
10230 const char *val;
10231 char *ifname;
10232
10233 ifname = get_main_ifname();
10234
10235 val = get_param(cmd, "chnum_band");
10236 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
10237 return -1;
10238
10239 return 1;
10240}
10241
10242
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010243static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10244 const char *val)
10245{
10246 char *token, *result;
10247 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
10248 channel_freq;
10249 char buf[100];
10250 char *saveptr;
10251
10252 /* Extract the channel info */
10253 token = strdup(val);
10254 if (!token)
10255 return -1;
10256 result = strtok_r(token, ";", &saveptr);
10257 if (result)
10258 channel = atoi(result);
10259
10260 /* Extract the channel width info */
10261 result = strtok_r(NULL, ";", &saveptr);
10262 if (result)
10263 chwidth = atoi(result);
10264
10265 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
10266 if (center_freq_idx < 0) {
10267 free(token);
10268 return -1;
10269 }
10270
10271 center_freq = get_5g_channel_freq(center_freq_idx);
10272 channel_freq = get_5g_channel_freq(channel);
10273
10274 /* Issue the channel switch command */
10275 snprintf(buf, sizeof(buf),
10276 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
10277 ifname, channel_freq, center_freq, chwidth);
10278 if (run_hostapd_cli(dut,buf) != 0) {
10279 sigma_dut_print(dut, DUT_MSG_ERROR,
10280 "hostapd_cli chan_switch failed");
10281 }
10282
10283 free(token);
10284 return 0;
10285}
10286
10287
10288static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
10289 struct sigma_conn *conn,
10290 struct sigma_cmd *cmd)
10291{
10292 const char *val;
10293 char *ifname;
10294
10295 ifname = get_main_ifname();
10296 val = get_param(cmd, "chnum_band");
10297 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
10298 return -1;
10299
10300 return 1;
10301}
10302
10303
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010304static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10305 struct sigma_cmd *cmd)
10306{
10307 /* const char *name = get_param(cmd, "NAME"); */
10308 /* const char *type = get_param(cmd, "Type"); */
10309
10310 switch (get_driver_type()) {
10311 case DRIVER_ATHEROS:
10312 return ath_ap_set_rfeature(dut, conn, cmd);
10313 case DRIVER_OPENWRT:
10314 switch (get_openwrt_driver_type()) {
10315 case OPENWRT_DRIVER_ATHEROS:
10316 return ath_ap_set_rfeature(dut, conn, cmd);
10317 default:
10318 send_resp(dut, conn, SIGMA_ERROR,
10319 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
10320 return 0;
10321 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053010322 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010323 case DRIVER_WCN:
10324 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010325 case DRIVER_MAC80211:
10326 return mac80211_ap_set_rfeature(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010327 default:
10328 send_resp(dut, conn, SIGMA_ERROR,
10329 "errorCode,Unsupported ap_set_rfeature with the current driver");
10330 return 0;
10331 }
10332}
10333
10334
10335static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
10336 struct sigma_cmd *cmd)
10337{
10338 /* const char *name = get_param(cmd, "NAME"); */
10339 return 1;
10340}
10341
10342
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010343static int cmd_ap_preset_testparameters(struct sigma_dut *dut,
10344 struct sigma_conn *conn,
10345 struct sigma_cmd *cmd)
10346{
10347 const char *val;
10348
10349 val = get_param(cmd, "Oper_Chn");
10350 if (val) {
10351 dut->ap_oper_chn = 1;
10352 dut->ap_channel = atoi(val);
10353 }
10354
10355 return 1;
10356}
10357
10358
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010359void ap_register_cmds(void)
10360{
10361 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
10362 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
10363 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
10364 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
10365 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
10366 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053010367 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010368 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
10369 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
10370 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
10371 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
10372 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
10373 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
10374 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
10375 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
10376 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
10377 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
10378 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
10379 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
10380 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
10381 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
10382 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
10383 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
10384 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010385 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
10386 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010387}