blob: f8f7798204fde2d08e0bd21d4d566835010342e3 [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
103static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
104 struct sigma_cmd *cmd)
105{
106 /* const char *name = get_param(cmd, "NAME"); */
107 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
108 return 0;
109}
110
111
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300112static void kill_hostapd_process_pid(struct sigma_dut *dut)
113{
114 FILE *f;
115 int pid, res;
116 char path[100];
117 int count;
118
119 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
120 if (!f)
121 return;
122 res = fscanf(f, "%d", &pid);
123 fclose(f);
124 if (res != 1)
125 return;
126 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
127 kill(pid, SIGTERM);
128 snprintf(path, sizeof(path), "/proc/%d", pid);
129 for (count = 0; count < 20 && file_exists(path); count++)
130 usleep(100000);
131}
132
133
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300134int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200135{
136#ifndef __QNXNTO__
137 struct ifreq ifr;
138 int s;
139
140 s = socket(AF_INET, SOCK_DGRAM, 0);
141 if (s < 0)
142 return -1;
143 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700144 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200145 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
146 perror("ioctl");
147 close(s);
148 return -1;
149 }
150 close(s);
151 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
152#else /* __QNXNTO__ */
153 struct ifaddrs *ifaddrshead = NULL;
154 int found = 0;
155 struct ifaddrs *temp_ifap = NULL;
156 struct sockaddr_dl *sdl = NULL;
157
158 if (getifaddrs(&ifaddrshead) != 0) {
159 perror("getifaddrs failed");
160 return -1;
161 }
162
163 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
164 ifaddrshead = ifaddrshead->ifa_next) {
165 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
166 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
167 found = 1;
168 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
169 if (sdl)
170 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
171 }
172 }
173
174 if (temp_ifap)
175 freeifaddrs(temp_ifap);
176
177 if (!found) {
178 perror("Failed to get the interface");
179 return -1;
180 }
181#endif /* __QNXNTO__ */
182 return 0;
183}
184
185
186static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
187 const char *val)
188{
189 char buf[60];
190
191 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
192 ifname, atoi(val));
193 if (system(buf) != 0) {
194 sigma_dut_print(dut, DUT_MSG_ERROR,
195 "wifitool ap_group_id failed");
196 }
197}
198
199
200void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
201 const char *val)
202{
203 char buf[60];
204
205 /* TODO: Enable support for other values */
206 if (strcasecmp(val, "40") == 0) {
207 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
208 ifname);
209 if (system(buf) != 0) {
210 sigma_dut_print(dut, DUT_MSG_ERROR,
211 "wifitool cts_width failed");
212 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800213 snprintf(buf, sizeof(buf),
214 "athdiag --set --address=0x10024 --val=0xd90b8a14");
215 if (system(buf) != 0) {
216 sigma_dut_print(dut, DUT_MSG_ERROR,
217 "disabling phy restart failed");
218 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200219 } else {
220 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
221 }
222}
223
224
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800225void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
226 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200227{
228 char buf[60];
229
230 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200231 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200232 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
233 if (system(buf) != 0) {
234 sigma_dut_print(dut, DUT_MSG_ERROR,
235 "iwpriv cwmenable 1 failed");
236 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800237 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
238 ifname);
239 if (system(buf) != 0) {
240 sigma_dut_print(dut, DUT_MSG_ERROR,
241 "disabling RTS from rate control logic failed");
242 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200243 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200244 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200245 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
246 if (system(buf) != 0) {
247 sigma_dut_print(dut, DUT_MSG_ERROR,
248 "iwpriv cwmenable 0 failed");
249 }
250 } else {
251 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
252 }
253}
254
255
256static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
257 const char *val)
258{
259 char buf[60];
260
261 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200262 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200263 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
264 if (system(buf) != 0) {
265 sigma_dut_print(dut, DUT_MSG_ERROR,
266 "iwconfig rts 64 failed");
267 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800268 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
269 ifname);
270 if (system(buf) != 0) {
271 sigma_dut_print(dut, DUT_MSG_ERROR,
272 "wifitool beeliner_fw_test 100 1 failed");
273 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200274 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200275 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200276 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
277 if (system(buf) != 0) {
278 sigma_dut_print(dut, DUT_MSG_ERROR,
279 "iwpriv rts 2347 failed");
280 }
281 } else {
282 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
283 }
284}
285
286
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800287static void ath_radio(struct sigma_dut *dut, const char *val)
288{
289 if (strcasecmp(val, "on") == 0) {
290 if (dut->ap_interface_5g == 1) {
291 run_system(dut, "uci set wireless.wifi0.disabled=0");
292 } else if (dut->ap_interface_2g == 1) {
293 run_system(dut, "uci set wireless.wifi1.disabled=0");
294 } else {
295 run_system(dut, "uci set wireless.wifi0.disabled=0");
296 run_system(dut, "uci set wireless.wifi1.disabled=0");
297 }
298 run_system(dut, "uci commit");
299 run_system(dut, "wifi down");
300 run_system(dut, "wifi up");
301 } else if (strcasecmp(val, "off") == 0) {
302 if (dut->ap_interface_5g == 1) {
303 run_system(dut, "uci set wireless.wifi0.disabled=1");
304 } else if (dut->ap_interface_2g == 1) {
305 run_system(dut, "uci set wireless.wifi1.disabled=1");
306 } else {
307 run_system(dut, "uci set wireless.wifi0.disabled=1");
308 run_system(dut, "uci set wireless.wifi1.disabled=1");
309 }
310 run_system(dut, "uci commit");
311 run_system(dut, "wifi down");
312 run_system(dut, "wifi up");
313 }
314}
315
316
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800317static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
318 const char *val)
319{
320 char buf[60];
321
322 if (strcasecmp(val, "disable") == 0) {
323 snprintf(buf, sizeof(buf), "iwpriv %s stealthdown 1", ifname);
324 if (system(buf) != 0) {
325 sigma_dut_print(dut, DUT_MSG_ERROR,
326 "disable deauthdisassoctx failed");
327 }
328 }
329}
330
331
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800332static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
333 const char *val)
334{
335 char buf[60];
336
337 if (strcasecmp(val, "high") == 0)
338 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
339 else if (strcasecmp(val, "low") == 0)
340 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
341 else
342 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
343
344 if (system(buf) != 0)
345 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
346}
347
348
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200349static enum ap_mode get_mode(const char *str)
350{
351 if (strcasecmp(str, "11a") == 0)
352 return AP_11a;
353 else if (strcasecmp(str, "11g") == 0)
354 return AP_11g;
355 else if (strcasecmp(str, "11b") == 0)
356 return AP_11b;
357 else if (strcasecmp(str, "11na") == 0)
358 return AP_11na;
359 else if (strcasecmp(str, "11ng") == 0)
360 return AP_11ng;
361 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
362 return AP_11ac;
363 else
364 return AP_inval;
365}
366
367
368static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
369{
370 char command[1000];
371 const char *bin;
372 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700373 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200374
375 if (file_exists("hostapd_cli"))
376 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300377 else if (file_exists("../../hostapd/hostapd_cli"))
378 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200379 else
380 bin = "hostapd_cli";
381
382 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700383 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200384
385 if (sigma_radio_ifname[0] &&
386 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700387 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200388 else if (sigma_radio_ifname[0] &&
389 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700390 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200391 }
392
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700393 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200394 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700395 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200396 else
397 snprintf(command, sizeof(command), "%s %s", bin, buf);
398 return run_system(dut, command);
399}
400
401
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700402static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
403 struct sigma_cmd *cmd)
404{
405 FILE *f;
406 int i;
407
408 f = fopen("/tmp/lci_cfg.txt", "w");
409 if (!f) {
410 sigma_dut_print(dut, DUT_MSG_ERROR,
411 "Failed to open /tmp/lci_cfg.txt");
412 return -1;
413 }
414
415 for (i = 2; i < cmd->count; i++)
416 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
417 fprintf(f, "\n");
418 fclose(f);
419
420 return 0;
421}
422
423
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200424static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
425 struct sigma_cmd *cmd)
426{
427 /* const char *name = get_param(cmd, "NAME"); */
428 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200429 const char *val;
430 unsigned int wlan_tag = 1;
431 char *ifname = get_main_ifname();
432
433 val = get_param(cmd, "WLAN_TAG");
434 if (val) {
435 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700436 if (wlan_tag < 1 || wlan_tag > 3) {
437 /*
438 * The only valid WLAN Tags as of now as per the latest
439 * WFA scripts are 1, 2, and 3.
440 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200441 send_resp(dut, conn, SIGMA_INVALID,
442 "errorCode,Invalid WLAN_TAG");
443 return 0;
444 }
445 }
446
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800447 val = get_param(cmd, "Interface");
448 if (val) {
449 if (strcasecmp(val, "5G") == 0)
450 dut->ap_interface_5g = 1;
451 else
452 dut->ap_interface_2g = 1;
453
454 if (dut->ap_interface_5g && dut->ap_interface_2g)
455 dut->ap_is_dual = 1;
456 }
457
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200458 val = get_param(cmd, "CountryCode");
459 if (val) {
460 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
461 return -1;
462 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
463 "%s", val);
464 }
465
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530466 val = get_param(cmd, "regulatory_mode");
467 if (val) {
468 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
469 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
470 }
471
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200472 val = get_param(cmd, "SSID");
473 if (val) {
474 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
475 return -1;
476
477 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700478 /*
479 * If tag is not specified, it is deemed to be 1.
480 * Hence tag of 1 is a special case and the values
481 * corresponding to wlan-tag=1 are stored separately
482 * from the values corresponding tags 2 and 3.
483 * This approach minimises the changes to existing code
484 * since most of the sigma_dut code does not deal with
485 * WLAN-TAG CAPI variable.
486 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200487 snprintf(dut->ap_ssid,
488 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700489 } else {
490 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
491 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
492 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200493 }
494 }
495
496 val = get_param(cmd, "CHANNEL");
497 if (val) {
498 const char *pos;
499 dut->ap_channel = atoi(val);
500 pos = strchr(val, ';');
501 if (pos) {
502 pos++;
503 dut->ap_channel_1 = atoi(pos);
504 }
505 }
506
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530507 /* Overwrite the AP channel with DFS channel if configured */
508 val = get_param(cmd, "dfs_chan");
509 if (val) {
510 dut->ap_channel = atoi(val);
511 }
512
513 val = get_param(cmd, "dfs_mode");
514 if (val) {
515 if (strcasecmp(val, "Enable") == 0)
516 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
517 else if (strcasecmp(val, "Disable") == 0)
518 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
519 else
520 sigma_dut_print(dut, DUT_MSG_ERROR,
521 "Unsupported dfs_mode value: %s", val);
522 }
523
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200524 val = get_param(cmd, "MODE");
525 if (val) {
526 char *str, *pos;
527
528 str = strdup(val);
529 if (str == NULL)
530 return -1;
531 pos = strchr(str, ';');
532 if (pos)
533 *pos++ = '\0';
534
535 dut->ap_is_dual = 0;
536 dut->ap_mode = get_mode(str);
537 if (dut->ap_mode == AP_inval) {
538 send_resp(dut, conn, SIGMA_INVALID,
539 "errorCode,Unsupported MODE");
540 free(str);
541 return 0;
542 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800543 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200544 dut->ap_chwidth = AP_80;
545
546 if (pos) {
547 dut->ap_mode_1 = get_mode(pos);
548 if (dut->ap_mode_1 == AP_inval) {
549 send_resp(dut, conn, SIGMA_INVALID,
550 "errorCode,Unsupported MODE");
551 free(str);
552 return 0;
553 }
554 if (dut->ap_mode_1 == AP_11ac)
555 dut->ap_chwidth_1 = AP_80;
556 dut->ap_is_dual = 1;
557 }
558
559 free(str);
560 } else if (dut->ap_mode == AP_inval) {
561 if (dut->ap_channel <= 11)
562 dut->ap_mode = AP_11ng;
563 else if (dut->program == PROGRAM_VHT)
564 dut->ap_mode = AP_11ac;
565 else
566 dut->ap_mode = AP_11na;
567 }
568
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530569 val = get_param(cmd, "WME");
570 if (val) {
571 if (strcasecmp(val, "on") == 0)
572 dut->ap_wme = AP_WME_ON;
573 else if (strcasecmp(val, "off") == 0)
574 dut->ap_wme = AP_WME_OFF;
575 else
576 sigma_dut_print(dut, DUT_MSG_ERROR,
577 "Unsupported WME value: %s", val);
578 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200579
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530580 val = get_param(cmd, "WMMPS");
581 if (val) {
582 if (strcasecmp(val, "on") == 0)
583 dut->ap_wmmps = AP_WMMPS_ON;
584 else if (strcasecmp(val, "off") == 0)
585 dut->ap_wmmps = AP_WMMPS_OFF;
586 else
587 sigma_dut_print(dut, DUT_MSG_ERROR,
588 "Unsupported WMMPS value: %s", val);
589 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200590
591 val = get_param(cmd, "RTS");
592 if (val)
593 dut->ap_rts = atoi(val);
594
595 val = get_param(cmd, "FRGMNT");
596 if (val)
597 dut->ap_frgmnt = atoi(val);
598
599 /* TODO: PWRSAVE */
600
601 val = get_param(cmd, "BCNINT");
602 if (val)
603 dut->ap_bcnint = atoi(val);
604
605 val = get_param(cmd, "RADIO");
606 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530607 enum driver_type drv = get_driver_type();
608
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200609 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800610 if (drv == DRIVER_OPENWRT)
611 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200612 if (drv == DRIVER_ATHEROS)
613 ath_ap_start_hostapd(dut);
614 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
615 return 0;
616 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530617 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800618 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300619 } else if (dut->use_hostapd_pid_file) {
620 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530621 } else if (kill_process(dut, "(hostapd)", 1,
622 SIGTERM) == 0 ||
623 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200624 sigma_dut_print(dut, DUT_MSG_INFO,
625 "Killed hostapd on radio,off");
626 }
627 } else {
628 send_resp(dut, conn, SIGMA_INVALID,
629 "errorCode,Unsupported RADIO value");
630 return 0;
631 }
632 }
633
634 val = get_param(cmd, "P2PMgmtBit");
635 if (val)
636 dut->ap_p2p_mgmt = atoi(val);
637
638 /* TODO: ChannelUsage */
639
640 /* TODO: 40_INTOLERANT */
641
642 val = get_param(cmd, "ADDBA_REJECT");
643 if (val) {
644 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200645 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200646 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200647 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200648 }
649
650 val = get_param(cmd, "AMPDU");
651 if (val) {
652 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200653 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200654 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200655 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200656 }
657
658 val = get_param(cmd, "AMPDU_EXP");
659 if (val)
660 dut->ap_ampdu_exp = atoi(val);
661
662 val = get_param(cmd, "AMSDU");
663 if (val) {
664 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200665 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200666 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200667 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200668 }
669
670 val = get_param(cmd, "NoAck");
671 if (val) {
672 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200673 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200674 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200675 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200676 }
677
678 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200679 /* TODO: MCS_32 */
680
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530681 val = get_param(cmd, "OFFSET");
682 if (val) {
683 if (strcasecmp(val, "Above") == 0)
684 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
685 else if (strcasecmp(val, "Below") == 0)
686 dut->ap_chwidth_offset = SEC_CH_40BELOW;
687 }
688
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200689 val = get_param(cmd, "MCS_FIXEDRATE");
690 if (val) {
691 dut->ap_fixed_rate = 1;
692 dut->ap_mcs = atoi(val);
693 }
694
695 val = get_param(cmd, "SPATIAL_RX_STREAM");
696 if (val) {
697 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
698 dut->ap_rx_streams = 1;
699 if (dut->device_type == AP_testbed)
700 dut->ap_vhtmcs_map = 0xfffc;
701 } else if (strcasecmp(val, "2SS") == 0 ||
702 strcasecmp(val, "2") == 0) {
703 dut->ap_rx_streams = 2;
704 if (dut->device_type == AP_testbed)
705 dut->ap_vhtmcs_map = 0xfff0;
706 } else if (strcasecmp(val, "3SS") == 0 ||
707 strcasecmp(val, "3") == 0) {
708 dut->ap_rx_streams = 3;
709 if (dut->device_type == AP_testbed)
710 dut->ap_vhtmcs_map = 0xffc0;
711 } else if (strcasecmp(val, "4SS") == 0 ||
712 strcasecmp(val, "4") == 0) {
713 dut->ap_rx_streams = 4;
714 }
715 }
716
717 val = get_param(cmd, "SPATIAL_TX_STREAM");
718 if (val) {
719 if (strcasecmp(val, "1SS") == 0 ||
720 strcasecmp(val, "1") == 0) {
721 dut->ap_tx_streams = 1;
722 if (dut->device_type == AP_testbed)
723 dut->ap_vhtmcs_map = 0xfffc;
724 } else if (strcasecmp(val, "2SS") == 0 ||
725 strcasecmp(val, "2") == 0) {
726 dut->ap_tx_streams = 2;
727 if (dut->device_type == AP_testbed)
728 dut->ap_vhtmcs_map = 0xfff0;
729 } else if (strcasecmp(val, "3SS") == 0 ||
730 strcasecmp(val, "3") == 0) {
731 dut->ap_tx_streams = 3;
732 if (dut->device_type == AP_testbed)
733 dut->ap_vhtmcs_map = 0xffc0;
734 } else if (strcasecmp(val, "4SS") == 0 ||
735 strcasecmp(val, "4") == 0) {
736 dut->ap_tx_streams = 4;
737 }
738 }
739
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700740 val = get_param(cmd, "BSS_max_idle");
741 if (val) {
742 if (strncasecmp(val, "Enable", 7) == 0) {
743 dut->wnm_bss_max_feature = VALUE_ENABLED;
744 } else if (strncasecmp(val, "Disable", 8) == 0) {
745 dut->wnm_bss_max_feature = VALUE_DISABLED;
746 } else {
747 send_resp(dut, conn, SIGMA_ERROR,
748 "errorCode,Invalid value for BSS_max_Feature");
749 return 0;
750 }
751 }
752
753 val = get_param(cmd, "BSS_Idle_Protection_options");
754 if (val) {
755 int protection = (int) strtol(val, (char **) NULL, 10);
756
757 if (protection != 1 && protection != 0) {
758 send_resp(dut, conn, SIGMA_ERROR,
759 "errorCode,Invalid value for BSS_Idle_Protection_options");
760 return 0;
761 }
762 dut->wnm_bss_max_protection = protection ?
763 VALUE_ENABLED : VALUE_DISABLED;
764 }
765
766 val = get_param(cmd, "BSS_max_Idle_period");
767 if (val) {
768 int idle_time = (int) strtol(val, (char **) NULL, 10);
769
770 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
771 send_resp(dut, conn, SIGMA_ERROR,
772 "errorCode,Invalid value for BSS_max_Idle_period");
773 return 0;
774 }
775 dut->wnm_bss_max_idle_time = idle_time;
776 }
777
778 val = get_param(cmd, "PROXY_ARP");
779 if (val)
780 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
781
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200782 val = get_param(cmd, "nss_mcs_cap");
783 if (val) {
784 int nss, mcs;
785 char token[20];
786 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530787 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200788
789 if (strlen(val) >= sizeof(token))
790 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300791 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530792 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530793 if (!result) {
794 sigma_dut_print(dut, DUT_MSG_ERROR,
795 "VHT NSS not specified");
796 return 0;
797 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200798 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530799 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200800 if (result == NULL) {
801 sigma_dut_print(dut, DUT_MSG_ERROR,
802 "VHTMCS NOT SPECIFIED!");
803 return 0;
804 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530805 result = strtok_r(result, "-", &saveptr);
806 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530807 if (!result) {
808 sigma_dut_print(dut, DUT_MSG_ERROR,
809 "VHT MCS not specified");
810 return 0;
811 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200812 mcs = atoi(result);
813 switch (nss) {
814 case 1:
815 switch (mcs) {
816 case 7:
817 dut->ap_vhtmcs_map = 0xfffc;
818 break;
819 case 8:
820 dut->ap_vhtmcs_map = 0xfffd;
821 break;
822 case 9:
823 dut->ap_vhtmcs_map = 0xfffe;
824 break;
825 default:
826 dut->ap_vhtmcs_map = 0xfffe;
827 break;
828 }
829 break;
830 case 2:
831 switch (mcs) {
832 case 7:
833 dut->ap_vhtmcs_map = 0xfff0;
834 break;
835 case 8:
836 dut->ap_vhtmcs_map = 0xfff5;
837 break;
838 case 9:
839 dut->ap_vhtmcs_map = 0xfffa;
840 break;
841 default:
842 dut->ap_vhtmcs_map = 0xfffa;
843 break;
844 }
845 break;
846 case 3:
847 switch (mcs) {
848 case 7:
849 dut->ap_vhtmcs_map = 0xffc0;
850 break;
851 case 8:
852 dut->ap_vhtmcs_map = 0xffd5;
853 break;
854 case 9:
855 dut->ap_vhtmcs_map = 0xffea;
856 break;
857 default:
858 dut->ap_vhtmcs_map = 0xffea;
859 break;
860 }
861 break;
862 default:
863 dut->ap_vhtmcs_map = 0xffea;
864 break;
865 }
866 }
867
868 /* TODO: MPDU_MIN_START_SPACING */
869 /* TODO: RIFS_TEST */
870 /* TODO: SGI20 */
871
872 val = get_param(cmd, "STBC_TX");
873 if (val)
874 dut->ap_tx_stbc = atoi(val);
875
876 val = get_param(cmd, "WIDTH");
877 if (val) {
878 if (strcasecmp(val, "20") == 0)
879 dut->ap_chwidth = AP_20;
880 else if (strcasecmp(val, "40") == 0)
881 dut->ap_chwidth = AP_40;
882 else if (strcasecmp(val, "80") == 0)
883 dut->ap_chwidth = AP_80;
884 else if (strcasecmp(val, "160") == 0)
885 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800886 else if (strcasecmp(val, "80plus80") == 0) {
887 dut->ap_80plus80 = 1;
888 dut->ap_chwidth = AP_80_80;
889 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200890 dut->ap_chwidth = AP_AUTO;
891 else {
892 send_resp(dut, conn, SIGMA_INVALID,
893 "errorCode,Unsupported WIDTH");
894 return 0;
895 }
896 }
897
898 /* TODO: WIDTH_SCAN */
899
900 val = get_param(cmd, "TDLSProhibit");
901 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
902 val = get_param(cmd, "TDLSChswitchProhibit");
903 dut->ap_tdls_prohibit_chswitch =
904 val && strcasecmp(val, "Enabled") == 0;
905 val = get_param(cmd, "HS2");
906 if (val && wlan_tag == 1)
907 dut->ap_hs2 = atoi(val);
908 val = get_param(cmd, "P2P_CROSS_CONNECT");
909 if (val)
910 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
911
912 val = get_param(cmd, "FakePubKey");
913 dut->ap_fake_pkhash = val && atoi(val);
914
915 val = get_param(cmd, "vht_tkip");
916 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
917 val = get_param(cmd, "vht_wep");
918 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
919
920 val = get_param(cmd, "Protect_mode");
921 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
922
923 val = get_param(cmd, "DYN_BW_SGNL");
924 if (val) {
925 switch (get_driver_type()) {
926 case DRIVER_OPENWRT:
927 switch (get_openwrt_driver_type()) {
928 case OPENWRT_DRIVER_ATHEROS:
929 ath_config_dyn_bw_sig(dut, ifname, val);
930 break;
931 default:
932 send_resp(dut, conn, SIGMA_ERROR,
933 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
934 return 0;
935 }
936 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +0530937 case DRIVER_WCN:
938 case DRIVER_LINUX_WCN:
939 ath_config_dyn_bw_sig(dut, ifname, val);
940 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200941 default:
942 sigma_dut_print(dut, DUT_MSG_ERROR,
943 "Unsupported DYN_BW_SGL with the current driver");
944 break;
945 }
946 }
947
948 val = get_param(cmd, "SGI80");
949 if (val) {
950 if (strcasecmp(val, "enable") == 0)
951 dut->ap_sgi80 = 1;
952 else if (strcasecmp(val, "disable") == 0)
953 dut->ap_sgi80 = 0;
954 else {
955 send_resp(dut, conn, SIGMA_INVALID,
956 "errorCode,Unsupported SGI80");
957 return 0;
958 }
959 }
960
961 val = get_param(cmd, "LDPC");
962 if (val) {
963 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200964 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200965 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200966 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200967 else {
968 send_resp(dut, conn, SIGMA_INVALID,
969 "errorCode,Unsupported LDPC");
970 return 0;
971 }
972 }
973
974 val = get_param(cmd, "BW_SGNL");
975 if (val) {
976 /*
977 * With dynamic bandwidth signaling enabled we should see
978 * RTS if the threshold is met.
979 */
980 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200981 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200982 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200983 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200984 } else {
985 send_resp(dut, conn, SIGMA_INVALID,
986 "errorCode,Unsupported BW_SGNL");
987 return 0;
988 }
989 }
990
991 val = get_param(cmd, "RTS_FORCE");
992 if (val) {
993 switch (get_driver_type()) {
994 case DRIVER_OPENWRT:
995 switch (get_openwrt_driver_type()) {
996 case OPENWRT_DRIVER_ATHEROS:
997 ath_config_rts_force(dut, ifname, val);
998 break;
999 default:
1000 send_resp(dut, conn, SIGMA_ERROR,
1001 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
1002 return 0;
1003 }
1004 break;
1005 default:
1006 sigma_dut_print(dut, DUT_MSG_ERROR,
1007 "Unsupported RTS_FORCE with the current driver");
1008 break;
1009 }
1010 }
1011
1012 val = get_param(cmd, "Zero_crc");
1013 if (val) {
1014 switch (get_driver_type()) {
1015 case DRIVER_ATHEROS:
1016 ath_set_zero_crc(dut, val);
1017 break;
1018 case DRIVER_OPENWRT:
1019 switch (get_openwrt_driver_type()) {
1020 case OPENWRT_DRIVER_ATHEROS:
1021 ath_set_zero_crc(dut, val);
1022 break;
1023 default:
1024 send_resp(dut, conn, SIGMA_ERROR,
1025 "errorCode,Unsupported zero_crc with the current driver");
1026 return 0;
1027 }
1028 break;
1029 default:
1030 send_resp(dut, conn, SIGMA_ERROR,
1031 "errorCode,Unsupported zero_crc with the current driver");
1032 return 0;
1033 }
1034 }
1035
1036 val = get_param(cmd, "TxBF");
1037 if (val)
1038 dut->ap_txBF = strcasecmp(val, "enable") == 0;
1039
1040 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301041 if (val) {
1042 if (strcasecmp(val, "enable") == 0) {
1043 dut->ap_txBF = 1;
1044 dut->ap_mu_txBF = 1;
1045 } else if (strcasecmp(val, "disable") == 0) {
1046 dut->ap_txBF = 0;
1047 dut->ap_mu_txBF = 0;
1048 } else {
1049 sigma_dut_print(dut, DUT_MSG_ERROR,
1050 "Unsupported MU_TxBF");
1051 }
1052 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001053
1054 /* UNSUPPORTED: tx_lgi_rate */
1055
1056 val = get_param(cmd, "wpsnfc");
1057 if (val)
1058 dut->ap_wpsnfc = atoi(val);
1059
1060 val = get_param(cmd, "GROUP_ID");
1061 if (val) {
1062 switch (get_driver_type()) {
1063 case DRIVER_OPENWRT:
1064 switch (get_openwrt_driver_type()) {
1065 case OPENWRT_DRIVER_ATHEROS:
1066 ath_ap_set_group_id(dut, ifname, val);
1067 break;
1068 default:
1069 send_resp(dut, conn, SIGMA_ERROR,
1070 "errorCode,Unsupported group_id with the current driver");
1071 return 0;
1072 }
1073 break;
1074 default:
1075 send_resp(dut, conn, SIGMA_ERROR,
1076 "errorCode,Unsupported group_id with the current driver");
1077 return 0;
1078 }
1079 }
1080
1081 val = get_param(cmd, "CTS_WIDTH");
1082 if (val) {
1083 switch (get_driver_type()) {
1084 case DRIVER_OPENWRT:
1085 switch (get_openwrt_driver_type()) {
1086 case OPENWRT_DRIVER_ATHEROS:
1087 ath_set_cts_width(dut, ifname, val);
1088 break;
1089 default:
1090 send_resp(dut, conn, SIGMA_ERROR,
1091 "errorCode,Unsupported cts_width with the current driver");
1092 return 0;
1093 }
1094 break;
1095 default:
1096 send_resp(dut, conn, SIGMA_ERROR,
1097 "errorCode,Unsupported cts_width with the current driver");
1098 return 0;
1099 }
1100 }
1101
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001102 val = get_param(cmd, "MU_NDPA_FrameFormat");
1103 if (val)
1104 dut->ap_ndpa_frame = atoi(val);
1105
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001106 val = get_param(cmd, "interworking");
1107 if (val && strcmp(val, "1") == 0)
1108 dut->ap_interworking = 1;
1109
1110 val = get_param(cmd, "GAS_CB_DELAY");
1111 if (val)
1112 dut->ap_gas_cb_delay = atoi(val);
1113
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001114 val = get_param(cmd, "LCI");
1115 if (val) {
1116 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1117 return -1;
1118 dut->ap_lci = 1;
1119 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1120 ath_set_lci_config(dut, val, cmd);
1121 }
1122
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001123 val = get_param(cmd, "InfoZ");
1124 if (val) {
1125 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1126 return -1;
1127 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1128 }
1129
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001130 val = get_param(cmd, "LocCivicAddr");
1131 if (val) {
1132 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1133 return -1;
1134 dut->ap_lcr = 1;
1135 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1136 if (dut->ap_lci == 0)
1137 ath_set_lci_config(dut, val, cmd);
1138 }
1139
1140 val = get_param(cmd, "NeighAPBSSID");
1141 if (val) {
1142 if (dut->ap_neighap < 3) {
1143 if (parse_mac_address(
1144 dut, val,
1145 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1146 send_resp(dut, conn, SIGMA_INVALID,
1147 "Failed to parse MAC address");
1148 return 0;
1149 }
1150 dut->ap_neighap++;
1151 if (dut->ap_lci == 1)
1152 dut->ap_scan = 1;
1153 }
1154 }
1155
1156 val = get_param(cmd, "OpChannel");
1157 if (val) {
1158 if (dut->ap_opchannel < 3) {
1159 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1160 dut->ap_opchannel++;
1161 }
1162 }
1163
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001164 val = get_param(cmd, "URI-FQDNdescriptor");
1165 if (val) {
1166 if (strcasecmp(val, "HELD") == 0) {
1167 dut->ap_fqdn_held = 1;
1168 } else if (strcasecmp(val, "SUPL") == 0) {
1169 dut->ap_fqdn_supl = 1;
1170 } else {
1171 send_resp(dut, conn, SIGMA_INVALID,
1172 "errorCode,Unsupported URI-FQDNdescriptor");
1173 return 0;
1174 }
1175 }
1176
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001177 val = get_param(cmd, "Reg_Domain");
1178 if (val) {
1179 if (strcasecmp(val, "Local") == 0) {
1180 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1181 } else if (strcasecmp(val, "Global") == 0) {
1182 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1183 } else {
1184 send_resp(dut, conn, SIGMA_ERROR,
1185 "errorCode,Wrong value for Reg_Domain");
1186 return 0;
1187 }
1188 }
1189
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001190 val = get_param(cmd, "NAME");
1191 if (val) {
1192 if (strcasecmp(val, "ap1mbo") == 0)
1193 dut->ap_name = 1;
1194 else if (strcasecmp(val, "ap2mbo") == 0)
1195 dut->ap_name = 2;
1196 else
1197 dut->ap_name = 0;
1198 }
1199
1200 val = get_param(cmd, "FT_OA");
1201 if (val) {
1202 if (strcasecmp(val, "Enable") == 0) {
1203 dut->ap_ft_oa = 1;
1204 } else if (strcasecmp(val, "Disable") == 0) {
1205 dut->ap_ft_oa = 0;
1206 } else {
1207 send_resp(dut, conn, SIGMA_ERROR,
1208 "errorCode,Wrong value for FT_OA");
1209 return 0;
1210 }
1211 }
1212
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001213 val = get_param(cmd, "Cellular_Cap_Pref");
1214 if (val)
1215 dut->ap_cell_cap_pref = atoi(val);
1216
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001217 val = get_param(cmd, "DOMAIN");
1218 if (val) {
1219 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1220 send_resp(dut, conn, SIGMA_ERROR,
1221 "errorCode,Too long DOMAIN");
1222 return 0;
1223 }
1224 snprintf(dut->ap_mobility_domain,
1225 sizeof(dut->ap_mobility_domain), "%s", val);
1226 }
1227
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001228 val = get_param(cmd, "ft_bss_list");
1229 if (val) {
1230 char *mac_str;
1231 int i;
1232 char *saveptr;
1233 char *mac_list_str;
1234
1235 mac_list_str = strdup(val);
1236 if (!mac_list_str)
1237 return -1;
1238 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1239 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1240 if (parse_mac_address(dut, mac_str,
1241 dut->ft_bss_mac_list[i]) < 0) {
1242 sigma_dut_print(dut, DUT_MSG_ERROR,
1243 "MAC Address not in proper format");
1244 break;
1245 }
1246 dut->ft_bss_mac_cnt++;
1247 mac_str = strtok_r(NULL, " ", &saveptr);
1248 }
1249 sigma_dut_print(dut, DUT_MSG_DEBUG,
1250 "Storing the following FT BSS MAC List");
1251 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1252 sigma_dut_print(dut, DUT_MSG_DEBUG,
1253 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1254 i,
1255 dut->ft_bss_mac_list[i][0],
1256 dut->ft_bss_mac_list[i][1],
1257 dut->ft_bss_mac_list[i][2],
1258 dut->ft_bss_mac_list[i][3],
1259 dut->ft_bss_mac_list[i][4],
1260 dut->ft_bss_mac_list[i][5]);
1261 }
1262 free(mac_list_str);
1263 }
1264
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001265 val = get_param(cmd, "OCESupport");
1266 if (val) {
1267 if (strcasecmp(val, "enable") == 0) {
1268 dut->ap_oce = VALUE_ENABLED;
1269 } else if (strcasecmp(val, "disable") == 0) {
1270 dut->ap_oce = VALUE_DISABLED;
1271 dut->ap_filsdscv = VALUE_DISABLED;
1272 } else {
1273 send_resp(dut, conn, SIGMA_INVALID,
1274 "errorCode,Unsupported OCE");
1275 return 0;
1276 }
1277 }
1278
1279 val = get_param(cmd, "FILSDscvInterval");
1280 if (val)
1281 dut->ap_fils_dscv_int = atoi(val);
1282
1283 val = get_param(cmd, "BroadcastSSID");
1284 if (val) {
1285 if (strcasecmp(val, "enable") == 0) {
1286 dut->ap_broadcast_ssid = VALUE_ENABLED;
1287 } else if (strcasecmp(val, "disable") == 0) {
1288 dut->ap_broadcast_ssid = VALUE_DISABLED;
1289 } else {
1290 send_resp(dut, conn, SIGMA_INVALID,
1291 "errorCode,Unsupported hidden SSID");
1292 return 0;
1293 }
1294 }
1295
1296 val = get_param(cmd, "FILSDscv");
1297 if (val) {
1298 if (strcasecmp(val, "enable") == 0) {
1299 dut->ap_filsdscv = VALUE_ENABLED;
1300 } else if (strcasecmp(val, "disable") == 0) {
1301 dut->ap_filsdscv = VALUE_DISABLED;
1302 } else {
1303 send_resp(dut, conn, SIGMA_INVALID,
1304 "errorCode,Unsupported FILSDscv");
1305 return 0;
1306 }
1307 }
1308
1309 val = get_param(cmd, "FILSHLP");
1310 if (val) {
1311 if (strcasecmp(val, "enable") == 0) {
1312 dut->ap_filshlp = VALUE_ENABLED;
1313 } else if (strcasecmp(val, "disable") == 0) {
1314 dut->ap_filshlp = VALUE_DISABLED;
1315 } else {
1316 send_resp(dut, conn, SIGMA_INVALID,
1317 "errorCode,Unsupported FILSHLP");
1318 return 0;
1319 }
1320 }
1321
1322 val = get_param(cmd, "NAIRealm");
1323 if (val) {
1324 dut->ap_nairealm_int = 1;
1325 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
1326 return -1;
1327 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1328 }
1329
1330 val = get_param(cmd, "DeauthDisassocTx");
1331 if (val) {
1332 if (strcasecmp(val, "disable") == 0) {
1333 deauth_disassoc(dut, ifname, val);
1334 } else {
1335 send_resp(dut, conn, SIGMA_INVALID,
1336 "errorCode,Unsupported DeauthDisassocTx");
1337 return 0;
1338 }
1339 }
1340
1341 val = get_param(cmd, "RNR");
1342 if (val) {
1343 if (strcasecmp(val, "enable") == 0) {
1344 dut->ap_rnr = VALUE_ENABLED;
1345 } else if (strcasecmp(val, "disable") == 0) {
1346 dut->ap_rnr = VALUE_DISABLED;
1347 } else {
1348 send_resp(dut, conn, SIGMA_INVALID,
1349 "errorCode,Unsupported RNR");
1350 return 0;
1351 }
1352 }
1353
1354 val = get_param(cmd, "BLEChannelUtil");
1355 if (val)
1356 dut->ap_blechanutil = atoi(val);
1357
1358 val = get_param(cmd, "BLEAvailAdminCap");
1359 if (val)
1360 dut->ap_ble_admit_cap = atoi(val);
1361
1362 val = get_param(cmd, "DataPPDUDuration");
1363 if (val)
1364 dut->ap_datappdudura = atoi(val);
1365
1366 val = get_param(cmd, "AirTimeFract");
1367 if (val)
1368 dut->ap_airtimefract = atoi(val);
1369
1370 val = get_param(cmd, "dhcpServIPADDR");
1371 if (val) {
1372 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
1373 return -1;
1374 snprintf(dut->ap_dhcpserv_ipaddr,
1375 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1376 dut->ap_dhcp_stop = 1;
1377 }
1378
1379 val = get_param(cmd, "ESP_IE");
1380 if (val) {
1381 if (strcasecmp(val, "enable") == 0) {
1382 dut->ap_esp = VALUE_ENABLED;
1383 } else if (strcasecmp(val, "disable") == 0) {
1384 dut->ap_esp = VALUE_DISABLED;
1385 } else {
1386 send_resp(dut, conn, SIGMA_INVALID,
1387 "errorCode,Unsupported ESP_IE");
1388 return 0;
1389 }
1390 }
1391
1392 val = get_param(cmd, "BAWinSize");
1393 if (val)
1394 dut->ap_bawinsize = atoi(val);
1395
1396 val = get_param(cmd, "BLEStaCount");
1397 if (val)
1398 dut->ap_blestacnt = atoi(val);
1399
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001400 val = get_param(cmd, "PPDUTxType");
1401 if (val) {
1402 if (strcasecmp(val, "MU") == 0) {
1403 dut->ap_he_ppdu = PPDU_MU;
1404 } else {
1405 send_resp(dut, conn, SIGMA_INVALID,
1406 "errorCode,Unsupported PPDUTxType");
1407 return 0;
1408 }
1409 }
1410
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001411 return 1;
1412}
1413
1414
1415static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1416{
1417 char buf[256];
1418 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1419
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301420 if (tid < 0 ||
1421 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1422 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1423 return;
1424 }
1425
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001426 snprintf(buf, sizeof(buf),
1427 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1428 ifname, VI_QOS_TMP_FILE);
1429 if (system(buf) != 0)
1430 return;
1431
1432 snprintf(buf, sizeof(buf),
1433 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1434 ifname, VI_QOS_TMP_FILE);
1435 if (system(buf) != 0)
1436 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1437
1438 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1439 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1440 if (system(buf) != 0) {
1441 sigma_dut_print(dut, DUT_MSG_ERROR,
1442 "Output redirection to VI_QOS_TMP_FILE failed");
1443 }
1444
1445 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1446 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1447 if (system(buf) != 0) {
1448 sigma_dut_print(dut, DUT_MSG_ERROR,
1449 "Append TID to VI_QOS_FILE failed ");
1450 }
1451
1452 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1453 if (system(buf) != 0)
1454 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1455}
1456
1457
1458static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1459 struct sigma_cmd *cmd)
1460{
1461 const char *val;
1462 char *ifname;
1463 char buf[256];
1464 int tid = 0;
1465
1466 ifname = get_main_ifname();
1467 val = get_param(cmd, "TID");
1468 if (val) {
1469 tid = atoi(val);
1470 if (tid)
1471 ath_inject_frame(dut, ifname, tid);
1472 }
1473
1474 /* NOTE: This is the command sequence on Peregrine for ADDBA */
1475 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
1476 if (system(buf) != 0) {
1477 sigma_dut_print(dut, DUT_MSG_ERROR,
1478 "iwpriv setaddbaoper failed");
1479 }
1480
1481 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1482 ifname, tid);
1483 if (system(buf) != 0) {
1484 sigma_dut_print(dut, DUT_MSG_ERROR,
1485 "wifitool senddelba failed");
1486 }
1487
1488 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1489 ifname, tid);
1490 if (system(buf) != 0) {
1491 sigma_dut_print(dut, DUT_MSG_ERROR,
1492 "wifitool sendaddba failed");
1493 }
1494
1495 return 1;
1496}
1497
1498
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301499static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1500 const char *sta_mac,
1501 const char *dir_path)
1502{
1503 DIR *dir;
1504 struct dirent *entry;
1505 char buf[128], path[128];
1506 int ret = 0;
1507
1508 dir = opendir(dir_path);
1509 if (!dir)
1510 return 0;
1511
1512 while ((entry = readdir(dir))) {
1513 ret = 1;
1514
1515 if (strcmp(entry->d_name, ".") == 0 ||
1516 strcmp(entry->d_name, "..") == 0)
1517 continue;
1518
1519 snprintf(path, sizeof(path) - 1, "%s/%s",
1520 dir_path, entry->d_name);
1521 path[sizeof(path) - 1] = 0;
1522
1523 if (strcmp(entry->d_name, sta_mac) == 0) {
1524 snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode",
1525 path);
1526 if (system(buf) != 0) {
1527 sigma_dut_print(dut, DUT_MSG_ERROR,
1528 "Failed to set aggr mode for ath10k");
1529 }
1530
1531 snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba",
1532 tid, path);
1533 if (system(buf) != 0) {
1534 sigma_dut_print(dut, DUT_MSG_ERROR,
1535 "Failed to set addbareq for ath10k");
1536 }
1537
1538 break;
1539 }
1540
1541 /* Recursively search subdirectories */
1542 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1543 }
1544
1545 closedir(dir);
1546
1547 return ret;
1548}
1549
1550
1551static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1552 struct sigma_cmd *cmd)
1553{
1554 const char *val;
1555 int tid = 0;
1556
1557 val = get_param(cmd, "TID");
1558 if (val)
1559 tid = atoi(val);
1560
1561 val = get_param(cmd, "sta_mac_address");
1562 if (!val) {
1563 sigma_dut_print(dut, DUT_MSG_ERROR,
1564 "Failed to parse station MAC address");
1565 return 0;
1566 }
1567
1568 return ath10k_debug_enable_addba_req(dut, tid, val,
1569 "/sys/kernel/debug/ieee80211");
1570}
1571
1572
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001573static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1574 struct sigma_cmd *cmd)
1575{
1576 /* const char *name = get_param(cmd, "NAME"); */
1577 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301578 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001579
1580 switch (get_driver_type()) {
1581 case DRIVER_ATHEROS:
1582 return ath_ap_send_addba_req(dut, conn, cmd);
1583 case DRIVER_OPENWRT:
1584 switch (get_openwrt_driver_type()) {
1585 case OPENWRT_DRIVER_ATHEROS:
1586 return ath_ap_send_addba_req(dut, conn, cmd);
1587 default:
1588 send_resp(dut, conn, SIGMA_ERROR,
1589 "errorCode,ap_send_addba_req not supported with this driver");
1590 return 0;
1591 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301592 case DRIVER_WCN:
1593 case DRIVER_LINUX_WCN:
1594 /* AP automatically sends ADDBA request after association. */
1595 sigma_dut_print(dut, DUT_MSG_INFO,
1596 "ap_send_addba_req command ignored");
1597 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301598 case DRIVER_MAC80211:
1599 if (stat("/sys/module/ath10k_core", &s) == 0)
1600 return ath10k_ap_send_addba_req(dut, cmd);
1601 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001602 default:
1603 send_resp(dut, conn, SIGMA_ERROR,
1604 "errorCode,ap_send_addba_req not supported with this driver");
1605 return 0;
1606 }
1607}
1608
1609
1610static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1611 struct sigma_cmd *cmd)
1612{
1613 /* const char *name = get_param(cmd, "NAME"); */
1614 const char *val;
1615 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301616 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001617
1618 val = get_param(cmd, "WLAN_TAG");
1619 if (val)
1620 wlan_tag = atoi(val);
1621
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301622 security = get_param(cmd, "Security");
1623
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001624 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001625 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301626 if (!val)
1627 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001628 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001629 if (strcasecmp(val, "NONE") == 0) {
1630 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1631 } else if (strcasecmp(val, "OSEN") == 0 &&
1632 wlan_tag == 2) {
1633 /*
1634 * OSEN only supported on WLAN_TAG = 2 for now
1635 */
1636 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301637 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1638 (security &&
1639 strcasecmp(security, "PSK") == 0 &&
1640 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001641 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1642 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02001643 } else if (strcasecmp(val, "OWE") == 0 &&
1644 wlan_tag == 2) {
1645 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1646 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001647 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648 send_resp(dut, conn, SIGMA_INVALID,
1649 "errorCode,Unsupported KEYMGNT");
1650 return 0;
1651 }
1652 return 1;
1653 }
1654 }
1655
1656 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301657 if (!val)
1658 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001659 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301660 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1661 (security && strcasecmp(security, "PSK") == 0 &&
1662 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001663 dut->ap_key_mgmt = AP_WPA2_PSK;
1664 dut->ap_cipher = AP_CCMP;
1665 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1666 strcasecmp(val, "WPA2-Ent") == 0) {
1667 dut->ap_key_mgmt = AP_WPA2_EAP;
1668 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001669 } else if (strcasecmp(val, "SuiteB") == 0) {
1670 dut->ap_key_mgmt = AP_SUITEB;
1671 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02001672 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001673 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1674 dut->ap_key_mgmt = AP_WPA_PSK;
1675 dut->ap_cipher = AP_TKIP;
1676 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1677 strcasecmp(val, "WPA-Ent") == 0) {
1678 dut->ap_key_mgmt = AP_WPA_EAP;
1679 dut->ap_cipher = AP_TKIP;
1680 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1681 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1682 dut->ap_cipher = AP_CCMP_TKIP;
1683 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1684 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1685 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02001686 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
1687 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03001688 dut->ap_key_mgmt = AP_WPA2_SAE;
1689 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001690 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03001691 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1692 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1693 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001694 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001695 } else if (strcasecmp(val, "OWE") == 0) {
1696 dut->ap_key_mgmt = AP_WPA2_OWE;
1697 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001698 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03001699 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
1700 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
1701 dut->ap_cipher = AP_CCMP;
1702 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001703 } else if (strcasecmp(val, "NONE") == 0) {
1704 dut->ap_key_mgmt = AP_OPEN;
1705 dut->ap_cipher = AP_PLAIN;
1706 } else {
1707 send_resp(dut, conn, SIGMA_INVALID,
1708 "errorCode,Unsupported KEYMGNT");
1709 return 0;
1710 }
1711 }
1712
Jouni Malinen30824df2017-08-22 21:21:38 +03001713 val = get_param(cmd, "ECGroupID");
1714 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001715 free(dut->ap_sae_groups);
1716 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001717 }
1718
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001719 val = get_param(cmd, "AntiCloggingThreshold");
1720 if (val)
1721 dut->sae_anti_clogging_threshold = atoi(val);
1722
Jouni Malinenb347db02017-09-02 01:36:03 +03001723 val = get_param(cmd, "Reflection");
1724 if (val)
1725 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1726
Jouni Malinen68143132017-09-02 02:34:08 +03001727 val = get_param(cmd, "InvalidSAEElement");
1728 if (val) {
1729 free(dut->sae_commit_override);
1730 dut->sae_commit_override = strdup(val);
1731 }
1732
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001733 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301734 if (!val)
1735 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001736 if (val) {
1737 if (strcasecmp(val, "WEP") == 0) {
1738 dut->ap_cipher = AP_WEP;
1739 } else if (strcasecmp(val, "TKIP") == 0) {
1740 dut->ap_cipher = AP_TKIP;
1741 } else if (strcasecmp(val, "AES") == 0 ||
1742 strcasecmp(val, "AES-CCMP") == 0) {
1743 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001744 } else if (strcasecmp(val, "AES-GCMP") == 0) {
1745 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001746 } else {
1747 send_resp(dut, conn, SIGMA_INVALID,
1748 "errorCode,Unsupported ENCRYPT");
1749 return 0;
1750 }
1751 }
1752
Jouni Malinen3d633da2017-09-14 22:19:21 +03001753 val = get_param(cmd, "PairwiseCipher");
1754 if (val) {
1755 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1756 dut->ap_cipher = AP_GCMP_256;
1757 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1758 dut->ap_cipher = AP_CCMP_256;
1759 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1760 dut->ap_cipher = AP_GCMP_128;
1761 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1762 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02001763 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
1764 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
1765 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001766 } else {
1767 send_resp(dut, conn, SIGMA_INVALID,
1768 "errorCode,Unsupported PairwiseCipher");
1769 return 0;
1770 }
1771 }
1772
Jouni Malinen2ba24492017-11-17 12:43:59 +02001773 val = get_param(cmd, "GroupCipher");
1774 if (val) {
1775 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1776 dut->ap_group_cipher = AP_GCMP_256;
1777 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1778 dut->ap_group_cipher = AP_CCMP_256;
1779 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1780 dut->ap_group_cipher = AP_GCMP_128;
1781 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1782 dut->ap_group_cipher = AP_CCMP;
1783 } else {
1784 send_resp(dut, conn, SIGMA_INVALID,
1785 "errorCode,Unsupported GroupCipher");
1786 return 0;
1787 }
1788 }
1789
Jouni Malinen3d633da2017-09-14 22:19:21 +03001790 val = get_param(cmd, "GroupMgntCipher");
1791 if (val) {
1792 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1793 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
1794 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1795 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
1796 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1797 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
1798 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1799 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
1800 } else {
1801 send_resp(dut, conn, SIGMA_INVALID,
1802 "errorCode,Unsupported GroupMgntCipher");
1803 return 0;
1804 }
1805 }
1806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001807 val = get_param(cmd, "WEPKEY");
1808 if (val) {
1809 size_t len;
1810 if (dut->ap_cipher != AP_WEP) {
1811 send_resp(dut, conn, SIGMA_INVALID,
1812 "errorCode,Unexpected WEPKEY without WEP "
1813 "configuration");
1814 return 0;
1815 }
1816 len = strlen(val);
1817 if (len != 10 && len != 26) {
1818 send_resp(dut, conn, SIGMA_INVALID,
1819 "errorCode,Unexpected WEPKEY length");
1820 return 0;
1821 }
1822 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1823 }
1824
1825 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301826 if (!val)
1827 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001828 if (val) {
Jouni Malinen2126f422017-10-11 23:24:33 +03001829 if (dut->ap_key_mgmt != AP_WPA2_SAE && strlen(val) > 64)
1830 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001831 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1832 return -1;
1833 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1834 "%s", val);
1835 }
1836
Jouni Malinen63370622017-11-18 17:47:13 +02001837 val = get_param(cmd, "PSKHEX");
1838 if (val) {
1839 if (strlen(val) != 64)
1840 return -1;
1841 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
1842 }
1843
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301844 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
1845 dut->ap_pmf = AP_PMF_OPTIONAL;
1846
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001847 val = get_param(cmd, "PMF");
1848 if (val) {
1849 if (strcasecmp(val, "Disabled") == 0) {
1850 dut->ap_pmf = AP_PMF_DISABLED;
1851 } else if (strcasecmp(val, "Optional") == 0) {
1852 dut->ap_pmf = AP_PMF_OPTIONAL;
1853 } else if (strcasecmp(val, "Required") == 0) {
1854 dut->ap_pmf = AP_PMF_REQUIRED;
1855 } else {
1856 send_resp(dut, conn, SIGMA_INVALID,
1857 "errorCode,Unsupported PMF");
1858 return 0;
1859 }
1860 }
1861
1862 if (dut->ap_key_mgmt == AP_OPEN) {
1863 dut->ap_hs2 = 0;
1864 dut->ap_pmf = AP_PMF_DISABLED;
1865 }
1866
1867 dut->ap_add_sha256 = 0;
1868 val = get_param(cmd, "SHA256AD");
1869 if (val == NULL)
1870 val = get_param(cmd, "SHA256");
1871 if (val) {
1872 if (strcasecmp(val, "Disabled") == 0) {
1873 } else if (strcasecmp(val, "Enabled") == 0) {
1874 dut->ap_add_sha256 = 1;
1875 } else {
1876 send_resp(dut, conn, SIGMA_INVALID,
1877 "errorCode,Unsupported PMF");
1878 return 0;
1879 }
1880 }
1881
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301882 val = get_param(cmd, "PreAuthentication");
1883 if (val) {
1884 if (strcasecmp(val, "disabled") == 0) {
1885 dut->ap_rsn_preauth = 0;
1886 } else if (strcasecmp(val, "enabled") == 0) {
1887 dut->ap_rsn_preauth = 1;
1888 } else {
1889 send_resp(dut, conn, SIGMA_INVALID,
1890 "errorCode,Unsupported PreAuthentication value");
1891 return 0;
1892 }
1893 }
1894
priyadharshini gowthamande81f392017-12-28 15:28:49 -08001895 val = get_param(cmd, "AKMSuiteType");
1896 if (val) {
1897 unsigned int akmsuitetype = 0;
1898
1899 dut->ap_akm = 1;
1900 akmsuitetype = atoi(val);
1901 if (akmsuitetype == 14) {
1902 dut->ap_add_sha256 = 1;
1903 } else if (akmsuitetype == 15) {
1904 dut->ap_add_sha384 = 1;
1905 } else {
1906 send_resp(dut, conn, SIGMA_INVALID,
1907 "errorCode,Unsupported AKMSuitetype");
1908 return 0;
1909 }
1910 }
1911
1912 val = get_param(cmd, "PMKSACaching");
1913 if (val) {
1914 dut->ap_pmksa = 1;
1915 if (strcasecmp(val, "disabled") == 0) {
1916 dut->ap_pmksa_caching = 1;
1917 } else if (strcasecmp(val, "enabled") == 0) {
1918 dut->ap_pmksa_caching = 0;
1919 } else {
1920 send_resp(dut, conn, SIGMA_INVALID,
1921 "errorCode,Unsupported PMKSACaching value");
1922 return 0;
1923 }
1924 }
1925
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001926 return 1;
1927}
1928
1929
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301930int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
1931 struct sigma_cmd *cmd)
1932{
1933 int status;
1934
1935 status = cmd_ap_set_wireless(dut, conn, cmd);
1936 if (status != 1)
1937 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301938 status = cmd_ap_set_security(dut, conn, cmd);
1939 if (status != 1)
1940 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301941 return cmd_ap_config_commit(dut, conn, cmd);
1942}
1943
1944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
1946 struct sigma_cmd *cmd)
1947{
1948 /* const char *name = get_param(cmd, "NAME"); */
1949 const char *val;
1950 unsigned int wlan_tag = 1, radius_port = 0;
1951 char *radius_ipaddr = NULL, *radius_password = NULL;
1952
1953 val = get_param(cmd, "WLAN_TAG");
1954 if (val) {
1955 wlan_tag = atoi(val);
1956 if (wlan_tag != 1 && wlan_tag != 2) {
1957 send_resp(dut, conn, SIGMA_INVALID,
1958 "errorCode,Invalid WLAN_TAG");
1959 return 0;
1960 }
1961 }
1962
1963 val = get_param(cmd, "PORT");
1964 if (val)
1965 radius_port = atoi(val);
1966
1967 if (wlan_tag == 1) {
1968 if (radius_port)
1969 dut->ap_radius_port = radius_port;
1970 radius_ipaddr = dut->ap_radius_ipaddr;
1971 radius_password = dut->ap_radius_password;
1972 } else if (wlan_tag == 2) {
1973 if (radius_port)
1974 dut->ap2_radius_port = radius_port;
1975 radius_ipaddr = dut->ap2_radius_ipaddr;
1976 radius_password = dut->ap2_radius_password;
1977 }
1978
1979 val = get_param(cmd, "IPADDR");
1980 if (val) {
1981 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
1982 return -1;
1983 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
1984 "%s", val);
1985 }
1986
1987 val = get_param(cmd, "PASSWORD");
1988 if (val) {
1989 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
1990 return -1;
1991 snprintf(radius_password,
1992 sizeof(dut->ap_radius_password), "%s", val);
1993 }
1994
1995 return 1;
1996}
1997
1998
1999static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2000 const char *key, const char *val)
2001{
2002 char buf[100];
2003
2004 if (val == NULL) {
2005 snprintf(buf, sizeof(buf),
2006 "uci delete wireless.wifi%d.%s", id, key);
2007 run_system(dut, buf);
2008 return;
2009 }
2010
2011 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2012 id, key, val);
2013 run_system(dut, buf);
2014}
2015
2016
2017static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2018 const char *key, const char *val)
2019{
2020 char buf[256];
2021
2022 if (val == NULL) {
2023 snprintf(buf, sizeof(buf),
2024 "uci del_list wireless.wifi%d.%s", id, key);
2025 run_system(dut, buf);
2026 return;
2027 }
2028
2029 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2030 id, key, val);
2031 run_system(dut, buf);
2032}
2033
2034
2035static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2036 const char *val)
2037{
2038 char buf[256];
2039
2040 if (val == NULL) {
2041 snprintf(buf, sizeof(buf),
2042 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2043 run_system(dut, buf);
2044 return;
2045 }
2046
2047 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2048 id, key, val);
2049 run_system(dut, buf);
2050}
2051
2052
2053static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2054 const char *key, const char *val)
2055{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002056 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002057
2058 if (val == NULL) {
2059 snprintf(buf, sizeof(buf),
2060 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2061 run_system(dut, buf);
2062 return;
2063 }
2064
2065 snprintf(buf, sizeof(buf),
2066 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2067 id, key, val);
2068 run_system(dut, buf);
2069}
2070
2071
2072static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2073 const char *val)
2074{
2075 char buf[256];
2076
2077 if (val == NULL) {
2078 snprintf(buf, sizeof(buf),
2079 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2080 run_system(dut, buf);
2081 return;
2082 }
2083
2084 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
2085 run_system(dut, buf);
2086 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2087 id, key, val);
2088 run_system(dut, buf);
2089 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2090 id, "network", "lan");
2091 run_system(dut, buf);
2092 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2093 id, "mode", "ap");
2094 run_system(dut, buf);
2095 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2096 id, "encryption", "none");
2097 run_system(dut, buf);
2098}
2099
2100
2101#define OPENWRT_MAX_NUM_RADIOS 3
2102static void owrt_ap_config_radio(struct sigma_dut *dut)
2103{
2104 int radio_id[MAX_RADIO] = { 0, 1 };
2105 int radio_count, radio_no;
2106 char buf[64];
2107
2108 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2109 radio_count++) {
2110 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2111 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2112 if (!sigma_radio_ifname[radio_no] ||
2113 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2114 continue;
2115 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2116 owrt_ap_set_vap(dut, radio_count, "device", buf);
2117 radio_id[radio_no] = radio_count;
2118 }
2119 }
2120
2121 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2122 switch (dut->ap_mode) {
2123 case AP_11g:
2124 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2125 break;
2126 case AP_11b:
2127 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2128 break;
2129 case AP_11ng:
2130 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2131 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2132 break;
2133 case AP_11a:
2134 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2135 break;
2136 case AP_11na:
2137 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2138 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2139 break;
2140 case AP_11ac:
2141 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2142 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2143 break;
2144 case AP_inval:
2145 sigma_dut_print(dut, DUT_MSG_ERROR,
2146 "MODE NOT SPECIFIED!");
2147 return;
2148 default:
2149 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2150 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2151 break;
2152 }
2153
2154 if (dut->ap_is_dual) {
2155 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2156 switch (dut->ap_mode_1) {
2157 case AP_11g:
2158 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2159 break;
2160 case AP_11b:
2161 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2162 break;
2163 case AP_11ng:
2164 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2165 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2166 break;
2167 case AP_11a:
2168 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2169 break;
2170 case AP_11na:
2171 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2172 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2173 break;
2174 case AP_11ac:
2175 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2176 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2177 break;
2178 case AP_inval:
2179 sigma_dut_print(dut, DUT_MSG_ERROR,
2180 "MODE NOT SPECIFIED!");
2181 return;
2182 default:
2183 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2184 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2185 break;
2186 }
2187
2188 }
2189
2190 /* Channel */
2191 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2192 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2193
2194 switch (dut->ap_chwidth) {
2195 case AP_20:
2196 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2197 break;
2198 case AP_40:
2199 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2200 break;
2201 case AP_80:
2202 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2203 break;
2204 case AP_160:
2205 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2206 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002207 case AP_80_80:
2208 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2209 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002210 case AP_AUTO:
2211 default:
2212 break;
2213 }
2214
2215 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2216 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2217 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2218 }
2219
2220 if (dut->ap_is_dual) {
2221 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2222 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2223 }
2224
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002225 /* Country Code */
2226 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2227 const char *country;
2228
2229 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2230 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002231 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002232 if (dut->ap_is_dual)
2233 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002234 } else if (dut->ap_countrycode[0]) {
2235 owrt_ap_set_radio(dut, radio_id[0], "country",
2236 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002237 }
2238
2239 if (dut->ap_disable_protection == 1) {
2240 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2241 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2242 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2243 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2244 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002245
2246 if (dut->ap_oce == VALUE_ENABLED &&
2247 get_driver_type() == DRIVER_OPENWRT)
2248 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002249}
2250
2251
2252static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2253{
2254 char buf[256];
2255
2256 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2257 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2258 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2259 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2260
2261 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2262 "'eng:Wi-Fi Alliance'");
2263
2264 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2265 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2266
2267 if (dut->ap_wan_metrics == 1)
2268 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2269 "'01:2500:384:0:0:10'");
2270 else if (dut->ap_wan_metrics == 1)
2271 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2272 "'01:1500:384:20:20:10'");
2273 else if (dut->ap_wan_metrics == 2)
2274 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2275 "'01:1500:384:20:20:10'");
2276 else if (dut->ap_wan_metrics == 3)
2277 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2278 "'01:2000:1000:20:20:10'");
2279 else if (dut->ap_wan_metrics == 4)
2280 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2281 "'01:8000:1000:20:20:10'");
2282 else if (dut->ap_wan_metrics == 5)
2283 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2284 "'01:9000:5000:20:20:10'");
2285
2286 if (dut->ap_conn_capab == 1) {
2287 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2288 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2289 "'6:20:1'");
2290 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2291 "'6:22:0'");
2292 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2293 "'6:80:1'");
2294 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2295 "'6:443:1'");
2296 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2297 "'6:1723:0'");
2298 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2299 "'6:5060:0'");
2300 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2301 "'17:500:1'");
2302 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2303 "'17:5060:0'");
2304 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2305 "'17:4500:1'");
2306 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2307 "'50:0:1'");
2308 } else if (dut->ap_conn_capab == 2) {
2309 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2310 "'6:80:1'");
2311 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2312 "'6:443:1'");
2313 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2314 "'17:5060:1'");
2315 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2316 "'6:5060:1'");
2317 } else if (dut->ap_conn_capab == 3) {
2318 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2319 "'6:80:1'");
2320 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2321 "'6:443:1'");
2322 }
2323
2324 if (dut->ap_oper_class == 1)
2325 snprintf(buf, sizeof(buf), "%s", "51");
2326 else if (dut->ap_oper_class == 2)
2327 snprintf(buf, sizeof(buf), "%s", "73");
2328 else if (dut->ap_oper_class == 3)
2329 snprintf(buf, sizeof(buf), "%s", "5173");
2330
2331 if (dut->ap_oper_class)
2332 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2333
2334 if (dut->ap_osu_provider_list) {
2335 char *osu_friendly_name = NULL;
2336 char *osu_icon = NULL;
2337 char *osu_ssid = NULL;
2338 char *osu_nai = NULL;
2339 char *osu_service_desc = NULL;
2340 char *hs20_icon_filename = NULL;
2341 char hs20_icon[150];
2342 int osu_method;
2343
2344 hs20_icon_filename = "icon_red_zxx.png";
2345 if (dut->ap_osu_icon_tag == 2)
2346 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2347 snprintf(hs20_icon, sizeof(hs20_icon),
2348 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2349 hs20_icon_filename);
2350 osu_icon = "icon_red_zxx.png";
2351 osu_ssid = "OSU";
2352 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2353 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2354 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2355 dut->ap_osu_method[0];
2356
2357 if (strlen(dut->ap_osu_server_uri[0]))
2358 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2359 dut->ap_osu_server_uri[0]);
2360 else
2361 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2362 "'https://osu-server.r2-testbed.wi-fi.org/'");
2363 switch (dut->ap_osu_provider_list) {
2364 case 1:
2365 case 101:
2366 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2367 "'eng:SP Red Test Only'");
2368 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2369 "'eng:Free service for test purpose'");
2370 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2371 hs20_icon);
2372
2373 hs20_icon_filename = "icon_red_eng.png";
2374 if (dut->ap_osu_icon_tag == 2)
2375 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2376
2377 snprintf(hs20_icon, sizeof(hs20_icon),
2378 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2379 hs20_icon_filename);
2380 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2381 "icon_red_eng.png");
2382 break;
2383 case 2:
2384 case 102:
2385 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2386 "'eng:Wireless Broadband Alliance'");
2387 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2388 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002389 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002390 if (dut->ap_osu_icon_tag == 2)
2391 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2392
2393 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002394 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002396 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2398 break;
2399 case 3:
2400 case 103:
2401 osu_friendly_name = "spa:SP Red Test Only";
2402 osu_service_desc = "spa:Free service for test purpose";
2403 break;
2404 case 4:
2405 case 104:
2406 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002407 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002408 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2409 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002410 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002411 if (dut->ap_osu_icon_tag == 2)
2412 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2413
2414 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002415 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002416 hs20_icon_filename);
2417 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2418 hs20_icon);
2419 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
2420
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 break;
2430 case 5:
2431 case 105:
2432 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002433 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002434 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2435 "'eng:Free service for test purpose'");
2436 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
2437
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002438 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002439 if (dut->ap_osu_icon_tag == 2)
2440 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2441
2442 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002443 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002445 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002446 break;
2447 case 6:
2448 case 106:
2449 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2450 "'eng:SP Green Test Only'");
2451 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2452 "'kor:SP 초록 테스트 전용'");
2453
2454 hs20_icon_filename = "icon_green_zxx.png";
2455 if (dut->ap_osu_icon_tag == 2)
2456 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2457
2458 snprintf(hs20_icon, sizeof(hs20_icon),
2459 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2460 hs20_icon_filename);
2461 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2462 hs20_icon);
2463
2464 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2465 "'icon_green_zxx.png'");
2466 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2467 dut->ap_osu_method[0];
2468
2469 snprintf(buf, sizeof(buf), "%d", osu_method);
2470 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2471
2472 if (strlen(dut->ap_osu_server_uri[1]))
2473 owrt_ap_set_list_vap(dut, vap_id,
2474 "osu_server_uri",
2475 dut->ap_osu_server_uri[1]);
2476 else
2477 owrt_ap_set_list_vap(dut, vap_id,
2478 "osu_server_uri",
2479 "'https://osu-server.r2-testbed.wi-fi.org/'");
2480
2481 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2482 "'eng:SP Orange Test Only'");
2483
2484 hs20_icon_filename = "icon_orange_zxx.png";
2485 if (dut->ap_osu_icon_tag == 2)
2486 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2487
2488 snprintf(hs20_icon, sizeof(hs20_icon),
2489 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2490 hs20_icon_filename);
2491
2492 osu_icon = "icon_orange_zxx.png";
2493 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2494 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2495 dut->ap_osu_method[1];
2496 osu_service_desc = NULL;
2497 break;
2498 case 7:
2499 case 107:
2500 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002501 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002502 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2503 "'eng:Free service for test purpose'");
2504
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002505 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002506 if (dut->ap_osu_icon_tag == 2)
2507 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2508
2509 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002510 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002511 hs20_icon_filename);
2512 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2513 hs20_icon);
2514
2515 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002516 "'icon_green_eng.png'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002517 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2518
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002519 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002520 if (dut->ap_osu_icon_tag == 2)
2521 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2522
2523 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002524 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002525 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002526 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002527 break;
2528 case 8:
2529 case 108:
2530 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2531 "'eng:SP Red Test Only'");
2532 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2533 "'eng:Free service for test purpose'");
2534 osu_ssid = "OSU-Encrypted";
2535 osu_nai = "'anonymous@hotspot.net'";
2536 break;
2537 case 9:
2538 case 109:
2539 osu_ssid = "OSU-OSEN";
2540 osu_nai = "'test-anonymous@wi-fi.org'";
2541 osu_friendly_name = "'eng:SP Orange Test Only'";
2542 hs20_icon_filename = "icon_orange_zxx.png";
2543 if (dut->ap_osu_icon_tag == 2)
2544 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2545
2546 snprintf(hs20_icon, sizeof(hs20_icon),
2547 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2548 hs20_icon_filename);
2549 osu_icon = "icon_orange_zxx.png";
2550 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2551 dut->ap_osu_method[0];
2552 osu_service_desc = NULL;
2553 break;
2554 default:
2555 break;
2556 }
2557
2558 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002559 if (strcmp(dut->ap_tag_ssid[0],
2560 dut->ap_osu_ssid) != 0 &&
2561 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002562 sigma_dut_print(dut, DUT_MSG_ERROR,
2563 "OSU_SSID and WLAN_TAG2 SSID differ");
2564 return -2;
2565 }
2566
2567 snprintf(buf, sizeof(buf), "'\"%s\"'",
2568 dut->ap_osu_ssid);
2569 } else {
2570 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2571 }
2572
2573 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2574
2575
2576 if (osu_friendly_name)
2577 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2578 osu_friendly_name);
2579 if (osu_service_desc)
2580 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2581 osu_service_desc);
2582 if (osu_nai)
2583 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2584
2585 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2586
2587 if (osu_icon)
2588 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2589 osu_icon);
2590
2591 if (dut->ap_osu_provider_list > 100) {
2592 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2593 "0");
2594 } else {
2595 snprintf(buf, sizeof(buf), "%d", osu_method);
2596 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2597 buf);
2598 }
2599 }
2600
2601 return 0;
2602}
2603
2604
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002605static void set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2606 char *anqp_string, size_t str_size)
2607{
2608 unsigned char bssid[ETH_ALEN];
2609 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2610 int preference = 0xff;
2611
2612 get_hwaddr(ifname, bssid);
2613 snprintf(anqp_string, str_size,
2614 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2615 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2616 preference,
2617 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2618 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2619 preference - 1);
2620}
2621
2622
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002623static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2624 size_t str_size, int wlan_tag)
2625{
Jouni Malinenf8984642017-10-12 00:02:37 +03002626 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002627 enum driver_type drv;
2628
2629 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002630 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2631 ifname = dut->hostapd_ifname;
2632 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002633 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2634 dut->ap_mode == AP_11ac) &&
2635 if_nametoindex("ath1") > 0)
2636 ifname = "ath1";
2637 else
2638 ifname = "ath0";
2639 } else if (drv == DRIVER_OPENWRT) {
2640 if (sigma_radio_ifname[0] &&
2641 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2642 ifname = "ath2";
2643 else if (sigma_radio_ifname[0] &&
2644 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2645 ifname = "ath1";
2646 else
2647 ifname = "ath0";
2648 } else {
2649 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2650 dut->ap_mode == AP_11ac) &&
2651 if_nametoindex("wlan1") > 0)
2652 ifname = "wlan1";
2653 else
2654 ifname = "wlan0";
2655 }
2656
2657 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2658 /* Handle tagged-ifname only on OPENWRT for now */
2659 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Jouni Malinenf8984642017-10-12 00:02:37 +03002660 } else if (drv == DRIVER_MAC80211 && wlan_tag == 2) {
2661 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002662 } else {
2663 snprintf(ifname_str, str_size, "%s", ifname);
2664 }
2665}
2666
2667
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002668static int owrt_ap_config_vap(struct sigma_dut *dut)
2669{
2670 char buf[256], *temp;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002671 int vap_id = 0, vap_count, i, j;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002672 const char *ifname;
2673 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002674
priyadharshini gowthaman73561262018-02-20 13:24:59 -08002675 if (sigma_radio_ifname[0] &&
2676 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2677 ifname = "ath2";
2678 else if (sigma_radio_ifname[0] &&
2679 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2680 ifname = "ath1";
2681 else
2682 ifname = "ath0";
2683
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002684 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002685 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002686
2687 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2688 if (sigma_radio_ifname[vap_id] &&
2689 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2690 break;
2691 }
2692 if (vap_id == MAX_RADIO)
2693 continue;
2694
2695 /* Single VAP configuration */
2696 if (!dut->ap_is_dual)
2697 vap_id = vap_count;
2698
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002699 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2700 /*
2701 * We keep a separate array of ap_tag_ssid and
2702 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2703 * So j=0 => WLAN_TAG = 2
2704 */
2705 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002706
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002707 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
2708 (dut->ap_interface_5g || dut->ap_interface_2g)) {
2709 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
2710 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
2711 "%s-owe", dut->ap_ssid);
2712 }
2713
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002714 if (dut->ap_tag_ssid[j][0] == '\0')
2715 continue;
2716
2717 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2718 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2719 "device", buf);
2720 /* SSID */
2721 snprintf(buf, sizeof(buf), "\"%s\"",
2722 dut->ap_tag_ssid[j]);
2723 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2724 "ssid", buf);
2725
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002726 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
2727 dut->ap_tag_ssid[0][0] &&
2728 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
2729 /* OWE transition mode */
2730 snprintf(buf, sizeof(buf), "%s", ifname);
2731 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2732 "owe_transition_ifname", buf);
2733 }
2734
2735 if (dut->ap_key_mgmt == AP_OPEN &&
2736 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2737 /* OWE transition mode */
2738 snprintf(buf, sizeof(buf), "%s", ifname);
2739 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2740 "owe_transition_ifname", buf);
2741 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2742 "hidden", "1");
2743 }
2744
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002745 if (dut->ap_ft_oa == 1) {
2746 unsigned char self_mac[ETH_ALEN];
2747 char mac_str[20];
2748
2749 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2750 "mobility_domain",
2751 dut->ap_mobility_domain);
2752 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2753 "ft_over_ds", "0");
2754 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2755 "ieee80211r", "1");
2756 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2757 "nasid", "nas1.example.com");
2758 get_hwaddr(sigma_radio_ifname[0], self_mac);
2759 snprintf(mac_str, sizeof(mac_str),
2760 "%02x:%02x:%02x:%02x:%02x:%02x",
2761 self_mac[0], self_mac[1], self_mac[2],
2762 self_mac[3], self_mac[4], self_mac[5]);
2763 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2764 "ap_macaddr", mac_str);
2765 snprintf(mac_str, sizeof(mac_str),
2766 "%02x%02x%02x%02x%02x%02x",
2767 self_mac[0], self_mac[1], self_mac[2],
2768 self_mac[3], self_mac[4], self_mac[5]);
2769 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2770 "r1_key_holder", mac_str);
2771 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2772 "ft_psk_generate_local", "1");
2773 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2774 "kh_key_hex",
2775 "000102030405060708090a0b0c0d0e0f");
2776 snprintf(mac_str, sizeof(mac_str),
2777 "%02x:%02x:%02x:%02x:%02x:%02x",
2778 dut->ft_bss_mac_list[0][0],
2779 dut->ft_bss_mac_list[0][1],
2780 dut->ft_bss_mac_list[0][2],
2781 dut->ft_bss_mac_list[0][3],
2782 dut->ft_bss_mac_list[0][4],
2783 dut->ft_bss_mac_list[0][5]);
2784 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2785 "ap2_macaddr", mac_str);
2786 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2787 "ap2_r1_key_holder", mac_str);
2788 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2789 "nasid2", "nas2.example.com");
2790 }
2791
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002792 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
2793 wlan_tag == 2) {
2794 /* Only supported for WLAN_TAG=2 */
2795 owrt_ap_set_vap(dut, vap_count + 1, "osen",
2796 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 snprintf(buf, sizeof(buf), "wpa2");
2798 owrt_ap_set_vap(dut, vap_count + 1,
2799 "encryption", buf);
2800 snprintf(buf, sizeof(buf), "%s",
2801 dut->ap2_radius_ipaddr);
2802 owrt_ap_set_vap(dut, vap_count + 1,
2803 "auth_server", buf);
2804 snprintf(buf, sizeof(buf), "%d",
2805 dut->ap2_radius_port);
2806 owrt_ap_set_vap(dut, vap_count + 1,
2807 "auth_port", buf);
2808 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002809 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002810 owrt_ap_set_vap(dut, vap_count + 1,
2811 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002812 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
2813 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2814 "encryption", "psk2+ccmp");
2815 snprintf(buf, sizeof(buf), "\"%s\"",
2816 dut->ap_passphrase);
2817 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2818 "key", buf);
2819 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002820 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002821 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002822 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2823 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2824 "owe", "1");
2825 snprintf(buf, sizeof(buf), "ccmp");
2826 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2827 "encryption", buf);
2828 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2829 "ieee80211w", "2");
2830 if (dut->ap_sae_groups) {
2831 snprintf(buf, sizeof(buf), "\'%s\'",
2832 dut->ap_sae_groups);
2833 owrt_ap_set_vap(dut, vap_count +
2834 (wlan_tag - 1),
2835 "owe_groups", buf);
2836 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002837 }
2838 }
2839
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002840 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002841 if (dut->program == PROGRAM_MBO &&
2842 get_driver_type() == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002843 unsigned char self_mac[ETH_ALEN];
2844 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002845 char anqp_string[200];
2846
2847 set_anqp_elem_value(dut, sigma_radio_ifname[0],
2848 anqp_string, sizeof(anqp_string));
2849 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
2850 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002851
2852 if (dut->ap_ft_oa == 1) {
2853 owrt_ap_set_vap(dut, vap_count,
2854 "mobility_domain",
2855 dut->ap_mobility_domain);
2856 owrt_ap_set_vap(dut, vap_count,
2857 "ft_over_ds", "0");
2858 owrt_ap_set_vap(dut, vap_count,
2859 "ieee80211r", "1");
2860 owrt_ap_set_vap(dut, vap_count,
2861 "nasid", "nas1.example.com");
2862 get_hwaddr(sigma_radio_ifname[0], self_mac);
2863 snprintf(mac_str, sizeof(mac_str),
2864 "%02x:%02x:%02x:%02x:%02x:%02x",
2865 self_mac[0], self_mac[1], self_mac[2],
2866 self_mac[3], self_mac[4], self_mac[5]);
2867 owrt_ap_set_vap(dut, vap_count,
2868 "ap_macaddr", mac_str);
2869 snprintf(mac_str, sizeof(mac_str),
2870 "%02x%02x%02x%02x%02x%02x",
2871 self_mac[0], self_mac[1], self_mac[2],
2872 self_mac[3], self_mac[4], self_mac[5]);
2873 owrt_ap_set_vap(dut, vap_count,
2874 "r1_key_holder", mac_str);
2875 owrt_ap_set_vap(dut, vap_count,
2876 "ft_psk_generate_local", "1");
2877 owrt_ap_set_vap(dut, vap_count,
2878 "kh_key_hex",
2879 "000102030405060708090a0b0c0d0e0f");
2880 snprintf(mac_str, sizeof(mac_str),
2881 "%02x:%02x:%02x:%02x:%02x:%02x",
2882 dut->ft_bss_mac_list[0][0],
2883 dut->ft_bss_mac_list[0][1],
2884 dut->ft_bss_mac_list[0][2],
2885 dut->ft_bss_mac_list[0][3],
2886 dut->ft_bss_mac_list[0][4],
2887 dut->ft_bss_mac_list[0][5]);
2888 owrt_ap_set_vap(dut, vap_count,
2889 "ap2_macaddr", mac_str);
2890 owrt_ap_set_vap(dut, vap_count,
2891 "ap2_r1_key_holder", mac_str);
2892 owrt_ap_set_vap(dut, vap_count,
2893 "nasid2", "nas2.example.com");
2894 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002895 }
2896
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002897 if (dut->ap_oce == VALUE_ENABLED &&
2898 get_driver_type() == DRIVER_OPENWRT) {
2899 owrt_ap_set_vap(dut, vap_id, "oce", "1");
2900 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2901 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
2902
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002903 if (dut->ap_80plus80 == 1)
2904 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
2905
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002906 if (dut->ap_akm == 1) {
2907 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
2908 "3600");
2909 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
2910 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
2911 "1");
2912 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
2913 "1234");
2914 owrt_ap_set_vap(dut, vap_id,
2915 "erp_send_reauth_start", "1");
2916 }
2917
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002918 if (dut->ap_filshlp == VALUE_ENABLED) {
2919 struct ifreq ifr;
2920 char *ifname;
2921 int s;
2922 struct sockaddr_in *ipaddr;
2923
2924 s = socket(AF_INET, SOCK_DGRAM, 0);
2925 if (s < 0) {
2926 sigma_dut_print(dut, DUT_MSG_ERROR,
2927 "Failed to open socket");
2928 return -1;
2929 }
2930 ifr.ifr_addr.sa_family = AF_INET;
2931
2932 memset(&ifr, 0, sizeof(ifr));
2933 ifname = "br-lan";
2934 strlcpy(ifr.ifr_name, ifname,
2935 sizeof(ifr.ifr_name));
2936 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
2937 perror("ioctl");
2938 close(s);
2939 return -1;
2940 }
2941
2942 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
2943 snprintf(buf, sizeof(buf), "%s",
2944 inet_ntoa(ipaddr->sin_addr));
2945 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
2946 buf);
2947 snprintf(buf, sizeof(buf), "%s",
2948 dut->ap_dhcpserv_ipaddr);
2949 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
2950 buf);
2951 owrt_ap_set_vap(dut, vap_id,
2952 "dhcp_rapid_commit_proxy", "1");
2953 owrt_ap_set_vap(dut, vap_id,
2954 "fils_hlp_wait_time", "300");
2955 }
2956
2957 if (dut->ap_filsdscv == VALUE_ENABLED) {
2958 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
2959 "1");
2960 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
2961 "20");
2962 }
2963 }
2964
2965 if (dut->ap_filsdscv == VALUE_DISABLED) {
2966 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
2967 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
2968 }
2969
2970 if (dut->ap_oce == VALUE_DISABLED &&
2971 get_driver_type() == DRIVER_OPENWRT) {
2972 owrt_ap_set_vap(dut, vap_id, "oce", "0");
2973 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
2974 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
2975
2976 if (dut->ap_filsdscv == VALUE_DISABLED) {
2977 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
2978 "0");
2979 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
2980 "0");
2981 }
2982
2983 if (dut->device_type == AP_testbed)
2984 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
2985 }
2986
2987 /* NAIRealm */
2988 if (dut->ap_nairealm_int == 1) {
2989 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
2990 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
2991 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
2992 }
2993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002994 /* SSID */
2995 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
2996 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
2997
2998 /* Encryption */
2999 switch (dut->ap_key_mgmt) {
3000 case AP_OPEN:
3001 if (dut->ap_cipher == AP_WEP) {
3002 owrt_ap_set_vap(dut, vap_count, "encryption",
3003 "wep-mixed");
3004 owrt_ap_set_vap(dut, vap_count, "key",
3005 dut->ap_wepkey);
3006 } else {
3007 owrt_ap_set_vap(dut, vap_count, "encryption",
3008 "none");
3009 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003010 if (dut->ap_key_mgmt == AP_OPEN &&
3011 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3012 /* OWE transition mode */
3013 snprintf(ifname2, sizeof(ifname2), "%s1",
3014 ifname);
3015 owrt_ap_set_vap(dut, vap_count,
3016 "owe_transition_ifname",
3017 ifname2);
3018 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003019 break;
3020 case AP_WPA2_PSK:
3021 case AP_WPA2_PSK_MIXED:
3022 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003023 case AP_WPA2_SAE:
3024 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003025 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3026 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027 snprintf(buf, sizeof(buf), "psk2");
3028 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3029 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003030 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3031 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003032 } else {
3033 snprintf(buf, sizeof(buf), "psk");
3034 }
3035
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003036 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3037 if (dut->ap_cipher == AP_CCMP_TKIP)
3038 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3039 else if (dut->ap_cipher == AP_TKIP)
3040 strlcat(buf, "+tkip", sizeof(buf));
3041 else
3042 strlcat(buf, "+ccmp", sizeof(buf));
3043 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003044
3045 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003046
3047 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3048 snprintf(buf, sizeof(buf), "\"%s\"",
3049 dut->ap_psk);
3050 owrt_ap_set_vap(dut, vap_count, "key", buf);
3051 } else {
3052 snprintf(buf, sizeof(buf), "\"%s\"",
3053 dut->ap_passphrase);
3054 owrt_ap_set_vap(dut, vap_count, "key", buf);
3055 }
3056
3057 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3058 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3059 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3060 else
3061 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3062
3063 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3064 snprintf(buf, sizeof(buf), "%s",
3065 dut->ap_passphrase);
3066 owrt_ap_set_vap(dut, vap_count, "sae_password",
3067 buf);
3068 } else {
3069 snprintf(buf, sizeof(buf), "%s",
3070 dut->ap_passphrase);
3071 owrt_ap_set_vap(dut, vap_count,
3072 "wpa_passphrase", buf);
3073 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003074 break;
3075 case AP_WPA2_EAP:
3076 case AP_WPA2_EAP_MIXED:
3077 case AP_WPA_EAP:
3078 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3079 snprintf(buf, sizeof(buf), "wpa2");
3080 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3081 snprintf(buf, sizeof(buf), "wpa-mixed");
3082 } else {
3083 snprintf(buf, sizeof(buf), "wpa");
3084 }
3085
Peng Xu591be452017-05-10 17:27:28 -07003086 if (dut->ap_cipher == AP_CCMP_TKIP)
3087 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3088 else if (dut->ap_cipher == AP_TKIP)
3089 strlcat(buf, "+tkip", sizeof(buf));
3090 else
3091 strlcat(buf, "+ccmp", sizeof(buf));
3092
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003093 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3094 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3095 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3096 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3097 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3098 snprintf(buf, sizeof(buf), "%s",
3099 dut->ap_radius_password);
3100 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3101 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003102 case AP_WPA2_EAP_OSEN:
3103 /* TODO */
3104 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003105 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003106 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3107 snprintf(buf, sizeof(buf), "gcmp");
3108 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3109 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3110 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3111 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3112 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3113 snprintf(buf, sizeof(buf), "%s",
3114 dut->ap_radius_password);
3115 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3116 snprintf(buf, sizeof(buf), "%d",
3117 dut->ap_group_mgmt_cipher);
3118 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3119 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003120 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003121 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003122 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3123 snprintf(buf, sizeof(buf), "ccmp");
3124 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3125 if (dut->ap_sae_groups) {
3126 snprintf(buf, sizeof(buf), "\'%s\'",
3127 dut->ap_sae_groups);
3128 owrt_ap_set_vap(dut, vap_count, "owe_groups",
3129 buf);
3130 }
3131
3132 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3133 dut->ap_tag_ssid[0][0] &&
3134 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3135 /* OWE transition mode */
3136 snprintf(ifname2, sizeof(ifname2), "%s1",
3137 ifname);
3138 owrt_ap_set_vap(dut, vap_count,
3139 "owe_transition_ifname",
3140 ifname2);
3141 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3142 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003143 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003144 }
3145
3146 if (!dut->ap_is_dual)
3147 break;
3148 }
3149
3150 if (dut->ap_is_dual)
3151 return 1;
3152
3153 /* PMF */
3154 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3155 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3156
3157 /* Add SHA256 */
3158 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3159 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3160
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003161 /* Add SHA384 for akmsuitetype 15 */
3162 if (dut->ap_akm == 1) {
3163 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3164 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3165 }
3166
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303167 /* Enable RSN preauthentication, if asked to */
3168 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3169 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003171 /* Hotspot 2.0 */
3172 if (dut->ap_hs2) {
3173 int ret;
3174
3175 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3176 if (ret)
3177 return ret;
3178 }
3179
3180 /* Interworking */
3181 if (dut->ap_interworking) {
3182 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3183 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3184 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3185 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3186 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3187 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3188 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3189 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3190 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3191 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3192
3193 if (dut->ap_gas_cb_delay > 0) {
3194 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3195 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3196 }
3197
3198 if (dut->ap_roaming_cons[0]) {
3199 char *rcons, *temp_ptr;
3200
3201 rcons = strdup(dut->ap_roaming_cons);
3202 if (rcons == NULL)
3203 return 0;
3204
3205 temp_ptr = strchr(rcons, ';');
3206
3207 if (temp_ptr)
3208 *temp_ptr++ = '\0';
3209
3210 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3211 rcons);
3212
3213 if (temp_ptr)
3214 owrt_ap_set_list_vap(dut, vap_id,
3215 "roaming_consortium",
3216 temp_ptr);
3217
3218 free(rcons);
3219 }
3220 }
3221
3222 if (dut->ap_venue_name) {
3223 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3224 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3225 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3226 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3227 }
3228
3229 if (dut->ap_net_auth_type == 1) {
3230 owrt_ap_set_vap(dut, vap_id, "network_auth_type",
3231 "'00https://tandc-server.wi-fi.org'");
3232 } else if (dut->ap_net_auth_type == 2) {
3233 owrt_ap_set_vap(dut, vap_id, "network_auth_type", "'01'");
3234 }
3235
3236 if (dut->ap_nai_realm_list == 1) {
3237 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3238 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3239 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3240 "'0,wi-fi.org;example.com,13[5:6]'");
3241
3242 } else if (dut->ap_nai_realm_list == 2) {
3243 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3244 "'0,wi-fi.org,21[2:4][5:7]'");
3245 } else if (dut->ap_nai_realm_list == 3) {
3246 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3247 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3248 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3249 "'0,wi-fi.org;example.com,13[5:6]'");
3250 } else if (dut->ap_nai_realm_list == 4) {
3251 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3252 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3253 } else if (dut->ap_nai_realm_list == 5) {
3254 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3255 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3256 } else if (dut->ap_nai_realm_list == 6) {
3257 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3258 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3259 } else if (dut->ap_nai_realm_list == 7) {
3260 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3261 "'0,wi-fi.org,13[5:6]'");
3262 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3263 "'0,wi-fi.org,21[2:4][5:7]'");
3264 }
3265
3266 if (dut->ap_domain_name_list[0])
3267 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3268 dut->ap_domain_name_list);
3269
3270 if (dut->ap_ip_addr_type_avail)
3271 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3272 "'0c'");
3273
3274 temp = buf;
3275
3276 *temp++ = '\'';
3277
3278 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3279 if (i)
3280 *temp++ = ';';
3281
3282 snprintf(temp,
3283 sizeof(dut->ap_plmn_mcc[i]) +
3284 sizeof(dut->ap_plmn_mnc[i]) + 1,
3285 "%s,%s",
3286 dut->ap_plmn_mcc[i],
3287 dut->ap_plmn_mnc[i]);
3288
3289 temp += strlen(dut->ap_plmn_mcc[i]) +
3290 strlen(dut->ap_plmn_mnc[i]) + 1;
3291 }
3292
3293 *temp++ = '\'';
3294 *temp++ = '\0';
3295
3296 if (i)
3297 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3298
3299 if (dut->ap_qos_map_set == 1)
3300 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3301 else if (dut->ap_qos_map_set == 2)
3302 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3303
3304 /* Proxy-ARP */
3305 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3306 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3307
3308 /* DGAF */
3309 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3310 /* parse to hostapd */
3311 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3312 /* parse to wifi driver */
3313 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3314
3315 /* HCBSSLoad */
3316 if (dut->ap_bss_load) {
3317 unsigned int bssload = 0;
3318
3319 if (dut->ap_bss_load == 1) {
3320 /* STA count: 1, CU: 50, AAC: 65535 */
3321 bssload = 0x0132ffff;
3322 } else if (dut->ap_bss_load == 2) {
3323 /* STA count: 1, CU: 200, AAC: 65535 */
3324 bssload = 0x01c8ffff;
3325 } else if (dut->ap_bss_load == 3) {
3326 /* STA count: 1, CU: 75, AAC: 65535 */
3327 bssload = 0x014bffff;
3328 }
3329
3330 snprintf(buf, sizeof(buf), "%d", bssload);
3331 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3332 }
3333
3334 /* L2TIF */
3335 if (dut->ap_l2tif)
3336 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3337
3338 if (dut->ap_disable_protection == 1)
3339 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3340
Sunil Dutt77b213d2017-09-14 18:24:40 +03003341 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003342 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3343 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
3344 }
3345
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05303346 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003347 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003348
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303349 if (dut->ap_tx_stbc) {
3350 /* STBC and beamforming are mutually exclusive features */
3351 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3352 }
3353
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303354 /* enable dfsmode */
3355 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3356 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3357
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003358 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3359 char anqpval[1024];
3360
3361 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3362
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003363 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303364 snprintf(anqpval, sizeof(anqpval),
3365 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003366 dut->ap_val_lci, dut->ap_infoz);
3367 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3368 }
3369
3370 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303371 snprintf(anqpval, sizeof(anqpval),
3372 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003373 dut->ap_val_lcr);
3374 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3375 }
3376
3377 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
3378 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3379 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
3380 }
3381
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003382 if (dut->program == PROGRAM_MBO) {
3383 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3384 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3385 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07003386 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003387
3388 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3389 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07003390 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3391 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003392 }
3393
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003394 if (dut->ap_ft_oa == 1) {
3395 unsigned char self_mac[ETH_ALEN];
3396 char mac_str[20];
3397
3398 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
3399 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
3400 get_hwaddr(sigma_radio_ifname[0], self_mac);
3401 snprintf(mac_str, sizeof(mac_str),
3402 "%02x:%02x:%02x:%02x:%02x:%02x",
3403 self_mac[0], self_mac[1], self_mac[2],
3404 self_mac[3], self_mac[4], self_mac[5]);
3405 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003406 snprintf(mac_str, sizeof(mac_str),
3407 "%02x:%02x:%02x:%02x:%02x:%02x",
3408 self_mac[0], self_mac[1], self_mac[2],
3409 self_mac[3], self_mac[4], self_mac[5]);
3410 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003411 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
3412 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
3413 "000102030405060708090a0b0c0d0e0f");
3414 snprintf(mac_str, sizeof(mac_str),
3415 "%02x:%02x:%02x:%02x:%02x:%02x",
3416 dut->ft_bss_mac_list[0][0],
3417 dut->ft_bss_mac_list[0][1],
3418 dut->ft_bss_mac_list[0][2],
3419 dut->ft_bss_mac_list[0][3],
3420 dut->ft_bss_mac_list[0][4],
3421 dut->ft_bss_mac_list[0][5]);
3422 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003423 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
3424 dut->ap_mobility_domain);
3425 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003426 }
3427
3428 if ((dut->ap_ft_oa == 1 && dut->ap_name == 0) ||
3429 (dut->ap_ft_oa == 1 && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003430 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
3431 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003432 }
3433
3434 if (dut->ap_ft_oa == 1 && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003435 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
3436 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003437 }
3438
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003439 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
3440 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
3441
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003442 /* Enable/disable PMKSA caching, if asked to */
3443 if (dut->ap_pmksa == 1) {
3444 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
3445 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
3446 }
3447
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003448 if (dut->rsne_override) {
3449 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
3450 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
3451 }
3452
3453 if (dut->sae_commit_override) {
3454 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
3455 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
3456 }
3457
3458 if (dut->ap_sae_groups) {
3459 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
3460 owrt_ap_set_vap(dut, vap_count, "sae_groups", buf);
3461 }
3462
3463 if (dut->sae_anti_clogging_threshold >= 0) {
3464 snprintf(buf, sizeof(buf), "%d",
3465 dut->sae_anti_clogging_threshold);
3466 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
3467 buf);
3468 }
3469
3470 if (dut->sae_reflection)
3471 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
3472
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003473 return 1;
3474}
3475
3476
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003477static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
3478{
3479 char anqpval[1024];
3480 unsigned char addr[6];
3481 unsigned char addr2[6];
3482 struct ifreq ifr;
3483 char *ifname;
3484 int s;
3485 int vap_id = 0;
3486
3487 s = socket(AF_INET, SOCK_DGRAM, 0);
3488 if (s < 0) {
3489 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
3490 return -1;
3491 }
3492
3493 memset(&ifr, 0, sizeof(ifr));
3494 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003495 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003496 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3497 perror("ioctl");
3498 close(s);
3499 return -1;
3500 }
3501 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
3502
3503 memset(&ifr, 0, sizeof(ifr));
3504 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003505 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003506 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3507 perror("ioctl");
3508 close(s);
3509 return -1;
3510 }
3511 close(s);
3512 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
3513
3514 snprintf(anqpval, sizeof(anqpval),
3515 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
3516 dut->ap_val_lci, dut->ap_infoz,
3517 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
3518 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
3519
3520 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3521 return 0;
3522}
3523
3524
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003525static int owrt_ap_post_config_commit(struct sigma_dut *dut,
3526 struct sigma_conn *conn,
3527 struct sigma_cmd *cmd)
3528{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003529 int ap_security = 0;
3530 int i;
3531
3532 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
3533 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
3534 ap_security = 1;
3535 }
3536 if (dut->ap_key_mgmt != AP_OPEN)
3537 ap_security = 1;
3538 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003539 /* allow some time for hostapd to start before returning
3540 * success */
3541 usleep(500000);
3542
3543 if (run_hostapd_cli(dut, "ping") != 0) {
3544 send_resp(dut, conn, SIGMA_ERROR,
3545 "errorCode,Failed to talk to hostapd");
3546 return 0;
3547 }
3548 }
3549
3550 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
3551 ath_ap_set_params(dut);
3552
3553 /* Send response */
3554 return 1;
3555}
3556
3557
3558static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
3559 struct sigma_conn *conn,
3560 struct sigma_cmd *cmd)
3561{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08003562 if (dut->program == PROGRAM_DPP &&
3563 get_driver_type() == DRIVER_OPENWRT) {
3564 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
3565 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
3566 }
3567
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003568 /* Stop the AP */
3569 run_system(dut, "wifi down");
3570
3571 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05303572 run_system(dut, "rm -rf /etc/config/wireless");
3573 switch (get_openwrt_driver_type()) {
3574 case OPENWRT_DRIVER_ATHEROS:
3575 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
3576 break;
3577 default:
3578 run_system(dut, "wifi detect > /etc/config/wireless");
3579 break;
3580 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003581
3582 /* Configure Radio & VAP, commit the config */
3583 owrt_ap_config_radio(dut);
3584 owrt_ap_config_vap(dut);
3585 run_system(dut, "uci commit");
3586
3587 /* Start AP */
3588 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003589 if (dut->program != PROGRAM_MBO &&
3590 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003591 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003592 /*
3593 * MBO has a different ANQP element value which is set in
3594 * owrt_ap_config_vap().
3595 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003596 owrt_ap_config_vap_anqp(dut);
3597 run_system(dut, "uci commit");
3598 run_system(dut, "wifi");
3599 }
3600
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003601 return owrt_ap_post_config_commit(dut, conn, cmd);
3602}
3603
3604
3605static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
3606{
3607 unsigned char bssid[6];
3608 char buf[100];
3609 char *ifname, *radio_name;
3610 int vap_id = 0;
3611
3612 if (sigma_radio_ifname[0] &&
3613 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3614 ifname = "ath2";
3615 radio_name = "wifi2";
3616 vap_id = 2;
3617 } else if (sigma_radio_ifname[0] &&
3618 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3619 ifname = "ath1";
3620 radio_name = "wifi1";
3621 vap_id = 1;
3622 } else {
3623 ifname = "ath0";
3624 radio_name = "wifi0";
3625 vap_id = 0;
3626 }
3627
3628 if (!get_hwaddr(ifname, bssid)) {
3629 snprintf(buf, sizeof(buf), "%s", bssid);
3630 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3631 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3632 "%02x:%02x:%02x:%02x:%02x:%02x",
3633 bssid[0], bssid[1], bssid[2], bssid[3],
3634 bssid[4], bssid[5]);
3635 } else {
3636 if (!get_hwaddr(radio_name, bssid)) {
3637 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3638 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3639 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3640 "%02x:%02x:%02x:%02x:%02x:%02x",
3641 bssid[0], bssid[1], bssid[2], bssid[3],
3642 bssid[4], bssid[5]);
3643 } else {
3644 /* Select & enable/disable radios */
3645 if (sigma_radio_ifname[0] &&
3646 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3647 /* We want to use wifi2 */
3648 owrt_ap_set_radio(dut, 0, "disabled", "1");
3649 owrt_ap_set_radio(dut, 1, "disabled", "1");
3650 owrt_ap_set_radio(dut, 2, "disabled", "0");
3651 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
3652 } else if (sigma_radio_ifname[0] &&
3653 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3654 /* We want to use wifi1 */
3655 owrt_ap_set_radio(dut, 0, "disabled", "1");
3656 owrt_ap_set_radio(dut, 1, "disabled", "0");
3657 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
3658 } else {
3659 /* We want to use wifi0 */
3660 owrt_ap_set_radio(dut, 0, "disabled", "0");
3661 owrt_ap_set_radio(dut, 1, "disabled", "1");
3662 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
3663 }
3664
3665 run_system(dut, "uci commit");
3666 run_system(dut, "wifi up");
3667
3668 if (!get_hwaddr(radio_name, bssid)) {
3669 snprintf(buf, sizeof(buf), "%s",
3670 dut->ap_hessid);
3671 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3672 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3673 "%02x:%02x:%02x:%02x:%02x:%02x",
3674 bssid[0], bssid[1], bssid[2], bssid[3],
3675 bssid[4], bssid[5]);
3676 }
3677 }
3678 }
3679}
3680
3681
3682static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
3683 struct sigma_cmd *cmd)
3684{
3685 switch (get_driver_type()) {
3686 case DRIVER_ATHEROS:
3687 run_system(dut, "apdown");
3688 sleep(1);
3689 run_system(dut, "reboot");
3690 break;
3691 case DRIVER_OPENWRT:
3692 run_system(dut, "wifi down");
3693 sleep(1);
3694 run_system(dut, "reboot");
3695 break;
3696 default:
3697 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
3698 break;
3699 }
3700
3701 return 1;
3702}
3703
3704
3705int ascii2hexstr(const char *str, char *hex)
3706{
3707 int i, length;
3708
3709 length = strlen(str);
3710
3711 for (i = 0; i < length; i++)
3712 snprintf(hex + i * 2, 3, "%X", str[i]);
3713
3714 hex[length * 2] = '\0';
3715 return 1;
3716}
3717
3718
3719static int kill_process(struct sigma_dut *dut, char *proc_name,
3720 unsigned char is_proc_instance_one, int sig)
3721{
3722#ifdef __linux__
3723 struct dirent *dp, *dp_in;
3724 const char *direc = "/proc/";
3725 char buf[100];
3726 DIR *dir = opendir(direc);
3727 DIR *dir_in;
3728 FILE *fp;
3729 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303730 char *saveptr;
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303731 int ret = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003732
3733 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303734 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003735
3736 while ((dp = readdir(dir)) != NULL) {
3737 if (dp->d_type != DT_DIR)
3738 continue;
3739
3740 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
3741 dir_in = opendir(buf);
3742 if (dir_in == NULL)
3743 continue;
3744 dp_in = readdir(dir_in);
3745 closedir(dir_in);
3746 if (dp_in == NULL)
3747 continue;
3748 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
3749 fp = fopen(buf, "r");
3750 if (fp == NULL)
3751 continue;
3752 if (fgets(buf, 100, fp) == NULL)
3753 buf[0] = '\0';
3754 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303755 pid = strtok_r(buf, " ", &saveptr);
3756 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003757 if (pid && temp &&
3758 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
3759 sigma_dut_print(dut, DUT_MSG_INFO,
3760 "killing %s process with PID %s",
3761 proc_name, pid);
3762 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
3763 atoi(pid));
3764 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303765 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003766 if (is_proc_instance_one)
3767 break;
3768 }
3769 }
3770
3771 closedir(dir);
3772
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303773 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003774#else /* __linux__ */
3775 return -1;
3776#endif /* __linux__ */
3777}
3778
3779
3780static int run_ndc(struct sigma_dut *dut, char *buf)
3781{
3782 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
3783 sleep(2);
3784 return run_system(dut, buf);
3785}
3786
3787
3788static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
3789 const char *field, const char *value)
3790{
3791 FILE *fcfg, *ftmp;
3792 char buf[MAX_CONF_LINE_LEN + 1];
3793 int len, found = 0, res;
3794
3795 /* Open the configuration file */
3796 fcfg = fopen(pfile, "r");
3797 if (!fcfg) {
3798 sigma_dut_print(dut, DUT_MSG_ERROR,
3799 "Failed to open hostapd conf file");
3800 return -1;
3801 }
3802
3803 snprintf(buf, sizeof(buf), "%s~", pfile);
3804 /* Open a temporary file */
3805 ftmp = fopen(buf, "w+");
3806 if (!ftmp) {
3807 fclose(fcfg);
3808 sigma_dut_print(dut, DUT_MSG_ERROR,
3809 "Failed to open temp buf");
3810 return -1;
3811 }
3812
3813 /* Read the values from the configuration file */
3814 len = strlen(field);
3815 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
3816 char *pline = buf;
3817
3818 /* commented line */
3819 if (buf[0] == '#')
3820 pline++;
3821
3822 /* Identify the configuration parameter to be updated */
3823 if (!found && strncmp(pline, field, len) == 0 &&
3824 pline[len] == '=') {
3825 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
3826 found = 1;
3827 sigma_dut_print(dut, DUT_MSG_INFO,
3828 "Updated hostapd conf file");
3829 }
3830
3831 fprintf(ftmp, "%s", buf);
3832 }
3833
3834 if (!found) {
3835 /* Configuration line not found */
3836 /* Add the new line at the end of file */
3837 fprintf(ftmp, "%s=%s\n", field, value);
3838 sigma_dut_print(dut, DUT_MSG_INFO,
3839 "Adding a new line in hostapd conf file");
3840 }
3841
3842 fclose(fcfg);
3843 fclose(ftmp);
3844
3845 snprintf(buf, sizeof(buf), "%s~", pfile);
3846
3847 /* Restore the updated configuration file */
3848 res = rename(buf, pfile);
3849
3850 /* Remove the temporary file. Ignore the return value */
3851 unlink(buf);
3852
3853 /* chmod is needed because open() may not set permissions properly
3854 * depending on the current umask */
3855 if (chmod(pfile, 0660) < 0) {
3856 unlink(pfile);
3857 sigma_dut_print(dut, DUT_MSG_ERROR,
3858 "Error changing permissions");
3859 return -1;
3860 }
3861
3862 if (res < 0) {
3863 sigma_dut_print(dut, DUT_MSG_ERROR,
3864 "Error restoring conf file");
3865 return -1;
3866 }
3867
3868 return 0;
3869}
3870
3871
3872static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
3873 struct sigma_conn *conn,
3874 struct sigma_cmd *cmd)
3875{
3876 char buf[100];
3877 struct stat s;
3878 int num_tries = 0, ret;
3879
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303880 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
3881 system("killall netd") == 0) {
3882 /* Avoid Error: Error connecting (Connection refused)
3883 * Wait some time to allow netd to reinitialize.
3884 */
3885 usleep(1500000);
3886 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003887
3888 while (num_tries < 10) {
3889 ret = run_ndc(dut, "ndc softap stopap");
3890 num_tries++;
3891 if (WIFEXITED(ret))
3892 ret = WEXITSTATUS(ret);
3893 /* On success, NDC exits with 0 */
3894 if (ret == 0)
3895 break;
3896 sigma_dut_print(dut, DUT_MSG_INFO,
3897 "Try No. %d: ndc softap stopap failed, exit code %d",
3898 num_tries, ret);
3899 }
3900
3901 if (ret != 0)
3902 sigma_dut_print(dut, DUT_MSG_ERROR,
3903 "ndc softap stopap command failed for 10 times - giving up");
3904
3905#ifdef ANDROID
3906 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05303907 system("rmmod -f wlan");
3908 usleep(500000);
3909 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003910#else /* ANDROID */
3911 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
3912 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
3913#endif /* ANDROID */
3914
3915 switch (dut->ap_mode) {
3916 case AP_11g:
3917 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
3918 break;
3919 case AP_11b:
3920 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
3921 break;
3922 case AP_11ng:
3923 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3924 break;
3925 case AP_11a:
3926 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
3927 break;
3928 case AP_11na:
3929 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3930 break;
3931 case AP_11ac:
3932 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
3933 break;
3934 default:
3935 break;
3936 }
3937
3938 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
3939 dut->ap_channel);
3940 run_ndc(dut, buf);
3941
3942 /*
3943 * ndc doesn't support double quotes as SSID string, so re-write
3944 * hostapd configuration file to update SSID.
3945 */
3946 if (dut->ap_ssid[0] != '\0')
3947 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
3948
3949 switch (dut->ap_key_mgmt) {
3950 case AP_OPEN:
3951 if (dut->ap_cipher == AP_WEP) {
3952 run_ndc(dut, "ndc softap qccmd set security_mode=1");
3953 snprintf(buf, sizeof(buf),
3954 "ndc softap qccmd set wep_key0=%s",
3955 dut->ap_wepkey);
3956 run_ndc(dut, buf);
3957 } else {
3958 run_ndc(dut, "ndc softap qccmd set security_mode=0");
3959 }
3960 break;
3961 case AP_WPA2_PSK:
3962 case AP_WPA2_PSK_MIXED:
3963 case AP_WPA_PSK:
3964 if (dut->ap_key_mgmt == AP_WPA2_PSK)
3965 run_ndc(dut, "ndc softap qccmd set security_mode=3");
3966 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
3967 run_ndc(dut, "ndc softap qccmd set security_mode=4");
3968 else
3969 run_ndc(dut, "ndc softap qccmd set security_mode=2");
3970
3971 /*
3972 * ndc doesn't support some special characters as passphrase,
3973 * so re-write hostapd configuration file to update Passphrase.
3974 */
3975 if (dut->ap_passphrase[0] != '\0')
3976 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
3977 "wpa_passphrase", dut->ap_passphrase);
3978
3979 if (dut->ap_cipher == AP_CCMP_TKIP)
3980 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3981 "TKIP CCMP");
3982 else if (dut->ap_cipher == AP_TKIP)
3983 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3984 "TKIP");
3985 else
3986 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3987 "CCMP &");
3988 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03003989 case AP_WPA2_SAE:
3990 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003991 case AP_WPA2_EAP:
3992 case AP_WPA2_EAP_MIXED:
3993 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03003994 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03003995 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003996 case AP_WPA2_EAP_OSEN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003997 /* Not supported */
3998 break;
3999 }
4000
4001 switch (dut->ap_pmf) {
4002 case AP_PMF_DISABLED:
4003 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4004 break;
4005 case AP_PMF_OPTIONAL:
4006 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4007 if (dut->ap_add_sha256)
4008 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4009 else
4010 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4011 break;
4012 case AP_PMF_REQUIRED:
4013 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4014 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4015 break;
4016 }
4017
4018 if (dut->ap_countrycode[0]) {
4019 snprintf(buf, sizeof(buf),
4020 "ndc softap qccmd set country_code=%s",
4021 dut->ap_countrycode);
4022 run_ndc(dut, buf);
4023 }
4024
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304025 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4026 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4027
4028 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4029 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4030
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004031 run_ndc(dut, "ndc softap startap");
4032
4033 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
4034 num_tries = 0;
4035 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4036 run_ndc(dut, "ndc softap stopap");
4037 run_ndc(dut, "ndc softap startap");
4038 num_tries++;
4039 }
4040
4041 if (num_tries == 10) {
4042 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4043 "iface %s :: reboot the APDUT", buf);
4044 return ret;
4045 }
4046
4047 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4048 ap_inet_addr, ap_inet_mask);
4049 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
4050 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
4051 if (system(buf) != 0) {
4052 sigma_dut_print(dut, DUT_MSG_ERROR,
4053 "Failed to intialize the interface");
4054 return -1;
4055 }
4056
4057 return 1;
4058}
4059
4060
4061static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4062{
4063 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4064 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4065
4066 if (dut->ap_oper_name) {
4067 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4068 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4069 }
4070
4071 if (dut->ap_wan_metrics == 1)
4072 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4073 else if (dut->ap_wan_metrics == 2)
4074 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4075 else if (dut->ap_wan_metrics == 3)
4076 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4077 else if (dut->ap_wan_metrics == 4)
4078 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4079 else if (dut->ap_wan_metrics == 5)
4080 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4081
4082 if (dut->ap_conn_capab == 1) {
4083 fprintf(f, "hs20_conn_capab=1:0:0\n");
4084 fprintf(f, "hs20_conn_capab=6:20:1\n");
4085 fprintf(f, "hs20_conn_capab=6:22:0\n");
4086 fprintf(f, "hs20_conn_capab=6:80:1\n");
4087 fprintf(f, "hs20_conn_capab=6:443:1\n");
4088 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4089 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4090 fprintf(f, "hs20_conn_capab=17:500:1\n");
4091 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4092 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4093 fprintf(f, "hs20_conn_capab=50:0:1\n");
4094 } else if (dut->ap_conn_capab == 2) {
4095 fprintf(f, "hs20_conn_capab=6:80:1\n");
4096 fprintf(f, "hs20_conn_capab=6:443:1\n");
4097 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4098 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4099 } else if (dut->ap_conn_capab == 3) {
4100 fprintf(f, "hs20_conn_capab=6:80:1\n");
4101 fprintf(f, "hs20_conn_capab=6:443:1\n");
4102 } else if (dut->ap_conn_capab == 4) {
4103 fprintf(f, "hs20_conn_capab=6:80:1\n");
4104 fprintf(f, "hs20_conn_capab=6:443:1\n");
4105 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4106 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4107 }
4108
4109 if (dut->ap_oper_class == 1)
4110 fprintf(f, "hs20_operating_class=51\n");
4111 else if (dut->ap_oper_class == 2)
4112 fprintf(f, "hs20_operating_class=73\n");
4113 else if (dut->ap_oper_class == 3)
4114 fprintf(f, "hs20_operating_class=5173\n");
4115
4116 if (dut->ap_osu_provider_list) {
4117 char *osu_friendly_name = NULL;
4118 char *osu_icon = NULL;
4119 char *osu_ssid = NULL;
4120 char *osu_nai = NULL;
4121 char *osu_service_desc = NULL;
4122 char *hs20_icon_filename = NULL;
4123 char hs20_icon[150];
4124 int osu_method;
4125
4126 hs20_icon_filename = "icon_red_zxx.png";
4127 if (dut->ap_osu_icon_tag == 2)
4128 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4129 snprintf(hs20_icon, sizeof(hs20_icon),
4130 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4131 hs20_icon_filename);
4132 osu_icon = "icon_red_zxx.png";
4133 osu_ssid = "OSU";
4134 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4135 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4136 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4137
4138 if (strlen(dut->ap_osu_server_uri[0]))
4139 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4140 else
4141 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4142
4143 switch (dut->ap_osu_provider_list) {
4144 case 1:
4145 case 101:
4146 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4147 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4148 hs20_icon_filename = "icon_red_eng.png";
4149 if (dut->ap_osu_icon_tag == 2)
4150 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4151 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4152 hs20_icon_filename);
4153 fprintf(f, "osu_icon=icon_red_eng.png\n");
4154 break;
4155 case 2:
4156 case 102:
4157 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4158 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4159 hs20_icon_filename = "icon_orange_zxx.png";
4160 if (dut->ap_osu_icon_tag == 2)
4161 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4162 snprintf(hs20_icon, sizeof(hs20_icon),
4163 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4164 hs20_icon_filename);
4165 osu_icon = "icon_orange_zxx.png";
4166 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4167 break;
4168 case 3:
4169 case 103:
4170 osu_friendly_name = "spa:SP Red Test Only";
4171 osu_service_desc = "spa:Free service for test purpose";
4172 break;
4173 case 4:
4174 case 104:
4175 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4176 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4177 hs20_icon_filename = "icon_orange_eng.png";
4178 if (dut->ap_osu_icon_tag == 2)
4179 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4180 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4181 hs20_icon_filename);
4182 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4183 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4184
4185 hs20_icon_filename = "icon_orange_zxx.png";
4186 if (dut->ap_osu_icon_tag == 2)
4187 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4188 snprintf(hs20_icon, sizeof(hs20_icon),
4189 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4190 hs20_icon_filename);
4191 osu_icon = "icon_orange_zxx.png";
4192 break;
4193 case 5:
4194 case 105:
4195 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4196 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4197 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4198 hs20_icon_filename = "icon_orange_zxx.png";
4199 if (dut->ap_osu_icon_tag == 2)
4200 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4201 snprintf(hs20_icon, sizeof(hs20_icon),
4202 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4203 hs20_icon_filename);
4204 osu_icon = "icon_orange_zxx.png";
4205 break;
4206 case 6:
4207 case 106:
4208 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4209 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4210 hs20_icon_filename = "icon_green_zxx.png";
4211 if (dut->ap_osu_icon_tag == 2)
4212 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4213 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4214 hs20_icon_filename);
4215 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4216 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4217 fprintf(f, "osu_method_list=%d\n", osu_method);
4218
4219 if (strlen(dut->ap_osu_server_uri[1]))
4220 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4221 else
4222 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4223 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4224 hs20_icon_filename = "icon_orange_zxx.png";
4225 if (dut->ap_osu_icon_tag == 2)
4226 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4227 snprintf(hs20_icon, sizeof(hs20_icon),
4228 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4229 hs20_icon_filename);
4230 osu_icon = "icon_orange_zxx.png";
4231 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4232 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4233 osu_service_desc = NULL;
4234 break;
4235 case 7:
4236 case 107:
4237 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4238 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4239 hs20_icon_filename = "icon_green_eng.png";
4240 if (dut->ap_osu_icon_tag == 2)
4241 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4242 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4243 hs20_icon_filename);
4244 fprintf(f, "osu_icon=icon_green_eng.png\n");
4245 osu_friendly_name = "kor:SP 초록 테스트 전용";
4246
4247 hs20_icon_filename = "icon_green_zxx.png";
4248 if (dut->ap_osu_icon_tag == 2)
4249 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4250 snprintf(hs20_icon, sizeof(hs20_icon),
4251 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4252 hs20_icon_filename);
4253 osu_icon = "icon_green_zxx.png";
4254 break;
4255 case 8:
4256 case 108:
4257 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4258 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4259 osu_ssid = "OSU-Encrypted";
4260 osu_nai = "anonymous@hotspot.net";
4261 break;
4262 case 9:
4263 case 109:
4264 osu_ssid = "OSU-OSEN";
4265 osu_nai = "test-anonymous@wi-fi.org";
4266 osu_friendly_name = "eng:SP Orange Test Only";
4267 hs20_icon_filename = "icon_orange_zxx.png";
4268 if (dut->ap_osu_icon_tag == 2)
4269 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4270 snprintf(hs20_icon, sizeof(hs20_icon),
4271 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4272 hs20_icon_filename);
4273 osu_icon = "icon_orange_zxx.png";
4274 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4275 osu_service_desc = NULL;
4276 break;
4277 default:
4278 break;
4279 }
4280
4281 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004282 if (strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
4283 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004284 sigma_dut_print(dut, DUT_MSG_ERROR,
4285 "OSU_SSID and "
4286 "WLAN_TAG2 SSID differ");
4287 return -2;
4288 }
4289 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
4290 } else
4291 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
4292
4293
4294 if (osu_friendly_name)
4295 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
4296
4297 if (osu_service_desc)
4298 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
4299
4300 if (osu_nai)
4301 fprintf(f, "osu_nai=%s\n", osu_nai);
4302
4303 fprintf(f, "hs20_icon=%s\n", hs20_icon);
4304
4305 if (osu_icon)
4306 fprintf(f, "osu_icon=%s\n", osu_icon);
4307
4308 if (dut->ap_osu_provider_list > 100)
4309 fprintf(f, "osu_method_list=0\n");
4310 else
4311 fprintf(f, "osu_method_list=%d\n", osu_method);
4312 }
4313
Jouni Malinen54a89b02018-05-01 00:16:26 +03004314 switch (dut->ap_venue_url) {
4315 case 1:
4316 fprintf(f,
4317 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4318 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
4319 break;
4320 case 2:
4321 fprintf(f,
4322 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4323 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4324 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4325 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4326 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4327 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4328 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4329 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4330 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4331 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4332 );
4333 break;
4334 }
4335
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03004336 switch (dut->ap_advice_of_charge) {
4337 case 1:
4338 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
4339 break;
4340 }
4341
Jouni Malinenac104532018-05-01 00:27:37 +03004342 switch (dut->ap_oper_icon_metadata) {
4343 case 1:
4344 fprintf(f,
4345 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
4346 "operator_icon=icon_red_eng.png\n");
4347 break;
4348 }
4349
Jouni Malinenac367142018-05-01 00:32:24 +03004350 switch (dut->ap_tnc_file_name) {
4351 case 1:
4352 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
4353 break;
4354 }
4355
4356 if (dut->ap_tnc_time_stamp)
4357 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
4358
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004359 return 0;
4360}
4361
4362
4363static void write_ap_roaming_cons(FILE *f, const char *list)
4364{
4365 char *buf, *pos, *end;
4366
4367 if (list == NULL || list[0] == '\0')
4368 return;
4369
4370 buf = strdup(list);
4371 if (buf == NULL)
4372 return;
4373
4374 pos = buf;
4375 while (pos && *pos) {
4376 end = strchr(pos, ';');
4377 if (end)
4378 *end++ = '\0';
4379 fprintf(f, "roaming_consortium=%s\n", pos);
4380 pos = end;
4381 }
4382
4383 free(buf);
4384}
4385
4386
4387static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
4388{
4389 int i;
4390 char buf[100], *temp;
4391
4392 if (dut->ap_gas_cb_delay > 0)
4393 fprintf(f, "gas_comeback_delay=%d\n",
4394 dut->ap_gas_cb_delay);
4395
4396 fprintf(f, "interworking=1\n"
4397 "access_network_type=%d\n"
4398 "internet=%d\n"
4399 "asra=0\n"
4400 "esr=0\n"
4401 "uesa=0\n"
4402 "venue_group=%d\n"
4403 "venue_type=%d\n",
4404 dut->ap_access_net_type,
4405 dut->ap_internet,
4406 dut->ap_venue_group,
4407 dut->ap_venue_type);
4408 if (dut->ap_hessid[0])
4409 fprintf(f, "hessid=%s\n", dut->ap_hessid);
4410
4411 write_ap_roaming_cons(f, dut->ap_roaming_cons);
4412
4413 if (dut->ap_venue_name) {
4414 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
4415 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
4416 }
4417
4418 if (dut->ap_net_auth_type == 1)
4419 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
4420 else if (dut->ap_net_auth_type == 2)
4421 fprintf(f, "network_auth_type=01\n");
4422
4423 if (dut->ap_nai_realm_list == 1) {
4424 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
4425 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4426 } else if (dut->ap_nai_realm_list == 2) {
4427 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4428 } else if (dut->ap_nai_realm_list == 3) {
4429 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
4430 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4431 } else if (dut->ap_nai_realm_list == 4) {
4432 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
4433 } else if (dut->ap_nai_realm_list == 5) {
4434 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
4435 } else if (dut->ap_nai_realm_list == 6) {
4436 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
4437 } else if (dut->ap_nai_realm_list == 7) {
4438 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
4439 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4440 }
4441
4442 if (dut->ap_domain_name_list[0]) {
4443 fprintf(f, "domain_name=%s\n",
4444 dut->ap_domain_name_list);
4445 }
4446
4447 if (dut->ap_ip_addr_type_avail == 1) {
4448 fprintf(f, "ipaddr_type_availability=0c\n");
4449 }
4450
4451 temp = buf;
4452 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
4453 i++) {
4454 if (i)
4455 *temp++ = ';';
4456
4457 snprintf(temp,
4458 sizeof(dut->ap_plmn_mcc[i]) +
4459 sizeof(dut->ap_plmn_mnc[i]) + 1,
4460 "%s,%s",
4461 dut->ap_plmn_mcc[i],
4462 dut->ap_plmn_mnc[i]);
4463
4464 temp += strlen(dut->ap_plmn_mcc[i]) +
4465 strlen(dut->ap_plmn_mnc[i]) + 1;
4466 }
4467 if (i)
4468 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
4469
4470 if (dut->ap_qos_map_set == 1)
4471 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
4472 else if (dut->ap_qos_map_set == 2)
4473 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
4474
4475 return 0;
4476}
4477
4478
4479static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
4480{
4481 FILE *f;
4482
4483 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4484 system("killall hostapd") == 0) {
4485 int i;
4486
4487 /* Wait some time to allow hostapd to complete cleanup before
4488 * starting a new process */
4489 for (i = 0; i < 10; i++) {
4490 usleep(500000);
4491 if (system("pidof hostapd") != 0)
4492 break;
4493 }
4494 }
4495
4496 f = fopen("/tmp/secath0", "a");
4497 if (f == NULL)
4498 return -2;
4499
4500 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
4501 fclose(f);
4502 return -2;
4503 }
4504
4505 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4506 fclose(f);
4507 return -2;
4508 }
4509
4510 fflush(f);
4511 fclose(f);
4512 return ath_ap_start_hostapd(dut);
4513}
4514
4515
4516static int ath_ap_start_hostapd(struct sigma_dut *dut)
4517{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004518 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004519 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
4520 else
4521 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
4522
4523 return 0;
4524}
4525
4526
4527#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
4528
4529static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
4530{
4531 FILE *f;
4532 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
4533 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
4534 char buf[100];
4535 int i;
4536
4537 f = fopen("/root/anqpserver.conf", "w");
4538 if (f == NULL)
4539 return -1;
4540
4541 if (dut->ap_nai_realm_list == 1) {
4542 nai_realm = 1;
4543 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");
4544 } else if (dut->ap_nai_realm_list == 2) {
4545 nai_realm = 1;
4546 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4547 } else if (dut->ap_nai_realm_list == 3) {
4548 nai_realm = 1;
4549 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");
4550 } else if (dut->ap_nai_realm_list == 4) {
4551 nai_realm = 1;
4552 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");
4553 } else
4554 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
4555
4556 if (dut->ap_domain_name_list[0]) {
4557 char *next, *start, *dnbuf, *dn1, *anqp_dn;
4558 int len, dn_len_max;
4559 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304560 if (dnbuf == NULL) {
4561 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004562 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304563 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004564
4565 len = strlen(dnbuf);
4566 dn_len_max = 50 + len*2;
4567 anqp_dn = malloc(dn_len_max);
4568 if (anqp_dn == NULL) {
4569 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304570 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004571 return -1;
4572 }
4573 start = dnbuf;
4574 dn1 = anqp_dn;
4575 while (start && *start) {
4576 char *hexstr;
4577
4578 next = strchr(start, ',');
4579 if (next)
4580 *next++ = '\0';
4581
4582 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05304583 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004584 if (hexstr == NULL) {
4585 free(dnbuf);
4586 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304587 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004588 return -1;
4589 }
4590 ascii2hexstr(start, hexstr);
4591 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
4592 free(hexstr);
4593 dn1 += 2 + len * 2;
4594 dn_len_max -= 2 + len * 2;
4595 start = next;
4596 }
4597 free(dnbuf);
4598 if (dut->ap_gas_cb_delay) {
4599 fprintf(f, "dyn_domain_name=0c01%04x%s",
4600 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4601 domain_name = 1;
4602 } else
4603 fprintf(f, "domain_name=0c01%04x%s",
4604 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4605 free(anqp_dn);
4606 } else
4607 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
4608
4609 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
4610
4611 if (dut->ap_oper_name) {
4612 if (dut->ap_gas_cb_delay) {
4613 fprintf(f, "dyn_oper_friendly_name="
4614 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4615 oper_name = 1;
4616 } else
4617 fprintf(f, "oper_friendly_name="
4618 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4619 } else
4620 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
4621
4622 if (dut->ap_venue_name) {
4623 if (dut->ap_gas_cb_delay) {
4624 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
4625 venue_name = 1;
4626 } else
4627 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
4628 } else
4629 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
4630
4631 if (dut->ap_wan_metrics) {
4632 if (dut->ap_gas_cb_delay) {
4633 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
4634 wan_metrics = 1;
4635 } else
4636 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
4637 "\n");
4638 } else
4639 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
4640
4641 if (dut->ap_conn_capab) {
4642 if (dut->ap_gas_cb_delay) {
4643 fprintf(f, "dyn_conn_capability="
4644 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4645 conn_cap = 1;
4646 } else
4647 fprintf(f, "conn_capability="
4648 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4649 } else
4650 sigma_dut_print(dut, DUT_MSG_ERROR,
4651 "not setting conn_capability");
4652
4653 if (dut->ap_ip_addr_type_avail) {
4654 if (dut->ap_gas_cb_delay) {
4655 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
4656 "\n");
4657 ipaddr_avail = 1;
4658 } else
4659 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
4660 } else
4661 sigma_dut_print(dut, DUT_MSG_ERROR,
4662 "not setting ipaddr_type_avail");
4663
4664 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
4665 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
4666 dut->ap_plmn_mcc[i][1],
4667 dut->ap_plmn_mcc[i][0],
4668 dut->ap_plmn_mnc[i][2] == '\0' ?
4669 'f' : dut->ap_plmn_mnc[i][2],
4670 dut->ap_plmn_mcc[i][2],
4671 dut->ap_plmn_mnc[i][1],
4672 dut->ap_plmn_mnc[i][0]);
4673 }
4674 if (i) {
4675 uint16_t ie_len = (i * 3) + 5;
4676 if (dut->ap_gas_cb_delay) {
4677 fprintf(f, "dyn_cell_net=0801");
4678 cell_net = 1;
4679 } else
4680 fprintf(f, "cell_net=0801");
4681 fprintf(f, "%04x", LE16(ie_len));
4682 fprintf(f, "00"); /* version */
4683 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
4684 fprintf(f, "00"); /* plmn list */
4685 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
4686 fprintf(f, "%02x", i); /* number of plmns */
4687 fprintf(f, "%s\n", buf); /* plmns */
4688 } else
4689 sigma_dut_print(dut, DUT_MSG_ERROR,
4690 "not setting 3gpp_cellular_network");
4691
4692 if (nai_realm || domain_name || oper_name || venue_name ||
4693 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
4694 fprintf(f, "anqp_attach=");
4695 if (venue_name)
4696 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
4697 if (nai_realm)
4698 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
4699 if (cell_net)
4700 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
4701 if (domain_name)
4702 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
4703 if (oper_name)
4704 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
4705 if (wan_metrics)
4706 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
4707 if (conn_cap)
4708 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
4709 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
4710 fprintf(f, "\n");
4711 }
4712
4713 fclose(f);
4714
4715 run_system(dut, "anqpserver -i ath0 &");
4716 if (!dut->ap_anqpserver_on)
4717 run_system(dut, "killall anqpserver");
4718
4719 return 1;
4720}
4721
4722
4723static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
4724{
4725 char buf[100];
4726
4727 run_system(dut, "cfg -a AP_STARTMODE=standard");
4728
4729 if (sigma_radio_ifname[0] &&
4730 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4731 run_system(dut, "cfg -a AP_RADIO_ID=1");
4732 switch (dut->ap_mode) {
4733 case AP_11g:
4734 run_system(dut, "cfg -a AP_CHMODE_2=11G");
4735 break;
4736 case AP_11b:
4737 run_system(dut, "cfg -a AP_CHMODE_2=11B");
4738 break;
4739 case AP_11ng:
4740 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
4741 break;
4742 case AP_11a:
4743 run_system(dut, "cfg -a AP_CHMODE_2=11A");
4744 break;
4745 case AP_11na:
4746 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
4747 break;
4748 case AP_11ac:
4749 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4750 break;
4751 default:
4752 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4753 break;
4754 }
4755
4756 switch (dut->ap_rx_streams) {
4757 case 1:
4758 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
4759 break;
4760 case 2:
4761 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
4762 break;
4763 case 3:
4764 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
4765 break;
4766 }
4767
4768 switch (dut->ap_tx_streams) {
4769 case 1:
4770 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
4771 break;
4772 case 2:
4773 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
4774 break;
4775 case 3:
4776 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
4777 break;
4778 }
4779
4780 switch (dut->ap_chwidth) {
4781 case AP_20:
4782 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
4783 break;
4784 case AP_40:
4785 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
4786 break;
4787 case AP_80:
4788 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4789 break;
4790 case AP_160:
4791 case AP_AUTO:
4792 default:
4793 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4794 break;
4795 }
4796
4797 if (dut->ap_tx_stbc) {
4798 run_system(dut, "cfg -a TX_STBC_2=1");
4799 }
4800
4801 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
4802 dut->ap_channel);
4803
4804 if (dut->ap_is_dual) {
4805 switch (dut->ap_mode_1) {
4806 case AP_11g:
4807 run_system(dut, "cfg -a AP_CHMODE=11G");
4808 break;
4809 case AP_11b:
4810 run_system(dut, "cfg -a AP_CHMODE=11B");
4811 break;
4812 case AP_11ng:
4813 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4814 break;
4815 case AP_11a:
4816 run_system(dut, "cfg -a AP_CHMODE=11A");
4817 break;
4818 case AP_11na:
4819 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4820 break;
4821 case AP_11ac:
4822 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4823 break;
4824 default:
4825 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4826 break;
4827 }
4828 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4829 dut->ap_channel_1);
4830 }
4831 run_system(dut, buf);
4832 } else {
4833 run_system(dut, "cfg -a AP_RADIO_ID=0");
4834 switch (dut->ap_mode) {
4835 case AP_11g:
4836 run_system(dut, "cfg -a AP_CHMODE=11G");
4837 break;
4838 case AP_11b:
4839 run_system(dut, "cfg -a AP_CHMODE=11B");
4840 break;
4841 case AP_11ng:
4842 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4843 break;
4844 case AP_11a:
4845 run_system(dut, "cfg -a AP_CHMODE=11A");
4846 break;
4847 case AP_11na:
4848 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4849 break;
4850 case AP_11ac:
4851 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4852 break;
4853 default:
4854 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4855 break;
4856 }
4857 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4858 dut->ap_channel);
4859 run_system(dut, buf);
4860 }
4861
4862 if (dut->ap_sgi80 == 1) {
4863 run_system(dut, "cfg -a SHORTGI=1");
4864 run_system(dut, "cfg -a SHORTGI_2=1");
4865 } else if (dut->ap_sgi80 == 0) {
4866 run_system(dut, "cfg -a SHORTGI=0");
4867 run_system(dut, "cfg -a SHORTGI_2=0");
4868 }
4869
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004870 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004871 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004872 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004873 run_system(dut, "cfg -a LDPC=0");
4874}
4875
4876
4877void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
4878{
4879 char buf[50];
4880
4881 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
4882 if (system(buf) != 0)
4883 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
4884
4885 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
4886 if (system(buf) != 0)
4887 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
4888
4889 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
4890 if (system(buf) != 0)
4891 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
4892
4893 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
4894 if (system(buf) != 0)
4895 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
4896}
4897
4898
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004899static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
4900 const char *val)
4901{
4902 if (strcasecmp(val, "enable") == 0) {
4903 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 1", ifname);
4904 } else if (strcasecmp(val, "disable") == 0) {
4905 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 0", ifname);
4906 } else {
4907 sigma_dut_print(dut, DUT_MSG_ERROR,
4908 "Unsupported assoc_disallow");
4909 }
4910}
4911
4912
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07004913static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
4914{
4915 int i;
4916 int least_pref = 1 << 8;
4917 char ifname[20];
4918 uint8_t self_mac[ETH_ALEN];
4919 char buf[200];
4920 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
4921
4922 get_if_name(dut, ifname, sizeof(ifname), 1);
4923 get_hwaddr(ifname, self_mac);
4924
4925 /* Clear off */
4926 snprintf(buf, sizeof(buf),
4927 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
4928 ifname);
4929 run_system(dut, buf);
4930
4931 /* Find the least preference number */
4932 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
4933 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
4934
4935 ap_ne_class = 1;
4936 ap_ne_pref = 255;
4937 ap_ne_op_ch = 1;
4938 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
4939 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
4940 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
4941 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
4942 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
4943 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
4944
4945 if (ap_ne_pref < least_pref)
4946 least_pref = ap_ne_pref;
4947 snprintf(buf, sizeof(buf),
4948 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4949 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
4950 mac_addr[3], mac_addr[4], mac_addr[5],
4951 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
4952 run_system(dut, buf);
4953 }
4954
4955 /* Now add the self AP Address */
4956 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
4957 if (dut->ap_channel <= 11)
4958 ap_ne_class = 81;
4959 else
4960 ap_ne_class = 115;
4961 } else {
4962 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
4963 }
4964
4965 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
4966 ap_ne_op_ch = dut->ap_channel;
4967 else
4968 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
4969
4970 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
4971 ap_ne_pref = least_pref - 1;
4972 else
4973 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
4974
4975 snprintf(buf, sizeof(buf),
4976 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4977 ifname, self_mac[0], self_mac[1], self_mac[2],
4978 self_mac[3], self_mac[4], self_mac[5],
4979 ap_ne_pref,
4980 ap_ne_class,
4981 ap_ne_op_ch);
4982 run_system(dut, buf);
4983}
4984
4985
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004986static void ath_ap_set_params(struct sigma_dut *dut)
4987{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08004988 const char *basedev = "wifi0";
4989 const char *basedev_radio = "wifi1";
4990 char *ifname = get_main_ifname();
4991 char *ifname_dual;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004992 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07004993 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004994
priyadharshini gowthamane1617462017-04-25 12:03:59 -07004995 if (sigma_radio_ifname[0])
4996 basedev = sigma_radio_ifname[0];
4997
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08004998 if (dut->ap_is_dual == 1) {
4999 basedev = sigma_radio_ifname[0];
5000 basedev_radio = sigma_radio_ifname[1];
5001 if (sigma_radio_ifname[0] &&
5002 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5003 ifname = "ath0";
5004 ifname_dual = "ath1";
5005 } else {
5006 ifname = "ath1";
5007 ifname_dual = "ath0";
5008 }
5009 }
5010
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005011 if (dut->ap_countrycode[0]) {
5012 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
5013 basedev, dut->ap_countrycode);
5014 if (system(buf) != 0) {
5015 sigma_dut_print(dut, DUT_MSG_ERROR,
5016 "iwpriv setCountry failed");
5017 }
5018 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5019 }
5020
5021 for (i = 0; i < NUM_AP_AC; i++) {
5022 if (dut->ap_qos[i].ac) {
5023 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
5024 ifname, i, dut->ap_qos[i].cwmin);
5025 if (system(buf) != 0) {
5026 sigma_dut_print(dut, DUT_MSG_ERROR,
5027 "iwpriv cwmin failed");
5028 }
5029
5030 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
5031 ifname, i, dut->ap_qos[i].cwmax);
5032 if (system(buf) != 0) {
5033 sigma_dut_print(dut, DUT_MSG_ERROR,
5034 "iwpriv cwmax failed");
5035 }
5036
5037 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
5038 ifname, i, dut->ap_qos[i].aifs);
5039 if (system(buf) != 0) {
5040 sigma_dut_print(dut, DUT_MSG_ERROR,
5041 "iwpriv aifs failed");
5042 }
5043
5044 snprintf(buf, sizeof(buf),
5045 "iwpriv %s txoplimit %d 0 %d",
5046 ifname, i, dut->ap_qos[i].txop);
5047 if (system(buf) != 0) {
5048 sigma_dut_print(dut, DUT_MSG_ERROR,
5049 "iwpriv txoplimit failed");
5050 }
5051
5052 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
5053 ifname, i, dut->ap_qos[i].acm);
5054 if (system(buf) != 0) {
5055 sigma_dut_print(dut, DUT_MSG_ERROR,
5056 "iwpriv acm failed");
5057 }
5058 }
5059 }
5060
5061 for (i = 0; i < NUM_AP_AC; i++) {
5062 if (dut->ap_sta_qos[i].ac) {
5063 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
5064 ifname, i, dut->ap_sta_qos[i].cwmin);
5065 if (system(buf) != 0) {
5066 sigma_dut_print(dut, DUT_MSG_ERROR,
5067 "iwpriv cwmin failed");
5068 }
5069
5070 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
5071 ifname, i, dut->ap_sta_qos[i].cwmax);
5072 if (system(buf) != 0) {
5073 sigma_dut_print(dut, DUT_MSG_ERROR,
5074 "iwpriv cwmax failed");
5075 }
5076
5077 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
5078 ifname, i, dut->ap_sta_qos[i].aifs);
5079 if (system(buf) != 0) {
5080 sigma_dut_print(dut, DUT_MSG_ERROR,
5081 "iwpriv aifs failed");
5082 }
5083
5084 snprintf(buf, sizeof(buf),
5085 "iwpriv %s txoplimit %d 1 %d",
5086 ifname, i, dut->ap_sta_qos[i].txop);
5087 if (system(buf) != 0) {
5088 sigma_dut_print(dut, DUT_MSG_ERROR,
5089 "iwpriv txoplimit failed");
5090 }
5091
5092 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
5093 ifname, i, dut->ap_sta_qos[i].acm);
5094 if (system(buf) != 0) {
5095 sigma_dut_print(dut, DUT_MSG_ERROR,
5096 "iwpriv acm failed");
5097 }
5098 }
5099 }
5100
5101 if (dut->ap_disable_protection == 1) {
5102 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
5103 if (system(buf) != 0) {
5104 sigma_dut_print(dut, DUT_MSG_ERROR,
5105 "iwpriv enablertscts failed");
5106 }
5107 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5108 }
5109
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005110 if (dut->ap_ldpc == VALUE_ENABLED) {
Sarvepalli, Rajesh Babu580572a2016-11-29 22:07:14 +05305111 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 3", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005112 if (system(buf) != 0) {
5113 sigma_dut_print(dut, DUT_MSG_ERROR,
priyadharshini gowthaman15b299d2017-04-20 12:10:45 -07005114 "iwpriv ldpc 3 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005115 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005116 } else if (dut->ap_ldpc == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
5118 if (system(buf) != 0) {
5119 sigma_dut_print(dut, DUT_MSG_ERROR,
5120 "iwpriv ldpc 0 failed");
5121 }
5122 }
5123
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005124 if (dut->ap_ampdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005125 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
5126 if (system(buf) != 0) {
5127 sigma_dut_print(dut, DUT_MSG_ERROR,
5128 "iwpriv ampdu 1 failed");
5129 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005130 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005131 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
5132 if (system(buf) != 0) {
5133 sigma_dut_print(dut, DUT_MSG_ERROR,
5134 "iwpriv ampdu 0 failed");
5135 }
5136 }
5137
5138 if (dut->ap_ampdu_exp) {
5139 if (dut->program == PROGRAM_VHT) {
5140 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
5141 ifname, dut->ap_ampdu_exp);
5142 if (system(buf) != 0) {
5143 sigma_dut_print(dut, DUT_MSG_ERROR,
5144 "iwpriv vhtmaxampdu failed");
5145 }
5146 } else {
5147 /* 11N */
5148 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
5149 ifname, dut->ap_ampdu_exp);
5150 if (system(buf) != 0) {
5151 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
5152 }
5153 }
5154 }
5155
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005156 if (dut->ap_noack == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005157 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
5158 if (system(buf) != 0) {
5159 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
5160 }
5161 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
5162 if (system(buf) != 0) {
5163 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
5164 }
5165 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
5166 if (system(buf) != 0) {
5167 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
5168 }
5169 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
5170 if (system(buf) != 0) {
5171 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
5172 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005173 } else if (dut->ap_noack == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005174 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
5175 if (system(buf) != 0) {
5176 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
5177 }
5178 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
5179 if (system(buf) != 0) {
5180 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
5181 }
5182 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
5183 if (system(buf) != 0) {
5184 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
5185 }
5186 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
5187 if (system(buf) != 0) {
5188 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
5189 }
5190 }
5191
5192 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
5193 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5194 ifname, dut->ap_vhtmcs_map);
5195 if (system(buf) != 0) {
5196 sigma_dut_print(dut, DUT_MSG_ERROR,
5197 "iwpriv vht_mcsmap failed");
5198 }
5199 }
5200
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005201 if (dut->ap_amsdu == VALUE_ENABLED) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005202 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005203 if (system(buf) != 0) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005204 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005205 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005206 } else if (dut->ap_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005207 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
5208 if (system(buf) != 0) {
5209 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
5210 }
5211 }
5212
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005213 if (dut->ap_rx_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005214 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
5215 if (system(buf) != 0) {
5216 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
5217 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005218 } else if (dut->ap_rx_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005219 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
5220 if (system(buf) != 0) {
5221 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
5222 }
5223 }
5224
5225 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005226 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5227 dut->ap_ampdu == VALUE_DISABLED &&
5228 dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005229 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
5230 if (system(buf) != 0) {
5231 sigma_dut_print(dut, DUT_MSG_ERROR,
5232 "iwpriv setaddbaoper 1 failed");
5233 }
5234
5235 snprintf(buf, sizeof(buf),
5236 "wifitool %s senddelba 1 0 1 4", ifname);
5237 if (system(buf) != 0) {
5238 sigma_dut_print(dut, DUT_MSG_ERROR,
5239 "wifitool senddelba failed");
5240 }
5241
5242 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5243 ifname);
5244 if (system(buf) != 0) {
5245 sigma_dut_print(dut, DUT_MSG_ERROR,
5246 "wifitool sendsingleamsdu failed");
5247 }
5248
5249 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
5250 if (system(buf) != 0) {
5251 sigma_dut_print(dut, DUT_MSG_ERROR,
5252 "iwpriv amsdu failed");
5253 }
5254 }
5255
5256 if (dut->ap_mode == AP_11ac) {
5257 int chwidth, nss;
5258
5259 switch (dut->ap_chwidth) {
5260 case AP_20:
5261 chwidth = 0;
5262 break;
5263 case AP_40:
5264 chwidth = 1;
5265 break;
5266 case AP_80:
5267 chwidth = 2;
5268 break;
5269 case AP_160:
5270 chwidth = 3;
5271 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005272 case AP_80_80:
5273 chwidth = 3;
5274 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005275 default:
5276 chwidth = 0;
5277 break;
5278 }
5279
5280 switch (dut->ap_tx_streams) {
5281 case 1:
5282 nss = 1;
5283 break;
5284 case 2:
5285 nss = 2;
5286 break;
5287 case 3:
5288 nss = 3;
5289 break;
5290 case 4:
5291 nss = 4;
5292 break;
5293 default:
5294 nss = 3;
5295 break;
5296 }
5297
5298 if (dut->ap_fixed_rate) {
5299 if (nss == 4)
5300 ath_disable_txbf(dut, ifname);
5301
5302 /* Set the nss */
5303 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
5304 ifname, nss);
5305 if (system(buf) != 0) {
5306 sigma_dut_print(dut, DUT_MSG_ERROR,
5307 "iwpriv nss failed");
5308 }
5309
5310 /* Set the channel width */
5311 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5312 ifname, chwidth);
5313 if (system(buf) != 0) {
5314 sigma_dut_print(dut, DUT_MSG_ERROR,
5315 "iwpriv chwidth failed");
5316 }
5317
5318 /* Set the VHT MCS */
5319 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
5320 ifname, dut->ap_mcs);
5321 if (system(buf) != 0) {
5322 sigma_dut_print(dut, DUT_MSG_ERROR,
5323 "iwpriv vhtmcs failed");
5324 }
5325 }
5326 }
5327
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005328 if (dut->ap_dyn_bw_sig == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005329 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
5330 if (system(buf) != 0) {
5331 sigma_dut_print(dut, DUT_MSG_ERROR,
5332 "iwpriv cwmenable 1 failed");
5333 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005334 } else if (dut->ap_dyn_bw_sig == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005335 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
5336 if (system(buf) != 0) {
5337 sigma_dut_print(dut, DUT_MSG_ERROR,
5338 "iwpriv cwmenable 0 failed");
5339 }
5340 }
5341
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005342 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005343 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5344 if (system(buf) != 0) {
5345 sigma_dut_print(dut, DUT_MSG_ERROR,
5346 "iwconfig rts 64 failed");
5347 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005348 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005349 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5350 if (system(buf) != 0) {
5351 sigma_dut_print(dut, DUT_MSG_ERROR,
5352 "iwpriv rts 2347 failed");
5353 }
5354 }
5355
5356 if (dut->ap_hs2) {
5357 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
5358 if (system(buf) != 0) {
5359 sigma_dut_print(dut, DUT_MSG_ERROR,
5360 "iwpriv qbssload failed");
5361 }
5362 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5363 }
5364
5365 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5366 unsigned int bssload = 0;
5367
5368 if (dut->ap_bss_load == 1) {
5369 /* STA count: 1, CU: 50, AAC: 65535 */
5370 bssload = 0x0132ffff;
5371 } else if (dut->ap_bss_load == 2) {
5372 /* STA count: 1, CU: 200, AAC: 65535 */
5373 bssload = 0x01c8ffff;
5374 } else if (dut->ap_bss_load == 3) {
5375 /* STA count: 1, CU: 75, AAC: 65535 */
5376 bssload = 0x014bffff;
5377 }
5378
5379 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
5380 ifname, bssload);
5381 if (system(buf) != 0) {
5382 sigma_dut_print(dut, DUT_MSG_ERROR,
5383 "iwpriv hcbssload failed");
5384 }
5385 } else if (dut->ap_bss_load == 0) {
5386 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5387 if (system(buf) != 0) {
5388 sigma_dut_print(dut, DUT_MSG_ERROR,
5389 "iwpriv qbssload failed");
5390 }
5391 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5392 }
5393
5394 if (dut->ap_dgaf_disable) {
5395 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
5396 if (system(buf) != 0) {
5397 sigma_dut_print(dut, DUT_MSG_ERROR,
5398 "iwpriv dgaf_disable failed");
5399 }
5400 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
5401 }
5402
5403 if (dut->ap_l2tif) {
5404 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
5405 if (system(buf) != 0) {
5406 sigma_dut_print(dut, DUT_MSG_ERROR,
5407 "iwpriv l2tif failed");
5408 }
5409 snprintf(buf, sizeof(buf),
5410 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
5411 if (system(buf) != 0)
5412 sigma_dut_print(dut, DUT_MSG_ERROR,
5413 "l2tif br failed");
5414
5415 snprintf(buf, sizeof(buf),
5416 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
5417 if (system(buf) != 0)
5418 sigma_dut_print(dut, DUT_MSG_ERROR,
5419 "l2tif brif failed");
5420 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
5421 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005422
5423 if (dut->ap_ndpa_frame == 0) {
5424 snprintf(buf, sizeof(buf),
5425 "wifitool %s beeliner_fw_test 117 192", ifname);
5426 if (system(buf) != 0) {
5427 sigma_dut_print(dut, DUT_MSG_ERROR,
5428 "wifitool beeliner_fw_test 117 192 failed");
5429 }
5430 snprintf(buf, sizeof(buf),
5431 "wifitool %s beeliner_fw_test 118 192", ifname);
5432 if (system(buf) != 0) {
5433 sigma_dut_print(dut, DUT_MSG_ERROR,
5434 "wifitool beeliner_fw_test 117 192 failed");
5435 }
5436 } else if (dut->ap_ndpa_frame == 1) {
5437 /* Driver default - no changes needed */
5438 } else if (dut->ap_ndpa_frame == 2) {
5439 snprintf(buf, sizeof(buf),
5440 "wifitool %s beeliner_fw_test 115 1", ifname);
5441 if (system(buf) != 0) {
5442 sigma_dut_print(dut, DUT_MSG_ERROR,
5443 "wifitool beeliner_fw_test 117 192 failed");
5444 }
5445 snprintf(buf, sizeof(buf),
5446 "wifitool %s beeliner_fw_test 116 1", ifname);
5447 if (system(buf) != 0) {
5448 sigma_dut_print(dut, DUT_MSG_ERROR,
5449 "wifitool beeliner_fw_test 117 192 failed");
5450 }
5451 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005452
5453 if (dut->ap_rtt == 1) {
5454 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5455 run_system(dut, buf);
5456 }
5457
5458 if (dut->ap_lci == 1) {
5459 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5460 run_system(dut, buf);
5461 }
5462
5463 if (dut->ap_lcr == 1) {
5464 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5465 run_system(dut, buf);
5466 }
5467
5468 if (dut->ap_rrm == 1) {
5469 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5470 run_system(dut, buf);
5471 }
5472
5473 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
5474 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
5475 }
5476
5477 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
5478 FILE *f;
5479
5480 f = fopen("/tmp/nbr_report.txt", "w");
5481 if (!f) {
5482 sigma_dut_print(dut, DUT_MSG_ERROR,
5483 "Failed to open /tmp/nbr_report.txt");
5484 return;
5485 }
5486
5487 fprintf(f,
5488 "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",
5489 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5490 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5491 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5492 dut->ap_val_opchannel[0]);
5493 fclose(f);
5494
5495 f = fopen("/tmp/ftmrr.txt", "w");
5496 if (!f) {
5497 sigma_dut_print(dut, DUT_MSG_ERROR,
5498 "Failed to open /tmp/ftmrr.txt");
5499 return;
5500 }
5501
5502 fprintf(f,
5503 "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",
5504 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5505 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5506 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5507 dut->ap_val_opchannel[0]);
5508 fclose(f);
5509 }
5510
5511 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
5512 FILE *f;
5513
5514 f = fopen("/tmp/nbr_report.txt", "a");
5515 if (!f) {
5516 sigma_dut_print(dut, DUT_MSG_ERROR,
5517 "Failed to open /tmp/nbr_report.txt");
5518 return;
5519 }
5520 fprintf(f,
5521 "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",
5522 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5523 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5524 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5525 dut->ap_val_opchannel[1]);
5526 fclose(f);
5527
5528 f = fopen("/tmp/ftmrr.txt", "a");
5529 if (!f) {
5530 sigma_dut_print(dut, DUT_MSG_ERROR,
5531 "Failed to open /tmp/ftmrr.txt");
5532 return;
5533 }
5534 fprintf(f,
5535 "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",
5536 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5537 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5538 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5539 dut->ap_val_opchannel[1]);
5540 fclose(f);
5541 }
5542
5543 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
5544 FILE *f;
5545
5546 f = fopen("/tmp/nbr_report.txt", "a");
5547 if (!f) {
5548 sigma_dut_print(dut, DUT_MSG_ERROR,
5549 "Failed to open /tmp/nbr_report.txt");
5550 return;
5551 }
5552
5553 fprintf(f,
5554 "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",
5555 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5556 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5557 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5558 dut->ap_val_opchannel[2]);
5559 fclose(f);
5560
5561 f = fopen("/tmp/ftmrr.txt", "a");
5562 if (!f) {
5563 sigma_dut_print(dut, DUT_MSG_ERROR,
5564 "Failed to open /tmp/ftmrr.txt");
5565 return;
5566 }
5567
5568 fprintf(f,
5569 "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",
5570 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5571 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5572 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5573 dut->ap_val_opchannel[2]);
5574 fclose(f);
5575 }
5576
5577 if (dut->ap_neighap) {
5578 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5579 run_system(dut, buf);
5580 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5581 run_system(dut, buf);
5582 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5583 run_system(dut, buf);
5584 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5585 run_system(dut, buf);
5586 }
5587
5588 if (dut->ap_scan == 1) {
5589 snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600",
5590 ifname);
5591 run_system(dut, buf);
5592 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
5593 run_system(dut, buf);
5594 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07005595
5596 if (dut->ap_set_bssidpref) {
5597 snprintf(buf, sizeof(buf),
5598 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
5599 ifname);
5600 if (system(buf) != 0) {
5601 sigma_dut_print(dut, DUT_MSG_ERROR,
5602 "wifitool clear bssidpref failed");
5603 }
5604 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005605
5606 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
5607 int feature_enable;
5608
5609 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
5610 snprintf(buf, sizeof(buf), "iwpriv %s wnm %d",
5611 ifname, feature_enable);
5612 run_system(dut, buf);
5613 snprintf(buf, sizeof(buf), "iwpriv %s wnm_bss %d",
5614 ifname, feature_enable);
5615 run_system(dut, buf);
5616 if (feature_enable) {
5617 const char *extra = "";
5618
5619 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
5620 if (dut->wnm_bss_max_protection ==
5621 VALUE_ENABLED)
5622 extra = " 1";
5623 else
5624 extra = " 0";
5625 }
5626 snprintf(buf, sizeof(buf),
5627 "wlanconfig %s wnm setbssmax %d%s",
5628 ifname, dut->wnm_bss_max_idle_time, extra);
5629 run_system(dut, buf);
5630 }
5631 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005632
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005633 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005634 apply_mbo_pref_ap_list(dut);
5635
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005636 snprintf(buf, sizeof(buf), "iwpriv %s mbo_cel_pref %d",
5637 ifname, dut->ap_cell_cap_pref);
5638 run_system(dut, buf);
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07005639
5640 snprintf(buf, sizeof(buf), "iwpriv %s mbocap 0x40", ifname);
5641 run_system(dut, buf);
5642
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005643 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005644 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005645
5646 if (dut->ap_oce == VALUE_ENABLED) {
5647 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 1",
5648 ifname);
5649 run_system(dut, buf);
5650 }
5651
5652 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
5653 snprintf(buf, sizeof(buf), "iwpriv %s prb_rate 5500", ifname);
5654 run_system(dut, buf);
5655 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 5500",
5656 ifname);
5657 run_system(dut, buf);
5658 }
5659
5660 if (dut->ap_oce == VALUE_DISABLED) {
5661 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 0",
5662 ifname);
5663 run_system(dut, buf);
5664 }
5665
5666 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
5667 snprintf(buf, sizeof(buf), "iwpriv %s mgmt_rate 1000", ifname);
5668 run_system(dut, buf);
5669 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 1000",
5670 ifname);
5671 run_system(dut, buf);
5672 }
5673
5674 if (dut->ap_bcnint) {
5675 snprintf(buf, sizeof(buf), "iwpriv %s bintval %d", ifname,
5676 dut->ap_bcnint);
5677 run_system(dut, buf);
5678 }
5679
5680 if (dut->ap_filsdscv == VALUE_DISABLED) {
5681 snprintf(buf, sizeof(buf), "iwpriv %s enable_fils 0 0", ifname);
5682 run_system(dut, buf);
5683 }
5684
5685 if (dut->ap_filshlp == VALUE_ENABLED) {
5686 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 1", ifname);
5687 if (system(buf) != 0) {
5688 sigma_dut_print(dut, DUT_MSG_ERROR,
5689 "iwpriv filshlp enable failed");
5690 }
5691 } else if (dut->ap_filshlp == VALUE_DISABLED) {
5692 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 0", ifname);
5693 if (system(buf) != 0) {
5694 sigma_dut_print(dut, DUT_MSG_ERROR,
5695 "iwpriv filshlp disable failed");
5696 }
5697 }
5698
5699 /* When RNR is enabled, also enable apchannelreport, background scan */
5700 if (dut->ap_rnr == VALUE_ENABLED) {
5701 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1", ifname);
5702 run_system(dut, buf);
5703 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1", ifname);
5704 run_system(dut, buf);
5705 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1", ifname);
5706 run_system(dut, buf);
5707 snprintf(buf, sizeof(buf), "iwpriv %s acs_ctrlflags 0x4",
5708 basedev);
5709 run_system(dut, buf);
5710 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5711 basedev);
5712 run_system(dut, buf);
5713 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1", basedev);
5714 run_system(dut, buf);
5715 if (dut->ap_is_dual == 1) {
5716 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1",
5717 ifname_dual);
5718 run_system(dut, buf);
5719 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1",
5720 ifname_dual);
5721 run_system(dut, buf);
5722 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1",
5723 ifname_dual);
5724 run_system(dut, buf);
5725 snprintf(buf, sizeof(buf),
5726 "iwpriv %s acs_ctrlflags 0x4", basedev_radio);
5727 run_system(dut, buf);
5728 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5729 basedev_radio);
5730 run_system(dut, buf);
5731 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1",
5732 basedev_radio);
5733 run_system(dut, buf);
5734 }
5735 }
5736
5737 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
5738 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5739 run_system(dut, buf);
5740 snprintf(buf, sizeof(buf),
5741 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
5742 ifname, dut->ap_blestacnt & 0xFF,
5743 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5744 dut->ap_ble_admit_cap & 0xFF,
5745 dut->ap_ble_admit_cap >> 8);
5746 run_system(dut, buf);
5747 snprintf(buf, sizeof(buf),
5748 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
5749 ifname, dut->ap_blestacnt & 0xFF,
5750 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5751 dut->ap_ble_admit_cap & 0xFF,
5752 dut->ap_ble_admit_cap >> 8);
5753 run_system(dut, buf);
5754 }
5755
5756 if (dut->ap_esp == VALUE_ENABLED) {
5757 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 5", basedev);
5758 if (system(buf) != 0) {
5759 sigma_dut_print(dut, DUT_MSG_ERROR,
5760 "iwpriv esp enable failed");
5761 }
5762 } else if (dut->ap_esp == VALUE_DISABLED) {
5763 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 0", basedev);
5764 if (system(buf) != 0) {
5765 sigma_dut_print(dut, DUT_MSG_ERROR,
5766 "iwpriv esp disable failed");
5767 }
5768 }
5769
5770 if (dut->ap_datappdudura) {
5771 snprintf(buf, sizeof(buf), "iwpriv %s esp_ppdu_dur %d", basedev,
5772 dut->ap_datappdudura);
5773 run_system(dut, buf);
5774 }
5775
5776 if (dut->ap_airtimefract) {
5777 snprintf(buf, sizeof(buf), "iwpriv %s esp_airtime %d", basedev,
5778 dut->ap_airtimefract);
5779 run_system(dut, buf);
5780 }
5781
5782 if (dut->ap_dhcp_stop) {
5783 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
5784 run_system(dut, buf);
5785 }
5786
5787 if (dut->ap_bawinsize) {
5788 snprintf(buf, sizeof(buf), "iwpriv %s esp_ba_window %d",
5789 basedev, dut->ap_bawinsize);
5790 run_system(dut, buf);
5791 }
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005792
5793 if (dut->program == PROGRAM_DPP) {
5794 if (dut->ap_interface_2g == 1) {
5795 snprintf(buf, sizeof(buf),
5796 "iwpriv %s set_bcn_rate 5500", ifname);
5797 run_system(dut, buf);
5798 snprintf(buf, sizeof(buf),
5799 "iwpriv %s prb_rate 5500", ifname);
5800 run_system(dut, buf);
5801 snprintf(buf, sizeof(buf),
5802 "iwpriv %s mgmt_rate 5500", ifname);
5803 run_system(dut, buf);
5804 }
5805
5806 snprintf(buf, sizeof(buf), "iwpriv %s set_rxfilter 0xffffffff",
5807 basedev);
5808 run_system(dut, buf);
5809 dut->hostapd_running = 1;
5810 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07005811
5812 if (dut->ap_he_ppdu == PPDU_MU) {
5813 run_system_wrapper(
5814 dut, "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
5815 ifname);
5816 run_system_wrapper(
5817 dut, "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
5818 ifname);
5819 run_system_wrapper(dut,
5820 "wifitool %s setUnitTestCmd 0x47 2 8 0",
5821 ifname);
5822 run_system_wrapper(dut,
5823 "wifitool %s setUnitTestCmd 0x47 2 29 0",
5824 ifname);
5825 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005826}
5827
5828
5829static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
5830 struct sigma_conn *conn,
5831 struct sigma_cmd *cmd)
5832{
5833 /* const char *name = get_param(cmd, "NAME"); */
5834 char buf[100];
5835 struct stat s;
5836 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
5837
5838 if (stat("/proc/athversion", &s) == 0) {
5839 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
5840 run_system(dut, "apdown");
5841 }
5842
5843 cmd_ath_ap_radio_config(dut);
5844
5845 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
5846 run_system(dut, buf);
5847
5848 switch (dut->ap_key_mgmt) {
5849 case AP_OPEN:
5850 if (dut->ap_cipher == AP_WEP) {
5851 run_system(dut, "cfg -a AP_SECMODE=WEP");
5852 run_system(dut, "cfg -a AP_SECFILE=NONE");
5853 /* shared auth mode not supported */
5854 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5855 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5856 snprintf(buf, sizeof(buf),
5857 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5858 dut->ap_wepkey);
5859 run_system(dut, buf);
5860 snprintf(buf, sizeof(buf),
5861 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5862 dut->ap_wepkey);
5863 run_system(dut, buf);
5864 } else {
5865 run_system(dut, "cfg -a AP_SECMODE=None");
5866 }
5867 break;
5868 case AP_WPA2_PSK:
5869 case AP_WPA2_PSK_MIXED:
5870 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005871 case AP_WPA2_SAE:
5872 case AP_WPA2_PSK_SAE:
5873 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5874 dut->ap_key_mgmt == AP_WPA2_SAE ||
5875 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005876 run_system(dut, "cfg -a AP_WPA=2");
5877 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5878 run_system(dut, "cfg -a AP_WPA=3");
5879 else
5880 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03005881 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005882 run_system(dut, "cfg -a AP_SECMODE=WPA");
5883 run_system(dut, "cfg -a AP_SECFILE=PSK");
5884 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
5885 dut->ap_passphrase);
5886 run_system(dut, buf);
5887 if (dut->ap_cipher == AP_CCMP_TKIP)
5888 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
5889 else if (dut->ap_cipher == AP_TKIP)
5890 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5891 else
5892 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5893 break;
5894 case AP_WPA2_EAP:
5895 case AP_WPA2_EAP_MIXED:
5896 case AP_WPA_EAP:
5897 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5898 run_system(dut, "cfg -a AP_WPA=2");
5899 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5900 run_system(dut, "cfg -a AP_WPA=3");
5901 else
5902 run_system(dut, "cfg -a AP_WPA=1");
5903 run_system(dut, "cfg -a AP_SECMODE=WPA");
5904 run_system(dut, "cfg -a AP_SECFILE=EAP");
5905 if (dut->ap_cipher == AP_CCMP_TKIP)
5906 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
5907 else if (dut->ap_cipher == AP_TKIP)
5908 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5909 else
5910 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5911 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
5912 dut->ap_radius_ipaddr);
5913 run_system(dut, buf);
5914 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
5915 dut->ap_radius_port);
5916 run_system(dut, buf);
5917 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
5918 dut->ap_radius_password);
5919 run_system(dut, buf);
5920 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03005921 case AP_WPA2_EAP_OSEN:
5922 /* TODO */
5923 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
5924 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03005925 case AP_SUITEB:
5926 /* TODO */
5927 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
5928 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03005929 case AP_WPA2_OWE:
5930 /* TODO */
5931 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
5932 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005933 }
5934
5935 if (dut->ap_is_dual) {
5936 /* ath1 settings in case of dual */
5937 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
5938 dut->ap_ssid);
5939 run_system(dut, buf);
5940
5941 switch (dut->ap_key_mgmt) {
5942 case AP_OPEN:
5943 if (dut->ap_cipher == AP_WEP) {
5944 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
5945 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
5946 /* shared auth mode not supported */
5947 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5948 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5949 snprintf(buf, sizeof(buf),
5950 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5951 dut->ap_wepkey);
5952 run_system(dut, buf);
5953 snprintf(buf, sizeof(buf),
5954 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5955 dut->ap_wepkey);
5956 run_system(dut, buf);
5957 } else {
5958 run_system(dut, "cfg -a AP_SECMODE_2=None");
5959 }
5960 break;
5961 case AP_WPA2_PSK:
5962 case AP_WPA2_PSK_MIXED:
5963 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005964 case AP_WPA2_SAE:
5965 case AP_WPA2_PSK_SAE:
5966 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5967 dut->ap_key_mgmt == AP_WPA2_SAE ||
5968 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005969 run_system(dut, "cfg -a AP_WPA_2=2");
5970 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5971 run_system(dut, "cfg -a AP_WPA_2=3");
5972 else
5973 run_system(dut, "cfg -a AP_WPA_2=1");
5974 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03005975 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005976 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5977 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
5978 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
5979 dut->ap_passphrase);
5980 run_system(dut, buf);
5981 if (dut->ap_cipher == AP_CCMP_TKIP)
5982 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
5983 else if (dut->ap_cipher == AP_TKIP)
5984 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
5985 else
5986 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
5987 break;
5988 case AP_WPA2_EAP:
5989 case AP_WPA2_EAP_MIXED:
5990 case AP_WPA_EAP:
5991 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5992 run_system(dut, "cfg -a AP_WPA_2=2");
5993 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5994 run_system(dut, "cfg -a AP_WPA_2=3");
5995 else
5996 run_system(dut, "cfg -a AP_WPA_2=1");
5997 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5998 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
5999 if (dut->ap_cipher == AP_CCMP_TKIP)
6000 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6001 else if (dut->ap_cipher == AP_TKIP)
6002 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6003 else
6004 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6005
6006 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6007 dut->ap_radius_ipaddr);
6008 run_system(dut, buf);
6009 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6010 dut->ap_radius_port);
6011 run_system(dut, buf);
6012 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6013 dut->ap_radius_password);
6014 run_system(dut, buf);
6015 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006016 case AP_WPA2_EAP_OSEN:
6017 /* TODO */
6018 sigma_dut_print(dut, DUT_MSG_ERROR,
6019 "EAP+OSEN not supported");
6020 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006021 case AP_SUITEB:
6022 /* TODO */
6023 sigma_dut_print(dut, DUT_MSG_ERROR,
6024 "SuiteB not supported");
6025 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006026 case AP_WPA2_OWE:
6027 /* TODO */
6028 sigma_dut_print(dut, DUT_MSG_ERROR,
6029 "OWE not supported");
6030 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006031 }
6032
6033 /* wifi0 settings in case of dual */
6034 run_system(dut, "cfg -a AP_RADIO_ID=0");
6035 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6036 run_system(dut, "cfg -a AP_STARTMODE=dual");
6037 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6038 run_system(dut, "cfg -a TX_CHAINMASK=7");
6039 run_system(dut, "cfg -a RX_CHAINMASK=7");
6040 }
6041
6042 switch (dut->ap_pmf) {
6043 case AP_PMF_DISABLED:
6044 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6045 run_system(dut, buf);
6046 break;
6047 case AP_PMF_OPTIONAL:
6048 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6049 run_system(dut, buf);
6050 break;
6051 case AP_PMF_REQUIRED:
6052 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6053 run_system(dut, buf);
6054 break;
6055 }
6056 if (dut->ap_add_sha256) {
6057 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6058 run_system(dut, buf);
6059 } else {
6060 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6061 run_system(dut, buf);
6062 }
6063
6064 if (dut->ap_hs2)
6065 run_system(dut, "cfg -a AP_HOTSPOT=1");
6066 else
6067 run_system(dut, "cfg -r AP_HOTSPOT");
6068
6069 if (dut->ap_interworking) {
6070 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6071 dut->ap_access_net_type);
6072 run_system(dut, buf);
6073 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6074 dut->ap_internet);
6075 run_system(dut, buf);
6076 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6077 dut->ap_venue_group);
6078 run_system(dut, buf);
6079 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6080 dut->ap_venue_type);
6081 run_system(dut, buf);
6082 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6083 dut->ap_hessid);
6084 run_system(dut, buf);
6085
6086 if (dut->ap_roaming_cons[0]) {
6087 char *second, *rc;
6088 rc = strdup(dut->ap_roaming_cons);
6089 if (rc == NULL)
6090 return 0;
6091
6092 second = strchr(rc, ';');
6093 if (second)
6094 *second++ = '\0';
6095
6096 snprintf(buf, sizeof(buf),
6097 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6098 run_system(dut, buf);
6099
6100 if (second) {
6101 snprintf(buf, sizeof(buf),
6102 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6103 "=%s", second);
6104 run_system(dut, buf);
6105 }
6106 free(rc);
6107 } else {
6108 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6109 run_system(dut,
6110 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6111 }
6112 } else {
6113 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6114 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6115 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6116 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6117 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6118 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6119 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6120 }
6121
6122 if (dut->ap_proxy_arp)
6123 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6124 else
6125 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6126 if (dut->ap_dgaf_disable)
6127 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6128 else
6129 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6130
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006131 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006132 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006133 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006134 run_system(dut, buf);
6135
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006136 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006137 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6138 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6139
6140 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6141 dut->ap2_radius_ipaddr);
6142 run_system(dut, buf);
6143
6144 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6145 dut->ap2_radius_port);
6146 run_system(dut, buf);
6147
6148 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6149 dut->ap2_radius_password);
6150 run_system(dut, buf);
6151 } else {
6152 run_system(dut, "cfg -a AP_SECMODE_2=None");
6153 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
6154 run_system(dut, "cfg -r AP_AUTH_PORT_2");
6155 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
6156 }
6157
6158 run_system(dut, "cfg -a AP_STARTMODE=multi");
6159 }
6160
6161 run_system(dut, "cfg -c");
6162
6163 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
6164 if (system("apup") != 0) {
6165 /* to be debugged why apup returns error
6166 send_resp(dut, conn, SIGMA_ERROR,
6167 "errorCode,apup failed");
6168 return 0;
6169 */
6170 }
6171 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
6172
6173 if (dut->ap_key_mgmt != AP_OPEN) {
6174 int res;
6175 /* allow some time for hostapd to start before returning
6176 * success */
6177 usleep(500000);
6178 if (run_hostapd_cli(dut, "ping") != 0) {
6179 send_resp(dut, conn, SIGMA_ERROR,
6180 "errorCode,Failed to talk to hostapd");
6181 return 0;
6182 }
6183
6184 if (dut->ap_hs2 && !dut->ap_anqpserver) {
6185 /* the cfg app doesn't like ";" in the variables */
6186 res = ath_ap_append_hostapd_conf(dut);
6187 if (res < 0)
6188 return res;
6189
6190 /* wait for hostapd to be ready */
6191 usleep(500000);
6192 if (run_hostapd_cli(dut, "ping") != 0) {
6193 send_resp(dut, conn, SIGMA_ERROR,
6194 "errorCode,Failed to talk to "
6195 "hostapd");
6196 return 0;
6197 }
6198 }
6199 }
6200
6201 ath_ap_set_params(dut);
6202
6203 if (dut->ap_anqpserver)
6204 return cmd_ath_ap_anqpserver_start(dut);
6205
6206 if (dut->ap2_proxy_arp)
6207 run_system(dut, "iwpriv ath1 proxy_arp 1");
6208
6209 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
6210 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
6211 if (system(buf) != 0) {
6212 sigma_dut_print(dut, DUT_MSG_ERROR,
6213 "iwpriv htweptkip failed");
6214 }
6215 }
6216
6217 return 1;
6218}
6219
6220
6221static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
6222 const char *ifname)
6223{
6224 char buf[200];
6225
6226 if (!chain || !ifname)
6227 return -2;
6228
6229 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6230 if (system(buf) != 0) {
6231 sigma_dut_print(dut, DUT_MSG_ERROR,
6232 "Failed to set ebtables rules, RULE-1, %s",
6233 chain);
6234 return -2;
6235 }
6236
6237 snprintf(buf, sizeof(buf),
6238 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6239 chain, ifname);
6240 if (system(buf) != 0) {
6241 sigma_dut_print(dut, DUT_MSG_ERROR,
6242 "Failed to set ebtables rules, RULE-2, %s",
6243 chain);
6244 return -2;
6245 }
6246
6247 snprintf(buf, sizeof(buf),
6248 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
6249 chain, ifname);
6250 if (system(buf) != 0) {
6251 sigma_dut_print(dut, DUT_MSG_ERROR,
6252 "Failed to set ebtables rules, RULE-3, %s",
6253 chain);
6254 return -2;
6255 }
6256
6257 snprintf(buf, sizeof(buf),
6258 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
6259 chain, ifname);
6260 if (system(buf) != 0) {
6261 sigma_dut_print(dut, DUT_MSG_ERROR,
6262 "Failed to set ebtables rules, RULE-4, %s",
6263 chain);
6264 return -2;
6265 }
6266
6267 return 0;
6268}
6269
6270
6271static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
6272 const char *chain,
6273 const char *ifname)
6274{
6275 char buf[200];
6276
6277 if (!chain || !ifname)
6278 return -2;
6279
6280 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6281 if (system(buf) != 0) {
6282 sigma_dut_print(dut, DUT_MSG_ERROR,
6283 "Failed to set ebtables rules, RULE-5, %s",
6284 chain);
6285 return -2;
6286 }
6287
6288 snprintf(buf, sizeof(buf),
6289 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6290 chain, ifname);
6291 if (system(buf) != 0) {
6292 sigma_dut_print(dut, DUT_MSG_ERROR,
6293 "Failed to set ebtables rules, RULE-6, %s",
6294 chain);
6295 return -2;
6296 }
6297
6298 snprintf(buf, sizeof(buf),
6299 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
6300 chain, ifname);
6301 if (system(buf) != 0) {
6302 sigma_dut_print(dut, DUT_MSG_ERROR,
6303 "Failed to set ebtables rules, RULE-7, %s",
6304 chain);
6305 return -2;
6306 }
6307
6308 snprintf(buf, sizeof(buf),
6309 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
6310 chain, ifname);
6311 if (system(buf) != 0) {
6312 sigma_dut_print(dut, DUT_MSG_ERROR,
6313 "Failed to set ebtables rules, RULE-8, %s",
6314 chain);
6315 return -2;
6316 }
6317
6318 return 0;
6319}
6320
6321
6322static int check_channel(int channel)
6323{
6324 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
6325 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
6326 161, 165 };
6327 int num_chan = sizeof(channel_list) / sizeof(int);
6328 int i;
6329
6330 for (i = 0; i < num_chan; i++) {
6331 if (channel == channel_list[i])
6332 return i;
6333 }
6334
6335 return -1;
6336}
6337
6338
6339static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
6340{
6341 int ch_base;
6342 int period;
6343
6344 if (check_channel(channel) < 0)
6345 return -1;
6346
6347 if (channel >= 36 && channel <= 64)
6348 ch_base = 36;
6349 else if (channel >= 100 && channel <= 144)
6350 ch_base = 100;
6351 else
6352 ch_base = 149;
6353
6354 period = channel % ch_base * 5 / chwidth;
6355 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
6356}
6357
6358
6359static int is_ht40plus_chan(int chan)
6360{
6361 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
6362 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
6363 chan == 132 || chan == 149 || chan == 157;
6364}
6365
6366
6367static int is_ht40minus_chan(int chan)
6368{
6369 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
6370 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
6371 chan == 136 || chan == 153 || chan == 161;
6372}
6373
6374
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05306375static int get_5g_channel_freq(int chan)
6376{
6377 return 5000 + chan * 5;
6378}
6379
6380
Jouni Malinen3d633da2017-09-14 22:19:21 +03006381static const char * hostapd_cipher_name(enum ap_cipher cipher)
6382{
6383 switch (cipher) {
6384 case AP_CCMP:
6385 return "CCMP";
6386 case AP_TKIP:
6387 return "TKIP";
6388 case AP_CCMP_TKIP:
6389 return "CCMP TKIP";
6390 case AP_GCMP_256:
6391 return "GCMP-256";
6392 case AP_GCMP_128:
6393 return "GCMP";
6394 case AP_CCMP_256:
6395 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02006396 case AP_CCMP_128_GCMP_256:
6397 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006398 default:
6399 return "UNKNOWN";
6400 }
6401}
6402
6403
6404static const char *
6405hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
6406{
6407 switch (cipher) {
6408 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03006409 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006410 case AP_BIP_CMAC_256:
6411 return "BIP-CMAC-256";
6412 case AP_BIP_GMAC_128:
6413 return "BIP-GMAC-128";
6414 case AP_BIP_CMAC_128:
6415 return "AES-128-CMAC";
6416 default:
6417 return "UNKNOWN";
6418 }
6419}
6420
6421
Jouni Malinena326d7b2017-09-04 13:46:02 +03006422int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
6423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006424{
6425 /* const char *name = get_param(cmd, "NAME"); */
6426 FILE *f;
6427 const char *ifname;
6428 char buf[500];
6429 char path[100];
6430 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03006431 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05306432#ifdef ANDROID
6433 struct group *gr;
6434#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006435
6436 drv = get_driver_type();
6437
6438 if (dut->mode == SIGMA_MODE_STATION) {
6439 stop_sta_mode(dut);
6440 sleep(1);
6441 }
6442
6443 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
6444 snprintf(buf, sizeof(buf), "ifconfig %s down",
6445 dut->sniffer_ifname);
6446 if (system(buf) != 0) {
6447 sigma_dut_print(dut, DUT_MSG_INFO,
6448 "Failed to run '%s'", buf);
6449 }
6450 snprintf(buf, sizeof(buf), "iw dev %s set type station",
6451 dut->sniffer_ifname);
6452 if (system(buf) != 0) {
6453 sigma_dut_print(dut, DUT_MSG_INFO,
6454 "Failed to run '%s'", buf);
6455 }
6456 }
6457
6458 dut->mode = SIGMA_MODE_AP;
6459
6460 if (drv == DRIVER_ATHEROS)
6461 return cmd_ath_ap_config_commit(dut, conn, cmd);
6462 if (drv == DRIVER_WCN)
6463 return cmd_wcn_ap_config_commit(dut, conn, cmd);
6464 if (drv == DRIVER_OPENWRT)
6465 return cmd_owrt_ap_config_commit(dut, conn, cmd);
6466
6467 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
6468 if (f == NULL) {
6469 sigma_dut_print(dut, DUT_MSG_ERROR,
6470 "%s: Failed to open sigma_dut-ap.conf",
6471 __func__);
6472 return -2;
6473 }
6474 switch (dut->ap_mode) {
6475 case AP_11g:
6476 case AP_11b:
6477 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306478 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
6479 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
6480 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006481 ifname = sigma_main_ifname;
6482 fprintf(f, "hw_mode=g\n");
6483 break;
6484 case AP_11a:
6485 case AP_11na:
6486 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306487 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006488 if (sigma_main_ifname)
6489 ifname = sigma_main_ifname;
6490 else
6491 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306492 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006493 if (if_nametoindex("wlan1") > 0)
6494 ifname = "wlan1";
6495 else
6496 ifname = "wlan0";
6497 } else {
6498 ifname = get_main_ifname();
6499 }
6500 fprintf(f, "hw_mode=a\n");
6501 break;
6502 default:
6503 fclose(f);
6504 return -1;
6505 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006506 if (dut->hostapd_ifname)
6507 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006508
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306509 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006510 fprintf(f, "driver=nl80211\n");
6511
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306512 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6513 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006514 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05306515 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
6516
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006517 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306518 if (dut->ap_mode == AP_11ng &&
6519 (dut->ap_chwidth == AP_40 ||
6520 (dut->ap_chwidth == AP_AUTO &&
6521 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006522 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306523 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006524 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306525 ht40minus = 1;
6526 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006527 }
6528
6529 /* configure ht_capab based on channel width */
6530 if (dut->ap_mode == AP_11na &&
6531 (dut->ap_chwidth == AP_40 ||
6532 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306533 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006534 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306535 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306537 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306539
6540 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306541 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306542
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306543 /* Overwrite the ht_capab with offset value if configured */
6544 if (dut->ap_chwidth == AP_40 &&
6545 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
6546 ht40plus = 1;
6547 ht40minus = 0;
6548 } else if (dut->ap_chwidth == AP_40 &&
6549 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
6550 ht40minus = 1;
6551 ht40plus = 0;
6552 }
6553
Tamizh chelvam431c6002017-03-07 17:07:16 +05306554 fprintf(f, "ht_capab=%s%s%s\n",
6555 ht40plus ? "[HT40+]" : "",
6556 ht40minus ? "[HT40-]" : "",
6557 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006558 }
6559
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306560 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6561 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006562 dut->ap_mode == AP_11ac) {
6563 fprintf(f, "ieee80211ac=1\n"
6564 "ieee80211n=1\n"
6565 "ht_capab=[HT40+]\n");
6566 }
6567
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306568 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6569 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006570 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
6571 if (dut->ap_countrycode[0]) {
6572 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
6573 fprintf(f, "ieee80211d=1\n");
6574 fprintf(f, "ieee80211h=1\n");
6575 }
6576 }
6577
6578 fprintf(f, "interface=%s\n", ifname);
6579 if (dut->bridge)
6580 fprintf(f, "bridge=%s\n", dut->bridge);
6581 fprintf(f, "channel=%d\n", dut->ap_channel);
6582
6583 if (sigma_hapd_ctrl)
6584 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
6585 else
6586 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
6587
6588 if (dut->ap_ssid[0])
6589 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6590 else
6591 fprintf(f, "ssid=QCA AP OOB\n");
6592 if (dut->ap_bcnint)
6593 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
6594
6595 switch (dut->ap_key_mgmt) {
6596 case AP_OPEN:
6597 if (dut->ap_cipher == AP_WEP)
6598 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
6599 break;
6600 case AP_WPA2_PSK:
6601 case AP_WPA2_PSK_MIXED:
6602 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006603 case AP_WPA2_SAE:
6604 case AP_WPA2_PSK_SAE:
6605 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6606 dut->ap_key_mgmt == AP_WPA2_SAE ||
6607 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608 fprintf(f, "wpa=2\n");
6609 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6610 fprintf(f, "wpa=3\n");
6611 else
6612 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03006613 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6614 key_mgmt = "SAE";
6615 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6616 key_mgmt = "WPA-PSK SAE";
6617 else
6618 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 switch (dut->ap_pmf) {
6620 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006621 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6623 break;
6624 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03006625 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6627 break;
6628 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006629 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6630 key_mgmt = "SAE";
6631 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6632 key_mgmt = "WPA-PSK-SHA256 SAE";
6633 else
6634 key_mgmt = "WPA-PSK-SHA256";
6635 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 break;
6637 }
Jouni Malinen2ba24492017-11-17 12:43:59 +02006638 fprintf(f, "wpa_pairwise=%s\n",
6639 hostapd_cipher_name(dut->ap_cipher));
6640 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6641 fprintf(f, "group_cipher=%s\n",
6642 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03006643 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6644 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02006645 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
6646 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03006647 else
6648 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006649 break;
6650 case AP_WPA2_EAP:
6651 case AP_WPA2_EAP_MIXED:
6652 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006653 case AP_WPA2_EAP_OSEN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006654 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006655 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
6656 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657 fprintf(f, "wpa=2\n");
6658 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6659 fprintf(f, "wpa=3\n");
6660 else
6661 fprintf(f, "wpa=1\n");
6662 switch (dut->ap_pmf) {
6663 case AP_PMF_DISABLED:
6664 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
6665 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
6666 break;
6667 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006668 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
6669 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
6670 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6671 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672 break;
6673 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006674 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
6675 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6676 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677 break;
6678 }
Jouni Malinen2ba24492017-11-17 12:43:59 +02006679 fprintf(f, "wpa_pairwise=%s\n",
6680 hostapd_cipher_name(dut->ap_cipher));
6681 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6682 fprintf(f, "group_cipher=%s\n",
6683 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006684 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6685 if (dut->ap_radius_port)
6686 fprintf(f, "auth_server_port=%d\n",
6687 dut->ap_radius_port);
6688 fprintf(f, "auth_server_shared_secret=%s\n",
6689 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03006690 if (dut->program == PROGRAM_HS2_R3) {
6691 fprintf(f, "radius_das_port=3799\n");
6692 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
6693 dut->ap_radius_password);
6694 fprintf(f, "radius_das_require_event_timestamp=1\n");
6695 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006696 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006697 case AP_SUITEB:
6698 fprintf(f, "ieee8021x=1\n");
6699 fprintf(f, "wpa=2\n");
6700 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03006701 fprintf(f, "wpa_pairwise=%s\n",
6702 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02006703 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6704 fprintf(f, "group_cipher=%s\n",
6705 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03006706 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
6707 fprintf(f, "group_mgmt_cipher=%s\n",
6708 hostapd_group_mgmt_cipher_name(
6709 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03006710 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6711 if (dut->ap_radius_port)
6712 fprintf(f, "auth_server_port=%d\n",
6713 dut->ap_radius_port);
6714 fprintf(f, "auth_server_shared_secret=%s\n",
6715 dut->ap_radius_password);
6716 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006717 case AP_WPA2_OWE:
6718 fprintf(f, "wpa=2\n");
6719 fprintf(f, "wpa_key_mgmt=OWE\n");
6720 fprintf(f, "rsn_pairwise=%s\n",
6721 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03006722 if (dut->ap_sae_groups)
6723 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03006724 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006725 }
6726
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05306727 if (dut->ap_rsn_preauth)
6728 fprintf(f, "rsn_preauth=1\n");
6729
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006730 switch (dut->ap_pmf) {
6731 case AP_PMF_DISABLED:
6732 break;
6733 case AP_PMF_OPTIONAL:
6734 fprintf(f, "ieee80211w=1\n");
Jouni Malinen1287cd72018-01-04 17:08:01 +02006735 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6736 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006737 break;
6738 case AP_PMF_REQUIRED:
6739 fprintf(f, "ieee80211w=2\n");
6740 break;
6741 }
6742
Jouni Malinen3c367e82017-06-23 17:01:47 +03006743 if (dut->rsne_override)
6744 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
6745
Jouni Malinen68143132017-09-02 02:34:08 +03006746 if (dut->sae_commit_override)
6747 fprintf(f, "sae_commit_override=%s\n",
6748 dut->sae_commit_override);
6749
Jouni Malinened670f42017-08-31 01:39:28 +03006750 if (dut->ap_sae_groups)
6751 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03006752
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006753 if (dut->sae_anti_clogging_threshold >= 0)
6754 fprintf(f, "sae_anti_clogging_threshold=%d\n",
6755 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03006756 if (dut->sae_reflection)
6757 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006758
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006759 if (dut->ap_p2p_mgmt)
6760 fprintf(f, "manage_p2p=1\n");
6761
6762 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
6763 fprintf(f, "tdls_prohibit=1\n");
6764 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
6765 fprintf(f, "tdls_prohibit_chan_switch=1\n");
6766 if (dut->ap_p2p_cross_connect >= 0) {
6767 fprintf(f, "manage_p2p=1\n"
6768 "allow_cross_connection=%d\n",
6769 dut->ap_p2p_cross_connect);
6770 }
6771
6772 if (dut->ap_l2tif || dut->ap_proxy_arp) {
6773 if (!dut->bridge) {
6774 sigma_dut_print(dut, DUT_MSG_ERROR,
6775 "Bridge must be configured. Run with -b <brname>.");
6776 fclose(f);
6777 return -2;
6778 }
6779 fprintf(f, "ap_isolate=1\n");
6780 }
6781
6782 if (dut->ap_proxy_arp)
6783 fprintf(f, "proxy_arp=1\n");
6784
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306785 if (dut->ap_wme)
6786 fprintf(f, "wmm_enabled=1\n");
6787
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306788 if (dut->ap_wmmps == AP_WMMPS_ON)
6789 fprintf(f, "uapsd_advertisement_enabled=1\n");
6790
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006791 if (dut->ap_hs2) {
6792 if (dut->ap_bss_load) {
6793 char *bss_load;
6794
6795 switch (dut->ap_bss_load) {
6796 case -1:
6797 bss_load = "bss_load_update_period=10";
6798 break;
6799 case 1:
6800 /* STA count: 1, CU: 50, AAC: 65535 */
6801 bss_load = "bss_load_test=1:50:65535";
6802 break;
6803 case 2:
6804 /* STA count: 1, CU: 200, AAC: 65535 */
6805 bss_load = "bss_load_test=1:200:65535";
6806 break;
6807 case 3:
6808 /* STA count: 1, CU: 75, AAC: 65535 */
6809 bss_load = "bss_load_test=1:75:65535";
6810 break;
6811 default:
6812 bss_load = NULL;
6813 break;
6814 }
6815
6816 if (!bss_load) {
6817 fclose(f);
6818 return -2;
6819 }
6820 fprintf(f, "%s\n", bss_load);
6821 }
6822
6823 if (append_hostapd_conf_hs2(dut, f)) {
6824 fclose(f);
6825 return -2;
6826 }
6827 }
6828
6829 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
6830 fclose(f);
6831 return -2;
6832 }
6833
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006834 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006835 unsigned char bssid[6];
6836 char ifname2[50];
6837
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306838 if (get_hwaddr(ifname, bssid)) {
6839 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006840 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306841 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03006842 if (bssid[0] & 0x02)
6843 bssid[5] ^= 0x01;
6844 else
6845 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006846
6847 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03006848 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006849 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006850 if (dut->bridge)
6851 fprintf(f, "bridge=%s\n", dut->bridge);
6852 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
6853 bssid[0], bssid[1], bssid[2], bssid[3],
6854 bssid[4], bssid[5]);
6855
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006856 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05306858 /* Disable DGAF for OSEN BSS */
6859 fprintf(f, "disable_dgaf=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006860 if (strlen(dut->ap2_radius_ipaddr))
6861 fprintf(f, "auth_server_addr=%s\n",
6862 dut->ap2_radius_ipaddr);
6863 if (dut->ap2_radius_port)
6864 fprintf(f, "auth_server_port=%d\n",
6865 dut->ap2_radius_port);
6866 if (strlen(dut->ap2_radius_password))
6867 fprintf(f, "auth_server_shared_secret=%s\n",
6868 dut->ap2_radius_password);
6869 }
6870
6871 if (dut->ap2_proxy_arp) {
6872 if (!dut->bridge) {
6873 sigma_dut_print(dut, DUT_MSG_ERROR,
6874 "Bridge must be configured. Run with -b <brname>.");
6875 fclose(f);
6876 return -2;
6877 }
6878 fprintf(f, "ap_isolate=1\n");
6879 fprintf(f, "proxy_arp=1\n");
6880
6881 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
6882 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
6883 fclose(f);
6884 return -2;
6885 }
6886
6887 }
6888 }
6889
6890 if (dut->program == PROGRAM_WPS) {
6891 fprintf(f, "eap_server=1\n"
6892 "wps_state=1\n"
6893 "device_name=QCA AP\n"
6894 "manufacturer=QCA\n"
6895 "device_type=6-0050F204-1\n"
6896 "config_methods=label virtual_display "
6897 "virtual_push_button keypad%s\n"
6898 "ap_pin=12345670\n"
6899 "friendly_name=QCA Access Point\n"
6900 "upnp_iface=%s\n",
6901 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
6902 dut->bridge ? dut->bridge : ifname);
6903 }
6904
6905 if (dut->program == PROGRAM_VHT) {
6906 int vht_oper_centr_freq_idx;
6907
6908 if (check_channel(dut->ap_channel) < 0) {
6909 send_resp(dut, conn, SIGMA_INVALID,
6910 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306911 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006912 return 0;
6913 }
6914
6915 switch (dut->ap_chwidth) {
6916 case AP_20:
6917 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
6918 vht_oper_centr_freq_idx =
6919 get_oper_centr_freq_seq_idx(20,
6920 dut->ap_channel);
6921 break;
6922 case AP_40:
6923 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
6924 vht_oper_centr_freq_idx =
6925 get_oper_centr_freq_seq_idx(40,
6926 dut->ap_channel);
6927 break;
6928 case AP_80:
6929 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
6930 vht_oper_centr_freq_idx =
6931 get_oper_centr_freq_seq_idx(80,
6932 dut->ap_channel);
6933 break;
6934 case AP_160:
6935 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
6936 vht_oper_centr_freq_idx =
6937 get_oper_centr_freq_seq_idx(160,
6938 dut->ap_channel);
6939 break;
6940 default:
6941 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
6942 vht_oper_centr_freq_idx =
6943 get_oper_centr_freq_seq_idx(80,
6944 dut->ap_channel);
6945 break;
6946 }
6947 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
6948 vht_oper_centr_freq_idx);
6949 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
6950
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006951 if (dut->ap_sgi80 || dut->ap_txBF ||
6952 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05306953 dut->ap_tx_stbc || dut->ap_mu_txBF) {
6954 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006955 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05306956 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05306957 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006958 (dut->ap_ldpc == VALUE_ENABLED) ?
6959 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05306960 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
6961 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006962 }
6963 }
6964
Jouni Malinen6d1d7392017-10-10 20:35:29 +03006965 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
6966 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
6967 /* OWE transition mode */
6968 unsigned char bssid[6];
6969 char ifname2[50];
6970 unsigned long val;
6971 FILE *f2;
6972
6973 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
6974
6975 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
6976 val = 0x12345678; /* default to something */
6977 f2 = fopen("/dev/urandom", "r");
6978 if (f2) {
6979 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
6980 sigma_dut_print(dut, DUT_MSG_ERROR,
6981 "Could not read /dev/urandom");
6982 }
6983 fclose(f2);
6984 }
6985 fprintf(f, "ssid=owe-%lx\n", val);
6986
6987 if (get_hwaddr(ifname, bssid)) {
6988 fclose(f);
6989 return -2;
6990 }
6991 if (bssid[0] & 0x02)
6992 bssid[5] ^= 0x01;
6993 else
6994 bssid[0] |= 0x02;
6995
6996 fprintf(f, "bss=%s\n", ifname2);
6997 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6998 if (dut->bridge)
6999 fprintf(f, "bridge=%s\n", dut->bridge);
7000 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7001 bssid[0], bssid[1], bssid[2], bssid[3],
7002 bssid[4], bssid[5]);
7003 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7004 }
7005
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007006 if (dut->ap_key_mgmt == AP_OPEN &&
7007 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
7008 /* OWE transition mode */
7009 unsigned char bssid[6];
7010 char ifname2[50];
7011 unsigned long val;
7012 FILE *f2;
7013
7014 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7015
7016 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7017 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7018
7019 if (get_hwaddr(ifname, bssid)) {
7020 fclose(f);
7021 return -2;
7022 }
7023 if (bssid[0] & 0x02)
7024 bssid[5] ^= 0x01;
7025 else
7026 bssid[0] |= 0x02;
7027
7028 fprintf(f, "bss=%s\n", ifname2);
7029 val = 0x12345678; /* default to something */
7030 f2 = fopen("/dev/urandom", "r");
7031 if (f2) {
7032 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7033 sigma_dut_print(dut, DUT_MSG_ERROR,
7034 "Could not read /dev/urandom");
7035 }
7036 fclose(f2);
7037 }
7038 fprintf(f, "ssid=owe-%lx\n", val);
7039 if (dut->bridge)
7040 fprintf(f, "bridge=%s\n", dut->bridge);
7041 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7042 bssid[0], bssid[1], bssid[2], bssid[3],
7043 bssid[4], bssid[5]);
7044 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7045 fprintf(f, "wpa=2\n");
7046 fprintf(f, "wpa_key_mgmt=OWE\n");
7047 fprintf(f, "rsn_pairwise=CCMP\n");
7048 fprintf(f, "ieee80211w=2\n");
7049 if (dut->ap_sae_groups)
7050 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
7051 }
7052
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307053 if (dut->program == PROGRAM_OCE) {
7054 fprintf(f, "oce=%d\n",
7055 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
7056 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007057 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007058 if (dut->use_hostapd_pid_file)
7059 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007060#ifdef __QNXNTO__
7061 if (system("slay hostapd") == 0)
7062#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007063 if (!dut->use_hostapd_pid_file &&
7064 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7065 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007066#endif /* __QNXNTO__ */
7067 {
7068 int i;
7069 /* Wait some time to allow hostapd to complete cleanup before
7070 * starting a new process */
7071 for (i = 0; i < 10; i++) {
7072 usleep(500000);
7073#ifdef __QNXNTO__
7074 if (system("pidin | grep hostapd") != 0)
7075 break;
7076#else /* __QNXNTO__ */
7077 if (system("pidof hostapd") != 0)
7078 break;
7079#endif /* __QNXNTO__ */
7080 }
7081 }
Jouni Malinend86e5822017-08-29 03:55:32 +03007082 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007083
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307084#ifdef ANDROID
7085 /* Set proper conf file permissions so that hostapd process
7086 * can access it.
7087 */
7088 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
7089 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
7090 sigma_dut_print(dut, DUT_MSG_ERROR,
7091 "Error changing permissions");
7092
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307093 gr = getgrnam("wifi");
7094 if (!gr ||
7095 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307096 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
7097#endif /* ANDROID */
7098
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 if (drv == DRIVER_QNXNTO) {
7100 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05307101 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007102 "/sigma_dut-ap.conf",
7103 dut->hostapd_debug_log ? "-ddKt -f " : "",
7104 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007105 dut->hostapd_entropy_log ? " -e" : "",
7106 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
7107 "");
7108 } else {
7109 /*
7110 * It looks like a monitor interface can cause some issues for
7111 * beaconing, so remove it (if injection was used) before
7112 * starting hostapd.
7113 */
7114 if (if_nametoindex("sigmadut") > 0 &&
7115 system("iw dev sigmadut del") != 0)
7116 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7117 "monitor interface");
7118
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007119 snprintf(path, sizeof(path), "%shostapd",
7120 file_exists("hostapd") ? "./" : "");
7121 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007122 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007123 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007124 dut->hostapd_debug_log ? " -ddKt -f" : "",
7125 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
7126 dut->hostapd_entropy_log ? " -e" : "",
7127 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007128 "",
7129 dut->use_hostapd_pid_file ?
7130 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007131 }
7132
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007133 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007134 if (system(buf) != 0) {
7135 send_resp(dut, conn, SIGMA_ERROR,
7136 "errorCode,Failed to start hostapd");
7137 return 0;
7138 }
7139
7140 /* allow some time for hostapd to start before returning success */
7141 usleep(500000);
7142 if (run_hostapd_cli(dut, "ping") != 0) {
7143 send_resp(dut, conn, SIGMA_ERROR,
7144 "errorCode,Failed to talk to hostapd");
7145 return 0;
7146 }
7147
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05307148 if (drv == DRIVER_LINUX_WCN) {
7149 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
7150 ap_inet_addr, ap_inet_mask);
7151 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
7152 ifname, ap_inet_addr, ap_inet_mask);
7153 if (system(buf) != 0) {
7154 sigma_dut_print(dut, DUT_MSG_ERROR,
7155 "Failed to initialize the interface");
7156 return -1;
7157 }
7158 }
7159
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007160 if (dut->ap_l2tif) {
7161 snprintf(path, sizeof(path),
7162 "/sys/class/net/%s/brport/hairpin_mode",
7163 ifname);
7164 if (!file_exists(path)) {
7165 sigma_dut_print(dut, DUT_MSG_ERROR,
7166 "%s must be binded to the bridge for L2TIF",
7167 ifname);
7168 return -2;
7169 }
7170
7171 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
7172 if (system(buf) != 0) {
7173 sigma_dut_print(dut, DUT_MSG_ERROR,
7174 "Failed to enable hairpin_mode for L2TIF");
7175 return -2;
7176 }
7177
7178 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
7179 if (system(buf) != 0) {
7180 sigma_dut_print(dut, DUT_MSG_ERROR,
7181 "Failed to set ebtables rules, RULE-9");
7182 return -2;
7183 }
7184
7185 snprintf(buf, sizeof(buf),
7186 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
7187 ifname);
7188 if (system(buf) != 0) {
7189 sigma_dut_print(dut, DUT_MSG_ERROR,
7190 "Failed to set ebtables rules, RULE-11");
7191 return -2;
7192 }
7193 }
7194
7195 if (dut->ap_proxy_arp) {
7196 if (dut->ap_dgaf_disable) {
7197 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
7198 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
7199 return -2;
7200 } else {
7201 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
7202 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
7203 return -2;
7204 }
7205
7206 /* For 4.5-(c) */
7207 snprintf(buf, sizeof(buf),
7208 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
7209 ifname);
7210 if (system(buf) != 0) {
7211 sigma_dut_print(dut, DUT_MSG_ERROR,
7212 "Failed to set ebtables rules, RULE-10");
7213 return -2;
7214 }
7215 }
7216
7217 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
7218 /* Drop TDLS frames */
7219 snprintf(buf, sizeof(buf),
7220 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
7221 if (system(buf) != 0) {
7222 sigma_dut_print(dut, DUT_MSG_ERROR,
7223 "Failed to set ebtables rules, RULE-13");
7224 return -2;
7225 }
7226 }
7227
7228 if (dut->ap_fake_pkhash &&
7229 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
7230 send_resp(dut, conn, SIGMA_ERROR,
7231 "errorCode,Could not enable FakePubKey");
7232 return 0;
7233 }
7234
Jouni Malinend86e5822017-08-29 03:55:32 +03007235 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007236 return 1;
7237}
7238
7239
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307240static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
7241 struct qos_params *qos, const char *cwmin,
7242 const char *cwmax, const char *aifs,
7243 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007244{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307245 int val;
7246
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007247 if (cwmin) {
7248 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307249 val = atoi(cwmin);
7250 if (val < 0 || val > 15) {
7251 send_resp(dut, conn, SIGMA_INVALID,
7252 "errorCode,Invalid cwMin");
7253 return 0;
7254 }
7255 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007256 }
7257
7258 if (cwmax) {
7259 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307260 val = atoi(cwmax);
7261 if (val < 0 || val > 15) {
7262 send_resp(dut, conn, SIGMA_INVALID,
7263 "errorCode,Invalid cwMax");
7264 return 0;
7265 }
7266 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007267 }
7268
7269 if (aifs) {
7270 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307271 val = atoi(aifs);
7272 if (val < 1 || val > 255) {
7273 send_resp(dut, conn, SIGMA_INVALID,
7274 "errorCode,Invalid AIFS");
7275 return 0;
7276 }
7277 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007278 }
7279
7280 if (txop) {
7281 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307282 val = atoi(txop);
7283 if (val < 0 || val > 0xffff) {
7284 send_resp(dut, conn, SIGMA_INVALID,
7285 "errorCode,Invalid txop");
7286 return 0;
7287 }
7288 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007289 }
7290
7291 if (acm) {
7292 qos->ac = 1;
7293 qos->acm = strcasecmp(acm, "on") == 0;
7294 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307295
7296 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007297}
7298
7299
7300static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
7301 struct sigma_cmd *cmd)
7302{
7303 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307304 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
7305 get_param(cmd, "cwmin_VO"),
7306 get_param(cmd, "cwmax_VO"),
7307 get_param(cmd, "AIFS_VO"),
7308 get_param(cmd, "TXOP_VO"),
7309 get_param(cmd, "ACM_VO")) ||
7310 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
7311 get_param(cmd, "cwmin_VI"),
7312 get_param(cmd, "cwmax_VI"),
7313 get_param(cmd, "AIFS_VI"),
7314 get_param(cmd, "TXOP_VI"),
7315 get_param(cmd, "ACM_VI")) ||
7316 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
7317 get_param(cmd, "cwmin_BE"),
7318 get_param(cmd, "cwmax_BE"),
7319 get_param(cmd, "AIFS_BE"),
7320 get_param(cmd, "TXOP_BE"),
7321 get_param(cmd, "ACM_BE")) ||
7322 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
7323 get_param(cmd, "cwmin_BK"),
7324 get_param(cmd, "cwmax_BK"),
7325 get_param(cmd, "AIFS_BK"),
7326 get_param(cmd, "TXOP_BK"),
7327 get_param(cmd, "ACM_BK")))
7328 return 0;
7329
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007330 return 1;
7331}
7332
7333
7334static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
7335 struct sigma_cmd *cmd)
7336{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307337 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
7338 get_param(cmd, "cwmin_VO"),
7339 get_param(cmd, "cwmax_VO"),
7340 get_param(cmd, "AIFS_VO"),
7341 get_param(cmd, "TXOP_VO"),
7342 get_param(cmd, "ACM_VO")) ||
7343 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
7344 get_param(cmd, "cwmin_VI"),
7345 get_param(cmd, "cwmax_VI"),
7346 get_param(cmd, "AIFS_VI"),
7347 get_param(cmd, "TXOP_VI"),
7348 get_param(cmd, "ACM_VI")) ||
7349 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
7350 get_param(cmd, "cwmin_BE"),
7351 get_param(cmd, "cwmax_BE"),
7352 get_param(cmd, "AIFS_BE"),
7353 get_param(cmd, "TXOP_BE"),
7354 get_param(cmd, "ACM_BE")) ||
7355 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
7356 get_param(cmd, "cwmin_BK"),
7357 get_param(cmd, "cwmax_BK"),
7358 get_param(cmd, "AIFS_BK"),
7359 get_param(cmd, "TXOP_BK"),
7360 get_param(cmd, "ACM_BK")))
7361 return 0;
7362
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007363 return 1;
7364}
7365
7366
7367static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
7368{
7369 unsigned char bssid[6];
7370 char buf[100];
7371 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
7372 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
7373 run_system(dut, "cfg -a AP_SECMODE=WPA");
7374 run_system(dut, "cfg -a AP_SECFILE=EAP");
7375 run_system(dut, "cfg -a AP_WPA=2");
7376 run_system(dut, "cfg -a AP_CYPHER=CCMP");
7377 run_system(dut, "cfg -a AP_HOTSPOT=1");
7378 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
7379 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
7380 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
7381 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
7382 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
7383 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
7384 if (!get_hwaddr("ath0", bssid)) {
7385 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7386 "%02x:%02x:%02x:%02x:%02x:%02x",
7387 bssid[0], bssid[1], bssid[2], bssid[3],
7388 bssid[4], bssid[5]);
7389 run_system(dut, buf);
7390 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7391 "%02x:%02x:%02x:%02x:%02x:%02x",
7392 bssid[0], bssid[1], bssid[2], bssid[3],
7393 bssid[4], bssid[5]);
7394 } else {
7395 if (!get_hwaddr("wifi0", bssid)) {
7396 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7397 "%02x:%02x:%02x:%02x:%02x:%02x",
7398 bssid[0], bssid[1], bssid[2], bssid[3],
7399 bssid[4], bssid[5]);
7400 run_system(dut, buf);
7401 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7402 "%02x:%02x:%02x:%02x:%02x:%02x",
7403 bssid[0], bssid[1], bssid[2], bssid[3],
7404 bssid[4], bssid[5]);
7405 } else {
7406 /* load the driver and try again */
7407 run_system(dut, "/etc/rc.d/rc.wlan up");
7408
7409 if (!get_hwaddr("wifi0", bssid)) {
7410 snprintf(buf, sizeof(buf),
7411 "cfg -a AP_HOTSPOT_HESSID="
7412 "%02x:%02x:%02x:%02x:%02x:%02x",
7413 bssid[0], bssid[1], bssid[2],
7414 bssid[3], bssid[4], bssid[5]);
7415 run_system(dut, buf);
7416 snprintf(dut->ap_hessid,
7417 sizeof(dut->ap_hessid),
7418 "%02x:%02x:%02x:%02x:%02x:%02x",
7419 bssid[0], bssid[1], bssid[2],
7420 bssid[3], bssid[4], bssid[5]);
7421 }
7422 }
7423 }
7424
7425 run_system(dut, "cfg -r AP_SSID_2");
7426 run_system(dut, "cfg -c");
7427 /* run_system(dut, "cfg -s"); */
7428}
7429
7430
7431static void ath_reset_vht_defaults(struct sigma_dut *dut)
7432{
7433 run_system(dut, "cfg -x");
7434 run_system(dut, "cfg -a AP_RADIO_ID=1");
7435 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
7436 run_system(dut, "cfg -a AP_STARTMODE=standard");
7437 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
7438 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
7439 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
7440 run_system(dut, "cfg -a ATH_countrycode=0x348");
7441 /* NOTE: For Beeliner we have to turn off MU-MIMO */
7442 if (system("rm /tmp/secath*") != 0) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "Failed to remove secath file");
7445 }
7446}
7447
7448
7449static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
7450 struct sigma_cmd *cmd)
7451{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307452 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307453 enum driver_type drv;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007454 int i;
7455
7456 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
7457 /*
7458 * Reset all tagged SSIDs to NULL-string and all key management
7459 * to open.
7460 */
7461 dut->ap_tag_ssid[i][0] = '\0';
7462 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
7463 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007464
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307465 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307466
7467 program = get_param(cmd, "program");
7468 if (!program)
7469 program = get_param(cmd, "prog");
7470 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007471 dut->device_type = AP_unknown;
7472 type = get_param(cmd, "type");
7473 if (type && strcasecmp(type, "Testbed") == 0)
7474 dut->device_type = AP_testbed;
7475 if (type && strcasecmp(type, "DUT") == 0)
7476 dut->device_type = AP_dut;
7477
7478 dut->ap_rts = 0;
7479 dut->ap_frgmnt = 0;
7480 dut->ap_bcnint = 0;
7481 dut->ap_key_mgmt = AP_OPEN;
7482 dut->ap_ssid[0] = '\0';
7483 dut->ap_fake_pkhash = 0;
7484 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
7485 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007486 dut->ap_addba_reject = VALUE_NOT_SET;
7487 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007488 dut->ap_is_dual = 0;
7489 dut->ap_mode = AP_inval;
7490 dut->ap_mode_1 = AP_inval;
7491
7492 dut->ap_allow_vht_wep = 0;
7493 dut->ap_allow_vht_tkip = 0;
7494 dut->ap_disable_protection = 0;
7495 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007496 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
7497 dut->ap_ldpc = VALUE_NOT_SET;
7498 dut->ap_sig_rts = VALUE_NOT_SET;
7499 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007500 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05307501 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007502 dut->ap_chwidth = AP_AUTO;
7503
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05307504 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007505 dut->ap_wpsnfc = 0;
7506 dut->ap_bss_load = -1;
7507 dut->ap_p2p_cross_connect = -1;
7508
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307509 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
7510 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307511 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307512
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007513 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007514 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08007515 dut->ap_interface_5g = 0;
7516 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08007517 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007518
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307519 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307520 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307521 dut->ap_wmmps = AP_WMMPS_ON;
7522 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307523 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307524 dut->ap_wmmps = AP_WMMPS_OFF;
7525 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307526
Jouni Malinen54a89b02018-05-01 00:16:26 +03007527 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03007528 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03007529 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03007530 dut->ap_tnc_file_name = 0;
7531 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03007532
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007533 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007534 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007535 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007536 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007537
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007538 if (drv == DRIVER_ATHEROS)
7539 cmd_ath_ap_hs2_reset(dut);
7540 else if (drv == DRIVER_OPENWRT)
7541 cmd_owrt_ap_hs2_reset(dut);
7542
7543 dut->ap_interworking = 1;
7544 dut->ap_access_net_type = 2;
7545 dut->ap_internet = 0;
7546 dut->ap_venue_group = 2;
7547 dut->ap_venue_type = 8;
7548 dut->ap_domain_name_list[0] = '\0';
7549 dut->ap_hs2 = 1;
7550 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
7551 "506f9a;001bc504bd");
7552 dut->ap_l2tif = 0;
7553 dut->ap_proxy_arp = 0;
7554 if (dut->bridge) {
7555 char buf[50];
7556
7557 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
7558 dut->bridge);
7559 if (system(buf) != 0) {
7560 sigma_dut_print(dut, DUT_MSG_DEBUG,
7561 "%s ip neigh table flushing failed",
7562 dut->bridge);
7563 }
7564
7565 snprintf(buf, sizeof(buf), "ebtables -F");
7566 if (system(buf) != 0) {
7567 sigma_dut_print(dut, DUT_MSG_DEBUG,
7568 "%s ebtables flushing failed",
7569 dut->bridge);
7570 }
7571 }
7572 dut->ap_dgaf_disable = 0;
7573 dut->ap_p2p_cross_connect = 0;
7574 dut->ap_gas_cb_delay = 0;
7575 dut->ap_nai_realm_list = 0;
7576 dut->ap_oper_name = 0;
7577 dut->ap_venue_name = 0;
7578 for (i = 0; i < 10; i++) {
7579 dut->ap_plmn_mcc[i][0] = '\0';
7580 dut->ap_plmn_mnc[i][0] = '\0';
7581 }
7582 dut->ap_wan_metrics = 0;
7583 dut->ap_conn_capab = 0;
7584 dut->ap_ip_addr_type_avail = 0;
7585 dut->ap_net_auth_type = 0;
7586 dut->ap_oper_class = 0;
7587 dut->ap_pmf = 0;
7588 dut->ap_add_sha256 = 0;
7589 }
7590
Jouni Malinenba630452018-06-22 11:49:59 +03007591 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
7592 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007593 int i;
7594 const char hessid[] = "50:6f:9a:00:11:22";
7595
7596 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
7597 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007598 dut->ap_pmf = 1;
7599 dut->ap_osu_provider_list = 0;
7600 for (i = 0; i < 10; i++) {
7601 dut->ap_osu_server_uri[i][0] = '\0';
7602 dut->ap_osu_method[i] = 0xFF;
7603 }
7604 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007605 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007606 dut->ap2_proxy_arp = 0;
7607 dut->ap_osu_icon_tag = 0;
7608 }
7609
7610 if (dut->program == PROGRAM_VHT) {
7611 /* Set up the defaults */
7612 dut->ap_mode = AP_11ac;
7613 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007614 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08007615 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007616 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007617 dut->ap_amsdu = VALUE_DISABLED;
7618 dut->ap_ldpc = VALUE_DISABLED;
7619 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007620 dut->ap_sgi80 = 0;
7621 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007622 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307623 /*
7624 * As LDPC is optional, don't enable this by default
7625 * for LINUX-WCN driver. The ap_set_wireless command
7626 * can be used to enable LDPC, when needed.
7627 */
7628 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007629 dut->ap_ldpc = VALUE_ENABLED;
7630 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007631 dut->ap_sgi80 = 1;
7632 }
7633 dut->ap_fixed_rate = 0;
7634 dut->ap_rx_streams = 3;
7635 dut->ap_tx_streams = 3;
7636 dut->ap_vhtmcs_map = 0;
7637 dut->ap_chwidth = AP_80;
7638 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007639 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05307640 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
7641 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007642 if (get_driver_type() == DRIVER_ATHEROS)
7643 ath_reset_vht_defaults(dut);
7644 }
7645
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007646 if (dut->program == PROGRAM_IOTLP) {
7647 dut->wnm_bss_max_feature = VALUE_DISABLED;
7648 dut->wnm_bss_max_idle_time = 0;
7649 dut->wnm_bss_max_protection = VALUE_NOT_SET;
7650 dut->ap_proxy_arp = 1;
7651 } else {
7652 /*
7653 * Do not touch the BSS-MAX Idle time feature
7654 * if the program is not IOTLP.
7655 */
7656 dut->wnm_bss_max_feature = VALUE_NOT_SET;
7657 dut->wnm_bss_max_idle_time = 0;
7658 dut->wnm_bss_max_protection = VALUE_NOT_SET;
7659 }
7660
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007661 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07007662 dut->ap_rrm = 1;
7663 dut->ap_rtt = 1;
7664 dut->ap_lci = 0;
7665 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07007666 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07007667 dut->ap_lcr = 0;
7668 dut->ap_val_lcr[0] = '\0';
7669 dut->ap_neighap = 0;
7670 dut->ap_opchannel = 0;
7671 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07007672 dut->ap_fqdn_held = 0;
7673 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07007674 dut->ap_interworking = 0;
7675 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007676 dut->ap_msnt_type = 0;
7677 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007678 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07007679 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07007680 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007681
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007682 if (dut->program == PROGRAM_MBO) {
7683 dut->ap_mbo = 1;
7684 dut->ap_interworking = 1;
7685 dut->ap_ne_class = 0;
7686 dut->ap_ne_op_ch = 0;
7687 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007688 dut->ap_btmreq_disassoc_imnt = 0;
7689 dut->ap_btmreq_term_bit = 0;
7690 dut->ap_disassoc_timer = 0;
7691 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07007692 dut->ap_channel = 36;
7693 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07007694 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07007695 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007696 dut->mbo_self_ap_tuple.ap_ne_class = -1;
7697 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
7698 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08007699 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08007700 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007701 }
7702
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08007703 if (dut->program == PROGRAM_OCE) {
7704 if (dut->ap_dhcp_stop)
7705 run_system(dut, "/etc/init.d/dnsmasq start");
7706
7707 dut->ap_dhcp_stop = 0;
7708 dut->ap_oce = VALUE_ENABLED;
7709 dut->ap_broadcast_ssid = VALUE_ENABLED;
7710 dut->ap_fils_dscv_int = 20;
7711 dut->ap_filsdscv = VALUE_ENABLED;
7712 dut->ap_filshlp = VALUE_DISABLED;
7713 dut->ap_rnr = VALUE_DISABLED;
7714 dut->ap_nairealm[0] = '\0';
7715 dut->ap_nairealm_int = 0;
7716 dut->ap_blechanutil = 0;
7717 dut->ap_ble_admit_cap = 0;
7718 dut->ap_esp = VALUE_ENABLED;
7719 dut->ap_datappdudura = 0;
7720 dut->ap_airtimefract = 0;
7721 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08007722 dut->ap_ul_availcap = 0;
7723 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08007724 dut->ap_akm = 0;
7725 dut->ap_add_sha256 = 0;
7726 dut->ap_add_sha384 = 0;
7727 dut->ap_pmksa = 0;
7728 dut->ap_pmksa_caching = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08007729 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08007730 }
7731
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07007732 dut->ap_he_ppdu = PPDU_NOT_SET;
7733
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08007734 dut->ap_oper_chn = 0;
7735
Jouni Malinen3c367e82017-06-23 17:01:47 +03007736 free(dut->rsne_override);
7737 dut->rsne_override = NULL;
7738
Jouni Malinen68143132017-09-02 02:34:08 +03007739 free(dut->sae_commit_override);
7740 dut->sae_commit_override = NULL;
7741
Jouni Malinened670f42017-08-31 01:39:28 +03007742 free(dut->ap_sae_groups);
7743 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03007744
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007745 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03007746 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007747
Jouni Malinen3d633da2017-09-14 22:19:21 +03007748 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02007749 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03007750 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02007751 dut->ap_passphrase[0] = '\0';
7752 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03007753
Jouni Malinend86e5822017-08-29 03:55:32 +03007754 dut->dpp_conf_id = -1;
7755
7756 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08007757
7758 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
7759 return 1;
7760
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007761 if (dut->use_hostapd_pid_file) {
7762 kill_hostapd_process_pid(dut);
7763 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7764 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007765 int i;
7766 /* Wait some time to allow hostapd to complete cleanup before
7767 * starting a new process */
7768 for (i = 0; i < 10; i++) {
7769 usleep(500000);
7770 if (system("pidof hostapd") != 0)
7771 break;
7772 }
7773 }
7774
7775 if (if_nametoindex("sigmadut") > 0 &&
7776 system("iw dev sigmadut del") != 0)
7777 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7778 "monitor interface");
7779
7780 return 1;
7781}
7782
7783
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307784int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
7785 struct sigma_cmd *cmd)
7786{
7787 return cmd_ap_reset_default(dut, conn, cmd);
7788}
7789
7790
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007791static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
7792 struct sigma_cmd *cmd)
7793{
7794 /* const char *name = get_param(cmd, "NAME"); */
7795 struct stat s;
7796 char resp[200];
7797 FILE *f;
7798 enum driver_type drv = get_driver_type();
7799
7800 switch (drv) {
7801 case DRIVER_ATHEROS: {
7802 /* Atheros AP */
7803 struct utsname uts;
7804 char *version, athver[100];
7805
7806 if (stat("/proc/athversion", &s) != 0) {
7807 if (system("/etc/rc.d/rc.wlan up") != 0) {
7808 }
7809 }
7810
7811 athver[0] = '\0';
7812 f = fopen("/proc/athversion", "r");
7813 if (f) {
7814 if (fgets(athver, sizeof(athver), f)) {
7815 char *pos = strchr(athver, '\n');
7816 if (pos)
7817 *pos = '\0';
7818 }
7819 fclose(f);
7820 }
7821
7822 if (uname(&uts) == 0)
7823 version = uts.release;
7824 else
7825 version = "Unknown";
7826
7827 if (if_nametoindex("ath1") > 0)
7828 snprintf(resp, sizeof(resp), "interface,ath0_24G "
7829 "ath1_5G,agent,1.0,version,%s/drv:%s",
7830 version, athver);
7831 else
7832 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
7833 "agent,1.0,version,%s/drv:%s",
7834 version, athver);
7835
7836 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7837 return 0;
7838 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307839 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007840 case DRIVER_MAC80211: {
7841 struct utsname uts;
7842 char *version;
7843
7844 if (uname(&uts) == 0)
7845 version = uts.release;
7846 else
7847 version = "Unknown";
7848
7849 if (if_nametoindex("wlan1") > 0)
7850 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
7851 "wlan1_5G,agent,1.0,version,%s", version);
7852 else
7853 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
7854 "agent,1.0,version,%s", version);
7855
7856 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7857 return 0;
7858 }
7859 case DRIVER_QNXNTO: {
7860 struct utsname uts;
7861 char *version;
7862
7863 if (uname(&uts) == 0)
7864 version = uts.release;
7865 else
7866 version = "Unknown";
7867 snprintf(resp, sizeof(resp),
7868 "interface,%s_any,agent,1.0,version,%s",
7869 sigma_main_ifname ? sigma_main_ifname : "NA",
7870 version);
7871 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7872 return 0;
7873 }
7874 case DRIVER_OPENWRT: {
7875 switch (get_openwrt_driver_type()) {
7876 case OPENWRT_DRIVER_ATHEROS: {
7877 struct utsname uts;
7878 char *version;
7879
7880 if (uname(&uts) == 0)
7881 version = uts.release;
7882 else
7883 version = "Unknown";
7884
7885 if (if_nametoindex("ath1") > 0)
7886 snprintf(resp, sizeof(resp),
7887 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
7888 version);
7889 else
7890 snprintf(resp, sizeof(resp),
7891 "interface,ath0_any,agent,1.0,version,%s",
7892 version);
7893
7894 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7895 return 0;
7896 }
7897 default:
7898 send_resp(dut, conn, SIGMA_ERROR,
7899 "errorCode,Unsupported openwrt driver");
7900 return 0;
7901 }
7902 }
7903 default:
7904 send_resp(dut, conn, SIGMA_ERROR,
7905 "errorCode,Unsupported driver");
7906 return 0;
7907 }
7908}
7909
7910
7911static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
7912 struct sigma_cmd *cmd)
7913{
7914 /* const char *name = get_param(cmd, "NAME"); */
7915 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7916 const char *val;
7917 char buf[100];
7918
7919 val = get_param(cmd, "MinorCode");
7920 if (val) {
7921 /* TODO: add support for P2P minor code */
7922 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
7923 "yet supported");
7924 return 0;
7925 }
7926
7927 val = get_param(cmd, "STA_MAC_ADDRESS");
7928 if (val == NULL)
7929 return -1;
7930 snprintf(buf, sizeof(buf), "deauth %s", val);
7931 if (run_hostapd_cli(dut, buf) != 0)
7932 return -2;
7933
7934 return 1;
7935}
7936
7937
7938#ifdef __linux__
7939int inject_frame(int s, const void *data, size_t len, int encrypt);
7940int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007941#endif /* __linux__ */
7942
7943enum send_frame_type {
7944 DISASSOC, DEAUTH, SAQUERY
7945};
7946enum send_frame_protection {
7947 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
7948};
7949
7950
7951static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7952 enum send_frame_type frame,
7953 enum send_frame_protection protected,
7954 const char *sta_addr)
7955{
7956#ifdef __linux__
7957 unsigned char buf[1000], *pos;
7958 int s, res;
7959 unsigned char addr_sta[6], addr_own[6];
7960 char *ifname;
7961 char cbuf[100];
7962 struct ifreq ifr;
7963
7964 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
7965 dut->ap_mode == AP_11ac) &&
7966 if_nametoindex("wlan1") > 0)
7967 ifname = "wlan1";
7968 else
7969 ifname = "wlan0";
7970
7971 if (hwaddr_aton(sta_addr, addr_sta) < 0)
7972 return -1;
7973
7974 s = socket(AF_INET, SOCK_DGRAM, 0);
7975 if (s < 0)
7976 return -1;
7977 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07007978 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007979 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
7980 perror("ioctl");
7981 close(s);
7982 return -1;
7983 }
7984 close(s);
7985 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
7986
7987 if (if_nametoindex("sigmadut") == 0) {
7988 snprintf(cbuf, sizeof(cbuf),
7989 "iw dev %s interface add sigmadut type monitor",
7990 ifname);
7991 if (system(cbuf) != 0 ||
7992 if_nametoindex("sigmadut") == 0) {
7993 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
7994 "monitor interface with '%s'", cbuf);
7995 return -2;
7996 }
7997 }
7998
7999 if (system("ifconfig sigmadut up") != 0) {
8000 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8001 "monitor interface up");
8002 return -2;
8003 }
8004
8005 pos = buf;
8006
8007 /* Frame Control */
8008 switch (frame) {
8009 case DISASSOC:
8010 *pos++ = 0xa0;
8011 break;
8012 case DEAUTH:
8013 *pos++ = 0xc0;
8014 break;
8015 case SAQUERY:
8016 *pos++ = 0xd0;
8017 break;
8018 }
8019
8020 if (protected == INCORRECT_KEY)
8021 *pos++ = 0x40; /* Set Protected field to 1 */
8022 else
8023 *pos++ = 0x00;
8024
8025 /* Duration */
8026 *pos++ = 0x00;
8027 *pos++ = 0x00;
8028
8029 /* addr1 = DA (station) */
8030 memcpy(pos, addr_sta, 6);
8031 pos += 6;
8032 /* addr2 = SA (own address) */
8033 memcpy(pos, addr_own, 6);
8034 pos += 6;
8035 /* addr3 = BSSID (own address) */
8036 memcpy(pos, addr_own, 6);
8037 pos += 6;
8038
8039 /* Seq# (to be filled by driver/mac80211) */
8040 *pos++ = 0x00;
8041 *pos++ = 0x00;
8042
8043 if (protected == INCORRECT_KEY) {
8044 /* CCMP parameters */
8045 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8046 pos += 8;
8047 }
8048
8049 if (protected == INCORRECT_KEY) {
8050 switch (frame) {
8051 case DEAUTH:
8052 /* Reason code (encrypted) */
8053 memcpy(pos, "\xa7\x39", 2);
8054 pos += 2;
8055 break;
8056 case DISASSOC:
8057 /* Reason code (encrypted) */
8058 memcpy(pos, "\xa7\x39", 2);
8059 pos += 2;
8060 break;
8061 case SAQUERY:
8062 /* Category|Action|TransID (encrypted) */
8063 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8064 pos += 4;
8065 break;
8066 default:
8067 return -1;
8068 }
8069
8070 /* CCMP MIC */
8071 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8072 pos += 8;
8073 } else {
8074 switch (frame) {
8075 case DEAUTH:
8076 /* reason code = 8 */
8077 *pos++ = 0x08;
8078 *pos++ = 0x00;
8079 break;
8080 case DISASSOC:
8081 /* reason code = 8 */
8082 *pos++ = 0x08;
8083 *pos++ = 0x00;
8084 break;
8085 case SAQUERY:
8086 /* Category - SA Query */
8087 *pos++ = 0x08;
8088 /* SA query Action - Request */
8089 *pos++ = 0x00;
8090 /* Transaction ID */
8091 *pos++ = 0x12;
8092 *pos++ = 0x34;
8093 break;
8094 }
8095 }
8096
8097 s = open_monitor("sigmadut");
8098 if (s < 0) {
8099 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8100 "monitor socket");
8101 return 0;
8102 }
8103
8104 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8105 if (res < 0) {
8106 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8107 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308108 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008109 return 0;
8110 }
8111 if (res < pos - buf) {
8112 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8113 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308114 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008115 return 0;
8116 }
8117
8118 close(s);
8119
8120 return 1;
8121#else /* __linux__ */
8122 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
8123 "yet supported");
8124 return 0;
8125#endif /* __linux__ */
8126}
8127
8128
8129int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8130 struct sigma_cmd *cmd)
8131{
8132 const char *val, *dest;
8133 char buf[100];
8134
8135 val = get_param(cmd, "FrameName");
8136 if (val == NULL)
8137 return -1;
8138
8139 if (strcasecmp(val, "QoSMapConfigure") == 0) {
8140 dest = get_param(cmd, "Dest");
8141 if (!dest)
8142 return -1;
8143
8144 val = get_param(cmd, "QoS_MAP_SET");
8145 if (val) {
8146 dut->ap_qos_map_set = atoi(val);
8147 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8148 dut->ap_qos_map_set);
8149 }
8150
8151 if (dut->ap_qos_map_set == 1)
8152 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8153 else if (dut->ap_qos_map_set == 2)
8154 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8155
8156 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8157 if (run_hostapd_cli(dut, buf) != 0)
8158 return -1;
8159 }
8160
8161 return 1;
8162}
8163
8164
8165static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8166 struct sigma_cmd *cmd)
8167{
8168 const char *val;
8169 char *ifname;
8170 char buf[100];
8171 int chwidth, nss;
8172
8173 val = get_param(cmd, "FrameName");
8174 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
8175 send_resp(dut, conn, SIGMA_ERROR,
8176 "errorCode,Unsupported FrameName");
8177 return 0;
8178 }
8179
8180 /*
8181 * Sequence of commands for Opmode notification on
8182 * Peregrine based products
8183 */
8184 ifname = get_main_ifname();
8185
8186 /* Disable STBC */
8187 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
8188 if (system(buf) != 0) {
8189 sigma_dut_print(dut, DUT_MSG_ERROR,
8190 "iwpriv tx_stbc 0 failed!");
8191 }
8192
8193 /* Check whether optional arg channel width was passed */
8194 val = get_param(cmd, "Channel_width");
8195 if (val) {
8196 switch (atoi(val)) {
8197 case 20:
8198 chwidth = 0;
8199 break;
8200 case 40:
8201 chwidth = 1;
8202 break;
8203 case 80:
8204 chwidth = 2;
8205 break;
8206 case 160:
8207 chwidth = 3;
8208 break;
8209 default:
8210 chwidth = 2;
8211 break;
8212 }
8213 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8214 ifname, chwidth);
8215 if (system(buf) != 0) {
8216 sigma_dut_print(dut, DUT_MSG_ERROR,
8217 "iwpriv chwidth failed!");
8218 }
8219 }
8220
8221 /* Check whether optional arg NSS was passed */
8222 val = get_param(cmd, "NSS");
8223 if (val) {
8224 /* Convert nss to chainmask */
8225 switch (atoi(val)) {
8226 case 1:
8227 nss = 1;
8228 break;
8229 case 2:
8230 nss = 3;
8231 break;
8232 case 3:
8233 nss = 7;
8234 break;
8235 default:
8236 /* We do not support NSS > 3 */
8237 nss = 3;
8238 break;
8239 }
8240 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
8241 ifname, nss);
8242 if (system(buf) != 0) {
8243 sigma_dut_print(dut, DUT_MSG_ERROR,
8244 "iwpriv rxchainmask failed!");
8245 }
8246 }
8247
8248 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03008249 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008250 if (system(buf) != 0) {
8251 sigma_dut_print(dut, DUT_MSG_ERROR,
8252 "iwpriv opmode_notify failed!");
8253 }
8254
8255 return 1;
8256}
8257
8258
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008259static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8260 struct sigma_cmd *cmd)
8261{
8262 const char *val;
8263 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008264 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008265
8266 val = get_param(cmd, "MsntType");
8267 if (val) {
8268 if (dut->ap_msnt_type == 0)
8269 dut->ap_msnt_type = atoi(val);
8270
8271 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
8272 dut->ap_msnt_type = atoi(val);
8273 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008274 val = get_param(cmd, "RandInterval");
8275 if (val)
8276 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008277 f = fopen("/tmp/ftmrr.txt", "a");
8278 if (!f) {
8279 sigma_dut_print(dut, DUT_MSG_ERROR,
8280 "Failed to open /tmp/ftmrr.txt");
8281 return -1;
8282 }
8283
8284 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008285 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",
8286 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008287 fclose(f);
8288 dut->ap_msnt_type = 5;
8289 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8290 }
8291 } else if (dut->ap_msnt_type == 5) {
8292 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8293 } else if (dut->ap_msnt_type == 2) {
8294 f = fopen("/tmp/wru.txt", "w");
8295 if (!f) {
8296 sigma_dut_print(dut, DUT_MSG_ERROR,
8297 "Failed to open /tmp/wru.txt");
8298 return -1;
8299 }
8300
8301 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
8302 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
8303 fclose(f);
8304 run_system(dut, "wpc -w /tmp/wru.txt");
8305 }
8306 }
8307 return 1;
8308}
8309
8310
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008311/*
8312 * The following functions parse_send_frame_params_int(),
8313 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
8314 * are used by ath_ap_send_frame_bcn_rpt_req().
8315 * Beacon Report Request is a frame used as part of the MBO program.
8316 * The command for sending beacon report has a lot of
8317 * arguments and having these functions reduces code size.
8318 *
8319 */
8320static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
8321 struct sigma_dut *dut,
8322 char *buf, size_t buf_size)
8323{
8324 const char *str_val;
8325 int int_val;
8326 char temp[100];
8327
8328 str_val = get_param(cmd, param);
8329 if (!str_val) {
8330 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8331 return -1;
8332 }
8333 int_val = atoi(str_val);
8334 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07008335 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008336 return 0;
8337}
8338
8339
8340static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
8341 struct sigma_dut *dut,
8342 char *buf, size_t buf_size)
8343{
8344 const char *str_val;
8345 char temp[100];
8346
8347 str_val = get_param(cmd, param);
8348 if (!str_val) {
8349 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8350 return -1;
8351 }
8352 snprintf(temp, sizeof(temp), " %s", str_val);
8353 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07008354 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008355 return 0;
8356}
8357
8358
8359static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
8360 struct sigma_dut *dut,
8361 char *buf, size_t buf_size)
8362{
8363 const char *str_val;
8364 unsigned char mac[6];
8365 char temp[100];
8366
8367 str_val = get_param(cmd, param);
8368 if (!str_val) {
8369 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8370 return -1;
8371 }
8372
8373 if (parse_mac_address(dut, str_val, mac) < 0) {
8374 sigma_dut_print(dut, DUT_MSG_ERROR,
8375 "MAC Address not in proper format");
8376 return -1;
8377 }
8378 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
8379 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07008380 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008381 return 0;
8382}
8383
8384
8385static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
8386 char *buf, size_t buf_size)
8387{
8388 const char *str_val;
8389 char *value = " 1";
8390
8391 str_val = get_param(cmd, param);
8392 if (!str_val || str_val[0] == '\0')
8393 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07008394 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008395
8396}
8397
8398
8399/*
8400 * wifitool athN sendbcnrpt
8401 * <STA MAC - Plugs in from Dest_MAC>
8402 * <regclass - Plugs in from RegClass - int>
8403 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
8404 * <rand_ivl - Plugs in from RandInt - string>
8405 * <duration - Plugs in from MeaDur - integer>
8406 * <mode - Plugs in from MeaMode - string>
8407 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
8408 * <rep_cond - Plugs in from RptCond - integer>
8409 * <rpt_detail - Plugs in from RptDet - integer>
8410 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
8411 * <chanrpt_mode - Plugs in from APChanRpt - integer>
8412 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
8413 * [AP channel numbers]
8414 */
8415static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
8416 struct sigma_cmd *cmd,
8417 const char *ifname)
8418{
8419 char buf[100];
8420 int rpt_det;
8421 const char *str_val;
8422 const char *mea_mode;
8423
8424 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
8425
8426 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
8427 return -1;
8428 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
8429 return -1;
8430 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
8431 return -1;
8432 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
8433 return -1;
8434 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
8435 return -1;
8436
8437 str_val = get_param(cmd, "MeaMode");
8438 if (!str_val) {
8439 sigma_dut_print(dut, DUT_MSG_ERROR,
8440 "MeaMode parameter not present in send bcn-rpt-req");
8441 return -1;
8442 }
8443 if (strcasecmp(str_val, "passive") == 0) {
8444 mea_mode = " 0";
8445 } else if (strcasecmp(str_val, "active") == 0) {
8446 mea_mode = " 1";
8447 } else if (strcasecmp(str_val, "table") == 0) {
8448 mea_mode = " 2";
8449 } else {
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "MEA-MODE Value not correctly given");
8452 return -1;
8453 }
Peng Xu591be452017-05-10 17:27:28 -07008454 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008455
8456 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
8457
8458 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
8459 return -1;
8460
8461 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
8462 return -1;
8463 str_val = get_param(cmd, "RptDet");
8464 rpt_det = str_val ? atoi(str_val) : 0;
8465
8466 if (rpt_det)
8467 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
8468 else
Peng Xu591be452017-05-10 17:27:28 -07008469 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008470
8471 if (rpt_det)
8472 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
8473 sizeof(buf));
8474 else
Peng Xu591be452017-05-10 17:27:28 -07008475 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008476
8477 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
8478 return -1;
8479
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008480 str_val = get_param(cmd, "APChanRpt");
8481 if (str_val) {
8482 const char *pos;
8483 int ap_chanrpt;
8484 int ap_chanrpt_2 = 0;
8485 char chanrpt[100];
8486
8487 ap_chanrpt = atoi(str_val);
8488 pos = strchr(str_val, '_');
8489 if (pos) {
8490 pos++;
8491 ap_chanrpt_2 = atoi(pos);
8492 }
8493 if (ap_chanrpt) {
8494 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
8495 strlcat(buf, chanrpt, sizeof(buf));
8496 }
8497 if (ap_chanrpt_2) {
8498 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
8499 strlcat(buf, chanrpt, sizeof(buf));
8500 }
8501 }
8502
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008503 run_system(dut, buf);
8504 return 0;
8505}
8506
8507
8508static void inform_and_sleep(struct sigma_dut *dut, int seconds)
8509{
8510 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
8511 sleep(seconds);
8512 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
8513 seconds);
8514}
8515
8516
8517static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
8518 struct sigma_cmd *cmd, const char *ifname)
8519{
8520 unsigned char mac_addr[ETH_ALEN];
8521 int disassoc_timer;
8522 char buf[100];
8523 const char *val;
8524 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008525
8526 val = get_param(cmd, "Dest_MAC");
8527 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
8528 sigma_dut_print(dut, DUT_MSG_ERROR,
8529 "MAC Address not in proper format");
8530 return -1;
8531 }
8532
8533 val = get_param(cmd, "Disassoc_Timer");
8534 if (val)
8535 disassoc_timer = atoi(val);
8536 else
8537 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02008538 if (disassoc_timer < 0) {
8539 sigma_dut_print(dut, DUT_MSG_ERROR,
8540 "Invalid Disassoc_Timer value %d",
8541 disassoc_timer);
8542 return -1;
8543 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008544
8545 val = get_param(cmd, "Cand_List");
8546 if (val && val[0])
8547 cand_list = atoi(val);
8548
8549 val = get_param(cmd, "BTMQuery_Reason_Code");
8550 if (val) {
8551 snprintf(buf, sizeof(buf), "iwpriv %s mbo_trans_rs %s",
8552 ifname, val);
8553 run_system(dut, buf);
8554 }
8555
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008556 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay) {
8557 snprintf(buf, sizeof(buf), "iwpriv %s mbo_asoc_ret 1", ifname);
8558 run_system(dut, buf);
8559 }
8560
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008561 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008562 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008563 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
8564 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
8565 dut->ap_btmreq_disassoc_imnt,
8566 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008567 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008568 dut->ap_btmreq_bss_term_dur);
8569 run_system(dut, buf);
8570
8571 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008572 if (dut->ap_btmreq_bss_term_tsf >= 2)
8573 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008574 run_system_wrapper(
8575 dut, "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8576 ifname,
8577 mac_addr[0], mac_addr[1], mac_addr[2],
8578 mac_addr[3], mac_addr[4], mac_addr[5]);
8579 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008580 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008581 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008582 run_system_wrapper(dut, "ifconfig %s up", ifname);
8583 } else if (dut->ap_btmreq_disassoc_imnt) {
8584 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
8585 run_system_wrapper(dut,
8586 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8587 ifname,
8588 mac_addr[0], mac_addr[1], mac_addr[2],
8589 mac_addr[3], mac_addr[4], mac_addr[5]);
8590 }
8591 return 0;
8592}
8593
8594
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008595static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
8596 struct sigma_cmd *cmd, const char *ifname)
8597{
8598 unsigned char mac_addr[ETH_ALEN];
8599 const char *val;
8600
8601 val = get_param(cmd, "Dest_MAC");
8602 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
8603 sigma_dut_print(dut, DUT_MSG_ERROR,
8604 "MAC Address not in proper format");
8605 return -1;
8606 }
8607
8608 run_system_wrapper(dut,
8609 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
8610 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
8611 mac_addr[3], mac_addr[4], mac_addr[5]);
8612 return 0;
8613}
8614
8615
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008616static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
8617 struct sigma_cmd *cmd)
8618{
8619 const char *val;
8620 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008621
8622 ifname = get_main_ifname();
8623
8624 val = get_param(cmd, "FrameName");
8625 if (!val)
8626 return -1;
8627
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008628 if (strcasecmp(val, "BTMReq") == 0)
8629 ath_ap_send_frame_btm_req(dut, cmd, ifname);
8630 else if (strcasecmp(val, "BcnRptReq") == 0)
8631 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008632 else if (strcasecmp(val, "disassoc") == 0)
8633 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008634 else
8635 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008636
8637 return 1;
8638}
8639
8640
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008641static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8642 struct sigma_cmd *cmd)
8643{
8644 switch (get_driver_type()) {
8645 case DRIVER_ATHEROS:
8646 return ath_ap_send_frame_vht(dut, conn, cmd);
8647 break;
8648 case DRIVER_OPENWRT:
8649 switch (get_openwrt_driver_type()) {
8650 case OPENWRT_DRIVER_ATHEROS:
8651 return ath_ap_send_frame_vht(dut, conn, cmd);
8652 default:
8653 send_resp(dut, conn, SIGMA_ERROR,
8654 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
8655 return 0;
8656 }
8657 default:
8658 send_resp(dut, conn, SIGMA_ERROR,
8659 "errorCode,Unsupported ap_send_frame with the current driver");
8660 return 0;
8661 }
8662}
8663
8664
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008665static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8666 struct sigma_cmd *cmd)
8667{
8668 switch (get_driver_type()) {
8669 case DRIVER_ATHEROS:
8670 return ath_ap_send_frame_loc(dut, conn, cmd);
8671 case DRIVER_OPENWRT:
8672 switch (get_openwrt_driver_type()) {
8673 case OPENWRT_DRIVER_ATHEROS:
8674 return ath_ap_send_frame_loc(dut, conn, cmd);
8675 default:
8676 send_resp(dut, conn, SIGMA_ERROR,
8677 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
8678 return 0;
8679 }
8680 default:
8681 send_resp(dut, conn, SIGMA_ERROR,
8682 "errorCode,Unsupported ap_send_frame_loc with the current driver");
8683 return 0;
8684 }
8685}
8686
8687
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008688static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
8689 struct sigma_cmd *cmd)
8690{
8691 switch (get_driver_type()) {
8692 case DRIVER_ATHEROS:
8693 return ath_ap_send_frame_mbo(dut, conn, cmd);
8694 case DRIVER_OPENWRT:
8695 switch (get_openwrt_driver_type()) {
8696 case OPENWRT_DRIVER_ATHEROS:
8697 return ath_ap_send_frame_mbo(dut, conn, cmd);
8698 default:
8699 send_resp(dut, conn, SIGMA_ERROR,
8700 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
8701 return 0;
8702 }
8703 default:
8704 send_resp(dut, conn, SIGMA_ERROR,
8705 "errorCode,Unsupported ap_send_frame with the current driver");
8706 return 0;
8707 }
8708}
8709
8710
Lior David0fe101e2017-03-09 16:09:50 +02008711static int ap_send_frame_60g(struct sigma_dut *dut,
8712 struct sigma_conn *conn,
8713 struct sigma_cmd *cmd)
8714{
8715 switch (get_driver_type()) {
8716#ifdef __linux__
8717 case DRIVER_WIL6210:
8718 return wil6210_send_frame_60g(dut, conn, cmd);
8719#endif /* __linux__ */
8720 default:
8721 send_resp(dut, conn, SIGMA_ERROR,
8722 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
8723 return 0;
8724 }
8725}
8726
8727
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008728int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8729 struct sigma_cmd *cmd)
8730{
8731 /* const char *name = get_param(cmd, "NAME"); */
8732 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8733 const char *val;
8734 enum send_frame_type frame;
8735 enum send_frame_protection protected;
8736 char buf[100];
8737
8738 val = get_param(cmd, "Program");
8739 if (val) {
8740 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008741 strcasecmp(val, "HS2-R2") == 0 ||
8742 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008743 return ap_send_frame_hs2(dut, conn, cmd);
8744 if (strcasecmp(val, "VHT") == 0)
8745 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008746 if (strcasecmp(val, "LOC") == 0)
8747 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008748 if (strcasecmp(val, "MBO") == 0)
8749 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02008750 if (strcasecmp(val, "60GHz") == 0)
8751 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008752 }
8753
8754 val = get_param(cmd, "PMFFrameType");
8755 if (val == NULL)
8756 val = get_param(cmd, "FrameName");
8757 if (val == NULL)
8758 val = get_param(cmd, "Type");
8759 if (val == NULL)
8760 return -1;
8761 if (strcasecmp(val, "disassoc") == 0)
8762 frame = DISASSOC;
8763 else if (strcasecmp(val, "deauth") == 0)
8764 frame = DEAUTH;
8765 else if (strcasecmp(val, "saquery") == 0)
8766 frame = SAQUERY;
8767 else {
8768 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8769 "PMFFrameType");
8770 return 0;
8771 }
8772
8773 val = get_param(cmd, "PMFProtected");
8774 if (val == NULL)
8775 val = get_param(cmd, "Protected");
8776 if (val == NULL)
8777 return -1;
8778 if (strcasecmp(val, "Correct-key") == 0 ||
8779 strcasecmp(val, "CorrectKey") == 0)
8780 protected = CORRECT_KEY;
8781 else if (strcasecmp(val, "IncorrectKey") == 0)
8782 protected = INCORRECT_KEY;
8783 else if (strcasecmp(val, "Unprotected") == 0)
8784 protected = UNPROTECTED;
8785 else {
8786 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
8787 "PMFProtected");
8788 return 0;
8789 }
8790
8791 val = get_param(cmd, "stationID");
8792 if (val == NULL)
8793 return -1;
8794
8795 if (protected == INCORRECT_KEY ||
8796 (protected == UNPROTECTED && frame == SAQUERY))
8797 return ap_inject_frame(dut, conn, frame, protected, val);
8798
8799 switch (frame) {
8800 case DISASSOC:
8801 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
8802 val, protected == CORRECT_KEY);
8803 break;
8804 case DEAUTH:
8805 snprintf(buf, sizeof(buf), "deauth %s test=%d",
8806 val, protected == CORRECT_KEY);
8807 break;
8808 case SAQUERY:
8809 snprintf(buf, sizeof(buf), "sa_query %s", val);
8810 break;
8811 }
8812
8813 if (run_hostapd_cli(dut, buf) != 0)
8814 return -2;
8815
8816 return 1;
8817}
8818
8819
8820static int cmd_ap_get_mac_address(struct sigma_dut *dut,
8821 struct sigma_conn *conn,
8822 struct sigma_cmd *cmd)
8823{
8824#if defined( __linux__)
8825 /* const char *name = get_param(cmd, "NAME"); */
8826 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03008827 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008828 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008829 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008830 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008831 int s, wlan_tag = 1;
8832 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008833
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008834 val = get_param(cmd, "WLAN_TAG");
8835 if (val) {
8836 wlan_tag = atoi(val);
8837 if (wlan_tag < 1 || wlan_tag > 3) {
8838 /*
8839 * The only valid WLAN Tags as of now as per the latest
8840 * WFA scripts are 1, 2, and 3.
8841 */
Jouni Malinenf8984642017-10-12 00:02:37 +03008842 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008843 "errorCode,Unsupported WLAN_TAG");
8844 return 0;
8845 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008846 }
8847
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008848 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
8849
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008850 s = socket(AF_INET, SOCK_DGRAM, 0);
8851 if (s < 0)
8852 return -1;
8853 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07008854 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008855 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
8856 perror("ioctl");
8857 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03008858 snprintf(resp, sizeof(resp),
8859 "errorCode,Could not find interface %s", ifname);
8860 send_resp(dut, conn, SIGMA_ERROR, resp);
8861 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008862 }
8863 close(s);
8864 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
8865
8866 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
8867 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
8868 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8869 return 0;
8870#elif defined( __QNXNTO__)
8871 char resp[50];
8872 unsigned char addr[6];
8873
8874 if (!sigma_main_ifname) {
8875 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
8876 return 0;
8877 }
8878
8879 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
8880 send_resp(dut, conn, SIGMA_ERROR,
8881 "errorCode,Failed to get address");
8882 return 0;
8883 }
8884 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
8885 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
8886 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8887 return 0;
8888#else /* __linux__ */
8889 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
8890 "yet supported");
8891 return 0;
8892#endif /* __linux__ */
8893}
8894
8895
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308896int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
8897 struct sigma_cmd *cmd)
8898{
8899 return cmd_ap_get_mac_address(dut, conn, cmd);
8900}
8901
8902
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008903static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
8904 struct sigma_cmd *cmd)
8905{
8906 /*
8907 * Ignore the command since the parameters are already handled through
8908 * ap_set_security.
8909 */
8910
8911 return 1;
8912}
8913
8914
8915static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8916 struct sigma_cmd *cmd)
8917{
8918 /* const char *name = get_param(cmd, "NAME"); */
8919 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8920 const char *val, *dest;
8921 char *pos, buf[100];
8922 int i, wlan_tag = 1;
8923
8924 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
8925 "following parameters");
8926 for (i = 0; i < cmd->count; i++) {
8927 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
8928 (cmd->values[i] ? cmd->values[i] : "NULL"));
8929 }
8930
8931 val = get_param(cmd, "ICMPv4_ECHO");
8932 if (val && atoi(val)) {
8933 snprintf(buf, sizeof(buf), "ebtables -F");
8934 if (system(buf) != 0) {
8935 sigma_dut_print(dut, DUT_MSG_ERROR,
8936 "Failed to set ebtables rules, RULE-12");
8937 }
8938 return 1;
8939 }
8940
8941 val = get_param(cmd, "WLAN_TAG");
8942 if (val) {
8943 wlan_tag = atoi(val);
8944 if (wlan_tag != 1 && wlan_tag != 2) {
8945 send_resp(dut, conn, SIGMA_INVALID,
8946 "errorCode,Invalid WLAN_TAG");
8947 return 0;
8948 }
8949 }
8950
8951 if (wlan_tag == 2) {
8952 val = get_param(cmd, "PROXY_ARP");
8953 if (val)
8954 dut->ap2_proxy_arp = atoi(val);
8955 return 1;
8956 }
8957
8958 dest = get_param(cmd, "STA_MAC");
8959 if (dest) {
8960 /* This is a special/ugly way of using this command.
8961 * If "Dest" MAC is included, assume that this command
8962 * is being issued after ap_config_commit for dynamically
8963 * setting the QoS Map Set.
8964 */
8965 val = get_param(cmd, "QoS_MAP_SET");
8966 if (val) {
8967 dut->ap_qos_map_set = atoi(val);
8968 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8969 dut->ap_qos_map_set);
8970 }
8971
8972 if (dut->ap_qos_map_set == 1)
8973 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8974 else if (dut->ap_qos_map_set == 2)
8975 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8976
8977 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8978 if (run_hostapd_cli(dut, buf) != 0)
8979 return -1;
8980 }
8981
8982 val = get_param(cmd, "DGAF_DISABLE");
8983 if (val)
8984 dut->ap_dgaf_disable = atoi(val);
8985
8986 dut->ap_interworking = 1;
8987
8988 val = get_param(cmd, "INTERWORKING");
8989 if (val == NULL)
8990 val = get_param(cmd, "INTERNETWORKING");
8991 if (val != NULL && atoi(val) == 0) {
8992 dut->ap_interworking = 0;
8993 dut->ap_hs2 = 0;
8994 return 1;
8995 }
8996
8997 val = get_param(cmd, "ACCS_NET_TYPE");
8998 if (val) {
8999 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
9000 strcasecmp(val, "Chargable_Public_Network") == 0 ||
9001 strcasecmp(val, "Chargable Public Network") == 0)
9002 dut->ap_access_net_type = 2;
9003 else
9004 dut->ap_access_net_type = atoi(val);
9005 }
9006
9007 val = get_param(cmd, "INTERNET");
9008 if (val)
9009 dut->ap_internet = atoi(val);
9010
9011 val = get_param(cmd, "VENUE_GRP");
9012 if (val) {
9013 if (strcasecmp(val, "Business") == 0)
9014 dut->ap_venue_group = 2;
9015 else
9016 dut->ap_venue_group = atoi(val);
9017 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9018 dut->ap_venue_name);
9019 }
9020
9021 val = get_param(cmd, "VENUE_TYPE");
9022 if (val) {
9023 if (strcasecmp(val, "R&D") == 0)
9024 dut->ap_venue_type = 8;
9025 else
9026 dut->ap_venue_type = atoi(val);
9027 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
9028 dut->ap_venue_type);
9029 }
9030
9031 val = get_param(cmd, "HESSID");
9032 if (val) {
9033 if (strlen(val) >= sizeof(dut->ap_hessid)) {
9034 send_resp(dut, conn, SIGMA_ERROR,
9035 "errorCode,Invalid HESSID");
9036 return 0;
9037 }
9038 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
9039 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
9040 dut->ap_hessid);
9041 }
9042
9043 val = get_param(cmd, "ROAMING_CONS");
9044 if (val) {
9045 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
9046 send_resp(dut, conn, SIGMA_ERROR,
9047 "errorCode,Invalid ROAMING_CONS");
9048 return 0;
9049 }
9050 if (strcasecmp(val, "Disabled") == 0) {
9051 dut->ap_roaming_cons[0] = '\0';
9052 } else {
9053 snprintf(dut->ap_roaming_cons,
9054 sizeof(dut->ap_roaming_cons), "%s", val);
9055 }
9056 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
9057 dut->ap_roaming_cons);
9058 }
9059
9060 val = get_param(cmd, "ANQP");
9061 if (val)
9062 dut->ap_anqpserver_on = atoi(val);
9063
9064 val = get_param(cmd, "NAI_REALM_LIST");
9065 if (val) {
9066 dut->ap_nai_realm_list = atoi(val);
9067 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
9068 dut->ap_nai_realm_list);
9069 }
9070
9071 val = get_param(cmd, "3GPP_INFO");
9072 if (val) {
9073 /* What kind of encoding format is used?! */
9074 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
9075 "not yet supported (contents not fully defined)");
9076 return 0;
9077 }
9078
9079 val = get_param(cmd, "DOMAIN_LIST");
9080 if (val) {
9081 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
9082 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
9083 "DOMAIN_LIST");
9084 return 0;
9085 }
9086 snprintf(dut->ap_domain_name_list,
9087 sizeof(dut->ap_domain_name_list), "%s", val);
9088 pos = dut->ap_domain_name_list;
9089 while (*pos) {
9090 if (*pos == ';')
9091 *pos = ',';
9092 pos++;
9093 }
9094 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
9095 dut->ap_domain_name_list);
9096 }
9097
9098 val = get_param(cmd, "OPER_NAME");
9099 if (val) {
9100 dut->ap_oper_name = atoi(val);
9101 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
9102 dut->ap_oper_name);
9103 }
9104
9105 val = get_param(cmd, "VENUE_NAME");
9106 if (val) {
9107 dut->ap_venue_name = atoi(val);
9108 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9109 dut->ap_venue_name);
9110 }
9111
9112 val = get_param(cmd, "GAS_CB_DELAY");
9113 if (val) {
9114 dut->ap_gas_cb_delay = atoi(val);
9115 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
9116 dut->ap_gas_cb_delay);
9117 }
9118
9119 val = get_param(cmd, "MIH");
9120 if (val && atoi(val) > 0) {
9121 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
9122 "supported");
9123 return 0;
9124 }
9125
9126 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
9127 if (val) {
9128 dut->ap_l2tif = atoi(val);
9129 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
9130 dut->ap_l2tif);
9131 }
9132
9133 val = get_param(cmd, "BCST_UNCST");
9134 if (val) {
9135 send_resp(dut, conn, SIGMA_ERROR,
9136 "errorCode,BCST_UNCST not yet supported");
9137 return 0;
9138 }
9139
9140 val = get_param(cmd, "PLMN_MCC");
9141 if (val) {
9142 char mcc[100], *start, *end;
9143 int i = 0;
9144 if (strlen(val) >= sizeof(mcc)) {
9145 send_resp(dut, conn, SIGMA_ERROR,
9146 "errorCode,PLMN_MCC too long");
9147 return 0;
9148 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009149 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009150 start = mcc;
9151 while ((end = strchr(start, ';'))) {
9152 /* process all except the last */
9153 *end = '\0';
9154 if (strlen(start) != 3) {
9155 send_resp(dut, conn, SIGMA_ERROR,
9156 "errorCode,Invalid PLMN_MCC");
9157 return 0;
9158 }
9159 snprintf(dut->ap_plmn_mcc[i],
9160 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9161 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9162 dut->ap_plmn_mcc[i]);
9163 i++;
9164 start = end + 1;
9165 *end = ';';
9166 }
9167 if (strlen(start) != 3) {
9168 send_resp(dut, conn, SIGMA_ERROR,
9169 "errorCode,Invalid PLMN_MCC");
9170 return 0;
9171 }
9172 /* process last or only one */
9173 snprintf(dut->ap_plmn_mcc[i],
9174 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9175 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9176 dut->ap_plmn_mcc[i]);
9177 }
9178
9179 val = get_param(cmd, "PLMN_MNC");
9180 if (val) {
9181 char mnc[100], *start, *end;
9182 int i = 0;
9183 if (strlen(val) >= sizeof(mnc)) {
9184 send_resp(dut, conn, SIGMA_ERROR,
9185 "errorCode,PLMN_MNC too long");
9186 return 0;
9187 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009188 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009189 start = mnc;
9190 while ((end = strchr(start, ';'))) {
9191 *end = '\0';
9192 if (strlen(start) != 2 && strlen(start) != 3) {
9193 send_resp(dut, conn, SIGMA_ERROR,
9194 "errorCode,Invalid PLMN_MNC");
9195 return 0;
9196 }
9197 snprintf(dut->ap_plmn_mnc[i],
9198 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9199 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9200 dut->ap_plmn_mnc[i]);
9201 i++;
9202 start = end + 1;
9203 *end = ';';
9204 }
9205 if (strlen(start) != 2 && strlen(start) != 3) {
9206 send_resp(dut, conn, SIGMA_ERROR,
9207 "errorCode,Invalid PLMN_MNC");
9208 return 0;
9209 }
9210 snprintf(dut->ap_plmn_mnc[i],
9211 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9212 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9213 dut->ap_plmn_mnc[i]);
9214 }
9215
9216 val = get_param(cmd, "PROXY_ARP");
9217 if (val) {
9218 dut->ap_proxy_arp = atoi(val);
9219 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
9220 dut->ap_proxy_arp);
9221 }
9222
9223 val = get_param(cmd, "WAN_METRICS");
9224 if (val) {
9225 dut->ap_wan_metrics = atoi(val);
9226 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
9227 dut->ap_wan_metrics);
9228 }
9229
9230 val = get_param(cmd, "CONN_CAP");
9231 if (val) {
9232 dut->ap_conn_capab = atoi(val);
9233 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
9234 dut->ap_conn_capab);
9235 }
9236
9237 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
9238 if (val) {
9239 dut->ap_ip_addr_type_avail = atoi(val);
9240 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
9241 dut->ap_ip_addr_type_avail);
9242 }
9243
9244 val = get_param(cmd, "NET_AUTH_TYPE");
9245 if (val) {
9246 dut->ap_net_auth_type = atoi(val);
9247 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
9248 dut->ap_net_auth_type);
9249 }
9250
9251 val = get_param(cmd, "OP_CLASS");
9252 if (val == NULL)
9253 val = get_param(cmd, "OPER_CLASS");
9254 if (val) {
9255 dut->ap_oper_class = atoi(val);
9256 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
9257 dut->ap_oper_class);
9258 }
9259
9260 val = get_param(cmd, "OSU_PROVIDER_LIST");
9261 if (val) {
9262 dut->ap_osu_provider_list = atoi(val);
9263 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
9264 dut->ap_osu_provider_list);
9265 }
9266
9267 val = get_param(cmd, "OSU_SERVER_URI");
9268 if (val) {
9269 i = 0;
9270 do {
9271 int len;
9272 const char *uri = val;
9273 val = strchr(val, ' ');
9274 len = val ? (val++ - uri) : (int) strlen(uri);
9275 if (len > 0 && len < 256) {
9276 memcpy(dut->ap_osu_server_uri[i], uri, len);
9277 dut->ap_osu_server_uri[i][len] = '\0';
9278 sigma_dut_print(dut, DUT_MSG_INFO,
9279 "ap_osu_server_uri[%d] %s", i,
9280 dut->ap_osu_server_uri[i]);
9281 }
9282 } while (val && ++i < 10);
9283 }
9284
9285 val = get_param(cmd, "OSU_METHOD");
9286 if (val) {
9287 i = 0;
9288 do {
9289 int len;
9290 const char *method = val;
9291 val = strchr(val, ' ');
9292 len = val ? (val++ - method) : (int) strlen(method);
9293 if (len > 0) {
9294 if (strncasecmp(method, "SOAP", len) == 0)
9295 dut->ap_osu_method[i] = 1;
9296 else if (strncasecmp(method, "OMADM", len) == 0)
9297 dut->ap_osu_method[i] = 0;
9298 else
9299 return -2;
9300 }
9301 } while (val && ++i < 10);
9302 }
9303
9304 val = get_param(cmd, "OSU_SSID");
9305 if (val) {
9306 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -07009307 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009308 sizeof(dut->ap_osu_ssid));
9309 sigma_dut_print(dut, DUT_MSG_INFO,
9310 "ap_osu_ssid %s",
9311 dut->ap_osu_ssid);
9312 }
9313 }
9314
9315 val = get_param(cmd, "OSU_ICON_TAG");
9316 if (val)
9317 dut->ap_osu_icon_tag = atoi(val);
9318
9319 val = get_param(cmd, "QoS_MAP_SET");
9320 if (val) {
9321 dut->ap_qos_map_set = atoi(val);
9322 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9323 dut->ap_qos_map_set);
9324 }
9325
9326 val = get_param(cmd, "BSS_LOAD");
9327 if (val) {
9328 dut->ap_bss_load = atoi(val);
9329 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
9330 dut->ap_bss_load);
9331 }
9332
Jouni Malinen54a89b02018-05-01 00:16:26 +03009333 val = get_param(cmd, "Venue_URL");
9334 if (val)
9335 dut->ap_venue_url = atoi(val);
9336
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03009337 val = get_param(cmd, "Advice_of_Charge");
9338 if (val)
9339 dut->ap_advice_of_charge = atoi(val);
9340
Jouni Malinenac104532018-05-01 00:27:37 +03009341 val = get_param(cmd, "Operator_Icon_Metadata");
9342 if (val)
9343 dut->ap_oper_icon_metadata = atoi(val);
9344
Jouni Malinenac367142018-05-01 00:32:24 +03009345 val = get_param(cmd, "TnC_File_Name");
9346 if (val)
9347 dut->ap_tnc_file_name = atoi(val);
9348
9349 val = get_param(cmd, "TnC_File_Time_Stamp");
9350 if (val)
9351 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
9352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009353 return 1;
9354}
9355
9356
9357void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
9358{
9359 char buf[100];
9360
9361 if (!file_exists("nfc-status"))
9362 return;
9363
9364 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
9365 run_system(dut, buf);
9366}
9367
9368
9369static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
9370 const char *info)
9371{
9372 int res;
9373
9374 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
9375 printf("%s\n\n", info);
9376
9377 nfc_status(dut, "START", info);
9378 res = run_system(dut, cmd);
9379 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
9380 if (res) {
9381 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
9382 cmd, res);
9383 return res;
9384 }
9385
9386 return 0;
9387}
9388
9389
9390static int ap_nfc_write_config_token(struct sigma_dut *dut,
9391 struct sigma_conn *conn,
9392 struct sigma_cmd *cmd)
9393{
9394 int res;
9395 char buf[300];
9396
9397 run_system(dut, "killall wps-ap-nfc.py");
9398 unlink("nfc-success");
9399 snprintf(buf, sizeof(buf),
9400 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
9401 dut->summary_log ? "--summary " : "",
9402 dut->summary_log ? dut->summary_log : "");
9403 res = run_nfc_command(dut, buf,
9404 "Touch NFC Tag to write WPS configuration token");
9405 if (res || !file_exists("nfc-success")) {
9406 send_resp(dut, conn, SIGMA_ERROR,
9407 "ErrorCode,Failed to write tag");
9408 return 0;
9409 }
9410
9411 return 1;
9412}
9413
9414
9415static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
9416 struct sigma_conn *conn,
9417 struct sigma_cmd *cmd)
9418{
9419 int res;
9420 char buf[300];
9421
9422 run_system(dut, "killall wps-ap-nfc.py");
9423
9424 unlink("nfc-success");
9425 snprintf(buf, sizeof(buf),
9426 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9427 dut->summary_log ? "--summary " : "",
9428 dut->summary_log ? dut->summary_log : "");
9429 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
9430 if (res || !file_exists("nfc-success")) {
9431 send_resp(dut, conn, SIGMA_ERROR,
9432 "ErrorCode,Failed to read tag");
9433 return 0;
9434 }
9435
9436 return 1;
9437}
9438
9439
9440static int ap_nfc_write_password_token(struct sigma_dut *dut,
9441 struct sigma_conn *conn,
9442 struct sigma_cmd *cmd)
9443{
9444 int res;
9445 char buf[300];
9446
9447 run_system(dut, "killall wps-ap-nfc.py");
9448 unlink("nfc-success");
9449 snprintf(buf, sizeof(buf),
9450 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
9451 dut->summary_log ? "--summary " : "",
9452 dut->summary_log ? dut->summary_log : "");
9453 res = run_nfc_command(dut, buf,
9454 "Touch NFC Tag to write WPS password token");
9455 if (res || !file_exists("nfc-success")) {
9456 send_resp(dut, conn, SIGMA_ERROR,
9457 "ErrorCode,Failed to write tag");
9458 return 0;
9459 }
9460
9461 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
9462 send_resp(dut, conn, SIGMA_ERROR,
9463 "ErrorCode,Failed to enable NFC password token");
9464 return 0;
9465 }
9466
9467 return 1;
9468}
9469
9470
9471static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
9472 struct sigma_conn *conn,
9473 struct sigma_cmd *cmd)
9474{
9475 int res;
9476 char buf[300];
9477
9478 run_system(dut, "killall wps-ap-nfc.py");
9479 unlink("nfc-success");
9480 snprintf(buf, sizeof(buf),
9481 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9482 dut->summary_log ? "--summary " : "",
9483 dut->summary_log ? dut->summary_log : "");
9484 res = run_nfc_command(dut, buf,
9485 "Touch NFC Device to respond to WPS connection handover");
9486 if (res) {
9487 send_resp(dut, conn, SIGMA_ERROR,
9488 "ErrorCode,Failed to enable NFC for connection "
9489 "handover");
9490 return 0;
9491 }
9492 if (!file_exists("nfc-success")) {
9493 send_resp(dut, conn, SIGMA_ERROR,
9494 "ErrorCode,Failed to complete NFC connection handover");
9495 return 0;
9496 }
9497
9498 return 1;
9499}
9500
9501
9502static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
9503 struct sigma_cmd *cmd)
9504{
9505 /* const char *name = get_param(cmd, "Name"); */
9506 /* const char *intf = get_param(cmd, "Interface"); */
9507 const char *oper = get_param(cmd, "Operation");
9508
9509 if (oper == NULL)
9510 return -1;
9511
9512 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
9513 return ap_nfc_write_config_token(dut, conn, cmd);
9514 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
9515 return ap_nfc_write_password_token(dut, conn, cmd);
9516 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
9517 return ap_nfc_wps_read_passwd(dut, conn, cmd);
9518 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
9519 return ap_nfc_wps_connection_handover(dut, conn, cmd);
9520
9521 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
9522 return 0;
9523}
9524
9525
9526static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
9527 struct sigma_cmd *cmd)
9528{
9529 char *pin = "12345670"; /* TODO: use random PIN */
9530 char resp[100];
9531
9532 snprintf(resp, sizeof(resp), "PIN,%s", pin);
9533 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9534
9535 return 0;
9536}
9537
9538
9539static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
9540 const char *val)
9541{
9542 char *token, *result;
9543 int nss = 0, chwidth = 0;
9544 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309545 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009546
9547 /*
9548 * The following commands should be invoked to generate
9549 * VHT op mode notification
9550 */
9551
9552 /* Extract the NSS info */
9553 token = strdup(val);
9554 if (!token)
9555 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309556 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009557 if (result) {
9558 int count = atoi(result);
9559
9560 /* We do not support NSS > 3 */
9561 if (count < 0 || count > 3) {
9562 free(token);
9563 return -1;
9564 }
9565
9566 /* Convert nss to chainmask */
9567 while (count--)
9568 nss = (nss << 1) | 1;
9569
9570 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
9571 ifname, nss);
9572 if (system(buf) != 0) {
9573 sigma_dut_print(dut, DUT_MSG_ERROR,
9574 "iwpriv wifi1 rxchainmask failed!");
9575 }
9576 }
9577
9578 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309579 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009580 if (result) {
9581 switch (atoi(result)) {
9582 case 20:
9583 chwidth = 0;
9584 break;
9585 case 40:
9586 chwidth = 1;
9587 break;
9588 case 80:
9589 chwidth = 2;
9590 break;
9591 case 160:
9592 chwidth = 3;
9593 break;
9594 default:
9595 chwidth = 2;
9596 break;
9597 }
9598 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9599 ifname, chwidth);
9600 if (system(buf) != 0) {
9601 sigma_dut_print(dut, DUT_MSG_ERROR,
9602 "iwpriv chwidth failed!");
9603 }
9604 }
9605
9606 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03009607 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009608 if (system(buf) != 0) {
9609 sigma_dut_print(dut, DUT_MSG_ERROR,
9610 "iwpriv opmode_notify failed!");
9611 }
9612 free(token);
9613
9614 return 0;
9615}
9616
9617
9618static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
9619 const char *val)
9620{
9621 /* String (nss_operating_mode; mcs_operating_mode) */
9622 int nss, mcs;
9623 char *token, *result;
9624 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309625 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009626
9627 token = strdup(val);
9628 if (!token)
9629 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309630 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309631 if (!result) {
9632 sigma_dut_print(dut, DUT_MSG_ERROR,
9633 "VHT NSS not specified");
9634 goto end;
9635 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009636 if (strcasecmp(result, "def") != 0) {
9637 nss = atoi(result);
9638
9639 if (nss == 4)
9640 ath_disable_txbf(dut, ifname);
9641
9642 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
9643 if (system(buf) != 0) {
9644 sigma_dut_print(dut, DUT_MSG_ERROR,
9645 "iwpriv nss failed");
9646 }
9647 } else {
9648 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
9649 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
9650 if (system(buf) != 0) {
9651 sigma_dut_print(dut, DUT_MSG_ERROR,
9652 "iwpriv nss failed");
9653 }
9654 }
9655 }
9656
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309657 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309658 if (!result) {
9659 sigma_dut_print(dut, DUT_MSG_ERROR,
9660 "VHT MCS not specified");
9661 goto end;
9662 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009663 if (strcasecmp(result, "def") == 0) {
9664 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
9665 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
9666 ifname);
9667 if (system(buf) != 0) {
9668 sigma_dut_print(dut, DUT_MSG_ERROR,
9669 "iwpriv vhtmcs failed");
9670 }
9671 } else {
9672 snprintf(buf, sizeof(buf),
9673 "iwpriv %s set11NRates 0", ifname);
9674 if (system(buf) != 0) {
9675 sigma_dut_print(dut, DUT_MSG_ERROR,
9676 "iwpriv set11NRates failed");
9677 }
9678 }
9679 } else {
9680 mcs = atoi(result);
9681 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
9682 if (system(buf) != 0) {
9683 sigma_dut_print(dut, DUT_MSG_ERROR,
9684 "iwpriv vhtmcs failed");
9685 }
9686 }
9687
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309688end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009689 free(token);
9690 return 0;
9691}
9692
9693
9694static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
9695 const char *val)
9696{
9697 char *token, *result;
9698 int channel = 36;
9699 int chwidth = 80;
9700 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309701 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009702
9703 /* Extract the channel info */
9704 token = strdup(val);
9705 if (!token)
9706 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309707 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009708 if (result)
9709 channel = atoi(result);
9710
9711 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309712 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009713 if (result)
9714 chwidth = atoi(result);
9715
9716 /* Issue the channel switch command */
9717 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
9718 ifname, channel, chwidth);
9719 if (system(buf) != 0) {
9720 sigma_dut_print(dut, DUT_MSG_ERROR,
9721 "iwpriv doth_ch_chwidth failed!");
9722 }
9723
9724 free(token);
9725 return 0;
9726}
9727
9728
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009729static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
9730 const char *val)
9731{
9732 char buf[80];
9733 unsigned char mac_addr[6];
9734
9735 if (parse_mac_address(dut, val, mac_addr) < 0)
9736 return -1;
9737
9738 snprintf(buf, sizeof(buf),
9739 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
9740 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
9741 run_system(dut, buf);
9742
9743 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
9744 ifname, mac_addr[4], mac_addr[5]);
9745 run_system(dut, buf);
9746
9747 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
9748 run_system(dut, buf);
9749
9750 return 0;
9751}
9752
9753
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009754void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08009755{
9756 char buf[60];
9757
9758 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
9759 if (system(buf) != 0) {
9760 sigma_dut_print(dut, DUT_MSG_ERROR,
9761 "disabling novap reset failed");
9762 }
9763}
9764
9765
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009766struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
9767 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009768{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009769 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009770
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009771 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
9772 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
9773 ETH_ALEN) == 0)
9774 return &dut->mbo_pref_aps[i];
9775 }
9776 return NULL;
9777}
9778
9779
9780static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
9781 int ap_ne_class, int ap_ne_op_ch,
9782 int ap_ne_pref)
9783{
9784 struct mbo_pref_ap *entry;
9785 uint8_t self_mac[ETH_ALEN];
9786 char ifname[50];
9787
9788 get_if_name(dut, ifname, sizeof(ifname), 1);
9789 get_hwaddr(ifname, self_mac);
9790
9791 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
9792 entry = &dut->mbo_self_ap_tuple;
9793 else
9794 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
9795
9796 if (!entry) {
9797 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
9798 sigma_dut_print(dut, DUT_MSG_ERROR,
9799 "Nebor AP List is full. Not adding");
9800 return;
9801 }
9802 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
9803 dut->mbo_pref_ap_cnt++;
9804 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
9805 entry->ap_ne_class = -1;
9806 entry->ap_ne_op_ch = -1;
9807 entry->ap_ne_pref = -1;
9808 }
9809 if (ap_ne_class != -1)
9810 entry->ap_ne_class = ap_ne_class;
9811 if (ap_ne_op_ch != -1)
9812 entry->ap_ne_op_ch = ap_ne_op_ch;
9813 if (ap_ne_pref != -1)
9814 entry->ap_ne_pref = ap_ne_pref;
9815}
9816
9817
9818static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
9819 struct sigma_cmd *cmd)
9820{
9821 unsigned char mac_addr[ETH_ALEN];
9822 const char *val;
9823 /*
9824 * -1 is invalid value for the following
9825 * to differentiate between unset and set values
9826 * -1 => implies not set by CAPI
9827 */
9828 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
9829 int list_offset = dut->mbo_pref_ap_cnt;
9830
9831 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
9832 sigma_dut_print(dut, DUT_MSG_ERROR,
9833 "AP Pref Entry list is full");
9834 return -1;
9835 }
9836
9837 val = get_param(cmd, "Nebor_Op_Class");
9838 if (val)
9839 ap_ne_class = atoi(val);
9840
9841 val = get_param(cmd, "Nebor_Op_Ch");
9842 if (val)
9843 ap_ne_op_ch = atoi(val);
9844
9845 val = get_param(cmd, "Nebor_Pref");
9846 if (val)
9847 ap_ne_pref = atoi(val);
9848
9849 val = get_param(cmd, "Nebor_BSSID");
9850 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009851 return -1;
9852
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009853 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
9854 ap_ne_pref);
9855 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009856 return 0;
9857}
9858
9859
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009860static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
9861 struct sigma_cmd *cmd)
9862{
9863 const char *val;
9864 char *ifname;
9865
9866 ifname = get_main_ifname();
9867
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08009868 /* Disable vap reset between the commands */
9869 novap_reset(dut, ifname);
9870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009871 val = get_param(cmd, "Opt_md_notif_ie");
9872 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
9873 return -1;
9874
9875 /* TODO: Optional arguments */
9876
9877 val = get_param(cmd, "nss_mcs_opt");
9878 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
9879 return -1;
9880
9881 val = get_param(cmd, "chnum_band");
9882 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
9883 return -1;
9884
9885 val = get_param(cmd, "RTS_FORCE");
9886 if (val)
9887 ath_config_rts_force(dut, ifname, val);
9888
9889 val = get_param(cmd, "DYN_BW_SGNL");
9890 if (val)
9891 ath_config_dyn_bw_sig(dut, ifname, val);
9892
9893 val = get_param(cmd, "CTS_WIDTH");
9894 if (val)
9895 ath_set_cts_width(dut, ifname, val);
9896
9897 val = get_param(cmd, "Ndpa_stainfo_mac");
9898 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
9899 return -1;
9900
9901 val = get_param(cmd, "txBandwidth");
9902 if (val && ath_set_width(dut, conn, ifname, val) < 0)
9903 return -1;
9904
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009905 val = get_param(cmd, "Assoc_Disallow");
9906 if (val)
9907 ath_set_assoc_disallow(dut, ifname, val);
9908
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009909
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009910 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009911 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009912 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009913 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009914 dut->ap_disassoc_timer = 1000;
9915 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009916
9917 val = get_param(cmd, "BTMReq_Term_Bit");
9918 if (val)
9919 dut->ap_btmreq_term_bit = atoi(val);
9920
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -07009921 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009922 if (val) {
9923 dut->ap_assoc_delay = 1;
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -07009924 run_system_wrapper(dut, "iwpriv %s mbo_asoc_ret %s",
9925 ifname, val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009926 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -07009927
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009928 val = get_param(cmd, "Disassoc_Timer");
9929 if (val)
9930 dut->ap_disassoc_timer = atoi(val);
9931
9932 val = get_param(cmd, "BSS_Term_Duration");
9933 if (val)
9934 dut->ap_btmreq_bss_term_dur = atoi(val);
9935
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009936 val = get_param(cmd, "BSS_Term_TSF");
9937 if (val)
9938 dut->ap_btmreq_bss_term_tsf = atoi(val);
9939
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08009940 val = get_param(cmd, "TxPower");
9941 if (val)
9942 ath_set_txpower(dut, ifname, val);
9943
9944 val = get_param(cmd, "DownlinkAvailCap");
9945 if (val)
9946 dut->ap_dl_availcap = atoi(val);
9947
9948 val = get_param(cmd, "UplinkAvailCap");
9949 if (val) {
9950 dut->ap_ul_availcap = atoi(val);
9951 run_system_wrapper(dut, "iwpriv %s oce_wan_mtr %d %d", ifname,
9952 dut->ap_dl_availcap, dut->ap_ul_availcap);
9953 }
9954
9955 val = get_param(cmd, "RSSIthreshold");
9956 if (val) {
9957 int rssithreshold;
9958
9959 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
9960 rssithreshold = atoi(val);
9961 run_system_wrapper(dut, "iwpriv %s oce_asoc_rssi %d", ifname,
9962 rssithreshold);
9963 }
9964
9965 val = get_param(cmd, "RetryDelay");
9966 if (val) {
9967 int retrydelay;
9968
9969 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
9970 retrydelay = atoi(val);
9971 run_system_wrapper(dut, "iwpriv %s oce_asoc_dly %d", ifname,
9972 retrydelay);
9973 }
9974
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009975 return 1;
9976}
9977
9978
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05309979static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
9980 const char *val)
9981{
9982 char *token, *result;
9983 int channel = 36;
9984 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309985 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05309986
9987 /* Extract the channel info */
9988 token = strdup(val);
9989 if (!token)
9990 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309991 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05309992 if (result)
9993 channel = atoi(result);
9994
9995 /* Issue the channel switch command */
9996 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
9997 ifname, channel);
9998 if (system(buf) != 0) {
9999 sigma_dut_print(dut, DUT_MSG_ERROR,
10000 "iwpriv setChanChange failed!");
10001 }
10002
10003 free(token);
10004 return 0;
10005}
10006
10007
10008static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10009 struct sigma_cmd *cmd)
10010{
10011 const char *val;
10012 char *ifname;
10013
10014 ifname = get_main_ifname();
10015
10016 val = get_param(cmd, "chnum_band");
10017 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
10018 return -1;
10019
10020 return 1;
10021}
10022
10023
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010024static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10025 const char *val)
10026{
10027 char *token, *result;
10028 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
10029 channel_freq;
10030 char buf[100];
10031 char *saveptr;
10032
10033 /* Extract the channel info */
10034 token = strdup(val);
10035 if (!token)
10036 return -1;
10037 result = strtok_r(token, ";", &saveptr);
10038 if (result)
10039 channel = atoi(result);
10040
10041 /* Extract the channel width info */
10042 result = strtok_r(NULL, ";", &saveptr);
10043 if (result)
10044 chwidth = atoi(result);
10045
10046 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
10047 if (center_freq_idx < 0) {
10048 free(token);
10049 return -1;
10050 }
10051
10052 center_freq = get_5g_channel_freq(center_freq_idx);
10053 channel_freq = get_5g_channel_freq(channel);
10054
10055 /* Issue the channel switch command */
10056 snprintf(buf, sizeof(buf),
10057 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
10058 ifname, channel_freq, center_freq, chwidth);
10059 if (run_hostapd_cli(dut,buf) != 0) {
10060 sigma_dut_print(dut, DUT_MSG_ERROR,
10061 "hostapd_cli chan_switch failed");
10062 }
10063
10064 free(token);
10065 return 0;
10066}
10067
10068
10069static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
10070 struct sigma_conn *conn,
10071 struct sigma_cmd *cmd)
10072{
10073 const char *val;
10074 char *ifname;
10075
10076 ifname = get_main_ifname();
10077 val = get_param(cmd, "chnum_band");
10078 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
10079 return -1;
10080
10081 return 1;
10082}
10083
10084
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010085static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10086 struct sigma_cmd *cmd)
10087{
10088 /* const char *name = get_param(cmd, "NAME"); */
10089 /* const char *type = get_param(cmd, "Type"); */
10090
10091 switch (get_driver_type()) {
10092 case DRIVER_ATHEROS:
10093 return ath_ap_set_rfeature(dut, conn, cmd);
10094 case DRIVER_OPENWRT:
10095 switch (get_openwrt_driver_type()) {
10096 case OPENWRT_DRIVER_ATHEROS:
10097 return ath_ap_set_rfeature(dut, conn, cmd);
10098 default:
10099 send_resp(dut, conn, SIGMA_ERROR,
10100 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
10101 return 0;
10102 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053010103 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010104 case DRIVER_WCN:
10105 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010106 case DRIVER_MAC80211:
10107 return mac80211_ap_set_rfeature(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010108 default:
10109 send_resp(dut, conn, SIGMA_ERROR,
10110 "errorCode,Unsupported ap_set_rfeature with the current driver");
10111 return 0;
10112 }
10113}
10114
10115
10116static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
10117 struct sigma_cmd *cmd)
10118{
10119 /* const char *name = get_param(cmd, "NAME"); */
10120 return 1;
10121}
10122
10123
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010124static int cmd_ap_preset_testparameters(struct sigma_dut *dut,
10125 struct sigma_conn *conn,
10126 struct sigma_cmd *cmd)
10127{
10128 const char *val;
10129
10130 val = get_param(cmd, "Oper_Chn");
10131 if (val) {
10132 dut->ap_oper_chn = 1;
10133 dut->ap_channel = atoi(val);
10134 }
10135
10136 return 1;
10137}
10138
10139
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010140void ap_register_cmds(void)
10141{
10142 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
10143 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
10144 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
10145 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
10146 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
10147 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053010148 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010149 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
10150 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
10151 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
10152 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
10153 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
10154 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
10155 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
10156 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
10157 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
10158 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
10159 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
10160 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
10161 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
10162 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
10163 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
10164 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
10165 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010166 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
10167 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168}