blob: ea4e165c4a0b520ce13d4379f566140a6bddf263 [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 Malinen13701222019-02-19 12:10:53 +02005 * Copyright (c) 2018-2019, 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__ */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +020026#include "wpa_ctrl.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020027#include "wpa_helpers.h"
28#ifdef ANDROID
29#include <hardware_legacy/wifi.h>
Veerendranath Jakkamd7e00082018-04-25 19:46:01 +053030#include <grp.h>
31#include <pwd.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020032#endif /* ANDROID */
33
34/* Temporary files for ap_send_addba_req */
35#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
36#define VI_QOS_FILE "/tmp/vi-qos.txt"
37#define VI_QOS_REFFILE "/etc/vi-qos.txt"
38
39/* Configuration file name on Android */
40#ifndef ANDROID_CONFIG_FILE
41#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
42#endif /* ANDROID_CONFIG_FILE */
43/* Maximum length of the line in the configuration file */
44#define MAX_CONF_LINE_LEN (156)
45
Jouni Malinend6bf1b42017-06-23 17:51:01 +030046#ifndef SIGMA_DUT_HOSTAPD_PID_FILE
47#define SIGMA_DUT_HOSTAPD_PID_FILE "/tmp/sigma_dut-ap-hostapd.pid"
48#endif /* SIGMA_DUT_HOSTAPD_PID_FILE */
49
Jouni Malinencd4e3c32015-10-29 12:39:56 +020050/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
51#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
52#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\""
53#define ANQP_IP_ADDR_TYPE_1 "060101000c"
54#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
55#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
56#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
57#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"
58#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
59
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030060#define ADV_OF_CHARGE_1 \
Jouni Malinen3001b432018-05-03 18:18:15 +030061"bc01000000d200454e475553443c3f786d6c2076657273696f6e3d22312e30222065" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030062"6e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f77" \
63"77772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f" \
64"74302f76312e302f616f637069223e3c4465736372697074696f6e3e57692d46692061636365" \
65"737320666f72203120686f75722c207768696c6520796f752077616974206174207468652067" \
Jouni Malinen3001b432018-05-03 18:18:15 +030066"6174652c2024302e39393c2f4465736372697074696f6e3e3c2f506c616e3ee3004652414341" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030067"443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f" \
68"3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f72672f737065" \
69"63696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f637069223e3c" \
Jouni Malinen3001b432018-05-03 18:18:15 +030070"4465736372697074696f6e3e416363c3a8732057692d46692070656e64616e74203120686575" \
71"72652c2070656e64616e742071756520766f757320617474656e64657a20c3a0206c6120706f" \
72"7274652c20302c393920243c2f4465736372697074696f6e3e3c2f506c616e3ea101010000c7" \
73"00454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d2255" \
74"54462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f" \
75"72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f" \
76"637069223e3c4465736372697074696f6e3e446f776e6c6f616420766964656f7320666f7220" \
77"796f757220666c696768742c2024322e393920666f7220313047423c2f446573637269707469" \
78"6f6e3e3c2f506c616e3ed3004652414341443c3f786d6c2076657273696f6e3d22312e302220" \
79"656e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f" \
80"7777772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f743264" \
81"6f74302f76312e302f616f637069223e3c4465736372697074696f6e3e54c3a96cc3a9636861" \
82"7267657a2064657320766964c3a96f7320706f757220766f74726520766f6c2c20322c393920" \
83"2420706f757220313020476f3c2f4465736372697074696f6e3e3c2f506c616e3ee40003002b" \
84"736572766963652d70726f76696465722e636f6d3b66656465726174696f6e2e6578616d706c" \
85"652e636f6db400454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64" \
86"696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77" \
87"692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76" \
88"312e302f616f637069223e3c4465736372697074696f6e3e46726565207769746820796f7572" \
89"20737562736372697074696f6e213c2f4465736372697074696f6e3e3c2f506c616e3e"
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030090
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +020091/*
92 * MTU for Ethernet need to take into account 8-byte SNAP header
93 * to be added when encapsulating Ethernet frame into 802.11.
94 */
95#ifndef IEEE80211_MAX_DATA_LEN_DMG
96#define IEEE80211_MAX_DATA_LEN_DMG 7920
97#endif /* IEEE80211_MAX_DATA_LEN_DMG */
98#ifndef IEEE80211_SNAP_LEN_DMG
99#define IEEE80211_SNAP_LEN_DMG 8
100#endif /* IEEE80211_SNAP_LEN_DMG */
101
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200102extern char *sigma_main_ifname;
103extern char *sigma_wpas_ctrl;
104extern char *sigma_hapd_ctrl;
105extern char *ap_inet_addr;
106extern char *ap_inet_mask;
107extern char *sigma_radio_ifname[];
108
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200109static int ath_ap_start_hostapd(struct sigma_dut *dut);
110static void ath_ap_set_params(struct sigma_dut *dut);
111static int kill_process(struct sigma_dut *dut, char *proc_name,
112 unsigned char is_proc_instance_one, int sig);
113
114
Jouni Malinen6be21c82018-08-01 18:47:24 +0300115static int ap_ft_enabled(struct sigma_dut *dut)
116{
117 return dut->ap_ft_oa == 1 ||
118 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
119 dut->ap_key_mgmt == AP_WPA2_FT_PSK ||
120 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP;
121}
122
123
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200124static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
125 struct sigma_cmd *cmd)
126{
127 /* const char *name = get_param(cmd, "NAME"); */
128 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
129 return 0;
130}
131
132
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300133static void kill_hostapd_process_pid(struct sigma_dut *dut)
134{
135 FILE *f;
136 int pid, res;
137 char path[100];
138 int count;
139
140 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
141 if (!f)
142 return;
143 res = fscanf(f, "%d", &pid);
144 fclose(f);
145 if (res != 1)
146 return;
147 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
148 kill(pid, SIGTERM);
149 snprintf(path, sizeof(path), "/proc/%d", pid);
150 for (count = 0; count < 20 && file_exists(path); count++)
151 usleep(100000);
152}
153
154
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300155int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200156{
157#ifndef __QNXNTO__
158 struct ifreq ifr;
159 int s;
160
161 s = socket(AF_INET, SOCK_DGRAM, 0);
162 if (s < 0)
163 return -1;
164 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700165 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200166 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
167 perror("ioctl");
168 close(s);
169 return -1;
170 }
171 close(s);
172 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
173#else /* __QNXNTO__ */
174 struct ifaddrs *ifaddrshead = NULL;
175 int found = 0;
176 struct ifaddrs *temp_ifap = NULL;
177 struct sockaddr_dl *sdl = NULL;
178
179 if (getifaddrs(&ifaddrshead) != 0) {
180 perror("getifaddrs failed");
181 return -1;
182 }
183
184 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
185 ifaddrshead = ifaddrshead->ifa_next) {
186 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
187 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
188 found = 1;
189 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
190 if (sdl)
191 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
192 }
193 }
194
195 if (temp_ifap)
196 freeifaddrs(temp_ifap);
197
198 if (!found) {
199 perror("Failed to get the interface");
200 return -1;
201 }
202#endif /* __QNXNTO__ */
203 return 0;
204}
205
206
207static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
208 const char *val)
209{
210 char buf[60];
211
212 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
213 ifname, atoi(val));
214 if (system(buf) != 0) {
215 sigma_dut_print(dut, DUT_MSG_ERROR,
216 "wifitool ap_group_id failed");
217 }
218}
219
220
221void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
222 const char *val)
223{
224 char buf[60];
225
226 /* TODO: Enable support for other values */
227 if (strcasecmp(val, "40") == 0) {
228 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
229 ifname);
230 if (system(buf) != 0) {
231 sigma_dut_print(dut, DUT_MSG_ERROR,
232 "wifitool cts_width failed");
233 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800234 snprintf(buf, sizeof(buf),
235 "athdiag --set --address=0x10024 --val=0xd90b8a14");
236 if (system(buf) != 0) {
237 sigma_dut_print(dut, DUT_MSG_ERROR,
238 "disabling phy restart failed");
239 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200240 } else {
241 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
242 }
243}
244
245
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800246void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
247 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200248{
249 char buf[60];
250
251 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200252 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200253 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
254 if (system(buf) != 0) {
255 sigma_dut_print(dut, DUT_MSG_ERROR,
256 "iwpriv cwmenable 1 failed");
257 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800258 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
259 ifname);
260 if (system(buf) != 0) {
261 sigma_dut_print(dut, DUT_MSG_ERROR,
262 "disabling RTS from rate control logic failed");
263 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200264 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200265 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200266 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
267 if (system(buf) != 0) {
268 sigma_dut_print(dut, DUT_MSG_ERROR,
269 "iwpriv cwmenable 0 failed");
270 }
271 } else {
272 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
273 }
274}
275
276
277static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
278 const char *val)
279{
280 char buf[60];
281
282 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200283 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200284 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
285 if (system(buf) != 0) {
286 sigma_dut_print(dut, DUT_MSG_ERROR,
287 "iwconfig rts 64 failed");
288 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800289 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
290 ifname);
291 if (system(buf) != 0) {
292 sigma_dut_print(dut, DUT_MSG_ERROR,
293 "wifitool beeliner_fw_test 100 1 failed");
294 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200295 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200296 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200297 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
298 if (system(buf) != 0) {
299 sigma_dut_print(dut, DUT_MSG_ERROR,
300 "iwpriv rts 2347 failed");
301 }
302 } else {
303 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
304 }
305}
306
307
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800308static void ath_radio(struct sigma_dut *dut, const char *val)
309{
310 if (strcasecmp(val, "on") == 0) {
311 if (dut->ap_interface_5g == 1) {
312 run_system(dut, "uci set wireless.wifi0.disabled=0");
313 } else if (dut->ap_interface_2g == 1) {
314 run_system(dut, "uci set wireless.wifi1.disabled=0");
315 } else {
316 run_system(dut, "uci set wireless.wifi0.disabled=0");
317 run_system(dut, "uci set wireless.wifi1.disabled=0");
318 }
319 run_system(dut, "uci commit");
320 run_system(dut, "wifi down");
321 run_system(dut, "wifi up");
322 } else if (strcasecmp(val, "off") == 0) {
323 if (dut->ap_interface_5g == 1) {
324 run_system(dut, "uci set wireless.wifi0.disabled=1");
325 } else if (dut->ap_interface_2g == 1) {
326 run_system(dut, "uci set wireless.wifi1.disabled=1");
327 } else {
328 run_system(dut, "uci set wireless.wifi0.disabled=1");
329 run_system(dut, "uci set wireless.wifi1.disabled=1");
330 }
331 run_system(dut, "uci commit");
332 run_system(dut, "wifi down");
333 run_system(dut, "wifi up");
334 }
335}
336
337
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800338static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
339 const char *val)
340{
341 char buf[60];
342
343 if (strcasecmp(val, "disable") == 0) {
344 snprintf(buf, sizeof(buf), "iwpriv %s stealthdown 1", ifname);
345 if (system(buf) != 0) {
346 sigma_dut_print(dut, DUT_MSG_ERROR,
347 "disable deauthdisassoctx failed");
348 }
349 }
350}
351
352
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800353static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
354 const char *val)
355{
356 char buf[60];
357
358 if (strcasecmp(val, "high") == 0)
359 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
360 else if (strcasecmp(val, "low") == 0)
361 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
362 else
363 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
364
365 if (system(buf) != 0)
366 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
367}
368
369
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200370static enum ap_mode get_mode(const char *str)
371{
372 if (strcasecmp(str, "11a") == 0)
373 return AP_11a;
374 else if (strcasecmp(str, "11g") == 0)
375 return AP_11g;
376 else if (strcasecmp(str, "11b") == 0)
377 return AP_11b;
378 else if (strcasecmp(str, "11na") == 0)
379 return AP_11na;
380 else if (strcasecmp(str, "11ng") == 0)
381 return AP_11ng;
382 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
383 return AP_11ac;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200384 else if (strcasecmp(str, "11ad") == 0)
385 return AP_11ad;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200386 else
387 return AP_inval;
388}
389
390
391static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
392{
393 char command[1000];
394 const char *bin;
395 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700396 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200397
398 if (file_exists("hostapd_cli"))
399 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300400 else if (file_exists("../../hostapd/hostapd_cli"))
401 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200402 else
403 bin = "hostapd_cli";
404
405 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700406 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200407
408 if (sigma_radio_ifname[0] &&
409 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700410 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200411 else if (sigma_radio_ifname[0] &&
412 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700413 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200414 }
415
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700416 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200417 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700418 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200419 else
420 snprintf(command, sizeof(command), "%s %s", bin, buf);
421 return run_system(dut, command);
422}
423
424
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700425static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
426 struct sigma_cmd *cmd)
427{
428 FILE *f;
429 int i;
430
431 f = fopen("/tmp/lci_cfg.txt", "w");
432 if (!f) {
433 sigma_dut_print(dut, DUT_MSG_ERROR,
434 "Failed to open /tmp/lci_cfg.txt");
435 return -1;
436 }
437
438 for (i = 2; i < cmd->count; i++)
439 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
440 fprintf(f, "\n");
441 fclose(f);
442
443 return 0;
444}
445
446
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200447static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
448 struct sigma_cmd *cmd)
449{
450 /* const char *name = get_param(cmd, "NAME"); */
451 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200452 const char *val;
453 unsigned int wlan_tag = 1;
454 char *ifname = get_main_ifname();
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +0200455 char buf[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200456
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200457 /* Allow program to be overridden if specified in the ap_set_wireless
458 * to support some 60 GHz test scripts where the program may be 60 GHz
459 * or WPS. */
460 val = get_param(cmd, "PROGRAM");
461 if (val)
462 dut->program = sigma_program_to_enum(val);
463
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200464 val = get_param(cmd, "WLAN_TAG");
465 if (val) {
466 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700467 if (wlan_tag < 1 || wlan_tag > 3) {
468 /*
469 * The only valid WLAN Tags as of now as per the latest
470 * WFA scripts are 1, 2, and 3.
471 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200472 send_resp(dut, conn, SIGMA_INVALID,
473 "errorCode,Invalid WLAN_TAG");
474 return 0;
475 }
476 }
477
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800478 val = get_param(cmd, "Interface");
479 if (val) {
480 if (strcasecmp(val, "5G") == 0)
481 dut->ap_interface_5g = 1;
482 else
483 dut->ap_interface_2g = 1;
484
485 if (dut->ap_interface_5g && dut->ap_interface_2g)
486 dut->ap_is_dual = 1;
487 }
488
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200489 val = get_param(cmd, "CountryCode");
490 if (val) {
491 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
492 return -1;
493 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
494 "%s", val);
495 }
496
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530497 val = get_param(cmd, "regulatory_mode");
498 if (val) {
499 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
500 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
501 }
502
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200503 val = get_param(cmd, "SSID");
504 if (val) {
505 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
506 return -1;
507
508 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700509 /*
510 * If tag is not specified, it is deemed to be 1.
511 * Hence tag of 1 is a special case and the values
512 * corresponding to wlan-tag=1 are stored separately
513 * from the values corresponding tags 2 and 3.
514 * This approach minimises the changes to existing code
515 * since most of the sigma_dut code does not deal with
516 * WLAN-TAG CAPI variable.
517 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200518 snprintf(dut->ap_ssid,
519 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700520 } else {
521 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
522 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
523 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200524 }
525 }
526
527 val = get_param(cmd, "CHANNEL");
528 if (val) {
529 const char *pos;
530 dut->ap_channel = atoi(val);
531 pos = strchr(val, ';');
532 if (pos) {
533 pos++;
534 dut->ap_channel_1 = atoi(pos);
535 }
536 }
537
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530538 /* Overwrite the AP channel with DFS channel if configured */
539 val = get_param(cmd, "dfs_chan");
540 if (val) {
541 dut->ap_channel = atoi(val);
542 }
543
544 val = get_param(cmd, "dfs_mode");
545 if (val) {
546 if (strcasecmp(val, "Enable") == 0)
547 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
548 else if (strcasecmp(val, "Disable") == 0)
549 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
550 else
551 sigma_dut_print(dut, DUT_MSG_ERROR,
552 "Unsupported dfs_mode value: %s", val);
553 }
554
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200555 val = get_param(cmd, "MODE");
556 if (val) {
557 char *str, *pos;
558
559 str = strdup(val);
560 if (str == NULL)
561 return -1;
562 pos = strchr(str, ';');
563 if (pos)
564 *pos++ = '\0';
565
566 dut->ap_is_dual = 0;
567 dut->ap_mode = get_mode(str);
568 if (dut->ap_mode == AP_inval) {
569 send_resp(dut, conn, SIGMA_INVALID,
570 "errorCode,Unsupported MODE");
571 free(str);
572 return 0;
573 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800574 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200575 dut->ap_chwidth = AP_80;
576
577 if (pos) {
578 dut->ap_mode_1 = get_mode(pos);
579 if (dut->ap_mode_1 == AP_inval) {
580 send_resp(dut, conn, SIGMA_INVALID,
581 "errorCode,Unsupported MODE");
582 free(str);
583 return 0;
584 }
585 if (dut->ap_mode_1 == AP_11ac)
586 dut->ap_chwidth_1 = AP_80;
587 dut->ap_is_dual = 1;
588 }
589
590 free(str);
591 } else if (dut->ap_mode == AP_inval) {
592 if (dut->ap_channel <= 11)
593 dut->ap_mode = AP_11ng;
594 else if (dut->program == PROGRAM_VHT)
595 dut->ap_mode = AP_11ac;
596 else
597 dut->ap_mode = AP_11na;
598 }
599
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200600 /* Override the AP mode in case of 60 GHz */
601 if (dut->program == PROGRAM_60GHZ) {
602 dut->ap_mode = AP_11ad;
603 /* Workaround to force channel 2 if not specified */
604 if (!dut->ap_channel)
605 dut->ap_channel = 2;
606 }
607
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530608 val = get_param(cmd, "WME");
609 if (val) {
610 if (strcasecmp(val, "on") == 0)
611 dut->ap_wme = AP_WME_ON;
612 else if (strcasecmp(val, "off") == 0)
613 dut->ap_wme = AP_WME_OFF;
614 else
615 sigma_dut_print(dut, DUT_MSG_ERROR,
616 "Unsupported WME value: %s", val);
617 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200618
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530619 val = get_param(cmd, "WMMPS");
620 if (val) {
621 if (strcasecmp(val, "on") == 0)
622 dut->ap_wmmps = AP_WMMPS_ON;
623 else if (strcasecmp(val, "off") == 0)
624 dut->ap_wmmps = AP_WMMPS_OFF;
625 else
626 sigma_dut_print(dut, DUT_MSG_ERROR,
627 "Unsupported WMMPS value: %s", val);
628 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200629
630 val = get_param(cmd, "RTS");
631 if (val)
632 dut->ap_rts = atoi(val);
633
634 val = get_param(cmd, "FRGMNT");
635 if (val)
636 dut->ap_frgmnt = atoi(val);
637
638 /* TODO: PWRSAVE */
639
640 val = get_param(cmd, "BCNINT");
641 if (val)
642 dut->ap_bcnint = atoi(val);
643
644 val = get_param(cmd, "RADIO");
645 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530646 enum driver_type drv = get_driver_type();
647
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200648 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800649 if (drv == DRIVER_OPENWRT)
650 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200651 if (drv == DRIVER_ATHEROS)
652 ath_ap_start_hostapd(dut);
653 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
654 return 0;
655 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530656 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800657 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300658 } else if (dut->use_hostapd_pid_file) {
659 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530660 } else if (kill_process(dut, "(hostapd)", 1,
661 SIGTERM) == 0 ||
662 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200663 sigma_dut_print(dut, DUT_MSG_INFO,
664 "Killed hostapd on radio,off");
665 }
666 } else {
667 send_resp(dut, conn, SIGMA_INVALID,
668 "errorCode,Unsupported RADIO value");
669 return 0;
670 }
671 }
672
673 val = get_param(cmd, "P2PMgmtBit");
674 if (val)
675 dut->ap_p2p_mgmt = atoi(val);
676
677 /* TODO: ChannelUsage */
678
679 /* TODO: 40_INTOLERANT */
680
681 val = get_param(cmd, "ADDBA_REJECT");
682 if (val) {
683 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200684 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200685 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200686 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200687 }
688
689 val = get_param(cmd, "AMPDU");
690 if (val) {
691 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200692 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200693 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200694 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200695 }
696
697 val = get_param(cmd, "AMPDU_EXP");
698 if (val)
699 dut->ap_ampdu_exp = atoi(val);
700
701 val = get_param(cmd, "AMSDU");
702 if (val) {
703 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200704 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200705 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200706 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200707 }
708
709 val = get_param(cmd, "NoAck");
710 if (val) {
711 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200712 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200713 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200714 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200715 }
716
717 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200718 /* TODO: MCS_32 */
719
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530720 val = get_param(cmd, "OFFSET");
721 if (val) {
722 if (strcasecmp(val, "Above") == 0)
723 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
724 else if (strcasecmp(val, "Below") == 0)
725 dut->ap_chwidth_offset = SEC_CH_40BELOW;
726 }
727
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200728 val = get_param(cmd, "MCS_FIXEDRATE");
729 if (val) {
730 dut->ap_fixed_rate = 1;
731 dut->ap_mcs = atoi(val);
732 }
733
734 val = get_param(cmd, "SPATIAL_RX_STREAM");
735 if (val) {
736 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
737 dut->ap_rx_streams = 1;
738 if (dut->device_type == AP_testbed)
739 dut->ap_vhtmcs_map = 0xfffc;
740 } else if (strcasecmp(val, "2SS") == 0 ||
741 strcasecmp(val, "2") == 0) {
742 dut->ap_rx_streams = 2;
743 if (dut->device_type == AP_testbed)
744 dut->ap_vhtmcs_map = 0xfff0;
745 } else if (strcasecmp(val, "3SS") == 0 ||
746 strcasecmp(val, "3") == 0) {
747 dut->ap_rx_streams = 3;
748 if (dut->device_type == AP_testbed)
749 dut->ap_vhtmcs_map = 0xffc0;
750 } else if (strcasecmp(val, "4SS") == 0 ||
751 strcasecmp(val, "4") == 0) {
752 dut->ap_rx_streams = 4;
753 }
754 }
755
756 val = get_param(cmd, "SPATIAL_TX_STREAM");
757 if (val) {
758 if (strcasecmp(val, "1SS") == 0 ||
759 strcasecmp(val, "1") == 0) {
760 dut->ap_tx_streams = 1;
761 if (dut->device_type == AP_testbed)
762 dut->ap_vhtmcs_map = 0xfffc;
763 } else if (strcasecmp(val, "2SS") == 0 ||
764 strcasecmp(val, "2") == 0) {
765 dut->ap_tx_streams = 2;
766 if (dut->device_type == AP_testbed)
767 dut->ap_vhtmcs_map = 0xfff0;
768 } else if (strcasecmp(val, "3SS") == 0 ||
769 strcasecmp(val, "3") == 0) {
770 dut->ap_tx_streams = 3;
771 if (dut->device_type == AP_testbed)
772 dut->ap_vhtmcs_map = 0xffc0;
773 } else if (strcasecmp(val, "4SS") == 0 ||
774 strcasecmp(val, "4") == 0) {
775 dut->ap_tx_streams = 4;
776 }
777 }
778
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700779 val = get_param(cmd, "BSS_max_idle");
780 if (val) {
781 if (strncasecmp(val, "Enable", 7) == 0) {
782 dut->wnm_bss_max_feature = VALUE_ENABLED;
783 } else if (strncasecmp(val, "Disable", 8) == 0) {
784 dut->wnm_bss_max_feature = VALUE_DISABLED;
785 } else {
786 send_resp(dut, conn, SIGMA_ERROR,
787 "errorCode,Invalid value for BSS_max_Feature");
788 return 0;
789 }
790 }
791
792 val = get_param(cmd, "BSS_Idle_Protection_options");
793 if (val) {
794 int protection = (int) strtol(val, (char **) NULL, 10);
795
796 if (protection != 1 && protection != 0) {
797 send_resp(dut, conn, SIGMA_ERROR,
798 "errorCode,Invalid value for BSS_Idle_Protection_options");
799 return 0;
800 }
801 dut->wnm_bss_max_protection = protection ?
802 VALUE_ENABLED : VALUE_DISABLED;
803 }
804
805 val = get_param(cmd, "BSS_max_Idle_period");
806 if (val) {
Jouni Malinen544edf02019-02-25 19:02:33 +0200807 long int idle_time = strtol(val, (char **) NULL, 10);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700808
809 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
810 send_resp(dut, conn, SIGMA_ERROR,
811 "errorCode,Invalid value for BSS_max_Idle_period");
812 return 0;
813 }
Jouni Malinen544edf02019-02-25 19:02:33 +0200814 dut->wnm_bss_max_idle_time = (int) idle_time;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700815 }
816
817 val = get_param(cmd, "PROXY_ARP");
818 if (val)
819 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
820
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200821 val = get_param(cmd, "nss_mcs_cap");
822 if (val) {
823 int nss, mcs;
824 char token[20];
825 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530826 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200827
828 if (strlen(val) >= sizeof(token))
829 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300830 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530831 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530832 if (!result) {
833 sigma_dut_print(dut, DUT_MSG_ERROR,
834 "VHT NSS not specified");
835 return 0;
836 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200837 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530838 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200839 if (result == NULL) {
840 sigma_dut_print(dut, DUT_MSG_ERROR,
841 "VHTMCS NOT SPECIFIED!");
842 return 0;
843 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530844 result = strtok_r(result, "-", &saveptr);
845 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530846 if (!result) {
847 sigma_dut_print(dut, DUT_MSG_ERROR,
848 "VHT MCS not specified");
849 return 0;
850 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200851 mcs = atoi(result);
852 switch (nss) {
853 case 1:
854 switch (mcs) {
855 case 7:
856 dut->ap_vhtmcs_map = 0xfffc;
857 break;
858 case 8:
859 dut->ap_vhtmcs_map = 0xfffd;
860 break;
861 case 9:
862 dut->ap_vhtmcs_map = 0xfffe;
863 break;
864 default:
865 dut->ap_vhtmcs_map = 0xfffe;
866 break;
867 }
868 break;
869 case 2:
870 switch (mcs) {
871 case 7:
872 dut->ap_vhtmcs_map = 0xfff0;
873 break;
874 case 8:
875 dut->ap_vhtmcs_map = 0xfff5;
876 break;
877 case 9:
878 dut->ap_vhtmcs_map = 0xfffa;
879 break;
880 default:
881 dut->ap_vhtmcs_map = 0xfffa;
882 break;
883 }
884 break;
885 case 3:
886 switch (mcs) {
887 case 7:
888 dut->ap_vhtmcs_map = 0xffc0;
889 break;
890 case 8:
891 dut->ap_vhtmcs_map = 0xffd5;
892 break;
893 case 9:
894 dut->ap_vhtmcs_map = 0xffea;
895 break;
896 default:
897 dut->ap_vhtmcs_map = 0xffea;
898 break;
899 }
900 break;
901 default:
902 dut->ap_vhtmcs_map = 0xffea;
903 break;
904 }
905 }
906
907 /* TODO: MPDU_MIN_START_SPACING */
908 /* TODO: RIFS_TEST */
909 /* TODO: SGI20 */
910
911 val = get_param(cmd, "STBC_TX");
912 if (val)
913 dut->ap_tx_stbc = atoi(val);
914
915 val = get_param(cmd, "WIDTH");
916 if (val) {
917 if (strcasecmp(val, "20") == 0)
918 dut->ap_chwidth = AP_20;
919 else if (strcasecmp(val, "40") == 0)
920 dut->ap_chwidth = AP_40;
921 else if (strcasecmp(val, "80") == 0)
922 dut->ap_chwidth = AP_80;
923 else if (strcasecmp(val, "160") == 0)
924 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800925 else if (strcasecmp(val, "80plus80") == 0) {
926 dut->ap_80plus80 = 1;
927 dut->ap_chwidth = AP_80_80;
928 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200929 dut->ap_chwidth = AP_AUTO;
930 else {
931 send_resp(dut, conn, SIGMA_INVALID,
932 "errorCode,Unsupported WIDTH");
933 return 0;
934 }
935 }
936
937 /* TODO: WIDTH_SCAN */
938
939 val = get_param(cmd, "TDLSProhibit");
940 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
941 val = get_param(cmd, "TDLSChswitchProhibit");
942 dut->ap_tdls_prohibit_chswitch =
943 val && strcasecmp(val, "Enabled") == 0;
944 val = get_param(cmd, "HS2");
945 if (val && wlan_tag == 1)
946 dut->ap_hs2 = atoi(val);
947 val = get_param(cmd, "P2P_CROSS_CONNECT");
948 if (val)
949 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
950
951 val = get_param(cmd, "FakePubKey");
952 dut->ap_fake_pkhash = val && atoi(val);
953
954 val = get_param(cmd, "vht_tkip");
955 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
956 val = get_param(cmd, "vht_wep");
957 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
958
959 val = get_param(cmd, "Protect_mode");
960 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
961
962 val = get_param(cmd, "DYN_BW_SGNL");
963 if (val) {
964 switch (get_driver_type()) {
965 case DRIVER_OPENWRT:
966 switch (get_openwrt_driver_type()) {
967 case OPENWRT_DRIVER_ATHEROS:
968 ath_config_dyn_bw_sig(dut, ifname, val);
969 break;
970 default:
971 send_resp(dut, conn, SIGMA_ERROR,
972 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
973 return 0;
974 }
975 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +0530976 case DRIVER_WCN:
977 case DRIVER_LINUX_WCN:
978 ath_config_dyn_bw_sig(dut, ifname, val);
979 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200980 default:
981 sigma_dut_print(dut, DUT_MSG_ERROR,
982 "Unsupported DYN_BW_SGL with the current driver");
983 break;
984 }
985 }
986
987 val = get_param(cmd, "SGI80");
988 if (val) {
989 if (strcasecmp(val, "enable") == 0)
990 dut->ap_sgi80 = 1;
991 else if (strcasecmp(val, "disable") == 0)
992 dut->ap_sgi80 = 0;
993 else {
994 send_resp(dut, conn, SIGMA_INVALID,
995 "errorCode,Unsupported SGI80");
996 return 0;
997 }
998 }
999
1000 val = get_param(cmd, "LDPC");
1001 if (val) {
1002 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001003 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001004 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001005 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001006 else {
1007 send_resp(dut, conn, SIGMA_INVALID,
1008 "errorCode,Unsupported LDPC");
1009 return 0;
1010 }
1011 }
1012
1013 val = get_param(cmd, "BW_SGNL");
1014 if (val) {
1015 /*
1016 * With dynamic bandwidth signaling enabled we should see
1017 * RTS if the threshold is met.
1018 */
1019 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001020 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001021 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001022 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001023 } else {
1024 send_resp(dut, conn, SIGMA_INVALID,
1025 "errorCode,Unsupported BW_SGNL");
1026 return 0;
1027 }
1028 }
1029
1030 val = get_param(cmd, "RTS_FORCE");
1031 if (val) {
1032 switch (get_driver_type()) {
1033 case DRIVER_OPENWRT:
1034 switch (get_openwrt_driver_type()) {
1035 case OPENWRT_DRIVER_ATHEROS:
1036 ath_config_rts_force(dut, ifname, val);
1037 break;
1038 default:
1039 send_resp(dut, conn, SIGMA_ERROR,
1040 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
1041 return 0;
1042 }
1043 break;
1044 default:
1045 sigma_dut_print(dut, DUT_MSG_ERROR,
1046 "Unsupported RTS_FORCE with the current driver");
1047 break;
1048 }
1049 }
1050
1051 val = get_param(cmd, "Zero_crc");
1052 if (val) {
1053 switch (get_driver_type()) {
1054 case DRIVER_ATHEROS:
1055 ath_set_zero_crc(dut, val);
1056 break;
1057 case DRIVER_OPENWRT:
1058 switch (get_openwrt_driver_type()) {
1059 case OPENWRT_DRIVER_ATHEROS:
1060 ath_set_zero_crc(dut, val);
1061 break;
1062 default:
1063 send_resp(dut, conn, SIGMA_ERROR,
1064 "errorCode,Unsupported zero_crc with the current driver");
1065 return 0;
1066 }
1067 break;
1068 default:
1069 send_resp(dut, conn, SIGMA_ERROR,
1070 "errorCode,Unsupported zero_crc with the current driver");
1071 return 0;
1072 }
1073 }
1074
1075 val = get_param(cmd, "TxBF");
1076 if (val)
1077 dut->ap_txBF = strcasecmp(val, "enable") == 0;
1078
1079 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301080 if (val) {
1081 if (strcasecmp(val, "enable") == 0) {
1082 dut->ap_txBF = 1;
1083 dut->ap_mu_txBF = 1;
1084 } else if (strcasecmp(val, "disable") == 0) {
1085 dut->ap_txBF = 0;
1086 dut->ap_mu_txBF = 0;
1087 } else {
1088 sigma_dut_print(dut, DUT_MSG_ERROR,
1089 "Unsupported MU_TxBF");
1090 }
1091 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001092
1093 /* UNSUPPORTED: tx_lgi_rate */
1094
1095 val = get_param(cmd, "wpsnfc");
1096 if (val)
1097 dut->ap_wpsnfc = atoi(val);
1098
1099 val = get_param(cmd, "GROUP_ID");
1100 if (val) {
1101 switch (get_driver_type()) {
1102 case DRIVER_OPENWRT:
1103 switch (get_openwrt_driver_type()) {
1104 case OPENWRT_DRIVER_ATHEROS:
1105 ath_ap_set_group_id(dut, ifname, val);
1106 break;
1107 default:
1108 send_resp(dut, conn, SIGMA_ERROR,
1109 "errorCode,Unsupported group_id with the current driver");
1110 return 0;
1111 }
1112 break;
1113 default:
1114 send_resp(dut, conn, SIGMA_ERROR,
1115 "errorCode,Unsupported group_id with the current driver");
1116 return 0;
1117 }
1118 }
1119
1120 val = get_param(cmd, "CTS_WIDTH");
1121 if (val) {
1122 switch (get_driver_type()) {
1123 case DRIVER_OPENWRT:
1124 switch (get_openwrt_driver_type()) {
1125 case OPENWRT_DRIVER_ATHEROS:
1126 ath_set_cts_width(dut, ifname, val);
1127 break;
1128 default:
1129 send_resp(dut, conn, SIGMA_ERROR,
1130 "errorCode,Unsupported cts_width with the current driver");
1131 return 0;
1132 }
1133 break;
1134 default:
1135 send_resp(dut, conn, SIGMA_ERROR,
1136 "errorCode,Unsupported cts_width with the current driver");
1137 return 0;
1138 }
1139 }
1140
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001141 val = get_param(cmd, "MU_NDPA_FrameFormat");
1142 if (val)
1143 dut->ap_ndpa_frame = atoi(val);
1144
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001145 val = get_param(cmd, "interworking");
1146 if (val && strcmp(val, "1") == 0)
1147 dut->ap_interworking = 1;
1148
1149 val = get_param(cmd, "GAS_CB_DELAY");
1150 if (val)
1151 dut->ap_gas_cb_delay = atoi(val);
1152
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001153 val = get_param(cmd, "LCI");
1154 if (val) {
1155 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1156 return -1;
1157 dut->ap_lci = 1;
1158 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1159 ath_set_lci_config(dut, val, cmd);
1160 }
1161
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001162 val = get_param(cmd, "InfoZ");
1163 if (val) {
1164 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1165 return -1;
1166 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1167 }
1168
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001169 val = get_param(cmd, "LocCivicAddr");
1170 if (val) {
1171 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1172 return -1;
1173 dut->ap_lcr = 1;
1174 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1175 if (dut->ap_lci == 0)
1176 ath_set_lci_config(dut, val, cmd);
1177 }
1178
1179 val = get_param(cmd, "NeighAPBSSID");
1180 if (val) {
1181 if (dut->ap_neighap < 3) {
1182 if (parse_mac_address(
1183 dut, val,
1184 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1185 send_resp(dut, conn, SIGMA_INVALID,
1186 "Failed to parse MAC address");
1187 return 0;
1188 }
1189 dut->ap_neighap++;
1190 if (dut->ap_lci == 1)
1191 dut->ap_scan = 1;
1192 }
1193 }
1194
1195 val = get_param(cmd, "OpChannel");
1196 if (val) {
1197 if (dut->ap_opchannel < 3) {
1198 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1199 dut->ap_opchannel++;
1200 }
1201 }
1202
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001203 val = get_param(cmd, "URI-FQDNdescriptor");
1204 if (val) {
1205 if (strcasecmp(val, "HELD") == 0) {
1206 dut->ap_fqdn_held = 1;
1207 } else if (strcasecmp(val, "SUPL") == 0) {
1208 dut->ap_fqdn_supl = 1;
1209 } else {
1210 send_resp(dut, conn, SIGMA_INVALID,
1211 "errorCode,Unsupported URI-FQDNdescriptor");
1212 return 0;
1213 }
1214 }
1215
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001216 val = get_param(cmd, "Reg_Domain");
1217 if (val) {
1218 if (strcasecmp(val, "Local") == 0) {
1219 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1220 } else if (strcasecmp(val, "Global") == 0) {
1221 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1222 } else {
1223 send_resp(dut, conn, SIGMA_ERROR,
1224 "errorCode,Wrong value for Reg_Domain");
1225 return 0;
1226 }
1227 }
1228
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001229 val = get_param(cmd, "NAME");
1230 if (val) {
1231 if (strcasecmp(val, "ap1mbo") == 0)
1232 dut->ap_name = 1;
1233 else if (strcasecmp(val, "ap2mbo") == 0)
1234 dut->ap_name = 2;
1235 else
1236 dut->ap_name = 0;
1237 }
1238
1239 val = get_param(cmd, "FT_OA");
1240 if (val) {
1241 if (strcasecmp(val, "Enable") == 0) {
1242 dut->ap_ft_oa = 1;
1243 } else if (strcasecmp(val, "Disable") == 0) {
1244 dut->ap_ft_oa = 0;
1245 } else {
1246 send_resp(dut, conn, SIGMA_ERROR,
1247 "errorCode,Wrong value for FT_OA");
1248 return 0;
1249 }
1250 }
1251
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001252 val = get_param(cmd, "Cellular_Cap_Pref");
1253 if (val)
1254 dut->ap_cell_cap_pref = atoi(val);
1255
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001256 val = get_param(cmd, "DOMAIN");
1257 if (val) {
1258 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1259 send_resp(dut, conn, SIGMA_ERROR,
1260 "errorCode,Too long DOMAIN");
1261 return 0;
1262 }
1263 snprintf(dut->ap_mobility_domain,
1264 sizeof(dut->ap_mobility_domain), "%s", val);
1265 }
1266
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001267 val = get_param(cmd, "ft_bss_list");
1268 if (val) {
1269 char *mac_str;
1270 int i;
1271 char *saveptr;
1272 char *mac_list_str;
1273
1274 mac_list_str = strdup(val);
1275 if (!mac_list_str)
1276 return -1;
1277 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1278 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1279 if (parse_mac_address(dut, mac_str,
1280 dut->ft_bss_mac_list[i]) < 0) {
1281 sigma_dut_print(dut, DUT_MSG_ERROR,
1282 "MAC Address not in proper format");
1283 break;
1284 }
1285 dut->ft_bss_mac_cnt++;
1286 mac_str = strtok_r(NULL, " ", &saveptr);
1287 }
1288 sigma_dut_print(dut, DUT_MSG_DEBUG,
1289 "Storing the following FT BSS MAC List");
1290 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1291 sigma_dut_print(dut, DUT_MSG_DEBUG,
1292 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1293 i,
1294 dut->ft_bss_mac_list[i][0],
1295 dut->ft_bss_mac_list[i][1],
1296 dut->ft_bss_mac_list[i][2],
1297 dut->ft_bss_mac_list[i][3],
1298 dut->ft_bss_mac_list[i][4],
1299 dut->ft_bss_mac_list[i][5]);
1300 }
1301 free(mac_list_str);
1302 }
1303
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001304 val = get_param(cmd, "OCESupport");
1305 if (val) {
1306 if (strcasecmp(val, "enable") == 0) {
1307 dut->ap_oce = VALUE_ENABLED;
1308 } else if (strcasecmp(val, "disable") == 0) {
1309 dut->ap_oce = VALUE_DISABLED;
1310 dut->ap_filsdscv = VALUE_DISABLED;
1311 } else {
1312 send_resp(dut, conn, SIGMA_INVALID,
1313 "errorCode,Unsupported OCE");
1314 return 0;
1315 }
1316 }
1317
1318 val = get_param(cmd, "FILSDscvInterval");
1319 if (val)
1320 dut->ap_fils_dscv_int = atoi(val);
1321
1322 val = get_param(cmd, "BroadcastSSID");
1323 if (val) {
1324 if (strcasecmp(val, "enable") == 0) {
1325 dut->ap_broadcast_ssid = VALUE_ENABLED;
1326 } else if (strcasecmp(val, "disable") == 0) {
1327 dut->ap_broadcast_ssid = VALUE_DISABLED;
1328 } else {
1329 send_resp(dut, conn, SIGMA_INVALID,
1330 "errorCode,Unsupported hidden SSID");
1331 return 0;
1332 }
1333 }
1334
1335 val = get_param(cmd, "FILSDscv");
1336 if (val) {
1337 if (strcasecmp(val, "enable") == 0) {
1338 dut->ap_filsdscv = VALUE_ENABLED;
1339 } else if (strcasecmp(val, "disable") == 0) {
1340 dut->ap_filsdscv = VALUE_DISABLED;
1341 } else {
1342 send_resp(dut, conn, SIGMA_INVALID,
1343 "errorCode,Unsupported FILSDscv");
1344 return 0;
1345 }
1346 }
1347
1348 val = get_param(cmd, "FILSHLP");
1349 if (val) {
1350 if (strcasecmp(val, "enable") == 0) {
1351 dut->ap_filshlp = VALUE_ENABLED;
1352 } else if (strcasecmp(val, "disable") == 0) {
1353 dut->ap_filshlp = VALUE_DISABLED;
1354 } else {
1355 send_resp(dut, conn, SIGMA_INVALID,
1356 "errorCode,Unsupported FILSHLP");
1357 return 0;
1358 }
1359 }
1360
1361 val = get_param(cmd, "NAIRealm");
1362 if (val) {
1363 dut->ap_nairealm_int = 1;
1364 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
1365 return -1;
1366 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1367 }
1368
1369 val = get_param(cmd, "DeauthDisassocTx");
1370 if (val) {
1371 if (strcasecmp(val, "disable") == 0) {
1372 deauth_disassoc(dut, ifname, val);
1373 } else {
1374 send_resp(dut, conn, SIGMA_INVALID,
1375 "errorCode,Unsupported DeauthDisassocTx");
1376 return 0;
1377 }
1378 }
1379
1380 val = get_param(cmd, "RNR");
1381 if (val) {
1382 if (strcasecmp(val, "enable") == 0) {
1383 dut->ap_rnr = VALUE_ENABLED;
1384 } else if (strcasecmp(val, "disable") == 0) {
1385 dut->ap_rnr = VALUE_DISABLED;
1386 } else {
1387 send_resp(dut, conn, SIGMA_INVALID,
1388 "errorCode,Unsupported RNR");
1389 return 0;
1390 }
1391 }
1392
1393 val = get_param(cmd, "BLEChannelUtil");
1394 if (val)
1395 dut->ap_blechanutil = atoi(val);
1396
1397 val = get_param(cmd, "BLEAvailAdminCap");
1398 if (val)
1399 dut->ap_ble_admit_cap = atoi(val);
1400
1401 val = get_param(cmd, "DataPPDUDuration");
1402 if (val)
1403 dut->ap_datappdudura = atoi(val);
1404
1405 val = get_param(cmd, "AirTimeFract");
1406 if (val)
1407 dut->ap_airtimefract = atoi(val);
1408
1409 val = get_param(cmd, "dhcpServIPADDR");
1410 if (val) {
1411 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
1412 return -1;
1413 snprintf(dut->ap_dhcpserv_ipaddr,
1414 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1415 dut->ap_dhcp_stop = 1;
1416 }
1417
1418 val = get_param(cmd, "ESP_IE");
1419 if (val) {
1420 if (strcasecmp(val, "enable") == 0) {
1421 dut->ap_esp = VALUE_ENABLED;
1422 } else if (strcasecmp(val, "disable") == 0) {
1423 dut->ap_esp = VALUE_DISABLED;
1424 } else {
1425 send_resp(dut, conn, SIGMA_INVALID,
1426 "errorCode,Unsupported ESP_IE");
1427 return 0;
1428 }
1429 }
1430
1431 val = get_param(cmd, "BAWinSize");
1432 if (val)
1433 dut->ap_bawinsize = atoi(val);
1434
1435 val = get_param(cmd, "BLEStaCount");
1436 if (val)
1437 dut->ap_blestacnt = atoi(val);
1438
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001439 val = get_param(cmd, "PPDUTxType");
1440 if (val) {
1441 if (strcasecmp(val, "MU") == 0) {
1442 dut->ap_he_ppdu = PPDU_MU;
1443 } else {
1444 send_resp(dut, conn, SIGMA_INVALID,
1445 "errorCode,Unsupported PPDUTxType");
1446 return 0;
1447 }
1448 }
1449
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02001450 val = get_param(cmd, "WscIEFragment");
1451 if (val && strcasecmp(val, "enable") == 0) {
1452 sigma_dut_print(dut, DUT_MSG_DEBUG,
1453 "Enable WSC IE fragmentation");
1454 dut->wsc_fragment = 1;
1455 }
1456
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02001457 val = get_param(cmd, "WpsVersion");
1458 if (val)
1459 dut->wps_forced_version = get_wps_forced_version(dut, val);
1460
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02001461 val = get_param(cmd, "WscEAPFragment");
1462 if (val && strcasecmp(val, "enable") == 0)
1463 dut->eap_fragment = 1;
1464
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001465 val = get_param(cmd, "MSDUSize");
1466 if (val) {
1467 int mtu;
1468
1469 dut->amsdu_size = atoi(val);
1470 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
1471 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
1472 sigma_dut_print(dut, DUT_MSG_ERROR,
1473 "MSDUSize %d is above max %d or below min %d",
1474 dut->amsdu_size,
1475 IEEE80211_MAX_DATA_LEN_DMG,
1476 IEEE80211_SNAP_LEN_DMG);
1477 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001478 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001479 }
1480
1481 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
1482 sigma_dut_print(dut, DUT_MSG_DEBUG,
1483 "Setting amsdu_size to %d", mtu);
1484 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
1485 get_station_ifname(), mtu);
1486
1487 if (system(buf) != 0) {
1488 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
1489 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001490 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001491 }
1492 }
1493
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001494 val = get_param(cmd, "BAckRcvBuf");
1495 if (val) {
1496 dut->back_rcv_buf = atoi(val);
1497 if (dut->back_rcv_buf == 0) {
1498 sigma_dut_print(dut, DUT_MSG_ERROR,
1499 "Failed to convert %s or value is 0",
1500 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001501 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001502 }
1503
1504 sigma_dut_print(dut, DUT_MSG_DEBUG,
1505 "Setting BAckRcvBuf to %s", val);
1506 }
1507
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001508 val = get_param(cmd, "ExtSchIE");
1509 if (val && !strcasecmp(val, "Enable")) {
1510 int num_allocs = MAX_ESE_ALLOCS;
1511
1512 if (sta_extract_60g_ese(dut, cmd, dut->ap_ese_allocs,
1513 &num_allocs)) {
1514 send_resp(dut, conn, SIGMA_INVALID,
1515 "errorCode,Invalid ExtSchIE");
1516 return 0;
1517 }
1518 dut->ap_num_ese_allocs = num_allocs;
1519 }
1520
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02001521 if (is_60g_sigma_dut(dut)) {
1522 unsigned int abft_len = 1; /* default is one slot */
1523
1524 val = get_param(cmd, "ABFTLRang");
1525 if (val) {
1526 sigma_dut_print(dut, DUT_MSG_DEBUG,
1527 "ABFTLRang parameter %s", val);
1528 if (strcasecmp(val, "Gt1") == 0)
1529 abft_len = 2; /* 2 slots in this case */
1530 }
1531
1532 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
1533 send_resp(dut, conn, SIGMA_ERROR,
1534 "ErrorCode,Can't set ABFT length");
1535 return STATUS_SENT;
1536 }
1537 }
1538
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001539 return 1;
1540}
1541
1542
1543static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1544{
1545 char buf[256];
1546 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1547
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301548 if (tid < 0 ||
1549 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1550 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1551 return;
1552 }
1553
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001554 snprintf(buf, sizeof(buf),
1555 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1556 ifname, VI_QOS_TMP_FILE);
1557 if (system(buf) != 0)
1558 return;
1559
1560 snprintf(buf, sizeof(buf),
1561 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1562 ifname, VI_QOS_TMP_FILE);
1563 if (system(buf) != 0)
1564 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1565
1566 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1567 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1568 if (system(buf) != 0) {
1569 sigma_dut_print(dut, DUT_MSG_ERROR,
1570 "Output redirection to VI_QOS_TMP_FILE failed");
1571 }
1572
1573 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1574 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1575 if (system(buf) != 0) {
1576 sigma_dut_print(dut, DUT_MSG_ERROR,
1577 "Append TID to VI_QOS_FILE failed ");
1578 }
1579
1580 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1581 if (system(buf) != 0)
1582 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1583}
1584
1585
1586static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1587 struct sigma_cmd *cmd)
1588{
1589 const char *val;
1590 char *ifname;
1591 char buf[256];
1592 int tid = 0;
1593
1594 ifname = get_main_ifname();
1595 val = get_param(cmd, "TID");
1596 if (val) {
1597 tid = atoi(val);
1598 if (tid)
1599 ath_inject_frame(dut, ifname, tid);
1600 }
1601
1602 /* NOTE: This is the command sequence on Peregrine for ADDBA */
1603 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
1604 if (system(buf) != 0) {
1605 sigma_dut_print(dut, DUT_MSG_ERROR,
1606 "iwpriv setaddbaoper failed");
1607 }
1608
1609 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1610 ifname, tid);
1611 if (system(buf) != 0) {
1612 sigma_dut_print(dut, DUT_MSG_ERROR,
1613 "wifitool senddelba failed");
1614 }
1615
1616 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1617 ifname, tid);
1618 if (system(buf) != 0) {
1619 sigma_dut_print(dut, DUT_MSG_ERROR,
1620 "wifitool sendaddba failed");
1621 }
1622
1623 return 1;
1624}
1625
1626
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301627static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1628 const char *sta_mac,
1629 const char *dir_path)
1630{
1631 DIR *dir;
1632 struct dirent *entry;
1633 char buf[128], path[128];
1634 int ret = 0;
1635
1636 dir = opendir(dir_path);
1637 if (!dir)
1638 return 0;
1639
1640 while ((entry = readdir(dir))) {
1641 ret = 1;
1642
1643 if (strcmp(entry->d_name, ".") == 0 ||
1644 strcmp(entry->d_name, "..") == 0)
1645 continue;
1646
1647 snprintf(path, sizeof(path) - 1, "%s/%s",
1648 dir_path, entry->d_name);
1649 path[sizeof(path) - 1] = 0;
1650
1651 if (strcmp(entry->d_name, sta_mac) == 0) {
1652 snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode",
1653 path);
1654 if (system(buf) != 0) {
1655 sigma_dut_print(dut, DUT_MSG_ERROR,
1656 "Failed to set aggr mode for ath10k");
1657 }
1658
1659 snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba",
1660 tid, path);
1661 if (system(buf) != 0) {
1662 sigma_dut_print(dut, DUT_MSG_ERROR,
1663 "Failed to set addbareq for ath10k");
1664 }
1665
1666 break;
1667 }
1668
1669 /* Recursively search subdirectories */
1670 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1671 }
1672
1673 closedir(dir);
1674
1675 return ret;
1676}
1677
1678
1679static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1680 struct sigma_cmd *cmd)
1681{
1682 const char *val;
1683 int tid = 0;
1684
1685 val = get_param(cmd, "TID");
1686 if (val)
1687 tid = atoi(val);
1688
1689 val = get_param(cmd, "sta_mac_address");
1690 if (!val) {
1691 sigma_dut_print(dut, DUT_MSG_ERROR,
1692 "Failed to parse station MAC address");
1693 return 0;
1694 }
1695
1696 return ath10k_debug_enable_addba_req(dut, tid, val,
1697 "/sys/kernel/debug/ieee80211");
1698}
1699
1700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001701static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1702 struct sigma_cmd *cmd)
1703{
1704 /* const char *name = get_param(cmd, "NAME"); */
1705 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301706 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001707
1708 switch (get_driver_type()) {
1709 case DRIVER_ATHEROS:
1710 return ath_ap_send_addba_req(dut, conn, cmd);
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02001711#ifdef __linux__
1712 case DRIVER_WIL6210:
1713 return send_addba_60g(dut, conn, cmd, "sta_mac_address");
1714#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001715 case DRIVER_OPENWRT:
1716 switch (get_openwrt_driver_type()) {
1717 case OPENWRT_DRIVER_ATHEROS:
1718 return ath_ap_send_addba_req(dut, conn, cmd);
1719 default:
1720 send_resp(dut, conn, SIGMA_ERROR,
1721 "errorCode,ap_send_addba_req not supported with this driver");
1722 return 0;
1723 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301724 case DRIVER_WCN:
1725 case DRIVER_LINUX_WCN:
1726 /* AP automatically sends ADDBA request after association. */
1727 sigma_dut_print(dut, DUT_MSG_INFO,
1728 "ap_send_addba_req command ignored");
1729 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301730 case DRIVER_MAC80211:
1731 if (stat("/sys/module/ath10k_core", &s) == 0)
1732 return ath10k_ap_send_addba_req(dut, cmd);
1733 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734 default:
1735 send_resp(dut, conn, SIGMA_ERROR,
1736 "errorCode,ap_send_addba_req not supported with this driver");
1737 return 0;
1738 }
1739}
1740
1741
1742static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1743 struct sigma_cmd *cmd)
1744{
1745 /* const char *name = get_param(cmd, "NAME"); */
1746 const char *val;
1747 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301748 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001749
1750 val = get_param(cmd, "WLAN_TAG");
1751 if (val)
1752 wlan_tag = atoi(val);
1753
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301754 security = get_param(cmd, "Security");
1755
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001756 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001757 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301758 if (!val)
1759 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001760 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001761 if (strcasecmp(val, "NONE") == 0) {
1762 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1763 } else if (strcasecmp(val, "OSEN") == 0 &&
1764 wlan_tag == 2) {
1765 /*
1766 * OSEN only supported on WLAN_TAG = 2 for now
1767 */
1768 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301769 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1770 (security &&
1771 strcasecmp(security, "PSK") == 0 &&
1772 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001773 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1774 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02001775 } else if (strcasecmp(val, "OWE") == 0 &&
1776 wlan_tag == 2) {
1777 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1778 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001779 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001780 send_resp(dut, conn, SIGMA_INVALID,
1781 "errorCode,Unsupported KEYMGNT");
1782 return 0;
1783 }
1784 return 1;
1785 }
1786 }
1787
1788 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301789 if (!val)
1790 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001791 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301792 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1793 (security && strcasecmp(security, "PSK") == 0 &&
1794 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001795 dut->ap_key_mgmt = AP_WPA2_PSK;
1796 dut->ap_cipher = AP_CCMP;
1797 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1798 strcasecmp(val, "WPA2-Ent") == 0) {
1799 dut->ap_key_mgmt = AP_WPA2_EAP;
1800 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001801 } else if (strcasecmp(val, "SuiteB") == 0) {
1802 dut->ap_key_mgmt = AP_SUITEB;
1803 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02001804 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001805 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1806 dut->ap_key_mgmt = AP_WPA_PSK;
1807 dut->ap_cipher = AP_TKIP;
1808 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1809 strcasecmp(val, "WPA-Ent") == 0) {
1810 dut->ap_key_mgmt = AP_WPA_EAP;
1811 dut->ap_cipher = AP_TKIP;
1812 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1813 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1814 dut->ap_cipher = AP_CCMP_TKIP;
1815 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1816 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1817 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02001818 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
1819 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03001820 dut->ap_key_mgmt = AP_WPA2_SAE;
1821 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001822 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03001823 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1824 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1825 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001826 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001827 } else if (strcasecmp(val, "OWE") == 0) {
1828 dut->ap_key_mgmt = AP_WPA2_OWE;
1829 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001830 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03001831 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
1832 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
1833 dut->ap_cipher = AP_CCMP;
1834 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03001835 } else if (strcasecmp(val, "OSEN") == 0) {
1836 dut->ap_key_mgmt = AP_OSEN;
1837 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03001838 } else if (strcasecmp(val, "FT-EAP") == 0) {
1839 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
1840 dut->ap_cipher = AP_CCMP;
1841 dut->ap_pmf = AP_PMF_OPTIONAL;
1842 } else if (strcasecmp(val, "FT-PSK") == 0) {
1843 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
1844 dut->ap_cipher = AP_CCMP;
1845 dut->ap_pmf = AP_PMF_OPTIONAL;
1846 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
1847 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
1848 dut->ap_cipher = AP_CCMP;
1849 dut->ap_pmf = AP_PMF_OPTIONAL;
1850 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
1851 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
1852 dut->ap_cipher = AP_CCMP;
1853 dut->ap_pmf = AP_PMF_OPTIONAL;
1854 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
1855 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
1856 dut->ap_cipher = AP_CCMP;
1857 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001858 } else if (strcasecmp(val, "NONE") == 0) {
1859 dut->ap_key_mgmt = AP_OPEN;
1860 dut->ap_cipher = AP_PLAIN;
1861 } else {
1862 send_resp(dut, conn, SIGMA_INVALID,
1863 "errorCode,Unsupported KEYMGNT");
1864 return 0;
1865 }
1866 }
1867
Jouni Malinen30824df2017-08-22 21:21:38 +03001868 val = get_param(cmd, "ECGroupID");
1869 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001870 free(dut->ap_sae_groups);
1871 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001872 }
1873
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001874 val = get_param(cmd, "AntiCloggingThreshold");
1875 if (val)
1876 dut->sae_anti_clogging_threshold = atoi(val);
1877
Jouni Malinenb347db02017-09-02 01:36:03 +03001878 val = get_param(cmd, "Reflection");
1879 if (val)
1880 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1881
Jouni Malinen68143132017-09-02 02:34:08 +03001882 val = get_param(cmd, "InvalidSAEElement");
1883 if (val) {
1884 free(dut->sae_commit_override);
1885 dut->sae_commit_override = strdup(val);
1886 }
1887
Jouni Malinen09550de2019-03-26 00:24:11 +02001888 val = get_param(cmd, "SAEPasswords");
1889 if (val) {
1890 free(dut->ap_sae_passwords);
1891 dut->ap_sae_passwords = strdup(val);
1892 }
1893
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001894 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301895 if (!val)
1896 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001897 if (val) {
1898 if (strcasecmp(val, "WEP") == 0) {
1899 dut->ap_cipher = AP_WEP;
1900 } else if (strcasecmp(val, "TKIP") == 0) {
1901 dut->ap_cipher = AP_TKIP;
1902 } else if (strcasecmp(val, "AES") == 0 ||
1903 strcasecmp(val, "AES-CCMP") == 0) {
1904 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001905 } else if (strcasecmp(val, "AES-GCMP") == 0) {
1906 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001907 } else {
1908 send_resp(dut, conn, SIGMA_INVALID,
1909 "errorCode,Unsupported ENCRYPT");
1910 return 0;
1911 }
1912 }
1913
Jouni Malinen3d633da2017-09-14 22:19:21 +03001914 val = get_param(cmd, "PairwiseCipher");
1915 if (val) {
1916 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1917 dut->ap_cipher = AP_GCMP_256;
1918 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1919 dut->ap_cipher = AP_CCMP_256;
1920 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1921 dut->ap_cipher = AP_GCMP_128;
1922 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1923 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02001924 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
1925 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
1926 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001927 } else {
1928 send_resp(dut, conn, SIGMA_INVALID,
1929 "errorCode,Unsupported PairwiseCipher");
1930 return 0;
1931 }
1932 }
1933
Jouni Malinen2ba24492017-11-17 12:43:59 +02001934 val = get_param(cmd, "GroupCipher");
1935 if (val) {
1936 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1937 dut->ap_group_cipher = AP_GCMP_256;
1938 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1939 dut->ap_group_cipher = AP_CCMP_256;
1940 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1941 dut->ap_group_cipher = AP_GCMP_128;
1942 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1943 dut->ap_group_cipher = AP_CCMP;
1944 } else {
1945 send_resp(dut, conn, SIGMA_INVALID,
1946 "errorCode,Unsupported GroupCipher");
1947 return 0;
1948 }
1949 }
1950
Jouni Malinen3d633da2017-09-14 22:19:21 +03001951 val = get_param(cmd, "GroupMgntCipher");
1952 if (val) {
1953 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1954 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
1955 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1956 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
1957 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1958 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
1959 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1960 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
1961 } else {
1962 send_resp(dut, conn, SIGMA_INVALID,
1963 "errorCode,Unsupported GroupMgntCipher");
1964 return 0;
1965 }
1966 }
1967
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001968 val = get_param(cmd, "WEPKEY");
1969 if (val) {
1970 size_t len;
1971 if (dut->ap_cipher != AP_WEP) {
1972 send_resp(dut, conn, SIGMA_INVALID,
1973 "errorCode,Unexpected WEPKEY without WEP "
1974 "configuration");
1975 return 0;
1976 }
1977 len = strlen(val);
1978 if (len != 10 && len != 26) {
1979 send_resp(dut, conn, SIGMA_INVALID,
1980 "errorCode,Unexpected WEPKEY length");
1981 return 0;
1982 }
1983 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1984 }
1985
1986 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301987 if (!val)
1988 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001989 if (val) {
Jouni Malinen2126f422017-10-11 23:24:33 +03001990 if (dut->ap_key_mgmt != AP_WPA2_SAE && strlen(val) > 64)
1991 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001992 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1993 return -1;
1994 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1995 "%s", val);
1996 }
1997
Jouni Malinen63370622017-11-18 17:47:13 +02001998 val = get_param(cmd, "PSKHEX");
1999 if (val) {
2000 if (strlen(val) != 64)
2001 return -1;
2002 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
2003 }
2004
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302005 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
2006 dut->ap_pmf = AP_PMF_OPTIONAL;
2007
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002008 val = get_param(cmd, "PMF");
2009 if (val) {
2010 if (strcasecmp(val, "Disabled") == 0) {
2011 dut->ap_pmf = AP_PMF_DISABLED;
2012 } else if (strcasecmp(val, "Optional") == 0) {
2013 dut->ap_pmf = AP_PMF_OPTIONAL;
2014 } else if (strcasecmp(val, "Required") == 0) {
2015 dut->ap_pmf = AP_PMF_REQUIRED;
2016 } else {
2017 send_resp(dut, conn, SIGMA_INVALID,
2018 "errorCode,Unsupported PMF");
2019 return 0;
2020 }
2021 }
2022
2023 if (dut->ap_key_mgmt == AP_OPEN) {
2024 dut->ap_hs2 = 0;
2025 dut->ap_pmf = AP_PMF_DISABLED;
2026 }
2027
2028 dut->ap_add_sha256 = 0;
2029 val = get_param(cmd, "SHA256AD");
2030 if (val == NULL)
2031 val = get_param(cmd, "SHA256");
2032 if (val) {
2033 if (strcasecmp(val, "Disabled") == 0) {
2034 } else if (strcasecmp(val, "Enabled") == 0) {
2035 dut->ap_add_sha256 = 1;
2036 } else {
2037 send_resp(dut, conn, SIGMA_INVALID,
Jouni Malinena7fa6202019-03-26 00:22:10 +02002038 "errorCode,Unsupported SHA256");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002039 return 0;
2040 }
2041 }
2042
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302043 val = get_param(cmd, "PreAuthentication");
2044 if (val) {
2045 if (strcasecmp(val, "disabled") == 0) {
2046 dut->ap_rsn_preauth = 0;
2047 } else if (strcasecmp(val, "enabled") == 0) {
2048 dut->ap_rsn_preauth = 1;
2049 } else {
2050 send_resp(dut, conn, SIGMA_INVALID,
2051 "errorCode,Unsupported PreAuthentication value");
2052 return 0;
2053 }
2054 }
2055
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002056 val = get_param(cmd, "AKMSuiteType");
2057 if (val) {
2058 unsigned int akmsuitetype = 0;
2059
2060 dut->ap_akm = 1;
2061 akmsuitetype = atoi(val);
2062 if (akmsuitetype == 14) {
2063 dut->ap_add_sha256 = 1;
2064 } else if (akmsuitetype == 15) {
2065 dut->ap_add_sha384 = 1;
2066 } else {
2067 send_resp(dut, conn, SIGMA_INVALID,
2068 "errorCode,Unsupported AKMSuitetype");
2069 return 0;
2070 }
2071 }
2072
2073 val = get_param(cmd, "PMKSACaching");
2074 if (val) {
2075 dut->ap_pmksa = 1;
2076 if (strcasecmp(val, "disabled") == 0) {
2077 dut->ap_pmksa_caching = 1;
2078 } else if (strcasecmp(val, "enabled") == 0) {
2079 dut->ap_pmksa_caching = 0;
2080 } else {
2081 send_resp(dut, conn, SIGMA_INVALID,
2082 "errorCode,Unsupported PMKSACaching value");
2083 return 0;
2084 }
2085 }
2086
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002087 return 1;
2088}
2089
2090
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302091int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2092 struct sigma_cmd *cmd)
2093{
2094 int status;
2095
2096 status = cmd_ap_set_wireless(dut, conn, cmd);
2097 if (status != 1)
2098 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302099 status = cmd_ap_set_security(dut, conn, cmd);
2100 if (status != 1)
2101 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302102 return cmd_ap_config_commit(dut, conn, cmd);
2103}
2104
2105
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002106static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
2107 struct sigma_cmd *cmd)
2108{
2109 /* const char *name = get_param(cmd, "NAME"); */
2110 const char *val;
2111 unsigned int wlan_tag = 1, radius_port = 0;
2112 char *radius_ipaddr = NULL, *radius_password = NULL;
2113
2114 val = get_param(cmd, "WLAN_TAG");
2115 if (val) {
2116 wlan_tag = atoi(val);
2117 if (wlan_tag != 1 && wlan_tag != 2) {
2118 send_resp(dut, conn, SIGMA_INVALID,
2119 "errorCode,Invalid WLAN_TAG");
2120 return 0;
2121 }
2122 }
2123
2124 val = get_param(cmd, "PORT");
2125 if (val)
2126 radius_port = atoi(val);
2127
2128 if (wlan_tag == 1) {
2129 if (radius_port)
2130 dut->ap_radius_port = radius_port;
2131 radius_ipaddr = dut->ap_radius_ipaddr;
2132 radius_password = dut->ap_radius_password;
2133 } else if (wlan_tag == 2) {
2134 if (radius_port)
2135 dut->ap2_radius_port = radius_port;
2136 radius_ipaddr = dut->ap2_radius_ipaddr;
2137 radius_password = dut->ap2_radius_password;
2138 }
2139
2140 val = get_param(cmd, "IPADDR");
2141 if (val) {
2142 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2143 return -1;
2144 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2145 "%s", val);
2146 }
2147
2148 val = get_param(cmd, "PASSWORD");
2149 if (val) {
2150 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2151 return -1;
2152 snprintf(radius_password,
2153 sizeof(dut->ap_radius_password), "%s", val);
2154 }
2155
2156 return 1;
2157}
2158
2159
2160static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2161 const char *key, const char *val)
2162{
2163 char buf[100];
2164
2165 if (val == NULL) {
2166 snprintf(buf, sizeof(buf),
2167 "uci delete wireless.wifi%d.%s", id, key);
2168 run_system(dut, buf);
2169 return;
2170 }
2171
2172 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2173 id, key, val);
2174 run_system(dut, buf);
2175}
2176
2177
2178static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2179 const char *key, const char *val)
2180{
2181 char buf[256];
2182
2183 if (val == NULL) {
2184 snprintf(buf, sizeof(buf),
2185 "uci del_list wireless.wifi%d.%s", id, key);
2186 run_system(dut, buf);
2187 return;
2188 }
2189
2190 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2191 id, key, val);
2192 run_system(dut, buf);
2193}
2194
2195
2196static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2197 const char *val)
2198{
2199 char buf[256];
2200
2201 if (val == NULL) {
2202 snprintf(buf, sizeof(buf),
2203 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2204 run_system(dut, buf);
2205 return;
2206 }
2207
2208 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2209 id, key, val);
2210 run_system(dut, buf);
2211}
2212
2213
2214static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2215 const char *key, const char *val)
2216{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002217 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002218
2219 if (val == NULL) {
2220 snprintf(buf, sizeof(buf),
2221 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2222 run_system(dut, buf);
2223 return;
2224 }
2225
2226 snprintf(buf, sizeof(buf),
2227 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2228 id, key, val);
2229 run_system(dut, buf);
2230}
2231
2232
2233static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2234 const char *val)
2235{
2236 char buf[256];
2237
2238 if (val == NULL) {
2239 snprintf(buf, sizeof(buf),
2240 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2241 run_system(dut, buf);
2242 return;
2243 }
2244
2245 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
2246 run_system(dut, buf);
2247 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2248 id, key, val);
2249 run_system(dut, buf);
2250 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2251 id, "network", "lan");
2252 run_system(dut, buf);
2253 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2254 id, "mode", "ap");
2255 run_system(dut, buf);
2256 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2257 id, "encryption", "none");
2258 run_system(dut, buf);
2259}
2260
2261
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002262#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002263static void owrt_ap_config_radio(struct sigma_dut *dut)
2264{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002265 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002266 int radio_count, radio_no;
2267 char buf[64];
2268
2269 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2270 radio_count++) {
2271 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2272 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2273 if (!sigma_radio_ifname[radio_no] ||
2274 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2275 continue;
2276 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2277 owrt_ap_set_vap(dut, radio_count, "device", buf);
2278 radio_id[radio_no] = radio_count;
2279 }
2280 }
2281
2282 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2283 switch (dut->ap_mode) {
2284 case AP_11g:
2285 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2286 break;
2287 case AP_11b:
2288 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2289 break;
2290 case AP_11ng:
2291 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2292 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2293 break;
2294 case AP_11a:
2295 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2296 break;
2297 case AP_11na:
2298 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2299 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2300 break;
2301 case AP_11ac:
2302 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2303 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2304 break;
2305 case AP_inval:
2306 sigma_dut_print(dut, DUT_MSG_ERROR,
2307 "MODE NOT SPECIFIED!");
2308 return;
2309 default:
2310 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2311 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2312 break;
2313 }
2314
2315 if (dut->ap_is_dual) {
2316 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2317 switch (dut->ap_mode_1) {
2318 case AP_11g:
2319 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2320 break;
2321 case AP_11b:
2322 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2323 break;
2324 case AP_11ng:
2325 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2326 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2327 break;
2328 case AP_11a:
2329 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2330 break;
2331 case AP_11na:
2332 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2333 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2334 break;
2335 case AP_11ac:
2336 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2337 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2338 break;
2339 case AP_inval:
2340 sigma_dut_print(dut, DUT_MSG_ERROR,
2341 "MODE NOT SPECIFIED!");
2342 return;
2343 default:
2344 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2345 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2346 break;
2347 }
2348
2349 }
2350
2351 /* Channel */
2352 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2353 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2354
2355 switch (dut->ap_chwidth) {
2356 case AP_20:
2357 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2358 break;
2359 case AP_40:
2360 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2361 break;
2362 case AP_80:
2363 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2364 break;
2365 case AP_160:
2366 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2367 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002368 case AP_80_80:
2369 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2370 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002371 case AP_AUTO:
2372 default:
2373 break;
2374 }
2375
2376 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2377 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2378 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2379 }
2380
2381 if (dut->ap_is_dual) {
2382 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2383 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2384 }
2385
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002386 /* Country Code */
2387 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2388 const char *country;
2389
2390 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2391 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002393 if (dut->ap_is_dual)
2394 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002395 } else if (dut->ap_countrycode[0]) {
2396 owrt_ap_set_radio(dut, radio_id[0], "country",
2397 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002398 }
2399
2400 if (dut->ap_disable_protection == 1) {
2401 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2402 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2403 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2404 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2405 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002406
2407 if (dut->ap_oce == VALUE_ENABLED &&
2408 get_driver_type() == DRIVER_OPENWRT)
2409 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002410}
2411
2412
2413static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2414{
2415 char buf[256];
2416
2417 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2418 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2419 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2420 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2421
2422 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2423 "'eng:Wi-Fi Alliance'");
2424
2425 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2426 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2427
2428 if (dut->ap_wan_metrics == 1)
2429 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2430 "'01:2500:384:0:0:10'");
2431 else if (dut->ap_wan_metrics == 1)
2432 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2433 "'01:1500:384:20:20:10'");
2434 else if (dut->ap_wan_metrics == 2)
2435 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2436 "'01:1500:384:20:20:10'");
2437 else if (dut->ap_wan_metrics == 3)
2438 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2439 "'01:2000:1000:20:20:10'");
2440 else if (dut->ap_wan_metrics == 4)
2441 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2442 "'01:8000:1000:20:20:10'");
2443 else if (dut->ap_wan_metrics == 5)
2444 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2445 "'01:9000:5000:20:20:10'");
2446
2447 if (dut->ap_conn_capab == 1) {
2448 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2449 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2450 "'6:20:1'");
2451 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2452 "'6:22:0'");
2453 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2454 "'6:80:1'");
2455 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2456 "'6:443:1'");
2457 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2458 "'6:1723:0'");
2459 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2460 "'6:5060:0'");
2461 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2462 "'17:500:1'");
2463 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2464 "'17:5060:0'");
2465 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2466 "'17:4500:1'");
2467 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2468 "'50:0:1'");
2469 } else if (dut->ap_conn_capab == 2) {
2470 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2471 "'6:80:1'");
2472 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2473 "'6:443:1'");
2474 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2475 "'17:5060:1'");
2476 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2477 "'6:5060:1'");
2478 } else if (dut->ap_conn_capab == 3) {
2479 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2480 "'6:80:1'");
2481 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2482 "'6:443:1'");
2483 }
2484
2485 if (dut->ap_oper_class == 1)
2486 snprintf(buf, sizeof(buf), "%s", "51");
2487 else if (dut->ap_oper_class == 2)
2488 snprintf(buf, sizeof(buf), "%s", "73");
2489 else if (dut->ap_oper_class == 3)
2490 snprintf(buf, sizeof(buf), "%s", "5173");
2491
2492 if (dut->ap_oper_class)
2493 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2494
2495 if (dut->ap_osu_provider_list) {
2496 char *osu_friendly_name = NULL;
2497 char *osu_icon = NULL;
2498 char *osu_ssid = NULL;
2499 char *osu_nai = NULL;
2500 char *osu_service_desc = NULL;
2501 char *hs20_icon_filename = NULL;
2502 char hs20_icon[150];
2503 int osu_method;
2504
2505 hs20_icon_filename = "icon_red_zxx.png";
2506 if (dut->ap_osu_icon_tag == 2)
2507 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2508 snprintf(hs20_icon, sizeof(hs20_icon),
2509 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2510 hs20_icon_filename);
2511 osu_icon = "icon_red_zxx.png";
2512 osu_ssid = "OSU";
2513 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2514 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2515 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2516 dut->ap_osu_method[0];
2517
2518 if (strlen(dut->ap_osu_server_uri[0]))
2519 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2520 dut->ap_osu_server_uri[0]);
2521 else
2522 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2523 "'https://osu-server.r2-testbed.wi-fi.org/'");
2524 switch (dut->ap_osu_provider_list) {
2525 case 1:
2526 case 101:
2527 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2528 "'eng:SP Red Test Only'");
2529 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2530 "'eng:Free service for test purpose'");
2531 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2532 hs20_icon);
2533
2534 hs20_icon_filename = "icon_red_eng.png";
2535 if (dut->ap_osu_icon_tag == 2)
2536 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2537
2538 snprintf(hs20_icon, sizeof(hs20_icon),
2539 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2540 hs20_icon_filename);
2541 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2542 "icon_red_eng.png");
2543 break;
2544 case 2:
2545 case 102:
2546 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2547 "'eng:Wireless Broadband Alliance'");
2548 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2549 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002550 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002551 if (dut->ap_osu_icon_tag == 2)
2552 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2553
2554 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002555 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002556 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002557 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002558 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2559 break;
2560 case 3:
2561 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03002562 osu_friendly_name = "'spa:SP Red Test Only'";
2563 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002564 break;
2565 case 4:
2566 case 104:
2567 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002568 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002569 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2570 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002571 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002572 if (dut->ap_osu_icon_tag == 2)
2573 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2574
2575 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002576 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002577 hs20_icon_filename);
2578 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2579 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002580 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002581
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002582 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002583 if (dut->ap_osu_icon_tag == 2)
2584 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2585
2586 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002587 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002588 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002589 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002590 break;
2591 case 5:
2592 case 105:
2593 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002594 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002595 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2596 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002597 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002598
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002599 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002600 if (dut->ap_osu_icon_tag == 2)
2601 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2602
2603 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002604 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002605 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002606 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002607 break;
2608 case 6:
2609 case 106:
2610 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2611 "'eng:SP Green Test Only'");
2612 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2613 "'kor:SP 초록 테스트 전용'");
2614
2615 hs20_icon_filename = "icon_green_zxx.png";
2616 if (dut->ap_osu_icon_tag == 2)
2617 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2618
2619 snprintf(hs20_icon, sizeof(hs20_icon),
2620 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2621 hs20_icon_filename);
2622 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2623 hs20_icon);
2624
2625 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2626 "'icon_green_zxx.png'");
2627 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2628 dut->ap_osu_method[0];
2629
2630 snprintf(buf, sizeof(buf), "%d", osu_method);
2631 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2632
2633 if (strlen(dut->ap_osu_server_uri[1]))
2634 owrt_ap_set_list_vap(dut, vap_id,
2635 "osu_server_uri",
2636 dut->ap_osu_server_uri[1]);
2637 else
2638 owrt_ap_set_list_vap(dut, vap_id,
2639 "osu_server_uri",
2640 "'https://osu-server.r2-testbed.wi-fi.org/'");
2641
2642 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2643 "'eng:SP Orange Test Only'");
2644
2645 hs20_icon_filename = "icon_orange_zxx.png";
2646 if (dut->ap_osu_icon_tag == 2)
2647 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2648
2649 snprintf(hs20_icon, sizeof(hs20_icon),
2650 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2651 hs20_icon_filename);
2652
2653 osu_icon = "icon_orange_zxx.png";
2654 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2655 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2656 dut->ap_osu_method[1];
2657 osu_service_desc = NULL;
2658 break;
2659 case 7:
2660 case 107:
2661 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002662 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002663 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2664 "'eng:Free service for test purpose'");
2665
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002666 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002667 if (dut->ap_osu_icon_tag == 2)
2668 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2669
2670 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002671 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002672 hs20_icon_filename);
2673 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2674 hs20_icon);
2675
2676 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002677 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002678 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002679
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002680 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002681 if (dut->ap_osu_icon_tag == 2)
2682 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2683
2684 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002685 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002686 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002687 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002688 break;
2689 case 8:
2690 case 108:
2691 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2692 "'eng:SP Red Test Only'");
2693 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2694 "'eng:Free service for test purpose'");
2695 osu_ssid = "OSU-Encrypted";
2696 osu_nai = "'anonymous@hotspot.net'";
2697 break;
2698 case 9:
2699 case 109:
2700 osu_ssid = "OSU-OSEN";
2701 osu_nai = "'test-anonymous@wi-fi.org'";
2702 osu_friendly_name = "'eng:SP Orange Test Only'";
2703 hs20_icon_filename = "icon_orange_zxx.png";
2704 if (dut->ap_osu_icon_tag == 2)
2705 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2706
2707 snprintf(hs20_icon, sizeof(hs20_icon),
2708 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2709 hs20_icon_filename);
2710 osu_icon = "icon_orange_zxx.png";
2711 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2712 dut->ap_osu_method[0];
2713 osu_service_desc = NULL;
2714 break;
2715 default:
2716 break;
2717 }
2718
2719 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03002720 if (dut->ap_tag_ssid[0][0] &&
2721 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002722 dut->ap_osu_ssid) != 0 &&
2723 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002724 sigma_dut_print(dut, DUT_MSG_ERROR,
2725 "OSU_SSID and WLAN_TAG2 SSID differ");
2726 return -2;
2727 }
2728
2729 snprintf(buf, sizeof(buf), "'\"%s\"'",
2730 dut->ap_osu_ssid);
2731 } else {
2732 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2733 }
2734
2735 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2736
2737
2738 if (osu_friendly_name)
2739 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2740 osu_friendly_name);
2741 if (osu_service_desc)
2742 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2743 osu_service_desc);
2744 if (osu_nai)
2745 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2746
2747 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2748
2749 if (osu_icon)
2750 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2751 osu_icon);
2752
2753 if (dut->ap_osu_provider_list > 100) {
2754 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2755 "0");
2756 } else {
2757 snprintf(buf, sizeof(buf), "%d", osu_method);
2758 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2759 buf);
2760 }
2761 }
2762
2763 return 0;
2764}
2765
2766
Jouni Malinen13701222019-02-19 12:10:53 +02002767static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2768 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002769{
2770 unsigned char bssid[ETH_ALEN];
2771 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2772 int preference = 0xff;
2773
Jouni Malinen13701222019-02-19 12:10:53 +02002774 if (get_hwaddr(ifname, bssid) < 0)
2775 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002776 snprintf(anqp_string, str_size,
2777 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2778 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2779 preference,
2780 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2781 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2782 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02002783 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002784}
2785
2786
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002787static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2788 size_t str_size, int wlan_tag)
2789{
Jouni Malinenf8984642017-10-12 00:02:37 +03002790 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002791 enum driver_type drv;
2792
2793 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002794 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2795 ifname = dut->hostapd_ifname;
2796 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002797 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2798 dut->ap_mode == AP_11ac) &&
2799 if_nametoindex("ath1") > 0)
2800 ifname = "ath1";
2801 else
2802 ifname = "ath0";
2803 } else if (drv == DRIVER_OPENWRT) {
2804 if (sigma_radio_ifname[0] &&
2805 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2806 ifname = "ath2";
2807 else if (sigma_radio_ifname[0] &&
2808 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2809 ifname = "ath1";
2810 else
2811 ifname = "ath0";
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02002812 } else if (drv == DRIVER_WIL6210) {
2813 ifname = get_main_ifname();
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002814 } else {
2815 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2816 dut->ap_mode == AP_11ac) &&
2817 if_nametoindex("wlan1") > 0)
2818 ifname = "wlan1";
2819 else
2820 ifname = "wlan0";
2821 }
2822
2823 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2824 /* Handle tagged-ifname only on OPENWRT for now */
2825 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08002826 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
2827 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03002828 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002829 } else {
2830 snprintf(ifname_str, str_size, "%s", ifname);
2831 }
2832}
2833
2834
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835static int owrt_ap_config_vap(struct sigma_dut *dut)
2836{
2837 char buf[256], *temp;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002838 int vap_id = 0, vap_count, i, j;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002839 const char *ifname;
2840 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002841
priyadharshini gowthaman73561262018-02-20 13:24:59 -08002842 if (sigma_radio_ifname[0] &&
2843 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2844 ifname = "ath2";
2845 else if (sigma_radio_ifname[0] &&
2846 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2847 ifname = "ath1";
2848 else
2849 ifname = "ath0";
2850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002851 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002852 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002853
2854 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2855 if (sigma_radio_ifname[vap_id] &&
2856 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2857 break;
2858 }
2859 if (vap_id == MAX_RADIO)
2860 continue;
2861
2862 /* Single VAP configuration */
2863 if (!dut->ap_is_dual)
2864 vap_id = vap_count;
2865
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002866 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2867 /*
2868 * We keep a separate array of ap_tag_ssid and
2869 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2870 * So j=0 => WLAN_TAG = 2
2871 */
2872 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002873
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002874 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
2875 (dut->ap_interface_5g || dut->ap_interface_2g)) {
2876 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
2877 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
2878 "%s-owe", dut->ap_ssid);
2879 }
2880
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002881 if (dut->ap_tag_ssid[j][0] == '\0')
2882 continue;
2883
2884 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2885 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2886 "device", buf);
2887 /* SSID */
2888 snprintf(buf, sizeof(buf), "\"%s\"",
2889 dut->ap_tag_ssid[j]);
2890 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2891 "ssid", buf);
2892
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002893 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
2894 dut->ap_tag_ssid[0][0] &&
2895 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
2896 /* OWE transition mode */
2897 snprintf(buf, sizeof(buf), "%s", ifname);
2898 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2899 "owe_transition_ifname", buf);
2900 }
2901
2902 if (dut->ap_key_mgmt == AP_OPEN &&
2903 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2904 /* OWE transition mode */
2905 snprintf(buf, sizeof(buf), "%s", ifname);
2906 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2907 "owe_transition_ifname", buf);
2908 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2909 "hidden", "1");
2910 }
2911
Jouni Malinen6be21c82018-08-01 18:47:24 +03002912 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002913 unsigned char self_mac[ETH_ALEN];
2914 char mac_str[20];
2915
2916 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2917 "mobility_domain",
2918 dut->ap_mobility_domain);
2919 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2920 "ft_over_ds", "0");
2921 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2922 "ieee80211r", "1");
2923 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2924 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02002925 if (get_hwaddr(sigma_radio_ifname[0],
2926 self_mac) < 0)
2927 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002928 snprintf(mac_str, sizeof(mac_str),
2929 "%02x:%02x:%02x:%02x:%02x:%02x",
2930 self_mac[0], self_mac[1], self_mac[2],
2931 self_mac[3], self_mac[4], self_mac[5]);
2932 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2933 "ap_macaddr", mac_str);
2934 snprintf(mac_str, sizeof(mac_str),
2935 "%02x%02x%02x%02x%02x%02x",
2936 self_mac[0], self_mac[1], self_mac[2],
2937 self_mac[3], self_mac[4], self_mac[5]);
2938 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2939 "r1_key_holder", mac_str);
2940 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2941 "ft_psk_generate_local", "1");
2942 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2943 "kh_key_hex",
2944 "000102030405060708090a0b0c0d0e0f");
2945 snprintf(mac_str, sizeof(mac_str),
2946 "%02x:%02x:%02x:%02x:%02x:%02x",
2947 dut->ft_bss_mac_list[0][0],
2948 dut->ft_bss_mac_list[0][1],
2949 dut->ft_bss_mac_list[0][2],
2950 dut->ft_bss_mac_list[0][3],
2951 dut->ft_bss_mac_list[0][4],
2952 dut->ft_bss_mac_list[0][5]);
2953 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2954 "ap2_macaddr", mac_str);
2955 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2956 "ap2_r1_key_holder", mac_str);
2957 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2958 "nasid2", "nas2.example.com");
2959 }
2960
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002961 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
2962 wlan_tag == 2) {
2963 /* Only supported for WLAN_TAG=2 */
2964 owrt_ap_set_vap(dut, vap_count + 1, "osen",
2965 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002966 snprintf(buf, sizeof(buf), "wpa2");
2967 owrt_ap_set_vap(dut, vap_count + 1,
2968 "encryption", buf);
2969 snprintf(buf, sizeof(buf), "%s",
2970 dut->ap2_radius_ipaddr);
2971 owrt_ap_set_vap(dut, vap_count + 1,
2972 "auth_server", buf);
2973 snprintf(buf, sizeof(buf), "%d",
2974 dut->ap2_radius_port);
2975 owrt_ap_set_vap(dut, vap_count + 1,
2976 "auth_port", buf);
2977 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002978 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002979 owrt_ap_set_vap(dut, vap_count + 1,
2980 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002981 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
2982 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2983 "encryption", "psk2+ccmp");
2984 snprintf(buf, sizeof(buf), "\"%s\"",
2985 dut->ap_passphrase);
2986 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2987 "key", buf);
2988 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002989 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002990 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002991 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2992 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2993 "owe", "1");
2994 snprintf(buf, sizeof(buf), "ccmp");
2995 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2996 "encryption", buf);
2997 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2998 "ieee80211w", "2");
2999 if (dut->ap_sae_groups) {
3000 snprintf(buf, sizeof(buf), "\'%s\'",
3001 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003002 owrt_ap_set_list_vap(dut, vap_count +
3003 (wlan_tag - 1),
3004 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003005 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003006 }
3007 }
3008
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003009 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003010 if (dut->program == PROGRAM_MBO &&
3011 get_driver_type() == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003012 unsigned char self_mac[ETH_ALEN];
3013 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003014 char anqp_string[200];
3015
Jouni Malinen13701222019-02-19 12:10:53 +02003016 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3017 anqp_string,
3018 sizeof(anqp_string)) < 0)
3019 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003020 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3021 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003022
Jouni Malinen6be21c82018-08-01 18:47:24 +03003023 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003024 owrt_ap_set_vap(dut, vap_count,
3025 "mobility_domain",
3026 dut->ap_mobility_domain);
3027 owrt_ap_set_vap(dut, vap_count,
3028 "ft_over_ds", "0");
3029 owrt_ap_set_vap(dut, vap_count,
3030 "ieee80211r", "1");
3031 owrt_ap_set_vap(dut, vap_count,
3032 "nasid", "nas1.example.com");
3033 get_hwaddr(sigma_radio_ifname[0], self_mac);
3034 snprintf(mac_str, sizeof(mac_str),
3035 "%02x:%02x:%02x:%02x:%02x:%02x",
3036 self_mac[0], self_mac[1], self_mac[2],
3037 self_mac[3], self_mac[4], self_mac[5]);
3038 owrt_ap_set_vap(dut, vap_count,
3039 "ap_macaddr", mac_str);
3040 snprintf(mac_str, sizeof(mac_str),
3041 "%02x%02x%02x%02x%02x%02x",
3042 self_mac[0], self_mac[1], self_mac[2],
3043 self_mac[3], self_mac[4], self_mac[5]);
3044 owrt_ap_set_vap(dut, vap_count,
3045 "r1_key_holder", mac_str);
3046 owrt_ap_set_vap(dut, vap_count,
3047 "ft_psk_generate_local", "1");
3048 owrt_ap_set_vap(dut, vap_count,
3049 "kh_key_hex",
3050 "000102030405060708090a0b0c0d0e0f");
3051 snprintf(mac_str, sizeof(mac_str),
3052 "%02x:%02x:%02x:%02x:%02x:%02x",
3053 dut->ft_bss_mac_list[0][0],
3054 dut->ft_bss_mac_list[0][1],
3055 dut->ft_bss_mac_list[0][2],
3056 dut->ft_bss_mac_list[0][3],
3057 dut->ft_bss_mac_list[0][4],
3058 dut->ft_bss_mac_list[0][5]);
3059 owrt_ap_set_vap(dut, vap_count,
3060 "ap2_macaddr", mac_str);
3061 owrt_ap_set_vap(dut, vap_count,
3062 "ap2_r1_key_holder", mac_str);
3063 owrt_ap_set_vap(dut, vap_count,
3064 "nasid2", "nas2.example.com");
3065 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003066 }
3067
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003068 if (dut->ap_oce == VALUE_ENABLED &&
3069 get_driver_type() == DRIVER_OPENWRT) {
3070 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3071 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3072 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3073
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003074 if (dut->ap_80plus80 == 1)
3075 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3076
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003077 if (dut->ap_akm == 1) {
3078 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3079 "3600");
3080 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3081 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3082 "1");
3083 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3084 "1234");
3085 owrt_ap_set_vap(dut, vap_id,
3086 "erp_send_reauth_start", "1");
3087 }
3088
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003089 if (dut->ap_filshlp == VALUE_ENABLED) {
3090 struct ifreq ifr;
3091 char *ifname;
3092 int s;
3093 struct sockaddr_in *ipaddr;
3094
3095 s = socket(AF_INET, SOCK_DGRAM, 0);
3096 if (s < 0) {
3097 sigma_dut_print(dut, DUT_MSG_ERROR,
3098 "Failed to open socket");
3099 return -1;
3100 }
3101 ifr.ifr_addr.sa_family = AF_INET;
3102
3103 memset(&ifr, 0, sizeof(ifr));
3104 ifname = "br-lan";
3105 strlcpy(ifr.ifr_name, ifname,
3106 sizeof(ifr.ifr_name));
3107 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3108 perror("ioctl");
3109 close(s);
3110 return -1;
3111 }
3112
3113 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3114 snprintf(buf, sizeof(buf), "%s",
3115 inet_ntoa(ipaddr->sin_addr));
3116 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3117 buf);
3118 snprintf(buf, sizeof(buf), "%s",
3119 dut->ap_dhcpserv_ipaddr);
3120 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3121 buf);
3122 owrt_ap_set_vap(dut, vap_id,
3123 "dhcp_rapid_commit_proxy", "1");
3124 owrt_ap_set_vap(dut, vap_id,
3125 "fils_hlp_wait_time", "300");
3126 }
3127
3128 if (dut->ap_filsdscv == VALUE_ENABLED) {
3129 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3130 "1");
3131 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3132 "20");
3133 }
3134 }
3135
3136 if (dut->ap_filsdscv == VALUE_DISABLED) {
3137 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3138 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3139 }
3140
3141 if (dut->ap_oce == VALUE_DISABLED &&
3142 get_driver_type() == DRIVER_OPENWRT) {
3143 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3144 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3145 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3146
3147 if (dut->ap_filsdscv == VALUE_DISABLED) {
3148 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3149 "0");
3150 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3151 "0");
3152 }
3153
3154 if (dut->device_type == AP_testbed)
3155 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3156 }
3157
3158 /* NAIRealm */
3159 if (dut->ap_nairealm_int == 1) {
3160 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3161 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3162 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3163 }
3164
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003165 /* SSID */
3166 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3167 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3168
3169 /* Encryption */
3170 switch (dut->ap_key_mgmt) {
3171 case AP_OPEN:
3172 if (dut->ap_cipher == AP_WEP) {
3173 owrt_ap_set_vap(dut, vap_count, "encryption",
3174 "wep-mixed");
3175 owrt_ap_set_vap(dut, vap_count, "key",
3176 dut->ap_wepkey);
3177 } else {
3178 owrt_ap_set_vap(dut, vap_count, "encryption",
3179 "none");
3180 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003181 if (dut->ap_key_mgmt == AP_OPEN &&
3182 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3183 /* OWE transition mode */
3184 snprintf(ifname2, sizeof(ifname2), "%s1",
3185 ifname);
3186 owrt_ap_set_vap(dut, vap_count,
3187 "owe_transition_ifname",
3188 ifname2);
3189 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003190 break;
3191 case AP_WPA2_PSK:
3192 case AP_WPA2_PSK_MIXED:
3193 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003194 case AP_WPA2_SAE:
3195 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003196 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3197 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003198 snprintf(buf, sizeof(buf), "psk2");
3199 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3200 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003201 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3202 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003203 } else {
3204 snprintf(buf, sizeof(buf), "psk");
3205 }
3206
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003207 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3208 if (dut->ap_cipher == AP_CCMP_TKIP)
3209 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3210 else if (dut->ap_cipher == AP_TKIP)
3211 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003212 else if (dut->ap_cipher == AP_GCMP_128)
3213 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003214 else
3215 strlcat(buf, "+ccmp", sizeof(buf));
3216 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003217
3218 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003219
3220 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3221 snprintf(buf, sizeof(buf), "\"%s\"",
3222 dut->ap_psk);
3223 owrt_ap_set_vap(dut, vap_count, "key", buf);
3224 } else {
3225 snprintf(buf, sizeof(buf), "\"%s\"",
3226 dut->ap_passphrase);
3227 owrt_ap_set_vap(dut, vap_count, "key", buf);
3228 }
3229
3230 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3231 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3232 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3233 else
3234 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3235
3236 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3237 snprintf(buf, sizeof(buf), "%s",
3238 dut->ap_passphrase);
3239 owrt_ap_set_vap(dut, vap_count, "sae_password",
3240 buf);
3241 } else {
3242 snprintf(buf, sizeof(buf), "%s",
3243 dut->ap_passphrase);
3244 owrt_ap_set_vap(dut, vap_count,
3245 "wpa_passphrase", buf);
3246 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003247 break;
3248 case AP_WPA2_EAP:
3249 case AP_WPA2_EAP_MIXED:
3250 case AP_WPA_EAP:
3251 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3252 snprintf(buf, sizeof(buf), "wpa2");
3253 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3254 snprintf(buf, sizeof(buf), "wpa-mixed");
3255 } else {
3256 snprintf(buf, sizeof(buf), "wpa");
3257 }
3258
Peng Xu591be452017-05-10 17:27:28 -07003259 if (dut->ap_cipher == AP_CCMP_TKIP)
3260 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3261 else if (dut->ap_cipher == AP_TKIP)
3262 strlcat(buf, "+tkip", sizeof(buf));
3263 else
3264 strlcat(buf, "+ccmp", sizeof(buf));
3265
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003266 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3267 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3268 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3269 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3270 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3271 snprintf(buf, sizeof(buf), "%s",
3272 dut->ap_radius_password);
3273 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3274 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003275 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003276 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003277 case AP_WPA2_FT_EAP:
3278 case AP_WPA2_FT_PSK:
3279 case AP_WPA2_EAP_SHA256:
3280 case AP_WPA2_PSK_SHA256:
3281 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003282 /* TODO */
3283 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003284 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003285 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3286 snprintf(buf, sizeof(buf), "gcmp");
3287 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3288 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3289 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3290 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3291 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3292 snprintf(buf, sizeof(buf), "%s",
3293 dut->ap_radius_password);
3294 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3295 snprintf(buf, sizeof(buf), "%d",
3296 dut->ap_group_mgmt_cipher);
3297 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3298 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003299 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003300 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003301 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3302 snprintf(buf, sizeof(buf), "ccmp");
3303 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3304 if (dut->ap_sae_groups) {
3305 snprintf(buf, sizeof(buf), "\'%s\'",
3306 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003307 owrt_ap_set_list_vap(dut, vap_count,
3308 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003309 }
3310
3311 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3312 dut->ap_tag_ssid[0][0] &&
3313 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3314 /* OWE transition mode */
3315 snprintf(ifname2, sizeof(ifname2), "%s1",
3316 ifname);
3317 owrt_ap_set_vap(dut, vap_count,
3318 "owe_transition_ifname",
3319 ifname2);
3320 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3321 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003322 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003323 }
3324
3325 if (!dut->ap_is_dual)
3326 break;
3327 }
3328
3329 if (dut->ap_is_dual)
3330 return 1;
3331
3332 /* PMF */
3333 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3334 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3335
3336 /* Add SHA256 */
3337 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3338 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3339
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003340 /* Add SHA384 for akmsuitetype 15 */
3341 if (dut->ap_akm == 1) {
3342 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3343 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3344 }
3345
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303346 /* Enable RSN preauthentication, if asked to */
3347 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3348 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3349
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003350 /* Hotspot 2.0 */
3351 if (dut->ap_hs2) {
3352 int ret;
3353
3354 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3355 if (ret)
3356 return ret;
3357 }
3358
3359 /* Interworking */
3360 if (dut->ap_interworking) {
3361 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3362 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3363 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3364 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3365 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3366 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3367 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3368 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3369 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3370 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3371
3372 if (dut->ap_gas_cb_delay > 0) {
3373 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3374 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3375 }
3376
3377 if (dut->ap_roaming_cons[0]) {
3378 char *rcons, *temp_ptr;
3379
3380 rcons = strdup(dut->ap_roaming_cons);
3381 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003382 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003383
3384 temp_ptr = strchr(rcons, ';');
3385
3386 if (temp_ptr)
3387 *temp_ptr++ = '\0';
3388
3389 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3390 rcons);
3391
3392 if (temp_ptr)
3393 owrt_ap_set_list_vap(dut, vap_id,
3394 "roaming_consortium",
3395 temp_ptr);
3396
3397 free(rcons);
3398 }
3399 }
3400
3401 if (dut->ap_venue_name) {
3402 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3403 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3404 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3405 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3406 }
3407
3408 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003409 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3410 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003411 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003412 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003413 }
3414
3415 if (dut->ap_nai_realm_list == 1) {
3416 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3417 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3418 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3419 "'0,wi-fi.org;example.com,13[5:6]'");
3420
3421 } else if (dut->ap_nai_realm_list == 2) {
3422 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3423 "'0,wi-fi.org,21[2:4][5:7]'");
3424 } else if (dut->ap_nai_realm_list == 3) {
3425 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3426 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3427 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3428 "'0,wi-fi.org;example.com,13[5:6]'");
3429 } else if (dut->ap_nai_realm_list == 4) {
3430 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3431 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3432 } else if (dut->ap_nai_realm_list == 5) {
3433 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3434 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3435 } else if (dut->ap_nai_realm_list == 6) {
3436 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3437 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3438 } else if (dut->ap_nai_realm_list == 7) {
3439 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3440 "'0,wi-fi.org,13[5:6]'");
3441 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3442 "'0,wi-fi.org,21[2:4][5:7]'");
3443 }
3444
3445 if (dut->ap_domain_name_list[0])
3446 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3447 dut->ap_domain_name_list);
3448
3449 if (dut->ap_ip_addr_type_avail)
3450 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3451 "'0c'");
3452
3453 temp = buf;
3454
3455 *temp++ = '\'';
3456
3457 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3458 if (i)
3459 *temp++ = ';';
3460
3461 snprintf(temp,
3462 sizeof(dut->ap_plmn_mcc[i]) +
3463 sizeof(dut->ap_plmn_mnc[i]) + 1,
3464 "%s,%s",
3465 dut->ap_plmn_mcc[i],
3466 dut->ap_plmn_mnc[i]);
3467
3468 temp += strlen(dut->ap_plmn_mcc[i]) +
3469 strlen(dut->ap_plmn_mnc[i]) + 1;
3470 }
3471
3472 *temp++ = '\'';
3473 *temp++ = '\0';
3474
3475 if (i)
3476 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3477
3478 if (dut->ap_qos_map_set == 1)
3479 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3480 else if (dut->ap_qos_map_set == 2)
3481 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3482
3483 /* Proxy-ARP */
3484 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3485 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3486
3487 /* DGAF */
3488 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3489 /* parse to hostapd */
3490 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3491 /* parse to wifi driver */
3492 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3493
3494 /* HCBSSLoad */
3495 if (dut->ap_bss_load) {
3496 unsigned int bssload = 0;
3497
3498 if (dut->ap_bss_load == 1) {
3499 /* STA count: 1, CU: 50, AAC: 65535 */
3500 bssload = 0x0132ffff;
3501 } else if (dut->ap_bss_load == 2) {
3502 /* STA count: 1, CU: 200, AAC: 65535 */
3503 bssload = 0x01c8ffff;
3504 } else if (dut->ap_bss_load == 3) {
3505 /* STA count: 1, CU: 75, AAC: 65535 */
3506 bssload = 0x014bffff;
3507 }
3508
3509 snprintf(buf, sizeof(buf), "%d", bssload);
3510 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3511 }
3512
3513 /* L2TIF */
3514 if (dut->ap_l2tif)
3515 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3516
3517 if (dut->ap_disable_protection == 1)
3518 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3519
Sunil Dutt77b213d2017-09-14 18:24:40 +03003520 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003521 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3522 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
3523 }
3524
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05303525 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003526 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003527
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303528 if (dut->ap_tx_stbc) {
3529 /* STBC and beamforming are mutually exclusive features */
3530 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3531 }
3532
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303533 /* enable dfsmode */
3534 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3535 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3536
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003537 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3538 char anqpval[1024];
3539
3540 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3541
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003542 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303543 snprintf(anqpval, sizeof(anqpval),
3544 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003545 dut->ap_val_lci, dut->ap_infoz);
3546 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3547 }
3548
3549 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303550 snprintf(anqpval, sizeof(anqpval),
3551 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003552 dut->ap_val_lcr);
3553 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3554 }
3555
3556 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
3557 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3558 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
3559 }
3560
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003561 if (dut->program == PROGRAM_MBO) {
3562 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3563 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3564 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07003565 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003566
3567 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3568 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07003569 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3570 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003571 }
3572
Jouni Malinen6be21c82018-08-01 18:47:24 +03003573 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003574 unsigned char self_mac[ETH_ALEN];
3575 char mac_str[20];
3576
3577 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
3578 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02003579 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
3580 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003581 snprintf(mac_str, sizeof(mac_str),
3582 "%02x:%02x:%02x:%02x:%02x:%02x",
3583 self_mac[0], self_mac[1], self_mac[2],
3584 self_mac[3], self_mac[4], self_mac[5]);
3585 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003586 snprintf(mac_str, sizeof(mac_str),
3587 "%02x:%02x:%02x:%02x:%02x:%02x",
3588 self_mac[0], self_mac[1], self_mac[2],
3589 self_mac[3], self_mac[4], self_mac[5]);
3590 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003591 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
3592 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
3593 "000102030405060708090a0b0c0d0e0f");
3594 snprintf(mac_str, sizeof(mac_str),
3595 "%02x:%02x:%02x:%02x:%02x:%02x",
3596 dut->ft_bss_mac_list[0][0],
3597 dut->ft_bss_mac_list[0][1],
3598 dut->ft_bss_mac_list[0][2],
3599 dut->ft_bss_mac_list[0][3],
3600 dut->ft_bss_mac_list[0][4],
3601 dut->ft_bss_mac_list[0][5]);
3602 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003603 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
3604 dut->ap_mobility_domain);
3605 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003606 }
3607
Jouni Malinen6be21c82018-08-01 18:47:24 +03003608 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
3609 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003610 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
3611 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003612 }
3613
Jouni Malinen6be21c82018-08-01 18:47:24 +03003614 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003615 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
3616 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003617 }
3618
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003619 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
3620 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
3621
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003622 /* Enable/disable PMKSA caching, if asked to */
3623 if (dut->ap_pmksa == 1) {
3624 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
3625 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
3626 }
3627
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003628 if (dut->rsne_override) {
3629 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
3630 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
3631 }
3632
3633 if (dut->sae_commit_override) {
3634 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
3635 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
3636 }
3637
3638 if (dut->ap_sae_groups) {
3639 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003640 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003641 }
3642
3643 if (dut->sae_anti_clogging_threshold >= 0) {
3644 snprintf(buf, sizeof(buf), "%d",
3645 dut->sae_anti_clogging_threshold);
3646 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
3647 buf);
3648 }
3649
3650 if (dut->sae_reflection)
3651 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
3652
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003653 return 1;
3654}
3655
3656
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003657static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
3658{
3659 char anqpval[1024];
3660 unsigned char addr[6];
3661 unsigned char addr2[6];
3662 struct ifreq ifr;
3663 char *ifname;
3664 int s;
3665 int vap_id = 0;
3666
3667 s = socket(AF_INET, SOCK_DGRAM, 0);
3668 if (s < 0) {
3669 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
3670 return -1;
3671 }
3672
3673 memset(&ifr, 0, sizeof(ifr));
3674 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003675 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003676 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3677 perror("ioctl");
3678 close(s);
3679 return -1;
3680 }
3681 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
3682
3683 memset(&ifr, 0, sizeof(ifr));
3684 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003685 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003686 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3687 perror("ioctl");
3688 close(s);
3689 return -1;
3690 }
3691 close(s);
3692 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
3693
3694 snprintf(anqpval, sizeof(anqpval),
3695 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
3696 dut->ap_val_lci, dut->ap_infoz,
3697 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
3698 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
3699
3700 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3701 return 0;
3702}
3703
3704
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003705static int owrt_ap_post_config_commit(struct sigma_dut *dut,
3706 struct sigma_conn *conn,
3707 struct sigma_cmd *cmd)
3708{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003709 int ap_security = 0;
3710 int i;
3711
3712 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
3713 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
3714 ap_security = 1;
3715 }
3716 if (dut->ap_key_mgmt != AP_OPEN)
3717 ap_security = 1;
3718 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003719 /* allow some time for hostapd to start before returning
3720 * success */
3721 usleep(500000);
3722
3723 if (run_hostapd_cli(dut, "ping") != 0) {
3724 send_resp(dut, conn, SIGMA_ERROR,
3725 "errorCode,Failed to talk to hostapd");
3726 return 0;
3727 }
3728 }
3729
3730 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
3731 ath_ap_set_params(dut);
3732
3733 /* Send response */
3734 return 1;
3735}
3736
3737
3738static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
3739 struct sigma_conn *conn,
3740 struct sigma_cmd *cmd)
3741{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08003742 if (dut->program == PROGRAM_DPP &&
3743 get_driver_type() == DRIVER_OPENWRT) {
3744 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
3745 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
3746 }
3747
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003748 /* Stop the AP */
3749 run_system(dut, "wifi down");
3750
3751 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05303752 run_system(dut, "rm -rf /etc/config/wireless");
3753 switch (get_openwrt_driver_type()) {
3754 case OPENWRT_DRIVER_ATHEROS:
3755 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
3756 break;
3757 default:
3758 run_system(dut, "wifi detect > /etc/config/wireless");
3759 break;
3760 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003761
3762 /* Configure Radio & VAP, commit the config */
3763 owrt_ap_config_radio(dut);
Jouni Malinen13701222019-02-19 12:10:53 +02003764 if (owrt_ap_config_vap(dut) < 0)
3765 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003766 run_system(dut, "uci commit");
3767
3768 /* Start AP */
3769 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003770 if (dut->program != PROGRAM_MBO &&
3771 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003772 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003773 /*
3774 * MBO has a different ANQP element value which is set in
3775 * owrt_ap_config_vap().
3776 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003777 owrt_ap_config_vap_anqp(dut);
3778 run_system(dut, "uci commit");
3779 run_system(dut, "wifi");
3780 }
3781
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003782 return owrt_ap_post_config_commit(dut, conn, cmd);
3783}
3784
3785
3786static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
3787{
3788 unsigned char bssid[6];
3789 char buf[100];
3790 char *ifname, *radio_name;
3791 int vap_id = 0;
3792
3793 if (sigma_radio_ifname[0] &&
3794 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3795 ifname = "ath2";
3796 radio_name = "wifi2";
3797 vap_id = 2;
3798 } else if (sigma_radio_ifname[0] &&
3799 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3800 ifname = "ath1";
3801 radio_name = "wifi1";
3802 vap_id = 1;
3803 } else {
3804 ifname = "ath0";
3805 radio_name = "wifi0";
3806 vap_id = 0;
3807 }
3808
3809 if (!get_hwaddr(ifname, bssid)) {
3810 snprintf(buf, sizeof(buf), "%s", bssid);
3811 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3812 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3813 "%02x:%02x:%02x:%02x:%02x:%02x",
3814 bssid[0], bssid[1], bssid[2], bssid[3],
3815 bssid[4], bssid[5]);
3816 } else {
3817 if (!get_hwaddr(radio_name, bssid)) {
3818 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3819 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3820 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3821 "%02x:%02x:%02x:%02x:%02x:%02x",
3822 bssid[0], bssid[1], bssid[2], bssid[3],
3823 bssid[4], bssid[5]);
3824 } else {
3825 /* Select & enable/disable radios */
3826 if (sigma_radio_ifname[0] &&
3827 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3828 /* We want to use wifi2 */
3829 owrt_ap_set_radio(dut, 0, "disabled", "1");
3830 owrt_ap_set_radio(dut, 1, "disabled", "1");
3831 owrt_ap_set_radio(dut, 2, "disabled", "0");
3832 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
3833 } else if (sigma_radio_ifname[0] &&
3834 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3835 /* We want to use wifi1 */
3836 owrt_ap_set_radio(dut, 0, "disabled", "1");
3837 owrt_ap_set_radio(dut, 1, "disabled", "0");
3838 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
3839 } else {
3840 /* We want to use wifi0 */
3841 owrt_ap_set_radio(dut, 0, "disabled", "0");
3842 owrt_ap_set_radio(dut, 1, "disabled", "1");
3843 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
3844 }
3845
3846 run_system(dut, "uci commit");
3847 run_system(dut, "wifi up");
3848
3849 if (!get_hwaddr(radio_name, bssid)) {
3850 snprintf(buf, sizeof(buf), "%s",
3851 dut->ap_hessid);
3852 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3853 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3854 "%02x:%02x:%02x:%02x:%02x:%02x",
3855 bssid[0], bssid[1], bssid[2], bssid[3],
3856 bssid[4], bssid[5]);
3857 }
3858 }
3859 }
3860}
3861
3862
3863static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
3864 struct sigma_cmd *cmd)
3865{
3866 switch (get_driver_type()) {
3867 case DRIVER_ATHEROS:
3868 run_system(dut, "apdown");
3869 sleep(1);
3870 run_system(dut, "reboot");
3871 break;
3872 case DRIVER_OPENWRT:
3873 run_system(dut, "wifi down");
3874 sleep(1);
3875 run_system(dut, "reboot");
3876 break;
3877 default:
3878 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
3879 break;
3880 }
3881
3882 return 1;
3883}
3884
3885
3886int ascii2hexstr(const char *str, char *hex)
3887{
3888 int i, length;
3889
3890 length = strlen(str);
3891
3892 for (i = 0; i < length; i++)
3893 snprintf(hex + i * 2, 3, "%X", str[i]);
3894
3895 hex[length * 2] = '\0';
3896 return 1;
3897}
3898
3899
3900static int kill_process(struct sigma_dut *dut, char *proc_name,
3901 unsigned char is_proc_instance_one, int sig)
3902{
3903#ifdef __linux__
3904 struct dirent *dp, *dp_in;
3905 const char *direc = "/proc/";
3906 char buf[100];
3907 DIR *dir = opendir(direc);
3908 DIR *dir_in;
3909 FILE *fp;
3910 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303911 char *saveptr;
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303912 int ret = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003913
3914 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303915 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003916
3917 while ((dp = readdir(dir)) != NULL) {
3918 if (dp->d_type != DT_DIR)
3919 continue;
3920
3921 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
3922 dir_in = opendir(buf);
3923 if (dir_in == NULL)
3924 continue;
3925 dp_in = readdir(dir_in);
3926 closedir(dir_in);
3927 if (dp_in == NULL)
3928 continue;
3929 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
3930 fp = fopen(buf, "r");
3931 if (fp == NULL)
3932 continue;
3933 if (fgets(buf, 100, fp) == NULL)
3934 buf[0] = '\0';
3935 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303936 pid = strtok_r(buf, " ", &saveptr);
3937 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003938 if (pid && temp &&
3939 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
3940 sigma_dut_print(dut, DUT_MSG_INFO,
3941 "killing %s process with PID %s",
3942 proc_name, pid);
3943 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
3944 atoi(pid));
3945 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303946 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003947 if (is_proc_instance_one)
3948 break;
3949 }
3950 }
3951
3952 closedir(dir);
3953
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303954 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003955#else /* __linux__ */
3956 return -1;
3957#endif /* __linux__ */
3958}
3959
3960
3961static int run_ndc(struct sigma_dut *dut, char *buf)
3962{
3963 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
3964 sleep(2);
3965 return run_system(dut, buf);
3966}
3967
3968
3969static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
3970 const char *field, const char *value)
3971{
3972 FILE *fcfg, *ftmp;
3973 char buf[MAX_CONF_LINE_LEN + 1];
3974 int len, found = 0, res;
3975
3976 /* Open the configuration file */
3977 fcfg = fopen(pfile, "r");
3978 if (!fcfg) {
3979 sigma_dut_print(dut, DUT_MSG_ERROR,
3980 "Failed to open hostapd conf file");
3981 return -1;
3982 }
3983
3984 snprintf(buf, sizeof(buf), "%s~", pfile);
3985 /* Open a temporary file */
3986 ftmp = fopen(buf, "w+");
3987 if (!ftmp) {
3988 fclose(fcfg);
3989 sigma_dut_print(dut, DUT_MSG_ERROR,
3990 "Failed to open temp buf");
3991 return -1;
3992 }
3993
3994 /* Read the values from the configuration file */
3995 len = strlen(field);
3996 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
3997 char *pline = buf;
3998
3999 /* commented line */
4000 if (buf[0] == '#')
4001 pline++;
4002
4003 /* Identify the configuration parameter to be updated */
4004 if (!found && strncmp(pline, field, len) == 0 &&
4005 pline[len] == '=') {
4006 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4007 found = 1;
4008 sigma_dut_print(dut, DUT_MSG_INFO,
4009 "Updated hostapd conf file");
4010 }
4011
4012 fprintf(ftmp, "%s", buf);
4013 }
4014
4015 if (!found) {
4016 /* Configuration line not found */
4017 /* Add the new line at the end of file */
4018 fprintf(ftmp, "%s=%s\n", field, value);
4019 sigma_dut_print(dut, DUT_MSG_INFO,
4020 "Adding a new line in hostapd conf file");
4021 }
4022
4023 fclose(fcfg);
4024 fclose(ftmp);
4025
4026 snprintf(buf, sizeof(buf), "%s~", pfile);
4027
4028 /* Restore the updated configuration file */
4029 res = rename(buf, pfile);
4030
4031 /* Remove the temporary file. Ignore the return value */
4032 unlink(buf);
4033
4034 /* chmod is needed because open() may not set permissions properly
4035 * depending on the current umask */
4036 if (chmod(pfile, 0660) < 0) {
4037 unlink(pfile);
4038 sigma_dut_print(dut, DUT_MSG_ERROR,
4039 "Error changing permissions");
4040 return -1;
4041 }
4042
4043 if (res < 0) {
4044 sigma_dut_print(dut, DUT_MSG_ERROR,
4045 "Error restoring conf file");
4046 return -1;
4047 }
4048
4049 return 0;
4050}
4051
4052
4053static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4054 struct sigma_conn *conn,
4055 struct sigma_cmd *cmd)
4056{
4057 char buf[100];
4058 struct stat s;
4059 int num_tries = 0, ret;
4060
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304061 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4062 system("killall netd") == 0) {
4063 /* Avoid Error: Error connecting (Connection refused)
4064 * Wait some time to allow netd to reinitialize.
4065 */
4066 usleep(1500000);
4067 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004068
4069 while (num_tries < 10) {
4070 ret = run_ndc(dut, "ndc softap stopap");
4071 num_tries++;
4072 if (WIFEXITED(ret))
4073 ret = WEXITSTATUS(ret);
4074 /* On success, NDC exits with 0 */
4075 if (ret == 0)
4076 break;
4077 sigma_dut_print(dut, DUT_MSG_INFO,
4078 "Try No. %d: ndc softap stopap failed, exit code %d",
4079 num_tries, ret);
4080 }
4081
4082 if (ret != 0)
4083 sigma_dut_print(dut, DUT_MSG_ERROR,
4084 "ndc softap stopap command failed for 10 times - giving up");
4085
4086#ifdef ANDROID
4087 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304088 system("rmmod -f wlan");
4089 usleep(500000);
4090 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004091#else /* ANDROID */
4092 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4093 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4094#endif /* ANDROID */
4095
4096 switch (dut->ap_mode) {
4097 case AP_11g:
4098 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4099 break;
4100 case AP_11b:
4101 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4102 break;
4103 case AP_11ng:
4104 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4105 break;
4106 case AP_11a:
4107 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4108 break;
4109 case AP_11na:
4110 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4111 break;
4112 case AP_11ac:
4113 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4114 break;
4115 default:
4116 break;
4117 }
4118
4119 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4120 dut->ap_channel);
4121 run_ndc(dut, buf);
4122
4123 /*
4124 * ndc doesn't support double quotes as SSID string, so re-write
4125 * hostapd configuration file to update SSID.
4126 */
4127 if (dut->ap_ssid[0] != '\0')
4128 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4129
4130 switch (dut->ap_key_mgmt) {
4131 case AP_OPEN:
4132 if (dut->ap_cipher == AP_WEP) {
4133 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4134 snprintf(buf, sizeof(buf),
4135 "ndc softap qccmd set wep_key0=%s",
4136 dut->ap_wepkey);
4137 run_ndc(dut, buf);
4138 } else {
4139 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4140 }
4141 break;
4142 case AP_WPA2_PSK:
4143 case AP_WPA2_PSK_MIXED:
4144 case AP_WPA_PSK:
4145 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4146 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4147 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4148 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4149 else
4150 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4151
4152 /*
4153 * ndc doesn't support some special characters as passphrase,
4154 * so re-write hostapd configuration file to update Passphrase.
4155 */
4156 if (dut->ap_passphrase[0] != '\0')
4157 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4158 "wpa_passphrase", dut->ap_passphrase);
4159
4160 if (dut->ap_cipher == AP_CCMP_TKIP)
4161 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4162 "TKIP CCMP");
4163 else if (dut->ap_cipher == AP_TKIP)
4164 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4165 "TKIP");
4166 else
4167 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4168 "CCMP &");
4169 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004170 case AP_WPA2_SAE:
4171 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004172 case AP_WPA2_EAP:
4173 case AP_WPA2_EAP_MIXED:
4174 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004175 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004176 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004177 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004178 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004179 case AP_WPA2_FT_EAP:
4180 case AP_WPA2_FT_PSK:
4181 case AP_WPA2_EAP_SHA256:
4182 case AP_WPA2_PSK_SHA256:
4183 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004184 /* Not supported */
4185 break;
4186 }
4187
4188 switch (dut->ap_pmf) {
4189 case AP_PMF_DISABLED:
4190 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4191 break;
4192 case AP_PMF_OPTIONAL:
4193 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4194 if (dut->ap_add_sha256)
4195 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4196 else
4197 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4198 break;
4199 case AP_PMF_REQUIRED:
4200 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4201 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4202 break;
4203 }
4204
4205 if (dut->ap_countrycode[0]) {
4206 snprintf(buf, sizeof(buf),
4207 "ndc softap qccmd set country_code=%s",
4208 dut->ap_countrycode);
4209 run_ndc(dut, buf);
4210 }
4211
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304212 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4213 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4214
4215 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4216 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4217
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004218 run_ndc(dut, "ndc softap startap");
4219
4220 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
4221 num_tries = 0;
4222 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4223 run_ndc(dut, "ndc softap stopap");
4224 run_ndc(dut, "ndc softap startap");
4225 num_tries++;
4226 }
4227
4228 if (num_tries == 10) {
4229 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4230 "iface %s :: reboot the APDUT", buf);
4231 return ret;
4232 }
4233
4234 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4235 ap_inet_addr, ap_inet_mask);
4236 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
4237 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
4238 if (system(buf) != 0) {
4239 sigma_dut_print(dut, DUT_MSG_ERROR,
4240 "Failed to intialize the interface");
4241 return -1;
4242 }
4243
4244 return 1;
4245}
4246
4247
4248static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4249{
4250 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4251 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4252
4253 if (dut->ap_oper_name) {
4254 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4255 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4256 }
4257
4258 if (dut->ap_wan_metrics == 1)
4259 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4260 else if (dut->ap_wan_metrics == 2)
4261 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4262 else if (dut->ap_wan_metrics == 3)
4263 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4264 else if (dut->ap_wan_metrics == 4)
4265 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4266 else if (dut->ap_wan_metrics == 5)
4267 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4268
4269 if (dut->ap_conn_capab == 1) {
4270 fprintf(f, "hs20_conn_capab=1:0:0\n");
4271 fprintf(f, "hs20_conn_capab=6:20:1\n");
4272 fprintf(f, "hs20_conn_capab=6:22:0\n");
4273 fprintf(f, "hs20_conn_capab=6:80:1\n");
4274 fprintf(f, "hs20_conn_capab=6:443:1\n");
4275 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4276 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4277 fprintf(f, "hs20_conn_capab=17:500:1\n");
4278 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4279 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4280 fprintf(f, "hs20_conn_capab=50:0:1\n");
4281 } else if (dut->ap_conn_capab == 2) {
4282 fprintf(f, "hs20_conn_capab=6:80:1\n");
4283 fprintf(f, "hs20_conn_capab=6:443:1\n");
4284 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4285 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4286 } else if (dut->ap_conn_capab == 3) {
4287 fprintf(f, "hs20_conn_capab=6:80:1\n");
4288 fprintf(f, "hs20_conn_capab=6:443:1\n");
4289 } else if (dut->ap_conn_capab == 4) {
4290 fprintf(f, "hs20_conn_capab=6:80:1\n");
4291 fprintf(f, "hs20_conn_capab=6:443:1\n");
4292 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4293 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4294 }
4295
4296 if (dut->ap_oper_class == 1)
4297 fprintf(f, "hs20_operating_class=51\n");
4298 else if (dut->ap_oper_class == 2)
4299 fprintf(f, "hs20_operating_class=73\n");
4300 else if (dut->ap_oper_class == 3)
4301 fprintf(f, "hs20_operating_class=5173\n");
4302
4303 if (dut->ap_osu_provider_list) {
4304 char *osu_friendly_name = NULL;
4305 char *osu_icon = NULL;
4306 char *osu_ssid = NULL;
4307 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004308 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004309 char *osu_service_desc = NULL;
4310 char *hs20_icon_filename = NULL;
4311 char hs20_icon[150];
4312 int osu_method;
4313
4314 hs20_icon_filename = "icon_red_zxx.png";
4315 if (dut->ap_osu_icon_tag == 2)
4316 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4317 snprintf(hs20_icon, sizeof(hs20_icon),
4318 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4319 hs20_icon_filename);
4320 osu_icon = "icon_red_zxx.png";
4321 osu_ssid = "OSU";
4322 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4323 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4324 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4325
4326 if (strlen(dut->ap_osu_server_uri[0]))
4327 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4328 else
4329 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4330
4331 switch (dut->ap_osu_provider_list) {
4332 case 1:
4333 case 101:
4334 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4335 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4336 hs20_icon_filename = "icon_red_eng.png";
4337 if (dut->ap_osu_icon_tag == 2)
4338 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4339 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4340 hs20_icon_filename);
4341 fprintf(f, "osu_icon=icon_red_eng.png\n");
4342 break;
4343 case 2:
4344 case 102:
4345 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4346 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4347 hs20_icon_filename = "icon_orange_zxx.png";
4348 if (dut->ap_osu_icon_tag == 2)
4349 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4350 snprintf(hs20_icon, sizeof(hs20_icon),
4351 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4352 hs20_icon_filename);
4353 osu_icon = "icon_orange_zxx.png";
4354 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4355 break;
4356 case 3:
4357 case 103:
4358 osu_friendly_name = "spa:SP Red Test Only";
4359 osu_service_desc = "spa:Free service for test purpose";
4360 break;
4361 case 4:
4362 case 104:
4363 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4364 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4365 hs20_icon_filename = "icon_orange_eng.png";
4366 if (dut->ap_osu_icon_tag == 2)
4367 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4368 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4369 hs20_icon_filename);
4370 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4371 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4372
4373 hs20_icon_filename = "icon_orange_zxx.png";
4374 if (dut->ap_osu_icon_tag == 2)
4375 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4376 snprintf(hs20_icon, sizeof(hs20_icon),
4377 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4378 hs20_icon_filename);
4379 osu_icon = "icon_orange_zxx.png";
4380 break;
4381 case 5:
4382 case 105:
4383 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4384 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4385 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4386 hs20_icon_filename = "icon_orange_zxx.png";
4387 if (dut->ap_osu_icon_tag == 2)
4388 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4389 snprintf(hs20_icon, sizeof(hs20_icon),
4390 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4391 hs20_icon_filename);
4392 osu_icon = "icon_orange_zxx.png";
4393 break;
4394 case 6:
4395 case 106:
4396 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4397 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4398 hs20_icon_filename = "icon_green_zxx.png";
4399 if (dut->ap_osu_icon_tag == 2)
4400 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4401 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4402 hs20_icon_filename);
4403 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4404 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4405 fprintf(f, "osu_method_list=%d\n", osu_method);
4406
4407 if (strlen(dut->ap_osu_server_uri[1]))
4408 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4409 else
4410 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4411 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4412 hs20_icon_filename = "icon_orange_zxx.png";
4413 if (dut->ap_osu_icon_tag == 2)
4414 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4415 snprintf(hs20_icon, sizeof(hs20_icon),
4416 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4417 hs20_icon_filename);
4418 osu_icon = "icon_orange_zxx.png";
4419 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4420 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4421 osu_service_desc = NULL;
4422 break;
4423 case 7:
4424 case 107:
4425 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4426 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4427 hs20_icon_filename = "icon_green_eng.png";
4428 if (dut->ap_osu_icon_tag == 2)
4429 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4430 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4431 hs20_icon_filename);
4432 fprintf(f, "osu_icon=icon_green_eng.png\n");
4433 osu_friendly_name = "kor:SP 초록 테스트 전용";
4434
4435 hs20_icon_filename = "icon_green_zxx.png";
4436 if (dut->ap_osu_icon_tag == 2)
4437 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4438 snprintf(hs20_icon, sizeof(hs20_icon),
4439 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4440 hs20_icon_filename);
4441 osu_icon = "icon_green_zxx.png";
4442 break;
4443 case 8:
4444 case 108:
4445 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4446 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4447 osu_ssid = "OSU-Encrypted";
4448 osu_nai = "anonymous@hotspot.net";
4449 break;
4450 case 9:
4451 case 109:
4452 osu_ssid = "OSU-OSEN";
4453 osu_nai = "test-anonymous@wi-fi.org";
4454 osu_friendly_name = "eng:SP Orange Test Only";
4455 hs20_icon_filename = "icon_orange_zxx.png";
4456 if (dut->ap_osu_icon_tag == 2)
4457 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4458 snprintf(hs20_icon, sizeof(hs20_icon),
4459 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4460 hs20_icon_filename);
4461 osu_icon = "icon_orange_zxx.png";
4462 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4463 osu_service_desc = NULL;
4464 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004465 case 10:
4466 case 110:
4467 /* OSU Provider #1 */
4468 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4469 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
4470 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
4471 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
4472 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
4473 1 : dut->ap_osu_method[0];
4474 fprintf(f, "osu_method_list=%d\n", osu_method);
4475 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
4476 switch (dut->ap_osu_provider_nai_list) {
4477 case 3:
4478 fprintf(f,
4479 "osu_nai2=test-anonymous@wi-fi.org\n");
4480 break;
4481 case 4:
4482 fprintf(f, "osu_nai2=random@hotspot.net\n");
4483 break;
4484 }
4485
4486 /* OSU Provider #2 */
4487 /* SP Red from defaults */
4488 if (strlen(dut->ap_osu_server_uri[1]))
4489 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4490 else
4491 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4492 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4493 snprintf(hs20_icon, sizeof(hs20_icon),
4494 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
4495 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
4496 1 : dut->ap_osu_method[1];
4497 osu_service_desc = NULL;
4498 osu_nai = "anonymous@hotspot.net";
4499 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004500 default:
4501 break;
4502 }
4503
Jouni Malinen93a837f2018-11-01 17:09:22 +02004504 switch (dut->ap_osu_provider_nai_list) {
4505 case 1:
4506 osu_nai2 = "anonymous@hotspot.net";
4507 break;
4508 case 2:
4509 osu_nai2 = "test-anonymous@wi-fi.org";
4510 break;
4511 case 3:
4512 /* OSU Provider NAI #1 written above */
4513 /* OSU Provider NAI #2 */
4514 osu_nai2 = "anonymous@hotspot.net";
4515 break;
4516 case 4:
4517 /* OSU Provider NAI #1 written above */
4518 /* OSU Provider NAI #2 */
4519 osu_nai2 = "anonymous@hotspot.net";
4520 break;
4521 }
4522
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004523 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03004524 if (dut->ap_tag_ssid[0][0] &&
4525 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004526 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004527 sigma_dut_print(dut, DUT_MSG_ERROR,
4528 "OSU_SSID and "
4529 "WLAN_TAG2 SSID differ");
4530 return -2;
4531 }
4532 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
4533 } else
4534 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
4535
4536
4537 if (osu_friendly_name)
4538 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
4539
4540 if (osu_service_desc)
4541 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
4542
4543 if (osu_nai)
4544 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02004545 if (osu_nai2)
4546 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004547
4548 fprintf(f, "hs20_icon=%s\n", hs20_icon);
4549
4550 if (osu_icon)
4551 fprintf(f, "osu_icon=%s\n", osu_icon);
4552
4553 if (dut->ap_osu_provider_list > 100)
4554 fprintf(f, "osu_method_list=0\n");
4555 else
4556 fprintf(f, "osu_method_list=%d\n", osu_method);
4557 }
4558
Jouni Malinen54a89b02018-05-01 00:16:26 +03004559 switch (dut->ap_venue_url) {
4560 case 1:
4561 fprintf(f,
4562 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4563 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
4564 break;
4565 case 2:
4566 fprintf(f,
4567 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4568 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4569 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4570 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4571 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4572 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4573 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4574 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4575 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4576 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4577 );
4578 break;
4579 }
4580
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03004581 switch (dut->ap_advice_of_charge) {
4582 case 1:
4583 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
4584 break;
4585 }
4586
Jouni Malinenac104532018-05-01 00:27:37 +03004587 switch (dut->ap_oper_icon_metadata) {
4588 case 1:
4589 fprintf(f,
4590 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
4591 "operator_icon=icon_red_eng.png\n");
4592 break;
4593 }
4594
Jouni Malinenac367142018-05-01 00:32:24 +03004595 switch (dut->ap_tnc_file_name) {
4596 case 1:
4597 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
4598 break;
4599 }
4600
4601 if (dut->ap_tnc_time_stamp)
4602 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
4603
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004604 return 0;
4605}
4606
4607
4608static void write_ap_roaming_cons(FILE *f, const char *list)
4609{
4610 char *buf, *pos, *end;
4611
4612 if (list == NULL || list[0] == '\0')
4613 return;
4614
4615 buf = strdup(list);
4616 if (buf == NULL)
4617 return;
4618
4619 pos = buf;
4620 while (pos && *pos) {
4621 end = strchr(pos, ';');
4622 if (end)
4623 *end++ = '\0';
4624 fprintf(f, "roaming_consortium=%s\n", pos);
4625 pos = end;
4626 }
4627
4628 free(buf);
4629}
4630
4631
4632static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
4633{
4634 int i;
4635 char buf[100], *temp;
4636
4637 if (dut->ap_gas_cb_delay > 0)
4638 fprintf(f, "gas_comeback_delay=%d\n",
4639 dut->ap_gas_cb_delay);
4640
4641 fprintf(f, "interworking=1\n"
4642 "access_network_type=%d\n"
4643 "internet=%d\n"
4644 "asra=0\n"
4645 "esr=0\n"
4646 "uesa=0\n"
4647 "venue_group=%d\n"
4648 "venue_type=%d\n",
4649 dut->ap_access_net_type,
4650 dut->ap_internet,
4651 dut->ap_venue_group,
4652 dut->ap_venue_type);
4653 if (dut->ap_hessid[0])
4654 fprintf(f, "hessid=%s\n", dut->ap_hessid);
4655
4656 write_ap_roaming_cons(f, dut->ap_roaming_cons);
4657
4658 if (dut->ap_venue_name) {
4659 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
4660 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
4661 }
4662
4663 if (dut->ap_net_auth_type == 1)
4664 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
4665 else if (dut->ap_net_auth_type == 2)
4666 fprintf(f, "network_auth_type=01\n");
4667
4668 if (dut->ap_nai_realm_list == 1) {
4669 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
4670 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4671 } else if (dut->ap_nai_realm_list == 2) {
4672 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4673 } else if (dut->ap_nai_realm_list == 3) {
4674 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
4675 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4676 } else if (dut->ap_nai_realm_list == 4) {
4677 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
4678 } else if (dut->ap_nai_realm_list == 5) {
4679 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
4680 } else if (dut->ap_nai_realm_list == 6) {
4681 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
4682 } else if (dut->ap_nai_realm_list == 7) {
4683 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
4684 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4685 }
4686
4687 if (dut->ap_domain_name_list[0]) {
4688 fprintf(f, "domain_name=%s\n",
4689 dut->ap_domain_name_list);
4690 }
4691
4692 if (dut->ap_ip_addr_type_avail == 1) {
4693 fprintf(f, "ipaddr_type_availability=0c\n");
4694 }
4695
4696 temp = buf;
4697 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
4698 i++) {
4699 if (i)
4700 *temp++ = ';';
4701
4702 snprintf(temp,
4703 sizeof(dut->ap_plmn_mcc[i]) +
4704 sizeof(dut->ap_plmn_mnc[i]) + 1,
4705 "%s,%s",
4706 dut->ap_plmn_mcc[i],
4707 dut->ap_plmn_mnc[i]);
4708
4709 temp += strlen(dut->ap_plmn_mcc[i]) +
4710 strlen(dut->ap_plmn_mnc[i]) + 1;
4711 }
4712 if (i)
4713 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
4714
4715 if (dut->ap_qos_map_set == 1)
4716 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
4717 else if (dut->ap_qos_map_set == 2)
4718 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
4719
4720 return 0;
4721}
4722
4723
4724static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
4725{
4726 FILE *f;
4727
4728 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4729 system("killall hostapd") == 0) {
4730 int i;
4731
4732 /* Wait some time to allow hostapd to complete cleanup before
4733 * starting a new process */
4734 for (i = 0; i < 10; i++) {
4735 usleep(500000);
4736 if (system("pidof hostapd") != 0)
4737 break;
4738 }
4739 }
4740
4741 f = fopen("/tmp/secath0", "a");
4742 if (f == NULL)
4743 return -2;
4744
4745 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
4746 fclose(f);
4747 return -2;
4748 }
4749
4750 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4751 fclose(f);
4752 return -2;
4753 }
4754
4755 fflush(f);
4756 fclose(f);
4757 return ath_ap_start_hostapd(dut);
4758}
4759
4760
4761static int ath_ap_start_hostapd(struct sigma_dut *dut)
4762{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004763 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004764 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
4765 else
4766 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
4767
4768 return 0;
4769}
4770
4771
4772#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
4773
4774static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
4775{
4776 FILE *f;
4777 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
4778 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
4779 char buf[100];
4780 int i;
4781
4782 f = fopen("/root/anqpserver.conf", "w");
4783 if (f == NULL)
4784 return -1;
4785
4786 if (dut->ap_nai_realm_list == 1) {
4787 nai_realm = 1;
4788 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");
4789 } else if (dut->ap_nai_realm_list == 2) {
4790 nai_realm = 1;
4791 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4792 } else if (dut->ap_nai_realm_list == 3) {
4793 nai_realm = 1;
4794 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");
4795 } else if (dut->ap_nai_realm_list == 4) {
4796 nai_realm = 1;
4797 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");
4798 } else
4799 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
4800
4801 if (dut->ap_domain_name_list[0]) {
4802 char *next, *start, *dnbuf, *dn1, *anqp_dn;
4803 int len, dn_len_max;
4804 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304805 if (dnbuf == NULL) {
4806 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004807 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304808 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004809
4810 len = strlen(dnbuf);
4811 dn_len_max = 50 + len*2;
4812 anqp_dn = malloc(dn_len_max);
4813 if (anqp_dn == NULL) {
4814 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304815 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004816 return -1;
4817 }
4818 start = dnbuf;
4819 dn1 = anqp_dn;
4820 while (start && *start) {
4821 char *hexstr;
4822
4823 next = strchr(start, ',');
4824 if (next)
4825 *next++ = '\0';
4826
4827 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05304828 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004829 if (hexstr == NULL) {
4830 free(dnbuf);
4831 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304832 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004833 return -1;
4834 }
4835 ascii2hexstr(start, hexstr);
4836 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
4837 free(hexstr);
4838 dn1 += 2 + len * 2;
4839 dn_len_max -= 2 + len * 2;
4840 start = next;
4841 }
4842 free(dnbuf);
4843 if (dut->ap_gas_cb_delay) {
4844 fprintf(f, "dyn_domain_name=0c01%04x%s",
4845 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4846 domain_name = 1;
4847 } else
4848 fprintf(f, "domain_name=0c01%04x%s",
4849 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4850 free(anqp_dn);
4851 } else
4852 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
4853
4854 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
4855
4856 if (dut->ap_oper_name) {
4857 if (dut->ap_gas_cb_delay) {
4858 fprintf(f, "dyn_oper_friendly_name="
4859 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4860 oper_name = 1;
4861 } else
4862 fprintf(f, "oper_friendly_name="
4863 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4864 } else
4865 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
4866
4867 if (dut->ap_venue_name) {
4868 if (dut->ap_gas_cb_delay) {
4869 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
4870 venue_name = 1;
4871 } else
4872 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
4873 } else
4874 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
4875
4876 if (dut->ap_wan_metrics) {
4877 if (dut->ap_gas_cb_delay) {
4878 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
4879 wan_metrics = 1;
4880 } else
4881 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
4882 "\n");
4883 } else
4884 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
4885
4886 if (dut->ap_conn_capab) {
4887 if (dut->ap_gas_cb_delay) {
4888 fprintf(f, "dyn_conn_capability="
4889 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4890 conn_cap = 1;
4891 } else
4892 fprintf(f, "conn_capability="
4893 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4894 } else
4895 sigma_dut_print(dut, DUT_MSG_ERROR,
4896 "not setting conn_capability");
4897
4898 if (dut->ap_ip_addr_type_avail) {
4899 if (dut->ap_gas_cb_delay) {
4900 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
4901 "\n");
4902 ipaddr_avail = 1;
4903 } else
4904 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
4905 } else
4906 sigma_dut_print(dut, DUT_MSG_ERROR,
4907 "not setting ipaddr_type_avail");
4908
4909 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
4910 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
4911 dut->ap_plmn_mcc[i][1],
4912 dut->ap_plmn_mcc[i][0],
4913 dut->ap_plmn_mnc[i][2] == '\0' ?
4914 'f' : dut->ap_plmn_mnc[i][2],
4915 dut->ap_plmn_mcc[i][2],
4916 dut->ap_plmn_mnc[i][1],
4917 dut->ap_plmn_mnc[i][0]);
4918 }
4919 if (i) {
4920 uint16_t ie_len = (i * 3) + 5;
4921 if (dut->ap_gas_cb_delay) {
4922 fprintf(f, "dyn_cell_net=0801");
4923 cell_net = 1;
4924 } else
4925 fprintf(f, "cell_net=0801");
4926 fprintf(f, "%04x", LE16(ie_len));
4927 fprintf(f, "00"); /* version */
4928 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
4929 fprintf(f, "00"); /* plmn list */
4930 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
4931 fprintf(f, "%02x", i); /* number of plmns */
4932 fprintf(f, "%s\n", buf); /* plmns */
4933 } else
4934 sigma_dut_print(dut, DUT_MSG_ERROR,
4935 "not setting 3gpp_cellular_network");
4936
4937 if (nai_realm || domain_name || oper_name || venue_name ||
4938 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
4939 fprintf(f, "anqp_attach=");
4940 if (venue_name)
4941 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
4942 if (nai_realm)
4943 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
4944 if (cell_net)
4945 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
4946 if (domain_name)
4947 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
4948 if (oper_name)
4949 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
4950 if (wan_metrics)
4951 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
4952 if (conn_cap)
4953 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
4954 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
4955 fprintf(f, "\n");
4956 }
4957
4958 fclose(f);
4959
4960 run_system(dut, "anqpserver -i ath0 &");
4961 if (!dut->ap_anqpserver_on)
4962 run_system(dut, "killall anqpserver");
4963
4964 return 1;
4965}
4966
4967
4968static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
4969{
4970 char buf[100];
4971
4972 run_system(dut, "cfg -a AP_STARTMODE=standard");
4973
4974 if (sigma_radio_ifname[0] &&
4975 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4976 run_system(dut, "cfg -a AP_RADIO_ID=1");
4977 switch (dut->ap_mode) {
4978 case AP_11g:
4979 run_system(dut, "cfg -a AP_CHMODE_2=11G");
4980 break;
4981 case AP_11b:
4982 run_system(dut, "cfg -a AP_CHMODE_2=11B");
4983 break;
4984 case AP_11ng:
4985 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
4986 break;
4987 case AP_11a:
4988 run_system(dut, "cfg -a AP_CHMODE_2=11A");
4989 break;
4990 case AP_11na:
4991 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
4992 break;
4993 case AP_11ac:
4994 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4995 break;
4996 default:
4997 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4998 break;
4999 }
5000
5001 switch (dut->ap_rx_streams) {
5002 case 1:
5003 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5004 break;
5005 case 2:
5006 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5007 break;
5008 case 3:
5009 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5010 break;
5011 }
5012
5013 switch (dut->ap_tx_streams) {
5014 case 1:
5015 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5016 break;
5017 case 2:
5018 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5019 break;
5020 case 3:
5021 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5022 break;
5023 }
5024
5025 switch (dut->ap_chwidth) {
5026 case AP_20:
5027 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5028 break;
5029 case AP_40:
5030 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5031 break;
5032 case AP_80:
5033 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5034 break;
5035 case AP_160:
5036 case AP_AUTO:
5037 default:
5038 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5039 break;
5040 }
5041
5042 if (dut->ap_tx_stbc) {
5043 run_system(dut, "cfg -a TX_STBC_2=1");
5044 }
5045
5046 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5047 dut->ap_channel);
5048
5049 if (dut->ap_is_dual) {
5050 switch (dut->ap_mode_1) {
5051 case AP_11g:
5052 run_system(dut, "cfg -a AP_CHMODE=11G");
5053 break;
5054 case AP_11b:
5055 run_system(dut, "cfg -a AP_CHMODE=11B");
5056 break;
5057 case AP_11ng:
5058 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5059 break;
5060 case AP_11a:
5061 run_system(dut, "cfg -a AP_CHMODE=11A");
5062 break;
5063 case AP_11na:
5064 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5065 break;
5066 case AP_11ac:
5067 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5068 break;
5069 default:
5070 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5071 break;
5072 }
5073 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5074 dut->ap_channel_1);
5075 }
5076 run_system(dut, buf);
5077 } else {
5078 run_system(dut, "cfg -a AP_RADIO_ID=0");
5079 switch (dut->ap_mode) {
5080 case AP_11g:
5081 run_system(dut, "cfg -a AP_CHMODE=11G");
5082 break;
5083 case AP_11b:
5084 run_system(dut, "cfg -a AP_CHMODE=11B");
5085 break;
5086 case AP_11ng:
5087 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5088 break;
5089 case AP_11a:
5090 run_system(dut, "cfg -a AP_CHMODE=11A");
5091 break;
5092 case AP_11na:
5093 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5094 break;
5095 case AP_11ac:
5096 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5097 break;
5098 default:
5099 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5100 break;
5101 }
5102 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5103 dut->ap_channel);
5104 run_system(dut, buf);
5105 }
5106
5107 if (dut->ap_sgi80 == 1) {
5108 run_system(dut, "cfg -a SHORTGI=1");
5109 run_system(dut, "cfg -a SHORTGI_2=1");
5110 } else if (dut->ap_sgi80 == 0) {
5111 run_system(dut, "cfg -a SHORTGI=0");
5112 run_system(dut, "cfg -a SHORTGI_2=0");
5113 }
5114
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005115 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005116 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005117 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005118 run_system(dut, "cfg -a LDPC=0");
5119}
5120
5121
5122void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5123{
5124 char buf[50];
5125
5126 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
5127 if (system(buf) != 0)
5128 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
5129
5130 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
5131 if (system(buf) != 0)
5132 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
5133
5134 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
5135 if (system(buf) != 0)
5136 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
5137
5138 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
5139 if (system(buf) != 0)
5140 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
5141}
5142
5143
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005144static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5145 const char *val)
5146{
5147 if (strcasecmp(val, "enable") == 0) {
5148 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 1", ifname);
5149 } else if (strcasecmp(val, "disable") == 0) {
5150 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 0", ifname);
5151 } else {
5152 sigma_dut_print(dut, DUT_MSG_ERROR,
5153 "Unsupported assoc_disallow");
5154 }
5155}
5156
5157
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005158static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5159{
5160 int i;
5161 int least_pref = 1 << 8;
5162 char ifname[20];
5163 uint8_t self_mac[ETH_ALEN];
5164 char buf[200];
5165 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5166
5167 get_if_name(dut, ifname, sizeof(ifname), 1);
5168 get_hwaddr(ifname, self_mac);
5169
5170 /* Clear off */
5171 snprintf(buf, sizeof(buf),
5172 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5173 ifname);
5174 run_system(dut, buf);
5175
5176 /* Find the least preference number */
5177 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5178 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5179
5180 ap_ne_class = 1;
5181 ap_ne_pref = 255;
5182 ap_ne_op_ch = 1;
5183 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5184 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5185 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5186 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5187 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5188 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5189
5190 if (ap_ne_pref < least_pref)
5191 least_pref = ap_ne_pref;
5192 snprintf(buf, sizeof(buf),
5193 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5194 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5195 mac_addr[3], mac_addr[4], mac_addr[5],
5196 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5197 run_system(dut, buf);
5198 }
5199
5200 /* Now add the self AP Address */
5201 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5202 if (dut->ap_channel <= 11)
5203 ap_ne_class = 81;
5204 else
5205 ap_ne_class = 115;
5206 } else {
5207 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5208 }
5209
5210 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5211 ap_ne_op_ch = dut->ap_channel;
5212 else
5213 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5214
5215 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5216 ap_ne_pref = least_pref - 1;
5217 else
5218 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5219
5220 snprintf(buf, sizeof(buf),
5221 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5222 ifname, self_mac[0], self_mac[1], self_mac[2],
5223 self_mac[3], self_mac[4], self_mac[5],
5224 ap_ne_pref,
5225 ap_ne_class,
5226 ap_ne_op_ch);
5227 run_system(dut, buf);
5228}
5229
5230
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005231static void ath_ap_set_params(struct sigma_dut *dut)
5232{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005233 const char *basedev = "wifi0";
5234 const char *basedev_radio = "wifi1";
5235 char *ifname = get_main_ifname();
5236 char *ifname_dual;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005237 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005238 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005239
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005240 if (sigma_radio_ifname[0])
5241 basedev = sigma_radio_ifname[0];
5242
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005243 if (dut->ap_is_dual == 1) {
5244 basedev = sigma_radio_ifname[0];
5245 basedev_radio = sigma_radio_ifname[1];
5246 if (sigma_radio_ifname[0] &&
5247 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5248 ifname = "ath0";
5249 ifname_dual = "ath1";
5250 } else {
5251 ifname = "ath1";
5252 ifname_dual = "ath0";
5253 }
5254 }
5255
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005256 if (dut->ap_countrycode[0]) {
5257 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
5258 basedev, dut->ap_countrycode);
5259 if (system(buf) != 0) {
5260 sigma_dut_print(dut, DUT_MSG_ERROR,
5261 "iwpriv setCountry failed");
5262 }
5263 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5264 }
5265
5266 for (i = 0; i < NUM_AP_AC; i++) {
5267 if (dut->ap_qos[i].ac) {
5268 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
5269 ifname, i, dut->ap_qos[i].cwmin);
5270 if (system(buf) != 0) {
5271 sigma_dut_print(dut, DUT_MSG_ERROR,
5272 "iwpriv cwmin failed");
5273 }
5274
5275 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
5276 ifname, i, dut->ap_qos[i].cwmax);
5277 if (system(buf) != 0) {
5278 sigma_dut_print(dut, DUT_MSG_ERROR,
5279 "iwpriv cwmax failed");
5280 }
5281
5282 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
5283 ifname, i, dut->ap_qos[i].aifs);
5284 if (system(buf) != 0) {
5285 sigma_dut_print(dut, DUT_MSG_ERROR,
5286 "iwpriv aifs failed");
5287 }
5288
5289 snprintf(buf, sizeof(buf),
5290 "iwpriv %s txoplimit %d 0 %d",
5291 ifname, i, dut->ap_qos[i].txop);
5292 if (system(buf) != 0) {
5293 sigma_dut_print(dut, DUT_MSG_ERROR,
5294 "iwpriv txoplimit failed");
5295 }
5296
5297 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
5298 ifname, i, dut->ap_qos[i].acm);
5299 if (system(buf) != 0) {
5300 sigma_dut_print(dut, DUT_MSG_ERROR,
5301 "iwpriv acm failed");
5302 }
5303 }
5304 }
5305
5306 for (i = 0; i < NUM_AP_AC; i++) {
5307 if (dut->ap_sta_qos[i].ac) {
5308 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
5309 ifname, i, dut->ap_sta_qos[i].cwmin);
5310 if (system(buf) != 0) {
5311 sigma_dut_print(dut, DUT_MSG_ERROR,
5312 "iwpriv cwmin failed");
5313 }
5314
5315 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
5316 ifname, i, dut->ap_sta_qos[i].cwmax);
5317 if (system(buf) != 0) {
5318 sigma_dut_print(dut, DUT_MSG_ERROR,
5319 "iwpriv cwmax failed");
5320 }
5321
5322 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
5323 ifname, i, dut->ap_sta_qos[i].aifs);
5324 if (system(buf) != 0) {
5325 sigma_dut_print(dut, DUT_MSG_ERROR,
5326 "iwpriv aifs failed");
5327 }
5328
5329 snprintf(buf, sizeof(buf),
5330 "iwpriv %s txoplimit %d 1 %d",
5331 ifname, i, dut->ap_sta_qos[i].txop);
5332 if (system(buf) != 0) {
5333 sigma_dut_print(dut, DUT_MSG_ERROR,
5334 "iwpriv txoplimit failed");
5335 }
5336
5337 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
5338 ifname, i, dut->ap_sta_qos[i].acm);
5339 if (system(buf) != 0) {
5340 sigma_dut_print(dut, DUT_MSG_ERROR,
5341 "iwpriv acm failed");
5342 }
5343 }
5344 }
5345
5346 if (dut->ap_disable_protection == 1) {
5347 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
5348 if (system(buf) != 0) {
5349 sigma_dut_print(dut, DUT_MSG_ERROR,
5350 "iwpriv enablertscts failed");
5351 }
5352 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5353 }
5354
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005355 if (dut->ap_ldpc == VALUE_ENABLED) {
Sarvepalli, Rajesh Babu580572a2016-11-29 22:07:14 +05305356 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 3", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005357 if (system(buf) != 0) {
5358 sigma_dut_print(dut, DUT_MSG_ERROR,
priyadharshini gowthaman15b299d2017-04-20 12:10:45 -07005359 "iwpriv ldpc 3 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005360 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005361 } else if (dut->ap_ldpc == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005362 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
5363 if (system(buf) != 0) {
5364 sigma_dut_print(dut, DUT_MSG_ERROR,
5365 "iwpriv ldpc 0 failed");
5366 }
5367 }
5368
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005369 if (dut->ap_ampdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005370 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
5371 if (system(buf) != 0) {
5372 sigma_dut_print(dut, DUT_MSG_ERROR,
5373 "iwpriv ampdu 1 failed");
5374 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005375 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005376 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
5377 if (system(buf) != 0) {
5378 sigma_dut_print(dut, DUT_MSG_ERROR,
5379 "iwpriv ampdu 0 failed");
5380 }
5381 }
5382
5383 if (dut->ap_ampdu_exp) {
5384 if (dut->program == PROGRAM_VHT) {
5385 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
5386 ifname, dut->ap_ampdu_exp);
5387 if (system(buf) != 0) {
5388 sigma_dut_print(dut, DUT_MSG_ERROR,
5389 "iwpriv vhtmaxampdu failed");
5390 }
5391 } else {
5392 /* 11N */
5393 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
5394 ifname, dut->ap_ampdu_exp);
5395 if (system(buf) != 0) {
5396 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
5397 }
5398 }
5399 }
5400
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005401 if (dut->ap_noack == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005402 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
5403 if (system(buf) != 0) {
5404 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
5405 }
5406 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
5407 if (system(buf) != 0) {
5408 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
5409 }
5410 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
5411 if (system(buf) != 0) {
5412 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
5413 }
5414 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
5415 if (system(buf) != 0) {
5416 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
5417 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005418 } else if (dut->ap_noack == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005419 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
5420 if (system(buf) != 0) {
5421 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
5422 }
5423 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
5424 if (system(buf) != 0) {
5425 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
5426 }
5427 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
5428 if (system(buf) != 0) {
5429 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
5430 }
5431 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
5432 if (system(buf) != 0) {
5433 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
5434 }
5435 }
5436
5437 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
5438 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5439 ifname, dut->ap_vhtmcs_map);
5440 if (system(buf) != 0) {
5441 sigma_dut_print(dut, DUT_MSG_ERROR,
5442 "iwpriv vht_mcsmap failed");
5443 }
5444 }
5445
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005446 if (dut->ap_amsdu == VALUE_ENABLED) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005447 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005448 if (system(buf) != 0) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03005449 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005450 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005451 } else if (dut->ap_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005452 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
5453 if (system(buf) != 0) {
5454 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
5455 }
5456 }
5457
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005458 if (dut->ap_rx_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005459 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
5460 if (system(buf) != 0) {
5461 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
5462 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005463 } else if (dut->ap_rx_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005464 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
5465 if (system(buf) != 0) {
5466 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
5467 }
5468 }
5469
5470 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005471 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5472 dut->ap_ampdu == VALUE_DISABLED &&
5473 dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005474 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
5475 if (system(buf) != 0) {
5476 sigma_dut_print(dut, DUT_MSG_ERROR,
5477 "iwpriv setaddbaoper 1 failed");
5478 }
5479
5480 snprintf(buf, sizeof(buf),
5481 "wifitool %s senddelba 1 0 1 4", ifname);
5482 if (system(buf) != 0) {
5483 sigma_dut_print(dut, DUT_MSG_ERROR,
5484 "wifitool senddelba failed");
5485 }
5486
5487 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5488 ifname);
5489 if (system(buf) != 0) {
5490 sigma_dut_print(dut, DUT_MSG_ERROR,
5491 "wifitool sendsingleamsdu failed");
5492 }
5493
5494 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
5495 if (system(buf) != 0) {
5496 sigma_dut_print(dut, DUT_MSG_ERROR,
5497 "iwpriv amsdu failed");
5498 }
5499 }
5500
5501 if (dut->ap_mode == AP_11ac) {
5502 int chwidth, nss;
5503
5504 switch (dut->ap_chwidth) {
5505 case AP_20:
5506 chwidth = 0;
5507 break;
5508 case AP_40:
5509 chwidth = 1;
5510 break;
5511 case AP_80:
5512 chwidth = 2;
5513 break;
5514 case AP_160:
5515 chwidth = 3;
5516 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005517 case AP_80_80:
5518 chwidth = 3;
5519 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005520 default:
5521 chwidth = 0;
5522 break;
5523 }
5524
5525 switch (dut->ap_tx_streams) {
5526 case 1:
5527 nss = 1;
5528 break;
5529 case 2:
5530 nss = 2;
5531 break;
5532 case 3:
5533 nss = 3;
5534 break;
5535 case 4:
5536 nss = 4;
5537 break;
5538 default:
5539 nss = 3;
5540 break;
5541 }
5542
5543 if (dut->ap_fixed_rate) {
5544 if (nss == 4)
5545 ath_disable_txbf(dut, ifname);
5546
5547 /* Set the nss */
5548 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
5549 ifname, nss);
5550 if (system(buf) != 0) {
5551 sigma_dut_print(dut, DUT_MSG_ERROR,
5552 "iwpriv nss failed");
5553 }
5554
5555 /* Set the channel width */
5556 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5557 ifname, chwidth);
5558 if (system(buf) != 0) {
5559 sigma_dut_print(dut, DUT_MSG_ERROR,
5560 "iwpriv chwidth failed");
5561 }
5562
5563 /* Set the VHT MCS */
5564 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
5565 ifname, dut->ap_mcs);
5566 if (system(buf) != 0) {
5567 sigma_dut_print(dut, DUT_MSG_ERROR,
5568 "iwpriv vhtmcs failed");
5569 }
5570 }
5571 }
5572
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005573 if (dut->ap_dyn_bw_sig == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005574 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
5575 if (system(buf) != 0) {
5576 sigma_dut_print(dut, DUT_MSG_ERROR,
5577 "iwpriv cwmenable 1 failed");
5578 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005579 } else if (dut->ap_dyn_bw_sig == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005580 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
5581 if (system(buf) != 0) {
5582 sigma_dut_print(dut, DUT_MSG_ERROR,
5583 "iwpriv cwmenable 0 failed");
5584 }
5585 }
5586
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005587 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005588 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5589 if (system(buf) != 0) {
5590 sigma_dut_print(dut, DUT_MSG_ERROR,
5591 "iwconfig rts 64 failed");
5592 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005593 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5595 if (system(buf) != 0) {
5596 sigma_dut_print(dut, DUT_MSG_ERROR,
5597 "iwpriv rts 2347 failed");
5598 }
5599 }
5600
5601 if (dut->ap_hs2) {
5602 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
5603 if (system(buf) != 0) {
5604 sigma_dut_print(dut, DUT_MSG_ERROR,
5605 "iwpriv qbssload failed");
5606 }
5607 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5608 }
5609
5610 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5611 unsigned int bssload = 0;
5612
5613 if (dut->ap_bss_load == 1) {
5614 /* STA count: 1, CU: 50, AAC: 65535 */
5615 bssload = 0x0132ffff;
5616 } else if (dut->ap_bss_load == 2) {
5617 /* STA count: 1, CU: 200, AAC: 65535 */
5618 bssload = 0x01c8ffff;
5619 } else if (dut->ap_bss_load == 3) {
5620 /* STA count: 1, CU: 75, AAC: 65535 */
5621 bssload = 0x014bffff;
5622 }
5623
5624 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
5625 ifname, bssload);
5626 if (system(buf) != 0) {
5627 sigma_dut_print(dut, DUT_MSG_ERROR,
5628 "iwpriv hcbssload failed");
5629 }
5630 } else if (dut->ap_bss_load == 0) {
5631 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5632 if (system(buf) != 0) {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "iwpriv qbssload failed");
5635 }
5636 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5637 }
5638
5639 if (dut->ap_dgaf_disable) {
5640 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
5641 if (system(buf) != 0) {
5642 sigma_dut_print(dut, DUT_MSG_ERROR,
5643 "iwpriv dgaf_disable failed");
5644 }
5645 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
5646 }
5647
5648 if (dut->ap_l2tif) {
5649 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
5650 if (system(buf) != 0) {
5651 sigma_dut_print(dut, DUT_MSG_ERROR,
5652 "iwpriv l2tif failed");
5653 }
5654 snprintf(buf, sizeof(buf),
5655 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
5656 if (system(buf) != 0)
5657 sigma_dut_print(dut, DUT_MSG_ERROR,
5658 "l2tif br failed");
5659
5660 snprintf(buf, sizeof(buf),
5661 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
5662 if (system(buf) != 0)
5663 sigma_dut_print(dut, DUT_MSG_ERROR,
5664 "l2tif brif failed");
5665 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
5666 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005667
5668 if (dut->ap_ndpa_frame == 0) {
5669 snprintf(buf, sizeof(buf),
5670 "wifitool %s beeliner_fw_test 117 192", ifname);
5671 if (system(buf) != 0) {
5672 sigma_dut_print(dut, DUT_MSG_ERROR,
5673 "wifitool beeliner_fw_test 117 192 failed");
5674 }
5675 snprintf(buf, sizeof(buf),
5676 "wifitool %s beeliner_fw_test 118 192", ifname);
5677 if (system(buf) != 0) {
5678 sigma_dut_print(dut, DUT_MSG_ERROR,
5679 "wifitool beeliner_fw_test 117 192 failed");
5680 }
5681 } else if (dut->ap_ndpa_frame == 1) {
5682 /* Driver default - no changes needed */
5683 } else if (dut->ap_ndpa_frame == 2) {
5684 snprintf(buf, sizeof(buf),
5685 "wifitool %s beeliner_fw_test 115 1", ifname);
5686 if (system(buf) != 0) {
5687 sigma_dut_print(dut, DUT_MSG_ERROR,
5688 "wifitool beeliner_fw_test 117 192 failed");
5689 }
5690 snprintf(buf, sizeof(buf),
5691 "wifitool %s beeliner_fw_test 116 1", ifname);
5692 if (system(buf) != 0) {
5693 sigma_dut_print(dut, DUT_MSG_ERROR,
5694 "wifitool beeliner_fw_test 117 192 failed");
5695 }
5696 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005697
5698 if (dut->ap_rtt == 1) {
5699 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5700 run_system(dut, buf);
5701 }
5702
5703 if (dut->ap_lci == 1) {
5704 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5705 run_system(dut, buf);
5706 }
5707
5708 if (dut->ap_lcr == 1) {
5709 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5710 run_system(dut, buf);
5711 }
5712
5713 if (dut->ap_rrm == 1) {
5714 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5715 run_system(dut, buf);
5716 }
5717
5718 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
5719 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
5720 }
5721
5722 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
5723 FILE *f;
5724
5725 f = fopen("/tmp/nbr_report.txt", "w");
5726 if (!f) {
5727 sigma_dut_print(dut, DUT_MSG_ERROR,
5728 "Failed to open /tmp/nbr_report.txt");
5729 return;
5730 }
5731
5732 fprintf(f,
5733 "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",
5734 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5735 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5736 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5737 dut->ap_val_opchannel[0]);
5738 fclose(f);
5739
5740 f = fopen("/tmp/ftmrr.txt", "w");
5741 if (!f) {
5742 sigma_dut_print(dut, DUT_MSG_ERROR,
5743 "Failed to open /tmp/ftmrr.txt");
5744 return;
5745 }
5746
5747 fprintf(f,
5748 "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",
5749 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5750 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5751 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5752 dut->ap_val_opchannel[0]);
5753 fclose(f);
5754 }
5755
5756 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
5757 FILE *f;
5758
5759 f = fopen("/tmp/nbr_report.txt", "a");
5760 if (!f) {
5761 sigma_dut_print(dut, DUT_MSG_ERROR,
5762 "Failed to open /tmp/nbr_report.txt");
5763 return;
5764 }
5765 fprintf(f,
5766 "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",
5767 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5768 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5769 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5770 dut->ap_val_opchannel[1]);
5771 fclose(f);
5772
5773 f = fopen("/tmp/ftmrr.txt", "a");
5774 if (!f) {
5775 sigma_dut_print(dut, DUT_MSG_ERROR,
5776 "Failed to open /tmp/ftmrr.txt");
5777 return;
5778 }
5779 fprintf(f,
5780 "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",
5781 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5782 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5783 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5784 dut->ap_val_opchannel[1]);
5785 fclose(f);
5786 }
5787
5788 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
5789 FILE *f;
5790
5791 f = fopen("/tmp/nbr_report.txt", "a");
5792 if (!f) {
5793 sigma_dut_print(dut, DUT_MSG_ERROR,
5794 "Failed to open /tmp/nbr_report.txt");
5795 return;
5796 }
5797
5798 fprintf(f,
5799 "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",
5800 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5801 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5802 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5803 dut->ap_val_opchannel[2]);
5804 fclose(f);
5805
5806 f = fopen("/tmp/ftmrr.txt", "a");
5807 if (!f) {
5808 sigma_dut_print(dut, DUT_MSG_ERROR,
5809 "Failed to open /tmp/ftmrr.txt");
5810 return;
5811 }
5812
5813 fprintf(f,
5814 "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",
5815 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5816 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5817 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5818 dut->ap_val_opchannel[2]);
5819 fclose(f);
5820 }
5821
5822 if (dut->ap_neighap) {
5823 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
5824 run_system(dut, buf);
5825 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
5826 run_system(dut, buf);
5827 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
5828 run_system(dut, buf);
5829 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
5830 run_system(dut, buf);
5831 }
5832
5833 if (dut->ap_scan == 1) {
5834 snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600",
5835 ifname);
5836 run_system(dut, buf);
5837 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
5838 run_system(dut, buf);
5839 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07005840
5841 if (dut->ap_set_bssidpref) {
5842 snprintf(buf, sizeof(buf),
5843 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
5844 ifname);
5845 if (system(buf) != 0) {
5846 sigma_dut_print(dut, DUT_MSG_ERROR,
5847 "wifitool clear bssidpref failed");
5848 }
5849 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005850
5851 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
5852 int feature_enable;
5853
5854 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
5855 snprintf(buf, sizeof(buf), "iwpriv %s wnm %d",
5856 ifname, feature_enable);
5857 run_system(dut, buf);
5858 snprintf(buf, sizeof(buf), "iwpriv %s wnm_bss %d",
5859 ifname, feature_enable);
5860 run_system(dut, buf);
5861 if (feature_enable) {
5862 const char *extra = "";
5863
5864 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
5865 if (dut->wnm_bss_max_protection ==
5866 VALUE_ENABLED)
5867 extra = " 1";
5868 else
5869 extra = " 0";
5870 }
5871 snprintf(buf, sizeof(buf),
5872 "wlanconfig %s wnm setbssmax %d%s",
5873 ifname, dut->wnm_bss_max_idle_time, extra);
5874 run_system(dut, buf);
5875 }
5876 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005877
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005878 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005879 apply_mbo_pref_ap_list(dut);
5880
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005881 snprintf(buf, sizeof(buf), "iwpriv %s mbo_cel_pref %d",
5882 ifname, dut->ap_cell_cap_pref);
5883 run_system(dut, buf);
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07005884
5885 snprintf(buf, sizeof(buf), "iwpriv %s mbocap 0x40", ifname);
5886 run_system(dut, buf);
5887
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005888 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005889 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005890
5891 if (dut->ap_oce == VALUE_ENABLED) {
5892 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 1",
5893 ifname);
5894 run_system(dut, buf);
5895 }
5896
5897 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
5898 snprintf(buf, sizeof(buf), "iwpriv %s prb_rate 5500", ifname);
5899 run_system(dut, buf);
5900 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 5500",
5901 ifname);
5902 run_system(dut, buf);
5903 }
5904
5905 if (dut->ap_oce == VALUE_DISABLED) {
5906 snprintf(buf, sizeof(buf), "iwpriv %s set_bpr_enable 0",
5907 ifname);
5908 run_system(dut, buf);
5909 }
5910
5911 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
5912 snprintf(buf, sizeof(buf), "iwpriv %s mgmt_rate 1000", ifname);
5913 run_system(dut, buf);
5914 snprintf(buf, sizeof(buf), "iwpriv %s set_bcn_rate 1000",
5915 ifname);
5916 run_system(dut, buf);
5917 }
5918
5919 if (dut->ap_bcnint) {
5920 snprintf(buf, sizeof(buf), "iwpriv %s bintval %d", ifname,
5921 dut->ap_bcnint);
5922 run_system(dut, buf);
5923 }
5924
5925 if (dut->ap_filsdscv == VALUE_DISABLED) {
5926 snprintf(buf, sizeof(buf), "iwpriv %s enable_fils 0 0", ifname);
5927 run_system(dut, buf);
5928 }
5929
5930 if (dut->ap_filshlp == VALUE_ENABLED) {
5931 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 1", ifname);
5932 if (system(buf) != 0) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR,
5934 "iwpriv filshlp enable failed");
5935 }
5936 } else if (dut->ap_filshlp == VALUE_DISABLED) {
5937 snprintf(buf, sizeof(buf), "iwpriv %s oce_hlp 0", ifname);
5938 if (system(buf) != 0) {
5939 sigma_dut_print(dut, DUT_MSG_ERROR,
5940 "iwpriv filshlp disable failed");
5941 }
5942 }
5943
5944 /* When RNR is enabled, also enable apchannelreport, background scan */
5945 if (dut->ap_rnr == VALUE_ENABLED) {
5946 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1", ifname);
5947 run_system(dut, buf);
5948 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1", ifname);
5949 run_system(dut, buf);
5950 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1", ifname);
5951 run_system(dut, buf);
5952 snprintf(buf, sizeof(buf), "iwpriv %s acs_ctrlflags 0x4",
5953 basedev);
5954 run_system(dut, buf);
5955 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5956 basedev);
5957 run_system(dut, buf);
5958 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1", basedev);
5959 run_system(dut, buf);
5960 if (dut->ap_is_dual == 1) {
5961 snprintf(buf, sizeof(buf), "iwpriv %s rnr 1",
5962 ifname_dual);
5963 run_system(dut, buf);
5964 snprintf(buf, sizeof(buf), "iwpriv %s rnr_tbtt 1",
5965 ifname_dual);
5966 run_system(dut, buf);
5967 snprintf(buf, sizeof(buf), "iwpriv %s apchanrpt 1",
5968 ifname_dual);
5969 run_system(dut, buf);
5970 snprintf(buf, sizeof(buf),
5971 "iwpriv %s acs_ctrlflags 0x4", basedev_radio);
5972 run_system(dut, buf);
5973 snprintf(buf, sizeof(buf), "iwpriv %s acs_scanintvl 60",
5974 basedev_radio);
5975 run_system(dut, buf);
5976 snprintf(buf, sizeof(buf), "iwpriv %s acs_bkscanen 1",
5977 basedev_radio);
5978 run_system(dut, buf);
5979 }
5980 }
5981
5982 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
5983 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
5984 run_system(dut, buf);
5985 snprintf(buf, sizeof(buf),
5986 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
5987 ifname, dut->ap_blestacnt & 0xFF,
5988 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5989 dut->ap_ble_admit_cap & 0xFF,
5990 dut->ap_ble_admit_cap >> 8);
5991 run_system(dut, buf);
5992 snprintf(buf, sizeof(buf),
5993 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
5994 ifname, dut->ap_blestacnt & 0xFF,
5995 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5996 dut->ap_ble_admit_cap & 0xFF,
5997 dut->ap_ble_admit_cap >> 8);
5998 run_system(dut, buf);
5999 }
6000
6001 if (dut->ap_esp == VALUE_ENABLED) {
6002 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 5", basedev);
6003 if (system(buf) != 0) {
6004 sigma_dut_print(dut, DUT_MSG_ERROR,
6005 "iwpriv esp enable failed");
6006 }
6007 } else if (dut->ap_esp == VALUE_DISABLED) {
6008 snprintf(buf, sizeof(buf), "iwpriv %s esp_period 0", basedev);
6009 if (system(buf) != 0) {
6010 sigma_dut_print(dut, DUT_MSG_ERROR,
6011 "iwpriv esp disable failed");
6012 }
6013 }
6014
6015 if (dut->ap_datappdudura) {
6016 snprintf(buf, sizeof(buf), "iwpriv %s esp_ppdu_dur %d", basedev,
6017 dut->ap_datappdudura);
6018 run_system(dut, buf);
6019 }
6020
6021 if (dut->ap_airtimefract) {
6022 snprintf(buf, sizeof(buf), "iwpriv %s esp_airtime %d", basedev,
6023 dut->ap_airtimefract);
6024 run_system(dut, buf);
6025 }
6026
6027 if (dut->ap_dhcp_stop) {
6028 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
6029 run_system(dut, buf);
6030 }
6031
6032 if (dut->ap_bawinsize) {
6033 snprintf(buf, sizeof(buf), "iwpriv %s esp_ba_window %d",
6034 basedev, dut->ap_bawinsize);
6035 run_system(dut, buf);
6036 }
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006037
6038 if (dut->program == PROGRAM_DPP) {
6039 if (dut->ap_interface_2g == 1) {
6040 snprintf(buf, sizeof(buf),
6041 "iwpriv %s set_bcn_rate 5500", ifname);
6042 run_system(dut, buf);
6043 snprintf(buf, sizeof(buf),
6044 "iwpriv %s prb_rate 5500", ifname);
6045 run_system(dut, buf);
6046 snprintf(buf, sizeof(buf),
6047 "iwpriv %s mgmt_rate 5500", ifname);
6048 run_system(dut, buf);
6049 }
6050
6051 snprintf(buf, sizeof(buf), "iwpriv %s set_rxfilter 0xffffffff",
6052 basedev);
6053 run_system(dut, buf);
6054 dut->hostapd_running = 1;
6055 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006056
6057 if (dut->ap_he_ppdu == PPDU_MU) {
6058 run_system_wrapper(
6059 dut, "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
6060 ifname);
6061 run_system_wrapper(
6062 dut, "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
6063 ifname);
6064 run_system_wrapper(dut,
6065 "wifitool %s setUnitTestCmd 0x47 2 8 0",
6066 ifname);
6067 run_system_wrapper(dut,
6068 "wifitool %s setUnitTestCmd 0x47 2 29 0",
6069 ifname);
6070 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006071}
6072
6073
6074static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
6075 struct sigma_conn *conn,
6076 struct sigma_cmd *cmd)
6077{
6078 /* const char *name = get_param(cmd, "NAME"); */
6079 char buf[100];
6080 struct stat s;
6081 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
6082
6083 if (stat("/proc/athversion", &s) == 0) {
6084 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
6085 run_system(dut, "apdown");
6086 }
6087
6088 cmd_ath_ap_radio_config(dut);
6089
6090 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
6091 run_system(dut, buf);
6092
6093 switch (dut->ap_key_mgmt) {
6094 case AP_OPEN:
6095 if (dut->ap_cipher == AP_WEP) {
6096 run_system(dut, "cfg -a AP_SECMODE=WEP");
6097 run_system(dut, "cfg -a AP_SECFILE=NONE");
6098 /* shared auth mode not supported */
6099 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6100 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6101 snprintf(buf, sizeof(buf),
6102 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6103 dut->ap_wepkey);
6104 run_system(dut, buf);
6105 snprintf(buf, sizeof(buf),
6106 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6107 dut->ap_wepkey);
6108 run_system(dut, buf);
6109 } else {
6110 run_system(dut, "cfg -a AP_SECMODE=None");
6111 }
6112 break;
6113 case AP_WPA2_PSK:
6114 case AP_WPA2_PSK_MIXED:
6115 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006116 case AP_WPA2_SAE:
6117 case AP_WPA2_PSK_SAE:
6118 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6119 dut->ap_key_mgmt == AP_WPA2_SAE ||
6120 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006121 run_system(dut, "cfg -a AP_WPA=2");
6122 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6123 run_system(dut, "cfg -a AP_WPA=3");
6124 else
6125 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03006126 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006127 run_system(dut, "cfg -a AP_SECMODE=WPA");
6128 run_system(dut, "cfg -a AP_SECFILE=PSK");
6129 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
6130 dut->ap_passphrase);
6131 run_system(dut, buf);
6132 if (dut->ap_cipher == AP_CCMP_TKIP)
6133 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6134 else if (dut->ap_cipher == AP_TKIP)
6135 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6136 else
6137 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6138 break;
6139 case AP_WPA2_EAP:
6140 case AP_WPA2_EAP_MIXED:
6141 case AP_WPA_EAP:
6142 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6143 run_system(dut, "cfg -a AP_WPA=2");
6144 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6145 run_system(dut, "cfg -a AP_WPA=3");
6146 else
6147 run_system(dut, "cfg -a AP_WPA=1");
6148 run_system(dut, "cfg -a AP_SECMODE=WPA");
6149 run_system(dut, "cfg -a AP_SECFILE=EAP");
6150 if (dut->ap_cipher == AP_CCMP_TKIP)
6151 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6152 else if (dut->ap_cipher == AP_TKIP)
6153 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6154 else
6155 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6156 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6157 dut->ap_radius_ipaddr);
6158 run_system(dut, buf);
6159 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6160 dut->ap_radius_port);
6161 run_system(dut, buf);
6162 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6163 dut->ap_radius_password);
6164 run_system(dut, buf);
6165 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006166 case AP_WPA2_EAP_OSEN:
6167 /* TODO */
6168 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6169 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006170 case AP_SUITEB:
6171 /* TODO */
6172 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6173 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006174 case AP_WPA2_OWE:
6175 /* TODO */
6176 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6177 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006178 case AP_WPA2_FT_EAP:
6179 case AP_WPA2_FT_PSK:
6180 case AP_WPA2_EAP_SHA256:
6181 case AP_WPA2_PSK_SHA256:
6182 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006183 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006184 /* TODO */
6185 send_resp(dut, conn, SIGMA_ERROR,
6186 "errorCode,Unsupported KeyMgnt value");
6187 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006188 }
6189
6190 if (dut->ap_is_dual) {
6191 /* ath1 settings in case of dual */
6192 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6193 dut->ap_ssid);
6194 run_system(dut, buf);
6195
6196 switch (dut->ap_key_mgmt) {
6197 case AP_OPEN:
6198 if (dut->ap_cipher == AP_WEP) {
6199 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6200 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6201 /* shared auth mode not supported */
6202 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6203 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6204 snprintf(buf, sizeof(buf),
6205 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6206 dut->ap_wepkey);
6207 run_system(dut, buf);
6208 snprintf(buf, sizeof(buf),
6209 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6210 dut->ap_wepkey);
6211 run_system(dut, buf);
6212 } else {
6213 run_system(dut, "cfg -a AP_SECMODE_2=None");
6214 }
6215 break;
6216 case AP_WPA2_PSK:
6217 case AP_WPA2_PSK_MIXED:
6218 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006219 case AP_WPA2_SAE:
6220 case AP_WPA2_PSK_SAE:
6221 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6222 dut->ap_key_mgmt == AP_WPA2_SAE ||
6223 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006224 run_system(dut, "cfg -a AP_WPA_2=2");
6225 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6226 run_system(dut, "cfg -a AP_WPA_2=3");
6227 else
6228 run_system(dut, "cfg -a AP_WPA_2=1");
6229 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006230 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006231 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6232 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
6233 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
6234 dut->ap_passphrase);
6235 run_system(dut, buf);
6236 if (dut->ap_cipher == AP_CCMP_TKIP)
6237 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6238 else if (dut->ap_cipher == AP_TKIP)
6239 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6240 else
6241 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6242 break;
6243 case AP_WPA2_EAP:
6244 case AP_WPA2_EAP_MIXED:
6245 case AP_WPA_EAP:
6246 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6247 run_system(dut, "cfg -a AP_WPA_2=2");
6248 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6249 run_system(dut, "cfg -a AP_WPA_2=3");
6250 else
6251 run_system(dut, "cfg -a AP_WPA_2=1");
6252 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6253 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6254 if (dut->ap_cipher == AP_CCMP_TKIP)
6255 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6256 else if (dut->ap_cipher == AP_TKIP)
6257 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6258 else
6259 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6260
6261 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6262 dut->ap_radius_ipaddr);
6263 run_system(dut, buf);
6264 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6265 dut->ap_radius_port);
6266 run_system(dut, buf);
6267 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6268 dut->ap_radius_password);
6269 run_system(dut, buf);
6270 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006271 case AP_WPA2_EAP_OSEN:
6272 /* TODO */
6273 sigma_dut_print(dut, DUT_MSG_ERROR,
6274 "EAP+OSEN not supported");
6275 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006276 case AP_SUITEB:
6277 /* TODO */
6278 sigma_dut_print(dut, DUT_MSG_ERROR,
6279 "SuiteB not supported");
6280 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006281 case AP_WPA2_OWE:
6282 /* TODO */
6283 sigma_dut_print(dut, DUT_MSG_ERROR,
6284 "OWE not supported");
6285 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006286 case AP_WPA2_FT_EAP:
6287 case AP_WPA2_FT_PSK:
6288 case AP_WPA2_EAP_SHA256:
6289 case AP_WPA2_PSK_SHA256:
6290 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006291 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006292 /* TODO */
6293 send_resp(dut, conn, SIGMA_ERROR,
6294 "errorCode,Unsupported KeyMgnt value");
6295 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006296 }
6297
6298 /* wifi0 settings in case of dual */
6299 run_system(dut, "cfg -a AP_RADIO_ID=0");
6300 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6301 run_system(dut, "cfg -a AP_STARTMODE=dual");
6302 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6303 run_system(dut, "cfg -a TX_CHAINMASK=7");
6304 run_system(dut, "cfg -a RX_CHAINMASK=7");
6305 }
6306
6307 switch (dut->ap_pmf) {
6308 case AP_PMF_DISABLED:
6309 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6310 run_system(dut, buf);
6311 break;
6312 case AP_PMF_OPTIONAL:
6313 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6314 run_system(dut, buf);
6315 break;
6316 case AP_PMF_REQUIRED:
6317 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6318 run_system(dut, buf);
6319 break;
6320 }
6321 if (dut->ap_add_sha256) {
6322 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6323 run_system(dut, buf);
6324 } else {
6325 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6326 run_system(dut, buf);
6327 }
6328
6329 if (dut->ap_hs2)
6330 run_system(dut, "cfg -a AP_HOTSPOT=1");
6331 else
6332 run_system(dut, "cfg -r AP_HOTSPOT");
6333
6334 if (dut->ap_interworking) {
6335 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6336 dut->ap_access_net_type);
6337 run_system(dut, buf);
6338 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6339 dut->ap_internet);
6340 run_system(dut, buf);
6341 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6342 dut->ap_venue_group);
6343 run_system(dut, buf);
6344 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6345 dut->ap_venue_type);
6346 run_system(dut, buf);
6347 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6348 dut->ap_hessid);
6349 run_system(dut, buf);
6350
6351 if (dut->ap_roaming_cons[0]) {
6352 char *second, *rc;
6353 rc = strdup(dut->ap_roaming_cons);
6354 if (rc == NULL)
6355 return 0;
6356
6357 second = strchr(rc, ';');
6358 if (second)
6359 *second++ = '\0';
6360
6361 snprintf(buf, sizeof(buf),
6362 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6363 run_system(dut, buf);
6364
6365 if (second) {
6366 snprintf(buf, sizeof(buf),
6367 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6368 "=%s", second);
6369 run_system(dut, buf);
6370 }
6371 free(rc);
6372 } else {
6373 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6374 run_system(dut,
6375 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6376 }
6377 } else {
6378 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6379 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6380 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6381 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6382 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6383 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6384 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6385 }
6386
6387 if (dut->ap_proxy_arp)
6388 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6389 else
6390 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6391 if (dut->ap_dgaf_disable)
6392 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6393 else
6394 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6395
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006396 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006397 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006398 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006399 run_system(dut, buf);
6400
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006401 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006402 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6403 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6404
6405 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6406 dut->ap2_radius_ipaddr);
6407 run_system(dut, buf);
6408
6409 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6410 dut->ap2_radius_port);
6411 run_system(dut, buf);
6412
6413 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
6414 dut->ap2_radius_password);
6415 run_system(dut, buf);
6416 } else {
6417 run_system(dut, "cfg -a AP_SECMODE_2=None");
6418 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
6419 run_system(dut, "cfg -r AP_AUTH_PORT_2");
6420 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
6421 }
6422
6423 run_system(dut, "cfg -a AP_STARTMODE=multi");
6424 }
6425
6426 run_system(dut, "cfg -c");
6427
6428 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
6429 if (system("apup") != 0) {
6430 /* to be debugged why apup returns error
6431 send_resp(dut, conn, SIGMA_ERROR,
6432 "errorCode,apup failed");
6433 return 0;
6434 */
6435 }
6436 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
6437
6438 if (dut->ap_key_mgmt != AP_OPEN) {
6439 int res;
6440 /* allow some time for hostapd to start before returning
6441 * success */
6442 usleep(500000);
6443 if (run_hostapd_cli(dut, "ping") != 0) {
6444 send_resp(dut, conn, SIGMA_ERROR,
6445 "errorCode,Failed to talk to hostapd");
6446 return 0;
6447 }
6448
6449 if (dut->ap_hs2 && !dut->ap_anqpserver) {
6450 /* the cfg app doesn't like ";" in the variables */
6451 res = ath_ap_append_hostapd_conf(dut);
6452 if (res < 0)
6453 return res;
6454
6455 /* wait for hostapd to be ready */
6456 usleep(500000);
6457 if (run_hostapd_cli(dut, "ping") != 0) {
6458 send_resp(dut, conn, SIGMA_ERROR,
6459 "errorCode,Failed to talk to "
6460 "hostapd");
6461 return 0;
6462 }
6463 }
6464 }
6465
6466 ath_ap_set_params(dut);
6467
6468 if (dut->ap_anqpserver)
6469 return cmd_ath_ap_anqpserver_start(dut);
6470
6471 if (dut->ap2_proxy_arp)
6472 run_system(dut, "iwpriv ath1 proxy_arp 1");
6473
6474 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
6475 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
6476 if (system(buf) != 0) {
6477 sigma_dut_print(dut, DUT_MSG_ERROR,
6478 "iwpriv htweptkip failed");
6479 }
6480 }
6481
6482 return 1;
6483}
6484
6485
6486static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
6487 const char *ifname)
6488{
6489 char buf[200];
6490
6491 if (!chain || !ifname)
6492 return -2;
6493
6494 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6495 if (system(buf) != 0) {
6496 sigma_dut_print(dut, DUT_MSG_ERROR,
6497 "Failed to set ebtables rules, RULE-1, %s",
6498 chain);
6499 return -2;
6500 }
6501
6502 snprintf(buf, sizeof(buf),
6503 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6504 chain, ifname);
6505 if (system(buf) != 0) {
6506 sigma_dut_print(dut, DUT_MSG_ERROR,
6507 "Failed to set ebtables rules, RULE-2, %s",
6508 chain);
6509 return -2;
6510 }
6511
6512 snprintf(buf, sizeof(buf),
6513 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
6514 chain, ifname);
6515 if (system(buf) != 0) {
6516 sigma_dut_print(dut, DUT_MSG_ERROR,
6517 "Failed to set ebtables rules, RULE-3, %s",
6518 chain);
6519 return -2;
6520 }
6521
6522 snprintf(buf, sizeof(buf),
6523 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
6524 chain, ifname);
6525 if (system(buf) != 0) {
6526 sigma_dut_print(dut, DUT_MSG_ERROR,
6527 "Failed to set ebtables rules, RULE-4, %s",
6528 chain);
6529 return -2;
6530 }
6531
6532 return 0;
6533}
6534
6535
6536static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
6537 const char *chain,
6538 const char *ifname)
6539{
6540 char buf[200];
6541
6542 if (!chain || !ifname)
6543 return -2;
6544
6545 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6546 if (system(buf) != 0) {
6547 sigma_dut_print(dut, DUT_MSG_ERROR,
6548 "Failed to set ebtables rules, RULE-5, %s",
6549 chain);
6550 return -2;
6551 }
6552
6553 snprintf(buf, sizeof(buf),
6554 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6555 chain, ifname);
6556 if (system(buf) != 0) {
6557 sigma_dut_print(dut, DUT_MSG_ERROR,
6558 "Failed to set ebtables rules, RULE-6, %s",
6559 chain);
6560 return -2;
6561 }
6562
6563 snprintf(buf, sizeof(buf),
6564 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
6565 chain, ifname);
6566 if (system(buf) != 0) {
6567 sigma_dut_print(dut, DUT_MSG_ERROR,
6568 "Failed to set ebtables rules, RULE-7, %s",
6569 chain);
6570 return -2;
6571 }
6572
6573 snprintf(buf, sizeof(buf),
6574 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
6575 chain, ifname);
6576 if (system(buf) != 0) {
6577 sigma_dut_print(dut, DUT_MSG_ERROR,
6578 "Failed to set ebtables rules, RULE-8, %s",
6579 chain);
6580 return -2;
6581 }
6582
6583 return 0;
6584}
6585
6586
Jouni Malinendbbc2c42018-11-14 23:55:41 +02006587static void set_ebtables_forward_drop(struct sigma_dut *dut,
6588 const char *ifname, const char *ifname2)
6589{
6590 char buf[128];
6591
6592 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6593 ifname, ifname2);
6594 if (system(buf) != 0)
6595 sigma_dut_print(dut, DUT_MSG_ERROR,
6596 "Failed to set ebtables rule");
6597
6598 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6599 ifname2, ifname);
6600 if (system(buf) != 0)
6601 sigma_dut_print(dut, DUT_MSG_ERROR,
6602 "Failed to set ebtables rule");
6603}
6604
6605
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006606static int check_channel(int channel)
6607{
6608 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
6609 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
6610 161, 165 };
6611 int num_chan = sizeof(channel_list) / sizeof(int);
6612 int i;
6613
6614 for (i = 0; i < num_chan; i++) {
6615 if (channel == channel_list[i])
6616 return i;
6617 }
6618
6619 return -1;
6620}
6621
6622
6623static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
6624{
6625 int ch_base;
6626 int period;
6627
6628 if (check_channel(channel) < 0)
6629 return -1;
6630
6631 if (channel >= 36 && channel <= 64)
6632 ch_base = 36;
6633 else if (channel >= 100 && channel <= 144)
6634 ch_base = 100;
6635 else
6636 ch_base = 149;
6637
6638 period = channel % ch_base * 5 / chwidth;
6639 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
6640}
6641
6642
6643static int is_ht40plus_chan(int chan)
6644{
6645 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
6646 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
6647 chan == 132 || chan == 149 || chan == 157;
6648}
6649
6650
6651static int is_ht40minus_chan(int chan)
6652{
6653 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
6654 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
6655 chan == 136 || chan == 153 || chan == 161;
6656}
6657
6658
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05306659static int get_5g_channel_freq(int chan)
6660{
6661 return 5000 + chan * 5;
6662}
6663
6664
Jouni Malinen3d633da2017-09-14 22:19:21 +03006665static const char * hostapd_cipher_name(enum ap_cipher cipher)
6666{
6667 switch (cipher) {
6668 case AP_CCMP:
6669 return "CCMP";
6670 case AP_TKIP:
6671 return "TKIP";
6672 case AP_CCMP_TKIP:
6673 return "CCMP TKIP";
6674 case AP_GCMP_256:
6675 return "GCMP-256";
6676 case AP_GCMP_128:
6677 return "GCMP";
6678 case AP_CCMP_256:
6679 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02006680 case AP_CCMP_128_GCMP_256:
6681 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006682 default:
6683 return "UNKNOWN";
6684 }
6685}
6686
6687
6688static const char *
6689hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
6690{
6691 switch (cipher) {
6692 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03006693 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006694 case AP_BIP_CMAC_256:
6695 return "BIP-CMAC-256";
6696 case AP_BIP_GMAC_128:
6697 return "BIP-GMAC-128";
6698 case AP_BIP_CMAC_128:
6699 return "AES-128-CMAC";
6700 default:
6701 return "UNKNOWN";
6702 }
6703}
6704
6705
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02006706static int ap_set_60g_ese(struct sigma_dut *dut, int count,
6707 struct sigma_ese_alloc *allocs)
6708{
6709 switch (get_driver_type()) {
6710#ifdef __linux__
6711 case DRIVER_WIL6210:
6712 return wil6210_set_ese(dut, count, allocs);
6713#endif /* __linux__ */
6714 default:
6715 sigma_dut_print(dut, DUT_MSG_ERROR,
6716 "Unsupported ap_set_60g_ese with the current driver");
6717 return -1;
6718 }
6719}
6720
6721
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006722static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6723{
6724 switch (get_driver_type()) {
6725#ifdef __linux__
6726 case DRIVER_WIL6210:
6727 return wil6210_set_force_mcs(dut, force, mcs);
6728#endif /* __linux__ */
6729 default:
6730 sigma_dut_print(dut, DUT_MSG_ERROR,
6731 "Unsupported ap_set_force_mcs with the current driver");
6732 return -1;
6733 }
6734}
6735
6736
Jouni Malinena326d7b2017-09-04 13:46:02 +03006737int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
6738 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006739{
6740 /* const char *name = get_param(cmd, "NAME"); */
6741 FILE *f;
6742 const char *ifname;
6743 char buf[500];
6744 char path[100];
6745 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03006746 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05306747#ifdef ANDROID
6748 struct group *gr;
6749#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006750
6751 drv = get_driver_type();
6752
6753 if (dut->mode == SIGMA_MODE_STATION) {
6754 stop_sta_mode(dut);
6755 sleep(1);
6756 }
6757
6758 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
6759 snprintf(buf, sizeof(buf), "ifconfig %s down",
6760 dut->sniffer_ifname);
6761 if (system(buf) != 0) {
6762 sigma_dut_print(dut, DUT_MSG_INFO,
6763 "Failed to run '%s'", buf);
6764 }
6765 snprintf(buf, sizeof(buf), "iw dev %s set type station",
6766 dut->sniffer_ifname);
6767 if (system(buf) != 0) {
6768 sigma_dut_print(dut, DUT_MSG_INFO,
6769 "Failed to run '%s'", buf);
6770 }
6771 }
6772
6773 dut->mode = SIGMA_MODE_AP;
6774
6775 if (drv == DRIVER_ATHEROS)
6776 return cmd_ath_ap_config_commit(dut, conn, cmd);
6777 if (drv == DRIVER_WCN)
6778 return cmd_wcn_ap_config_commit(dut, conn, cmd);
6779 if (drv == DRIVER_OPENWRT)
6780 return cmd_owrt_ap_config_commit(dut, conn, cmd);
6781
6782 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
6783 if (f == NULL) {
6784 sigma_dut_print(dut, DUT_MSG_ERROR,
6785 "%s: Failed to open sigma_dut-ap.conf",
6786 __func__);
6787 return -2;
6788 }
6789 switch (dut->ap_mode) {
6790 case AP_11g:
6791 case AP_11b:
6792 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306793 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
6794 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
6795 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006796 ifname = sigma_main_ifname;
6797 fprintf(f, "hw_mode=g\n");
6798 break;
6799 case AP_11a:
6800 case AP_11na:
6801 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306802 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006803 if (sigma_main_ifname)
6804 ifname = sigma_main_ifname;
6805 else
6806 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306807 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006808 if (if_nametoindex("wlan1") > 0)
6809 ifname = "wlan1";
6810 else
6811 ifname = "wlan0";
6812 } else {
6813 ifname = get_main_ifname();
6814 }
6815 fprintf(f, "hw_mode=a\n");
6816 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02006817 case AP_11ad:
6818 ifname = get_main_ifname();
6819 fprintf(f, "hw_mode=ad\n");
6820 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006821 default:
6822 fclose(f);
6823 return -1;
6824 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006825 if (dut->hostapd_ifname)
6826 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006827
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306828 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006829 fprintf(f, "driver=nl80211\n");
6830
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306831 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6832 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006833 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05306834 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
6835
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006836 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306837 if (dut->ap_mode == AP_11ng &&
6838 (dut->ap_chwidth == AP_40 ||
6839 (dut->ap_chwidth == AP_AUTO &&
6840 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006841 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306842 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306844 ht40minus = 1;
6845 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006846 }
6847
6848 /* configure ht_capab based on channel width */
6849 if (dut->ap_mode == AP_11na &&
6850 (dut->ap_chwidth == AP_40 ||
6851 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306852 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006853 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306854 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006855 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306856 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306858
6859 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306860 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306861
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306862 /* Overwrite the ht_capab with offset value if configured */
6863 if (dut->ap_chwidth == AP_40 &&
6864 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
6865 ht40plus = 1;
6866 ht40minus = 0;
6867 } else if (dut->ap_chwidth == AP_40 &&
6868 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
6869 ht40minus = 1;
6870 ht40plus = 0;
6871 }
6872
Tamizh chelvam431c6002017-03-07 17:07:16 +05306873 fprintf(f, "ht_capab=%s%s%s\n",
6874 ht40plus ? "[HT40+]" : "",
6875 ht40minus ? "[HT40-]" : "",
6876 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006877 }
6878
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306879 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6880 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006881 dut->ap_mode == AP_11ac) {
6882 fprintf(f, "ieee80211ac=1\n"
6883 "ieee80211n=1\n"
6884 "ht_capab=[HT40+]\n");
6885 }
6886
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306887 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6888 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006889 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
6890 if (dut->ap_countrycode[0]) {
6891 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
6892 fprintf(f, "ieee80211d=1\n");
6893 fprintf(f, "ieee80211h=1\n");
6894 }
6895 }
6896
6897 fprintf(f, "interface=%s\n", ifname);
6898 if (dut->bridge)
6899 fprintf(f, "bridge=%s\n", dut->bridge);
6900 fprintf(f, "channel=%d\n", dut->ap_channel);
6901
6902 if (sigma_hapd_ctrl)
6903 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
6904 else
6905 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
6906
6907 if (dut->ap_ssid[0])
6908 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6909 else
6910 fprintf(f, "ssid=QCA AP OOB\n");
6911 if (dut->ap_bcnint)
6912 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
6913
6914 switch (dut->ap_key_mgmt) {
6915 case AP_OPEN:
6916 if (dut->ap_cipher == AP_WEP)
6917 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
6918 break;
6919 case AP_WPA2_PSK:
6920 case AP_WPA2_PSK_MIXED:
6921 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006922 case AP_WPA2_SAE:
6923 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006924 case AP_WPA2_PSK_SHA256:
6925 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006926 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6927 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006928 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
6929 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
6930 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006931 fprintf(f, "wpa=2\n");
6932 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6933 fprintf(f, "wpa=3\n");
6934 else
6935 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03006936 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6937 key_mgmt = "SAE";
6938 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6939 key_mgmt = "WPA-PSK SAE";
6940 else
6941 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006942 switch (dut->ap_pmf) {
6943 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006944 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006945 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6946 break;
6947 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03006948 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006949 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6950 break;
6951 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006952 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6953 key_mgmt = "SAE";
6954 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6955 key_mgmt = "WPA-PSK-SHA256 SAE";
6956 else
6957 key_mgmt = "WPA-PSK-SHA256";
6958 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006959 break;
6960 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03006961 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
6962 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
6963 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
6964 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02006965 fprintf(f, "wpa_pairwise=%s\n",
6966 hostapd_cipher_name(dut->ap_cipher));
6967 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6968 fprintf(f, "group_cipher=%s\n",
6969 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03006970 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6971 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02006972 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
6973 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03006974 else
6975 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006976 break;
6977 case AP_WPA2_EAP:
6978 case AP_WPA2_EAP_MIXED:
6979 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006980 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006981 case AP_WPA2_EAP_SHA256:
6982 case AP_WPA2_FT_EAP:
6983 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006984 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006985 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006986 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
6987 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
6988 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
6989 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006990 fprintf(f, "wpa=2\n");
6991 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6992 fprintf(f, "wpa=3\n");
6993 else
6994 fprintf(f, "wpa=1\n");
6995 switch (dut->ap_pmf) {
6996 case AP_PMF_DISABLED:
6997 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
6998 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
6999 break;
7000 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007001 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
7002 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
7003 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7004 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007005 break;
7006 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007007 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
7008 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7009 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007010 break;
7011 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007012 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
7013 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
7014 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
7015 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
7016 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
7017 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007018 fprintf(f, "wpa_pairwise=%s\n",
7019 hostapd_cipher_name(dut->ap_cipher));
7020 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7021 fprintf(f, "group_cipher=%s\n",
7022 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007023 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7024 if (dut->ap_radius_port)
7025 fprintf(f, "auth_server_port=%d\n",
7026 dut->ap_radius_port);
7027 fprintf(f, "auth_server_shared_secret=%s\n",
7028 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03007029 if (dut->program == PROGRAM_HS2_R3) {
7030 fprintf(f, "radius_das_port=3799\n");
7031 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
7032 dut->ap_radius_password);
7033 fprintf(f, "radius_das_require_event_timestamp=1\n");
7034 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007035 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03007036 case AP_SUITEB:
7037 fprintf(f, "ieee8021x=1\n");
7038 fprintf(f, "wpa=2\n");
7039 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03007040 fprintf(f, "wpa_pairwise=%s\n",
7041 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02007042 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7043 fprintf(f, "group_cipher=%s\n",
7044 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03007045 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7046 fprintf(f, "group_mgmt_cipher=%s\n",
7047 hostapd_group_mgmt_cipher_name(
7048 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03007049 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7050 if (dut->ap_radius_port)
7051 fprintf(f, "auth_server_port=%d\n",
7052 dut->ap_radius_port);
7053 fprintf(f, "auth_server_shared_secret=%s\n",
7054 dut->ap_radius_password);
7055 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03007056 case AP_WPA2_OWE:
7057 fprintf(f, "wpa=2\n");
7058 fprintf(f, "wpa_key_mgmt=OWE\n");
7059 fprintf(f, "rsn_pairwise=%s\n",
7060 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03007061 if (dut->ap_sae_groups)
7062 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03007063 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03007064 case AP_OSEN:
7065 fprintf(f, "osen=1\n");
7066 fprintf(f, "disable_dgaf=1\n");
7067 fprintf(f, "wpa_pairwise=%s\n",
7068 hostapd_cipher_name(dut->ap_cipher));
7069 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7070 fprintf(f, "group_cipher=%s\n",
7071 hostapd_cipher_name(dut->ap_group_cipher));
7072 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7073 if (dut->ap_radius_port)
7074 fprintf(f, "auth_server_port=%d\n",
7075 dut->ap_radius_port);
7076 fprintf(f, "auth_server_shared_secret=%s\n",
7077 dut->ap_radius_password);
7078 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007079 }
7080
Jouni Malinen09550de2019-03-26 00:24:11 +02007081 if (dut->ap_sae_passwords) {
7082 char *tmp, *pos, *end, *id;
7083
7084 tmp = strdup(dut->ap_sae_passwords);
7085 if (!tmp) {
7086 fclose(f);
7087 return ERROR_SEND_STATUS;
7088 }
7089
7090 pos = tmp;
7091 while (*pos) {
7092 end = strchr(pos, ';');
7093 if (end)
7094 *end = '\0';
7095 id = strchr(pos, ':');
7096 if (id)
7097 *id++ = '\0';
7098
7099 fprintf(f, "sae_password=%s%s%s\n",
7100 pos, id ? "|id=" : "", id ? id : "");
7101 if (!end)
7102 break;
7103 pos = end + 1;
7104 }
7105
7106 free(tmp);
7107 }
7108
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05307109 if (dut->ap_rsn_preauth)
7110 fprintf(f, "rsn_preauth=1\n");
7111
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007112 switch (dut->ap_pmf) {
7113 case AP_PMF_DISABLED:
7114 break;
7115 case AP_PMF_OPTIONAL:
7116 fprintf(f, "ieee80211w=1\n");
Jouni Malinen1287cd72018-01-04 17:08:01 +02007117 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7118 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007119 break;
7120 case AP_PMF_REQUIRED:
7121 fprintf(f, "ieee80211w=2\n");
7122 break;
7123 }
7124
Jouni Malinen6be21c82018-08-01 18:47:24 +03007125 if (ap_ft_enabled(dut)) {
7126 unsigned char own_addr[ETH_ALEN];
7127
7128 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
7129 fprintf(f, "ft_over_ds=0\n");
7130 fprintf(f, "nas_identifier=nas1.example.com\n");
7131 if (get_hwaddr(ifname, own_addr) < 0) {
7132 memset(own_addr, 0, ETH_ALEN);
7133 own_addr[0] = 0x02;
7134 }
7135 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7136 own_addr[0], own_addr[1], own_addr[2],
7137 own_addr[3], own_addr[4], own_addr[5]);
7138 fprintf(f, "ft_psk_generate_local=1\n");
7139 fprintf(f, "pmk_r1_push=0\n");
7140 fprintf(f,
7141 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
7142 fprintf(f,
7143 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff");
7144 }
7145
Jouni Malinen3c367e82017-06-23 17:01:47 +03007146 if (dut->rsne_override)
7147 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
7148
Jouni Malinen68143132017-09-02 02:34:08 +03007149 if (dut->sae_commit_override)
7150 fprintf(f, "sae_commit_override=%s\n",
7151 dut->sae_commit_override);
7152
Jouni Malinened670f42017-08-31 01:39:28 +03007153 if (dut->ap_sae_groups)
7154 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007155
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007156 if (dut->sae_anti_clogging_threshold >= 0)
7157 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7158 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007159 if (dut->sae_reflection)
7160 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007161
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007162 if (dut->ap_p2p_mgmt)
7163 fprintf(f, "manage_p2p=1\n");
7164
7165 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7166 fprintf(f, "tdls_prohibit=1\n");
7167 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
7168 fprintf(f, "tdls_prohibit_chan_switch=1\n");
7169 if (dut->ap_p2p_cross_connect >= 0) {
7170 fprintf(f, "manage_p2p=1\n"
7171 "allow_cross_connection=%d\n",
7172 dut->ap_p2p_cross_connect);
7173 }
7174
Jouni Malinen4d479c92018-11-06 00:43:36 +02007175 if (dut->ap_l2tif || dut->ap_proxy_arp ||
7176 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007177 if (!dut->bridge) {
7178 sigma_dut_print(dut, DUT_MSG_ERROR,
7179 "Bridge must be configured. Run with -b <brname>.");
7180 fclose(f);
7181 return -2;
7182 }
7183 fprintf(f, "ap_isolate=1\n");
7184 }
7185
7186 if (dut->ap_proxy_arp)
7187 fprintf(f, "proxy_arp=1\n");
7188
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307189 if (dut->ap_wme)
7190 fprintf(f, "wmm_enabled=1\n");
7191
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307192 if (dut->ap_wmmps == AP_WMMPS_ON)
7193 fprintf(f, "uapsd_advertisement_enabled=1\n");
7194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007195 if (dut->ap_hs2) {
7196 if (dut->ap_bss_load) {
7197 char *bss_load;
7198
7199 switch (dut->ap_bss_load) {
7200 case -1:
7201 bss_load = "bss_load_update_period=10";
7202 break;
7203 case 1:
7204 /* STA count: 1, CU: 50, AAC: 65535 */
7205 bss_load = "bss_load_test=1:50:65535";
7206 break;
7207 case 2:
7208 /* STA count: 1, CU: 200, AAC: 65535 */
7209 bss_load = "bss_load_test=1:200:65535";
7210 break;
7211 case 3:
7212 /* STA count: 1, CU: 75, AAC: 65535 */
7213 bss_load = "bss_load_test=1:75:65535";
7214 break;
7215 default:
7216 bss_load = NULL;
7217 break;
7218 }
7219
7220 if (!bss_load) {
7221 fclose(f);
7222 return -2;
7223 }
7224 fprintf(f, "%s\n", bss_load);
7225 }
7226
7227 if (append_hostapd_conf_hs2(dut, f)) {
7228 fclose(f);
7229 return -2;
7230 }
7231 }
7232
7233 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
7234 fclose(f);
7235 return -2;
7236 }
7237
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007238 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007239 unsigned char bssid[6];
7240 char ifname2[50];
7241
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307242 if (get_hwaddr(ifname, bssid)) {
7243 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007244 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307245 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03007246 if (bssid[0] & 0x02)
7247 bssid[5] ^= 0x01;
7248 else
7249 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007250
7251 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03007252 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007253 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007254 if (dut->bridge)
7255 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007256
7257 if (drv == DRIVER_LINUX_WCN)
7258 fprintf(f, "use_driver_iface_addr=1\n");
7259 else
7260 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7261 bssid[0], bssid[1], bssid[2], bssid[3],
7262 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007263
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007264 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007265 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05307266 /* Disable DGAF for OSEN BSS */
7267 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007268 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007269 if (strlen(dut->ap2_radius_ipaddr))
7270 fprintf(f, "auth_server_addr=%s\n",
7271 dut->ap2_radius_ipaddr);
7272 if (dut->ap2_radius_port)
7273 fprintf(f, "auth_server_port=%d\n",
7274 dut->ap2_radius_port);
7275 if (strlen(dut->ap2_radius_password))
7276 fprintf(f, "auth_server_shared_secret=%s\n",
7277 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007278
7279 set_ebtables_forward_drop(dut, ifname, ifname2);
7280 } else if (dut->ap2_osu) {
7281 fprintf(f, "ap_isolate=1\n");
7282 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007283 }
7284
7285 if (dut->ap2_proxy_arp) {
7286 if (!dut->bridge) {
7287 sigma_dut_print(dut, DUT_MSG_ERROR,
7288 "Bridge must be configured. Run with -b <brname>.");
7289 fclose(f);
7290 return -2;
7291 }
7292 fprintf(f, "ap_isolate=1\n");
7293 fprintf(f, "proxy_arp=1\n");
7294
7295 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
7296 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
7297 fclose(f);
7298 return -2;
7299 }
7300
7301 }
7302 }
7303
7304 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007305 /* 60G WPS tests requires wps_state of 2 (configured) */
7306 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
7307
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007308 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007309 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007310 "device_name=QCA AP\n"
7311 "manufacturer=QCA\n"
7312 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007313 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007314 "virtual_push_button keypad%s\n"
7315 "ap_pin=12345670\n"
7316 "friendly_name=QCA Access Point\n"
7317 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007318 wps_state,
7319 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007320 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
7321 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007322 if (dut->wsc_fragment) {
7323 fprintf(f, "device_name=%s\n"
7324 "manufacturer=%s\n"
7325 "model_name=%s\n"
7326 "model_number=%s\n"
7327 "serial_number=%s\n",
7328 WPS_LONG_DEVICE_NAME,
7329 WPS_LONG_MANUFACTURER,
7330 WPS_LONG_MODEL_NAME,
7331 WPS_LONG_MODEL_NUMBER,
7332 WPS_LONG_SERIAL_NUMBER);
7333 } else {
7334 fprintf(f, "device_name=QCA AP\n"
7335 "manufacturer=QCA\n");
7336 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007337 if (dut->eap_fragment)
7338 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007339 }
7340
7341 if (dut->program == PROGRAM_VHT) {
7342 int vht_oper_centr_freq_idx;
7343
7344 if (check_channel(dut->ap_channel) < 0) {
7345 send_resp(dut, conn, SIGMA_INVALID,
7346 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307347 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007348 return 0;
7349 }
7350
7351 switch (dut->ap_chwidth) {
7352 case AP_20:
7353 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7354 vht_oper_centr_freq_idx =
7355 get_oper_centr_freq_seq_idx(20,
7356 dut->ap_channel);
7357 break;
7358 case AP_40:
7359 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7360 vht_oper_centr_freq_idx =
7361 get_oper_centr_freq_seq_idx(40,
7362 dut->ap_channel);
7363 break;
7364 case AP_80:
7365 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
7366 vht_oper_centr_freq_idx =
7367 get_oper_centr_freq_seq_idx(80,
7368 dut->ap_channel);
7369 break;
7370 case AP_160:
7371 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
7372 vht_oper_centr_freq_idx =
7373 get_oper_centr_freq_seq_idx(160,
7374 dut->ap_channel);
7375 break;
7376 default:
7377 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
7378 vht_oper_centr_freq_idx =
7379 get_oper_centr_freq_seq_idx(80,
7380 dut->ap_channel);
7381 break;
7382 }
7383 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
7384 vht_oper_centr_freq_idx);
7385 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
7386
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007387 if (dut->ap_sgi80 || dut->ap_txBF ||
7388 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307389 dut->ap_tx_stbc || dut->ap_mu_txBF) {
7390 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007391 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05307392 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05307393 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007394 (dut->ap_ldpc == VALUE_ENABLED) ?
7395 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307396 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
7397 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007398 }
7399 }
7400
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007401 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
7402 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
7403 /* OWE transition mode */
7404 unsigned char bssid[6];
7405 char ifname2[50];
7406 unsigned long val;
7407 FILE *f2;
7408
7409 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7410
7411 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7412 val = 0x12345678; /* default to something */
7413 f2 = fopen("/dev/urandom", "r");
7414 if (f2) {
7415 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7416 sigma_dut_print(dut, DUT_MSG_ERROR,
7417 "Could not read /dev/urandom");
7418 }
7419 fclose(f2);
7420 }
7421 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007422 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007423
7424 if (get_hwaddr(ifname, bssid)) {
7425 fclose(f);
7426 return -2;
7427 }
7428 if (bssid[0] & 0x02)
7429 bssid[5] ^= 0x01;
7430 else
7431 bssid[0] |= 0x02;
7432
7433 fprintf(f, "bss=%s\n", ifname2);
7434 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7435 if (dut->bridge)
7436 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007437 if (drv == DRIVER_LINUX_WCN)
7438 fprintf(f, "use_driver_iface_addr=1\n");
7439 else
7440 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7441 bssid[0], bssid[1], bssid[2], bssid[3],
7442 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007443 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7444 }
7445
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007446 if (dut->ap_key_mgmt == AP_OPEN &&
7447 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
7448 /* OWE transition mode */
7449 unsigned char bssid[6];
7450 char ifname2[50];
7451 unsigned long val;
7452 FILE *f2;
7453
7454 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7455
7456 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7457 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7458
7459 if (get_hwaddr(ifname, bssid)) {
7460 fclose(f);
7461 return -2;
7462 }
7463 if (bssid[0] & 0x02)
7464 bssid[5] ^= 0x01;
7465 else
7466 bssid[0] |= 0x02;
7467
7468 fprintf(f, "bss=%s\n", ifname2);
7469 val = 0x12345678; /* default to something */
7470 f2 = fopen("/dev/urandom", "r");
7471 if (f2) {
7472 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7473 sigma_dut_print(dut, DUT_MSG_ERROR,
7474 "Could not read /dev/urandom");
7475 }
7476 fclose(f2);
7477 }
7478 fprintf(f, "ssid=owe-%lx\n", val);
7479 if (dut->bridge)
7480 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007481 if (drv == DRIVER_LINUX_WCN)
7482 fprintf(f, "use_driver_iface_addr=1\n");
7483 else
7484 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7485 bssid[0], bssid[1], bssid[2], bssid[3],
7486 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007487 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7488 fprintf(f, "wpa=2\n");
7489 fprintf(f, "wpa_key_mgmt=OWE\n");
7490 fprintf(f, "rsn_pairwise=CCMP\n");
7491 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007492 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007493 if (dut->ap_sae_groups)
7494 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
7495 }
7496
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307497 if (dut->program == PROGRAM_OCE) {
7498 fprintf(f, "oce=%d\n",
7499 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
7500 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007501 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007502 if (dut->use_hostapd_pid_file)
7503 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007504#ifdef __QNXNTO__
7505 if (system("slay hostapd") == 0)
7506#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007507 if (!dut->use_hostapd_pid_file &&
7508 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7509 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007510#endif /* __QNXNTO__ */
7511 {
7512 int i;
7513 /* Wait some time to allow hostapd to complete cleanup before
7514 * starting a new process */
7515 for (i = 0; i < 10; i++) {
7516 usleep(500000);
7517#ifdef __QNXNTO__
7518 if (system("pidin | grep hostapd") != 0)
7519 break;
7520#else /* __QNXNTO__ */
7521 if (system("pidof hostapd") != 0)
7522 break;
7523#endif /* __QNXNTO__ */
7524 }
7525 }
Jouni Malinend86e5822017-08-29 03:55:32 +03007526 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007527
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307528#ifdef ANDROID
7529 /* Set proper conf file permissions so that hostapd process
7530 * can access it.
7531 */
7532 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
7533 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
7534 sigma_dut_print(dut, DUT_MSG_ERROR,
7535 "Error changing permissions");
7536
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307537 gr = getgrnam("wifi");
7538 if (!gr ||
7539 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307540 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
7541#endif /* ANDROID */
7542
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007543 if (drv == DRIVER_QNXNTO) {
7544 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05307545 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007546 "/sigma_dut-ap.conf",
7547 dut->hostapd_debug_log ? "-ddKt -f " : "",
7548 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007549 dut->hostapd_entropy_log ? " -e" : "",
7550 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
7551 "");
7552 } else {
7553 /*
7554 * It looks like a monitor interface can cause some issues for
7555 * beaconing, so remove it (if injection was used) before
7556 * starting hostapd.
7557 */
7558 if (if_nametoindex("sigmadut") > 0 &&
7559 system("iw dev sigmadut del") != 0)
7560 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7561 "monitor interface");
7562
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007563 snprintf(path, sizeof(path), "%shostapd",
7564 file_exists("hostapd") ? "./" : "");
7565 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007566 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007567 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007568 dut->hostapd_debug_log ? " -ddKt -f" : "",
7569 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
7570 dut->hostapd_entropy_log ? " -e" : "",
7571 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007572 "",
7573 dut->use_hostapd_pid_file ?
7574 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007575 }
7576
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007577 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007578 if (system(buf) != 0) {
7579 send_resp(dut, conn, SIGMA_ERROR,
7580 "errorCode,Failed to start hostapd");
7581 return 0;
7582 }
7583
7584 /* allow some time for hostapd to start before returning success */
7585 usleep(500000);
7586 if (run_hostapd_cli(dut, "ping") != 0) {
7587 send_resp(dut, conn, SIGMA_ERROR,
7588 "errorCode,Failed to talk to hostapd");
7589 return 0;
7590 }
7591
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05307592 if (drv == DRIVER_LINUX_WCN) {
7593 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
7594 ap_inet_addr, ap_inet_mask);
7595 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
7596 ifname, ap_inet_addr, ap_inet_mask);
7597 if (system(buf) != 0) {
7598 sigma_dut_print(dut, DUT_MSG_ERROR,
7599 "Failed to initialize the interface");
7600 return -1;
7601 }
7602 }
7603
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007604 if (dut->ap_l2tif) {
7605 snprintf(path, sizeof(path),
7606 "/sys/class/net/%s/brport/hairpin_mode",
7607 ifname);
7608 if (!file_exists(path)) {
7609 sigma_dut_print(dut, DUT_MSG_ERROR,
7610 "%s must be binded to the bridge for L2TIF",
7611 ifname);
7612 return -2;
7613 }
7614
7615 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
7616 if (system(buf) != 0) {
7617 sigma_dut_print(dut, DUT_MSG_ERROR,
7618 "Failed to enable hairpin_mode for L2TIF");
7619 return -2;
7620 }
7621
7622 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
7623 if (system(buf) != 0) {
7624 sigma_dut_print(dut, DUT_MSG_ERROR,
7625 "Failed to set ebtables rules, RULE-9");
7626 return -2;
7627 }
7628
7629 snprintf(buf, sizeof(buf),
7630 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
7631 ifname);
7632 if (system(buf) != 0) {
7633 sigma_dut_print(dut, DUT_MSG_ERROR,
7634 "Failed to set ebtables rules, RULE-11");
7635 return -2;
7636 }
7637 }
7638
7639 if (dut->ap_proxy_arp) {
7640 if (dut->ap_dgaf_disable) {
7641 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
7642 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
7643 return -2;
7644 } else {
7645 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
7646 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
7647 return -2;
7648 }
7649
7650 /* For 4.5-(c) */
7651 snprintf(buf, sizeof(buf),
7652 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
7653 ifname);
7654 if (system(buf) != 0) {
7655 sigma_dut_print(dut, DUT_MSG_ERROR,
7656 "Failed to set ebtables rules, RULE-10");
7657 return -2;
7658 }
7659 }
7660
7661 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
7662 /* Drop TDLS frames */
7663 snprintf(buf, sizeof(buf),
7664 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
7665 if (system(buf) != 0) {
7666 sigma_dut_print(dut, DUT_MSG_ERROR,
7667 "Failed to set ebtables rules, RULE-13");
7668 return -2;
7669 }
7670 }
7671
7672 if (dut->ap_fake_pkhash &&
7673 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
7674 send_resp(dut, conn, SIGMA_ERROR,
7675 "errorCode,Could not enable FakePubKey");
7676 return 0;
7677 }
7678
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007679 if (dut->program == PROGRAM_60GHZ && dut->ap_num_ese_allocs > 0) {
7680 /* wait extra time for AP to start */
7681 sleep(2);
7682 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
7683 dut->ap_ese_allocs)) {
7684 send_resp(dut, conn, SIGMA_ERROR,
7685 "errorCode,Could not set ExtSch");
7686 return 0;
7687 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007688 if (dut->ap_fixed_rate) {
7689 sigma_dut_print(dut, DUT_MSG_DEBUG,
7690 "forcing TX MCS index %d",
7691 dut->ap_mcs);
7692 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
7693 send_resp(dut, conn, SIGMA_ERROR,
7694 "errorCode,Could not force MCS");
7695 return -2;
7696 }
7697 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007698 }
7699
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007700 if (dut->wps_forced_version) {
7701 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
7702 dut->wps_forced_version);
7703 if (hapd_command(ifname, buf) < 0) {
7704 send_resp(dut, conn, SIGMA_ERROR,
7705 "errorCode,Fail to set wps_version_number");
7706 return STATUS_SENT;
7707 }
7708 }
7709
Jouni Malinend86e5822017-08-29 03:55:32 +03007710 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007711 return 1;
7712}
7713
7714
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307715static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
7716 struct qos_params *qos, const char *cwmin,
7717 const char *cwmax, const char *aifs,
7718 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007719{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307720 int val;
7721
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007722 if (cwmin) {
7723 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307724 val = atoi(cwmin);
7725 if (val < 0 || val > 15) {
7726 send_resp(dut, conn, SIGMA_INVALID,
7727 "errorCode,Invalid cwMin");
7728 return 0;
7729 }
7730 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731 }
7732
7733 if (cwmax) {
7734 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307735 val = atoi(cwmax);
7736 if (val < 0 || val > 15) {
7737 send_resp(dut, conn, SIGMA_INVALID,
7738 "errorCode,Invalid cwMax");
7739 return 0;
7740 }
7741 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007742 }
7743
7744 if (aifs) {
7745 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307746 val = atoi(aifs);
7747 if (val < 1 || val > 255) {
7748 send_resp(dut, conn, SIGMA_INVALID,
7749 "errorCode,Invalid AIFS");
7750 return 0;
7751 }
7752 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007753 }
7754
7755 if (txop) {
7756 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307757 val = atoi(txop);
7758 if (val < 0 || val > 0xffff) {
7759 send_resp(dut, conn, SIGMA_INVALID,
7760 "errorCode,Invalid txop");
7761 return 0;
7762 }
7763 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007764 }
7765
7766 if (acm) {
7767 qos->ac = 1;
7768 qos->acm = strcasecmp(acm, "on") == 0;
7769 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307770
7771 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007772}
7773
7774
7775static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
7776 struct sigma_cmd *cmd)
7777{
7778 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307779 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
7780 get_param(cmd, "cwmin_VO"),
7781 get_param(cmd, "cwmax_VO"),
7782 get_param(cmd, "AIFS_VO"),
7783 get_param(cmd, "TXOP_VO"),
7784 get_param(cmd, "ACM_VO")) ||
7785 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
7786 get_param(cmd, "cwmin_VI"),
7787 get_param(cmd, "cwmax_VI"),
7788 get_param(cmd, "AIFS_VI"),
7789 get_param(cmd, "TXOP_VI"),
7790 get_param(cmd, "ACM_VI")) ||
7791 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
7792 get_param(cmd, "cwmin_BE"),
7793 get_param(cmd, "cwmax_BE"),
7794 get_param(cmd, "AIFS_BE"),
7795 get_param(cmd, "TXOP_BE"),
7796 get_param(cmd, "ACM_BE")) ||
7797 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
7798 get_param(cmd, "cwmin_BK"),
7799 get_param(cmd, "cwmax_BK"),
7800 get_param(cmd, "AIFS_BK"),
7801 get_param(cmd, "TXOP_BK"),
7802 get_param(cmd, "ACM_BK")))
7803 return 0;
7804
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007805 return 1;
7806}
7807
7808
7809static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
7810 struct sigma_cmd *cmd)
7811{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307812 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
7813 get_param(cmd, "cwmin_VO"),
7814 get_param(cmd, "cwmax_VO"),
7815 get_param(cmd, "AIFS_VO"),
7816 get_param(cmd, "TXOP_VO"),
7817 get_param(cmd, "ACM_VO")) ||
7818 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
7819 get_param(cmd, "cwmin_VI"),
7820 get_param(cmd, "cwmax_VI"),
7821 get_param(cmd, "AIFS_VI"),
7822 get_param(cmd, "TXOP_VI"),
7823 get_param(cmd, "ACM_VI")) ||
7824 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
7825 get_param(cmd, "cwmin_BE"),
7826 get_param(cmd, "cwmax_BE"),
7827 get_param(cmd, "AIFS_BE"),
7828 get_param(cmd, "TXOP_BE"),
7829 get_param(cmd, "ACM_BE")) ||
7830 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
7831 get_param(cmd, "cwmin_BK"),
7832 get_param(cmd, "cwmax_BK"),
7833 get_param(cmd, "AIFS_BK"),
7834 get_param(cmd, "TXOP_BK"),
7835 get_param(cmd, "ACM_BK")))
7836 return 0;
7837
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007838 return 1;
7839}
7840
7841
7842static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
7843{
7844 unsigned char bssid[6];
7845 char buf[100];
7846 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
7847 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
7848 run_system(dut, "cfg -a AP_SECMODE=WPA");
7849 run_system(dut, "cfg -a AP_SECFILE=EAP");
7850 run_system(dut, "cfg -a AP_WPA=2");
7851 run_system(dut, "cfg -a AP_CYPHER=CCMP");
7852 run_system(dut, "cfg -a AP_HOTSPOT=1");
7853 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
7854 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
7855 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
7856 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
7857 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
7858 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
7859 if (!get_hwaddr("ath0", bssid)) {
7860 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7861 "%02x:%02x:%02x:%02x:%02x:%02x",
7862 bssid[0], bssid[1], bssid[2], bssid[3],
7863 bssid[4], bssid[5]);
7864 run_system(dut, buf);
7865 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7866 "%02x:%02x:%02x:%02x:%02x:%02x",
7867 bssid[0], bssid[1], bssid[2], bssid[3],
7868 bssid[4], bssid[5]);
7869 } else {
7870 if (!get_hwaddr("wifi0", bssid)) {
7871 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7872 "%02x:%02x:%02x:%02x:%02x:%02x",
7873 bssid[0], bssid[1], bssid[2], bssid[3],
7874 bssid[4], bssid[5]);
7875 run_system(dut, buf);
7876 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7877 "%02x:%02x:%02x:%02x:%02x:%02x",
7878 bssid[0], bssid[1], bssid[2], bssid[3],
7879 bssid[4], bssid[5]);
7880 } else {
7881 /* load the driver and try again */
7882 run_system(dut, "/etc/rc.d/rc.wlan up");
7883
7884 if (!get_hwaddr("wifi0", bssid)) {
7885 snprintf(buf, sizeof(buf),
7886 "cfg -a AP_HOTSPOT_HESSID="
7887 "%02x:%02x:%02x:%02x:%02x:%02x",
7888 bssid[0], bssid[1], bssid[2],
7889 bssid[3], bssid[4], bssid[5]);
7890 run_system(dut, buf);
7891 snprintf(dut->ap_hessid,
7892 sizeof(dut->ap_hessid),
7893 "%02x:%02x:%02x:%02x:%02x:%02x",
7894 bssid[0], bssid[1], bssid[2],
7895 bssid[3], bssid[4], bssid[5]);
7896 }
7897 }
7898 }
7899
7900 run_system(dut, "cfg -r AP_SSID_2");
7901 run_system(dut, "cfg -c");
7902 /* run_system(dut, "cfg -s"); */
7903}
7904
7905
7906static void ath_reset_vht_defaults(struct sigma_dut *dut)
7907{
7908 run_system(dut, "cfg -x");
7909 run_system(dut, "cfg -a AP_RADIO_ID=1");
7910 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
7911 run_system(dut, "cfg -a AP_STARTMODE=standard");
7912 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
7913 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
7914 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
7915 run_system(dut, "cfg -a ATH_countrycode=0x348");
7916 /* NOTE: For Beeliner we have to turn off MU-MIMO */
7917 if (system("rm /tmp/secath*") != 0) {
7918 sigma_dut_print(dut, DUT_MSG_ERROR,
7919 "Failed to remove secath file");
7920 }
7921}
7922
7923
7924static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
7925 struct sigma_cmd *cmd)
7926{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307927 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307928 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007929 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007930 int i;
7931
7932 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
7933 /*
7934 * Reset all tagged SSIDs to NULL-string and all key management
7935 * to open.
7936 */
7937 dut->ap_tag_ssid[i][0] = '\0';
7938 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
7939 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007940
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307941 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307942
7943 program = get_param(cmd, "program");
7944 if (!program)
7945 program = get_param(cmd, "prog");
7946 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007947 dut->device_type = AP_unknown;
7948 type = get_param(cmd, "type");
7949 if (type && strcasecmp(type, "Testbed") == 0)
7950 dut->device_type = AP_testbed;
7951 if (type && strcasecmp(type, "DUT") == 0)
7952 dut->device_type = AP_dut;
7953
7954 dut->ap_rts = 0;
7955 dut->ap_frgmnt = 0;
7956 dut->ap_bcnint = 0;
7957 dut->ap_key_mgmt = AP_OPEN;
7958 dut->ap_ssid[0] = '\0';
7959 dut->ap_fake_pkhash = 0;
7960 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
7961 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007962 dut->ap_addba_reject = VALUE_NOT_SET;
7963 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007964 dut->ap_is_dual = 0;
7965 dut->ap_mode = AP_inval;
7966 dut->ap_mode_1 = AP_inval;
7967
7968 dut->ap_allow_vht_wep = 0;
7969 dut->ap_allow_vht_tkip = 0;
7970 dut->ap_disable_protection = 0;
7971 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007972 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
7973 dut->ap_ldpc = VALUE_NOT_SET;
7974 dut->ap_sig_rts = VALUE_NOT_SET;
7975 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007976 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05307977 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007978 dut->ap_chwidth = AP_AUTO;
7979
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05307980 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007981 dut->ap_wpsnfc = 0;
7982 dut->ap_bss_load = -1;
7983 dut->ap_p2p_cross_connect = -1;
7984
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307985 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
7986 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307987 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307988
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007989 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007990 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08007991 dut->ap_interface_5g = 0;
7992 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08007993 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007994
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007995 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007996 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007997 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007998
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307999 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308000 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308001 dut->ap_wmmps = AP_WMMPS_ON;
8002 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308003 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308004 dut->ap_wmmps = AP_WMMPS_OFF;
8005 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308006
Jouni Malinen54a89b02018-05-01 00:16:26 +03008007 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03008008 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03008009 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03008010 dut->ap_tnc_file_name = 0;
8011 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03008012
Jouni Malinen09550de2019-03-26 00:24:11 +02008013 free(dut->ap_sae_passwords);
8014 dut->ap_sae_passwords = NULL;
8015
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008016 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008017 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008018 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008019 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008020
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008021 if (drv == DRIVER_ATHEROS)
8022 cmd_ath_ap_hs2_reset(dut);
8023 else if (drv == DRIVER_OPENWRT)
8024 cmd_owrt_ap_hs2_reset(dut);
8025
8026 dut->ap_interworking = 1;
8027 dut->ap_access_net_type = 2;
8028 dut->ap_internet = 0;
8029 dut->ap_venue_group = 2;
8030 dut->ap_venue_type = 8;
8031 dut->ap_domain_name_list[0] = '\0';
8032 dut->ap_hs2 = 1;
8033 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
8034 "506f9a;001bc504bd");
8035 dut->ap_l2tif = 0;
8036 dut->ap_proxy_arp = 0;
8037 if (dut->bridge) {
8038 char buf[50];
8039
8040 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
8041 dut->bridge);
8042 if (system(buf) != 0) {
8043 sigma_dut_print(dut, DUT_MSG_DEBUG,
8044 "%s ip neigh table flushing failed",
8045 dut->bridge);
8046 }
8047
8048 snprintf(buf, sizeof(buf), "ebtables -F");
8049 if (system(buf) != 0) {
8050 sigma_dut_print(dut, DUT_MSG_DEBUG,
8051 "%s ebtables flushing failed",
8052 dut->bridge);
8053 }
8054 }
8055 dut->ap_dgaf_disable = 0;
8056 dut->ap_p2p_cross_connect = 0;
8057 dut->ap_gas_cb_delay = 0;
8058 dut->ap_nai_realm_list = 0;
8059 dut->ap_oper_name = 0;
8060 dut->ap_venue_name = 0;
8061 for (i = 0; i < 10; i++) {
8062 dut->ap_plmn_mcc[i][0] = '\0';
8063 dut->ap_plmn_mnc[i][0] = '\0';
8064 }
8065 dut->ap_wan_metrics = 0;
8066 dut->ap_conn_capab = 0;
8067 dut->ap_ip_addr_type_avail = 0;
8068 dut->ap_net_auth_type = 0;
8069 dut->ap_oper_class = 0;
8070 dut->ap_pmf = 0;
8071 dut->ap_add_sha256 = 0;
8072 }
8073
Jouni Malinenba630452018-06-22 11:49:59 +03008074 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
8075 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008076 int i;
8077 const char hessid[] = "50:6f:9a:00:11:22";
8078
8079 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
8080 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008081 dut->ap_pmf = 1;
8082 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02008083 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008084 for (i = 0; i < 10; i++) {
8085 dut->ap_osu_server_uri[i][0] = '\0';
8086 dut->ap_osu_method[i] = 0xFF;
8087 }
8088 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008089 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008090 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008091 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008092 dut->ap_osu_icon_tag = 0;
8093 }
8094
8095 if (dut->program == PROGRAM_VHT) {
8096 /* Set up the defaults */
8097 dut->ap_mode = AP_11ac;
8098 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008099 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08008100 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008101 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008102 dut->ap_amsdu = VALUE_DISABLED;
8103 dut->ap_ldpc = VALUE_DISABLED;
8104 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008105 dut->ap_sgi80 = 0;
8106 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008107 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308108 /*
8109 * As LDPC is optional, don't enable this by default
8110 * for LINUX-WCN driver. The ap_set_wireless command
8111 * can be used to enable LDPC, when needed.
8112 */
8113 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008114 dut->ap_ldpc = VALUE_ENABLED;
8115 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008116 dut->ap_sgi80 = 1;
8117 }
8118 dut->ap_fixed_rate = 0;
8119 dut->ap_rx_streams = 3;
8120 dut->ap_tx_streams = 3;
8121 dut->ap_vhtmcs_map = 0;
8122 dut->ap_chwidth = AP_80;
8123 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008124 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05308125 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8126 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008127 if (get_driver_type() == DRIVER_ATHEROS)
8128 ath_reset_vht_defaults(dut);
8129 }
8130
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008131 if (dut->program == PROGRAM_IOTLP) {
8132 dut->wnm_bss_max_feature = VALUE_DISABLED;
8133 dut->wnm_bss_max_idle_time = 0;
8134 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8135 dut->ap_proxy_arp = 1;
8136 } else {
8137 /*
8138 * Do not touch the BSS-MAX Idle time feature
8139 * if the program is not IOTLP.
8140 */
8141 dut->wnm_bss_max_feature = VALUE_NOT_SET;
8142 dut->wnm_bss_max_idle_time = 0;
8143 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8144 }
8145
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008146 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008147 dut->ap_rrm = 1;
8148 dut->ap_rtt = 1;
8149 dut->ap_lci = 0;
8150 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008151 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008152 dut->ap_lcr = 0;
8153 dut->ap_val_lcr[0] = '\0';
8154 dut->ap_neighap = 0;
8155 dut->ap_opchannel = 0;
8156 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008157 dut->ap_fqdn_held = 0;
8158 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07008159 dut->ap_interworking = 0;
8160 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008161 dut->ap_msnt_type = 0;
8162 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008163 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07008164 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07008165 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008166
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008167 if (dut->program == PROGRAM_MBO) {
8168 dut->ap_mbo = 1;
8169 dut->ap_interworking = 1;
8170 dut->ap_ne_class = 0;
8171 dut->ap_ne_op_ch = 0;
8172 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008173 dut->ap_btmreq_disassoc_imnt = 0;
8174 dut->ap_btmreq_term_bit = 0;
8175 dut->ap_disassoc_timer = 0;
8176 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07008177 dut->ap_channel = 36;
8178 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07008179 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07008180 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008181 dut->mbo_self_ap_tuple.ap_ne_class = -1;
8182 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
8183 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008184 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008185 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008186 }
8187
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008188 if (dut->program == PROGRAM_OCE) {
8189 if (dut->ap_dhcp_stop)
8190 run_system(dut, "/etc/init.d/dnsmasq start");
8191
8192 dut->ap_dhcp_stop = 0;
8193 dut->ap_oce = VALUE_ENABLED;
8194 dut->ap_broadcast_ssid = VALUE_ENABLED;
8195 dut->ap_fils_dscv_int = 20;
8196 dut->ap_filsdscv = VALUE_ENABLED;
8197 dut->ap_filshlp = VALUE_DISABLED;
8198 dut->ap_rnr = VALUE_DISABLED;
8199 dut->ap_nairealm[0] = '\0';
8200 dut->ap_nairealm_int = 0;
8201 dut->ap_blechanutil = 0;
8202 dut->ap_ble_admit_cap = 0;
8203 dut->ap_esp = VALUE_ENABLED;
8204 dut->ap_datappdudura = 0;
8205 dut->ap_airtimefract = 0;
8206 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08008207 dut->ap_ul_availcap = 0;
8208 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08008209 dut->ap_akm = 0;
8210 dut->ap_add_sha256 = 0;
8211 dut->ap_add_sha384 = 0;
8212 dut->ap_pmksa = 0;
8213 dut->ap_pmksa_caching = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08008214 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008215 }
8216
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008217 dut->ap_he_ppdu = PPDU_NOT_SET;
8218
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08008219 dut->ap_oper_chn = 0;
8220
Jouni Malinen3c367e82017-06-23 17:01:47 +03008221 free(dut->rsne_override);
8222 dut->rsne_override = NULL;
8223
Jouni Malinen68143132017-09-02 02:34:08 +03008224 free(dut->sae_commit_override);
8225 dut->sae_commit_override = NULL;
8226
Jouni Malinened670f42017-08-31 01:39:28 +03008227 free(dut->ap_sae_groups);
8228 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03008229
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008230 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03008231 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008232
Jouni Malinen3d633da2017-09-14 22:19:21 +03008233 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02008234 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03008235 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02008236 dut->ap_passphrase[0] = '\0';
8237 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03008238
Jouni Malinend86e5822017-08-29 03:55:32 +03008239 dut->dpp_conf_id = -1;
8240
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008241 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008242 dut->ap_mode = AP_11ad;
8243 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008244 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008245 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008246 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008247 dut->ap_fixed_rate = 0;
8248
8249 dut->dev_role = DEVROLE_AP;
8250
8251 sigma_dut_print(dut, DUT_MSG_DEBUG,
8252 "Setting msdu_size to MAX: 7912");
8253 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
8254 get_main_ifname());
8255
8256 if (system(buf) != 0) {
8257 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8258 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008259 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008260 }
8261
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008262 if (ap_set_force_mcs(dut, 0, 1)) {
8263 sigma_dut_print(dut, DUT_MSG_ERROR,
8264 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008265 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008266 }
8267
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008268 if (set_ps(get_main_ifname(), dut, 1)) {
8269 sigma_dut_print(dut, DUT_MSG_ERROR,
8270 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008271 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008272 }
8273 }
8274
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02008275 if (dut->program == PROGRAM_WPS &&
8276 get_driver_type() == DRIVER_WIL6210) {
8277 /*
8278 * In 60 GHz WPS tests, we configure the AP OOB to
8279 * secure connection with a random passphrase.
8280 */
8281 char r[16], passphrase[65];
8282
8283 if (random_get_bytes(r, sizeof(r))) {
8284 sigma_dut_print(dut, DUT_MSG_ERROR,
8285 "Failed to get random bytes");
8286 return ERROR_SEND_STATUS;
8287 }
8288 if (base64_encode(r, sizeof(r),
8289 passphrase, sizeof(passphrase))) {
8290 sigma_dut_print(dut, DUT_MSG_ERROR,
8291 "Failed to generate random passphrase");
8292 return ERROR_SEND_STATUS;
8293 }
8294
8295 dut->ap_key_mgmt = AP_WPA2_PSK;
8296 dut->ap_cipher = AP_GCMP_128;
8297 strlcpy(dut->ap_passphrase, passphrase,
8298 sizeof(dut->ap_passphrase));
8299 sigma_dut_print(dut, DUT_MSG_DEBUG,
8300 "60G WPS: configure secure AP with random passphrase");
8301 }
8302
Jouni Malinend86e5822017-08-29 03:55:32 +03008303 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08008304
8305 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8306 return 1;
8307
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008308 if (dut->use_hostapd_pid_file) {
8309 kill_hostapd_process_pid(dut);
8310 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8311 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008312 int i;
8313 /* Wait some time to allow hostapd to complete cleanup before
8314 * starting a new process */
8315 for (i = 0; i < 10; i++) {
8316 usleep(500000);
8317 if (system("pidof hostapd") != 0)
8318 break;
8319 }
8320 }
8321
8322 if (if_nametoindex("sigmadut") > 0 &&
8323 system("iw dev sigmadut del") != 0)
8324 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8325 "monitor interface");
8326
8327 return 1;
8328}
8329
8330
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308331int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
8332 struct sigma_cmd *cmd)
8333{
8334 return cmd_ap_reset_default(dut, conn, cmd);
8335}
8336
8337
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008338static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
8339 struct sigma_cmd *cmd)
8340{
8341 /* const char *name = get_param(cmd, "NAME"); */
8342 struct stat s;
8343 char resp[200];
8344 FILE *f;
8345 enum driver_type drv = get_driver_type();
8346
8347 switch (drv) {
8348 case DRIVER_ATHEROS: {
8349 /* Atheros AP */
8350 struct utsname uts;
8351 char *version, athver[100];
8352
8353 if (stat("/proc/athversion", &s) != 0) {
8354 if (system("/etc/rc.d/rc.wlan up") != 0) {
8355 }
8356 }
8357
8358 athver[0] = '\0';
8359 f = fopen("/proc/athversion", "r");
8360 if (f) {
8361 if (fgets(athver, sizeof(athver), f)) {
8362 char *pos = strchr(athver, '\n');
8363 if (pos)
8364 *pos = '\0';
8365 }
8366 fclose(f);
8367 }
8368
8369 if (uname(&uts) == 0)
8370 version = uts.release;
8371 else
8372 version = "Unknown";
8373
8374 if (if_nametoindex("ath1") > 0)
8375 snprintf(resp, sizeof(resp), "interface,ath0_24G "
8376 "ath1_5G,agent,1.0,version,%s/drv:%s",
8377 version, athver);
8378 else
8379 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
8380 "agent,1.0,version,%s/drv:%s",
8381 version, athver);
8382
8383 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8384 return 0;
8385 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05308386 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008387 case DRIVER_MAC80211: {
8388 struct utsname uts;
8389 char *version;
8390
8391 if (uname(&uts) == 0)
8392 version = uts.release;
8393 else
8394 version = "Unknown";
8395
8396 if (if_nametoindex("wlan1") > 0)
8397 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
8398 "wlan1_5G,agent,1.0,version,%s", version);
8399 else
8400 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
8401 "agent,1.0,version,%s", version);
8402
8403 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8404 return 0;
8405 }
8406 case DRIVER_QNXNTO: {
8407 struct utsname uts;
8408 char *version;
8409
8410 if (uname(&uts) == 0)
8411 version = uts.release;
8412 else
8413 version = "Unknown";
8414 snprintf(resp, sizeof(resp),
8415 "interface,%s_any,agent,1.0,version,%s",
8416 sigma_main_ifname ? sigma_main_ifname : "NA",
8417 version);
8418 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8419 return 0;
8420 }
8421 case DRIVER_OPENWRT: {
8422 switch (get_openwrt_driver_type()) {
8423 case OPENWRT_DRIVER_ATHEROS: {
8424 struct utsname uts;
8425 char *version;
8426
8427 if (uname(&uts) == 0)
8428 version = uts.release;
8429 else
8430 version = "Unknown";
8431
8432 if (if_nametoindex("ath1") > 0)
8433 snprintf(resp, sizeof(resp),
8434 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
8435 version);
8436 else
8437 snprintf(resp, sizeof(resp),
8438 "interface,ath0_any,agent,1.0,version,%s",
8439 version);
8440
8441 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8442 return 0;
8443 }
8444 default:
8445 send_resp(dut, conn, SIGMA_ERROR,
8446 "errorCode,Unsupported openwrt driver");
8447 return 0;
8448 }
8449 }
8450 default:
8451 send_resp(dut, conn, SIGMA_ERROR,
8452 "errorCode,Unsupported driver");
8453 return 0;
8454 }
8455}
8456
8457
8458static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
8459 struct sigma_cmd *cmd)
8460{
8461 /* const char *name = get_param(cmd, "NAME"); */
8462 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8463 const char *val;
8464 char buf[100];
8465
8466 val = get_param(cmd, "MinorCode");
8467 if (val) {
8468 /* TODO: add support for P2P minor code */
8469 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
8470 "yet supported");
8471 return 0;
8472 }
8473
8474 val = get_param(cmd, "STA_MAC_ADDRESS");
8475 if (val == NULL)
8476 return -1;
8477 snprintf(buf, sizeof(buf), "deauth %s", val);
8478 if (run_hostapd_cli(dut, buf) != 0)
8479 return -2;
8480
8481 return 1;
8482}
8483
8484
8485#ifdef __linux__
8486int inject_frame(int s, const void *data, size_t len, int encrypt);
8487int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008488#endif /* __linux__ */
8489
8490enum send_frame_type {
8491 DISASSOC, DEAUTH, SAQUERY
8492};
8493enum send_frame_protection {
8494 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8495};
8496
8497
8498static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8499 enum send_frame_type frame,
8500 enum send_frame_protection protected,
8501 const char *sta_addr)
8502{
8503#ifdef __linux__
8504 unsigned char buf[1000], *pos;
8505 int s, res;
8506 unsigned char addr_sta[6], addr_own[6];
8507 char *ifname;
8508 char cbuf[100];
8509 struct ifreq ifr;
8510
8511 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
8512 dut->ap_mode == AP_11ac) &&
8513 if_nametoindex("wlan1") > 0)
8514 ifname = "wlan1";
8515 else
8516 ifname = "wlan0";
8517
8518 if (hwaddr_aton(sta_addr, addr_sta) < 0)
8519 return -1;
8520
8521 s = socket(AF_INET, SOCK_DGRAM, 0);
8522 if (s < 0)
8523 return -1;
8524 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07008525 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008526 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
8527 perror("ioctl");
8528 close(s);
8529 return -1;
8530 }
8531 close(s);
8532 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
8533
8534 if (if_nametoindex("sigmadut") == 0) {
8535 snprintf(cbuf, sizeof(cbuf),
8536 "iw dev %s interface add sigmadut type monitor",
8537 ifname);
8538 if (system(cbuf) != 0 ||
8539 if_nametoindex("sigmadut") == 0) {
8540 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8541 "monitor interface with '%s'", cbuf);
8542 return -2;
8543 }
8544 }
8545
8546 if (system("ifconfig sigmadut up") != 0) {
8547 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8548 "monitor interface up");
8549 return -2;
8550 }
8551
8552 pos = buf;
8553
8554 /* Frame Control */
8555 switch (frame) {
8556 case DISASSOC:
8557 *pos++ = 0xa0;
8558 break;
8559 case DEAUTH:
8560 *pos++ = 0xc0;
8561 break;
8562 case SAQUERY:
8563 *pos++ = 0xd0;
8564 break;
8565 }
8566
8567 if (protected == INCORRECT_KEY)
8568 *pos++ = 0x40; /* Set Protected field to 1 */
8569 else
8570 *pos++ = 0x00;
8571
8572 /* Duration */
8573 *pos++ = 0x00;
8574 *pos++ = 0x00;
8575
8576 /* addr1 = DA (station) */
8577 memcpy(pos, addr_sta, 6);
8578 pos += 6;
8579 /* addr2 = SA (own address) */
8580 memcpy(pos, addr_own, 6);
8581 pos += 6;
8582 /* addr3 = BSSID (own address) */
8583 memcpy(pos, addr_own, 6);
8584 pos += 6;
8585
8586 /* Seq# (to be filled by driver/mac80211) */
8587 *pos++ = 0x00;
8588 *pos++ = 0x00;
8589
8590 if (protected == INCORRECT_KEY) {
8591 /* CCMP parameters */
8592 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8593 pos += 8;
8594 }
8595
8596 if (protected == INCORRECT_KEY) {
8597 switch (frame) {
8598 case DEAUTH:
8599 /* Reason code (encrypted) */
8600 memcpy(pos, "\xa7\x39", 2);
8601 pos += 2;
8602 break;
8603 case DISASSOC:
8604 /* Reason code (encrypted) */
8605 memcpy(pos, "\xa7\x39", 2);
8606 pos += 2;
8607 break;
8608 case SAQUERY:
8609 /* Category|Action|TransID (encrypted) */
8610 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8611 pos += 4;
8612 break;
8613 default:
8614 return -1;
8615 }
8616
8617 /* CCMP MIC */
8618 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8619 pos += 8;
8620 } else {
8621 switch (frame) {
8622 case DEAUTH:
8623 /* reason code = 8 */
8624 *pos++ = 0x08;
8625 *pos++ = 0x00;
8626 break;
8627 case DISASSOC:
8628 /* reason code = 8 */
8629 *pos++ = 0x08;
8630 *pos++ = 0x00;
8631 break;
8632 case SAQUERY:
8633 /* Category - SA Query */
8634 *pos++ = 0x08;
8635 /* SA query Action - Request */
8636 *pos++ = 0x00;
8637 /* Transaction ID */
8638 *pos++ = 0x12;
8639 *pos++ = 0x34;
8640 break;
8641 }
8642 }
8643
8644 s = open_monitor("sigmadut");
8645 if (s < 0) {
8646 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8647 "monitor socket");
8648 return 0;
8649 }
8650
8651 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8652 if (res < 0) {
8653 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8654 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308655 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008656 return 0;
8657 }
8658 if (res < pos - buf) {
8659 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8660 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308661 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008662 return 0;
8663 }
8664
8665 close(s);
8666
8667 return 1;
8668#else /* __linux__ */
8669 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
8670 "yet supported");
8671 return 0;
8672#endif /* __linux__ */
8673}
8674
8675
8676int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8677 struct sigma_cmd *cmd)
8678{
8679 const char *val, *dest;
8680 char buf[100];
8681
8682 val = get_param(cmd, "FrameName");
8683 if (val == NULL)
8684 return -1;
8685
8686 if (strcasecmp(val, "QoSMapConfigure") == 0) {
8687 dest = get_param(cmd, "Dest");
8688 if (!dest)
8689 return -1;
8690
8691 val = get_param(cmd, "QoS_MAP_SET");
8692 if (val) {
8693 dut->ap_qos_map_set = atoi(val);
8694 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8695 dut->ap_qos_map_set);
8696 }
8697
8698 if (dut->ap_qos_map_set == 1)
8699 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8700 else if (dut->ap_qos_map_set == 2)
8701 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8702
8703 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8704 if (run_hostapd_cli(dut, buf) != 0)
8705 return -1;
8706 }
8707
8708 return 1;
8709}
8710
8711
8712static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8713 struct sigma_cmd *cmd)
8714{
8715 const char *val;
8716 char *ifname;
8717 char buf[100];
8718 int chwidth, nss;
8719
8720 val = get_param(cmd, "FrameName");
8721 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
8722 send_resp(dut, conn, SIGMA_ERROR,
8723 "errorCode,Unsupported FrameName");
8724 return 0;
8725 }
8726
8727 /*
8728 * Sequence of commands for Opmode notification on
8729 * Peregrine based products
8730 */
8731 ifname = get_main_ifname();
8732
8733 /* Disable STBC */
8734 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
8735 if (system(buf) != 0) {
8736 sigma_dut_print(dut, DUT_MSG_ERROR,
8737 "iwpriv tx_stbc 0 failed!");
8738 }
8739
8740 /* Check whether optional arg channel width was passed */
8741 val = get_param(cmd, "Channel_width");
8742 if (val) {
8743 switch (atoi(val)) {
8744 case 20:
8745 chwidth = 0;
8746 break;
8747 case 40:
8748 chwidth = 1;
8749 break;
8750 case 80:
8751 chwidth = 2;
8752 break;
8753 case 160:
8754 chwidth = 3;
8755 break;
8756 default:
8757 chwidth = 2;
8758 break;
8759 }
8760 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8761 ifname, chwidth);
8762 if (system(buf) != 0) {
8763 sigma_dut_print(dut, DUT_MSG_ERROR,
8764 "iwpriv chwidth failed!");
8765 }
8766 }
8767
8768 /* Check whether optional arg NSS was passed */
8769 val = get_param(cmd, "NSS");
8770 if (val) {
8771 /* Convert nss to chainmask */
8772 switch (atoi(val)) {
8773 case 1:
8774 nss = 1;
8775 break;
8776 case 2:
8777 nss = 3;
8778 break;
8779 case 3:
8780 nss = 7;
8781 break;
8782 default:
8783 /* We do not support NSS > 3 */
8784 nss = 3;
8785 break;
8786 }
8787 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
8788 ifname, nss);
8789 if (system(buf) != 0) {
8790 sigma_dut_print(dut, DUT_MSG_ERROR,
8791 "iwpriv rxchainmask failed!");
8792 }
8793 }
8794
8795 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03008796 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008797 if (system(buf) != 0) {
8798 sigma_dut_print(dut, DUT_MSG_ERROR,
8799 "iwpriv opmode_notify failed!");
8800 }
8801
8802 return 1;
8803}
8804
8805
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008806static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8807 struct sigma_cmd *cmd)
8808{
8809 const char *val;
8810 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008811 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008812
8813 val = get_param(cmd, "MsntType");
8814 if (val) {
8815 if (dut->ap_msnt_type == 0)
8816 dut->ap_msnt_type = atoi(val);
8817
8818 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
8819 dut->ap_msnt_type = atoi(val);
8820 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008821 val = get_param(cmd, "RandInterval");
8822 if (val)
8823 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008824 f = fopen("/tmp/ftmrr.txt", "a");
8825 if (!f) {
8826 sigma_dut_print(dut, DUT_MSG_ERROR,
8827 "Failed to open /tmp/ftmrr.txt");
8828 return -1;
8829 }
8830
8831 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008832 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",
8833 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008834 fclose(f);
8835 dut->ap_msnt_type = 5;
8836 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8837 }
8838 } else if (dut->ap_msnt_type == 5) {
8839 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8840 } else if (dut->ap_msnt_type == 2) {
8841 f = fopen("/tmp/wru.txt", "w");
8842 if (!f) {
8843 sigma_dut_print(dut, DUT_MSG_ERROR,
8844 "Failed to open /tmp/wru.txt");
8845 return -1;
8846 }
8847
8848 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
8849 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
8850 fclose(f);
8851 run_system(dut, "wpc -w /tmp/wru.txt");
8852 }
8853 }
8854 return 1;
8855}
8856
8857
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008858/*
8859 * The following functions parse_send_frame_params_int(),
8860 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
8861 * are used by ath_ap_send_frame_bcn_rpt_req().
8862 * Beacon Report Request is a frame used as part of the MBO program.
8863 * The command for sending beacon report has a lot of
8864 * arguments and having these functions reduces code size.
8865 *
8866 */
8867static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
8868 struct sigma_dut *dut,
8869 char *buf, size_t buf_size)
8870{
8871 const char *str_val;
8872 int int_val;
8873 char temp[100];
8874
8875 str_val = get_param(cmd, param);
8876 if (!str_val) {
8877 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8878 return -1;
8879 }
8880 int_val = atoi(str_val);
8881 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07008882 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008883 return 0;
8884}
8885
8886
8887static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
8888 struct sigma_dut *dut,
8889 char *buf, size_t buf_size)
8890{
8891 const char *str_val;
8892 char temp[100];
8893
8894 str_val = get_param(cmd, param);
8895 if (!str_val) {
8896 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8897 return -1;
8898 }
8899 snprintf(temp, sizeof(temp), " %s", str_val);
8900 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07008901 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008902 return 0;
8903}
8904
8905
8906static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
8907 struct sigma_dut *dut,
8908 char *buf, size_t buf_size)
8909{
8910 const char *str_val;
8911 unsigned char mac[6];
8912 char temp[100];
8913
8914 str_val = get_param(cmd, param);
8915 if (!str_val) {
8916 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8917 return -1;
8918 }
8919
8920 if (parse_mac_address(dut, str_val, mac) < 0) {
8921 sigma_dut_print(dut, DUT_MSG_ERROR,
8922 "MAC Address not in proper format");
8923 return -1;
8924 }
8925 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
8926 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07008927 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008928 return 0;
8929}
8930
8931
8932static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
8933 char *buf, size_t buf_size)
8934{
8935 const char *str_val;
8936 char *value = " 1";
8937
8938 str_val = get_param(cmd, param);
8939 if (!str_val || str_val[0] == '\0')
8940 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07008941 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008942
8943}
8944
8945
8946/*
8947 * wifitool athN sendbcnrpt
8948 * <STA MAC - Plugs in from Dest_MAC>
8949 * <regclass - Plugs in from RegClass - int>
8950 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
8951 * <rand_ivl - Plugs in from RandInt - string>
8952 * <duration - Plugs in from MeaDur - integer>
8953 * <mode - Plugs in from MeaMode - string>
8954 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
8955 * <rep_cond - Plugs in from RptCond - integer>
8956 * <rpt_detail - Plugs in from RptDet - integer>
8957 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
8958 * <chanrpt_mode - Plugs in from APChanRpt - integer>
8959 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
8960 * [AP channel numbers]
8961 */
8962static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
8963 struct sigma_cmd *cmd,
8964 const char *ifname)
8965{
8966 char buf[100];
8967 int rpt_det;
8968 const char *str_val;
8969 const char *mea_mode;
8970
8971 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
8972
8973 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
8974 return -1;
8975 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
8976 return -1;
8977 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
8978 return -1;
8979 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
8980 return -1;
8981 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
8982 return -1;
8983
8984 str_val = get_param(cmd, "MeaMode");
8985 if (!str_val) {
8986 sigma_dut_print(dut, DUT_MSG_ERROR,
8987 "MeaMode parameter not present in send bcn-rpt-req");
8988 return -1;
8989 }
8990 if (strcasecmp(str_val, "passive") == 0) {
8991 mea_mode = " 0";
8992 } else if (strcasecmp(str_val, "active") == 0) {
8993 mea_mode = " 1";
8994 } else if (strcasecmp(str_val, "table") == 0) {
8995 mea_mode = " 2";
8996 } else {
8997 sigma_dut_print(dut, DUT_MSG_ERROR,
8998 "MEA-MODE Value not correctly given");
8999 return -1;
9000 }
Peng Xu591be452017-05-10 17:27:28 -07009001 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009002
9003 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
9004
9005 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
9006 return -1;
9007
9008 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
9009 return -1;
9010 str_val = get_param(cmd, "RptDet");
9011 rpt_det = str_val ? atoi(str_val) : 0;
9012
9013 if (rpt_det)
9014 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
9015 else
Peng Xu591be452017-05-10 17:27:28 -07009016 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009017
9018 if (rpt_det)
9019 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
9020 sizeof(buf));
9021 else
Peng Xu591be452017-05-10 17:27:28 -07009022 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009023
9024 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
9025 return -1;
9026
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009027 str_val = get_param(cmd, "APChanRpt");
9028 if (str_val) {
9029 const char *pos;
9030 int ap_chanrpt;
9031 int ap_chanrpt_2 = 0;
9032 char chanrpt[100];
9033
9034 ap_chanrpt = atoi(str_val);
9035 pos = strchr(str_val, '_');
9036 if (pos) {
9037 pos++;
9038 ap_chanrpt_2 = atoi(pos);
9039 }
9040 if (ap_chanrpt) {
9041 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
9042 strlcat(buf, chanrpt, sizeof(buf));
9043 }
9044 if (ap_chanrpt_2) {
9045 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
9046 strlcat(buf, chanrpt, sizeof(buf));
9047 }
9048 }
9049
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009050 run_system(dut, buf);
9051 return 0;
9052}
9053
9054
9055static void inform_and_sleep(struct sigma_dut *dut, int seconds)
9056{
9057 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
9058 sleep(seconds);
9059 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
9060 seconds);
9061}
9062
9063
9064static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
9065 struct sigma_cmd *cmd, const char *ifname)
9066{
9067 unsigned char mac_addr[ETH_ALEN];
9068 int disassoc_timer;
9069 char buf[100];
9070 const char *val;
9071 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009072
9073 val = get_param(cmd, "Dest_MAC");
9074 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9075 sigma_dut_print(dut, DUT_MSG_ERROR,
9076 "MAC Address not in proper format");
9077 return -1;
9078 }
9079
9080 val = get_param(cmd, "Disassoc_Timer");
9081 if (val)
9082 disassoc_timer = atoi(val);
9083 else
9084 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02009085 if (disassoc_timer < 0) {
9086 sigma_dut_print(dut, DUT_MSG_ERROR,
9087 "Invalid Disassoc_Timer value %d",
9088 disassoc_timer);
9089 return -1;
9090 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009091
9092 val = get_param(cmd, "Cand_List");
9093 if (val && val[0])
9094 cand_list = atoi(val);
9095
9096 val = get_param(cmd, "BTMQuery_Reason_Code");
9097 if (val) {
9098 snprintf(buf, sizeof(buf), "iwpriv %s mbo_trans_rs %s",
9099 ifname, val);
9100 run_system(dut, buf);
9101 }
9102
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009103 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay) {
9104 snprintf(buf, sizeof(buf), "iwpriv %s mbo_asoc_ret 1", ifname);
9105 run_system(dut, buf);
9106 }
9107
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009108 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009109 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009110 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
9111 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
9112 dut->ap_btmreq_disassoc_imnt,
9113 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009114 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009115 dut->ap_btmreq_bss_term_dur);
9116 run_system(dut, buf);
9117
9118 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009119 if (dut->ap_btmreq_bss_term_tsf >= 2)
9120 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009121 run_system_wrapper(
9122 dut, "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9123 ifname,
9124 mac_addr[0], mac_addr[1], mac_addr[2],
9125 mac_addr[3], mac_addr[4], mac_addr[5]);
9126 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009127 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009128 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009129 run_system_wrapper(dut, "ifconfig %s up", ifname);
9130 } else if (dut->ap_btmreq_disassoc_imnt) {
9131 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
9132 run_system_wrapper(dut,
9133 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9134 ifname,
9135 mac_addr[0], mac_addr[1], mac_addr[2],
9136 mac_addr[3], mac_addr[4], mac_addr[5]);
9137 }
9138 return 0;
9139}
9140
9141
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009142static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
9143 struct sigma_cmd *cmd, const char *ifname)
9144{
9145 unsigned char mac_addr[ETH_ALEN];
9146 const char *val;
9147
9148 val = get_param(cmd, "Dest_MAC");
9149 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9150 sigma_dut_print(dut, DUT_MSG_ERROR,
9151 "MAC Address not in proper format");
9152 return -1;
9153 }
9154
9155 run_system_wrapper(dut,
9156 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9157 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
9158 mac_addr[3], mac_addr[4], mac_addr[5]);
9159 return 0;
9160}
9161
9162
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009163static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9164 struct sigma_cmd *cmd)
9165{
9166 const char *val;
9167 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009168
9169 ifname = get_main_ifname();
9170
9171 val = get_param(cmd, "FrameName");
9172 if (!val)
9173 return -1;
9174
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009175 if (strcasecmp(val, "BTMReq") == 0)
9176 ath_ap_send_frame_btm_req(dut, cmd, ifname);
9177 else if (strcasecmp(val, "BcnRptReq") == 0)
9178 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009179 else if (strcasecmp(val, "disassoc") == 0)
9180 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009181 else
9182 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009183
9184 return 1;
9185}
9186
9187
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009188static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9189 struct sigma_cmd *cmd)
9190{
9191 switch (get_driver_type()) {
9192 case DRIVER_ATHEROS:
9193 return ath_ap_send_frame_vht(dut, conn, cmd);
9194 break;
9195 case DRIVER_OPENWRT:
9196 switch (get_openwrt_driver_type()) {
9197 case OPENWRT_DRIVER_ATHEROS:
9198 return ath_ap_send_frame_vht(dut, conn, cmd);
9199 default:
9200 send_resp(dut, conn, SIGMA_ERROR,
9201 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9202 return 0;
9203 }
9204 default:
9205 send_resp(dut, conn, SIGMA_ERROR,
9206 "errorCode,Unsupported ap_send_frame with the current driver");
9207 return 0;
9208 }
9209}
9210
9211
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009212static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9213 struct sigma_cmd *cmd)
9214{
9215 switch (get_driver_type()) {
9216 case DRIVER_ATHEROS:
9217 return ath_ap_send_frame_loc(dut, conn, cmd);
9218 case DRIVER_OPENWRT:
9219 switch (get_openwrt_driver_type()) {
9220 case OPENWRT_DRIVER_ATHEROS:
9221 return ath_ap_send_frame_loc(dut, conn, cmd);
9222 default:
9223 send_resp(dut, conn, SIGMA_ERROR,
9224 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
9225 return 0;
9226 }
9227 default:
9228 send_resp(dut, conn, SIGMA_ERROR,
9229 "errorCode,Unsupported ap_send_frame_loc with the current driver");
9230 return 0;
9231 }
9232}
9233
9234
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009235static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9236 struct sigma_cmd *cmd)
9237{
9238 switch (get_driver_type()) {
9239 case DRIVER_ATHEROS:
9240 return ath_ap_send_frame_mbo(dut, conn, cmd);
9241 case DRIVER_OPENWRT:
9242 switch (get_openwrt_driver_type()) {
9243 case OPENWRT_DRIVER_ATHEROS:
9244 return ath_ap_send_frame_mbo(dut, conn, cmd);
9245 default:
9246 send_resp(dut, conn, SIGMA_ERROR,
9247 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9248 return 0;
9249 }
9250 default:
9251 send_resp(dut, conn, SIGMA_ERROR,
9252 "errorCode,Unsupported ap_send_frame with the current driver");
9253 return 0;
9254 }
9255}
9256
9257
Lior David0fe101e2017-03-09 16:09:50 +02009258static int ap_send_frame_60g(struct sigma_dut *dut,
9259 struct sigma_conn *conn,
9260 struct sigma_cmd *cmd)
9261{
9262 switch (get_driver_type()) {
9263#ifdef __linux__
9264 case DRIVER_WIL6210:
9265 return wil6210_send_frame_60g(dut, conn, cmd);
9266#endif /* __linux__ */
9267 default:
9268 send_resp(dut, conn, SIGMA_ERROR,
9269 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9270 return 0;
9271 }
9272}
9273
9274
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009275int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9276 struct sigma_cmd *cmd)
9277{
9278 /* const char *name = get_param(cmd, "NAME"); */
9279 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9280 const char *val;
9281 enum send_frame_type frame;
9282 enum send_frame_protection protected;
9283 char buf[100];
9284
9285 val = get_param(cmd, "Program");
9286 if (val) {
9287 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07009288 strcasecmp(val, "HS2-R2") == 0 ||
9289 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009290 return ap_send_frame_hs2(dut, conn, cmd);
9291 if (strcasecmp(val, "VHT") == 0)
9292 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009293 if (strcasecmp(val, "LOC") == 0)
9294 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009295 if (strcasecmp(val, "MBO") == 0)
9296 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009297 if (strcasecmp(val, "60GHz") == 0)
9298 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009299 }
9300
9301 val = get_param(cmd, "PMFFrameType");
9302 if (val == NULL)
9303 val = get_param(cmd, "FrameName");
9304 if (val == NULL)
9305 val = get_param(cmd, "Type");
9306 if (val == NULL)
9307 return -1;
9308 if (strcasecmp(val, "disassoc") == 0)
9309 frame = DISASSOC;
9310 else if (strcasecmp(val, "deauth") == 0)
9311 frame = DEAUTH;
9312 else if (strcasecmp(val, "saquery") == 0)
9313 frame = SAQUERY;
9314 else {
9315 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9316 "PMFFrameType");
9317 return 0;
9318 }
9319
9320 val = get_param(cmd, "PMFProtected");
9321 if (val == NULL)
9322 val = get_param(cmd, "Protected");
9323 if (val == NULL)
9324 return -1;
9325 if (strcasecmp(val, "Correct-key") == 0 ||
9326 strcasecmp(val, "CorrectKey") == 0)
9327 protected = CORRECT_KEY;
9328 else if (strcasecmp(val, "IncorrectKey") == 0)
9329 protected = INCORRECT_KEY;
9330 else if (strcasecmp(val, "Unprotected") == 0)
9331 protected = UNPROTECTED;
9332 else {
9333 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9334 "PMFProtected");
9335 return 0;
9336 }
9337
9338 val = get_param(cmd, "stationID");
9339 if (val == NULL)
9340 return -1;
9341
9342 if (protected == INCORRECT_KEY ||
9343 (protected == UNPROTECTED && frame == SAQUERY))
9344 return ap_inject_frame(dut, conn, frame, protected, val);
9345
9346 switch (frame) {
9347 case DISASSOC:
9348 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
9349 val, protected == CORRECT_KEY);
9350 break;
9351 case DEAUTH:
9352 snprintf(buf, sizeof(buf), "deauth %s test=%d",
9353 val, protected == CORRECT_KEY);
9354 break;
9355 case SAQUERY:
9356 snprintf(buf, sizeof(buf), "sa_query %s", val);
9357 break;
9358 }
9359
9360 if (run_hostapd_cli(dut, buf) != 0)
9361 return -2;
9362
9363 return 1;
9364}
9365
9366
9367static int cmd_ap_get_mac_address(struct sigma_dut *dut,
9368 struct sigma_conn *conn,
9369 struct sigma_cmd *cmd)
9370{
9371#if defined( __linux__)
9372 /* const char *name = get_param(cmd, "NAME"); */
9373 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03009374 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009375 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009376 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009377 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009378 int s, wlan_tag = 1;
9379 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009380
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009381 val = get_param(cmd, "WLAN_TAG");
9382 if (val) {
9383 wlan_tag = atoi(val);
9384 if (wlan_tag < 1 || wlan_tag > 3) {
9385 /*
9386 * The only valid WLAN Tags as of now as per the latest
9387 * WFA scripts are 1, 2, and 3.
9388 */
Jouni Malinenf8984642017-10-12 00:02:37 +03009389 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009390 "errorCode,Unsupported WLAN_TAG");
9391 return 0;
9392 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009393 }
9394
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009395 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
9396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009397 s = socket(AF_INET, SOCK_DGRAM, 0);
9398 if (s < 0)
9399 return -1;
9400 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009401 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009402 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9403 perror("ioctl");
9404 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03009405 snprintf(resp, sizeof(resp),
9406 "errorCode,Could not find interface %s", ifname);
9407 send_resp(dut, conn, SIGMA_ERROR, resp);
9408 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009409 }
9410 close(s);
9411 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
9412
9413 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9414 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9415 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9416 return 0;
9417#elif defined( __QNXNTO__)
9418 char resp[50];
9419 unsigned char addr[6];
9420
9421 if (!sigma_main_ifname) {
9422 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
9423 return 0;
9424 }
9425
9426 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
9427 send_resp(dut, conn, SIGMA_ERROR,
9428 "errorCode,Failed to get address");
9429 return 0;
9430 }
9431 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9432 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9433 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9434 return 0;
9435#else /* __linux__ */
9436 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
9437 "yet supported");
9438 return 0;
9439#endif /* __linux__ */
9440}
9441
9442
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309443int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
9444 struct sigma_cmd *cmd)
9445{
9446 return cmd_ap_get_mac_address(dut, conn, cmd);
9447}
9448
9449
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009450static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
9451 struct sigma_cmd *cmd)
9452{
9453 /*
9454 * Ignore the command since the parameters are already handled through
9455 * ap_set_security.
9456 */
9457
9458 return 1;
9459}
9460
9461
9462static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
9463 struct sigma_cmd *cmd)
9464{
9465 /* const char *name = get_param(cmd, "NAME"); */
9466 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9467 const char *val, *dest;
9468 char *pos, buf[100];
9469 int i, wlan_tag = 1;
9470
9471 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
9472 "following parameters");
9473 for (i = 0; i < cmd->count; i++) {
9474 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
9475 (cmd->values[i] ? cmd->values[i] : "NULL"));
9476 }
9477
9478 val = get_param(cmd, "ICMPv4_ECHO");
9479 if (val && atoi(val)) {
9480 snprintf(buf, sizeof(buf), "ebtables -F");
9481 if (system(buf) != 0) {
9482 sigma_dut_print(dut, DUT_MSG_ERROR,
9483 "Failed to set ebtables rules, RULE-12");
9484 }
9485 return 1;
9486 }
9487
9488 val = get_param(cmd, "WLAN_TAG");
9489 if (val) {
9490 wlan_tag = atoi(val);
9491 if (wlan_tag != 1 && wlan_tag != 2) {
9492 send_resp(dut, conn, SIGMA_INVALID,
9493 "errorCode,Invalid WLAN_TAG");
9494 return 0;
9495 }
9496 }
9497
9498 if (wlan_tag == 2) {
9499 val = get_param(cmd, "PROXY_ARP");
9500 if (val)
9501 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02009502
9503 val = get_param(cmd, "OSU");
9504 if (val)
9505 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009506 return 1;
9507 }
9508
9509 dest = get_param(cmd, "STA_MAC");
9510 if (dest) {
9511 /* This is a special/ugly way of using this command.
9512 * If "Dest" MAC is included, assume that this command
9513 * is being issued after ap_config_commit for dynamically
9514 * setting the QoS Map Set.
9515 */
9516 val = get_param(cmd, "QoS_MAP_SET");
9517 if (val) {
9518 dut->ap_qos_map_set = atoi(val);
9519 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9520 dut->ap_qos_map_set);
9521 }
9522
9523 if (dut->ap_qos_map_set == 1)
9524 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9525 else if (dut->ap_qos_map_set == 2)
9526 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9527
9528 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9529 if (run_hostapd_cli(dut, buf) != 0)
9530 return -1;
9531 }
9532
9533 val = get_param(cmd, "DGAF_DISABLE");
9534 if (val)
9535 dut->ap_dgaf_disable = atoi(val);
9536
9537 dut->ap_interworking = 1;
9538
9539 val = get_param(cmd, "INTERWORKING");
9540 if (val == NULL)
9541 val = get_param(cmd, "INTERNETWORKING");
9542 if (val != NULL && atoi(val) == 0) {
9543 dut->ap_interworking = 0;
9544 dut->ap_hs2 = 0;
9545 return 1;
9546 }
9547
9548 val = get_param(cmd, "ACCS_NET_TYPE");
9549 if (val) {
9550 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
9551 strcasecmp(val, "Chargable_Public_Network") == 0 ||
9552 strcasecmp(val, "Chargable Public Network") == 0)
9553 dut->ap_access_net_type = 2;
9554 else
9555 dut->ap_access_net_type = atoi(val);
9556 }
9557
9558 val = get_param(cmd, "INTERNET");
9559 if (val)
9560 dut->ap_internet = atoi(val);
9561
9562 val = get_param(cmd, "VENUE_GRP");
9563 if (val) {
9564 if (strcasecmp(val, "Business") == 0)
9565 dut->ap_venue_group = 2;
9566 else
9567 dut->ap_venue_group = atoi(val);
9568 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9569 dut->ap_venue_name);
9570 }
9571
9572 val = get_param(cmd, "VENUE_TYPE");
9573 if (val) {
9574 if (strcasecmp(val, "R&D") == 0)
9575 dut->ap_venue_type = 8;
9576 else
9577 dut->ap_venue_type = atoi(val);
9578 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
9579 dut->ap_venue_type);
9580 }
9581
9582 val = get_param(cmd, "HESSID");
9583 if (val) {
9584 if (strlen(val) >= sizeof(dut->ap_hessid)) {
9585 send_resp(dut, conn, SIGMA_ERROR,
9586 "errorCode,Invalid HESSID");
9587 return 0;
9588 }
9589 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
9590 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
9591 dut->ap_hessid);
9592 }
9593
9594 val = get_param(cmd, "ROAMING_CONS");
9595 if (val) {
9596 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
9597 send_resp(dut, conn, SIGMA_ERROR,
9598 "errorCode,Invalid ROAMING_CONS");
9599 return 0;
9600 }
9601 if (strcasecmp(val, "Disabled") == 0) {
9602 dut->ap_roaming_cons[0] = '\0';
9603 } else {
9604 snprintf(dut->ap_roaming_cons,
9605 sizeof(dut->ap_roaming_cons), "%s", val);
9606 }
9607 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
9608 dut->ap_roaming_cons);
9609 }
9610
9611 val = get_param(cmd, "ANQP");
9612 if (val)
9613 dut->ap_anqpserver_on = atoi(val);
9614
9615 val = get_param(cmd, "NAI_REALM_LIST");
9616 if (val) {
9617 dut->ap_nai_realm_list = atoi(val);
9618 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
9619 dut->ap_nai_realm_list);
9620 }
9621
9622 val = get_param(cmd, "3GPP_INFO");
9623 if (val) {
9624 /* What kind of encoding format is used?! */
9625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
9626 "not yet supported (contents not fully defined)");
9627 return 0;
9628 }
9629
9630 val = get_param(cmd, "DOMAIN_LIST");
9631 if (val) {
9632 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
9633 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
9634 "DOMAIN_LIST");
9635 return 0;
9636 }
9637 snprintf(dut->ap_domain_name_list,
9638 sizeof(dut->ap_domain_name_list), "%s", val);
9639 pos = dut->ap_domain_name_list;
9640 while (*pos) {
9641 if (*pos == ';')
9642 *pos = ',';
9643 pos++;
9644 }
9645 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
9646 dut->ap_domain_name_list);
9647 }
9648
9649 val = get_param(cmd, "OPER_NAME");
9650 if (val) {
9651 dut->ap_oper_name = atoi(val);
9652 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
9653 dut->ap_oper_name);
9654 }
9655
9656 val = get_param(cmd, "VENUE_NAME");
9657 if (val) {
9658 dut->ap_venue_name = atoi(val);
9659 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9660 dut->ap_venue_name);
9661 }
9662
9663 val = get_param(cmd, "GAS_CB_DELAY");
9664 if (val) {
9665 dut->ap_gas_cb_delay = atoi(val);
9666 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
9667 dut->ap_gas_cb_delay);
9668 }
9669
9670 val = get_param(cmd, "MIH");
9671 if (val && atoi(val) > 0) {
9672 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
9673 "supported");
9674 return 0;
9675 }
9676
9677 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
9678 if (val) {
9679 dut->ap_l2tif = atoi(val);
9680 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
9681 dut->ap_l2tif);
9682 }
9683
9684 val = get_param(cmd, "BCST_UNCST");
9685 if (val) {
9686 send_resp(dut, conn, SIGMA_ERROR,
9687 "errorCode,BCST_UNCST not yet supported");
9688 return 0;
9689 }
9690
9691 val = get_param(cmd, "PLMN_MCC");
9692 if (val) {
9693 char mcc[100], *start, *end;
9694 int i = 0;
9695 if (strlen(val) >= sizeof(mcc)) {
9696 send_resp(dut, conn, SIGMA_ERROR,
9697 "errorCode,PLMN_MCC too long");
9698 return 0;
9699 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009700 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009701 start = mcc;
9702 while ((end = strchr(start, ';'))) {
9703 /* process all except the last */
9704 *end = '\0';
9705 if (strlen(start) != 3) {
9706 send_resp(dut, conn, SIGMA_ERROR,
9707 "errorCode,Invalid PLMN_MCC");
9708 return 0;
9709 }
9710 snprintf(dut->ap_plmn_mcc[i],
9711 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9712 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9713 dut->ap_plmn_mcc[i]);
9714 i++;
9715 start = end + 1;
9716 *end = ';';
9717 }
9718 if (strlen(start) != 3) {
9719 send_resp(dut, conn, SIGMA_ERROR,
9720 "errorCode,Invalid PLMN_MCC");
9721 return 0;
9722 }
9723 /* process last or only one */
9724 snprintf(dut->ap_plmn_mcc[i],
9725 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9726 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9727 dut->ap_plmn_mcc[i]);
9728 }
9729
9730 val = get_param(cmd, "PLMN_MNC");
9731 if (val) {
9732 char mnc[100], *start, *end;
9733 int i = 0;
9734 if (strlen(val) >= sizeof(mnc)) {
9735 send_resp(dut, conn, SIGMA_ERROR,
9736 "errorCode,PLMN_MNC too long");
9737 return 0;
9738 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009739 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009740 start = mnc;
9741 while ((end = strchr(start, ';'))) {
9742 *end = '\0';
9743 if (strlen(start) != 2 && strlen(start) != 3) {
9744 send_resp(dut, conn, SIGMA_ERROR,
9745 "errorCode,Invalid PLMN_MNC");
9746 return 0;
9747 }
9748 snprintf(dut->ap_plmn_mnc[i],
9749 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9750 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9751 dut->ap_plmn_mnc[i]);
9752 i++;
9753 start = end + 1;
9754 *end = ';';
9755 }
9756 if (strlen(start) != 2 && strlen(start) != 3) {
9757 send_resp(dut, conn, SIGMA_ERROR,
9758 "errorCode,Invalid PLMN_MNC");
9759 return 0;
9760 }
9761 snprintf(dut->ap_plmn_mnc[i],
9762 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9763 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9764 dut->ap_plmn_mnc[i]);
9765 }
9766
9767 val = get_param(cmd, "PROXY_ARP");
9768 if (val) {
9769 dut->ap_proxy_arp = atoi(val);
9770 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
9771 dut->ap_proxy_arp);
9772 }
9773
9774 val = get_param(cmd, "WAN_METRICS");
9775 if (val) {
9776 dut->ap_wan_metrics = atoi(val);
9777 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
9778 dut->ap_wan_metrics);
9779 }
9780
9781 val = get_param(cmd, "CONN_CAP");
9782 if (val) {
9783 dut->ap_conn_capab = atoi(val);
9784 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
9785 dut->ap_conn_capab);
9786 }
9787
9788 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
9789 if (val) {
9790 dut->ap_ip_addr_type_avail = atoi(val);
9791 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
9792 dut->ap_ip_addr_type_avail);
9793 }
9794
9795 val = get_param(cmd, "NET_AUTH_TYPE");
9796 if (val) {
9797 dut->ap_net_auth_type = atoi(val);
9798 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
9799 dut->ap_net_auth_type);
9800 }
9801
9802 val = get_param(cmd, "OP_CLASS");
9803 if (val == NULL)
9804 val = get_param(cmd, "OPER_CLASS");
9805 if (val) {
9806 dut->ap_oper_class = atoi(val);
9807 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
9808 dut->ap_oper_class);
9809 }
9810
9811 val = get_param(cmd, "OSU_PROVIDER_LIST");
9812 if (val) {
9813 dut->ap_osu_provider_list = atoi(val);
9814 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
9815 dut->ap_osu_provider_list);
9816 }
9817
Jouni Malinen93a837f2018-11-01 17:09:22 +02009818 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
9819 if (val) {
9820 dut->ap_osu_provider_nai_list = atoi(val);
9821 sigma_dut_print(dut, DUT_MSG_INFO,
9822 "ap_osu_provider_nai_list %d",
9823 dut->ap_osu_provider_nai_list);
9824 }
9825
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009826 val = get_param(cmd, "OSU_SERVER_URI");
9827 if (val) {
9828 i = 0;
9829 do {
9830 int len;
9831 const char *uri = val;
9832 val = strchr(val, ' ');
9833 len = val ? (val++ - uri) : (int) strlen(uri);
9834 if (len > 0 && len < 256) {
9835 memcpy(dut->ap_osu_server_uri[i], uri, len);
9836 dut->ap_osu_server_uri[i][len] = '\0';
9837 sigma_dut_print(dut, DUT_MSG_INFO,
9838 "ap_osu_server_uri[%d] %s", i,
9839 dut->ap_osu_server_uri[i]);
9840 }
9841 } while (val && ++i < 10);
9842 }
9843
9844 val = get_param(cmd, "OSU_METHOD");
9845 if (val) {
9846 i = 0;
9847 do {
9848 int len;
9849 const char *method = val;
9850 val = strchr(val, ' ');
9851 len = val ? (val++ - method) : (int) strlen(method);
9852 if (len > 0) {
9853 if (strncasecmp(method, "SOAP", len) == 0)
9854 dut->ap_osu_method[i] = 1;
9855 else if (strncasecmp(method, "OMADM", len) == 0)
9856 dut->ap_osu_method[i] = 0;
9857 else
9858 return -2;
9859 }
9860 } while (val && ++i < 10);
9861 }
9862
9863 val = get_param(cmd, "OSU_SSID");
9864 if (val) {
9865 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -07009866 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009867 sizeof(dut->ap_osu_ssid));
9868 sigma_dut_print(dut, DUT_MSG_INFO,
9869 "ap_osu_ssid %s",
9870 dut->ap_osu_ssid);
9871 }
9872 }
9873
9874 val = get_param(cmd, "OSU_ICON_TAG");
9875 if (val)
9876 dut->ap_osu_icon_tag = atoi(val);
9877
9878 val = get_param(cmd, "QoS_MAP_SET");
9879 if (val) {
9880 dut->ap_qos_map_set = atoi(val);
9881 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9882 dut->ap_qos_map_set);
9883 }
9884
9885 val = get_param(cmd, "BSS_LOAD");
9886 if (val) {
9887 dut->ap_bss_load = atoi(val);
9888 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
9889 dut->ap_bss_load);
9890 }
9891
Jouni Malinen54a89b02018-05-01 00:16:26 +03009892 val = get_param(cmd, "Venue_URL");
9893 if (val)
9894 dut->ap_venue_url = atoi(val);
9895
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03009896 val = get_param(cmd, "Advice_of_Charge");
9897 if (val)
9898 dut->ap_advice_of_charge = atoi(val);
9899
Jouni Malinenac104532018-05-01 00:27:37 +03009900 val = get_param(cmd, "Operator_Icon_Metadata");
9901 if (val)
9902 dut->ap_oper_icon_metadata = atoi(val);
9903
Jouni Malinenac367142018-05-01 00:32:24 +03009904 val = get_param(cmd, "TnC_File_Name");
9905 if (val)
9906 dut->ap_tnc_file_name = atoi(val);
9907
9908 val = get_param(cmd, "TnC_File_Time_Stamp");
9909 if (val)
9910 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
9911
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009912 return 1;
9913}
9914
9915
9916void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
9917{
9918 char buf[100];
9919
9920 if (!file_exists("nfc-status"))
9921 return;
9922
9923 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
9924 run_system(dut, buf);
9925}
9926
9927
9928static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
9929 const char *info)
9930{
9931 int res;
9932
9933 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
9934 printf("%s\n\n", info);
9935
9936 nfc_status(dut, "START", info);
9937 res = run_system(dut, cmd);
9938 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
9939 if (res) {
9940 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
9941 cmd, res);
9942 return res;
9943 }
9944
9945 return 0;
9946}
9947
9948
9949static int ap_nfc_write_config_token(struct sigma_dut *dut,
9950 struct sigma_conn *conn,
9951 struct sigma_cmd *cmd)
9952{
9953 int res;
9954 char buf[300];
9955
9956 run_system(dut, "killall wps-ap-nfc.py");
9957 unlink("nfc-success");
9958 snprintf(buf, sizeof(buf),
9959 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
9960 dut->summary_log ? "--summary " : "",
9961 dut->summary_log ? dut->summary_log : "");
9962 res = run_nfc_command(dut, buf,
9963 "Touch NFC Tag to write WPS configuration token");
9964 if (res || !file_exists("nfc-success")) {
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "ErrorCode,Failed to write tag");
9967 return 0;
9968 }
9969
9970 return 1;
9971}
9972
9973
9974static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
9975 struct sigma_conn *conn,
9976 struct sigma_cmd *cmd)
9977{
9978 int res;
9979 char buf[300];
9980
9981 run_system(dut, "killall wps-ap-nfc.py");
9982
9983 unlink("nfc-success");
9984 snprintf(buf, sizeof(buf),
9985 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9986 dut->summary_log ? "--summary " : "",
9987 dut->summary_log ? dut->summary_log : "");
9988 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
9989 if (res || !file_exists("nfc-success")) {
9990 send_resp(dut, conn, SIGMA_ERROR,
9991 "ErrorCode,Failed to read tag");
9992 return 0;
9993 }
9994
9995 return 1;
9996}
9997
9998
9999static int ap_nfc_write_password_token(struct sigma_dut *dut,
10000 struct sigma_conn *conn,
10001 struct sigma_cmd *cmd)
10002{
10003 int res;
10004 char buf[300];
10005
10006 run_system(dut, "killall wps-ap-nfc.py");
10007 unlink("nfc-success");
10008 snprintf(buf, sizeof(buf),
10009 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
10010 dut->summary_log ? "--summary " : "",
10011 dut->summary_log ? dut->summary_log : "");
10012 res = run_nfc_command(dut, buf,
10013 "Touch NFC Tag to write WPS password token");
10014 if (res || !file_exists("nfc-success")) {
10015 send_resp(dut, conn, SIGMA_ERROR,
10016 "ErrorCode,Failed to write tag");
10017 return 0;
10018 }
10019
10020 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
10021 send_resp(dut, conn, SIGMA_ERROR,
10022 "ErrorCode,Failed to enable NFC password token");
10023 return 0;
10024 }
10025
10026 return 1;
10027}
10028
10029
10030static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
10031 struct sigma_conn *conn,
10032 struct sigma_cmd *cmd)
10033{
10034 int res;
10035 char buf[300];
10036
10037 run_system(dut, "killall wps-ap-nfc.py");
10038 unlink("nfc-success");
10039 snprintf(buf, sizeof(buf),
10040 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10041 dut->summary_log ? "--summary " : "",
10042 dut->summary_log ? dut->summary_log : "");
10043 res = run_nfc_command(dut, buf,
10044 "Touch NFC Device to respond to WPS connection handover");
10045 if (res) {
10046 send_resp(dut, conn, SIGMA_ERROR,
10047 "ErrorCode,Failed to enable NFC for connection "
10048 "handover");
10049 return 0;
10050 }
10051 if (!file_exists("nfc-success")) {
10052 send_resp(dut, conn, SIGMA_ERROR,
10053 "ErrorCode,Failed to complete NFC connection handover");
10054 return 0;
10055 }
10056
10057 return 1;
10058}
10059
10060
10061static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
10062 struct sigma_cmd *cmd)
10063{
10064 /* const char *name = get_param(cmd, "Name"); */
10065 /* const char *intf = get_param(cmd, "Interface"); */
10066 const char *oper = get_param(cmd, "Operation");
10067
10068 if (oper == NULL)
10069 return -1;
10070
10071 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
10072 return ap_nfc_write_config_token(dut, conn, cmd);
10073 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
10074 return ap_nfc_write_password_token(dut, conn, cmd);
10075 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
10076 return ap_nfc_wps_read_passwd(dut, conn, cmd);
10077 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
10078 return ap_nfc_wps_connection_handover(dut, conn, cmd);
10079
10080 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
10081 return 0;
10082}
10083
10084
10085static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
10086 struct sigma_cmd *cmd)
10087{
10088 char *pin = "12345670"; /* TODO: use random PIN */
10089 char resp[100];
10090
10091 snprintf(resp, sizeof(resp), "PIN,%s", pin);
10092 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10093
10094 return 0;
10095}
10096
10097
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010098static int cmd_ap_wps_enter_pin(struct sigma_dut *dut, struct sigma_conn *conn,
10099 struct sigma_cmd *cmd)
10100{
10101 const char *pin = get_param(cmd, "PIN");
10102 char wps_pin[11];
10103
10104 if (!pin)
10105 return -1;
10106
10107 sigma_dut_print(dut, DUT_MSG_DEBUG,
10108 "Authorize a client to join with WPS PIN %s", pin);
10109
10110 strlcpy(wps_pin, pin, sizeof(wps_pin));
10111 /* we need to tolerate extra '-' characters entered */
10112 str_remove_chars(wps_pin, '-');
10113 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
10114 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
10115
10116 return 1;
10117}
10118
10119
10120static int cmd_ap_wps_set_pbc(struct sigma_dut *dut, struct sigma_conn *conn,
10121 struct sigma_cmd *cmd)
10122{
10123 sigma_dut_print(dut, DUT_MSG_DEBUG,
10124 "Selecting the push button configuration method");
10125
10126 dut->wps_method = WFA_CS_WPS_PBC;
10127
10128 return 1;
10129}
10130
10131
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020010132int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
10133 struct sigma_cmd *cmd)
10134{
10135 char buf[100], resp[256];
10136 const char *intf = get_param(cmd, "interface");
10137 const char *config_method = get_param(cmd, "WPSConfigMethod");
10138
10139 if (config_method && strcasecmp(config_method, "PBC") == 0)
10140 dut->wps_method = WFA_CS_WPS_PBC;
10141
10142 if (!intf)
10143 intf = get_main_ifname();
10144
10145 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
10146 send_resp(dut, conn, SIGMA_ERROR,
10147 "ErrorCode,WPS parameters not yet set");
10148 return STATUS_SENT;
10149 }
10150
10151 if (dut->wps_method == WFA_CS_WPS_PBC)
10152 snprintf(buf, sizeof(buf), "WPS_PBC");
10153 else /* WFA_CS_WPS_PIN_KEYPAD */
10154 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
10155
10156 /* Run WPS command */
10157 if (hapd_command(intf, buf) < 0) {
10158 /* command fails immediately if overlapped session detected */
10159 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
10160 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10161 return STATUS_SENT;
10162 }
10163
10164 /* In AP mode return immediately and do not wait for WPS registration */
10165 return SUCCESS_SEND_STATUS;
10166}
10167
10168
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010169static int cmd_ap_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10170 struct sigma_cmd *cmd)
10171{
10172 char value[256], resp[512];
10173 const char *param = get_param(cmd, "parameter");
10174 const char *ifname = get_param(cmd, "Interface");
10175
10176 if (!ifname)
10177 ifname = get_main_ifname();
10178
10179 if (!param) {
10180 send_resp(dut, conn, SIGMA_ERROR,
10181 "ErrorCode,Parameter not specified");
10182 return 0;
10183 }
10184
10185 if (strcasecmp(param, "SSID") == 0) {
10186 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
10187 sigma_dut_print(dut, DUT_MSG_ERROR,
10188 "Failed to get SSID");
10189 return -2;
10190 }
10191 snprintf(resp, sizeof(resp), "SSID,%s", value);
10192 } else if (strcasecmp(param, "PSK") == 0) {
10193 if (get_hapd_config(ifname, "passphrase", value,
10194 sizeof(value))) {
10195 sigma_dut_print(dut, DUT_MSG_ERROR,
10196 "Failed to get PSK");
10197 return -2;
10198 }
10199 snprintf(resp, sizeof(resp), "PSK,%s", value);
10200 } else {
10201 send_resp(dut, conn, SIGMA_ERROR,
10202 "ErrorCode,Unsupported parameter");
10203 return 0;
10204 }
10205
10206 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10207 return 0;
10208}
10209
10210
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010211static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
10212 const char *val)
10213{
10214 char *token, *result;
10215 int nss = 0, chwidth = 0;
10216 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010217 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010218
10219 /*
10220 * The following commands should be invoked to generate
10221 * VHT op mode notification
10222 */
10223
10224 /* Extract the NSS info */
10225 token = strdup(val);
10226 if (!token)
10227 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010228 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010229 if (result) {
10230 int count = atoi(result);
10231
10232 /* We do not support NSS > 3 */
10233 if (count < 0 || count > 3) {
10234 free(token);
10235 return -1;
10236 }
10237
10238 /* Convert nss to chainmask */
10239 while (count--)
10240 nss = (nss << 1) | 1;
10241
10242 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
10243 ifname, nss);
10244 if (system(buf) != 0) {
10245 sigma_dut_print(dut, DUT_MSG_ERROR,
10246 "iwpriv wifi1 rxchainmask failed!");
10247 }
10248 }
10249
10250 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010251 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010252 if (result) {
10253 switch (atoi(result)) {
10254 case 20:
10255 chwidth = 0;
10256 break;
10257 case 40:
10258 chwidth = 1;
10259 break;
10260 case 80:
10261 chwidth = 2;
10262 break;
10263 case 160:
10264 chwidth = 3;
10265 break;
10266 default:
10267 chwidth = 2;
10268 break;
10269 }
10270 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
10271 ifname, chwidth);
10272 if (system(buf) != 0) {
10273 sigma_dut_print(dut, DUT_MSG_ERROR,
10274 "iwpriv chwidth failed!");
10275 }
10276 }
10277
10278 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +030010279 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010280 if (system(buf) != 0) {
10281 sigma_dut_print(dut, DUT_MSG_ERROR,
10282 "iwpriv opmode_notify failed!");
10283 }
10284 free(token);
10285
10286 return 0;
10287}
10288
10289
10290static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
10291 const char *val)
10292{
10293 /* String (nss_operating_mode; mcs_operating_mode) */
10294 int nss, mcs;
10295 char *token, *result;
10296 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010297 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010298
10299 token = strdup(val);
10300 if (!token)
10301 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010302 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010303 if (!result) {
10304 sigma_dut_print(dut, DUT_MSG_ERROR,
10305 "VHT NSS not specified");
10306 goto end;
10307 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010308 if (strcasecmp(result, "def") != 0) {
10309 nss = atoi(result);
10310
10311 if (nss == 4)
10312 ath_disable_txbf(dut, ifname);
10313
10314 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
10315 if (system(buf) != 0) {
10316 sigma_dut_print(dut, DUT_MSG_ERROR,
10317 "iwpriv nss failed");
10318 }
10319 } else {
10320 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
10321 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
10322 if (system(buf) != 0) {
10323 sigma_dut_print(dut, DUT_MSG_ERROR,
10324 "iwpriv nss failed");
10325 }
10326 }
10327 }
10328
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010329 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010330 if (!result) {
10331 sigma_dut_print(dut, DUT_MSG_ERROR,
10332 "VHT MCS not specified");
10333 goto end;
10334 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010335 if (strcasecmp(result, "def") == 0) {
10336 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
10337 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
10338 ifname);
10339 if (system(buf) != 0) {
10340 sigma_dut_print(dut, DUT_MSG_ERROR,
10341 "iwpriv vhtmcs failed");
10342 }
10343 } else {
10344 snprintf(buf, sizeof(buf),
10345 "iwpriv %s set11NRates 0", ifname);
10346 if (system(buf) != 0) {
10347 sigma_dut_print(dut, DUT_MSG_ERROR,
10348 "iwpriv set11NRates failed");
10349 }
10350 }
10351 } else {
10352 mcs = atoi(result);
10353 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
10354 if (system(buf) != 0) {
10355 sigma_dut_print(dut, DUT_MSG_ERROR,
10356 "iwpriv vhtmcs failed");
10357 }
10358 }
10359
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010360end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010361 free(token);
10362 return 0;
10363}
10364
10365
10366static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10367 const char *val)
10368{
10369 char *token, *result;
10370 int channel = 36;
10371 int chwidth = 80;
10372 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010373 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010374
10375 /* Extract the channel info */
10376 token = strdup(val);
10377 if (!token)
10378 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010379 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010380 if (result)
10381 channel = atoi(result);
10382
10383 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010384 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010385 if (result)
10386 chwidth = atoi(result);
10387
10388 /* Issue the channel switch command */
10389 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
10390 ifname, channel, chwidth);
10391 if (system(buf) != 0) {
10392 sigma_dut_print(dut, DUT_MSG_ERROR,
10393 "iwpriv doth_ch_chwidth failed!");
10394 }
10395
10396 free(token);
10397 return 0;
10398}
10399
10400
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010401static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
10402 const char *val)
10403{
10404 char buf[80];
10405 unsigned char mac_addr[6];
10406
10407 if (parse_mac_address(dut, val, mac_addr) < 0)
10408 return -1;
10409
10410 snprintf(buf, sizeof(buf),
10411 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
10412 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
10413 run_system(dut, buf);
10414
10415 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
10416 ifname, mac_addr[4], mac_addr[5]);
10417 run_system(dut, buf);
10418
10419 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
10420 run_system(dut, buf);
10421
10422 return 0;
10423}
10424
10425
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080010426void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010427{
10428 char buf[60];
10429
10430 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
10431 if (system(buf) != 0) {
10432 sigma_dut_print(dut, DUT_MSG_ERROR,
10433 "disabling novap reset failed");
10434 }
10435}
10436
10437
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010438struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
10439 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010440{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010441 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010442
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010443 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
10444 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
10445 ETH_ALEN) == 0)
10446 return &dut->mbo_pref_aps[i];
10447 }
10448 return NULL;
10449}
10450
10451
10452static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
10453 int ap_ne_class, int ap_ne_op_ch,
10454 int ap_ne_pref)
10455{
10456 struct mbo_pref_ap *entry;
10457 uint8_t self_mac[ETH_ALEN];
10458 char ifname[50];
10459
10460 get_if_name(dut, ifname, sizeof(ifname), 1);
10461 get_hwaddr(ifname, self_mac);
10462
10463 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
10464 entry = &dut->mbo_self_ap_tuple;
10465 else
10466 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
10467
10468 if (!entry) {
10469 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
10470 sigma_dut_print(dut, DUT_MSG_ERROR,
10471 "Nebor AP List is full. Not adding");
10472 return;
10473 }
10474 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
10475 dut->mbo_pref_ap_cnt++;
10476 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
10477 entry->ap_ne_class = -1;
10478 entry->ap_ne_op_ch = -1;
10479 entry->ap_ne_pref = -1;
10480 }
10481 if (ap_ne_class != -1)
10482 entry->ap_ne_class = ap_ne_class;
10483 if (ap_ne_op_ch != -1)
10484 entry->ap_ne_op_ch = ap_ne_op_ch;
10485 if (ap_ne_pref != -1)
10486 entry->ap_ne_pref = ap_ne_pref;
10487}
10488
10489
10490static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
10491 struct sigma_cmd *cmd)
10492{
10493 unsigned char mac_addr[ETH_ALEN];
10494 const char *val;
10495 /*
10496 * -1 is invalid value for the following
10497 * to differentiate between unset and set values
10498 * -1 => implies not set by CAPI
10499 */
10500 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
10501 int list_offset = dut->mbo_pref_ap_cnt;
10502
10503 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
10504 sigma_dut_print(dut, DUT_MSG_ERROR,
10505 "AP Pref Entry list is full");
10506 return -1;
10507 }
10508
10509 val = get_param(cmd, "Nebor_Op_Class");
10510 if (val)
10511 ap_ne_class = atoi(val);
10512
10513 val = get_param(cmd, "Nebor_Op_Ch");
10514 if (val)
10515 ap_ne_op_ch = atoi(val);
10516
10517 val = get_param(cmd, "Nebor_Pref");
10518 if (val)
10519 ap_ne_pref = atoi(val);
10520
10521 val = get_param(cmd, "Nebor_BSSID");
10522 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010523 return -1;
10524
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010525 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
10526 ap_ne_pref);
10527 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010528 return 0;
10529}
10530
10531
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010532static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10533 struct sigma_cmd *cmd)
10534{
10535 const char *val;
10536 char *ifname;
10537
10538 ifname = get_main_ifname();
10539
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010540 /* Disable vap reset between the commands */
10541 novap_reset(dut, ifname);
10542
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010543 val = get_param(cmd, "Opt_md_notif_ie");
10544 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
10545 return -1;
10546
10547 /* TODO: Optional arguments */
10548
10549 val = get_param(cmd, "nss_mcs_opt");
10550 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
10551 return -1;
10552
10553 val = get_param(cmd, "chnum_band");
10554 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
10555 return -1;
10556
10557 val = get_param(cmd, "RTS_FORCE");
10558 if (val)
10559 ath_config_rts_force(dut, ifname, val);
10560
10561 val = get_param(cmd, "DYN_BW_SGNL");
10562 if (val)
10563 ath_config_dyn_bw_sig(dut, ifname, val);
10564
10565 val = get_param(cmd, "CTS_WIDTH");
10566 if (val)
10567 ath_set_cts_width(dut, ifname, val);
10568
10569 val = get_param(cmd, "Ndpa_stainfo_mac");
10570 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
10571 return -1;
10572
10573 val = get_param(cmd, "txBandwidth");
10574 if (val && ath_set_width(dut, conn, ifname, val) < 0)
10575 return -1;
10576
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010577 val = get_param(cmd, "Assoc_Disallow");
10578 if (val)
10579 ath_set_assoc_disallow(dut, ifname, val);
10580
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010581
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010582 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010583 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010584 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010585 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010586 dut->ap_disassoc_timer = 1000;
10587 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010588
10589 val = get_param(cmd, "BTMReq_Term_Bit");
10590 if (val)
10591 dut->ap_btmreq_term_bit = atoi(val);
10592
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010593 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010594 if (val) {
10595 dut->ap_assoc_delay = 1;
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010596 run_system_wrapper(dut, "iwpriv %s mbo_asoc_ret %s",
10597 ifname, val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010598 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010599
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010600 val = get_param(cmd, "Disassoc_Timer");
10601 if (val)
10602 dut->ap_disassoc_timer = atoi(val);
10603
10604 val = get_param(cmd, "BSS_Term_Duration");
10605 if (val)
10606 dut->ap_btmreq_bss_term_dur = atoi(val);
10607
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080010608 val = get_param(cmd, "BSS_Term_TSF");
10609 if (val)
10610 dut->ap_btmreq_bss_term_tsf = atoi(val);
10611
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010612 val = get_param(cmd, "TxPower");
10613 if (val)
10614 ath_set_txpower(dut, ifname, val);
10615
10616 val = get_param(cmd, "DownlinkAvailCap");
10617 if (val)
10618 dut->ap_dl_availcap = atoi(val);
10619
10620 val = get_param(cmd, "UplinkAvailCap");
10621 if (val) {
10622 dut->ap_ul_availcap = atoi(val);
10623 run_system_wrapper(dut, "iwpriv %s oce_wan_mtr %d %d", ifname,
10624 dut->ap_dl_availcap, dut->ap_ul_availcap);
10625 }
10626
10627 val = get_param(cmd, "RSSIthreshold");
10628 if (val) {
10629 int rssithreshold;
10630
10631 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
10632 rssithreshold = atoi(val);
10633 run_system_wrapper(dut, "iwpriv %s oce_asoc_rssi %d", ifname,
10634 rssithreshold);
10635 }
10636
10637 val = get_param(cmd, "RetryDelay");
10638 if (val) {
10639 int retrydelay;
10640
10641 run_system_wrapper(dut, "iwpriv %s oce_asoc_rej 1", ifname);
10642 retrydelay = atoi(val);
10643 run_system_wrapper(dut, "iwpriv %s oce_asoc_dly %d", ifname,
10644 retrydelay);
10645 }
10646
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010647 return 1;
10648}
10649
10650
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010651static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10652 const char *val)
10653{
10654 char *token, *result;
10655 int channel = 36;
10656 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010657 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010658
10659 /* Extract the channel info */
10660 token = strdup(val);
10661 if (!token)
10662 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010663 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010664 if (result)
10665 channel = atoi(result);
10666
10667 /* Issue the channel switch command */
10668 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
10669 ifname, channel);
10670 if (system(buf) != 0) {
10671 sigma_dut_print(dut, DUT_MSG_ERROR,
10672 "iwpriv setChanChange failed!");
10673 }
10674
10675 free(token);
10676 return 0;
10677}
10678
10679
10680static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10681 struct sigma_cmd *cmd)
10682{
10683 const char *val;
10684 char *ifname;
10685
10686 ifname = get_main_ifname();
10687
10688 val = get_param(cmd, "chnum_band");
10689 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
10690 return -1;
10691
10692 return 1;
10693}
10694
10695
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010696static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10697 const char *val)
10698{
10699 char *token, *result;
10700 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
10701 channel_freq;
10702 char buf[100];
10703 char *saveptr;
10704
10705 /* Extract the channel info */
10706 token = strdup(val);
10707 if (!token)
10708 return -1;
10709 result = strtok_r(token, ";", &saveptr);
10710 if (result)
10711 channel = atoi(result);
10712
10713 /* Extract the channel width info */
10714 result = strtok_r(NULL, ";", &saveptr);
10715 if (result)
10716 chwidth = atoi(result);
10717
10718 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
10719 if (center_freq_idx < 0) {
10720 free(token);
10721 return -1;
10722 }
10723
10724 center_freq = get_5g_channel_freq(center_freq_idx);
10725 channel_freq = get_5g_channel_freq(channel);
10726
10727 /* Issue the channel switch command */
10728 snprintf(buf, sizeof(buf),
10729 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
10730 ifname, channel_freq, center_freq, chwidth);
10731 if (run_hostapd_cli(dut,buf) != 0) {
10732 sigma_dut_print(dut, DUT_MSG_ERROR,
10733 "hostapd_cli chan_switch failed");
10734 }
10735
10736 free(token);
10737 return 0;
10738}
10739
10740
10741static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
10742 struct sigma_conn *conn,
10743 struct sigma_cmd *cmd)
10744{
10745 const char *val;
10746 char *ifname;
10747
10748 ifname = get_main_ifname();
10749 val = get_param(cmd, "chnum_band");
10750 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
10751 return -1;
10752
10753 return 1;
10754}
10755
10756
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010757#ifdef __linux__
10758static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
10759 struct sigma_conn *conn,
10760 struct sigma_cmd *cmd)
10761{
10762 const char *val;
10763
10764 val = get_param(cmd, "ExtSchIE");
10765 if (val && !strcasecmp(val, "Enable")) {
10766 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
10767 int count = MAX_ESE_ALLOCS;
10768
10769 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
10770 return -1;
10771 if (wil6210_set_ese(dut, count, allocs))
10772 return -1;
10773 return 1;
10774 }
10775
10776 send_resp(dut, conn, SIGMA_ERROR,
10777 "errorCode,Invalid ap_set_rfeature(60G)");
10778 return 0;
10779}
10780#endif /* __linux__ */
10781
10782
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010783static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10784 struct sigma_cmd *cmd)
10785{
10786 /* const char *name = get_param(cmd, "NAME"); */
10787 /* const char *type = get_param(cmd, "Type"); */
10788
10789 switch (get_driver_type()) {
10790 case DRIVER_ATHEROS:
10791 return ath_ap_set_rfeature(dut, conn, cmd);
10792 case DRIVER_OPENWRT:
10793 switch (get_openwrt_driver_type()) {
10794 case OPENWRT_DRIVER_ATHEROS:
10795 return ath_ap_set_rfeature(dut, conn, cmd);
10796 default:
10797 send_resp(dut, conn, SIGMA_ERROR,
10798 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
10799 return 0;
10800 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053010801 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010802 case DRIVER_WCN:
10803 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010804 case DRIVER_MAC80211:
10805 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010806#ifdef __linux__
10807 case DRIVER_WIL6210:
10808 return wil6210_ap_set_rfeature(dut, conn, cmd);
10809#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010810 default:
10811 send_resp(dut, conn, SIGMA_ERROR,
10812 "errorCode,Unsupported ap_set_rfeature with the current driver");
10813 return 0;
10814 }
10815}
10816
10817
10818static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
10819 struct sigma_cmd *cmd)
10820{
10821 /* const char *name = get_param(cmd, "NAME"); */
10822 return 1;
10823}
10824
10825
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010826static int cmd_ap_preset_testparameters(struct sigma_dut *dut,
10827 struct sigma_conn *conn,
10828 struct sigma_cmd *cmd)
10829{
10830 const char *val;
10831
10832 val = get_param(cmd, "Oper_Chn");
10833 if (val) {
10834 dut->ap_oper_chn = 1;
10835 dut->ap_channel = atoi(val);
10836 }
10837
10838 return 1;
10839}
10840
10841
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010842void ap_register_cmds(void)
10843{
10844 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
10845 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
10846 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
10847 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
10848 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
10849 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053010850 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010851 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
10852 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
10853 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
10854 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
10855 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
10856 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
10857 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
10858 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
10859 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
10860 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
10861 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
10862 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
10863 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
10864 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
10865 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
10866 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010867 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
10868 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010869 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010870 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080010871 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
10872 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010873}