blob: 3cf6225a7ecf549ecaefcc0c5400e0a4390343cf [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 ||
Jouni Malinenda5f35b2019-03-26 00:25:53 +0200120 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP ||
121 (dut->ap_akm_values &
122 ((1 << AKM_FT_EAP) |
123 (1 << AKM_FT_PSK) |
124 (1 << AKM_FT_SAE) |
125 (1 << AKM_FT_SUITE_B) |
126 (1 << AKM_FT_FILS_SHA256) |
127 (1 << AKM_FT_FILS_SHA384)));
Jouni Malinen6be21c82018-08-01 18:47:24 +0300128}
129
130
Jouni Malinenf7222712019-06-13 01:50:21 +0300131static enum sigma_cmd_result cmd_ap_ca_version(struct sigma_dut *dut,
132 struct sigma_conn *conn,
133 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200134{
135 /* const char *name = get_param(cmd, "NAME"); */
136 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
137 return 0;
138}
139
140
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300141static void kill_hostapd_process_pid(struct sigma_dut *dut)
142{
143 FILE *f;
144 int pid, res;
145 char path[100];
146 int count;
147
148 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
149 if (!f)
150 return;
151 res = fscanf(f, "%d", &pid);
152 fclose(f);
153 if (res != 1)
154 return;
155 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
156 kill(pid, SIGTERM);
157 snprintf(path, sizeof(path), "/proc/%d", pid);
158 for (count = 0; count < 20 && file_exists(path); count++)
159 usleep(100000);
160}
161
162
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300163int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200164{
165#ifndef __QNXNTO__
166 struct ifreq ifr;
167 int s;
168
169 s = socket(AF_INET, SOCK_DGRAM, 0);
170 if (s < 0)
171 return -1;
172 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700173 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200174 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
175 perror("ioctl");
176 close(s);
177 return -1;
178 }
179 close(s);
180 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
181#else /* __QNXNTO__ */
182 struct ifaddrs *ifaddrshead = NULL;
183 int found = 0;
184 struct ifaddrs *temp_ifap = NULL;
185 struct sockaddr_dl *sdl = NULL;
186
187 if (getifaddrs(&ifaddrshead) != 0) {
188 perror("getifaddrs failed");
189 return -1;
190 }
191
192 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
193 ifaddrshead = ifaddrshead->ifa_next) {
194 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
195 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
196 found = 1;
197 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
198 if (sdl)
199 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
200 }
201 }
202
203 if (temp_ifap)
204 freeifaddrs(temp_ifap);
205
206 if (!found) {
207 perror("Failed to get the interface");
208 return -1;
209 }
210#endif /* __QNXNTO__ */
211 return 0;
212}
213
214
215static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
216 const char *val)
217{
218 char buf[60];
219
220 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
221 ifname, atoi(val));
222 if (system(buf) != 0) {
223 sigma_dut_print(dut, DUT_MSG_ERROR,
224 "wifitool ap_group_id failed");
225 }
226}
227
228
229void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
230 const char *val)
231{
232 char buf[60];
233
234 /* TODO: Enable support for other values */
235 if (strcasecmp(val, "40") == 0) {
236 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
237 ifname);
238 if (system(buf) != 0) {
239 sigma_dut_print(dut, DUT_MSG_ERROR,
240 "wifitool cts_width failed");
241 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800242 snprintf(buf, sizeof(buf),
243 "athdiag --set --address=0x10024 --val=0xd90b8a14");
244 if (system(buf) != 0) {
245 sigma_dut_print(dut, DUT_MSG_ERROR,
246 "disabling phy restart failed");
247 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200248 } else {
249 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
250 }
251}
252
253
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800254void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
255 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200256{
257 char buf[60];
258
259 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200260 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700261 run_iwpriv(dut, ifname, "cwmenable 1");
262
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800263 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
264 ifname);
265 if (system(buf) != 0) {
266 sigma_dut_print(dut, DUT_MSG_ERROR,
267 "disabling RTS from rate control logic failed");
268 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200269 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200270 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700271 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200272 } else {
273 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
274 }
275}
276
277
278static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
279 const char *val)
280{
281 char buf[60];
282
283 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200284 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200285 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
286 if (system(buf) != 0) {
287 sigma_dut_print(dut, DUT_MSG_ERROR,
288 "iwconfig rts 64 failed");
289 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800290 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
291 ifname);
292 if (system(buf) != 0) {
293 sigma_dut_print(dut, DUT_MSG_ERROR,
294 "wifitool beeliner_fw_test 100 1 failed");
295 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200296 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200297 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200298 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
299 if (system(buf) != 0) {
300 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700301 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200302 }
303 } else {
304 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
305 }
306}
307
308
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800309static void ath_radio(struct sigma_dut *dut, const char *val)
310{
311 if (strcasecmp(val, "on") == 0) {
312 if (dut->ap_interface_5g == 1) {
313 run_system(dut, "uci set wireless.wifi0.disabled=0");
314 } else if (dut->ap_interface_2g == 1) {
315 run_system(dut, "uci set wireless.wifi1.disabled=0");
316 } else {
317 run_system(dut, "uci set wireless.wifi0.disabled=0");
318 run_system(dut, "uci set wireless.wifi1.disabled=0");
319 }
320 run_system(dut, "uci commit");
321 run_system(dut, "wifi down");
322 run_system(dut, "wifi up");
323 } else if (strcasecmp(val, "off") == 0) {
324 if (dut->ap_interface_5g == 1) {
325 run_system(dut, "uci set wireless.wifi0.disabled=1");
326 } else if (dut->ap_interface_2g == 1) {
327 run_system(dut, "uci set wireless.wifi1.disabled=1");
328 } else {
329 run_system(dut, "uci set wireless.wifi0.disabled=1");
330 run_system(dut, "uci set wireless.wifi1.disabled=1");
331 }
332 run_system(dut, "uci commit");
333 run_system(dut, "wifi down");
334 run_system(dut, "wifi up");
335 }
336}
337
338
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800339static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
340 const char *val)
341{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700342 if (strcasecmp(val, "disable") == 0)
343 run_iwpriv(dut, ifname, "stealthdown 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800344}
345
346
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800347static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
348 const char *val)
349{
350 char buf[60];
351
352 if (strcasecmp(val, "high") == 0)
353 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
354 else if (strcasecmp(val, "low") == 0)
355 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
356 else
357 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
358
359 if (system(buf) != 0)
360 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
361}
362
363
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200364static enum ap_mode get_mode(const char *str)
365{
366 if (strcasecmp(str, "11a") == 0)
367 return AP_11a;
368 else if (strcasecmp(str, "11g") == 0)
369 return AP_11g;
370 else if (strcasecmp(str, "11b") == 0)
371 return AP_11b;
372 else if (strcasecmp(str, "11na") == 0)
373 return AP_11na;
374 else if (strcasecmp(str, "11ng") == 0)
375 return AP_11ng;
376 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
377 return AP_11ac;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200378 else if (strcasecmp(str, "11ad") == 0)
379 return AP_11ad;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200380 else
381 return AP_inval;
382}
383
384
385static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
386{
387 char command[1000];
388 const char *bin;
389 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700390 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200391
392 if (file_exists("hostapd_cli"))
393 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300394 else if (file_exists("../../hostapd/hostapd_cli"))
395 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200396 else
397 bin = "hostapd_cli";
398
399 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700400 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200401
402 if (sigma_radio_ifname[0] &&
403 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700404 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405 else if (sigma_radio_ifname[0] &&
406 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700407 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200408 }
409
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700410 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200411 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700412 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200413 else
414 snprintf(command, sizeof(command), "%s %s", bin, buf);
415 return run_system(dut, command);
416}
417
418
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700419static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
420 struct sigma_cmd *cmd)
421{
422 FILE *f;
423 int i;
424
425 f = fopen("/tmp/lci_cfg.txt", "w");
426 if (!f) {
427 sigma_dut_print(dut, DUT_MSG_ERROR,
428 "Failed to open /tmp/lci_cfg.txt");
429 return -1;
430 }
431
432 for (i = 2; i < cmd->count; i++)
433 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
434 fprintf(f, "\n");
435 fclose(f);
436
437 return 0;
438}
439
440
hangtian00606622019-04-19 11:15:48 +0800441static void set_ap_country_code(struct sigma_dut *dut)
442{
443#if defined(ANDROID) || defined(LINUX_EMBEDDED)
444 char buf[256];
445
446 if (dut->ap_countrycode[0]) {
447 snprintf(buf, sizeof(buf), "DRIVER COUNTRY %s",
448 dut->ap_countrycode);
449 if (wpa_command(get_station_ifname(), buf) < 0)
450 sigma_dut_print(dut, DUT_MSG_ERROR,
451 "Failed to set country code");
452 else
453 sigma_dut_print(dut, DUT_MSG_INFO,
454 "Successfully set country code to %s",
455 dut->ap_countrycode);
456 }
457#endif
458}
459
460
Jouni Malinenf7222712019-06-13 01:50:21 +0300461static enum sigma_cmd_result cmd_ap_set_wireless(struct sigma_dut *dut,
462 struct sigma_conn *conn,
463 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200464{
465 /* const char *name = get_param(cmd, "NAME"); */
466 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200467 const char *val;
468 unsigned int wlan_tag = 1;
469 char *ifname = get_main_ifname();
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +0200470 char buf[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200471
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200472 /* Allow program to be overridden if specified in the ap_set_wireless
473 * to support some 60 GHz test scripts where the program may be 60 GHz
474 * or WPS. */
475 val = get_param(cmd, "PROGRAM");
476 if (val)
477 dut->program = sigma_program_to_enum(val);
478
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200479 val = get_param(cmd, "WLAN_TAG");
480 if (val) {
481 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700482 if (wlan_tag < 1 || wlan_tag > 3) {
483 /*
484 * The only valid WLAN Tags as of now as per the latest
485 * WFA scripts are 1, 2, and 3.
486 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200487 send_resp(dut, conn, SIGMA_INVALID,
488 "errorCode,Invalid WLAN_TAG");
489 return 0;
490 }
491 }
492
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800493 val = get_param(cmd, "Interface");
494 if (val) {
495 if (strcasecmp(val, "5G") == 0)
496 dut->ap_interface_5g = 1;
497 else
498 dut->ap_interface_2g = 1;
499
500 if (dut->ap_interface_5g && dut->ap_interface_2g)
501 dut->ap_is_dual = 1;
502 }
503
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200504 val = get_param(cmd, "CountryCode");
505 if (val) {
506 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
507 return -1;
508 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
509 "%s", val);
hangtian00606622019-04-19 11:15:48 +0800510
511 /*
512 * Regdomain self-managed driver does not accept hostapd country
513 * code setting in all cases. Try to use wpa_supplicant DRIVER
514 * command first to set the driver to a specific country code
515 * before starting AP functionality. This is targeting cases
516 * where wpa_supplicant is running on the device as well for
517 * non-AP mode functionality.
518 */
519 if (get_driver_type() == DRIVER_LINUX_WCN)
520 set_ap_country_code(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200521 }
522
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530523 val = get_param(cmd, "regulatory_mode");
524 if (val) {
525 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
526 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
527 }
528
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200529 val = get_param(cmd, "SSID");
530 if (val) {
531 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
532 return -1;
533
534 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700535 /*
536 * If tag is not specified, it is deemed to be 1.
537 * Hence tag of 1 is a special case and the values
538 * corresponding to wlan-tag=1 are stored separately
539 * from the values corresponding tags 2 and 3.
540 * This approach minimises the changes to existing code
541 * since most of the sigma_dut code does not deal with
542 * WLAN-TAG CAPI variable.
543 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200544 snprintf(dut->ap_ssid,
545 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700546 } else {
547 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
548 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
549 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200550 }
551 }
552
553 val = get_param(cmd, "CHANNEL");
554 if (val) {
555 const char *pos;
556 dut->ap_channel = atoi(val);
557 pos = strchr(val, ';');
558 if (pos) {
559 pos++;
560 dut->ap_channel_1 = atoi(pos);
561 }
562 }
563
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530564 /* Overwrite the AP channel with DFS channel if configured */
565 val = get_param(cmd, "dfs_chan");
566 if (val) {
567 dut->ap_channel = atoi(val);
568 }
569
570 val = get_param(cmd, "dfs_mode");
571 if (val) {
572 if (strcasecmp(val, "Enable") == 0)
573 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
574 else if (strcasecmp(val, "Disable") == 0)
575 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
576 else
577 sigma_dut_print(dut, DUT_MSG_ERROR,
578 "Unsupported dfs_mode value: %s", val);
579 }
580
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200581 val = get_param(cmd, "MODE");
582 if (val) {
583 char *str, *pos;
584
585 str = strdup(val);
586 if (str == NULL)
587 return -1;
588 pos = strchr(str, ';');
589 if (pos)
590 *pos++ = '\0';
591
592 dut->ap_is_dual = 0;
593 dut->ap_mode = get_mode(str);
594 if (dut->ap_mode == AP_inval) {
595 send_resp(dut, conn, SIGMA_INVALID,
596 "errorCode,Unsupported MODE");
597 free(str);
598 return 0;
599 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800600 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200601 dut->ap_chwidth = AP_80;
602
603 if (pos) {
604 dut->ap_mode_1 = get_mode(pos);
605 if (dut->ap_mode_1 == AP_inval) {
606 send_resp(dut, conn, SIGMA_INVALID,
607 "errorCode,Unsupported MODE");
608 free(str);
609 return 0;
610 }
611 if (dut->ap_mode_1 == AP_11ac)
612 dut->ap_chwidth_1 = AP_80;
613 dut->ap_is_dual = 1;
614 }
615
616 free(str);
617 } else if (dut->ap_mode == AP_inval) {
618 if (dut->ap_channel <= 11)
619 dut->ap_mode = AP_11ng;
620 else if (dut->program == PROGRAM_VHT)
621 dut->ap_mode = AP_11ac;
622 else
623 dut->ap_mode = AP_11na;
624 }
625
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200626 /* Override the AP mode in case of 60 GHz */
627 if (dut->program == PROGRAM_60GHZ) {
628 dut->ap_mode = AP_11ad;
629 /* Workaround to force channel 2 if not specified */
630 if (!dut->ap_channel)
631 dut->ap_channel = 2;
632 }
633
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530634 val = get_param(cmd, "WME");
635 if (val) {
636 if (strcasecmp(val, "on") == 0)
637 dut->ap_wme = AP_WME_ON;
638 else if (strcasecmp(val, "off") == 0)
639 dut->ap_wme = AP_WME_OFF;
640 else
641 sigma_dut_print(dut, DUT_MSG_ERROR,
642 "Unsupported WME value: %s", val);
643 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200644
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530645 val = get_param(cmd, "WMMPS");
646 if (val) {
647 if (strcasecmp(val, "on") == 0)
648 dut->ap_wmmps = AP_WMMPS_ON;
649 else if (strcasecmp(val, "off") == 0)
650 dut->ap_wmmps = AP_WMMPS_OFF;
651 else
652 sigma_dut_print(dut, DUT_MSG_ERROR,
653 "Unsupported WMMPS value: %s", val);
654 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200655
656 val = get_param(cmd, "RTS");
657 if (val)
658 dut->ap_rts = atoi(val);
659
660 val = get_param(cmd, "FRGMNT");
661 if (val)
662 dut->ap_frgmnt = atoi(val);
663
664 /* TODO: PWRSAVE */
665
666 val = get_param(cmd, "BCNINT");
667 if (val)
668 dut->ap_bcnint = atoi(val);
669
670 val = get_param(cmd, "RADIO");
671 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530672 enum driver_type drv = get_driver_type();
673
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200674 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800675 if (drv == DRIVER_OPENWRT)
676 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200677 if (drv == DRIVER_ATHEROS)
678 ath_ap_start_hostapd(dut);
679 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
680 return 0;
681 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530682 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800683 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300684 } else if (dut->use_hostapd_pid_file) {
685 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530686 } else if (kill_process(dut, "(hostapd)", 1,
687 SIGTERM) == 0 ||
688 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200689 sigma_dut_print(dut, DUT_MSG_INFO,
690 "Killed hostapd on radio,off");
691 }
692 } else {
693 send_resp(dut, conn, SIGMA_INVALID,
694 "errorCode,Unsupported RADIO value");
695 return 0;
696 }
697 }
698
699 val = get_param(cmd, "P2PMgmtBit");
700 if (val)
701 dut->ap_p2p_mgmt = atoi(val);
702
703 /* TODO: ChannelUsage */
704
705 /* TODO: 40_INTOLERANT */
706
707 val = get_param(cmd, "ADDBA_REJECT");
708 if (val) {
709 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200710 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200711 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200712 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200713 }
714
715 val = get_param(cmd, "AMPDU");
716 if (val) {
717 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200718 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200719 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200720 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200721 }
722
723 val = get_param(cmd, "AMPDU_EXP");
724 if (val)
725 dut->ap_ampdu_exp = atoi(val);
726
727 val = get_param(cmd, "AMSDU");
728 if (val) {
729 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200730 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200731 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200732 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200733 }
734
735 val = get_param(cmd, "NoAck");
736 if (val) {
737 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200738 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200739 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200740 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200741 }
742
743 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200744 /* TODO: MCS_32 */
745
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530746 val = get_param(cmd, "OFFSET");
747 if (val) {
748 if (strcasecmp(val, "Above") == 0)
749 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
750 else if (strcasecmp(val, "Below") == 0)
751 dut->ap_chwidth_offset = SEC_CH_40BELOW;
752 }
753
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200754 val = get_param(cmd, "MCS_FIXEDRATE");
755 if (val) {
756 dut->ap_fixed_rate = 1;
757 dut->ap_mcs = atoi(val);
758 }
759
760 val = get_param(cmd, "SPATIAL_RX_STREAM");
761 if (val) {
762 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
763 dut->ap_rx_streams = 1;
764 if (dut->device_type == AP_testbed)
765 dut->ap_vhtmcs_map = 0xfffc;
766 } else if (strcasecmp(val, "2SS") == 0 ||
767 strcasecmp(val, "2") == 0) {
768 dut->ap_rx_streams = 2;
769 if (dut->device_type == AP_testbed)
770 dut->ap_vhtmcs_map = 0xfff0;
771 } else if (strcasecmp(val, "3SS") == 0 ||
772 strcasecmp(val, "3") == 0) {
773 dut->ap_rx_streams = 3;
774 if (dut->device_type == AP_testbed)
775 dut->ap_vhtmcs_map = 0xffc0;
776 } else if (strcasecmp(val, "4SS") == 0 ||
777 strcasecmp(val, "4") == 0) {
778 dut->ap_rx_streams = 4;
779 }
780 }
781
782 val = get_param(cmd, "SPATIAL_TX_STREAM");
783 if (val) {
784 if (strcasecmp(val, "1SS") == 0 ||
785 strcasecmp(val, "1") == 0) {
786 dut->ap_tx_streams = 1;
787 if (dut->device_type == AP_testbed)
788 dut->ap_vhtmcs_map = 0xfffc;
789 } else if (strcasecmp(val, "2SS") == 0 ||
790 strcasecmp(val, "2") == 0) {
791 dut->ap_tx_streams = 2;
792 if (dut->device_type == AP_testbed)
793 dut->ap_vhtmcs_map = 0xfff0;
794 } else if (strcasecmp(val, "3SS") == 0 ||
795 strcasecmp(val, "3") == 0) {
796 dut->ap_tx_streams = 3;
797 if (dut->device_type == AP_testbed)
798 dut->ap_vhtmcs_map = 0xffc0;
799 } else if (strcasecmp(val, "4SS") == 0 ||
800 strcasecmp(val, "4") == 0) {
801 dut->ap_tx_streams = 4;
802 }
803 }
804
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700805 val = get_param(cmd, "BSS_max_idle");
806 if (val) {
807 if (strncasecmp(val, "Enable", 7) == 0) {
808 dut->wnm_bss_max_feature = VALUE_ENABLED;
809 } else if (strncasecmp(val, "Disable", 8) == 0) {
810 dut->wnm_bss_max_feature = VALUE_DISABLED;
811 } else {
812 send_resp(dut, conn, SIGMA_ERROR,
813 "errorCode,Invalid value for BSS_max_Feature");
814 return 0;
815 }
816 }
817
818 val = get_param(cmd, "BSS_Idle_Protection_options");
819 if (val) {
820 int protection = (int) strtol(val, (char **) NULL, 10);
821
822 if (protection != 1 && protection != 0) {
823 send_resp(dut, conn, SIGMA_ERROR,
824 "errorCode,Invalid value for BSS_Idle_Protection_options");
825 return 0;
826 }
827 dut->wnm_bss_max_protection = protection ?
828 VALUE_ENABLED : VALUE_DISABLED;
829 }
830
831 val = get_param(cmd, "BSS_max_Idle_period");
832 if (val) {
Jouni Malinen544edf02019-02-25 19:02:33 +0200833 long int idle_time = strtol(val, (char **) NULL, 10);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700834
835 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
836 send_resp(dut, conn, SIGMA_ERROR,
837 "errorCode,Invalid value for BSS_max_Idle_period");
838 return 0;
839 }
Jouni Malinen544edf02019-02-25 19:02:33 +0200840 dut->wnm_bss_max_idle_time = (int) idle_time;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700841 }
842
843 val = get_param(cmd, "PROXY_ARP");
844 if (val)
845 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
846
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200847 val = get_param(cmd, "nss_mcs_cap");
848 if (val) {
849 int nss, mcs;
850 char token[20];
851 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530852 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200853
854 if (strlen(val) >= sizeof(token))
855 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300856 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530857 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530858 if (!result) {
859 sigma_dut_print(dut, DUT_MSG_ERROR,
860 "VHT NSS not specified");
861 return 0;
862 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200863 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530864 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200865 if (result == NULL) {
866 sigma_dut_print(dut, DUT_MSG_ERROR,
867 "VHTMCS NOT SPECIFIED!");
868 return 0;
869 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530870 result = strtok_r(result, "-", &saveptr);
871 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530872 if (!result) {
873 sigma_dut_print(dut, DUT_MSG_ERROR,
874 "VHT MCS not specified");
875 return 0;
876 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200877 mcs = atoi(result);
878 switch (nss) {
879 case 1:
880 switch (mcs) {
881 case 7:
882 dut->ap_vhtmcs_map = 0xfffc;
883 break;
884 case 8:
885 dut->ap_vhtmcs_map = 0xfffd;
886 break;
887 case 9:
888 dut->ap_vhtmcs_map = 0xfffe;
889 break;
890 default:
891 dut->ap_vhtmcs_map = 0xfffe;
892 break;
893 }
894 break;
895 case 2:
896 switch (mcs) {
897 case 7:
898 dut->ap_vhtmcs_map = 0xfff0;
899 break;
900 case 8:
901 dut->ap_vhtmcs_map = 0xfff5;
902 break;
903 case 9:
904 dut->ap_vhtmcs_map = 0xfffa;
905 break;
906 default:
907 dut->ap_vhtmcs_map = 0xfffa;
908 break;
909 }
910 break;
911 case 3:
912 switch (mcs) {
913 case 7:
914 dut->ap_vhtmcs_map = 0xffc0;
915 break;
916 case 8:
917 dut->ap_vhtmcs_map = 0xffd5;
918 break;
919 case 9:
920 dut->ap_vhtmcs_map = 0xffea;
921 break;
922 default:
923 dut->ap_vhtmcs_map = 0xffea;
924 break;
925 }
926 break;
927 default:
928 dut->ap_vhtmcs_map = 0xffea;
929 break;
930 }
931 }
932
933 /* TODO: MPDU_MIN_START_SPACING */
934 /* TODO: RIFS_TEST */
935 /* TODO: SGI20 */
936
937 val = get_param(cmd, "STBC_TX");
938 if (val)
939 dut->ap_tx_stbc = atoi(val);
940
941 val = get_param(cmd, "WIDTH");
942 if (val) {
943 if (strcasecmp(val, "20") == 0)
944 dut->ap_chwidth = AP_20;
945 else if (strcasecmp(val, "40") == 0)
946 dut->ap_chwidth = AP_40;
947 else if (strcasecmp(val, "80") == 0)
948 dut->ap_chwidth = AP_80;
949 else if (strcasecmp(val, "160") == 0)
950 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800951 else if (strcasecmp(val, "80plus80") == 0) {
952 dut->ap_80plus80 = 1;
953 dut->ap_chwidth = AP_80_80;
954 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200955 dut->ap_chwidth = AP_AUTO;
956 else {
957 send_resp(dut, conn, SIGMA_INVALID,
958 "errorCode,Unsupported WIDTH");
959 return 0;
960 }
961 }
962
963 /* TODO: WIDTH_SCAN */
964
965 val = get_param(cmd, "TDLSProhibit");
966 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
967 val = get_param(cmd, "TDLSChswitchProhibit");
968 dut->ap_tdls_prohibit_chswitch =
969 val && strcasecmp(val, "Enabled") == 0;
970 val = get_param(cmd, "HS2");
971 if (val && wlan_tag == 1)
972 dut->ap_hs2 = atoi(val);
973 val = get_param(cmd, "P2P_CROSS_CONNECT");
974 if (val)
975 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
976
977 val = get_param(cmd, "FakePubKey");
978 dut->ap_fake_pkhash = val && atoi(val);
979
980 val = get_param(cmd, "vht_tkip");
981 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
982 val = get_param(cmd, "vht_wep");
983 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
984
985 val = get_param(cmd, "Protect_mode");
986 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
987
988 val = get_param(cmd, "DYN_BW_SGNL");
989 if (val) {
990 switch (get_driver_type()) {
991 case DRIVER_OPENWRT:
992 switch (get_openwrt_driver_type()) {
993 case OPENWRT_DRIVER_ATHEROS:
994 ath_config_dyn_bw_sig(dut, ifname, val);
995 break;
996 default:
997 send_resp(dut, conn, SIGMA_ERROR,
998 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
999 return 0;
1000 }
1001 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +05301002 case DRIVER_WCN:
1003 case DRIVER_LINUX_WCN:
1004 ath_config_dyn_bw_sig(dut, ifname, val);
1005 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001006 default:
1007 sigma_dut_print(dut, DUT_MSG_ERROR,
1008 "Unsupported DYN_BW_SGL with the current driver");
1009 break;
1010 }
1011 }
1012
1013 val = get_param(cmd, "SGI80");
1014 if (val) {
1015 if (strcasecmp(val, "enable") == 0)
1016 dut->ap_sgi80 = 1;
1017 else if (strcasecmp(val, "disable") == 0)
1018 dut->ap_sgi80 = 0;
1019 else {
1020 send_resp(dut, conn, SIGMA_INVALID,
1021 "errorCode,Unsupported SGI80");
1022 return 0;
1023 }
1024 }
1025
1026 val = get_param(cmd, "LDPC");
1027 if (val) {
1028 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001029 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001030 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001031 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001032 else {
1033 send_resp(dut, conn, SIGMA_INVALID,
1034 "errorCode,Unsupported LDPC");
1035 return 0;
1036 }
1037 }
1038
1039 val = get_param(cmd, "BW_SGNL");
1040 if (val) {
1041 /*
1042 * With dynamic bandwidth signaling enabled we should see
1043 * RTS if the threshold is met.
1044 */
1045 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001046 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001047 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001048 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001049 } else {
1050 send_resp(dut, conn, SIGMA_INVALID,
1051 "errorCode,Unsupported BW_SGNL");
1052 return 0;
1053 }
1054 }
1055
1056 val = get_param(cmd, "RTS_FORCE");
1057 if (val) {
1058 switch (get_driver_type()) {
1059 case DRIVER_OPENWRT:
1060 switch (get_openwrt_driver_type()) {
1061 case OPENWRT_DRIVER_ATHEROS:
1062 ath_config_rts_force(dut, ifname, val);
1063 break;
1064 default:
1065 send_resp(dut, conn, SIGMA_ERROR,
1066 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
1067 return 0;
1068 }
1069 break;
1070 default:
1071 sigma_dut_print(dut, DUT_MSG_ERROR,
1072 "Unsupported RTS_FORCE with the current driver");
1073 break;
1074 }
1075 }
1076
1077 val = get_param(cmd, "Zero_crc");
1078 if (val) {
1079 switch (get_driver_type()) {
1080 case DRIVER_ATHEROS:
1081 ath_set_zero_crc(dut, val);
1082 break;
1083 case DRIVER_OPENWRT:
1084 switch (get_openwrt_driver_type()) {
1085 case OPENWRT_DRIVER_ATHEROS:
1086 ath_set_zero_crc(dut, val);
1087 break;
1088 default:
1089 send_resp(dut, conn, SIGMA_ERROR,
1090 "errorCode,Unsupported zero_crc with the current driver");
1091 return 0;
1092 }
1093 break;
1094 default:
1095 send_resp(dut, conn, SIGMA_ERROR,
1096 "errorCode,Unsupported zero_crc with the current driver");
1097 return 0;
1098 }
1099 }
1100
1101 val = get_param(cmd, "TxBF");
1102 if (val)
1103 dut->ap_txBF = strcasecmp(val, "enable") == 0;
1104
1105 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301106 if (val) {
1107 if (strcasecmp(val, "enable") == 0) {
1108 dut->ap_txBF = 1;
1109 dut->ap_mu_txBF = 1;
1110 } else if (strcasecmp(val, "disable") == 0) {
1111 dut->ap_txBF = 0;
1112 dut->ap_mu_txBF = 0;
1113 } else {
1114 sigma_dut_print(dut, DUT_MSG_ERROR,
1115 "Unsupported MU_TxBF");
1116 }
1117 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001118
1119 /* UNSUPPORTED: tx_lgi_rate */
1120
1121 val = get_param(cmd, "wpsnfc");
1122 if (val)
1123 dut->ap_wpsnfc = atoi(val);
1124
1125 val = get_param(cmd, "GROUP_ID");
1126 if (val) {
1127 switch (get_driver_type()) {
1128 case DRIVER_OPENWRT:
1129 switch (get_openwrt_driver_type()) {
1130 case OPENWRT_DRIVER_ATHEROS:
1131 ath_ap_set_group_id(dut, ifname, val);
1132 break;
1133 default:
1134 send_resp(dut, conn, SIGMA_ERROR,
1135 "errorCode,Unsupported group_id with the current driver");
1136 return 0;
1137 }
1138 break;
1139 default:
1140 send_resp(dut, conn, SIGMA_ERROR,
1141 "errorCode,Unsupported group_id with the current driver");
1142 return 0;
1143 }
1144 }
1145
1146 val = get_param(cmd, "CTS_WIDTH");
1147 if (val) {
1148 switch (get_driver_type()) {
1149 case DRIVER_OPENWRT:
1150 switch (get_openwrt_driver_type()) {
1151 case OPENWRT_DRIVER_ATHEROS:
1152 ath_set_cts_width(dut, ifname, val);
1153 break;
1154 default:
1155 send_resp(dut, conn, SIGMA_ERROR,
1156 "errorCode,Unsupported cts_width with the current driver");
1157 return 0;
1158 }
1159 break;
1160 default:
1161 send_resp(dut, conn, SIGMA_ERROR,
1162 "errorCode,Unsupported cts_width with the current driver");
1163 return 0;
1164 }
1165 }
1166
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001167 val = get_param(cmd, "MU_NDPA_FrameFormat");
1168 if (val)
1169 dut->ap_ndpa_frame = atoi(val);
1170
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001171 val = get_param(cmd, "interworking");
1172 if (val && strcmp(val, "1") == 0)
1173 dut->ap_interworking = 1;
1174
1175 val = get_param(cmd, "GAS_CB_DELAY");
1176 if (val)
1177 dut->ap_gas_cb_delay = atoi(val);
1178
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001179 val = get_param(cmd, "LCI");
1180 if (val) {
1181 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1182 return -1;
1183 dut->ap_lci = 1;
1184 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1185 ath_set_lci_config(dut, val, cmd);
1186 }
1187
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001188 val = get_param(cmd, "InfoZ");
1189 if (val) {
1190 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1191 return -1;
1192 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1193 }
1194
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001195 val = get_param(cmd, "LocCivicAddr");
1196 if (val) {
1197 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1198 return -1;
1199 dut->ap_lcr = 1;
1200 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1201 if (dut->ap_lci == 0)
1202 ath_set_lci_config(dut, val, cmd);
1203 }
1204
1205 val = get_param(cmd, "NeighAPBSSID");
1206 if (val) {
1207 if (dut->ap_neighap < 3) {
1208 if (parse_mac_address(
1209 dut, val,
1210 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1211 send_resp(dut, conn, SIGMA_INVALID,
1212 "Failed to parse MAC address");
1213 return 0;
1214 }
1215 dut->ap_neighap++;
1216 if (dut->ap_lci == 1)
1217 dut->ap_scan = 1;
1218 }
1219 }
1220
1221 val = get_param(cmd, "OpChannel");
1222 if (val) {
1223 if (dut->ap_opchannel < 3) {
1224 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1225 dut->ap_opchannel++;
1226 }
1227 }
1228
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001229 val = get_param(cmd, "URI-FQDNdescriptor");
1230 if (val) {
1231 if (strcasecmp(val, "HELD") == 0) {
1232 dut->ap_fqdn_held = 1;
1233 } else if (strcasecmp(val, "SUPL") == 0) {
1234 dut->ap_fqdn_supl = 1;
1235 } else {
1236 send_resp(dut, conn, SIGMA_INVALID,
1237 "errorCode,Unsupported URI-FQDNdescriptor");
1238 return 0;
1239 }
1240 }
1241
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001242 val = get_param(cmd, "Reg_Domain");
1243 if (val) {
1244 if (strcasecmp(val, "Local") == 0) {
1245 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1246 } else if (strcasecmp(val, "Global") == 0) {
1247 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1248 } else {
1249 send_resp(dut, conn, SIGMA_ERROR,
1250 "errorCode,Wrong value for Reg_Domain");
1251 return 0;
1252 }
1253 }
1254
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001255 val = get_param(cmd, "NAME");
1256 if (val) {
1257 if (strcasecmp(val, "ap1mbo") == 0)
1258 dut->ap_name = 1;
1259 else if (strcasecmp(val, "ap2mbo") == 0)
1260 dut->ap_name = 2;
1261 else
1262 dut->ap_name = 0;
1263 }
1264
1265 val = get_param(cmd, "FT_OA");
1266 if (val) {
1267 if (strcasecmp(val, "Enable") == 0) {
1268 dut->ap_ft_oa = 1;
1269 } else if (strcasecmp(val, "Disable") == 0) {
1270 dut->ap_ft_oa = 0;
1271 } else {
1272 send_resp(dut, conn, SIGMA_ERROR,
1273 "errorCode,Wrong value for FT_OA");
1274 return 0;
1275 }
1276 }
1277
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001278 val = get_param(cmd, "Cellular_Cap_Pref");
1279 if (val)
1280 dut->ap_cell_cap_pref = atoi(val);
1281
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001282 val = get_param(cmd, "DOMAIN");
1283 if (val) {
1284 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1285 send_resp(dut, conn, SIGMA_ERROR,
1286 "errorCode,Too long DOMAIN");
1287 return 0;
1288 }
1289 snprintf(dut->ap_mobility_domain,
1290 sizeof(dut->ap_mobility_domain), "%s", val);
1291 }
1292
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001293 val = get_param(cmd, "ft_bss_list");
1294 if (val) {
1295 char *mac_str;
1296 int i;
1297 char *saveptr;
1298 char *mac_list_str;
1299
1300 mac_list_str = strdup(val);
1301 if (!mac_list_str)
1302 return -1;
1303 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1304 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1305 if (parse_mac_address(dut, mac_str,
1306 dut->ft_bss_mac_list[i]) < 0) {
1307 sigma_dut_print(dut, DUT_MSG_ERROR,
1308 "MAC Address not in proper format");
1309 break;
1310 }
1311 dut->ft_bss_mac_cnt++;
1312 mac_str = strtok_r(NULL, " ", &saveptr);
1313 }
1314 sigma_dut_print(dut, DUT_MSG_DEBUG,
1315 "Storing the following FT BSS MAC List");
1316 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1317 sigma_dut_print(dut, DUT_MSG_DEBUG,
1318 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1319 i,
1320 dut->ft_bss_mac_list[i][0],
1321 dut->ft_bss_mac_list[i][1],
1322 dut->ft_bss_mac_list[i][2],
1323 dut->ft_bss_mac_list[i][3],
1324 dut->ft_bss_mac_list[i][4],
1325 dut->ft_bss_mac_list[i][5]);
1326 }
1327 free(mac_list_str);
1328 }
1329
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001330 val = get_param(cmd, "OCESupport");
1331 if (val) {
1332 if (strcasecmp(val, "enable") == 0) {
1333 dut->ap_oce = VALUE_ENABLED;
1334 } else if (strcasecmp(val, "disable") == 0) {
1335 dut->ap_oce = VALUE_DISABLED;
1336 dut->ap_filsdscv = VALUE_DISABLED;
1337 } else {
1338 send_resp(dut, conn, SIGMA_INVALID,
1339 "errorCode,Unsupported OCE");
1340 return 0;
1341 }
1342 }
1343
1344 val = get_param(cmd, "FILSDscvInterval");
1345 if (val)
1346 dut->ap_fils_dscv_int = atoi(val);
1347
1348 val = get_param(cmd, "BroadcastSSID");
1349 if (val) {
1350 if (strcasecmp(val, "enable") == 0) {
1351 dut->ap_broadcast_ssid = VALUE_ENABLED;
1352 } else if (strcasecmp(val, "disable") == 0) {
1353 dut->ap_broadcast_ssid = VALUE_DISABLED;
1354 } else {
1355 send_resp(dut, conn, SIGMA_INVALID,
1356 "errorCode,Unsupported hidden SSID");
1357 return 0;
1358 }
1359 }
1360
1361 val = get_param(cmd, "FILSDscv");
1362 if (val) {
1363 if (strcasecmp(val, "enable") == 0) {
1364 dut->ap_filsdscv = VALUE_ENABLED;
1365 } else if (strcasecmp(val, "disable") == 0) {
1366 dut->ap_filsdscv = VALUE_DISABLED;
1367 } else {
1368 send_resp(dut, conn, SIGMA_INVALID,
1369 "errorCode,Unsupported FILSDscv");
1370 return 0;
1371 }
1372 }
1373
1374 val = get_param(cmd, "FILSHLP");
1375 if (val) {
1376 if (strcasecmp(val, "enable") == 0) {
1377 dut->ap_filshlp = VALUE_ENABLED;
1378 } else if (strcasecmp(val, "disable") == 0) {
1379 dut->ap_filshlp = VALUE_DISABLED;
1380 } else {
1381 send_resp(dut, conn, SIGMA_INVALID,
1382 "errorCode,Unsupported FILSHLP");
1383 return 0;
1384 }
1385 }
1386
1387 val = get_param(cmd, "NAIRealm");
1388 if (val) {
1389 dut->ap_nairealm_int = 1;
1390 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
1391 return -1;
1392 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1393 }
1394
1395 val = get_param(cmd, "DeauthDisassocTx");
1396 if (val) {
1397 if (strcasecmp(val, "disable") == 0) {
1398 deauth_disassoc(dut, ifname, val);
1399 } else {
1400 send_resp(dut, conn, SIGMA_INVALID,
1401 "errorCode,Unsupported DeauthDisassocTx");
1402 return 0;
1403 }
1404 }
1405
1406 val = get_param(cmd, "RNR");
1407 if (val) {
1408 if (strcasecmp(val, "enable") == 0) {
1409 dut->ap_rnr = VALUE_ENABLED;
1410 } else if (strcasecmp(val, "disable") == 0) {
1411 dut->ap_rnr = VALUE_DISABLED;
1412 } else {
1413 send_resp(dut, conn, SIGMA_INVALID,
1414 "errorCode,Unsupported RNR");
1415 return 0;
1416 }
1417 }
1418
1419 val = get_param(cmd, "BLEChannelUtil");
1420 if (val)
1421 dut->ap_blechanutil = atoi(val);
1422
1423 val = get_param(cmd, "BLEAvailAdminCap");
1424 if (val)
1425 dut->ap_ble_admit_cap = atoi(val);
1426
1427 val = get_param(cmd, "DataPPDUDuration");
1428 if (val)
1429 dut->ap_datappdudura = atoi(val);
1430
1431 val = get_param(cmd, "AirTimeFract");
1432 if (val)
1433 dut->ap_airtimefract = atoi(val);
1434
1435 val = get_param(cmd, "dhcpServIPADDR");
1436 if (val) {
1437 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
1438 return -1;
1439 snprintf(dut->ap_dhcpserv_ipaddr,
1440 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1441 dut->ap_dhcp_stop = 1;
1442 }
1443
1444 val = get_param(cmd, "ESP_IE");
1445 if (val) {
1446 if (strcasecmp(val, "enable") == 0) {
1447 dut->ap_esp = VALUE_ENABLED;
1448 } else if (strcasecmp(val, "disable") == 0) {
1449 dut->ap_esp = VALUE_DISABLED;
1450 } else {
1451 send_resp(dut, conn, SIGMA_INVALID,
1452 "errorCode,Unsupported ESP_IE");
1453 return 0;
1454 }
1455 }
1456
1457 val = get_param(cmd, "BAWinSize");
1458 if (val)
1459 dut->ap_bawinsize = atoi(val);
1460
1461 val = get_param(cmd, "BLEStaCount");
1462 if (val)
1463 dut->ap_blestacnt = atoi(val);
1464
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001465 val = get_param(cmd, "PPDUTxType");
1466 if (val) {
1467 if (strcasecmp(val, "MU") == 0) {
1468 dut->ap_he_ppdu = PPDU_MU;
1469 } else {
1470 send_resp(dut, conn, SIGMA_INVALID,
1471 "errorCode,Unsupported PPDUTxType");
1472 return 0;
1473 }
1474 }
1475
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02001476 val = get_param(cmd, "WscIEFragment");
1477 if (val && strcasecmp(val, "enable") == 0) {
1478 sigma_dut_print(dut, DUT_MSG_DEBUG,
1479 "Enable WSC IE fragmentation");
1480 dut->wsc_fragment = 1;
1481 }
1482
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02001483 val = get_param(cmd, "WpsVersion");
1484 if (val)
1485 dut->wps_forced_version = get_wps_forced_version(dut, val);
1486
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02001487 val = get_param(cmd, "WscEAPFragment");
1488 if (val && strcasecmp(val, "enable") == 0)
1489 dut->eap_fragment = 1;
1490
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001491 val = get_param(cmd, "MSDUSize");
1492 if (val) {
1493 int mtu;
1494
1495 dut->amsdu_size = atoi(val);
1496 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
1497 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
1498 sigma_dut_print(dut, DUT_MSG_ERROR,
1499 "MSDUSize %d is above max %d or below min %d",
1500 dut->amsdu_size,
1501 IEEE80211_MAX_DATA_LEN_DMG,
1502 IEEE80211_SNAP_LEN_DMG);
1503 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001504 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001505 }
1506
1507 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
1508 sigma_dut_print(dut, DUT_MSG_DEBUG,
1509 "Setting amsdu_size to %d", mtu);
1510 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
1511 get_station_ifname(), mtu);
1512
1513 if (system(buf) != 0) {
1514 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
1515 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001516 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001517 }
1518 }
1519
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001520 val = get_param(cmd, "BAckRcvBuf");
1521 if (val) {
1522 dut->back_rcv_buf = atoi(val);
1523 if (dut->back_rcv_buf == 0) {
1524 sigma_dut_print(dut, DUT_MSG_ERROR,
1525 "Failed to convert %s or value is 0",
1526 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001527 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001528 }
1529
1530 sigma_dut_print(dut, DUT_MSG_DEBUG,
1531 "Setting BAckRcvBuf to %s", val);
1532 }
1533
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001534 val = get_param(cmd, "ExtSchIE");
1535 if (val && !strcasecmp(val, "Enable")) {
1536 int num_allocs = MAX_ESE_ALLOCS;
1537
1538 if (sta_extract_60g_ese(dut, cmd, dut->ap_ese_allocs,
1539 &num_allocs)) {
1540 send_resp(dut, conn, SIGMA_INVALID,
1541 "errorCode,Invalid ExtSchIE");
1542 return 0;
1543 }
1544 dut->ap_num_ese_allocs = num_allocs;
1545 }
1546
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02001547 if (is_60g_sigma_dut(dut)) {
1548 unsigned int abft_len = 1; /* default is one slot */
1549
1550 val = get_param(cmd, "ABFTLRang");
1551 if (val) {
1552 sigma_dut_print(dut, DUT_MSG_DEBUG,
1553 "ABFTLRang parameter %s", val);
1554 if (strcasecmp(val, "Gt1") == 0)
1555 abft_len = 2; /* 2 slots in this case */
1556 }
1557
1558 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
1559 send_resp(dut, conn, SIGMA_ERROR,
1560 "ErrorCode,Can't set ABFT length");
1561 return STATUS_SENT;
1562 }
1563 }
1564
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001565 val = get_param(cmd, "OFDMA");
1566 if (val) {
1567 if (strcasecmp(val, "UL") == 0) {
1568 dut->ap_he_ulofdma = VALUE_ENABLED;
1569 } else {
1570 send_resp(dut, conn, SIGMA_ERROR,
1571 "errorCode,Unsupported OFDMA value");
1572 return STATUS_SENT_ERROR;
1573 }
1574 }
1575
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001576 return 1;
1577}
1578
1579
1580static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1581{
1582 char buf[256];
1583 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1584
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301585 if (tid < 0 ||
1586 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1587 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1588 return;
1589 }
1590
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001591 snprintf(buf, sizeof(buf),
1592 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1593 ifname, VI_QOS_TMP_FILE);
1594 if (system(buf) != 0)
1595 return;
1596
1597 snprintf(buf, sizeof(buf),
1598 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1599 ifname, VI_QOS_TMP_FILE);
1600 if (system(buf) != 0)
1601 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1602
1603 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1604 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1605 if (system(buf) != 0) {
1606 sigma_dut_print(dut, DUT_MSG_ERROR,
1607 "Output redirection to VI_QOS_TMP_FILE failed");
1608 }
1609
1610 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1611 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1612 if (system(buf) != 0) {
1613 sigma_dut_print(dut, DUT_MSG_ERROR,
1614 "Append TID to VI_QOS_FILE failed ");
1615 }
1616
1617 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1618 if (system(buf) != 0)
1619 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1620}
1621
1622
1623static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1624 struct sigma_cmd *cmd)
1625{
1626 const char *val;
1627 char *ifname;
1628 char buf[256];
1629 int tid = 0;
1630
1631 ifname = get_main_ifname();
1632 val = get_param(cmd, "TID");
1633 if (val) {
1634 tid = atoi(val);
1635 if (tid)
1636 ath_inject_frame(dut, ifname, tid);
1637 }
1638
1639 /* NOTE: This is the command sequence on Peregrine for ADDBA */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07001640 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641
1642 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1643 ifname, tid);
1644 if (system(buf) != 0) {
1645 sigma_dut_print(dut, DUT_MSG_ERROR,
1646 "wifitool senddelba failed");
1647 }
1648
1649 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1650 ifname, tid);
1651 if (system(buf) != 0) {
1652 sigma_dut_print(dut, DUT_MSG_ERROR,
1653 "wifitool sendaddba failed");
1654 }
1655
1656 return 1;
1657}
1658
1659
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301660static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1661 const char *sta_mac,
1662 const char *dir_path)
1663{
1664 DIR *dir;
1665 struct dirent *entry;
1666 char buf[128], path[128];
Jouni Malinen3aa72862019-05-29 23:14:51 +03001667 int ret = 0, res;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301668
1669 dir = opendir(dir_path);
1670 if (!dir)
1671 return 0;
1672
1673 while ((entry = readdir(dir))) {
1674 ret = 1;
1675
1676 if (strcmp(entry->d_name, ".") == 0 ||
1677 strcmp(entry->d_name, "..") == 0)
1678 continue;
1679
Jouni Malinen3aa72862019-05-29 23:14:51 +03001680 res = snprintf(path, sizeof(path) - 1, "%s/%s",
1681 dir_path, entry->d_name);
1682 if (res < 0 || res >= sizeof(path))
1683 continue;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301684
1685 if (strcmp(entry->d_name, sta_mac) == 0) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03001686 res = snprintf(buf, sizeof(buf),
1687 "echo 1 > %s/aggr_mode", path);
1688 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301689 sigma_dut_print(dut, DUT_MSG_ERROR,
1690 "Failed to set aggr mode for ath10k");
1691 }
1692
Jouni Malinen3aa72862019-05-29 23:14:51 +03001693 res = snprintf(buf, sizeof(buf),
1694 "echo %d 32 > %s/addba", tid, path);
1695 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301696 sigma_dut_print(dut, DUT_MSG_ERROR,
1697 "Failed to set addbareq for ath10k");
1698 }
1699
1700 break;
1701 }
1702
1703 /* Recursively search subdirectories */
1704 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1705 }
1706
1707 closedir(dir);
1708
1709 return ret;
1710}
1711
1712
1713static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1714 struct sigma_cmd *cmd)
1715{
1716 const char *val;
1717 int tid = 0;
1718
1719 val = get_param(cmd, "TID");
1720 if (val)
1721 tid = atoi(val);
1722
1723 val = get_param(cmd, "sta_mac_address");
1724 if (!val) {
1725 sigma_dut_print(dut, DUT_MSG_ERROR,
1726 "Failed to parse station MAC address");
1727 return 0;
1728 }
1729
1730 return ath10k_debug_enable_addba_req(dut, tid, val,
1731 "/sys/kernel/debug/ieee80211");
1732}
1733
1734
Jouni Malinenf7222712019-06-13 01:50:21 +03001735static enum sigma_cmd_result cmd_ap_send_addba_req(struct sigma_dut *dut,
1736 struct sigma_conn *conn,
1737 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001738{
1739 /* const char *name = get_param(cmd, "NAME"); */
1740 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301741 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001742
1743 switch (get_driver_type()) {
1744 case DRIVER_ATHEROS:
1745 return ath_ap_send_addba_req(dut, conn, cmd);
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02001746#ifdef __linux__
1747 case DRIVER_WIL6210:
1748 return send_addba_60g(dut, conn, cmd, "sta_mac_address");
1749#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001750 case DRIVER_OPENWRT:
1751 switch (get_openwrt_driver_type()) {
1752 case OPENWRT_DRIVER_ATHEROS:
1753 return ath_ap_send_addba_req(dut, conn, cmd);
1754 default:
1755 send_resp(dut, conn, SIGMA_ERROR,
1756 "errorCode,ap_send_addba_req not supported with this driver");
1757 return 0;
1758 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301759 case DRIVER_WCN:
1760 case DRIVER_LINUX_WCN:
1761 /* AP automatically sends ADDBA request after association. */
1762 sigma_dut_print(dut, DUT_MSG_INFO,
1763 "ap_send_addba_req command ignored");
1764 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301765 case DRIVER_MAC80211:
1766 if (stat("/sys/module/ath10k_core", &s) == 0)
1767 return ath10k_ap_send_addba_req(dut, cmd);
1768 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001769 default:
1770 send_resp(dut, conn, SIGMA_ERROR,
1771 "errorCode,ap_send_addba_req not supported with this driver");
1772 return 0;
1773 }
1774}
1775
1776
Jouni Malinenf7222712019-06-13 01:50:21 +03001777static enum sigma_cmd_result cmd_ap_set_security(struct sigma_dut *dut,
1778 struct sigma_conn *conn,
1779 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001780{
1781 /* const char *name = get_param(cmd, "NAME"); */
1782 const char *val;
1783 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301784 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001785
1786 val = get_param(cmd, "WLAN_TAG");
1787 if (val)
1788 wlan_tag = atoi(val);
1789
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301790 security = get_param(cmd, "Security");
1791
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001792 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001793 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301794 if (!val)
1795 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001796 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001797 if (strcasecmp(val, "NONE") == 0) {
1798 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1799 } else if (strcasecmp(val, "OSEN") == 0 &&
1800 wlan_tag == 2) {
1801 /*
1802 * OSEN only supported on WLAN_TAG = 2 for now
1803 */
1804 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301805 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1806 (security &&
1807 strcasecmp(security, "PSK") == 0 &&
1808 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001809 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1810 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02001811 } else if (strcasecmp(val, "OWE") == 0 &&
1812 wlan_tag == 2) {
1813 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1814 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001815 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001816 send_resp(dut, conn, SIGMA_INVALID,
1817 "errorCode,Unsupported KEYMGNT");
1818 return 0;
1819 }
1820 return 1;
1821 }
1822 }
1823
1824 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301825 if (!val)
1826 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001827 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301828 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1829 (security && strcasecmp(security, "PSK") == 0 &&
1830 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001831 dut->ap_key_mgmt = AP_WPA2_PSK;
1832 dut->ap_cipher = AP_CCMP;
1833 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1834 strcasecmp(val, "WPA2-Ent") == 0) {
1835 dut->ap_key_mgmt = AP_WPA2_EAP;
1836 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001837 } else if (strcasecmp(val, "SuiteB") == 0) {
1838 dut->ap_key_mgmt = AP_SUITEB;
1839 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02001840 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001841 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1842 dut->ap_key_mgmt = AP_WPA_PSK;
1843 dut->ap_cipher = AP_TKIP;
1844 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1845 strcasecmp(val, "WPA-Ent") == 0) {
1846 dut->ap_key_mgmt = AP_WPA_EAP;
1847 dut->ap_cipher = AP_TKIP;
1848 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1849 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1850 dut->ap_cipher = AP_CCMP_TKIP;
1851 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1852 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1853 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02001854 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
1855 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03001856 dut->ap_key_mgmt = AP_WPA2_SAE;
1857 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001858 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03001859 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1860 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1861 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001862 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001863 } else if (strcasecmp(val, "OWE") == 0) {
1864 dut->ap_key_mgmt = AP_WPA2_OWE;
1865 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001866 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03001867 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
1868 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
1869 dut->ap_cipher = AP_CCMP;
1870 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03001871 } else if (strcasecmp(val, "OSEN") == 0) {
1872 dut->ap_key_mgmt = AP_OSEN;
1873 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03001874 } else if (strcasecmp(val, "FT-EAP") == 0) {
1875 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
1876 dut->ap_cipher = AP_CCMP;
1877 dut->ap_pmf = AP_PMF_OPTIONAL;
1878 } else if (strcasecmp(val, "FT-PSK") == 0) {
1879 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
1880 dut->ap_cipher = AP_CCMP;
1881 dut->ap_pmf = AP_PMF_OPTIONAL;
1882 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
1883 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
1884 dut->ap_cipher = AP_CCMP;
1885 dut->ap_pmf = AP_PMF_OPTIONAL;
1886 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
1887 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
1888 dut->ap_cipher = AP_CCMP;
1889 dut->ap_pmf = AP_PMF_OPTIONAL;
1890 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
1891 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
1892 dut->ap_cipher = AP_CCMP;
1893 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001894 } else if (strcasecmp(val, "NONE") == 0) {
1895 dut->ap_key_mgmt = AP_OPEN;
1896 dut->ap_cipher = AP_PLAIN;
1897 } else {
1898 send_resp(dut, conn, SIGMA_INVALID,
1899 "errorCode,Unsupported KEYMGNT");
1900 return 0;
1901 }
1902 }
1903
Jouni Malinen30824df2017-08-22 21:21:38 +03001904 val = get_param(cmd, "ECGroupID");
1905 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001906 free(dut->ap_sae_groups);
1907 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001908 }
1909
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001910 val = get_param(cmd, "AntiCloggingThreshold");
1911 if (val)
1912 dut->sae_anti_clogging_threshold = atoi(val);
1913
Jouni Malinenb347db02017-09-02 01:36:03 +03001914 val = get_param(cmd, "Reflection");
1915 if (val)
1916 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1917
Jouni Malinen68143132017-09-02 02:34:08 +03001918 val = get_param(cmd, "InvalidSAEElement");
1919 if (val) {
1920 free(dut->sae_commit_override);
1921 dut->sae_commit_override = strdup(val);
1922 }
1923
Jouni Malinen09550de2019-03-26 00:24:11 +02001924 val = get_param(cmd, "SAEPasswords");
1925 if (val) {
1926 free(dut->ap_sae_passwords);
1927 dut->ap_sae_passwords = strdup(val);
1928 }
1929
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001930 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301931 if (!val)
1932 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001933 if (val) {
1934 if (strcasecmp(val, "WEP") == 0) {
1935 dut->ap_cipher = AP_WEP;
1936 } else if (strcasecmp(val, "TKIP") == 0) {
1937 dut->ap_cipher = AP_TKIP;
1938 } else if (strcasecmp(val, "AES") == 0 ||
1939 strcasecmp(val, "AES-CCMP") == 0) {
1940 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001941 } else if (strcasecmp(val, "AES-GCMP") == 0) {
1942 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001943 } else {
1944 send_resp(dut, conn, SIGMA_INVALID,
1945 "errorCode,Unsupported ENCRYPT");
1946 return 0;
1947 }
1948 }
1949
Jouni Malinen3d633da2017-09-14 22:19:21 +03001950 val = get_param(cmd, "PairwiseCipher");
1951 if (val) {
1952 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1953 dut->ap_cipher = AP_GCMP_256;
1954 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1955 dut->ap_cipher = AP_CCMP_256;
1956 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1957 dut->ap_cipher = AP_GCMP_128;
1958 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1959 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02001960 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
1961 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
1962 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001963 } else {
1964 send_resp(dut, conn, SIGMA_INVALID,
1965 "errorCode,Unsupported PairwiseCipher");
1966 return 0;
1967 }
1968 }
1969
Jouni Malinen2ba24492017-11-17 12:43:59 +02001970 val = get_param(cmd, "GroupCipher");
1971 if (val) {
1972 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1973 dut->ap_group_cipher = AP_GCMP_256;
1974 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1975 dut->ap_group_cipher = AP_CCMP_256;
1976 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1977 dut->ap_group_cipher = AP_GCMP_128;
1978 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1979 dut->ap_group_cipher = AP_CCMP;
1980 } else {
1981 send_resp(dut, conn, SIGMA_INVALID,
1982 "errorCode,Unsupported GroupCipher");
1983 return 0;
1984 }
1985 }
1986
Jouni Malinen3d633da2017-09-14 22:19:21 +03001987 val = get_param(cmd, "GroupMgntCipher");
1988 if (val) {
1989 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1990 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
1991 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1992 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
1993 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1994 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
1995 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1996 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
1997 } else {
1998 send_resp(dut, conn, SIGMA_INVALID,
1999 "errorCode,Unsupported GroupMgntCipher");
2000 return 0;
2001 }
2002 }
2003
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002004 val = get_param(cmd, "WEPKEY");
2005 if (val) {
2006 size_t len;
2007 if (dut->ap_cipher != AP_WEP) {
2008 send_resp(dut, conn, SIGMA_INVALID,
2009 "errorCode,Unexpected WEPKEY without WEP "
2010 "configuration");
2011 return 0;
2012 }
2013 len = strlen(val);
2014 if (len != 10 && len != 26) {
2015 send_resp(dut, conn, SIGMA_INVALID,
2016 "errorCode,Unexpected WEPKEY length");
2017 return 0;
2018 }
2019 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
2020 }
2021
2022 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302023 if (!val)
2024 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002025 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002026 if (dut->ap_key_mgmt != AP_WPA2_SAE &&
2027 (dut->ap_akm_values & (AKM_WPA_PSK | AKM_SAE)) !=
2028 AKM_SAE &&
2029 strlen(val) > 64) {
2030 sigma_dut_print(dut, DUT_MSG_ERROR,
2031 "Too long PSK/passphtase");
Jouni Malinen2126f422017-10-11 23:24:33 +03002032 return -1;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002033 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002034 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
2035 return -1;
2036 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
2037 "%s", val);
2038 }
2039
Jouni Malinen63370622017-11-18 17:47:13 +02002040 val = get_param(cmd, "PSKHEX");
2041 if (val) {
2042 if (strlen(val) != 64)
2043 return -1;
2044 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
2045 }
2046
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302047 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
2048 dut->ap_pmf = AP_PMF_OPTIONAL;
2049
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002050 val = get_param(cmd, "PMF");
2051 if (val) {
2052 if (strcasecmp(val, "Disabled") == 0) {
2053 dut->ap_pmf = AP_PMF_DISABLED;
2054 } else if (strcasecmp(val, "Optional") == 0) {
2055 dut->ap_pmf = AP_PMF_OPTIONAL;
2056 } else if (strcasecmp(val, "Required") == 0) {
2057 dut->ap_pmf = AP_PMF_REQUIRED;
2058 } else {
2059 send_resp(dut, conn, SIGMA_INVALID,
2060 "errorCode,Unsupported PMF");
2061 return 0;
2062 }
2063 }
2064
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065 dut->ap_add_sha256 = 0;
2066 val = get_param(cmd, "SHA256AD");
2067 if (val == NULL)
2068 val = get_param(cmd, "SHA256");
2069 if (val) {
2070 if (strcasecmp(val, "Disabled") == 0) {
2071 } else if (strcasecmp(val, "Enabled") == 0) {
2072 dut->ap_add_sha256 = 1;
2073 } else {
2074 send_resp(dut, conn, SIGMA_INVALID,
Jouni Malinena7fa6202019-03-26 00:22:10 +02002075 "errorCode,Unsupported SHA256");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002076 return 0;
2077 }
2078 }
2079
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302080 val = get_param(cmd, "PreAuthentication");
2081 if (val) {
2082 if (strcasecmp(val, "disabled") == 0) {
2083 dut->ap_rsn_preauth = 0;
2084 } else if (strcasecmp(val, "enabled") == 0) {
2085 dut->ap_rsn_preauth = 1;
2086 } else {
2087 send_resp(dut, conn, SIGMA_INVALID,
2088 "errorCode,Unsupported PreAuthentication value");
2089 return 0;
2090 }
2091 }
2092
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002093 val = get_param(cmd, "AKMSuiteType");
2094 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002095 const char *in_pos = val;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002096
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002097 dut->ap_akm_values = 0;
2098 while (*in_pos) {
2099 int akm = atoi(in_pos);
2100
2101 if (akm < 0 || akm >= 32) {
2102 send_resp(dut, conn, SIGMA_ERROR,
2103 "errorCode,Unsupported AKMSuiteType value");
2104 return STATUS_SENT;
2105 }
2106
2107 dut->ap_akm_values |= 1 << akm;
2108
2109 in_pos = strchr(in_pos, ';');
2110 if (!in_pos)
2111 break;
2112 while (*in_pos == ';')
2113 in_pos++;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002114 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002115 dut->ap_akm = 1;
2116 if (dut->ap_akm_values & (1 << 14))
2117 dut->ap_add_sha384 = 1;
2118 if (dut->ap_akm_values & (1 << 15))
2119 dut->ap_add_sha384 = 1;
2120 }
2121
2122 if (dut->ap_key_mgmt == AP_OPEN && !dut->ap_akm_values) {
2123 dut->ap_hs2 = 0;
2124 dut->ap_pmf = AP_PMF_DISABLED;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002125 }
2126
2127 val = get_param(cmd, "PMKSACaching");
2128 if (val) {
2129 dut->ap_pmksa = 1;
2130 if (strcasecmp(val, "disabled") == 0) {
2131 dut->ap_pmksa_caching = 1;
2132 } else if (strcasecmp(val, "enabled") == 0) {
2133 dut->ap_pmksa_caching = 0;
2134 } else {
2135 send_resp(dut, conn, SIGMA_INVALID,
2136 "errorCode,Unsupported PMKSACaching value");
2137 return 0;
2138 }
2139 }
2140
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002141 return 1;
2142}
2143
2144
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302145int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2146 struct sigma_cmd *cmd)
2147{
2148 int status;
2149
2150 status = cmd_ap_set_wireless(dut, conn, cmd);
2151 if (status != 1)
2152 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302153 status = cmd_ap_set_security(dut, conn, cmd);
2154 if (status != 1)
2155 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302156 return cmd_ap_config_commit(dut, conn, cmd);
2157}
2158
2159
Jouni Malinenf7222712019-06-13 01:50:21 +03002160static enum sigma_cmd_result cmd_ap_set_radius(struct sigma_dut *dut,
2161 struct sigma_conn *conn,
2162 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002163{
2164 /* const char *name = get_param(cmd, "NAME"); */
2165 const char *val;
2166 unsigned int wlan_tag = 1, radius_port = 0;
2167 char *radius_ipaddr = NULL, *radius_password = NULL;
2168
2169 val = get_param(cmd, "WLAN_TAG");
2170 if (val) {
2171 wlan_tag = atoi(val);
2172 if (wlan_tag != 1 && wlan_tag != 2) {
2173 send_resp(dut, conn, SIGMA_INVALID,
2174 "errorCode,Invalid WLAN_TAG");
2175 return 0;
2176 }
2177 }
2178
2179 val = get_param(cmd, "PORT");
2180 if (val)
2181 radius_port = atoi(val);
2182
2183 if (wlan_tag == 1) {
2184 if (radius_port)
2185 dut->ap_radius_port = radius_port;
2186 radius_ipaddr = dut->ap_radius_ipaddr;
2187 radius_password = dut->ap_radius_password;
2188 } else if (wlan_tag == 2) {
2189 if (radius_port)
2190 dut->ap2_radius_port = radius_port;
2191 radius_ipaddr = dut->ap2_radius_ipaddr;
2192 radius_password = dut->ap2_radius_password;
2193 }
2194
2195 val = get_param(cmd, "IPADDR");
2196 if (val) {
2197 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2198 return -1;
2199 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2200 "%s", val);
2201 }
2202
2203 val = get_param(cmd, "PASSWORD");
2204 if (val) {
2205 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2206 return -1;
2207 snprintf(radius_password,
2208 sizeof(dut->ap_radius_password), "%s", val);
2209 }
2210
2211 return 1;
2212}
2213
2214
2215static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2216 const char *key, const char *val)
2217{
2218 char buf[100];
2219
2220 if (val == NULL) {
2221 snprintf(buf, sizeof(buf),
2222 "uci delete wireless.wifi%d.%s", id, key);
2223 run_system(dut, buf);
2224 return;
2225 }
2226
2227 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2228 id, key, val);
2229 run_system(dut, buf);
2230}
2231
2232
2233static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2234 const char *key, const char *val)
2235{
2236 char buf[256];
2237
2238 if (val == NULL) {
2239 snprintf(buf, sizeof(buf),
2240 "uci del_list wireless.wifi%d.%s", id, key);
2241 run_system(dut, buf);
2242 return;
2243 }
2244
2245 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2246 id, key, val);
2247 run_system(dut, buf);
2248}
2249
2250
2251static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2252 const char *val)
2253{
2254 char buf[256];
2255
2256 if (val == NULL) {
2257 snprintf(buf, sizeof(buf),
2258 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2259 run_system(dut, buf);
2260 return;
2261 }
2262
2263 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2264 id, key, val);
2265 run_system(dut, buf);
2266}
2267
2268
2269static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2270 const char *key, const char *val)
2271{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002272 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002273
2274 if (val == NULL) {
2275 snprintf(buf, sizeof(buf),
2276 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2277 run_system(dut, buf);
2278 return;
2279 }
2280
2281 snprintf(buf, sizeof(buf),
2282 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2283 id, key, val);
2284 run_system(dut, buf);
2285}
2286
2287
2288static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2289 const char *val)
2290{
2291 char buf[256];
Jouni Malinen3aa72862019-05-29 23:14:51 +03002292 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002293
2294 if (val == NULL) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002295 res = snprintf(buf, sizeof(buf),
2296 "uci delete wireless.@wifi-iface[%d].%s",
2297 id, key);
2298 if (res >= 0 && res < sizeof(buf))
2299 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002300 return;
2301 }
2302
Jouni Malinen3aa72862019-05-29 23:14:51 +03002303 run_system(dut, "uci add wireless wifi-iface");
2304 res = snprintf(buf, sizeof(buf),
2305 "uci set wireless.@wifi-iface[%d].%s=%s",
2306 id, key, val);
2307 if (res >= 0 && res < sizeof(buf))
2308 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002309 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2310 id, "network", "lan");
2311 run_system(dut, buf);
2312 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2313 id, "mode", "ap");
2314 run_system(dut, buf);
2315 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2316 id, "encryption", "none");
2317 run_system(dut, buf);
2318}
2319
2320
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002321#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002322static void owrt_ap_config_radio(struct sigma_dut *dut)
2323{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002324 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002325 int radio_count, radio_no;
2326 char buf[64];
2327
2328 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2329 radio_count++) {
2330 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2331 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2332 if (!sigma_radio_ifname[radio_no] ||
2333 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2334 continue;
2335 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2336 owrt_ap_set_vap(dut, radio_count, "device", buf);
2337 radio_id[radio_no] = radio_count;
2338 }
2339 }
2340
2341 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2342 switch (dut->ap_mode) {
2343 case AP_11g:
2344 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2345 break;
2346 case AP_11b:
2347 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2348 break;
2349 case AP_11ng:
2350 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2351 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2352 break;
2353 case AP_11a:
2354 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2355 break;
2356 case AP_11na:
2357 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2358 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2359 break;
2360 case AP_11ac:
2361 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2362 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2363 break;
2364 case AP_inval:
2365 sigma_dut_print(dut, DUT_MSG_ERROR,
2366 "MODE NOT SPECIFIED!");
2367 return;
2368 default:
2369 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2370 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2371 break;
2372 }
2373
2374 if (dut->ap_is_dual) {
2375 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2376 switch (dut->ap_mode_1) {
2377 case AP_11g:
2378 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2379 break;
2380 case AP_11b:
2381 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2382 break;
2383 case AP_11ng:
2384 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2385 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2386 break;
2387 case AP_11a:
2388 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2389 break;
2390 case AP_11na:
2391 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2392 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2393 break;
2394 case AP_11ac:
2395 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2396 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2397 break;
2398 case AP_inval:
2399 sigma_dut_print(dut, DUT_MSG_ERROR,
2400 "MODE NOT SPECIFIED!");
2401 return;
2402 default:
2403 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2404 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2405 break;
2406 }
2407
2408 }
2409
2410 /* Channel */
2411 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2412 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2413
2414 switch (dut->ap_chwidth) {
2415 case AP_20:
2416 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2417 break;
2418 case AP_40:
2419 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2420 break;
2421 case AP_80:
2422 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2423 break;
2424 case AP_160:
2425 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2426 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002427 case AP_80_80:
2428 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2429 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002430 case AP_AUTO:
2431 default:
2432 break;
2433 }
2434
2435 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2436 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2437 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2438 }
2439
2440 if (dut->ap_is_dual) {
2441 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2442 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2443 }
2444
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002445 /* Country Code */
2446 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2447 const char *country;
2448
2449 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2450 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002451 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002452 if (dut->ap_is_dual)
2453 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002454 } else if (dut->ap_countrycode[0]) {
2455 owrt_ap_set_radio(dut, radio_id[0], "country",
2456 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002457 }
2458
2459 if (dut->ap_disable_protection == 1) {
2460 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2461 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2462 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2463 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2464 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002465
2466 if (dut->ap_oce == VALUE_ENABLED &&
2467 get_driver_type() == DRIVER_OPENWRT)
2468 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002469}
2470
2471
2472static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2473{
2474 char buf[256];
2475
2476 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2477 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2478 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2479 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2480
2481 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2482 "'eng:Wi-Fi Alliance'");
2483
2484 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2485 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2486
2487 if (dut->ap_wan_metrics == 1)
2488 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2489 "'01:2500:384:0:0:10'");
2490 else if (dut->ap_wan_metrics == 1)
2491 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2492 "'01:1500:384:20:20:10'");
2493 else if (dut->ap_wan_metrics == 2)
2494 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2495 "'01:1500:384:20:20:10'");
2496 else if (dut->ap_wan_metrics == 3)
2497 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2498 "'01:2000:1000:20:20:10'");
2499 else if (dut->ap_wan_metrics == 4)
2500 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2501 "'01:8000:1000:20:20:10'");
2502 else if (dut->ap_wan_metrics == 5)
2503 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2504 "'01:9000:5000:20:20:10'");
2505
2506 if (dut->ap_conn_capab == 1) {
2507 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2508 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2509 "'6:20:1'");
2510 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2511 "'6:22:0'");
2512 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2513 "'6:80:1'");
2514 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2515 "'6:443:1'");
2516 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2517 "'6:1723:0'");
2518 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2519 "'6:5060:0'");
2520 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2521 "'17:500:1'");
2522 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2523 "'17:5060:0'");
2524 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2525 "'17:4500:1'");
2526 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2527 "'50:0:1'");
2528 } else if (dut->ap_conn_capab == 2) {
2529 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2530 "'6:80:1'");
2531 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2532 "'6:443:1'");
2533 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2534 "'17:5060:1'");
2535 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2536 "'6:5060:1'");
2537 } else if (dut->ap_conn_capab == 3) {
2538 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2539 "'6:80:1'");
2540 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2541 "'6:443:1'");
2542 }
2543
2544 if (dut->ap_oper_class == 1)
2545 snprintf(buf, sizeof(buf), "%s", "51");
2546 else if (dut->ap_oper_class == 2)
2547 snprintf(buf, sizeof(buf), "%s", "73");
2548 else if (dut->ap_oper_class == 3)
2549 snprintf(buf, sizeof(buf), "%s", "5173");
2550
2551 if (dut->ap_oper_class)
2552 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2553
2554 if (dut->ap_osu_provider_list) {
2555 char *osu_friendly_name = NULL;
2556 char *osu_icon = NULL;
2557 char *osu_ssid = NULL;
2558 char *osu_nai = NULL;
2559 char *osu_service_desc = NULL;
2560 char *hs20_icon_filename = NULL;
2561 char hs20_icon[150];
2562 int osu_method;
2563
2564 hs20_icon_filename = "icon_red_zxx.png";
2565 if (dut->ap_osu_icon_tag == 2)
2566 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2567 snprintf(hs20_icon, sizeof(hs20_icon),
2568 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2569 hs20_icon_filename);
2570 osu_icon = "icon_red_zxx.png";
2571 osu_ssid = "OSU";
2572 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2573 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2574 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2575 dut->ap_osu_method[0];
2576
2577 if (strlen(dut->ap_osu_server_uri[0]))
2578 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2579 dut->ap_osu_server_uri[0]);
2580 else
2581 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2582 "'https://osu-server.r2-testbed.wi-fi.org/'");
2583 switch (dut->ap_osu_provider_list) {
2584 case 1:
2585 case 101:
2586 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2587 "'eng:SP Red Test Only'");
2588 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2589 "'eng:Free service for test purpose'");
2590 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2591 hs20_icon);
2592
2593 hs20_icon_filename = "icon_red_eng.png";
2594 if (dut->ap_osu_icon_tag == 2)
2595 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2596
2597 snprintf(hs20_icon, sizeof(hs20_icon),
2598 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2599 hs20_icon_filename);
2600 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2601 "icon_red_eng.png");
2602 break;
2603 case 2:
2604 case 102:
2605 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2606 "'eng:Wireless Broadband Alliance'");
2607 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2608 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002609 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 if (dut->ap_osu_icon_tag == 2)
2611 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2612
2613 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002614 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002615 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002616 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002617 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2618 break;
2619 case 3:
2620 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03002621 osu_friendly_name = "'spa:SP Red Test Only'";
2622 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002623 break;
2624 case 4:
2625 case 104:
2626 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002627 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002628 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2629 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002630 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002631 if (dut->ap_osu_icon_tag == 2)
2632 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2633
2634 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002635 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002636 hs20_icon_filename);
2637 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2638 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002639 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002640
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002641 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002642 if (dut->ap_osu_icon_tag == 2)
2643 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2644
2645 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002646 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002647 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002648 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002649 break;
2650 case 5:
2651 case 105:
2652 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002653 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002654 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2655 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002656 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002657
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002658 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002659 if (dut->ap_osu_icon_tag == 2)
2660 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2661
2662 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002663 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002664 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002665 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002666 break;
2667 case 6:
2668 case 106:
2669 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2670 "'eng:SP Green Test Only'");
2671 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2672 "'kor:SP 초록 테스트 전용'");
2673
2674 hs20_icon_filename = "icon_green_zxx.png";
2675 if (dut->ap_osu_icon_tag == 2)
2676 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2677
2678 snprintf(hs20_icon, sizeof(hs20_icon),
2679 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2680 hs20_icon_filename);
2681 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2682 hs20_icon);
2683
2684 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2685 "'icon_green_zxx.png'");
2686 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2687 dut->ap_osu_method[0];
2688
2689 snprintf(buf, sizeof(buf), "%d", osu_method);
2690 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2691
2692 if (strlen(dut->ap_osu_server_uri[1]))
2693 owrt_ap_set_list_vap(dut, vap_id,
2694 "osu_server_uri",
2695 dut->ap_osu_server_uri[1]);
2696 else
2697 owrt_ap_set_list_vap(dut, vap_id,
2698 "osu_server_uri",
2699 "'https://osu-server.r2-testbed.wi-fi.org/'");
2700
2701 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2702 "'eng:SP Orange Test Only'");
2703
2704 hs20_icon_filename = "icon_orange_zxx.png";
2705 if (dut->ap_osu_icon_tag == 2)
2706 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2707
2708 snprintf(hs20_icon, sizeof(hs20_icon),
2709 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2710 hs20_icon_filename);
2711
2712 osu_icon = "icon_orange_zxx.png";
2713 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2714 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2715 dut->ap_osu_method[1];
2716 osu_service_desc = NULL;
2717 break;
2718 case 7:
2719 case 107:
2720 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002721 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2723 "'eng:Free service for test purpose'");
2724
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002725 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 if (dut->ap_osu_icon_tag == 2)
2727 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2728
2729 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002730 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002731 hs20_icon_filename);
2732 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2733 hs20_icon);
2734
2735 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002736 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002737 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002738
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002739 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002740 if (dut->ap_osu_icon_tag == 2)
2741 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2742
2743 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002744 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002745 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002746 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002747 break;
2748 case 8:
2749 case 108:
2750 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2751 "'eng:SP Red Test Only'");
2752 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2753 "'eng:Free service for test purpose'");
2754 osu_ssid = "OSU-Encrypted";
2755 osu_nai = "'anonymous@hotspot.net'";
2756 break;
2757 case 9:
2758 case 109:
2759 osu_ssid = "OSU-OSEN";
2760 osu_nai = "'test-anonymous@wi-fi.org'";
2761 osu_friendly_name = "'eng:SP Orange Test Only'";
2762 hs20_icon_filename = "icon_orange_zxx.png";
2763 if (dut->ap_osu_icon_tag == 2)
2764 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2765
2766 snprintf(hs20_icon, sizeof(hs20_icon),
2767 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2768 hs20_icon_filename);
2769 osu_icon = "icon_orange_zxx.png";
2770 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2771 dut->ap_osu_method[0];
2772 osu_service_desc = NULL;
2773 break;
2774 default:
2775 break;
2776 }
2777
2778 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03002779 if (dut->ap_tag_ssid[0][0] &&
2780 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002781 dut->ap_osu_ssid) != 0 &&
2782 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002783 sigma_dut_print(dut, DUT_MSG_ERROR,
2784 "OSU_SSID and WLAN_TAG2 SSID differ");
2785 return -2;
2786 }
2787
2788 snprintf(buf, sizeof(buf), "'\"%s\"'",
2789 dut->ap_osu_ssid);
2790 } else {
2791 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2792 }
2793
2794 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2795
2796
2797 if (osu_friendly_name)
2798 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2799 osu_friendly_name);
2800 if (osu_service_desc)
2801 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2802 osu_service_desc);
2803 if (osu_nai)
2804 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2805
2806 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2807
2808 if (osu_icon)
2809 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2810 osu_icon);
2811
2812 if (dut->ap_osu_provider_list > 100) {
2813 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2814 "0");
2815 } else {
2816 snprintf(buf, sizeof(buf), "%d", osu_method);
2817 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2818 buf);
2819 }
2820 }
2821
2822 return 0;
2823}
2824
2825
Jouni Malinen13701222019-02-19 12:10:53 +02002826static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2827 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002828{
2829 unsigned char bssid[ETH_ALEN];
2830 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2831 int preference = 0xff;
2832
Jouni Malinen13701222019-02-19 12:10:53 +02002833 if (get_hwaddr(ifname, bssid) < 0)
2834 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002835 snprintf(anqp_string, str_size,
2836 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2837 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2838 preference,
2839 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2840 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2841 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02002842 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002843}
2844
2845
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002846static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2847 size_t str_size, int wlan_tag)
2848{
Jouni Malinenf8984642017-10-12 00:02:37 +03002849 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002850 enum driver_type drv;
2851
2852 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002853 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2854 ifname = dut->hostapd_ifname;
2855 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002856 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2857 dut->ap_mode == AP_11ac) &&
2858 if_nametoindex("ath1") > 0)
2859 ifname = "ath1";
2860 else
2861 ifname = "ath0";
2862 } else if (drv == DRIVER_OPENWRT) {
2863 if (sigma_radio_ifname[0] &&
2864 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2865 ifname = "ath2";
2866 else if (sigma_radio_ifname[0] &&
2867 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2868 ifname = "ath1";
2869 else
2870 ifname = "ath0";
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02002871 } else if (drv == DRIVER_WIL6210) {
2872 ifname = get_main_ifname();
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002873 } else {
2874 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2875 dut->ap_mode == AP_11ac) &&
2876 if_nametoindex("wlan1") > 0)
2877 ifname = "wlan1";
2878 else
2879 ifname = "wlan0";
2880 }
2881
2882 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2883 /* Handle tagged-ifname only on OPENWRT for now */
2884 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08002885 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
2886 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03002887 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002888 } else {
2889 snprintf(ifname_str, str_size, "%s", ifname);
2890 }
2891}
2892
2893
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894static int owrt_ap_config_vap(struct sigma_dut *dut)
2895{
2896 char buf[256], *temp;
Jouni Malinen3aa72862019-05-29 23:14:51 +03002897 int vap_id = 0, vap_count, i, j, res;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002898 const char *ifname;
2899 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002900
priyadharshini gowthaman73561262018-02-20 13:24:59 -08002901 if (sigma_radio_ifname[0] &&
2902 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2903 ifname = "ath2";
2904 else if (sigma_radio_ifname[0] &&
2905 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2906 ifname = "ath1";
2907 else
2908 ifname = "ath0";
2909
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002910 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002911 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002912
2913 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2914 if (sigma_radio_ifname[vap_id] &&
2915 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2916 break;
2917 }
2918 if (vap_id == MAX_RADIO)
2919 continue;
2920
2921 /* Single VAP configuration */
2922 if (!dut->ap_is_dual)
2923 vap_id = vap_count;
2924
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002925 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2926 /*
2927 * We keep a separate array of ap_tag_ssid and
2928 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2929 * So j=0 => WLAN_TAG = 2
2930 */
2931 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002933 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
2934 (dut->ap_interface_5g || dut->ap_interface_2g)) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002935 res = snprintf(
2936 dut->ap_tag_ssid[wlan_tag - 2],
2937 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
2938 "%s-owe", dut->ap_ssid);
2939 if (res < 0 ||
2940 res >= sizeof(dut->ap_tag_ssid[wlan_tag -
2941 2]))
2942 dut->ap_tag_ssid[wlan_tag - 2][0] =
2943 '\0';
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002944 }
2945
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002946 if (dut->ap_tag_ssid[j][0] == '\0')
2947 continue;
2948
2949 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2950 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2951 "device", buf);
2952 /* SSID */
2953 snprintf(buf, sizeof(buf), "\"%s\"",
2954 dut->ap_tag_ssid[j]);
2955 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2956 "ssid", buf);
2957
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002958 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
2959 dut->ap_tag_ssid[0][0] &&
2960 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
2961 /* OWE transition mode */
2962 snprintf(buf, sizeof(buf), "%s", ifname);
2963 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2964 "owe_transition_ifname", buf);
2965 }
2966
2967 if (dut->ap_key_mgmt == AP_OPEN &&
2968 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
2969 /* OWE transition mode */
2970 snprintf(buf, sizeof(buf), "%s", ifname);
2971 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2972 "owe_transition_ifname", buf);
2973 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2974 "hidden", "1");
2975 }
2976
Jouni Malinen6be21c82018-08-01 18:47:24 +03002977 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002978 unsigned char self_mac[ETH_ALEN];
2979 char mac_str[20];
2980
2981 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2982 "mobility_domain",
2983 dut->ap_mobility_domain);
2984 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2985 "ft_over_ds", "0");
2986 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2987 "ieee80211r", "1");
2988 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2989 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02002990 if (get_hwaddr(sigma_radio_ifname[0],
2991 self_mac) < 0)
2992 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08002993 snprintf(mac_str, sizeof(mac_str),
2994 "%02x:%02x:%02x:%02x:%02x:%02x",
2995 self_mac[0], self_mac[1], self_mac[2],
2996 self_mac[3], self_mac[4], self_mac[5]);
2997 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2998 "ap_macaddr", mac_str);
2999 snprintf(mac_str, sizeof(mac_str),
3000 "%02x%02x%02x%02x%02x%02x",
3001 self_mac[0], self_mac[1], self_mac[2],
3002 self_mac[3], self_mac[4], self_mac[5]);
3003 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3004 "r1_key_holder", mac_str);
3005 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3006 "ft_psk_generate_local", "1");
3007 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3008 "kh_key_hex",
3009 "000102030405060708090a0b0c0d0e0f");
3010 snprintf(mac_str, sizeof(mac_str),
3011 "%02x:%02x:%02x:%02x:%02x:%02x",
3012 dut->ft_bss_mac_list[0][0],
3013 dut->ft_bss_mac_list[0][1],
3014 dut->ft_bss_mac_list[0][2],
3015 dut->ft_bss_mac_list[0][3],
3016 dut->ft_bss_mac_list[0][4],
3017 dut->ft_bss_mac_list[0][5]);
3018 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3019 "ap2_macaddr", mac_str);
3020 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3021 "ap2_r1_key_holder", mac_str);
3022 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3023 "nasid2", "nas2.example.com");
3024 }
3025
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003026 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
3027 wlan_tag == 2) {
3028 /* Only supported for WLAN_TAG=2 */
3029 owrt_ap_set_vap(dut, vap_count + 1, "osen",
3030 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003031 snprintf(buf, sizeof(buf), "wpa2");
3032 owrt_ap_set_vap(dut, vap_count + 1,
3033 "encryption", buf);
3034 snprintf(buf, sizeof(buf), "%s",
3035 dut->ap2_radius_ipaddr);
3036 owrt_ap_set_vap(dut, vap_count + 1,
3037 "auth_server", buf);
3038 snprintf(buf, sizeof(buf), "%d",
3039 dut->ap2_radius_port);
3040 owrt_ap_set_vap(dut, vap_count + 1,
3041 "auth_port", buf);
3042 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003043 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003044 owrt_ap_set_vap(dut, vap_count + 1,
3045 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003046 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
3047 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3048 "encryption", "psk2+ccmp");
3049 snprintf(buf, sizeof(buf), "\"%s\"",
3050 dut->ap_passphrase);
3051 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3052 "key", buf);
3053 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003054 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003055 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003056 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3057 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3058 "owe", "1");
3059 snprintf(buf, sizeof(buf), "ccmp");
3060 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3061 "encryption", buf);
3062 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3063 "ieee80211w", "2");
3064 if (dut->ap_sae_groups) {
3065 snprintf(buf, sizeof(buf), "\'%s\'",
3066 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003067 owrt_ap_set_list_vap(dut, vap_count +
3068 (wlan_tag - 1),
3069 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003070 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003071 }
3072 }
3073
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003074 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003075 if (dut->program == PROGRAM_MBO &&
3076 get_driver_type() == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003077 unsigned char self_mac[ETH_ALEN];
3078 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003079 char anqp_string[200];
3080
Jouni Malinen13701222019-02-19 12:10:53 +02003081 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3082 anqp_string,
3083 sizeof(anqp_string)) < 0)
3084 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003085 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3086 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003087
Jouni Malinen6be21c82018-08-01 18:47:24 +03003088 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003089 owrt_ap_set_vap(dut, vap_count,
3090 "mobility_domain",
3091 dut->ap_mobility_domain);
3092 owrt_ap_set_vap(dut, vap_count,
3093 "ft_over_ds", "0");
3094 owrt_ap_set_vap(dut, vap_count,
3095 "ieee80211r", "1");
3096 owrt_ap_set_vap(dut, vap_count,
3097 "nasid", "nas1.example.com");
3098 get_hwaddr(sigma_radio_ifname[0], self_mac);
3099 snprintf(mac_str, sizeof(mac_str),
3100 "%02x:%02x:%02x:%02x:%02x:%02x",
3101 self_mac[0], self_mac[1], self_mac[2],
3102 self_mac[3], self_mac[4], self_mac[5]);
3103 owrt_ap_set_vap(dut, vap_count,
3104 "ap_macaddr", mac_str);
3105 snprintf(mac_str, sizeof(mac_str),
3106 "%02x%02x%02x%02x%02x%02x",
3107 self_mac[0], self_mac[1], self_mac[2],
3108 self_mac[3], self_mac[4], self_mac[5]);
3109 owrt_ap_set_vap(dut, vap_count,
3110 "r1_key_holder", mac_str);
3111 owrt_ap_set_vap(dut, vap_count,
3112 "ft_psk_generate_local", "1");
3113 owrt_ap_set_vap(dut, vap_count,
3114 "kh_key_hex",
3115 "000102030405060708090a0b0c0d0e0f");
3116 snprintf(mac_str, sizeof(mac_str),
3117 "%02x:%02x:%02x:%02x:%02x:%02x",
3118 dut->ft_bss_mac_list[0][0],
3119 dut->ft_bss_mac_list[0][1],
3120 dut->ft_bss_mac_list[0][2],
3121 dut->ft_bss_mac_list[0][3],
3122 dut->ft_bss_mac_list[0][4],
3123 dut->ft_bss_mac_list[0][5]);
3124 owrt_ap_set_vap(dut, vap_count,
3125 "ap2_macaddr", mac_str);
3126 owrt_ap_set_vap(dut, vap_count,
3127 "ap2_r1_key_holder", mac_str);
3128 owrt_ap_set_vap(dut, vap_count,
3129 "nasid2", "nas2.example.com");
3130 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003131 }
3132
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003133 if (dut->ap_oce == VALUE_ENABLED &&
3134 get_driver_type() == DRIVER_OPENWRT) {
3135 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3136 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3137 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3138
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003139 if (dut->ap_80plus80 == 1)
3140 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3141
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003142 if (dut->ap_akm == 1) {
3143 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3144 "3600");
3145 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3146 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3147 "1");
3148 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3149 "1234");
3150 owrt_ap_set_vap(dut, vap_id,
3151 "erp_send_reauth_start", "1");
3152 }
3153
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003154 if (dut->ap_filshlp == VALUE_ENABLED) {
3155 struct ifreq ifr;
3156 char *ifname;
3157 int s;
3158 struct sockaddr_in *ipaddr;
3159
3160 s = socket(AF_INET, SOCK_DGRAM, 0);
3161 if (s < 0) {
3162 sigma_dut_print(dut, DUT_MSG_ERROR,
3163 "Failed to open socket");
3164 return -1;
3165 }
3166 ifr.ifr_addr.sa_family = AF_INET;
3167
3168 memset(&ifr, 0, sizeof(ifr));
3169 ifname = "br-lan";
3170 strlcpy(ifr.ifr_name, ifname,
3171 sizeof(ifr.ifr_name));
3172 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3173 perror("ioctl");
3174 close(s);
3175 return -1;
3176 }
3177
3178 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3179 snprintf(buf, sizeof(buf), "%s",
3180 inet_ntoa(ipaddr->sin_addr));
3181 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3182 buf);
3183 snprintf(buf, sizeof(buf), "%s",
3184 dut->ap_dhcpserv_ipaddr);
3185 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3186 buf);
3187 owrt_ap_set_vap(dut, vap_id,
3188 "dhcp_rapid_commit_proxy", "1");
3189 owrt_ap_set_vap(dut, vap_id,
3190 "fils_hlp_wait_time", "300");
3191 }
3192
3193 if (dut->ap_filsdscv == VALUE_ENABLED) {
3194 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3195 "1");
3196 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3197 "20");
3198 }
3199 }
3200
3201 if (dut->ap_filsdscv == VALUE_DISABLED) {
3202 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3203 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3204 }
3205
3206 if (dut->ap_oce == VALUE_DISABLED &&
3207 get_driver_type() == DRIVER_OPENWRT) {
3208 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3209 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3210 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3211
3212 if (dut->ap_filsdscv == VALUE_DISABLED) {
3213 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3214 "0");
3215 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3216 "0");
3217 }
3218
3219 if (dut->device_type == AP_testbed)
3220 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3221 }
3222
3223 /* NAIRealm */
3224 if (dut->ap_nairealm_int == 1) {
3225 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3226 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3227 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3228 }
3229
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003230 /* SSID */
3231 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3232 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3233
3234 /* Encryption */
3235 switch (dut->ap_key_mgmt) {
3236 case AP_OPEN:
3237 if (dut->ap_cipher == AP_WEP) {
3238 owrt_ap_set_vap(dut, vap_count, "encryption",
3239 "wep-mixed");
3240 owrt_ap_set_vap(dut, vap_count, "key",
3241 dut->ap_wepkey);
3242 } else {
3243 owrt_ap_set_vap(dut, vap_count, "encryption",
3244 "none");
3245 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003246 if (dut->ap_key_mgmt == AP_OPEN &&
3247 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3248 /* OWE transition mode */
3249 snprintf(ifname2, sizeof(ifname2), "%s1",
3250 ifname);
3251 owrt_ap_set_vap(dut, vap_count,
3252 "owe_transition_ifname",
3253 ifname2);
3254 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003255 break;
3256 case AP_WPA2_PSK:
3257 case AP_WPA2_PSK_MIXED:
3258 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003259 case AP_WPA2_SAE:
3260 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003261 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3262 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003263 snprintf(buf, sizeof(buf), "psk2");
3264 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3265 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003266 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3267 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003268 } else {
3269 snprintf(buf, sizeof(buf), "psk");
3270 }
3271
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003272 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3273 if (dut->ap_cipher == AP_CCMP_TKIP)
3274 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3275 else if (dut->ap_cipher == AP_TKIP)
3276 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003277 else if (dut->ap_cipher == AP_GCMP_128)
3278 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003279 else
3280 strlcat(buf, "+ccmp", sizeof(buf));
3281 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003282
3283 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003284
3285 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3286 snprintf(buf, sizeof(buf), "\"%s\"",
3287 dut->ap_psk);
3288 owrt_ap_set_vap(dut, vap_count, "key", buf);
3289 } else {
3290 snprintf(buf, sizeof(buf), "\"%s\"",
3291 dut->ap_passphrase);
3292 owrt_ap_set_vap(dut, vap_count, "key", buf);
3293 }
3294
3295 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3296 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3297 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3298 else
3299 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3300
3301 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3302 snprintf(buf, sizeof(buf), "%s",
3303 dut->ap_passphrase);
3304 owrt_ap_set_vap(dut, vap_count, "sae_password",
3305 buf);
3306 } else {
3307 snprintf(buf, sizeof(buf), "%s",
3308 dut->ap_passphrase);
3309 owrt_ap_set_vap(dut, vap_count,
3310 "wpa_passphrase", buf);
3311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003312 break;
3313 case AP_WPA2_EAP:
3314 case AP_WPA2_EAP_MIXED:
3315 case AP_WPA_EAP:
3316 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3317 snprintf(buf, sizeof(buf), "wpa2");
3318 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3319 snprintf(buf, sizeof(buf), "wpa-mixed");
3320 } else {
3321 snprintf(buf, sizeof(buf), "wpa");
3322 }
3323
Peng Xu591be452017-05-10 17:27:28 -07003324 if (dut->ap_cipher == AP_CCMP_TKIP)
3325 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3326 else if (dut->ap_cipher == AP_TKIP)
3327 strlcat(buf, "+tkip", sizeof(buf));
3328 else
3329 strlcat(buf, "+ccmp", sizeof(buf));
3330
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003331 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3332 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3333 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3334 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3335 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3336 snprintf(buf, sizeof(buf), "%s",
3337 dut->ap_radius_password);
3338 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3339 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003340 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003341 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003342 case AP_WPA2_FT_EAP:
3343 case AP_WPA2_FT_PSK:
3344 case AP_WPA2_EAP_SHA256:
3345 case AP_WPA2_PSK_SHA256:
3346 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003347 /* TODO */
3348 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003349 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003350 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3351 snprintf(buf, sizeof(buf), "gcmp");
3352 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3353 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3354 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3355 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3356 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3357 snprintf(buf, sizeof(buf), "%s",
3358 dut->ap_radius_password);
3359 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3360 snprintf(buf, sizeof(buf), "%d",
3361 dut->ap_group_mgmt_cipher);
3362 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3363 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003364 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003365 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003366 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3367 snprintf(buf, sizeof(buf), "ccmp");
3368 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3369 if (dut->ap_sae_groups) {
3370 snprintf(buf, sizeof(buf), "\'%s\'",
3371 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003372 owrt_ap_set_list_vap(dut, vap_count,
3373 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003374 }
3375
3376 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3377 dut->ap_tag_ssid[0][0] &&
3378 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3379 /* OWE transition mode */
3380 snprintf(ifname2, sizeof(ifname2), "%s1",
3381 ifname);
3382 owrt_ap_set_vap(dut, vap_count,
3383 "owe_transition_ifname",
3384 ifname2);
3385 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3386 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003387 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003388 }
3389
3390 if (!dut->ap_is_dual)
3391 break;
3392 }
3393
3394 if (dut->ap_is_dual)
3395 return 1;
3396
3397 /* PMF */
3398 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3399 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3400
3401 /* Add SHA256 */
3402 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3403 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3404
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003405 /* Add SHA384 for akmsuitetype 15 */
3406 if (dut->ap_akm == 1) {
3407 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3408 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3409 }
3410
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303411 /* Enable RSN preauthentication, if asked to */
3412 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3413 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3414
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003415 /* Hotspot 2.0 */
3416 if (dut->ap_hs2) {
3417 int ret;
3418
3419 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3420 if (ret)
3421 return ret;
3422 }
3423
3424 /* Interworking */
3425 if (dut->ap_interworking) {
3426 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3427 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3428 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3429 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3430 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3431 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3432 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3433 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3434 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3435 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3436
3437 if (dut->ap_gas_cb_delay > 0) {
3438 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3439 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3440 }
3441
3442 if (dut->ap_roaming_cons[0]) {
3443 char *rcons, *temp_ptr;
3444
3445 rcons = strdup(dut->ap_roaming_cons);
3446 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003447 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003448
3449 temp_ptr = strchr(rcons, ';');
3450
3451 if (temp_ptr)
3452 *temp_ptr++ = '\0';
3453
3454 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3455 rcons);
3456
3457 if (temp_ptr)
3458 owrt_ap_set_list_vap(dut, vap_id,
3459 "roaming_consortium",
3460 temp_ptr);
3461
3462 free(rcons);
3463 }
3464 }
3465
3466 if (dut->ap_venue_name) {
3467 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3468 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3469 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3470 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3471 }
3472
3473 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003474 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3475 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003476 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003477 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003478 }
3479
3480 if (dut->ap_nai_realm_list == 1) {
3481 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3482 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3483 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3484 "'0,wi-fi.org;example.com,13[5:6]'");
3485
3486 } else if (dut->ap_nai_realm_list == 2) {
3487 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3488 "'0,wi-fi.org,21[2:4][5:7]'");
3489 } else if (dut->ap_nai_realm_list == 3) {
3490 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3491 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3492 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3493 "'0,wi-fi.org;example.com,13[5:6]'");
3494 } else if (dut->ap_nai_realm_list == 4) {
3495 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3496 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3497 } else if (dut->ap_nai_realm_list == 5) {
3498 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3499 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3500 } else if (dut->ap_nai_realm_list == 6) {
3501 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3502 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3503 } else if (dut->ap_nai_realm_list == 7) {
3504 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3505 "'0,wi-fi.org,13[5:6]'");
3506 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3507 "'0,wi-fi.org,21[2:4][5:7]'");
3508 }
3509
3510 if (dut->ap_domain_name_list[0])
3511 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3512 dut->ap_domain_name_list);
3513
3514 if (dut->ap_ip_addr_type_avail)
3515 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3516 "'0c'");
3517
3518 temp = buf;
3519
3520 *temp++ = '\'';
3521
3522 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3523 if (i)
3524 *temp++ = ';';
3525
3526 snprintf(temp,
3527 sizeof(dut->ap_plmn_mcc[i]) +
3528 sizeof(dut->ap_plmn_mnc[i]) + 1,
3529 "%s,%s",
3530 dut->ap_plmn_mcc[i],
3531 dut->ap_plmn_mnc[i]);
3532
3533 temp += strlen(dut->ap_plmn_mcc[i]) +
3534 strlen(dut->ap_plmn_mnc[i]) + 1;
3535 }
3536
3537 *temp++ = '\'';
3538 *temp++ = '\0';
3539
3540 if (i)
3541 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3542
3543 if (dut->ap_qos_map_set == 1)
3544 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3545 else if (dut->ap_qos_map_set == 2)
3546 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3547
3548 /* Proxy-ARP */
3549 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3550 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3551
3552 /* DGAF */
3553 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3554 /* parse to hostapd */
3555 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3556 /* parse to wifi driver */
3557 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3558
3559 /* HCBSSLoad */
3560 if (dut->ap_bss_load) {
3561 unsigned int bssload = 0;
3562
3563 if (dut->ap_bss_load == 1) {
3564 /* STA count: 1, CU: 50, AAC: 65535 */
3565 bssload = 0x0132ffff;
3566 } else if (dut->ap_bss_load == 2) {
3567 /* STA count: 1, CU: 200, AAC: 65535 */
3568 bssload = 0x01c8ffff;
3569 } else if (dut->ap_bss_load == 3) {
3570 /* STA count: 1, CU: 75, AAC: 65535 */
3571 bssload = 0x014bffff;
3572 }
3573
3574 snprintf(buf, sizeof(buf), "%d", bssload);
3575 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3576 }
3577
3578 /* L2TIF */
3579 if (dut->ap_l2tif)
3580 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3581
3582 if (dut->ap_disable_protection == 1)
3583 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3584
Sunil Dutt77b213d2017-09-14 18:24:40 +03003585 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003586 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3587 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
3588 }
3589
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05303590 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003591 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003592
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303593 if (dut->ap_tx_stbc) {
3594 /* STBC and beamforming are mutually exclusive features */
3595 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3596 }
3597
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303598 /* enable dfsmode */
3599 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3600 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3601
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003602 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3603 char anqpval[1024];
3604
3605 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3606
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003607 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303608 snprintf(anqpval, sizeof(anqpval),
3609 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003610 dut->ap_val_lci, dut->ap_infoz);
3611 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3612 }
3613
3614 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303615 snprintf(anqpval, sizeof(anqpval),
3616 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003617 dut->ap_val_lcr);
3618 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3619 }
3620
3621 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
3622 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3623 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
3624 }
3625
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003626 if (dut->program == PROGRAM_MBO) {
3627 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3628 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3629 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07003630 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003631
3632 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3633 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07003634 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3635 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003636 }
3637
Jouni Malinen6be21c82018-08-01 18:47:24 +03003638 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003639 unsigned char self_mac[ETH_ALEN];
3640 char mac_str[20];
3641
3642 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
3643 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02003644 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
3645 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003646 snprintf(mac_str, sizeof(mac_str),
3647 "%02x:%02x:%02x:%02x:%02x:%02x",
3648 self_mac[0], self_mac[1], self_mac[2],
3649 self_mac[3], self_mac[4], self_mac[5]);
3650 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003651 snprintf(mac_str, sizeof(mac_str),
3652 "%02x:%02x:%02x:%02x:%02x:%02x",
3653 self_mac[0], self_mac[1], self_mac[2],
3654 self_mac[3], self_mac[4], self_mac[5]);
3655 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003656 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
3657 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
3658 "000102030405060708090a0b0c0d0e0f");
3659 snprintf(mac_str, sizeof(mac_str),
3660 "%02x:%02x:%02x:%02x:%02x:%02x",
3661 dut->ft_bss_mac_list[0][0],
3662 dut->ft_bss_mac_list[0][1],
3663 dut->ft_bss_mac_list[0][2],
3664 dut->ft_bss_mac_list[0][3],
3665 dut->ft_bss_mac_list[0][4],
3666 dut->ft_bss_mac_list[0][5]);
3667 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003668 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
3669 dut->ap_mobility_domain);
3670 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003671 }
3672
Jouni Malinen6be21c82018-08-01 18:47:24 +03003673 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
3674 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003675 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
3676 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003677 }
3678
Jouni Malinen6be21c82018-08-01 18:47:24 +03003679 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003680 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
3681 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003682 }
3683
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003684 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
3685 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
3686
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003687 /* Enable/disable PMKSA caching, if asked to */
3688 if (dut->ap_pmksa == 1) {
3689 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
3690 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
3691 }
3692
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003693 if (dut->rsne_override) {
3694 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
3695 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
3696 }
3697
3698 if (dut->sae_commit_override) {
3699 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
3700 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
3701 }
3702
3703 if (dut->ap_sae_groups) {
3704 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003705 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003706 }
3707
3708 if (dut->sae_anti_clogging_threshold >= 0) {
3709 snprintf(buf, sizeof(buf), "%d",
3710 dut->sae_anti_clogging_threshold);
3711 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
3712 buf);
3713 }
3714
3715 if (dut->sae_reflection)
3716 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
3717
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003718 return 1;
3719}
3720
3721
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003722static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
3723{
3724 char anqpval[1024];
3725 unsigned char addr[6];
3726 unsigned char addr2[6];
3727 struct ifreq ifr;
3728 char *ifname;
3729 int s;
3730 int vap_id = 0;
3731
3732 s = socket(AF_INET, SOCK_DGRAM, 0);
3733 if (s < 0) {
3734 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
3735 return -1;
3736 }
3737
3738 memset(&ifr, 0, sizeof(ifr));
3739 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003740 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003741 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3742 perror("ioctl");
3743 close(s);
3744 return -1;
3745 }
3746 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
3747
3748 memset(&ifr, 0, sizeof(ifr));
3749 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003750 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003751 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3752 perror("ioctl");
3753 close(s);
3754 return -1;
3755 }
3756 close(s);
3757 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
3758
3759 snprintf(anqpval, sizeof(anqpval),
3760 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
3761 dut->ap_val_lci, dut->ap_infoz,
3762 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
3763 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
3764
3765 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3766 return 0;
3767}
3768
3769
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003770static int owrt_ap_post_config_commit(struct sigma_dut *dut,
3771 struct sigma_conn *conn,
3772 struct sigma_cmd *cmd)
3773{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003774 int ap_security = 0;
3775 int i;
3776
3777 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
3778 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
3779 ap_security = 1;
3780 }
3781 if (dut->ap_key_mgmt != AP_OPEN)
3782 ap_security = 1;
3783 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003784 /* allow some time for hostapd to start before returning
3785 * success */
3786 usleep(500000);
3787
3788 if (run_hostapd_cli(dut, "ping") != 0) {
3789 send_resp(dut, conn, SIGMA_ERROR,
3790 "errorCode,Failed to talk to hostapd");
3791 return 0;
3792 }
3793 }
3794
3795 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
3796 ath_ap_set_params(dut);
3797
3798 /* Send response */
3799 return 1;
3800}
3801
3802
3803static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
3804 struct sigma_conn *conn,
3805 struct sigma_cmd *cmd)
3806{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08003807 if (dut->program == PROGRAM_DPP &&
3808 get_driver_type() == DRIVER_OPENWRT) {
3809 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
3810 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
3811 }
3812
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003813 /* Stop the AP */
3814 run_system(dut, "wifi down");
3815
3816 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05303817 run_system(dut, "rm -rf /etc/config/wireless");
3818 switch (get_openwrt_driver_type()) {
3819 case OPENWRT_DRIVER_ATHEROS:
3820 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
3821 break;
3822 default:
3823 run_system(dut, "wifi detect > /etc/config/wireless");
3824 break;
3825 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003826
3827 /* Configure Radio & VAP, commit the config */
3828 owrt_ap_config_radio(dut);
Jouni Malinen13701222019-02-19 12:10:53 +02003829 if (owrt_ap_config_vap(dut) < 0)
3830 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003831 run_system(dut, "uci commit");
3832
3833 /* Start AP */
3834 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003835 if (dut->program != PROGRAM_MBO &&
3836 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003837 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003838 /*
3839 * MBO has a different ANQP element value which is set in
3840 * owrt_ap_config_vap().
3841 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003842 owrt_ap_config_vap_anqp(dut);
3843 run_system(dut, "uci commit");
3844 run_system(dut, "wifi");
3845 }
3846
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003847 return owrt_ap_post_config_commit(dut, conn, cmd);
3848}
3849
3850
3851static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
3852{
3853 unsigned char bssid[6];
3854 char buf[100];
3855 char *ifname, *radio_name;
3856 int vap_id = 0;
3857
3858 if (sigma_radio_ifname[0] &&
3859 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3860 ifname = "ath2";
3861 radio_name = "wifi2";
3862 vap_id = 2;
3863 } else if (sigma_radio_ifname[0] &&
3864 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3865 ifname = "ath1";
3866 radio_name = "wifi1";
3867 vap_id = 1;
3868 } else {
3869 ifname = "ath0";
3870 radio_name = "wifi0";
3871 vap_id = 0;
3872 }
3873
3874 if (!get_hwaddr(ifname, bssid)) {
3875 snprintf(buf, sizeof(buf), "%s", bssid);
3876 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3877 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3878 "%02x:%02x:%02x:%02x:%02x:%02x",
3879 bssid[0], bssid[1], bssid[2], bssid[3],
3880 bssid[4], bssid[5]);
3881 } else {
3882 if (!get_hwaddr(radio_name, bssid)) {
3883 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3884 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3885 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3886 "%02x:%02x:%02x:%02x:%02x:%02x",
3887 bssid[0], bssid[1], bssid[2], bssid[3],
3888 bssid[4], bssid[5]);
3889 } else {
3890 /* Select & enable/disable radios */
3891 if (sigma_radio_ifname[0] &&
3892 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3893 /* We want to use wifi2 */
3894 owrt_ap_set_radio(dut, 0, "disabled", "1");
3895 owrt_ap_set_radio(dut, 1, "disabled", "1");
3896 owrt_ap_set_radio(dut, 2, "disabled", "0");
3897 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
3898 } else if (sigma_radio_ifname[0] &&
3899 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3900 /* We want to use wifi1 */
3901 owrt_ap_set_radio(dut, 0, "disabled", "1");
3902 owrt_ap_set_radio(dut, 1, "disabled", "0");
3903 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
3904 } else {
3905 /* We want to use wifi0 */
3906 owrt_ap_set_radio(dut, 0, "disabled", "0");
3907 owrt_ap_set_radio(dut, 1, "disabled", "1");
3908 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
3909 }
3910
3911 run_system(dut, "uci commit");
3912 run_system(dut, "wifi up");
3913
3914 if (!get_hwaddr(radio_name, bssid)) {
3915 snprintf(buf, sizeof(buf), "%s",
3916 dut->ap_hessid);
3917 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3918 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3919 "%02x:%02x:%02x:%02x:%02x:%02x",
3920 bssid[0], bssid[1], bssid[2], bssid[3],
3921 bssid[4], bssid[5]);
3922 }
3923 }
3924 }
3925}
3926
3927
Jouni Malinenf7222712019-06-13 01:50:21 +03003928static enum sigma_cmd_result cmd_ap_reboot(struct sigma_dut *dut,
3929 struct sigma_conn *conn,
3930 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003931{
3932 switch (get_driver_type()) {
3933 case DRIVER_ATHEROS:
3934 run_system(dut, "apdown");
3935 sleep(1);
3936 run_system(dut, "reboot");
3937 break;
3938 case DRIVER_OPENWRT:
3939 run_system(dut, "wifi down");
3940 sleep(1);
3941 run_system(dut, "reboot");
3942 break;
3943 default:
3944 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
3945 break;
3946 }
3947
3948 return 1;
3949}
3950
3951
3952int ascii2hexstr(const char *str, char *hex)
3953{
3954 int i, length;
3955
3956 length = strlen(str);
3957
3958 for (i = 0; i < length; i++)
3959 snprintf(hex + i * 2, 3, "%X", str[i]);
3960
3961 hex[length * 2] = '\0';
3962 return 1;
3963}
3964
3965
3966static int kill_process(struct sigma_dut *dut, char *proc_name,
3967 unsigned char is_proc_instance_one, int sig)
3968{
3969#ifdef __linux__
3970 struct dirent *dp, *dp_in;
3971 const char *direc = "/proc/";
3972 char buf[100];
3973 DIR *dir = opendir(direc);
3974 DIR *dir_in;
3975 FILE *fp;
3976 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303977 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +03003978 int ret = -1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003979
3980 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303981 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003982
3983 while ((dp = readdir(dir)) != NULL) {
3984 if (dp->d_type != DT_DIR)
3985 continue;
3986
Jouni Malinen3aa72862019-05-29 23:14:51 +03003987 res = snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
3988 if (res < 0 || res >= sizeof(buf))
3989 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003990 dir_in = opendir(buf);
3991 if (dir_in == NULL)
3992 continue;
3993 dp_in = readdir(dir_in);
3994 closedir(dir_in);
3995 if (dp_in == NULL)
3996 continue;
Jouni Malinen3aa72862019-05-29 23:14:51 +03003997 res = snprintf(buf, sizeof(buf), "%s%s/stat",
3998 direc, dp->d_name);
3999 if (res < 0 || res >= sizeof(buf))
4000 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004001 fp = fopen(buf, "r");
4002 if (fp == NULL)
4003 continue;
4004 if (fgets(buf, 100, fp) == NULL)
4005 buf[0] = '\0';
4006 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304007 pid = strtok_r(buf, " ", &saveptr);
4008 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004009 if (pid && temp &&
4010 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
4011 sigma_dut_print(dut, DUT_MSG_INFO,
4012 "killing %s process with PID %s",
4013 proc_name, pid);
4014 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
4015 atoi(pid));
4016 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304017 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004018 if (is_proc_instance_one)
4019 break;
4020 }
4021 }
4022
4023 closedir(dir);
4024
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304025 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004026#else /* __linux__ */
4027 return -1;
4028#endif /* __linux__ */
4029}
4030
4031
4032static int run_ndc(struct sigma_dut *dut, char *buf)
4033{
4034 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
4035 sleep(2);
4036 return run_system(dut, buf);
4037}
4038
4039
4040static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
4041 const char *field, const char *value)
4042{
4043 FILE *fcfg, *ftmp;
4044 char buf[MAX_CONF_LINE_LEN + 1];
4045 int len, found = 0, res;
4046
4047 /* Open the configuration file */
4048 fcfg = fopen(pfile, "r");
4049 if (!fcfg) {
4050 sigma_dut_print(dut, DUT_MSG_ERROR,
4051 "Failed to open hostapd conf file");
4052 return -1;
4053 }
4054
4055 snprintf(buf, sizeof(buf), "%s~", pfile);
4056 /* Open a temporary file */
4057 ftmp = fopen(buf, "w+");
4058 if (!ftmp) {
4059 fclose(fcfg);
4060 sigma_dut_print(dut, DUT_MSG_ERROR,
4061 "Failed to open temp buf");
4062 return -1;
4063 }
4064
4065 /* Read the values from the configuration file */
4066 len = strlen(field);
4067 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
4068 char *pline = buf;
4069
4070 /* commented line */
4071 if (buf[0] == '#')
4072 pline++;
4073
4074 /* Identify the configuration parameter to be updated */
4075 if (!found && strncmp(pline, field, len) == 0 &&
4076 pline[len] == '=') {
4077 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4078 found = 1;
4079 sigma_dut_print(dut, DUT_MSG_INFO,
4080 "Updated hostapd conf file");
4081 }
4082
4083 fprintf(ftmp, "%s", buf);
4084 }
4085
4086 if (!found) {
4087 /* Configuration line not found */
4088 /* Add the new line at the end of file */
4089 fprintf(ftmp, "%s=%s\n", field, value);
4090 sigma_dut_print(dut, DUT_MSG_INFO,
4091 "Adding a new line in hostapd conf file");
4092 }
4093
4094 fclose(fcfg);
4095 fclose(ftmp);
4096
4097 snprintf(buf, sizeof(buf), "%s~", pfile);
4098
4099 /* Restore the updated configuration file */
4100 res = rename(buf, pfile);
4101
4102 /* Remove the temporary file. Ignore the return value */
4103 unlink(buf);
4104
4105 /* chmod is needed because open() may not set permissions properly
4106 * depending on the current umask */
4107 if (chmod(pfile, 0660) < 0) {
4108 unlink(pfile);
4109 sigma_dut_print(dut, DUT_MSG_ERROR,
4110 "Error changing permissions");
4111 return -1;
4112 }
4113
4114 if (res < 0) {
4115 sigma_dut_print(dut, DUT_MSG_ERROR,
4116 "Error restoring conf file");
4117 return -1;
4118 }
4119
4120 return 0;
4121}
4122
4123
4124static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4125 struct sigma_conn *conn,
4126 struct sigma_cmd *cmd)
4127{
4128 char buf[100];
4129 struct stat s;
4130 int num_tries = 0, ret;
4131
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304132 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4133 system("killall netd") == 0) {
4134 /* Avoid Error: Error connecting (Connection refused)
4135 * Wait some time to allow netd to reinitialize.
4136 */
4137 usleep(1500000);
4138 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004139
4140 while (num_tries < 10) {
4141 ret = run_ndc(dut, "ndc softap stopap");
4142 num_tries++;
4143 if (WIFEXITED(ret))
4144 ret = WEXITSTATUS(ret);
4145 /* On success, NDC exits with 0 */
4146 if (ret == 0)
4147 break;
4148 sigma_dut_print(dut, DUT_MSG_INFO,
4149 "Try No. %d: ndc softap stopap failed, exit code %d",
4150 num_tries, ret);
4151 }
4152
4153 if (ret != 0)
4154 sigma_dut_print(dut, DUT_MSG_ERROR,
4155 "ndc softap stopap command failed for 10 times - giving up");
4156
4157#ifdef ANDROID
4158 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304159 system("rmmod -f wlan");
4160 usleep(500000);
4161 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004162#else /* ANDROID */
4163 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4164 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4165#endif /* ANDROID */
4166
4167 switch (dut->ap_mode) {
4168 case AP_11g:
4169 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4170 break;
4171 case AP_11b:
4172 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4173 break;
4174 case AP_11ng:
4175 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4176 break;
4177 case AP_11a:
4178 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4179 break;
4180 case AP_11na:
4181 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4182 break;
4183 case AP_11ac:
4184 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4185 break;
4186 default:
4187 break;
4188 }
4189
4190 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4191 dut->ap_channel);
4192 run_ndc(dut, buf);
4193
4194 /*
4195 * ndc doesn't support double quotes as SSID string, so re-write
4196 * hostapd configuration file to update SSID.
4197 */
4198 if (dut->ap_ssid[0] != '\0')
4199 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4200
4201 switch (dut->ap_key_mgmt) {
4202 case AP_OPEN:
4203 if (dut->ap_cipher == AP_WEP) {
4204 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4205 snprintf(buf, sizeof(buf),
4206 "ndc softap qccmd set wep_key0=%s",
4207 dut->ap_wepkey);
4208 run_ndc(dut, buf);
4209 } else {
4210 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4211 }
4212 break;
4213 case AP_WPA2_PSK:
4214 case AP_WPA2_PSK_MIXED:
4215 case AP_WPA_PSK:
4216 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4217 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4218 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4219 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4220 else
4221 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4222
4223 /*
4224 * ndc doesn't support some special characters as passphrase,
4225 * so re-write hostapd configuration file to update Passphrase.
4226 */
4227 if (dut->ap_passphrase[0] != '\0')
4228 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4229 "wpa_passphrase", dut->ap_passphrase);
4230
4231 if (dut->ap_cipher == AP_CCMP_TKIP)
4232 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4233 "TKIP CCMP");
4234 else if (dut->ap_cipher == AP_TKIP)
4235 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4236 "TKIP");
4237 else
4238 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4239 "CCMP &");
4240 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004241 case AP_WPA2_SAE:
4242 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004243 case AP_WPA2_EAP:
4244 case AP_WPA2_EAP_MIXED:
4245 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004246 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004247 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004248 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004249 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004250 case AP_WPA2_FT_EAP:
4251 case AP_WPA2_FT_PSK:
4252 case AP_WPA2_EAP_SHA256:
4253 case AP_WPA2_PSK_SHA256:
4254 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004255 /* Not supported */
4256 break;
4257 }
4258
4259 switch (dut->ap_pmf) {
4260 case AP_PMF_DISABLED:
4261 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4262 break;
4263 case AP_PMF_OPTIONAL:
4264 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4265 if (dut->ap_add_sha256)
4266 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4267 else
4268 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4269 break;
4270 case AP_PMF_REQUIRED:
4271 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4272 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4273 break;
4274 }
4275
4276 if (dut->ap_countrycode[0]) {
4277 snprintf(buf, sizeof(buf),
4278 "ndc softap qccmd set country_code=%s",
4279 dut->ap_countrycode);
4280 run_ndc(dut, buf);
4281 }
4282
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304283 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4284 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4285
4286 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4287 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4288
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004289 run_ndc(dut, "ndc softap startap");
4290
4291 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
4292 num_tries = 0;
4293 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4294 run_ndc(dut, "ndc softap stopap");
4295 run_ndc(dut, "ndc softap startap");
4296 num_tries++;
4297 }
4298
4299 if (num_tries == 10) {
4300 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4301 "iface %s :: reboot the APDUT", buf);
4302 return ret;
4303 }
4304
4305 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4306 ap_inet_addr, ap_inet_mask);
4307 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
4308 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
4309 if (system(buf) != 0) {
4310 sigma_dut_print(dut, DUT_MSG_ERROR,
4311 "Failed to intialize the interface");
4312 return -1;
4313 }
4314
4315 return 1;
4316}
4317
4318
4319static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4320{
4321 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4322 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4323
4324 if (dut->ap_oper_name) {
4325 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4326 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4327 }
4328
4329 if (dut->ap_wan_metrics == 1)
4330 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4331 else if (dut->ap_wan_metrics == 2)
4332 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4333 else if (dut->ap_wan_metrics == 3)
4334 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4335 else if (dut->ap_wan_metrics == 4)
4336 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4337 else if (dut->ap_wan_metrics == 5)
4338 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4339
4340 if (dut->ap_conn_capab == 1) {
4341 fprintf(f, "hs20_conn_capab=1:0:0\n");
4342 fprintf(f, "hs20_conn_capab=6:20:1\n");
4343 fprintf(f, "hs20_conn_capab=6:22:0\n");
4344 fprintf(f, "hs20_conn_capab=6:80:1\n");
4345 fprintf(f, "hs20_conn_capab=6:443:1\n");
4346 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4347 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4348 fprintf(f, "hs20_conn_capab=17:500:1\n");
4349 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4350 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4351 fprintf(f, "hs20_conn_capab=50:0:1\n");
4352 } else if (dut->ap_conn_capab == 2) {
4353 fprintf(f, "hs20_conn_capab=6:80:1\n");
4354 fprintf(f, "hs20_conn_capab=6:443:1\n");
4355 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4356 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4357 } else if (dut->ap_conn_capab == 3) {
4358 fprintf(f, "hs20_conn_capab=6:80:1\n");
4359 fprintf(f, "hs20_conn_capab=6:443:1\n");
4360 } else if (dut->ap_conn_capab == 4) {
4361 fprintf(f, "hs20_conn_capab=6:80:1\n");
4362 fprintf(f, "hs20_conn_capab=6:443:1\n");
4363 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4364 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4365 }
4366
4367 if (dut->ap_oper_class == 1)
4368 fprintf(f, "hs20_operating_class=51\n");
4369 else if (dut->ap_oper_class == 2)
4370 fprintf(f, "hs20_operating_class=73\n");
4371 else if (dut->ap_oper_class == 3)
4372 fprintf(f, "hs20_operating_class=5173\n");
4373
4374 if (dut->ap_osu_provider_list) {
4375 char *osu_friendly_name = NULL;
4376 char *osu_icon = NULL;
4377 char *osu_ssid = NULL;
4378 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004379 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004380 char *osu_service_desc = NULL;
4381 char *hs20_icon_filename = NULL;
4382 char hs20_icon[150];
4383 int osu_method;
4384
4385 hs20_icon_filename = "icon_red_zxx.png";
4386 if (dut->ap_osu_icon_tag == 2)
4387 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4388 snprintf(hs20_icon, sizeof(hs20_icon),
4389 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4390 hs20_icon_filename);
4391 osu_icon = "icon_red_zxx.png";
4392 osu_ssid = "OSU";
4393 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4394 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4395 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4396
4397 if (strlen(dut->ap_osu_server_uri[0]))
4398 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4399 else
4400 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4401
4402 switch (dut->ap_osu_provider_list) {
4403 case 1:
4404 case 101:
4405 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4406 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4407 hs20_icon_filename = "icon_red_eng.png";
4408 if (dut->ap_osu_icon_tag == 2)
4409 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4410 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4411 hs20_icon_filename);
4412 fprintf(f, "osu_icon=icon_red_eng.png\n");
4413 break;
4414 case 2:
4415 case 102:
4416 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4417 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4418 hs20_icon_filename = "icon_orange_zxx.png";
4419 if (dut->ap_osu_icon_tag == 2)
4420 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4421 snprintf(hs20_icon, sizeof(hs20_icon),
4422 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4423 hs20_icon_filename);
4424 osu_icon = "icon_orange_zxx.png";
4425 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4426 break;
4427 case 3:
4428 case 103:
4429 osu_friendly_name = "spa:SP Red Test Only";
4430 osu_service_desc = "spa:Free service for test purpose";
4431 break;
4432 case 4:
4433 case 104:
4434 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4435 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4436 hs20_icon_filename = "icon_orange_eng.png";
4437 if (dut->ap_osu_icon_tag == 2)
4438 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4439 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4440 hs20_icon_filename);
4441 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4442 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4443
4444 hs20_icon_filename = "icon_orange_zxx.png";
4445 if (dut->ap_osu_icon_tag == 2)
4446 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4447 snprintf(hs20_icon, sizeof(hs20_icon),
4448 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4449 hs20_icon_filename);
4450 osu_icon = "icon_orange_zxx.png";
4451 break;
4452 case 5:
4453 case 105:
4454 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4455 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4456 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4457 hs20_icon_filename = "icon_orange_zxx.png";
4458 if (dut->ap_osu_icon_tag == 2)
4459 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4460 snprintf(hs20_icon, sizeof(hs20_icon),
4461 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4462 hs20_icon_filename);
4463 osu_icon = "icon_orange_zxx.png";
4464 break;
4465 case 6:
4466 case 106:
4467 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4468 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4469 hs20_icon_filename = "icon_green_zxx.png";
4470 if (dut->ap_osu_icon_tag == 2)
4471 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4472 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4473 hs20_icon_filename);
4474 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4475 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4476 fprintf(f, "osu_method_list=%d\n", osu_method);
4477
4478 if (strlen(dut->ap_osu_server_uri[1]))
4479 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4480 else
4481 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4482 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4483 hs20_icon_filename = "icon_orange_zxx.png";
4484 if (dut->ap_osu_icon_tag == 2)
4485 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4486 snprintf(hs20_icon, sizeof(hs20_icon),
4487 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4488 hs20_icon_filename);
4489 osu_icon = "icon_orange_zxx.png";
4490 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4491 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4492 osu_service_desc = NULL;
4493 break;
4494 case 7:
4495 case 107:
4496 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4497 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4498 hs20_icon_filename = "icon_green_eng.png";
4499 if (dut->ap_osu_icon_tag == 2)
4500 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4501 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4502 hs20_icon_filename);
4503 fprintf(f, "osu_icon=icon_green_eng.png\n");
4504 osu_friendly_name = "kor:SP 초록 테스트 전용";
4505
4506 hs20_icon_filename = "icon_green_zxx.png";
4507 if (dut->ap_osu_icon_tag == 2)
4508 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4509 snprintf(hs20_icon, sizeof(hs20_icon),
4510 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4511 hs20_icon_filename);
4512 osu_icon = "icon_green_zxx.png";
4513 break;
4514 case 8:
4515 case 108:
4516 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4517 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4518 osu_ssid = "OSU-Encrypted";
4519 osu_nai = "anonymous@hotspot.net";
4520 break;
4521 case 9:
4522 case 109:
4523 osu_ssid = "OSU-OSEN";
4524 osu_nai = "test-anonymous@wi-fi.org";
4525 osu_friendly_name = "eng:SP Orange Test Only";
4526 hs20_icon_filename = "icon_orange_zxx.png";
4527 if (dut->ap_osu_icon_tag == 2)
4528 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4529 snprintf(hs20_icon, sizeof(hs20_icon),
4530 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4531 hs20_icon_filename);
4532 osu_icon = "icon_orange_zxx.png";
4533 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4534 osu_service_desc = NULL;
4535 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004536 case 10:
4537 case 110:
4538 /* OSU Provider #1 */
4539 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4540 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
4541 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
4542 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
4543 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
4544 1 : dut->ap_osu_method[0];
4545 fprintf(f, "osu_method_list=%d\n", osu_method);
4546 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
4547 switch (dut->ap_osu_provider_nai_list) {
4548 case 3:
4549 fprintf(f,
4550 "osu_nai2=test-anonymous@wi-fi.org\n");
4551 break;
4552 case 4:
4553 fprintf(f, "osu_nai2=random@hotspot.net\n");
4554 break;
4555 }
4556
4557 /* OSU Provider #2 */
4558 /* SP Red from defaults */
4559 if (strlen(dut->ap_osu_server_uri[1]))
4560 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4561 else
4562 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4563 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4564 snprintf(hs20_icon, sizeof(hs20_icon),
4565 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
4566 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
4567 1 : dut->ap_osu_method[1];
4568 osu_service_desc = NULL;
4569 osu_nai = "anonymous@hotspot.net";
4570 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004571 default:
4572 break;
4573 }
4574
Jouni Malinen93a837f2018-11-01 17:09:22 +02004575 switch (dut->ap_osu_provider_nai_list) {
4576 case 1:
4577 osu_nai2 = "anonymous@hotspot.net";
4578 break;
4579 case 2:
4580 osu_nai2 = "test-anonymous@wi-fi.org";
4581 break;
4582 case 3:
4583 /* OSU Provider NAI #1 written above */
4584 /* OSU Provider NAI #2 */
4585 osu_nai2 = "anonymous@hotspot.net";
4586 break;
4587 case 4:
4588 /* OSU Provider NAI #1 written above */
4589 /* OSU Provider NAI #2 */
4590 osu_nai2 = "anonymous@hotspot.net";
4591 break;
4592 }
4593
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004594 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03004595 if (dut->ap_tag_ssid[0][0] &&
4596 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004597 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004598 sigma_dut_print(dut, DUT_MSG_ERROR,
4599 "OSU_SSID and "
4600 "WLAN_TAG2 SSID differ");
4601 return -2;
4602 }
4603 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
4604 } else
4605 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
4606
4607
4608 if (osu_friendly_name)
4609 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
4610
4611 if (osu_service_desc)
4612 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
4613
4614 if (osu_nai)
4615 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02004616 if (osu_nai2)
4617 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004618
4619 fprintf(f, "hs20_icon=%s\n", hs20_icon);
4620
4621 if (osu_icon)
4622 fprintf(f, "osu_icon=%s\n", osu_icon);
4623
4624 if (dut->ap_osu_provider_list > 100)
4625 fprintf(f, "osu_method_list=0\n");
4626 else
4627 fprintf(f, "osu_method_list=%d\n", osu_method);
4628 }
4629
Jouni Malinen54a89b02018-05-01 00:16:26 +03004630 switch (dut->ap_venue_url) {
4631 case 1:
4632 fprintf(f,
4633 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4634 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
4635 break;
4636 case 2:
4637 fprintf(f,
4638 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4639 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4640 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4641 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4642 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4643 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4644 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4645 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4646 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4647 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4648 );
4649 break;
4650 }
4651
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03004652 switch (dut->ap_advice_of_charge) {
4653 case 1:
4654 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
4655 break;
4656 }
4657
Jouni Malinenac104532018-05-01 00:27:37 +03004658 switch (dut->ap_oper_icon_metadata) {
4659 case 1:
4660 fprintf(f,
4661 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
4662 "operator_icon=icon_red_eng.png\n");
4663 break;
4664 }
4665
Jouni Malinenac367142018-05-01 00:32:24 +03004666 switch (dut->ap_tnc_file_name) {
4667 case 1:
4668 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
4669 break;
4670 }
4671
4672 if (dut->ap_tnc_time_stamp)
4673 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
4674
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004675 return 0;
4676}
4677
4678
4679static void write_ap_roaming_cons(FILE *f, const char *list)
4680{
4681 char *buf, *pos, *end;
4682
4683 if (list == NULL || list[0] == '\0')
4684 return;
4685
4686 buf = strdup(list);
4687 if (buf == NULL)
4688 return;
4689
4690 pos = buf;
4691 while (pos && *pos) {
4692 end = strchr(pos, ';');
4693 if (end)
4694 *end++ = '\0';
4695 fprintf(f, "roaming_consortium=%s\n", pos);
4696 pos = end;
4697 }
4698
4699 free(buf);
4700}
4701
4702
4703static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
4704{
4705 int i;
4706 char buf[100], *temp;
4707
4708 if (dut->ap_gas_cb_delay > 0)
4709 fprintf(f, "gas_comeback_delay=%d\n",
4710 dut->ap_gas_cb_delay);
4711
4712 fprintf(f, "interworking=1\n"
4713 "access_network_type=%d\n"
4714 "internet=%d\n"
4715 "asra=0\n"
4716 "esr=0\n"
4717 "uesa=0\n"
4718 "venue_group=%d\n"
4719 "venue_type=%d\n",
4720 dut->ap_access_net_type,
4721 dut->ap_internet,
4722 dut->ap_venue_group,
4723 dut->ap_venue_type);
4724 if (dut->ap_hessid[0])
4725 fprintf(f, "hessid=%s\n", dut->ap_hessid);
4726
4727 write_ap_roaming_cons(f, dut->ap_roaming_cons);
4728
4729 if (dut->ap_venue_name) {
4730 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
4731 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
4732 }
4733
4734 if (dut->ap_net_auth_type == 1)
4735 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
4736 else if (dut->ap_net_auth_type == 2)
4737 fprintf(f, "network_auth_type=01\n");
4738
4739 if (dut->ap_nai_realm_list == 1) {
4740 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
4741 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4742 } else if (dut->ap_nai_realm_list == 2) {
4743 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4744 } else if (dut->ap_nai_realm_list == 3) {
4745 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
4746 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4747 } else if (dut->ap_nai_realm_list == 4) {
4748 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
4749 } else if (dut->ap_nai_realm_list == 5) {
4750 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
4751 } else if (dut->ap_nai_realm_list == 6) {
4752 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
4753 } else if (dut->ap_nai_realm_list == 7) {
4754 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
4755 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4756 }
4757
4758 if (dut->ap_domain_name_list[0]) {
4759 fprintf(f, "domain_name=%s\n",
4760 dut->ap_domain_name_list);
4761 }
4762
4763 if (dut->ap_ip_addr_type_avail == 1) {
4764 fprintf(f, "ipaddr_type_availability=0c\n");
4765 }
4766
4767 temp = buf;
4768 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
4769 i++) {
4770 if (i)
4771 *temp++ = ';';
4772
4773 snprintf(temp,
4774 sizeof(dut->ap_plmn_mcc[i]) +
4775 sizeof(dut->ap_plmn_mnc[i]) + 1,
4776 "%s,%s",
4777 dut->ap_plmn_mcc[i],
4778 dut->ap_plmn_mnc[i]);
4779
4780 temp += strlen(dut->ap_plmn_mcc[i]) +
4781 strlen(dut->ap_plmn_mnc[i]) + 1;
4782 }
4783 if (i)
4784 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
4785
4786 if (dut->ap_qos_map_set == 1)
4787 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
4788 else if (dut->ap_qos_map_set == 2)
4789 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
4790
4791 return 0;
4792}
4793
4794
4795static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
4796{
4797 FILE *f;
4798
4799 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4800 system("killall hostapd") == 0) {
4801 int i;
4802
4803 /* Wait some time to allow hostapd to complete cleanup before
4804 * starting a new process */
4805 for (i = 0; i < 10; i++) {
4806 usleep(500000);
4807 if (system("pidof hostapd") != 0)
4808 break;
4809 }
4810 }
4811
4812 f = fopen("/tmp/secath0", "a");
4813 if (f == NULL)
4814 return -2;
4815
4816 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
4817 fclose(f);
4818 return -2;
4819 }
4820
4821 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4822 fclose(f);
4823 return -2;
4824 }
4825
4826 fflush(f);
4827 fclose(f);
4828 return ath_ap_start_hostapd(dut);
4829}
4830
4831
4832static int ath_ap_start_hostapd(struct sigma_dut *dut)
4833{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004834 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004835 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
4836 else
4837 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
4838
4839 return 0;
4840}
4841
4842
4843#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
4844
4845static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
4846{
4847 FILE *f;
4848 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
4849 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
4850 char buf[100];
4851 int i;
4852
4853 f = fopen("/root/anqpserver.conf", "w");
4854 if (f == NULL)
4855 return -1;
4856
4857 if (dut->ap_nai_realm_list == 1) {
4858 nai_realm = 1;
4859 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");
4860 } else if (dut->ap_nai_realm_list == 2) {
4861 nai_realm = 1;
4862 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4863 } else if (dut->ap_nai_realm_list == 3) {
4864 nai_realm = 1;
4865 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");
4866 } else if (dut->ap_nai_realm_list == 4) {
4867 nai_realm = 1;
4868 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");
4869 } else
4870 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
4871
4872 if (dut->ap_domain_name_list[0]) {
4873 char *next, *start, *dnbuf, *dn1, *anqp_dn;
4874 int len, dn_len_max;
4875 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304876 if (dnbuf == NULL) {
4877 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004878 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304879 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004880
4881 len = strlen(dnbuf);
4882 dn_len_max = 50 + len*2;
4883 anqp_dn = malloc(dn_len_max);
4884 if (anqp_dn == NULL) {
4885 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304886 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004887 return -1;
4888 }
4889 start = dnbuf;
4890 dn1 = anqp_dn;
4891 while (start && *start) {
4892 char *hexstr;
4893
4894 next = strchr(start, ',');
4895 if (next)
4896 *next++ = '\0';
4897
4898 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05304899 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004900 if (hexstr == NULL) {
4901 free(dnbuf);
4902 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304903 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004904 return -1;
4905 }
4906 ascii2hexstr(start, hexstr);
4907 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
4908 free(hexstr);
4909 dn1 += 2 + len * 2;
4910 dn_len_max -= 2 + len * 2;
4911 start = next;
4912 }
4913 free(dnbuf);
4914 if (dut->ap_gas_cb_delay) {
4915 fprintf(f, "dyn_domain_name=0c01%04x%s",
4916 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4917 domain_name = 1;
4918 } else
4919 fprintf(f, "domain_name=0c01%04x%s",
4920 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
4921 free(anqp_dn);
4922 } else
4923 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
4924
4925 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
4926
4927 if (dut->ap_oper_name) {
4928 if (dut->ap_gas_cb_delay) {
4929 fprintf(f, "dyn_oper_friendly_name="
4930 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4931 oper_name = 1;
4932 } else
4933 fprintf(f, "oper_friendly_name="
4934 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
4935 } else
4936 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
4937
4938 if (dut->ap_venue_name) {
4939 if (dut->ap_gas_cb_delay) {
4940 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
4941 venue_name = 1;
4942 } else
4943 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
4944 } else
4945 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
4946
4947 if (dut->ap_wan_metrics) {
4948 if (dut->ap_gas_cb_delay) {
4949 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
4950 wan_metrics = 1;
4951 } else
4952 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
4953 "\n");
4954 } else
4955 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
4956
4957 if (dut->ap_conn_capab) {
4958 if (dut->ap_gas_cb_delay) {
4959 fprintf(f, "dyn_conn_capability="
4960 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4961 conn_cap = 1;
4962 } else
4963 fprintf(f, "conn_capability="
4964 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
4965 } else
4966 sigma_dut_print(dut, DUT_MSG_ERROR,
4967 "not setting conn_capability");
4968
4969 if (dut->ap_ip_addr_type_avail) {
4970 if (dut->ap_gas_cb_delay) {
4971 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
4972 "\n");
4973 ipaddr_avail = 1;
4974 } else
4975 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
4976 } else
4977 sigma_dut_print(dut, DUT_MSG_ERROR,
4978 "not setting ipaddr_type_avail");
4979
4980 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
4981 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
4982 dut->ap_plmn_mcc[i][1],
4983 dut->ap_plmn_mcc[i][0],
4984 dut->ap_plmn_mnc[i][2] == '\0' ?
4985 'f' : dut->ap_plmn_mnc[i][2],
4986 dut->ap_plmn_mcc[i][2],
4987 dut->ap_plmn_mnc[i][1],
4988 dut->ap_plmn_mnc[i][0]);
4989 }
4990 if (i) {
4991 uint16_t ie_len = (i * 3) + 5;
4992 if (dut->ap_gas_cb_delay) {
4993 fprintf(f, "dyn_cell_net=0801");
4994 cell_net = 1;
4995 } else
4996 fprintf(f, "cell_net=0801");
4997 fprintf(f, "%04x", LE16(ie_len));
4998 fprintf(f, "00"); /* version */
4999 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
5000 fprintf(f, "00"); /* plmn list */
5001 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
5002 fprintf(f, "%02x", i); /* number of plmns */
5003 fprintf(f, "%s\n", buf); /* plmns */
5004 } else
5005 sigma_dut_print(dut, DUT_MSG_ERROR,
5006 "not setting 3gpp_cellular_network");
5007
5008 if (nai_realm || domain_name || oper_name || venue_name ||
5009 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
5010 fprintf(f, "anqp_attach=");
5011 if (venue_name)
5012 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
5013 if (nai_realm)
5014 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
5015 if (cell_net)
5016 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
5017 if (domain_name)
5018 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
5019 if (oper_name)
5020 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
5021 if (wan_metrics)
5022 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
5023 if (conn_cap)
5024 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
5025 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
5026 fprintf(f, "\n");
5027 }
5028
5029 fclose(f);
5030
5031 run_system(dut, "anqpserver -i ath0 &");
5032 if (!dut->ap_anqpserver_on)
5033 run_system(dut, "killall anqpserver");
5034
5035 return 1;
5036}
5037
5038
5039static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
5040{
5041 char buf[100];
5042
5043 run_system(dut, "cfg -a AP_STARTMODE=standard");
5044
5045 if (sigma_radio_ifname[0] &&
5046 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
5047 run_system(dut, "cfg -a AP_RADIO_ID=1");
5048 switch (dut->ap_mode) {
5049 case AP_11g:
5050 run_system(dut, "cfg -a AP_CHMODE_2=11G");
5051 break;
5052 case AP_11b:
5053 run_system(dut, "cfg -a AP_CHMODE_2=11B");
5054 break;
5055 case AP_11ng:
5056 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
5057 break;
5058 case AP_11a:
5059 run_system(dut, "cfg -a AP_CHMODE_2=11A");
5060 break;
5061 case AP_11na:
5062 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
5063 break;
5064 case AP_11ac:
5065 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5066 break;
5067 default:
5068 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5069 break;
5070 }
5071
5072 switch (dut->ap_rx_streams) {
5073 case 1:
5074 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5075 break;
5076 case 2:
5077 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5078 break;
5079 case 3:
5080 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5081 break;
5082 }
5083
5084 switch (dut->ap_tx_streams) {
5085 case 1:
5086 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5087 break;
5088 case 2:
5089 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5090 break;
5091 case 3:
5092 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5093 break;
5094 }
5095
5096 switch (dut->ap_chwidth) {
5097 case AP_20:
5098 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5099 break;
5100 case AP_40:
5101 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5102 break;
5103 case AP_80:
5104 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5105 break;
5106 case AP_160:
5107 case AP_AUTO:
5108 default:
5109 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5110 break;
5111 }
5112
5113 if (dut->ap_tx_stbc) {
5114 run_system(dut, "cfg -a TX_STBC_2=1");
5115 }
5116
5117 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5118 dut->ap_channel);
5119
5120 if (dut->ap_is_dual) {
5121 switch (dut->ap_mode_1) {
5122 case AP_11g:
5123 run_system(dut, "cfg -a AP_CHMODE=11G");
5124 break;
5125 case AP_11b:
5126 run_system(dut, "cfg -a AP_CHMODE=11B");
5127 break;
5128 case AP_11ng:
5129 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5130 break;
5131 case AP_11a:
5132 run_system(dut, "cfg -a AP_CHMODE=11A");
5133 break;
5134 case AP_11na:
5135 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5136 break;
5137 case AP_11ac:
5138 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5139 break;
5140 default:
5141 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5142 break;
5143 }
5144 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5145 dut->ap_channel_1);
5146 }
5147 run_system(dut, buf);
5148 } else {
5149 run_system(dut, "cfg -a AP_RADIO_ID=0");
5150 switch (dut->ap_mode) {
5151 case AP_11g:
5152 run_system(dut, "cfg -a AP_CHMODE=11G");
5153 break;
5154 case AP_11b:
5155 run_system(dut, "cfg -a AP_CHMODE=11B");
5156 break;
5157 case AP_11ng:
5158 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5159 break;
5160 case AP_11a:
5161 run_system(dut, "cfg -a AP_CHMODE=11A");
5162 break;
5163 case AP_11na:
5164 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5165 break;
5166 case AP_11ac:
5167 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5168 break;
5169 default:
5170 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5171 break;
5172 }
5173 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5174 dut->ap_channel);
5175 run_system(dut, buf);
5176 }
5177
5178 if (dut->ap_sgi80 == 1) {
5179 run_system(dut, "cfg -a SHORTGI=1");
5180 run_system(dut, "cfg -a SHORTGI_2=1");
5181 } else if (dut->ap_sgi80 == 0) {
5182 run_system(dut, "cfg -a SHORTGI=0");
5183 run_system(dut, "cfg -a SHORTGI_2=0");
5184 }
5185
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005186 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005187 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005188 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005189 run_system(dut, "cfg -a LDPC=0");
5190}
5191
5192
5193void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5194{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005195 run_iwpriv(dut, intf, "vhtsubfee 0");
5196 run_iwpriv(dut, intf, "vhtsubfer 0");
5197 run_iwpriv(dut, intf, "vhtmubfee 0");
5198 run_iwpriv(dut, intf, "vhtmubfer 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005199}
5200
5201
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005202static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5203 const char *val)
5204{
5205 if (strcasecmp(val, "enable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005206 run_iwpriv(dut, ifname, "mbo_asoc_dis 1");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005207 } else if (strcasecmp(val, "disable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005208 run_iwpriv(dut, ifname, "mbo_asoc_dis 0");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005209 } else {
5210 sigma_dut_print(dut, DUT_MSG_ERROR,
5211 "Unsupported assoc_disallow");
5212 }
5213}
5214
5215
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005216static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5217{
5218 int i;
5219 int least_pref = 1 << 8;
5220 char ifname[20];
5221 uint8_t self_mac[ETH_ALEN];
5222 char buf[200];
5223 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5224
5225 get_if_name(dut, ifname, sizeof(ifname), 1);
5226 get_hwaddr(ifname, self_mac);
5227
5228 /* Clear off */
5229 snprintf(buf, sizeof(buf),
5230 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5231 ifname);
5232 run_system(dut, buf);
5233
5234 /* Find the least preference number */
5235 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5236 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5237
5238 ap_ne_class = 1;
5239 ap_ne_pref = 255;
5240 ap_ne_op_ch = 1;
5241 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5242 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5243 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5244 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5245 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5246 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5247
5248 if (ap_ne_pref < least_pref)
5249 least_pref = ap_ne_pref;
5250 snprintf(buf, sizeof(buf),
5251 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5252 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5253 mac_addr[3], mac_addr[4], mac_addr[5],
5254 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5255 run_system(dut, buf);
5256 }
5257
5258 /* Now add the self AP Address */
5259 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5260 if (dut->ap_channel <= 11)
5261 ap_ne_class = 81;
5262 else
5263 ap_ne_class = 115;
5264 } else {
5265 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5266 }
5267
5268 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5269 ap_ne_op_ch = dut->ap_channel;
5270 else
5271 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5272
5273 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5274 ap_ne_pref = least_pref - 1;
5275 else
5276 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5277
5278 snprintf(buf, sizeof(buf),
5279 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5280 ifname, self_mac[0], self_mac[1], self_mac[2],
5281 self_mac[3], self_mac[4], self_mac[5],
5282 ap_ne_pref,
5283 ap_ne_class,
5284 ap_ne_op_ch);
5285 run_system(dut, buf);
5286}
5287
5288
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005289static void ath_ap_set_params(struct sigma_dut *dut)
5290{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005291 const char *basedev = "wifi0";
5292 const char *basedev_radio = "wifi1";
5293 char *ifname = get_main_ifname();
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005294 char *ifname_dual = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005295 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005296 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005297
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005298 if (sigma_radio_ifname[0])
5299 basedev = sigma_radio_ifname[0];
5300
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005301 if (dut->ap_is_dual == 1) {
5302 basedev = sigma_radio_ifname[0];
5303 basedev_radio = sigma_radio_ifname[1];
5304 if (sigma_radio_ifname[0] &&
5305 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5306 ifname = "ath0";
5307 ifname_dual = "ath1";
5308 } else {
5309 ifname = "ath1";
5310 ifname_dual = "ath0";
5311 }
5312 }
5313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005314 if (dut->ap_countrycode[0]) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005315 run_iwpriv(dut, basedev, "setCountry %s", dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005316 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5317 }
5318
5319 for (i = 0; i < NUM_AP_AC; i++) {
5320 if (dut->ap_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005321 run_iwpriv(dut, ifname, "cwmin %d 0 %d", i,
5322 dut->ap_qos[i].cwmin);
5323 run_iwpriv(dut, ifname, "cwmax %d 0 %d", i,
5324 dut->ap_qos[i].cwmax);
5325 run_iwpriv(dut, ifname, "aifs %d 0 %d", i,
5326 dut->ap_qos[i].aifs);
5327 run_iwpriv(dut, ifname, "txoplimit %d 0 %d", i,
5328 dut->ap_qos[i].txop);
5329 run_iwpriv(dut, ifname, "acm %d 0 %d", i,
5330 dut->ap_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005331 }
5332 }
5333
5334 for (i = 0; i < NUM_AP_AC; i++) {
5335 if (dut->ap_sta_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005336 run_iwpriv(dut, ifname, "cwmin %d 1 %d", i,
5337 dut->ap_sta_qos[i].cwmin);
5338 run_iwpriv(dut, ifname, "cwmax %d 1 %d", i,
5339 dut->ap_sta_qos[i].cwmax);
5340 run_iwpriv(dut, ifname, "aifs %d 1 %d", i,
5341 dut->ap_sta_qos[i].aifs);
5342 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", i,
5343 dut->ap_sta_qos[i].txop);
5344 run_iwpriv(dut, ifname, "acm %d 1 %d", i,
5345 dut->ap_sta_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005346 }
5347 }
5348
5349 if (dut->ap_disable_protection == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005350 run_iwpriv(dut, ifname, "enablertscts 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005351 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5352 }
5353
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005354 if (dut->ap_ldpc == VALUE_ENABLED)
5355 run_iwpriv(dut, ifname, "ldpc 3");
5356 else if (dut->ap_ldpc == VALUE_DISABLED)
5357 run_iwpriv(dut, ifname, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005358
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005359 if (dut->ap_ampdu == VALUE_ENABLED)
5360 run_iwpriv(dut, ifname, "ampdu 1");
5361 else if (dut->ap_ampdu == VALUE_DISABLED)
5362 run_iwpriv(dut, ifname, "ampdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005363
5364 if (dut->ap_ampdu_exp) {
5365 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005366 run_iwpriv(dut, ifname, "vhtmaxampdu %d",
5367 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005368 } else {
5369 /* 11N */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005370 run_iwpriv(dut, ifname, "maxampdu %d",
5371 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005372 }
5373 }
5374
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005375 if (dut->ap_noack == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005376 run_iwpriv(dut, ifname, "noackpolicy 0 0 1");
5377 run_iwpriv(dut, ifname, "noackpolicy 1 0 1");
5378 run_iwpriv(dut, ifname, "noackpolicy 2 0 1");
5379 run_iwpriv(dut, ifname, "noackpolicy 3 0 1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005380 } else if (dut->ap_noack == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005381 run_iwpriv(dut, ifname, "noackpolicy 0 0 0");
5382 run_iwpriv(dut, ifname, "noackpolicy 1 0 0");
5383 run_iwpriv(dut, ifname, "noackpolicy 2 0 0");
5384 run_iwpriv(dut, ifname, "noackpolicy 3 0 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005385 }
5386
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005387 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map)
5388 run_iwpriv(dut, ifname, "vht_mcsmap 0x%04x",
5389 dut->ap_vhtmcs_map);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005390
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005391 if (dut->ap_amsdu == VALUE_ENABLED)
5392 run_iwpriv(dut, ifname, "amsdu 2");
5393 else if (dut->ap_amsdu == VALUE_DISABLED)
5394 run_iwpriv(dut, ifname, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005395
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005396 if (dut->ap_rx_amsdu == VALUE_ENABLED)
5397 run_iwpriv(dut, basedev_radio, "rx_amsdu 1");
5398 else if (dut->ap_rx_amsdu == VALUE_DISABLED)
5399 run_iwpriv(dut, basedev_radio, "rx_amsdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005400
5401 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005402 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5403 dut->ap_ampdu == VALUE_DISABLED &&
5404 dut->ap_amsdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005405 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005406
5407 snprintf(buf, sizeof(buf),
5408 "wifitool %s senddelba 1 0 1 4", ifname);
5409 if (system(buf) != 0) {
5410 sigma_dut_print(dut, DUT_MSG_ERROR,
5411 "wifitool senddelba failed");
5412 }
5413
5414 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5415 ifname);
5416 if (system(buf) != 0) {
5417 sigma_dut_print(dut, DUT_MSG_ERROR,
5418 "wifitool sendsingleamsdu failed");
5419 }
5420
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005421 run_iwpriv(dut, ifname, "amsdu 10");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005422 }
5423
5424 if (dut->ap_mode == AP_11ac) {
5425 int chwidth, nss;
5426
5427 switch (dut->ap_chwidth) {
5428 case AP_20:
5429 chwidth = 0;
5430 break;
5431 case AP_40:
5432 chwidth = 1;
5433 break;
5434 case AP_80:
5435 chwidth = 2;
5436 break;
5437 case AP_160:
5438 chwidth = 3;
5439 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005440 case AP_80_80:
5441 chwidth = 3;
5442 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005443 default:
5444 chwidth = 0;
5445 break;
5446 }
5447
5448 switch (dut->ap_tx_streams) {
5449 case 1:
5450 nss = 1;
5451 break;
5452 case 2:
5453 nss = 2;
5454 break;
5455 case 3:
5456 nss = 3;
5457 break;
5458 case 4:
5459 nss = 4;
5460 break;
5461 default:
5462 nss = 3;
5463 break;
5464 }
5465
5466 if (dut->ap_fixed_rate) {
5467 if (nss == 4)
5468 ath_disable_txbf(dut, ifname);
5469
5470 /* Set the nss */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005471 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005472
5473 /* Set the channel width */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005474 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005475
5476 /* Set the VHT MCS */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005477 run_iwpriv(dut, ifname, "vhtmcs %d", dut->ap_mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005478 }
5479 }
5480
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005481 if (dut->ap_dyn_bw_sig == VALUE_ENABLED)
5482 run_iwpriv(dut, ifname, "cwmenable 1");
5483 else if (dut->ap_dyn_bw_sig == VALUE_DISABLED)
5484 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005485
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005486 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005487 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5488 if (system(buf) != 0) {
5489 sigma_dut_print(dut, DUT_MSG_ERROR,
5490 "iwconfig rts 64 failed");
5491 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005492 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005493 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5494 if (system(buf) != 0) {
5495 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005496 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005497 }
5498 }
5499
5500 if (dut->ap_hs2) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005501 run_iwpriv(dut, ifname, "qbssload 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005502 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5503 }
5504
5505 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5506 unsigned int bssload = 0;
5507
5508 if (dut->ap_bss_load == 1) {
5509 /* STA count: 1, CU: 50, AAC: 65535 */
5510 bssload = 0x0132ffff;
5511 } else if (dut->ap_bss_load == 2) {
5512 /* STA count: 1, CU: 200, AAC: 65535 */
5513 bssload = 0x01c8ffff;
5514 } else if (dut->ap_bss_load == 3) {
5515 /* STA count: 1, CU: 75, AAC: 65535 */
5516 bssload = 0x014bffff;
5517 }
5518
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005519 run_iwpriv(dut, ifname, "hcbssload %u", bssload);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005520 } else if (dut->ap_bss_load == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005521 run_iwpriv(dut, ifname, "qbssload 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005522 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5523 }
5524
5525 if (dut->ap_dgaf_disable) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005526 run_iwpriv(dut, ifname, "dgaf_disable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005527 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
5528 }
5529
5530 if (dut->ap_l2tif) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005531 run_iwpriv(dut, ifname, "l2tif 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005532 snprintf(buf, sizeof(buf),
5533 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
5534 if (system(buf) != 0)
5535 sigma_dut_print(dut, DUT_MSG_ERROR,
5536 "l2tif br failed");
5537
5538 snprintf(buf, sizeof(buf),
5539 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
5540 if (system(buf) != 0)
5541 sigma_dut_print(dut, DUT_MSG_ERROR,
5542 "l2tif brif failed");
5543 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
5544 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005545
5546 if (dut->ap_ndpa_frame == 0) {
5547 snprintf(buf, sizeof(buf),
5548 "wifitool %s beeliner_fw_test 117 192", ifname);
5549 if (system(buf) != 0) {
5550 sigma_dut_print(dut, DUT_MSG_ERROR,
5551 "wifitool beeliner_fw_test 117 192 failed");
5552 }
5553 snprintf(buf, sizeof(buf),
5554 "wifitool %s beeliner_fw_test 118 192", ifname);
5555 if (system(buf) != 0) {
5556 sigma_dut_print(dut, DUT_MSG_ERROR,
5557 "wifitool beeliner_fw_test 117 192 failed");
5558 }
5559 } else if (dut->ap_ndpa_frame == 1) {
5560 /* Driver default - no changes needed */
5561 } else if (dut->ap_ndpa_frame == 2) {
5562 snprintf(buf, sizeof(buf),
5563 "wifitool %s beeliner_fw_test 115 1", ifname);
5564 if (system(buf) != 0) {
5565 sigma_dut_print(dut, DUT_MSG_ERROR,
5566 "wifitool beeliner_fw_test 117 192 failed");
5567 }
5568 snprintf(buf, sizeof(buf),
5569 "wifitool %s beeliner_fw_test 116 1", ifname);
5570 if (system(buf) != 0) {
5571 sigma_dut_print(dut, DUT_MSG_ERROR,
5572 "wifitool beeliner_fw_test 117 192 failed");
5573 }
5574 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005575
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005576 if (dut->ap_rtt == 1)
5577 run_iwpriv(dut, ifname, "enable_rtt 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005578
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005579 if (dut->ap_lci == 1)
5580 run_iwpriv(dut, ifname, "enable_lci 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005581
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005582 if (dut->ap_lcr == 1)
5583 run_iwpriv(dut, ifname, "enable_lcr 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005584
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005585 if (dut->ap_rrm == 1)
5586 run_iwpriv(dut, ifname, "enable_rmm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005587
5588 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
5589 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
5590 }
5591
5592 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
5593 FILE *f;
5594
5595 f = fopen("/tmp/nbr_report.txt", "w");
5596 if (!f) {
5597 sigma_dut_print(dut, DUT_MSG_ERROR,
5598 "Failed to open /tmp/nbr_report.txt");
5599 return;
5600 }
5601
5602 fprintf(f,
5603 "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",
5604 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5605 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5606 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5607 dut->ap_val_opchannel[0]);
5608 fclose(f);
5609
5610 f = fopen("/tmp/ftmrr.txt", "w");
5611 if (!f) {
5612 sigma_dut_print(dut, DUT_MSG_ERROR,
5613 "Failed to open /tmp/ftmrr.txt");
5614 return;
5615 }
5616
5617 fprintf(f,
5618 "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",
5619 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5620 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5621 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5622 dut->ap_val_opchannel[0]);
5623 fclose(f);
5624 }
5625
5626 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
5627 FILE *f;
5628
5629 f = fopen("/tmp/nbr_report.txt", "a");
5630 if (!f) {
5631 sigma_dut_print(dut, DUT_MSG_ERROR,
5632 "Failed to open /tmp/nbr_report.txt");
5633 return;
5634 }
5635 fprintf(f,
5636 "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",
5637 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5638 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5639 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5640 dut->ap_val_opchannel[1]);
5641 fclose(f);
5642
5643 f = fopen("/tmp/ftmrr.txt", "a");
5644 if (!f) {
5645 sigma_dut_print(dut, DUT_MSG_ERROR,
5646 "Failed to open /tmp/ftmrr.txt");
5647 return;
5648 }
5649 fprintf(f,
5650 "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",
5651 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5652 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5653 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5654 dut->ap_val_opchannel[1]);
5655 fclose(f);
5656 }
5657
5658 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
5659 FILE *f;
5660
5661 f = fopen("/tmp/nbr_report.txt", "a");
5662 if (!f) {
5663 sigma_dut_print(dut, DUT_MSG_ERROR,
5664 "Failed to open /tmp/nbr_report.txt");
5665 return;
5666 }
5667
5668 fprintf(f,
5669 "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",
5670 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5671 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5672 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5673 dut->ap_val_opchannel[2]);
5674 fclose(f);
5675
5676 f = fopen("/tmp/ftmrr.txt", "a");
5677 if (!f) {
5678 sigma_dut_print(dut, DUT_MSG_ERROR,
5679 "Failed to open /tmp/ftmrr.txt");
5680 return;
5681 }
5682
5683 fprintf(f,
5684 "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",
5685 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5686 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5687 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5688 dut->ap_val_opchannel[2]);
5689 fclose(f);
5690 }
5691
5692 if (dut->ap_neighap) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005693 run_iwpriv(dut, ifname, "enable_rtt 1");
5694 run_iwpriv(dut, ifname, "enable_lci 1");
5695 run_iwpriv(dut, ifname, "enable_lcr 1");
5696 run_iwpriv(dut, ifname, "enable_rrm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005697 }
5698
5699 if (dut->ap_scan == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005700 run_iwpriv(dut, ifname, "scanentryage 600");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005701 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
5702 run_system(dut, buf);
5703 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07005704
5705 if (dut->ap_set_bssidpref) {
5706 snprintf(buf, sizeof(buf),
5707 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
5708 ifname);
5709 if (system(buf) != 0) {
5710 sigma_dut_print(dut, DUT_MSG_ERROR,
5711 "wifitool clear bssidpref failed");
5712 }
5713 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005714
5715 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
5716 int feature_enable;
5717
5718 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005719 run_iwpriv(dut, ifname, "wnm %d", feature_enable);
5720 run_iwpriv(dut, ifname, "wnm_bss %d", feature_enable);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005721 if (feature_enable) {
5722 const char *extra = "";
5723
5724 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
5725 if (dut->wnm_bss_max_protection ==
5726 VALUE_ENABLED)
5727 extra = " 1";
5728 else
5729 extra = " 0";
5730 }
5731 snprintf(buf, sizeof(buf),
5732 "wlanconfig %s wnm setbssmax %d%s",
5733 ifname, dut->wnm_bss_max_idle_time, extra);
5734 run_system(dut, buf);
5735 }
5736 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005737
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005738 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005739 apply_mbo_pref_ap_list(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005740 run_iwpriv(dut, ifname, "mbo_cel_pref %d",
5741 dut->ap_cell_cap_pref);
5742 run_iwpriv(dut, ifname, "mbocap 0x40");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005743 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005744 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005745
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005746 if (dut->ap_oce == VALUE_ENABLED)
5747 run_iwpriv(dut, ifname, "set_bpr_enable 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005748
5749 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005750 run_iwpriv(dut, ifname, "prb_rate 5500");
5751 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005752 }
5753
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005754 if (dut->ap_oce == VALUE_DISABLED)
5755 run_iwpriv(dut, ifname, "set_bpr_enable 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005756
5757 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005758 run_iwpriv(dut, ifname, "mgmt_rate 1000");
5759 run_iwpriv(dut, ifname, "set_bcn_rate 1000");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005760 }
5761
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005762 if (dut->ap_bcnint)
5763 run_iwpriv(dut, ifname, "bintval %d", dut->ap_bcnint);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005764
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005765 if (dut->ap_filsdscv == VALUE_DISABLED)
5766 run_iwpriv(dut, ifname, "enable_fils 0 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005767
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005768 if (dut->ap_filshlp == VALUE_ENABLED)
5769 run_iwpriv(dut, ifname, "oce_hlp 1");
5770 else if (dut->ap_filshlp == VALUE_DISABLED)
5771 run_iwpriv(dut, ifname, "oce_hlp 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005772
5773 /* When RNR is enabled, also enable apchannelreport, background scan */
5774 if (dut->ap_rnr == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005775 run_iwpriv(dut, ifname, "rnr 1");
5776 run_iwpriv(dut, ifname, "rnr_tbtt 1");
5777 run_iwpriv(dut, ifname, "apchanrpt 1");
5778 run_iwpriv(dut, basedev, "acs_ctrlflags 0x4");
5779 run_iwpriv(dut, basedev, "acs_scanintvl 60");
5780 run_iwpriv(dut, basedev, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005781 if (dut->ap_is_dual == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005782 run_iwpriv(dut, ifname_dual, "rnr 1");
5783 run_iwpriv(dut, ifname_dual, "rnr_tbtt 1");
5784 run_iwpriv(dut, ifname_dual, "apchanrpt 1");
5785 run_iwpriv(dut, basedev_radio, "acs_ctrlflags 0x4");
5786 run_iwpriv(dut, basedev_radio, "acs_scanintvl 60");
5787 run_iwpriv(dut, basedev_radio, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005788 }
5789 }
5790
5791 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005792 run_iwpriv(dut, ifname, "qbssload 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005793 snprintf(buf, sizeof(buf),
5794 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
5795 ifname, dut->ap_blestacnt & 0xFF,
5796 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5797 dut->ap_ble_admit_cap & 0xFF,
5798 dut->ap_ble_admit_cap >> 8);
5799 run_system(dut, buf);
5800 snprintf(buf, sizeof(buf),
5801 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
5802 ifname, dut->ap_blestacnt & 0xFF,
5803 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5804 dut->ap_ble_admit_cap & 0xFF,
5805 dut->ap_ble_admit_cap >> 8);
5806 run_system(dut, buf);
5807 }
5808
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005809 if (dut->ap_esp == VALUE_ENABLED)
5810 run_iwpriv(dut, basedev, "esp_period 5");
5811 else if (dut->ap_esp == VALUE_DISABLED)
5812 run_iwpriv(dut, basedev, "esp_period 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005813
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005814 if (dut->ap_datappdudura)
5815 run_iwpriv(dut, basedev, "esp_ppdu_dur %d",
5816 dut->ap_datappdudura);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005817
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005818 if (dut->ap_airtimefract)
5819 run_iwpriv(dut, basedev, "esp_airtime %d",
5820 dut->ap_airtimefract);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005821
5822 if (dut->ap_dhcp_stop) {
5823 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
5824 run_system(dut, buf);
5825 }
5826
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005827 if (dut->ap_bawinsize)
5828 run_iwpriv(dut, basedev, "esp_ba_window %d", dut->ap_bawinsize);
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005829
5830 if (dut->program == PROGRAM_DPP) {
5831 if (dut->ap_interface_2g == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005832 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
5833 run_iwpriv(dut, ifname, "prb_rate 5500");
5834 run_iwpriv(dut, ifname, "mgmt_rate 5500");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005835 }
5836
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005837 run_iwpriv(dut, basedev, "set_rxfilter 0xffffffff");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005838 dut->hostapd_running = 1;
5839 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07005840
5841 if (dut->ap_he_ppdu == PPDU_MU) {
5842 run_system_wrapper(
5843 dut, "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
5844 ifname);
5845 run_system_wrapper(
5846 dut, "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
5847 ifname);
5848 run_system_wrapper(dut,
5849 "wifitool %s setUnitTestCmd 0x47 2 8 0",
5850 ifname);
5851 run_system_wrapper(dut,
5852 "wifitool %s setUnitTestCmd 0x47 2 29 0",
5853 ifname);
5854 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005855}
5856
5857
5858static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
5859 struct sigma_conn *conn,
5860 struct sigma_cmd *cmd)
5861{
5862 /* const char *name = get_param(cmd, "NAME"); */
5863 char buf[100];
5864 struct stat s;
5865 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
Jouni Malinen3aa72862019-05-29 23:14:51 +03005866 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867
5868 if (stat("/proc/athversion", &s) == 0) {
5869 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
5870 run_system(dut, "apdown");
5871 }
5872
5873 cmd_ath_ap_radio_config(dut);
5874
5875 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
5876 run_system(dut, buf);
5877
5878 switch (dut->ap_key_mgmt) {
5879 case AP_OPEN:
5880 if (dut->ap_cipher == AP_WEP) {
5881 run_system(dut, "cfg -a AP_SECMODE=WEP");
5882 run_system(dut, "cfg -a AP_SECFILE=NONE");
5883 /* shared auth mode not supported */
5884 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5885 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5886 snprintf(buf, sizeof(buf),
5887 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5888 dut->ap_wepkey);
5889 run_system(dut, buf);
5890 snprintf(buf, sizeof(buf),
5891 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5892 dut->ap_wepkey);
5893 run_system(dut, buf);
5894 } else {
5895 run_system(dut, "cfg -a AP_SECMODE=None");
5896 }
5897 break;
5898 case AP_WPA2_PSK:
5899 case AP_WPA2_PSK_MIXED:
5900 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005901 case AP_WPA2_SAE:
5902 case AP_WPA2_PSK_SAE:
5903 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5904 dut->ap_key_mgmt == AP_WPA2_SAE ||
5905 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005906 run_system(dut, "cfg -a AP_WPA=2");
5907 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5908 run_system(dut, "cfg -a AP_WPA=3");
5909 else
5910 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03005911 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005912 run_system(dut, "cfg -a AP_SECMODE=WPA");
5913 run_system(dut, "cfg -a AP_SECFILE=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03005914 res = snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
5915 dut->ap_passphrase);
5916 if (res < 0 || res >= sizeof(buf))
5917 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005918 run_system(dut, buf);
5919 if (dut->ap_cipher == AP_CCMP_TKIP)
5920 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
5921 else if (dut->ap_cipher == AP_TKIP)
5922 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5923 else
5924 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5925 break;
5926 case AP_WPA2_EAP:
5927 case AP_WPA2_EAP_MIXED:
5928 case AP_WPA_EAP:
5929 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5930 run_system(dut, "cfg -a AP_WPA=2");
5931 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5932 run_system(dut, "cfg -a AP_WPA=3");
5933 else
5934 run_system(dut, "cfg -a AP_WPA=1");
5935 run_system(dut, "cfg -a AP_SECMODE=WPA");
5936 run_system(dut, "cfg -a AP_SECFILE=EAP");
5937 if (dut->ap_cipher == AP_CCMP_TKIP)
5938 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
5939 else if (dut->ap_cipher == AP_TKIP)
5940 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5941 else
5942 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5943 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
5944 dut->ap_radius_ipaddr);
5945 run_system(dut, buf);
5946 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
5947 dut->ap_radius_port);
5948 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03005949 res = snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
5950 dut->ap_radius_password);
5951 if (res < 0 || res >= sizeof(buf))
5952 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005953 run_system(dut, buf);
5954 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03005955 case AP_WPA2_EAP_OSEN:
5956 /* TODO */
5957 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
5958 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03005959 case AP_SUITEB:
5960 /* TODO */
5961 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
5962 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03005963 case AP_WPA2_OWE:
5964 /* TODO */
5965 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
5966 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03005967 case AP_WPA2_FT_EAP:
5968 case AP_WPA2_FT_PSK:
5969 case AP_WPA2_EAP_SHA256:
5970 case AP_WPA2_PSK_SHA256:
5971 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03005972 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03005973 /* TODO */
5974 send_resp(dut, conn, SIGMA_ERROR,
5975 "errorCode,Unsupported KeyMgnt value");
5976 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005977 }
5978
5979 if (dut->ap_is_dual) {
5980 /* ath1 settings in case of dual */
5981 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
5982 dut->ap_ssid);
5983 run_system(dut, buf);
5984
5985 switch (dut->ap_key_mgmt) {
5986 case AP_OPEN:
5987 if (dut->ap_cipher == AP_WEP) {
5988 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
5989 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
5990 /* shared auth mode not supported */
5991 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5992 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5993 snprintf(buf, sizeof(buf),
5994 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5995 dut->ap_wepkey);
5996 run_system(dut, buf);
5997 snprintf(buf, sizeof(buf),
5998 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5999 dut->ap_wepkey);
6000 run_system(dut, buf);
6001 } else {
6002 run_system(dut, "cfg -a AP_SECMODE_2=None");
6003 }
6004 break;
6005 case AP_WPA2_PSK:
6006 case AP_WPA2_PSK_MIXED:
6007 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006008 case AP_WPA2_SAE:
6009 case AP_WPA2_PSK_SAE:
6010 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6011 dut->ap_key_mgmt == AP_WPA2_SAE ||
6012 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006013 run_system(dut, "cfg -a AP_WPA_2=2");
6014 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6015 run_system(dut, "cfg -a AP_WPA_2=3");
6016 else
6017 run_system(dut, "cfg -a AP_WPA_2=1");
6018 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006019 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006020 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6021 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006022 res = snprintf(buf, sizeof(buf),
6023 "cfg -a 'PSK_KEY_2=%s'",
6024 dut->ap_passphrase);
6025 if (res < 0 || res >= sizeof(buf))
6026 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027 run_system(dut, buf);
6028 if (dut->ap_cipher == AP_CCMP_TKIP)
6029 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6030 else if (dut->ap_cipher == AP_TKIP)
6031 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6032 else
6033 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6034 break;
6035 case AP_WPA2_EAP:
6036 case AP_WPA2_EAP_MIXED:
6037 case AP_WPA_EAP:
6038 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6039 run_system(dut, "cfg -a AP_WPA_2=2");
6040 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6041 run_system(dut, "cfg -a AP_WPA_2=3");
6042 else
6043 run_system(dut, "cfg -a AP_WPA_2=1");
6044 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6045 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6046 if (dut->ap_cipher == AP_CCMP_TKIP)
6047 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6048 else if (dut->ap_cipher == AP_TKIP)
6049 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6050 else
6051 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6052
6053 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6054 dut->ap_radius_ipaddr);
6055 run_system(dut, buf);
6056 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6057 dut->ap_radius_port);
6058 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006059 res = snprintf(buf, sizeof(buf),
6060 "cfg -a AP_AUTH_SECRET_2=%s",
6061 dut->ap_radius_password);
6062 if (res < 0 || res >= sizeof(buf))
6063 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006064 run_system(dut, buf);
6065 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006066 case AP_WPA2_EAP_OSEN:
6067 /* TODO */
6068 sigma_dut_print(dut, DUT_MSG_ERROR,
6069 "EAP+OSEN not supported");
6070 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006071 case AP_SUITEB:
6072 /* TODO */
6073 sigma_dut_print(dut, DUT_MSG_ERROR,
6074 "SuiteB not supported");
6075 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006076 case AP_WPA2_OWE:
6077 /* TODO */
6078 sigma_dut_print(dut, DUT_MSG_ERROR,
6079 "OWE not supported");
6080 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006081 case AP_WPA2_FT_EAP:
6082 case AP_WPA2_FT_PSK:
6083 case AP_WPA2_EAP_SHA256:
6084 case AP_WPA2_PSK_SHA256:
6085 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006086 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006087 /* TODO */
6088 send_resp(dut, conn, SIGMA_ERROR,
6089 "errorCode,Unsupported KeyMgnt value");
6090 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006091 }
6092
6093 /* wifi0 settings in case of dual */
6094 run_system(dut, "cfg -a AP_RADIO_ID=0");
6095 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6096 run_system(dut, "cfg -a AP_STARTMODE=dual");
6097 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6098 run_system(dut, "cfg -a TX_CHAINMASK=7");
6099 run_system(dut, "cfg -a RX_CHAINMASK=7");
6100 }
6101
6102 switch (dut->ap_pmf) {
6103 case AP_PMF_DISABLED:
6104 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6105 run_system(dut, buf);
6106 break;
6107 case AP_PMF_OPTIONAL:
6108 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6109 run_system(dut, buf);
6110 break;
6111 case AP_PMF_REQUIRED:
6112 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6113 run_system(dut, buf);
6114 break;
6115 }
6116 if (dut->ap_add_sha256) {
6117 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6118 run_system(dut, buf);
6119 } else {
6120 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6121 run_system(dut, buf);
6122 }
6123
6124 if (dut->ap_hs2)
6125 run_system(dut, "cfg -a AP_HOTSPOT=1");
6126 else
6127 run_system(dut, "cfg -r AP_HOTSPOT");
6128
6129 if (dut->ap_interworking) {
6130 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6131 dut->ap_access_net_type);
6132 run_system(dut, buf);
6133 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6134 dut->ap_internet);
6135 run_system(dut, buf);
6136 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6137 dut->ap_venue_group);
6138 run_system(dut, buf);
6139 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6140 dut->ap_venue_type);
6141 run_system(dut, buf);
6142 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6143 dut->ap_hessid);
6144 run_system(dut, buf);
6145
6146 if (dut->ap_roaming_cons[0]) {
6147 char *second, *rc;
6148 rc = strdup(dut->ap_roaming_cons);
6149 if (rc == NULL)
6150 return 0;
6151
6152 second = strchr(rc, ';');
6153 if (second)
6154 *second++ = '\0';
6155
6156 snprintf(buf, sizeof(buf),
6157 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6158 run_system(dut, buf);
6159
6160 if (second) {
6161 snprintf(buf, sizeof(buf),
6162 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6163 "=%s", second);
6164 run_system(dut, buf);
6165 }
6166 free(rc);
6167 } else {
6168 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6169 run_system(dut,
6170 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6171 }
6172 } else {
6173 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6174 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6175 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6176 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6177 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6178 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6179 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6180 }
6181
6182 if (dut->ap_proxy_arp)
6183 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6184 else
6185 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6186 if (dut->ap_dgaf_disable)
6187 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6188 else
6189 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6190
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006191 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006192 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006193 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006194 run_system(dut, buf);
6195
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006196 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006197 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6198 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6199
Jouni Malinen3aa72862019-05-29 23:14:51 +03006200 res = snprintf(buf, sizeof(buf),
6201 "cfg -a AP_AUTH_SERVER_2=%s",
6202 dut->ap2_radius_ipaddr);
6203 if (res < 0 || res >= sizeof(buf))
6204 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006205 run_system(dut, buf);
6206
Jouni Malinen3aa72862019-05-29 23:14:51 +03006207 res = snprintf(buf, sizeof(buf),
6208 "cfg -a AP_AUTH_PORT_2=%d",
6209 dut->ap2_radius_port);
6210 if (res < 0 || res >= sizeof(buf))
6211 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006212 run_system(dut, buf);
6213
Jouni Malinen3aa72862019-05-29 23:14:51 +03006214 res = snprintf(buf, sizeof(buf),
6215 "cfg -a AP_AUTH_SECRET_2=%s",
6216 dut->ap2_radius_password);
6217 if (res < 0 || res >= sizeof(buf))
6218 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006219 run_system(dut, buf);
6220 } else {
6221 run_system(dut, "cfg -a AP_SECMODE_2=None");
6222 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
6223 run_system(dut, "cfg -r AP_AUTH_PORT_2");
6224 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
6225 }
6226
6227 run_system(dut, "cfg -a AP_STARTMODE=multi");
6228 }
6229
6230 run_system(dut, "cfg -c");
6231
6232 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
6233 if (system("apup") != 0) {
6234 /* to be debugged why apup returns error
6235 send_resp(dut, conn, SIGMA_ERROR,
6236 "errorCode,apup failed");
6237 return 0;
6238 */
6239 }
6240 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
6241
6242 if (dut->ap_key_mgmt != AP_OPEN) {
6243 int res;
6244 /* allow some time for hostapd to start before returning
6245 * success */
6246 usleep(500000);
6247 if (run_hostapd_cli(dut, "ping") != 0) {
6248 send_resp(dut, conn, SIGMA_ERROR,
6249 "errorCode,Failed to talk to hostapd");
6250 return 0;
6251 }
6252
6253 if (dut->ap_hs2 && !dut->ap_anqpserver) {
6254 /* the cfg app doesn't like ";" in the variables */
6255 res = ath_ap_append_hostapd_conf(dut);
6256 if (res < 0)
6257 return res;
6258
6259 /* wait for hostapd to be ready */
6260 usleep(500000);
6261 if (run_hostapd_cli(dut, "ping") != 0) {
6262 send_resp(dut, conn, SIGMA_ERROR,
6263 "errorCode,Failed to talk to "
6264 "hostapd");
6265 return 0;
6266 }
6267 }
6268 }
6269
6270 ath_ap_set_params(dut);
6271
6272 if (dut->ap_anqpserver)
6273 return cmd_ath_ap_anqpserver_start(dut);
6274
6275 if (dut->ap2_proxy_arp)
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006276 run_iwpriv(dut, ifname, "proxy_arp 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006277
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006278 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip)
6279 run_iwpriv(dut, ifname, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006280
6281 return 1;
6282}
6283
6284
6285static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
6286 const char *ifname)
6287{
6288 char buf[200];
6289
6290 if (!chain || !ifname)
6291 return -2;
6292
6293 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6294 if (system(buf) != 0) {
6295 sigma_dut_print(dut, DUT_MSG_ERROR,
6296 "Failed to set ebtables rules, RULE-1, %s",
6297 chain);
6298 return -2;
6299 }
6300
6301 snprintf(buf, sizeof(buf),
6302 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6303 chain, ifname);
6304 if (system(buf) != 0) {
6305 sigma_dut_print(dut, DUT_MSG_ERROR,
6306 "Failed to set ebtables rules, RULE-2, %s",
6307 chain);
6308 return -2;
6309 }
6310
6311 snprintf(buf, sizeof(buf),
6312 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
6313 chain, ifname);
6314 if (system(buf) != 0) {
6315 sigma_dut_print(dut, DUT_MSG_ERROR,
6316 "Failed to set ebtables rules, RULE-3, %s",
6317 chain);
6318 return -2;
6319 }
6320
6321 snprintf(buf, sizeof(buf),
6322 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
6323 chain, ifname);
6324 if (system(buf) != 0) {
6325 sigma_dut_print(dut, DUT_MSG_ERROR,
6326 "Failed to set ebtables rules, RULE-4, %s",
6327 chain);
6328 return -2;
6329 }
6330
6331 return 0;
6332}
6333
6334
6335static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
6336 const char *chain,
6337 const char *ifname)
6338{
6339 char buf[200];
6340
6341 if (!chain || !ifname)
6342 return -2;
6343
6344 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6345 if (system(buf) != 0) {
6346 sigma_dut_print(dut, DUT_MSG_ERROR,
6347 "Failed to set ebtables rules, RULE-5, %s",
6348 chain);
6349 return -2;
6350 }
6351
6352 snprintf(buf, sizeof(buf),
6353 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6354 chain, ifname);
6355 if (system(buf) != 0) {
6356 sigma_dut_print(dut, DUT_MSG_ERROR,
6357 "Failed to set ebtables rules, RULE-6, %s",
6358 chain);
6359 return -2;
6360 }
6361
6362 snprintf(buf, sizeof(buf),
6363 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
6364 chain, ifname);
6365 if (system(buf) != 0) {
6366 sigma_dut_print(dut, DUT_MSG_ERROR,
6367 "Failed to set ebtables rules, RULE-7, %s",
6368 chain);
6369 return -2;
6370 }
6371
6372 snprintf(buf, sizeof(buf),
6373 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
6374 chain, ifname);
6375 if (system(buf) != 0) {
6376 sigma_dut_print(dut, DUT_MSG_ERROR,
6377 "Failed to set ebtables rules, RULE-8, %s",
6378 chain);
6379 return -2;
6380 }
6381
6382 return 0;
6383}
6384
6385
Jouni Malinendbbc2c42018-11-14 23:55:41 +02006386static void set_ebtables_forward_drop(struct sigma_dut *dut,
6387 const char *ifname, const char *ifname2)
6388{
6389 char buf[128];
6390
6391 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6392 ifname, ifname2);
6393 if (system(buf) != 0)
6394 sigma_dut_print(dut, DUT_MSG_ERROR,
6395 "Failed to set ebtables rule");
6396
6397 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6398 ifname2, ifname);
6399 if (system(buf) != 0)
6400 sigma_dut_print(dut, DUT_MSG_ERROR,
6401 "Failed to set ebtables rule");
6402}
6403
6404
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006405static int check_channel(int channel)
6406{
6407 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
6408 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
6409 161, 165 };
6410 int num_chan = sizeof(channel_list) / sizeof(int);
6411 int i;
6412
6413 for (i = 0; i < num_chan; i++) {
6414 if (channel == channel_list[i])
6415 return i;
6416 }
6417
6418 return -1;
6419}
6420
6421
6422static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
6423{
6424 int ch_base;
6425 int period;
6426
6427 if (check_channel(channel) < 0)
6428 return -1;
6429
6430 if (channel >= 36 && channel <= 64)
6431 ch_base = 36;
6432 else if (channel >= 100 && channel <= 144)
6433 ch_base = 100;
6434 else
6435 ch_base = 149;
6436
6437 period = channel % ch_base * 5 / chwidth;
6438 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
6439}
6440
6441
6442static int is_ht40plus_chan(int chan)
6443{
6444 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
6445 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
6446 chan == 132 || chan == 149 || chan == 157;
6447}
6448
6449
6450static int is_ht40minus_chan(int chan)
6451{
6452 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
6453 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
6454 chan == 136 || chan == 153 || chan == 161;
6455}
6456
6457
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05306458static int get_5g_channel_freq(int chan)
6459{
6460 return 5000 + chan * 5;
6461}
6462
6463
Jouni Malinen3d633da2017-09-14 22:19:21 +03006464static const char * hostapd_cipher_name(enum ap_cipher cipher)
6465{
6466 switch (cipher) {
6467 case AP_CCMP:
6468 return "CCMP";
6469 case AP_TKIP:
6470 return "TKIP";
6471 case AP_CCMP_TKIP:
6472 return "CCMP TKIP";
6473 case AP_GCMP_256:
6474 return "GCMP-256";
6475 case AP_GCMP_128:
6476 return "GCMP";
6477 case AP_CCMP_256:
6478 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02006479 case AP_CCMP_128_GCMP_256:
6480 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006481 default:
6482 return "UNKNOWN";
6483 }
6484}
6485
6486
6487static const char *
6488hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
6489{
6490 switch (cipher) {
6491 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03006492 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006493 case AP_BIP_CMAC_256:
6494 return "BIP-CMAC-256";
6495 case AP_BIP_GMAC_128:
6496 return "BIP-GMAC-128";
6497 case AP_BIP_CMAC_128:
6498 return "AES-128-CMAC";
6499 default:
6500 return "UNKNOWN";
6501 }
6502}
6503
6504
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02006505static int ap_set_60g_ese(struct sigma_dut *dut, int count,
6506 struct sigma_ese_alloc *allocs)
6507{
6508 switch (get_driver_type()) {
6509#ifdef __linux__
6510 case DRIVER_WIL6210:
6511 return wil6210_set_ese(dut, count, allocs);
6512#endif /* __linux__ */
6513 default:
6514 sigma_dut_print(dut, DUT_MSG_ERROR,
6515 "Unsupported ap_set_60g_ese with the current driver");
6516 return -1;
6517 }
6518}
6519
6520
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006521static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6522{
6523 switch (get_driver_type()) {
6524#ifdef __linux__
6525 case DRIVER_WIL6210:
6526 return wil6210_set_force_mcs(dut, force, mcs);
6527#endif /* __linux__ */
6528 default:
6529 sigma_dut_print(dut, DUT_MSG_ERROR,
6530 "Unsupported ap_set_force_mcs with the current driver");
6531 return -1;
6532 }
6533}
6534
6535
Jouni Malinenf7222712019-06-13 01:50:21 +03006536enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
6537 struct sigma_conn *conn,
6538 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006539{
6540 /* const char *name = get_param(cmd, "NAME"); */
6541 FILE *f;
6542 const char *ifname;
6543 char buf[500];
6544 char path[100];
6545 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03006546 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05306547#ifdef ANDROID
6548 struct group *gr;
6549#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006550
6551 drv = get_driver_type();
6552
6553 if (dut->mode == SIGMA_MODE_STATION) {
6554 stop_sta_mode(dut);
6555 sleep(1);
6556 }
6557
6558 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
6559 snprintf(buf, sizeof(buf), "ifconfig %s down",
6560 dut->sniffer_ifname);
6561 if (system(buf) != 0) {
6562 sigma_dut_print(dut, DUT_MSG_INFO,
6563 "Failed to run '%s'", buf);
6564 }
6565 snprintf(buf, sizeof(buf), "iw dev %s set type station",
6566 dut->sniffer_ifname);
6567 if (system(buf) != 0) {
6568 sigma_dut_print(dut, DUT_MSG_INFO,
6569 "Failed to run '%s'", buf);
6570 }
6571 }
6572
6573 dut->mode = SIGMA_MODE_AP;
6574
6575 if (drv == DRIVER_ATHEROS)
6576 return cmd_ath_ap_config_commit(dut, conn, cmd);
6577 if (drv == DRIVER_WCN)
6578 return cmd_wcn_ap_config_commit(dut, conn, cmd);
6579 if (drv == DRIVER_OPENWRT)
6580 return cmd_owrt_ap_config_commit(dut, conn, cmd);
6581
6582 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
6583 if (f == NULL) {
6584 sigma_dut_print(dut, DUT_MSG_ERROR,
6585 "%s: Failed to open sigma_dut-ap.conf",
6586 __func__);
6587 return -2;
6588 }
6589 switch (dut->ap_mode) {
6590 case AP_11g:
6591 case AP_11b:
6592 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306593 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
6594 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
6595 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006596 ifname = sigma_main_ifname;
6597 fprintf(f, "hw_mode=g\n");
6598 break;
6599 case AP_11a:
6600 case AP_11na:
6601 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306602 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006603 if (sigma_main_ifname)
6604 ifname = sigma_main_ifname;
6605 else
6606 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306607 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608 if (if_nametoindex("wlan1") > 0)
6609 ifname = "wlan1";
6610 else
6611 ifname = "wlan0";
6612 } else {
6613 ifname = get_main_ifname();
6614 }
6615 fprintf(f, "hw_mode=a\n");
6616 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02006617 case AP_11ad:
6618 ifname = get_main_ifname();
6619 fprintf(f, "hw_mode=ad\n");
6620 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006621 default:
6622 fclose(f);
6623 return -1;
6624 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006625 if (dut->hostapd_ifname)
6626 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006627
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306628 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006629 fprintf(f, "driver=nl80211\n");
6630
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306631 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6632 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006633 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05306634 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
6635
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006636 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306637 if (dut->ap_mode == AP_11ng &&
6638 (dut->ap_chwidth == AP_40 ||
6639 (dut->ap_chwidth == AP_AUTO &&
6640 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006641 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306642 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306644 ht40minus = 1;
6645 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006646 }
6647
6648 /* configure ht_capab based on channel width */
6649 if (dut->ap_mode == AP_11na &&
6650 (dut->ap_chwidth == AP_40 ||
6651 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306652 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006653 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306654 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306656 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006657 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306658
6659 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306660 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306661
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306662 /* Overwrite the ht_capab with offset value if configured */
6663 if (dut->ap_chwidth == AP_40 &&
6664 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
6665 ht40plus = 1;
6666 ht40minus = 0;
6667 } else if (dut->ap_chwidth == AP_40 &&
6668 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
6669 ht40minus = 1;
6670 ht40plus = 0;
6671 }
6672
Tamizh chelvam431c6002017-03-07 17:07:16 +05306673 fprintf(f, "ht_capab=%s%s%s\n",
6674 ht40plus ? "[HT40+]" : "",
6675 ht40minus ? "[HT40-]" : "",
6676 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677 }
6678
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306679 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6680 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006681 dut->ap_mode == AP_11ac) {
Hu Wang29392102019-07-03 15:41:12 +08006682 int ht40plus = 0, ht40minus = 0;
6683
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006684 fprintf(f, "ieee80211ac=1\n"
Hu Wang29392102019-07-03 15:41:12 +08006685 "ieee80211n=1\n");
6686
6687 /* configure ht_capab based on channel width */
6688 if (dut->ap_chwidth != AP_20) {
6689 if (is_ht40plus_chan(dut->ap_channel))
6690 ht40plus = 1;
6691 else if (is_ht40minus_chan(dut->ap_channel))
6692 ht40minus = 1;
6693
6694 fprintf(f, "ht_capab=%s%s\n",
6695 ht40plus ? "[HT40+]" : "",
6696 ht40minus ? "[HT40-]" : "");
6697 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006698 }
6699
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306700 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6701 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006702 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
6703 if (dut->ap_countrycode[0]) {
6704 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
6705 fprintf(f, "ieee80211d=1\n");
6706 fprintf(f, "ieee80211h=1\n");
6707 }
6708 }
6709
6710 fprintf(f, "interface=%s\n", ifname);
6711 if (dut->bridge)
6712 fprintf(f, "bridge=%s\n", dut->bridge);
6713 fprintf(f, "channel=%d\n", dut->ap_channel);
6714
6715 if (sigma_hapd_ctrl)
6716 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
6717 else
6718 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
6719
6720 if (dut->ap_ssid[0])
6721 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6722 else
6723 fprintf(f, "ssid=QCA AP OOB\n");
6724 if (dut->ap_bcnint)
6725 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
6726
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006727 if (dut->ap_akm_values) {
6728 struct {
6729 int akm;
6730 const char *str;
6731 } akms[] = {
6732 { AKM_WPA_EAP, "WPA-EAP" },
6733 { AKM_WPA_PSK, "WPA-PSK" },
6734 { AKM_FT_EAP, "FT-EAP" },
6735 { AKM_FT_PSK, "FT-PSK" },
6736 { AKM_EAP_SHA256, "WPA-EAP-SHA256" },
6737 { AKM_PSK_SHA256, "WPA-PSK-SHA256" },
6738 { AKM_SAE, "SAE" },
6739 { AKM_FT_SAE, "FT-SAE" },
6740 { AKM_SUITE_B, "WPA-EAP-SUITE-B-192" },
6741 { AKM_FT_SUITE_B, "FT-EAP-SHA384" },
6742 { AKM_FILS_SHA256, "FILS-SHA256" },
6743 { AKM_FILS_SHA384, "FILS-SHA384" },
6744 { AKM_FT_FILS_SHA256, "FT-FILS-SHA256" },
6745 { AKM_FT_FILS_SHA384, "FT-FILS-SHA384" },
6746 };
Jouni Malinen8400c082019-04-26 13:26:07 +03006747 int first = 1;
6748 unsigned int i;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006749
6750 fprintf(f, "wpa_key_mgmt=");
6751 for (i = 0; i < ARRAY_SIZE(akms); i++) {
6752 if (dut->ap_akm_values & (1 << akms[i].akm)) {
6753 fprintf(f, "%s%s", first ? "" : " ",
6754 akms[i].str);
6755 first = 0;
6756 }
6757 }
6758 fprintf(f, "\n");
6759 /* TODO: mixed mode and WPAv1 only */
6760 fprintf(f, "wpa=2\n");
6761 fprintf(f, "wpa_pairwise=%s\n",
6762 hostapd_cipher_name(dut->ap_cipher));
6763 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6764 fprintf(f, "group_cipher=%s\n",
6765 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3e255412019-03-28 22:04:08 +02006766 if ((dut->ap_akm_values &
6767 ((1 << AKM_SAE) | (1 << AKM_FT_SAE))) &&
6768 !(dut->ap_akm_values &
6769 ((1 << AKM_WPA_PSK) | (1 << AKM_FT_PSK))) &&
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006770 dut->ap_passphrase[0])
6771 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
6772 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
6773 fprintf(f, "wpa_psk=%s", dut->ap_psk);
6774 else if (dut->ap_passphrase[0])
6775 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinen10ed9e72019-03-28 03:00:11 +02006776 if (dut->ap_akm_values & ((1 << AKM_WPA_EAP) |
Jouni Malinene5393c32019-06-20 01:34:34 +03006777 (1 << AKM_FT_EAP) |
Jouni Malinen10ed9e72019-03-28 03:00:11 +02006778 (1 << AKM_EAP_SHA256) |
6779 (1 << AKM_SUITE_B) |
6780 (1 << AKM_FT_SUITE_B) |
6781 (1 << AKM_FILS_SHA256) |
6782 (1 << AKM_FILS_SHA384) |
6783 (1 << AKM_FT_FILS_SHA256) |
6784 (1 << AKM_FT_FILS_SHA384))) {
6785 fprintf(f, "ieee8021x=1\n");
6786 fprintf(f, "auth_server_addr=%s\n",
6787 dut->ap_radius_ipaddr);
6788 if (dut->ap_radius_port)
6789 fprintf(f, "auth_server_port=%d\n",
6790 dut->ap_radius_port);
6791 fprintf(f, "auth_server_shared_secret=%s\n",
6792 dut->ap_radius_password);
6793 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006794 goto skip_key_mgmt;
6795 }
6796
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797 switch (dut->ap_key_mgmt) {
6798 case AP_OPEN:
6799 if (dut->ap_cipher == AP_WEP)
6800 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
6801 break;
6802 case AP_WPA2_PSK:
6803 case AP_WPA2_PSK_MIXED:
6804 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006805 case AP_WPA2_SAE:
6806 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006807 case AP_WPA2_PSK_SHA256:
6808 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006809 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6810 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006811 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
6812 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
6813 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006814 fprintf(f, "wpa=2\n");
6815 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6816 fprintf(f, "wpa=3\n");
6817 else
6818 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03006819 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6820 key_mgmt = "SAE";
6821 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6822 key_mgmt = "WPA-PSK SAE";
6823 else
6824 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006825 switch (dut->ap_pmf) {
6826 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006827 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6829 break;
6830 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03006831 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006832 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
6833 break;
6834 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03006835 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6836 key_mgmt = "SAE";
6837 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
6838 key_mgmt = "WPA-PSK-SHA256 SAE";
6839 else
6840 key_mgmt = "WPA-PSK-SHA256";
6841 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006842 break;
6843 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03006844 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
6845 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
6846 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
6847 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02006848 fprintf(f, "wpa_pairwise=%s\n",
6849 hostapd_cipher_name(dut->ap_cipher));
6850 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6851 fprintf(f, "group_cipher=%s\n",
6852 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03006853 if (dut->ap_key_mgmt == AP_WPA2_SAE)
6854 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02006855 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
6856 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03006857 else
6858 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006859 break;
6860 case AP_WPA2_EAP:
6861 case AP_WPA2_EAP_MIXED:
6862 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006863 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006864 case AP_WPA2_EAP_SHA256:
6865 case AP_WPA2_FT_EAP:
6866 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006867 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006868 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03006869 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
6870 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
6871 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
6872 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006873 fprintf(f, "wpa=2\n");
6874 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6875 fprintf(f, "wpa=3\n");
6876 else
6877 fprintf(f, "wpa=1\n");
6878 switch (dut->ap_pmf) {
6879 case AP_PMF_DISABLED:
6880 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
6881 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
6882 break;
6883 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006884 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
6885 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
6886 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6887 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006888 break;
6889 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006890 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
6891 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
6892 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006893 break;
6894 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03006895 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
6896 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
6897 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
6898 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
6899 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
6900 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02006901 fprintf(f, "wpa_pairwise=%s\n",
6902 hostapd_cipher_name(dut->ap_cipher));
6903 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6904 fprintf(f, "group_cipher=%s\n",
6905 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006906 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6907 if (dut->ap_radius_port)
6908 fprintf(f, "auth_server_port=%d\n",
6909 dut->ap_radius_port);
6910 fprintf(f, "auth_server_shared_secret=%s\n",
6911 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03006912 if (dut->program == PROGRAM_HS2_R3) {
6913 fprintf(f, "radius_das_port=3799\n");
6914 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
6915 dut->ap_radius_password);
6916 fprintf(f, "radius_das_require_event_timestamp=1\n");
6917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006918 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006919 case AP_SUITEB:
6920 fprintf(f, "ieee8021x=1\n");
6921 fprintf(f, "wpa=2\n");
6922 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03006923 fprintf(f, "wpa_pairwise=%s\n",
6924 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02006925 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6926 fprintf(f, "group_cipher=%s\n",
6927 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03006928 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
6929 fprintf(f, "group_mgmt_cipher=%s\n",
6930 hostapd_group_mgmt_cipher_name(
6931 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03006932 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6933 if (dut->ap_radius_port)
6934 fprintf(f, "auth_server_port=%d\n",
6935 dut->ap_radius_port);
6936 fprintf(f, "auth_server_shared_secret=%s\n",
6937 dut->ap_radius_password);
6938 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006939 case AP_WPA2_OWE:
6940 fprintf(f, "wpa=2\n");
6941 fprintf(f, "wpa_key_mgmt=OWE\n");
6942 fprintf(f, "rsn_pairwise=%s\n",
6943 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03006944 if (dut->ap_sae_groups)
6945 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03006946 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03006947 case AP_OSEN:
6948 fprintf(f, "osen=1\n");
6949 fprintf(f, "disable_dgaf=1\n");
6950 fprintf(f, "wpa_pairwise=%s\n",
6951 hostapd_cipher_name(dut->ap_cipher));
6952 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
6953 fprintf(f, "group_cipher=%s\n",
6954 hostapd_cipher_name(dut->ap_group_cipher));
6955 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
6956 if (dut->ap_radius_port)
6957 fprintf(f, "auth_server_port=%d\n",
6958 dut->ap_radius_port);
6959 fprintf(f, "auth_server_shared_secret=%s\n",
6960 dut->ap_radius_password);
6961 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006962 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006963skip_key_mgmt:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006964
Jouni Malinen09550de2019-03-26 00:24:11 +02006965 if (dut->ap_sae_passwords) {
6966 char *tmp, *pos, *end, *id;
6967
6968 tmp = strdup(dut->ap_sae_passwords);
6969 if (!tmp) {
6970 fclose(f);
6971 return ERROR_SEND_STATUS;
6972 }
6973
6974 pos = tmp;
6975 while (*pos) {
6976 end = strchr(pos, ';');
6977 if (end)
6978 *end = '\0';
6979 id = strchr(pos, ':');
6980 if (id)
6981 *id++ = '\0';
6982
6983 fprintf(f, "sae_password=%s%s%s\n",
6984 pos, id ? "|id=" : "", id ? id : "");
6985 if (!end)
6986 break;
6987 pos = end + 1;
6988 }
6989
6990 free(tmp);
6991 }
6992
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05306993 if (dut->ap_rsn_preauth)
6994 fprintf(f, "rsn_preauth=1\n");
6995
Jouni Malinenb75c5322019-06-14 01:47:43 +03006996 if (dut->ap_pmksa && dut->ap_pmksa_caching)
6997 fprintf(f, "disable_pmksa_caching=1\n");
6998
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006999 switch (dut->ap_pmf) {
7000 case AP_PMF_DISABLED:
7001 break;
7002 case AP_PMF_OPTIONAL:
7003 fprintf(f, "ieee80211w=1\n");
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007004 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7005 (dut->ap_akm_values & (AKM_SAE | AKM_WPA_PSK)) ==
7006 (AKM_SAE | AKM_WPA_PSK))
Jouni Malinen1287cd72018-01-04 17:08:01 +02007007 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007008 break;
7009 case AP_PMF_REQUIRED:
7010 fprintf(f, "ieee80211w=2\n");
7011 break;
7012 }
7013
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007014 if (dut->ap_pmf != AP_PMF_DISABLED &&
7015 dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7016 fprintf(f, "group_mgmt_cipher=%s\n",
7017 hostapd_group_mgmt_cipher_name(
7018 dut->ap_group_mgmt_cipher));
7019
Jouni Malinen6be21c82018-08-01 18:47:24 +03007020 if (ap_ft_enabled(dut)) {
7021 unsigned char own_addr[ETH_ALEN];
7022
7023 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
7024 fprintf(f, "ft_over_ds=0\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007025 if (get_hwaddr(ifname, own_addr) < 0) {
7026 memset(own_addr, 0, ETH_ALEN);
7027 own_addr[0] = 0x02;
7028 }
Jouni Malinenc9674462019-03-26 02:40:19 +02007029 fprintf(f,
7030 "nas_identifier=%02x%02x%02x%02x%02x%02x.nas.example.com\n",
7031 own_addr[0], own_addr[1], own_addr[2],
7032 own_addr[3], own_addr[4], own_addr[5]);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007033 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7034 own_addr[0], own_addr[1], own_addr[2],
7035 own_addr[3], own_addr[4], own_addr[5]);
7036 fprintf(f, "ft_psk_generate_local=1\n");
7037 fprintf(f, "pmk_r1_push=0\n");
7038 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007039 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007040 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007041 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007042 }
7043
Jouni Malinen3c367e82017-06-23 17:01:47 +03007044 if (dut->rsne_override)
7045 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
7046
Jouni Malinen68143132017-09-02 02:34:08 +03007047 if (dut->sae_commit_override)
7048 fprintf(f, "sae_commit_override=%s\n",
7049 dut->sae_commit_override);
7050
Jouni Malinened670f42017-08-31 01:39:28 +03007051 if (dut->ap_sae_groups)
7052 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007053
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007054 if (dut->sae_anti_clogging_threshold >= 0)
7055 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7056 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007057 if (dut->sae_reflection)
7058 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007059
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007060 if (dut->ap_p2p_mgmt)
7061 fprintf(f, "manage_p2p=1\n");
7062
7063 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7064 fprintf(f, "tdls_prohibit=1\n");
7065 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
7066 fprintf(f, "tdls_prohibit_chan_switch=1\n");
7067 if (dut->ap_p2p_cross_connect >= 0) {
7068 fprintf(f, "manage_p2p=1\n"
7069 "allow_cross_connection=%d\n",
7070 dut->ap_p2p_cross_connect);
7071 }
7072
Jouni Malinen4d479c92018-11-06 00:43:36 +02007073 if (dut->ap_l2tif || dut->ap_proxy_arp ||
7074 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075 if (!dut->bridge) {
7076 sigma_dut_print(dut, DUT_MSG_ERROR,
7077 "Bridge must be configured. Run with -b <brname>.");
7078 fclose(f);
7079 return -2;
7080 }
7081 fprintf(f, "ap_isolate=1\n");
7082 }
7083
7084 if (dut->ap_proxy_arp)
7085 fprintf(f, "proxy_arp=1\n");
7086
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307087 if (dut->ap_wme)
7088 fprintf(f, "wmm_enabled=1\n");
7089
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307090 if (dut->ap_wmmps == AP_WMMPS_ON)
7091 fprintf(f, "uapsd_advertisement_enabled=1\n");
7092
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007093 if (dut->ap_hs2) {
7094 if (dut->ap_bss_load) {
7095 char *bss_load;
7096
7097 switch (dut->ap_bss_load) {
7098 case -1:
7099 bss_load = "bss_load_update_period=10";
7100 break;
7101 case 1:
7102 /* STA count: 1, CU: 50, AAC: 65535 */
7103 bss_load = "bss_load_test=1:50:65535";
7104 break;
7105 case 2:
7106 /* STA count: 1, CU: 200, AAC: 65535 */
7107 bss_load = "bss_load_test=1:200:65535";
7108 break;
7109 case 3:
7110 /* STA count: 1, CU: 75, AAC: 65535 */
7111 bss_load = "bss_load_test=1:75:65535";
7112 break;
7113 default:
7114 bss_load = NULL;
7115 break;
7116 }
7117
7118 if (!bss_load) {
7119 fclose(f);
7120 return -2;
7121 }
7122 fprintf(f, "%s\n", bss_load);
7123 }
7124
7125 if (append_hostapd_conf_hs2(dut, f)) {
7126 fclose(f);
7127 return -2;
7128 }
7129 }
7130
7131 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
7132 fclose(f);
7133 return -2;
7134 }
7135
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007136 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137 unsigned char bssid[6];
7138 char ifname2[50];
7139
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307140 if (get_hwaddr(ifname, bssid)) {
7141 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007142 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307143 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03007144 if (bssid[0] & 0x02)
7145 bssid[5] ^= 0x01;
7146 else
7147 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007148
7149 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03007150 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007151 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007152 if (dut->bridge)
7153 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007154
7155 if (drv == DRIVER_LINUX_WCN)
7156 fprintf(f, "use_driver_iface_addr=1\n");
7157 else
7158 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7159 bssid[0], bssid[1], bssid[2], bssid[3],
7160 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007161
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007162 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007163 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05307164 /* Disable DGAF for OSEN BSS */
7165 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007166 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007167 if (strlen(dut->ap2_radius_ipaddr))
7168 fprintf(f, "auth_server_addr=%s\n",
7169 dut->ap2_radius_ipaddr);
7170 if (dut->ap2_radius_port)
7171 fprintf(f, "auth_server_port=%d\n",
7172 dut->ap2_radius_port);
7173 if (strlen(dut->ap2_radius_password))
7174 fprintf(f, "auth_server_shared_secret=%s\n",
7175 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007176
7177 set_ebtables_forward_drop(dut, ifname, ifname2);
7178 } else if (dut->ap2_osu) {
7179 fprintf(f, "ap_isolate=1\n");
7180 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007181 }
7182
7183 if (dut->ap2_proxy_arp) {
7184 if (!dut->bridge) {
7185 sigma_dut_print(dut, DUT_MSG_ERROR,
7186 "Bridge must be configured. Run with -b <brname>.");
7187 fclose(f);
7188 return -2;
7189 }
7190 fprintf(f, "ap_isolate=1\n");
7191 fprintf(f, "proxy_arp=1\n");
7192
7193 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
7194 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
7195 fclose(f);
7196 return -2;
7197 }
7198
7199 }
7200 }
7201
7202 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007203 /* 60G WPS tests requires wps_state of 2 (configured) */
7204 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
7205
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007206 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007207 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007208 "device_name=QCA AP\n"
7209 "manufacturer=QCA\n"
7210 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007211 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007212 "virtual_push_button keypad%s\n"
7213 "ap_pin=12345670\n"
7214 "friendly_name=QCA Access Point\n"
7215 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007216 wps_state,
7217 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007218 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
7219 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007220 if (dut->wsc_fragment) {
7221 fprintf(f, "device_name=%s\n"
7222 "manufacturer=%s\n"
7223 "model_name=%s\n"
7224 "model_number=%s\n"
7225 "serial_number=%s\n",
7226 WPS_LONG_DEVICE_NAME,
7227 WPS_LONG_MANUFACTURER,
7228 WPS_LONG_MODEL_NAME,
7229 WPS_LONG_MODEL_NUMBER,
7230 WPS_LONG_SERIAL_NUMBER);
7231 } else {
7232 fprintf(f, "device_name=QCA AP\n"
7233 "manufacturer=QCA\n");
7234 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007235 if (dut->eap_fragment)
7236 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007237 }
7238
7239 if (dut->program == PROGRAM_VHT) {
7240 int vht_oper_centr_freq_idx;
7241
7242 if (check_channel(dut->ap_channel) < 0) {
7243 send_resp(dut, conn, SIGMA_INVALID,
7244 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307245 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007246 return 0;
7247 }
7248
7249 switch (dut->ap_chwidth) {
7250 case AP_20:
7251 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7252 vht_oper_centr_freq_idx =
7253 get_oper_centr_freq_seq_idx(20,
7254 dut->ap_channel);
7255 break;
7256 case AP_40:
7257 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7258 vht_oper_centr_freq_idx =
7259 get_oper_centr_freq_seq_idx(40,
7260 dut->ap_channel);
7261 break;
7262 case AP_80:
7263 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
7264 vht_oper_centr_freq_idx =
7265 get_oper_centr_freq_seq_idx(80,
7266 dut->ap_channel);
7267 break;
7268 case AP_160:
7269 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
7270 vht_oper_centr_freq_idx =
7271 get_oper_centr_freq_seq_idx(160,
7272 dut->ap_channel);
7273 break;
7274 default:
7275 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
7276 vht_oper_centr_freq_idx =
7277 get_oper_centr_freq_seq_idx(80,
7278 dut->ap_channel);
7279 break;
7280 }
7281 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
7282 vht_oper_centr_freq_idx);
7283 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
7284
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007285 if (dut->ap_sgi80 || dut->ap_txBF ||
7286 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307287 dut->ap_tx_stbc || dut->ap_mu_txBF) {
7288 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007289 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05307290 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05307291 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007292 (dut->ap_ldpc == VALUE_ENABLED) ?
7293 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307294 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
7295 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007296 }
7297 }
7298
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007299 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
7300 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
7301 /* OWE transition mode */
7302 unsigned char bssid[6];
7303 char ifname2[50];
7304 unsigned long val;
7305 FILE *f2;
7306
7307 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7308
7309 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7310 val = 0x12345678; /* default to something */
7311 f2 = fopen("/dev/urandom", "r");
7312 if (f2) {
7313 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7314 sigma_dut_print(dut, DUT_MSG_ERROR,
7315 "Could not read /dev/urandom");
7316 }
7317 fclose(f2);
7318 }
7319 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007320 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007321
7322 if (get_hwaddr(ifname, bssid)) {
7323 fclose(f);
7324 return -2;
7325 }
7326 if (bssid[0] & 0x02)
7327 bssid[5] ^= 0x01;
7328 else
7329 bssid[0] |= 0x02;
7330
7331 fprintf(f, "bss=%s\n", ifname2);
7332 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7333 if (dut->bridge)
7334 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007335 if (drv == DRIVER_LINUX_WCN)
7336 fprintf(f, "use_driver_iface_addr=1\n");
7337 else
7338 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7339 bssid[0], bssid[1], bssid[2], bssid[3],
7340 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007341 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7342 }
7343
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007344 if (dut->ap_key_mgmt == AP_OPEN &&
7345 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
7346 /* OWE transition mode */
7347 unsigned char bssid[6];
7348 char ifname2[50];
7349 unsigned long val;
7350 FILE *f2;
7351
7352 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7353
7354 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7355 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7356
7357 if (get_hwaddr(ifname, bssid)) {
7358 fclose(f);
7359 return -2;
7360 }
7361 if (bssid[0] & 0x02)
7362 bssid[5] ^= 0x01;
7363 else
7364 bssid[0] |= 0x02;
7365
7366 fprintf(f, "bss=%s\n", ifname2);
7367 val = 0x12345678; /* default to something */
7368 f2 = fopen("/dev/urandom", "r");
7369 if (f2) {
7370 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7371 sigma_dut_print(dut, DUT_MSG_ERROR,
7372 "Could not read /dev/urandom");
7373 }
7374 fclose(f2);
7375 }
7376 fprintf(f, "ssid=owe-%lx\n", val);
7377 if (dut->bridge)
7378 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007379 if (drv == DRIVER_LINUX_WCN)
7380 fprintf(f, "use_driver_iface_addr=1\n");
7381 else
7382 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7383 bssid[0], bssid[1], bssid[2], bssid[3],
7384 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007385 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7386 fprintf(f, "wpa=2\n");
7387 fprintf(f, "wpa_key_mgmt=OWE\n");
7388 fprintf(f, "rsn_pairwise=CCMP\n");
7389 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007390 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007391 if (dut->ap_sae_groups)
7392 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
7393 }
7394
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307395 if (dut->program == PROGRAM_OCE) {
7396 fprintf(f, "oce=%d\n",
7397 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
7398 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007399 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007400 if (dut->use_hostapd_pid_file)
7401 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007402#ifdef __QNXNTO__
7403 if (system("slay hostapd") == 0)
7404#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007405 if (!dut->use_hostapd_pid_file &&
7406 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7407 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007408#endif /* __QNXNTO__ */
7409 {
7410 int i;
7411 /* Wait some time to allow hostapd to complete cleanup before
7412 * starting a new process */
7413 for (i = 0; i < 10; i++) {
7414 usleep(500000);
7415#ifdef __QNXNTO__
7416 if (system("pidin | grep hostapd") != 0)
7417 break;
7418#else /* __QNXNTO__ */
7419 if (system("pidof hostapd") != 0)
7420 break;
7421#endif /* __QNXNTO__ */
7422 }
7423 }
Jouni Malinend86e5822017-08-29 03:55:32 +03007424 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007425
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307426#ifdef ANDROID
7427 /* Set proper conf file permissions so that hostapd process
7428 * can access it.
7429 */
7430 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
7431 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
7432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "Error changing permissions");
7434
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307435 gr = getgrnam("wifi");
7436 if (!gr ||
7437 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307438 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
7439#endif /* ANDROID */
7440
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007441 if (drv == DRIVER_QNXNTO) {
7442 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05307443 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007444 "/sigma_dut-ap.conf",
7445 dut->hostapd_debug_log ? "-ddKt -f " : "",
7446 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007447 dut->hostapd_entropy_log ? " -e" : "",
7448 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
7449 "");
7450 } else {
7451 /*
7452 * It looks like a monitor interface can cause some issues for
7453 * beaconing, so remove it (if injection was used) before
7454 * starting hostapd.
7455 */
7456 if (if_nametoindex("sigmadut") > 0 &&
7457 system("iw dev sigmadut del") != 0)
7458 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7459 "monitor interface");
7460
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007461 snprintf(path, sizeof(path), "%shostapd",
7462 file_exists("hostapd") ? "./" : "");
7463 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007464 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007465 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007466 dut->hostapd_debug_log ? " -ddKt -f" : "",
7467 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
7468 dut->hostapd_entropy_log ? " -e" : "",
7469 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007470 "",
7471 dut->use_hostapd_pid_file ?
7472 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007473 }
7474
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007475 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007476 if (system(buf) != 0) {
7477 send_resp(dut, conn, SIGMA_ERROR,
7478 "errorCode,Failed to start hostapd");
7479 return 0;
7480 }
7481
7482 /* allow some time for hostapd to start before returning success */
7483 usleep(500000);
7484 if (run_hostapd_cli(dut, "ping") != 0) {
7485 send_resp(dut, conn, SIGMA_ERROR,
7486 "errorCode,Failed to talk to hostapd");
7487 return 0;
7488 }
7489
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05307490 if (drv == DRIVER_LINUX_WCN) {
7491 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
7492 ap_inet_addr, ap_inet_mask);
7493 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
7494 ifname, ap_inet_addr, ap_inet_mask);
7495 if (system(buf) != 0) {
7496 sigma_dut_print(dut, DUT_MSG_ERROR,
7497 "Failed to initialize the interface");
7498 return -1;
7499 }
7500 }
7501
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007502 if (dut->ap_l2tif) {
7503 snprintf(path, sizeof(path),
7504 "/sys/class/net/%s/brport/hairpin_mode",
7505 ifname);
7506 if (!file_exists(path)) {
7507 sigma_dut_print(dut, DUT_MSG_ERROR,
7508 "%s must be binded to the bridge for L2TIF",
7509 ifname);
7510 return -2;
7511 }
7512
7513 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
7514 if (system(buf) != 0) {
7515 sigma_dut_print(dut, DUT_MSG_ERROR,
7516 "Failed to enable hairpin_mode for L2TIF");
7517 return -2;
7518 }
7519
7520 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
7521 if (system(buf) != 0) {
7522 sigma_dut_print(dut, DUT_MSG_ERROR,
7523 "Failed to set ebtables rules, RULE-9");
7524 return -2;
7525 }
7526
7527 snprintf(buf, sizeof(buf),
7528 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
7529 ifname);
7530 if (system(buf) != 0) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "Failed to set ebtables rules, RULE-11");
7533 return -2;
7534 }
7535 }
7536
7537 if (dut->ap_proxy_arp) {
7538 if (dut->ap_dgaf_disable) {
7539 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
7540 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
7541 return -2;
7542 } else {
7543 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
7544 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
7545 return -2;
7546 }
7547
7548 /* For 4.5-(c) */
7549 snprintf(buf, sizeof(buf),
7550 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
7551 ifname);
7552 if (system(buf) != 0) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "Failed to set ebtables rules, RULE-10");
7555 return -2;
7556 }
7557 }
7558
7559 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
7560 /* Drop TDLS frames */
7561 snprintf(buf, sizeof(buf),
7562 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
7563 if (system(buf) != 0) {
7564 sigma_dut_print(dut, DUT_MSG_ERROR,
7565 "Failed to set ebtables rules, RULE-13");
7566 return -2;
7567 }
7568 }
7569
7570 if (dut->ap_fake_pkhash &&
7571 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
7572 send_resp(dut, conn, SIGMA_ERROR,
7573 "errorCode,Could not enable FakePubKey");
7574 return 0;
7575 }
7576
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007577 if (dut->program == PROGRAM_60GHZ && dut->ap_num_ese_allocs > 0) {
7578 /* wait extra time for AP to start */
7579 sleep(2);
7580 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
7581 dut->ap_ese_allocs)) {
7582 send_resp(dut, conn, SIGMA_ERROR,
7583 "errorCode,Could not set ExtSch");
7584 return 0;
7585 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007586 if (dut->ap_fixed_rate) {
7587 sigma_dut_print(dut, DUT_MSG_DEBUG,
7588 "forcing TX MCS index %d",
7589 dut->ap_mcs);
7590 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
7591 send_resp(dut, conn, SIGMA_ERROR,
7592 "errorCode,Could not force MCS");
7593 return -2;
7594 }
7595 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007596 }
7597
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007598 if (dut->wps_forced_version) {
7599 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
7600 dut->wps_forced_version);
7601 if (hapd_command(ifname, buf) < 0) {
7602 send_resp(dut, conn, SIGMA_ERROR,
7603 "errorCode,Fail to set wps_version_number");
7604 return STATUS_SENT;
7605 }
7606 }
7607
Jouni Malinend86e5822017-08-29 03:55:32 +03007608 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007609 return 1;
7610}
7611
7612
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307613static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
7614 struct qos_params *qos, const char *cwmin,
7615 const char *cwmax, const char *aifs,
7616 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007617{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307618 int val;
7619
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007620 if (cwmin) {
7621 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307622 val = atoi(cwmin);
7623 if (val < 0 || val > 15) {
7624 send_resp(dut, conn, SIGMA_INVALID,
7625 "errorCode,Invalid cwMin");
7626 return 0;
7627 }
7628 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007629 }
7630
7631 if (cwmax) {
7632 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307633 val = atoi(cwmax);
7634 if (val < 0 || val > 15) {
7635 send_resp(dut, conn, SIGMA_INVALID,
7636 "errorCode,Invalid cwMax");
7637 return 0;
7638 }
7639 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007640 }
7641
7642 if (aifs) {
7643 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307644 val = atoi(aifs);
7645 if (val < 1 || val > 255) {
7646 send_resp(dut, conn, SIGMA_INVALID,
7647 "errorCode,Invalid AIFS");
7648 return 0;
7649 }
7650 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007651 }
7652
7653 if (txop) {
7654 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307655 val = atoi(txop);
7656 if (val < 0 || val > 0xffff) {
7657 send_resp(dut, conn, SIGMA_INVALID,
7658 "errorCode,Invalid txop");
7659 return 0;
7660 }
7661 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007662 }
7663
7664 if (acm) {
7665 qos->ac = 1;
7666 qos->acm = strcasecmp(acm, "on") == 0;
7667 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307668
7669 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007670}
7671
7672
Jouni Malinenf7222712019-06-13 01:50:21 +03007673static enum sigma_cmd_result cmd_ap_set_apqos(struct sigma_dut *dut,
7674 struct sigma_conn *conn,
7675 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007676{
7677 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307678 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
7679 get_param(cmd, "cwmin_VO"),
7680 get_param(cmd, "cwmax_VO"),
7681 get_param(cmd, "AIFS_VO"),
7682 get_param(cmd, "TXOP_VO"),
7683 get_param(cmd, "ACM_VO")) ||
7684 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
7685 get_param(cmd, "cwmin_VI"),
7686 get_param(cmd, "cwmax_VI"),
7687 get_param(cmd, "AIFS_VI"),
7688 get_param(cmd, "TXOP_VI"),
7689 get_param(cmd, "ACM_VI")) ||
7690 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
7691 get_param(cmd, "cwmin_BE"),
7692 get_param(cmd, "cwmax_BE"),
7693 get_param(cmd, "AIFS_BE"),
7694 get_param(cmd, "TXOP_BE"),
7695 get_param(cmd, "ACM_BE")) ||
7696 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
7697 get_param(cmd, "cwmin_BK"),
7698 get_param(cmd, "cwmax_BK"),
7699 get_param(cmd, "AIFS_BK"),
7700 get_param(cmd, "TXOP_BK"),
7701 get_param(cmd, "ACM_BK")))
7702 return 0;
7703
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007704 return 1;
7705}
7706
7707
Jouni Malinenf7222712019-06-13 01:50:21 +03007708static enum sigma_cmd_result cmd_ap_set_staqos(struct sigma_dut *dut,
7709 struct sigma_conn *conn,
7710 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007711{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307712 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
7713 get_param(cmd, "cwmin_VO"),
7714 get_param(cmd, "cwmax_VO"),
7715 get_param(cmd, "AIFS_VO"),
7716 get_param(cmd, "TXOP_VO"),
7717 get_param(cmd, "ACM_VO")) ||
7718 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
7719 get_param(cmd, "cwmin_VI"),
7720 get_param(cmd, "cwmax_VI"),
7721 get_param(cmd, "AIFS_VI"),
7722 get_param(cmd, "TXOP_VI"),
7723 get_param(cmd, "ACM_VI")) ||
7724 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
7725 get_param(cmd, "cwmin_BE"),
7726 get_param(cmd, "cwmax_BE"),
7727 get_param(cmd, "AIFS_BE"),
7728 get_param(cmd, "TXOP_BE"),
7729 get_param(cmd, "ACM_BE")) ||
7730 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
7731 get_param(cmd, "cwmin_BK"),
7732 get_param(cmd, "cwmax_BK"),
7733 get_param(cmd, "AIFS_BK"),
7734 get_param(cmd, "TXOP_BK"),
7735 get_param(cmd, "ACM_BK")))
7736 return 0;
7737
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007738 return 1;
7739}
7740
7741
7742static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
7743{
7744 unsigned char bssid[6];
7745 char buf[100];
7746 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
7747 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
7748 run_system(dut, "cfg -a AP_SECMODE=WPA");
7749 run_system(dut, "cfg -a AP_SECFILE=EAP");
7750 run_system(dut, "cfg -a AP_WPA=2");
7751 run_system(dut, "cfg -a AP_CYPHER=CCMP");
7752 run_system(dut, "cfg -a AP_HOTSPOT=1");
7753 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
7754 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
7755 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
7756 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
7757 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
7758 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
7759 if (!get_hwaddr("ath0", bssid)) {
7760 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7761 "%02x:%02x:%02x:%02x:%02x:%02x",
7762 bssid[0], bssid[1], bssid[2], bssid[3],
7763 bssid[4], bssid[5]);
7764 run_system(dut, buf);
7765 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7766 "%02x:%02x:%02x:%02x:%02x:%02x",
7767 bssid[0], bssid[1], bssid[2], bssid[3],
7768 bssid[4], bssid[5]);
7769 } else {
7770 if (!get_hwaddr("wifi0", bssid)) {
7771 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
7772 "%02x:%02x:%02x:%02x:%02x:%02x",
7773 bssid[0], bssid[1], bssid[2], bssid[3],
7774 bssid[4], bssid[5]);
7775 run_system(dut, buf);
7776 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
7777 "%02x:%02x:%02x:%02x:%02x:%02x",
7778 bssid[0], bssid[1], bssid[2], bssid[3],
7779 bssid[4], bssid[5]);
7780 } else {
7781 /* load the driver and try again */
7782 run_system(dut, "/etc/rc.d/rc.wlan up");
7783
7784 if (!get_hwaddr("wifi0", bssid)) {
7785 snprintf(buf, sizeof(buf),
7786 "cfg -a AP_HOTSPOT_HESSID="
7787 "%02x:%02x:%02x:%02x:%02x:%02x",
7788 bssid[0], bssid[1], bssid[2],
7789 bssid[3], bssid[4], bssid[5]);
7790 run_system(dut, buf);
7791 snprintf(dut->ap_hessid,
7792 sizeof(dut->ap_hessid),
7793 "%02x:%02x:%02x:%02x:%02x:%02x",
7794 bssid[0], bssid[1], bssid[2],
7795 bssid[3], bssid[4], bssid[5]);
7796 }
7797 }
7798 }
7799
7800 run_system(dut, "cfg -r AP_SSID_2");
7801 run_system(dut, "cfg -c");
7802 /* run_system(dut, "cfg -s"); */
7803}
7804
7805
7806static void ath_reset_vht_defaults(struct sigma_dut *dut)
7807{
7808 run_system(dut, "cfg -x");
7809 run_system(dut, "cfg -a AP_RADIO_ID=1");
7810 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
7811 run_system(dut, "cfg -a AP_STARTMODE=standard");
7812 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
7813 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
7814 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
7815 run_system(dut, "cfg -a ATH_countrycode=0x348");
7816 /* NOTE: For Beeliner we have to turn off MU-MIMO */
7817 if (system("rm /tmp/secath*") != 0) {
7818 sigma_dut_print(dut, DUT_MSG_ERROR,
7819 "Failed to remove secath file");
7820 }
7821}
7822
7823
Jouni Malinenf7222712019-06-13 01:50:21 +03007824static enum sigma_cmd_result cmd_ap_reset_default(struct sigma_dut *dut,
7825 struct sigma_conn *conn,
7826 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007827{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307828 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307829 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007830 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007831 int i;
7832
7833 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
7834 /*
7835 * Reset all tagged SSIDs to NULL-string and all key management
7836 * to open.
7837 */
7838 dut->ap_tag_ssid[i][0] = '\0';
7839 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
7840 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007841
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05307842 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307843
7844 program = get_param(cmd, "program");
7845 if (!program)
7846 program = get_param(cmd, "prog");
7847 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007848 dut->device_type = AP_unknown;
7849 type = get_param(cmd, "type");
7850 if (type && strcasecmp(type, "Testbed") == 0)
7851 dut->device_type = AP_testbed;
7852 if (type && strcasecmp(type, "DUT") == 0)
7853 dut->device_type = AP_dut;
7854
7855 dut->ap_rts = 0;
7856 dut->ap_frgmnt = 0;
7857 dut->ap_bcnint = 0;
7858 dut->ap_key_mgmt = AP_OPEN;
7859 dut->ap_ssid[0] = '\0';
7860 dut->ap_fake_pkhash = 0;
7861 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
7862 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007863 dut->ap_addba_reject = VALUE_NOT_SET;
7864 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007865 dut->ap_is_dual = 0;
7866 dut->ap_mode = AP_inval;
7867 dut->ap_mode_1 = AP_inval;
7868
7869 dut->ap_allow_vht_wep = 0;
7870 dut->ap_allow_vht_tkip = 0;
7871 dut->ap_disable_protection = 0;
7872 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007873 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
7874 dut->ap_ldpc = VALUE_NOT_SET;
7875 dut->ap_sig_rts = VALUE_NOT_SET;
7876 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007877 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05307878 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007879 dut->ap_chwidth = AP_AUTO;
7880
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05307881 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007882 dut->ap_wpsnfc = 0;
7883 dut->ap_bss_load = -1;
7884 dut->ap_p2p_cross_connect = -1;
7885
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307886 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
7887 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307888 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05307889
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007890 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07007891 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08007892 dut->ap_interface_5g = 0;
7893 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08007894 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07007895
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007896 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007897 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007898 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007899
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307900 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307901 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307902 dut->ap_wmmps = AP_WMMPS_ON;
7903 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307904 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307905 dut->ap_wmmps = AP_WMMPS_OFF;
7906 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307907
Jouni Malinen54a89b02018-05-01 00:16:26 +03007908 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03007909 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03007910 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03007911 dut->ap_tnc_file_name = 0;
7912 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03007913
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007914 dut->ap_akm_values = 0;
Jouni Malinen09550de2019-03-26 00:24:11 +02007915 free(dut->ap_sae_passwords);
7916 dut->ap_sae_passwords = NULL;
7917
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007918 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007919 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007920 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007921 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007922
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007923 if (drv == DRIVER_ATHEROS)
7924 cmd_ath_ap_hs2_reset(dut);
7925 else if (drv == DRIVER_OPENWRT)
7926 cmd_owrt_ap_hs2_reset(dut);
7927
7928 dut->ap_interworking = 1;
7929 dut->ap_access_net_type = 2;
7930 dut->ap_internet = 0;
7931 dut->ap_venue_group = 2;
7932 dut->ap_venue_type = 8;
7933 dut->ap_domain_name_list[0] = '\0';
7934 dut->ap_hs2 = 1;
7935 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
7936 "506f9a;001bc504bd");
7937 dut->ap_l2tif = 0;
7938 dut->ap_proxy_arp = 0;
7939 if (dut->bridge) {
7940 char buf[50];
7941
7942 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
7943 dut->bridge);
7944 if (system(buf) != 0) {
7945 sigma_dut_print(dut, DUT_MSG_DEBUG,
7946 "%s ip neigh table flushing failed",
7947 dut->bridge);
7948 }
7949
7950 snprintf(buf, sizeof(buf), "ebtables -F");
7951 if (system(buf) != 0) {
7952 sigma_dut_print(dut, DUT_MSG_DEBUG,
7953 "%s ebtables flushing failed",
7954 dut->bridge);
7955 }
7956 }
7957 dut->ap_dgaf_disable = 0;
7958 dut->ap_p2p_cross_connect = 0;
7959 dut->ap_gas_cb_delay = 0;
7960 dut->ap_nai_realm_list = 0;
7961 dut->ap_oper_name = 0;
7962 dut->ap_venue_name = 0;
7963 for (i = 0; i < 10; i++) {
7964 dut->ap_plmn_mcc[i][0] = '\0';
7965 dut->ap_plmn_mnc[i][0] = '\0';
7966 }
7967 dut->ap_wan_metrics = 0;
7968 dut->ap_conn_capab = 0;
7969 dut->ap_ip_addr_type_avail = 0;
7970 dut->ap_net_auth_type = 0;
7971 dut->ap_oper_class = 0;
7972 dut->ap_pmf = 0;
7973 dut->ap_add_sha256 = 0;
7974 }
7975
Jouni Malinenba630452018-06-22 11:49:59 +03007976 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
7977 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007978 int i;
7979 const char hessid[] = "50:6f:9a:00:11:22";
7980
7981 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
7982 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007983 dut->ap_pmf = 1;
7984 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02007985 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007986 for (i = 0; i < 10; i++) {
7987 dut->ap_osu_server_uri[i][0] = '\0';
7988 dut->ap_osu_method[i] = 0xFF;
7989 }
7990 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007991 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007992 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007993 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007994 dut->ap_osu_icon_tag = 0;
7995 }
7996
7997 if (dut->program == PROGRAM_VHT) {
7998 /* Set up the defaults */
7999 dut->ap_mode = AP_11ac;
8000 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008001 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08008002 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008003 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008004 dut->ap_amsdu = VALUE_DISABLED;
8005 dut->ap_ldpc = VALUE_DISABLED;
8006 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008007 dut->ap_sgi80 = 0;
8008 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008009 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308010 /*
8011 * As LDPC is optional, don't enable this by default
8012 * for LINUX-WCN driver. The ap_set_wireless command
8013 * can be used to enable LDPC, when needed.
8014 */
8015 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008016 dut->ap_ldpc = VALUE_ENABLED;
8017 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008018 dut->ap_sgi80 = 1;
8019 }
8020 dut->ap_fixed_rate = 0;
8021 dut->ap_rx_streams = 3;
8022 dut->ap_tx_streams = 3;
8023 dut->ap_vhtmcs_map = 0;
8024 dut->ap_chwidth = AP_80;
8025 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008026 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05308027 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8028 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008029 if (get_driver_type() == DRIVER_ATHEROS)
8030 ath_reset_vht_defaults(dut);
8031 }
8032
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008033 if (dut->program == PROGRAM_IOTLP) {
8034 dut->wnm_bss_max_feature = VALUE_DISABLED;
8035 dut->wnm_bss_max_idle_time = 0;
8036 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8037 dut->ap_proxy_arp = 1;
8038 } else {
8039 /*
8040 * Do not touch the BSS-MAX Idle time feature
8041 * if the program is not IOTLP.
8042 */
8043 dut->wnm_bss_max_feature = VALUE_NOT_SET;
8044 dut->wnm_bss_max_idle_time = 0;
8045 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8046 }
8047
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008048 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008049 dut->ap_rrm = 1;
8050 dut->ap_rtt = 1;
8051 dut->ap_lci = 0;
8052 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008053 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008054 dut->ap_lcr = 0;
8055 dut->ap_val_lcr[0] = '\0';
8056 dut->ap_neighap = 0;
8057 dut->ap_opchannel = 0;
8058 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008059 dut->ap_fqdn_held = 0;
8060 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07008061 dut->ap_interworking = 0;
8062 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008063 dut->ap_msnt_type = 0;
8064 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008065 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07008066 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07008067 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008068
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008069 if (dut->program == PROGRAM_MBO) {
8070 dut->ap_mbo = 1;
8071 dut->ap_interworking = 1;
8072 dut->ap_ne_class = 0;
8073 dut->ap_ne_op_ch = 0;
8074 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008075 dut->ap_btmreq_disassoc_imnt = 0;
8076 dut->ap_btmreq_term_bit = 0;
8077 dut->ap_disassoc_timer = 0;
8078 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07008079 dut->ap_channel = 36;
8080 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07008081 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07008082 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008083 dut->mbo_self_ap_tuple.ap_ne_class = -1;
8084 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
8085 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008086 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008087 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008088 }
8089
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008090 if (dut->program == PROGRAM_OCE) {
8091 if (dut->ap_dhcp_stop)
8092 run_system(dut, "/etc/init.d/dnsmasq start");
8093
8094 dut->ap_dhcp_stop = 0;
8095 dut->ap_oce = VALUE_ENABLED;
8096 dut->ap_broadcast_ssid = VALUE_ENABLED;
8097 dut->ap_fils_dscv_int = 20;
8098 dut->ap_filsdscv = VALUE_ENABLED;
8099 dut->ap_filshlp = VALUE_DISABLED;
8100 dut->ap_rnr = VALUE_DISABLED;
8101 dut->ap_nairealm[0] = '\0';
8102 dut->ap_nairealm_int = 0;
8103 dut->ap_blechanutil = 0;
8104 dut->ap_ble_admit_cap = 0;
8105 dut->ap_esp = VALUE_ENABLED;
8106 dut->ap_datappdudura = 0;
8107 dut->ap_airtimefract = 0;
8108 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08008109 dut->ap_ul_availcap = 0;
8110 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08008111 dut->ap_akm = 0;
8112 dut->ap_add_sha256 = 0;
8113 dut->ap_add_sha384 = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08008114 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008115 }
8116
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008117 dut->ap_he_ppdu = PPDU_NOT_SET;
8118
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08008119 dut->ap_oper_chn = 0;
8120
Jouni Malinenb75c5322019-06-14 01:47:43 +03008121 dut->ap_pmksa = 0;
8122 dut->ap_pmksa_caching = 0;
8123
Jouni Malinen3c367e82017-06-23 17:01:47 +03008124 free(dut->rsne_override);
8125 dut->rsne_override = NULL;
8126
Jouni Malinen68143132017-09-02 02:34:08 +03008127 free(dut->sae_commit_override);
8128 dut->sae_commit_override = NULL;
8129
Jouni Malinened670f42017-08-31 01:39:28 +03008130 free(dut->ap_sae_groups);
8131 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03008132
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008133 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03008134 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008135
Jouni Malinen3d633da2017-09-14 22:19:21 +03008136 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02008137 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03008138 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02008139 dut->ap_passphrase[0] = '\0';
8140 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03008141
Jouni Malinend86e5822017-08-29 03:55:32 +03008142 dut->dpp_conf_id = -1;
8143
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008144 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008145 dut->ap_mode = AP_11ad;
8146 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008147 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008148 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008149 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008150 dut->ap_fixed_rate = 0;
8151
8152 dut->dev_role = DEVROLE_AP;
8153
8154 sigma_dut_print(dut, DUT_MSG_DEBUG,
8155 "Setting msdu_size to MAX: 7912");
8156 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
8157 get_main_ifname());
8158
8159 if (system(buf) != 0) {
8160 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8161 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008162 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008163 }
8164
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008165 if (ap_set_force_mcs(dut, 0, 1)) {
8166 sigma_dut_print(dut, DUT_MSG_ERROR,
8167 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008168 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008169 }
8170
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008171 if (set_ps(get_main_ifname(), dut, 1)) {
8172 sigma_dut_print(dut, DUT_MSG_ERROR,
8173 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008174 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008175 }
8176 }
8177
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02008178 if (dut->program == PROGRAM_WPS &&
8179 get_driver_type() == DRIVER_WIL6210) {
8180 /*
8181 * In 60 GHz WPS tests, we configure the AP OOB to
8182 * secure connection with a random passphrase.
8183 */
8184 char r[16], passphrase[65];
8185
8186 if (random_get_bytes(r, sizeof(r))) {
8187 sigma_dut_print(dut, DUT_MSG_ERROR,
8188 "Failed to get random bytes");
8189 return ERROR_SEND_STATUS;
8190 }
8191 if (base64_encode(r, sizeof(r),
8192 passphrase, sizeof(passphrase))) {
8193 sigma_dut_print(dut, DUT_MSG_ERROR,
8194 "Failed to generate random passphrase");
8195 return ERROR_SEND_STATUS;
8196 }
8197
8198 dut->ap_key_mgmt = AP_WPA2_PSK;
8199 dut->ap_cipher = AP_GCMP_128;
8200 strlcpy(dut->ap_passphrase, passphrase,
8201 sizeof(dut->ap_passphrase));
8202 sigma_dut_print(dut, DUT_MSG_DEBUG,
8203 "60G WPS: configure secure AP with random passphrase");
8204 }
8205
Jouni Malinend86e5822017-08-29 03:55:32 +03008206 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08008207
8208 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8209 return 1;
8210
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008211 if (dut->use_hostapd_pid_file) {
8212 kill_hostapd_process_pid(dut);
8213 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8214 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008215 int i;
8216 /* Wait some time to allow hostapd to complete cleanup before
8217 * starting a new process */
8218 for (i = 0; i < 10; i++) {
8219 usleep(500000);
8220 if (system("pidof hostapd") != 0)
8221 break;
8222 }
8223 }
8224
8225 if (if_nametoindex("sigmadut") > 0 &&
8226 system("iw dev sigmadut del") != 0)
8227 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8228 "monitor interface");
8229
8230 return 1;
8231}
8232
8233
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308234int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
8235 struct sigma_cmd *cmd)
8236{
8237 return cmd_ap_reset_default(dut, conn, cmd);
8238}
8239
8240
Jouni Malinenf7222712019-06-13 01:50:21 +03008241static enum sigma_cmd_result cmd_ap_get_info(struct sigma_dut *dut,
8242 struct sigma_conn *conn,
8243 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008244{
8245 /* const char *name = get_param(cmd, "NAME"); */
8246 struct stat s;
8247 char resp[200];
8248 FILE *f;
8249 enum driver_type drv = get_driver_type();
Jouni Malinen3aa72862019-05-29 23:14:51 +03008250 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008251
8252 switch (drv) {
8253 case DRIVER_ATHEROS: {
8254 /* Atheros AP */
8255 struct utsname uts;
8256 char *version, athver[100];
8257
8258 if (stat("/proc/athversion", &s) != 0) {
8259 if (system("/etc/rc.d/rc.wlan up") != 0) {
8260 }
8261 }
8262
8263 athver[0] = '\0';
8264 f = fopen("/proc/athversion", "r");
8265 if (f) {
8266 if (fgets(athver, sizeof(athver), f)) {
8267 char *pos = strchr(athver, '\n');
8268 if (pos)
8269 *pos = '\0';
8270 }
8271 fclose(f);
8272 }
8273
8274 if (uname(&uts) == 0)
8275 version = uts.release;
8276 else
8277 version = "Unknown";
8278
8279 if (if_nametoindex("ath1") > 0)
Jouni Malinen3aa72862019-05-29 23:14:51 +03008280 res = snprintf(resp, sizeof(resp),
8281 "interface,ath0_24G ath1_5G,agent,1.0,version,%s/drv:%s",
8282 version, athver);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008283 else
Jouni Malinen3aa72862019-05-29 23:14:51 +03008284 res = snprintf(resp, sizeof(resp),
8285 "interface,ath0_24G,agent,1.0,version,%s/drv:%s",
8286 version, athver);
8287 if (res < 0 || res >= sizeof(resp))
8288 send_resp(dut, conn, SIGMA_ERROR, NULL);
8289 else
8290 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008291 return 0;
8292 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05308293 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008294 case DRIVER_MAC80211: {
8295 struct utsname uts;
8296 char *version;
8297
8298 if (uname(&uts) == 0)
8299 version = uts.release;
8300 else
8301 version = "Unknown";
8302
8303 if (if_nametoindex("wlan1") > 0)
8304 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
8305 "wlan1_5G,agent,1.0,version,%s", version);
8306 else
8307 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
8308 "agent,1.0,version,%s", version);
8309
8310 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8311 return 0;
8312 }
8313 case DRIVER_QNXNTO: {
8314 struct utsname uts;
8315 char *version;
8316
8317 if (uname(&uts) == 0)
8318 version = uts.release;
8319 else
8320 version = "Unknown";
8321 snprintf(resp, sizeof(resp),
8322 "interface,%s_any,agent,1.0,version,%s",
8323 sigma_main_ifname ? sigma_main_ifname : "NA",
8324 version);
8325 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8326 return 0;
8327 }
8328 case DRIVER_OPENWRT: {
8329 switch (get_openwrt_driver_type()) {
8330 case OPENWRT_DRIVER_ATHEROS: {
8331 struct utsname uts;
8332 char *version;
8333
8334 if (uname(&uts) == 0)
8335 version = uts.release;
8336 else
8337 version = "Unknown";
8338
8339 if (if_nametoindex("ath1") > 0)
8340 snprintf(resp, sizeof(resp),
8341 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
8342 version);
8343 else
8344 snprintf(resp, sizeof(resp),
8345 "interface,ath0_any,agent,1.0,version,%s",
8346 version);
8347
8348 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8349 return 0;
8350 }
8351 default:
8352 send_resp(dut, conn, SIGMA_ERROR,
8353 "errorCode,Unsupported openwrt driver");
8354 return 0;
8355 }
8356 }
8357 default:
8358 send_resp(dut, conn, SIGMA_ERROR,
8359 "errorCode,Unsupported driver");
8360 return 0;
8361 }
8362}
8363
8364
Jouni Malinenf7222712019-06-13 01:50:21 +03008365static enum sigma_cmd_result cmd_ap_deauth_sta(struct sigma_dut *dut,
8366 struct sigma_conn *conn,
8367 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008368{
8369 /* const char *name = get_param(cmd, "NAME"); */
8370 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8371 const char *val;
8372 char buf[100];
8373
8374 val = get_param(cmd, "MinorCode");
8375 if (val) {
8376 /* TODO: add support for P2P minor code */
8377 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
8378 "yet supported");
8379 return 0;
8380 }
8381
8382 val = get_param(cmd, "STA_MAC_ADDRESS");
8383 if (val == NULL)
8384 return -1;
8385 snprintf(buf, sizeof(buf), "deauth %s", val);
8386 if (run_hostapd_cli(dut, buf) != 0)
8387 return -2;
8388
8389 return 1;
8390}
8391
8392
8393#ifdef __linux__
8394int inject_frame(int s, const void *data, size_t len, int encrypt);
8395int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008396#endif /* __linux__ */
8397
8398enum send_frame_type {
8399 DISASSOC, DEAUTH, SAQUERY
8400};
8401enum send_frame_protection {
8402 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8403};
8404
8405
8406static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8407 enum send_frame_type frame,
8408 enum send_frame_protection protected,
8409 const char *sta_addr)
8410{
8411#ifdef __linux__
8412 unsigned char buf[1000], *pos;
8413 int s, res;
8414 unsigned char addr_sta[6], addr_own[6];
8415 char *ifname;
8416 char cbuf[100];
8417 struct ifreq ifr;
8418
8419 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
8420 dut->ap_mode == AP_11ac) &&
8421 if_nametoindex("wlan1") > 0)
8422 ifname = "wlan1";
8423 else
8424 ifname = "wlan0";
8425
8426 if (hwaddr_aton(sta_addr, addr_sta) < 0)
8427 return -1;
8428
8429 s = socket(AF_INET, SOCK_DGRAM, 0);
8430 if (s < 0)
8431 return -1;
8432 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07008433 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008434 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
8435 perror("ioctl");
8436 close(s);
8437 return -1;
8438 }
8439 close(s);
8440 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
8441
8442 if (if_nametoindex("sigmadut") == 0) {
8443 snprintf(cbuf, sizeof(cbuf),
8444 "iw dev %s interface add sigmadut type monitor",
8445 ifname);
8446 if (system(cbuf) != 0 ||
8447 if_nametoindex("sigmadut") == 0) {
8448 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8449 "monitor interface with '%s'", cbuf);
8450 return -2;
8451 }
8452 }
8453
8454 if (system("ifconfig sigmadut up") != 0) {
8455 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8456 "monitor interface up");
8457 return -2;
8458 }
8459
8460 pos = buf;
8461
8462 /* Frame Control */
8463 switch (frame) {
8464 case DISASSOC:
8465 *pos++ = 0xa0;
8466 break;
8467 case DEAUTH:
8468 *pos++ = 0xc0;
8469 break;
8470 case SAQUERY:
8471 *pos++ = 0xd0;
8472 break;
8473 }
8474
8475 if (protected == INCORRECT_KEY)
8476 *pos++ = 0x40; /* Set Protected field to 1 */
8477 else
8478 *pos++ = 0x00;
8479
8480 /* Duration */
8481 *pos++ = 0x00;
8482 *pos++ = 0x00;
8483
8484 /* addr1 = DA (station) */
8485 memcpy(pos, addr_sta, 6);
8486 pos += 6;
8487 /* addr2 = SA (own address) */
8488 memcpy(pos, addr_own, 6);
8489 pos += 6;
8490 /* addr3 = BSSID (own address) */
8491 memcpy(pos, addr_own, 6);
8492 pos += 6;
8493
8494 /* Seq# (to be filled by driver/mac80211) */
8495 *pos++ = 0x00;
8496 *pos++ = 0x00;
8497
8498 if (protected == INCORRECT_KEY) {
8499 /* CCMP parameters */
8500 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8501 pos += 8;
8502 }
8503
8504 if (protected == INCORRECT_KEY) {
8505 switch (frame) {
8506 case DEAUTH:
8507 /* Reason code (encrypted) */
8508 memcpy(pos, "\xa7\x39", 2);
8509 pos += 2;
8510 break;
8511 case DISASSOC:
8512 /* Reason code (encrypted) */
8513 memcpy(pos, "\xa7\x39", 2);
8514 pos += 2;
8515 break;
8516 case SAQUERY:
8517 /* Category|Action|TransID (encrypted) */
8518 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8519 pos += 4;
8520 break;
8521 default:
8522 return -1;
8523 }
8524
8525 /* CCMP MIC */
8526 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8527 pos += 8;
8528 } else {
8529 switch (frame) {
8530 case DEAUTH:
8531 /* reason code = 8 */
8532 *pos++ = 0x08;
8533 *pos++ = 0x00;
8534 break;
8535 case DISASSOC:
8536 /* reason code = 8 */
8537 *pos++ = 0x08;
8538 *pos++ = 0x00;
8539 break;
8540 case SAQUERY:
8541 /* Category - SA Query */
8542 *pos++ = 0x08;
8543 /* SA query Action - Request */
8544 *pos++ = 0x00;
8545 /* Transaction ID */
8546 *pos++ = 0x12;
8547 *pos++ = 0x34;
8548 break;
8549 }
8550 }
8551
8552 s = open_monitor("sigmadut");
8553 if (s < 0) {
8554 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8555 "monitor socket");
8556 return 0;
8557 }
8558
8559 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8560 if (res < 0) {
8561 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8562 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308563 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008564 return 0;
8565 }
8566 if (res < pos - buf) {
8567 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8568 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308569 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008570 return 0;
8571 }
8572
8573 close(s);
8574
8575 return 1;
8576#else /* __linux__ */
8577 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
8578 "yet supported");
8579 return 0;
8580#endif /* __linux__ */
8581}
8582
8583
8584int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8585 struct sigma_cmd *cmd)
8586{
8587 const char *val, *dest;
8588 char buf[100];
8589
8590 val = get_param(cmd, "FrameName");
8591 if (val == NULL)
8592 return -1;
8593
8594 if (strcasecmp(val, "QoSMapConfigure") == 0) {
8595 dest = get_param(cmd, "Dest");
8596 if (!dest)
8597 return -1;
8598
8599 val = get_param(cmd, "QoS_MAP_SET");
8600 if (val) {
8601 dut->ap_qos_map_set = atoi(val);
8602 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8603 dut->ap_qos_map_set);
8604 }
8605
8606 if (dut->ap_qos_map_set == 1)
8607 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8608 else if (dut->ap_qos_map_set == 2)
8609 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8610
8611 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8612 if (run_hostapd_cli(dut, buf) != 0)
8613 return -1;
8614 }
8615
8616 return 1;
8617}
8618
8619
8620static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8621 struct sigma_cmd *cmd)
8622{
8623 const char *val;
8624 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008625 int chwidth, nss;
8626
8627 val = get_param(cmd, "FrameName");
8628 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
8629 send_resp(dut, conn, SIGMA_ERROR,
8630 "errorCode,Unsupported FrameName");
8631 return 0;
8632 }
8633
8634 /*
8635 * Sequence of commands for Opmode notification on
8636 * Peregrine based products
8637 */
8638 ifname = get_main_ifname();
8639
8640 /* Disable STBC */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008641 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008642
8643 /* Check whether optional arg channel width was passed */
8644 val = get_param(cmd, "Channel_width");
8645 if (val) {
8646 switch (atoi(val)) {
8647 case 20:
8648 chwidth = 0;
8649 break;
8650 case 40:
8651 chwidth = 1;
8652 break;
8653 case 80:
8654 chwidth = 2;
8655 break;
8656 case 160:
8657 chwidth = 3;
8658 break;
8659 default:
8660 chwidth = 2;
8661 break;
8662 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008663 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008664 }
8665
8666 /* Check whether optional arg NSS was passed */
8667 val = get_param(cmd, "NSS");
8668 if (val) {
8669 /* Convert nss to chainmask */
8670 switch (atoi(val)) {
8671 case 1:
8672 nss = 1;
8673 break;
8674 case 2:
8675 nss = 3;
8676 break;
8677 case 3:
8678 nss = 7;
8679 break;
8680 default:
8681 /* We do not support NSS > 3 */
8682 nss = 3;
8683 break;
8684 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008685 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008686 }
8687
8688 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008689 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690
8691 return 1;
8692}
8693
8694
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008695static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8696 struct sigma_cmd *cmd)
8697{
8698 const char *val;
8699 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008700 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008701
8702 val = get_param(cmd, "MsntType");
8703 if (val) {
8704 if (dut->ap_msnt_type == 0)
8705 dut->ap_msnt_type = atoi(val);
8706
8707 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
8708 dut->ap_msnt_type = atoi(val);
8709 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008710 val = get_param(cmd, "RandInterval");
8711 if (val)
8712 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008713 f = fopen("/tmp/ftmrr.txt", "a");
8714 if (!f) {
8715 sigma_dut_print(dut, DUT_MSG_ERROR,
8716 "Failed to open /tmp/ftmrr.txt");
8717 return -1;
8718 }
8719
8720 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008721 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",
8722 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008723 fclose(f);
8724 dut->ap_msnt_type = 5;
8725 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8726 }
8727 } else if (dut->ap_msnt_type == 5) {
8728 run_system(dut, "wpc -f /tmp/ftmrr.txt");
8729 } else if (dut->ap_msnt_type == 2) {
8730 f = fopen("/tmp/wru.txt", "w");
8731 if (!f) {
8732 sigma_dut_print(dut, DUT_MSG_ERROR,
8733 "Failed to open /tmp/wru.txt");
8734 return -1;
8735 }
8736
8737 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
8738 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
8739 fclose(f);
8740 run_system(dut, "wpc -w /tmp/wru.txt");
8741 }
8742 }
8743 return 1;
8744}
8745
8746
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008747/*
8748 * The following functions parse_send_frame_params_int(),
8749 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
8750 * are used by ath_ap_send_frame_bcn_rpt_req().
8751 * Beacon Report Request is a frame used as part of the MBO program.
8752 * The command for sending beacon report has a lot of
8753 * arguments and having these functions reduces code size.
8754 *
8755 */
8756static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
8757 struct sigma_dut *dut,
8758 char *buf, size_t buf_size)
8759{
8760 const char *str_val;
8761 int int_val;
8762 char temp[100];
8763
8764 str_val = get_param(cmd, param);
8765 if (!str_val) {
8766 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8767 return -1;
8768 }
8769 int_val = atoi(str_val);
8770 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07008771 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008772 return 0;
8773}
8774
8775
8776static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
8777 struct sigma_dut *dut,
8778 char *buf, size_t buf_size)
8779{
8780 const char *str_val;
8781 char temp[100];
8782
8783 str_val = get_param(cmd, param);
8784 if (!str_val) {
8785 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8786 return -1;
8787 }
8788 snprintf(temp, sizeof(temp), " %s", str_val);
8789 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07008790 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008791 return 0;
8792}
8793
8794
8795static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
8796 struct sigma_dut *dut,
8797 char *buf, size_t buf_size)
8798{
8799 const char *str_val;
8800 unsigned char mac[6];
8801 char temp[100];
8802
8803 str_val = get_param(cmd, param);
8804 if (!str_val) {
8805 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
8806 return -1;
8807 }
8808
8809 if (parse_mac_address(dut, str_val, mac) < 0) {
8810 sigma_dut_print(dut, DUT_MSG_ERROR,
8811 "MAC Address not in proper format");
8812 return -1;
8813 }
8814 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
8815 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07008816 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008817 return 0;
8818}
8819
8820
8821static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
8822 char *buf, size_t buf_size)
8823{
8824 const char *str_val;
8825 char *value = " 1";
8826
8827 str_val = get_param(cmd, param);
8828 if (!str_val || str_val[0] == '\0')
8829 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07008830 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008831
8832}
8833
8834
8835/*
8836 * wifitool athN sendbcnrpt
8837 * <STA MAC - Plugs in from Dest_MAC>
8838 * <regclass - Plugs in from RegClass - int>
8839 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
8840 * <rand_ivl - Plugs in from RandInt - string>
8841 * <duration - Plugs in from MeaDur - integer>
8842 * <mode - Plugs in from MeaMode - string>
8843 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
8844 * <rep_cond - Plugs in from RptCond - integer>
8845 * <rpt_detail - Plugs in from RptDet - integer>
8846 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
8847 * <chanrpt_mode - Plugs in from APChanRpt - integer>
8848 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
8849 * [AP channel numbers]
8850 */
8851static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
8852 struct sigma_cmd *cmd,
8853 const char *ifname)
8854{
8855 char buf[100];
8856 int rpt_det;
8857 const char *str_val;
8858 const char *mea_mode;
8859
8860 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
8861
8862 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
8863 return -1;
8864 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
8865 return -1;
8866 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
8867 return -1;
8868 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
8869 return -1;
8870 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
8871 return -1;
8872
8873 str_val = get_param(cmd, "MeaMode");
8874 if (!str_val) {
8875 sigma_dut_print(dut, DUT_MSG_ERROR,
8876 "MeaMode parameter not present in send bcn-rpt-req");
8877 return -1;
8878 }
8879 if (strcasecmp(str_val, "passive") == 0) {
8880 mea_mode = " 0";
8881 } else if (strcasecmp(str_val, "active") == 0) {
8882 mea_mode = " 1";
8883 } else if (strcasecmp(str_val, "table") == 0) {
8884 mea_mode = " 2";
8885 } else {
8886 sigma_dut_print(dut, DUT_MSG_ERROR,
8887 "MEA-MODE Value not correctly given");
8888 return -1;
8889 }
Peng Xu591be452017-05-10 17:27:28 -07008890 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008891
8892 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
8893
8894 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
8895 return -1;
8896
8897 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
8898 return -1;
8899 str_val = get_param(cmd, "RptDet");
8900 rpt_det = str_val ? atoi(str_val) : 0;
8901
8902 if (rpt_det)
8903 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
8904 else
Peng Xu591be452017-05-10 17:27:28 -07008905 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008906
8907 if (rpt_det)
8908 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
8909 sizeof(buf));
8910 else
Peng Xu591be452017-05-10 17:27:28 -07008911 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008912
8913 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
8914 return -1;
8915
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08008916 str_val = get_param(cmd, "APChanRpt");
8917 if (str_val) {
8918 const char *pos;
8919 int ap_chanrpt;
8920 int ap_chanrpt_2 = 0;
8921 char chanrpt[100];
8922
8923 ap_chanrpt = atoi(str_val);
8924 pos = strchr(str_val, '_');
8925 if (pos) {
8926 pos++;
8927 ap_chanrpt_2 = atoi(pos);
8928 }
8929 if (ap_chanrpt) {
8930 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
8931 strlcat(buf, chanrpt, sizeof(buf));
8932 }
8933 if (ap_chanrpt_2) {
8934 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
8935 strlcat(buf, chanrpt, sizeof(buf));
8936 }
8937 }
8938
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008939 run_system(dut, buf);
8940 return 0;
8941}
8942
8943
8944static void inform_and_sleep(struct sigma_dut *dut, int seconds)
8945{
8946 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
8947 sleep(seconds);
8948 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
8949 seconds);
8950}
8951
8952
8953static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
8954 struct sigma_cmd *cmd, const char *ifname)
8955{
8956 unsigned char mac_addr[ETH_ALEN];
8957 int disassoc_timer;
8958 char buf[100];
8959 const char *val;
8960 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008961
8962 val = get_param(cmd, "Dest_MAC");
8963 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
8964 sigma_dut_print(dut, DUT_MSG_ERROR,
8965 "MAC Address not in proper format");
8966 return -1;
8967 }
8968
8969 val = get_param(cmd, "Disassoc_Timer");
8970 if (val)
8971 disassoc_timer = atoi(val);
8972 else
8973 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02008974 if (disassoc_timer < 0) {
8975 sigma_dut_print(dut, DUT_MSG_ERROR,
8976 "Invalid Disassoc_Timer value %d",
8977 disassoc_timer);
8978 return -1;
8979 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008980
8981 val = get_param(cmd, "Cand_List");
8982 if (val && val[0])
8983 cand_list = atoi(val);
8984
8985 val = get_param(cmd, "BTMQuery_Reason_Code");
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008986 if (val)
8987 run_iwpriv(dut, ifname, "mbo_trans_rs %s", val);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008988
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008989 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay)
8990 run_iwpriv(dut, ifname, "mbo_asoc_ret 1");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008991
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008992 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008993 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008994 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
8995 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
8996 dut->ap_btmreq_disassoc_imnt,
8997 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008998 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008999 dut->ap_btmreq_bss_term_dur);
9000 run_system(dut, buf);
9001
9002 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009003 if (dut->ap_btmreq_bss_term_tsf >= 2)
9004 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009005 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9006 mac_addr[0], mac_addr[1], mac_addr[2],
9007 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009008 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009009 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009010 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009011 run_system_wrapper(dut, "ifconfig %s up", ifname);
9012 } else if (dut->ap_btmreq_disassoc_imnt) {
9013 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009014 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9015 mac_addr[0], mac_addr[1], mac_addr[2],
9016 mac_addr[3], mac_addr[4], mac_addr[5]);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009017 }
9018 return 0;
9019}
9020
9021
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009022static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
9023 struct sigma_cmd *cmd, const char *ifname)
9024{
9025 unsigned char mac_addr[ETH_ALEN];
9026 const char *val;
9027
9028 val = get_param(cmd, "Dest_MAC");
9029 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9030 sigma_dut_print(dut, DUT_MSG_ERROR,
9031 "MAC Address not in proper format");
9032 return -1;
9033 }
9034
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009035 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9036 mac_addr[0], mac_addr[1], mac_addr[2],
9037 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009038 return 0;
9039}
9040
9041
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009042static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9043 struct sigma_cmd *cmd)
9044{
9045 const char *val;
9046 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009047
9048 ifname = get_main_ifname();
9049
9050 val = get_param(cmd, "FrameName");
9051 if (!val)
9052 return -1;
9053
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009054 if (strcasecmp(val, "BTMReq") == 0)
9055 ath_ap_send_frame_btm_req(dut, cmd, ifname);
9056 else if (strcasecmp(val, "BcnRptReq") == 0)
9057 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009058 else if (strcasecmp(val, "disassoc") == 0)
9059 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009060 else
9061 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009062
9063 return 1;
9064}
9065
9066
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009067static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9068 struct sigma_cmd *cmd)
9069{
9070 switch (get_driver_type()) {
9071 case DRIVER_ATHEROS:
9072 return ath_ap_send_frame_vht(dut, conn, cmd);
9073 break;
9074 case DRIVER_OPENWRT:
9075 switch (get_openwrt_driver_type()) {
9076 case OPENWRT_DRIVER_ATHEROS:
9077 return ath_ap_send_frame_vht(dut, conn, cmd);
9078 default:
9079 send_resp(dut, conn, SIGMA_ERROR,
9080 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9081 return 0;
9082 }
9083 default:
9084 send_resp(dut, conn, SIGMA_ERROR,
9085 "errorCode,Unsupported ap_send_frame with the current driver");
9086 return 0;
9087 }
9088}
9089
9090
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009091static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9092 struct sigma_cmd *cmd)
9093{
9094 switch (get_driver_type()) {
9095 case DRIVER_ATHEROS:
9096 return ath_ap_send_frame_loc(dut, conn, cmd);
9097 case DRIVER_OPENWRT:
9098 switch (get_openwrt_driver_type()) {
9099 case OPENWRT_DRIVER_ATHEROS:
9100 return ath_ap_send_frame_loc(dut, conn, cmd);
9101 default:
9102 send_resp(dut, conn, SIGMA_ERROR,
9103 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
9104 return 0;
9105 }
9106 default:
9107 send_resp(dut, conn, SIGMA_ERROR,
9108 "errorCode,Unsupported ap_send_frame_loc with the current driver");
9109 return 0;
9110 }
9111}
9112
9113
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009114static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9115 struct sigma_cmd *cmd)
9116{
9117 switch (get_driver_type()) {
9118 case DRIVER_ATHEROS:
9119 return ath_ap_send_frame_mbo(dut, conn, cmd);
9120 case DRIVER_OPENWRT:
9121 switch (get_openwrt_driver_type()) {
9122 case OPENWRT_DRIVER_ATHEROS:
9123 return ath_ap_send_frame_mbo(dut, conn, cmd);
9124 default:
9125 send_resp(dut, conn, SIGMA_ERROR,
9126 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9127 return 0;
9128 }
9129 default:
9130 send_resp(dut, conn, SIGMA_ERROR,
9131 "errorCode,Unsupported ap_send_frame with the current driver");
9132 return 0;
9133 }
9134}
9135
9136
Lior David0fe101e2017-03-09 16:09:50 +02009137static int ap_send_frame_60g(struct sigma_dut *dut,
9138 struct sigma_conn *conn,
9139 struct sigma_cmd *cmd)
9140{
9141 switch (get_driver_type()) {
9142#ifdef __linux__
9143 case DRIVER_WIL6210:
9144 return wil6210_send_frame_60g(dut, conn, cmd);
9145#endif /* __linux__ */
9146 default:
9147 send_resp(dut, conn, SIGMA_ERROR,
9148 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9149 return 0;
9150 }
9151}
9152
9153
Jouni Malinenf7222712019-06-13 01:50:21 +03009154enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
9155 struct sigma_conn *conn,
9156 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009157{
9158 /* const char *name = get_param(cmd, "NAME"); */
9159 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9160 const char *val;
9161 enum send_frame_type frame;
9162 enum send_frame_protection protected;
9163 char buf[100];
9164
9165 val = get_param(cmd, "Program");
9166 if (val) {
9167 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07009168 strcasecmp(val, "HS2-R2") == 0 ||
9169 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009170 return ap_send_frame_hs2(dut, conn, cmd);
9171 if (strcasecmp(val, "VHT") == 0)
9172 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009173 if (strcasecmp(val, "LOC") == 0)
9174 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009175 if (strcasecmp(val, "MBO") == 0)
9176 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009177 if (strcasecmp(val, "60GHz") == 0)
9178 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009179 }
9180
9181 val = get_param(cmd, "PMFFrameType");
9182 if (val == NULL)
9183 val = get_param(cmd, "FrameName");
9184 if (val == NULL)
9185 val = get_param(cmd, "Type");
9186 if (val == NULL)
9187 return -1;
9188 if (strcasecmp(val, "disassoc") == 0)
9189 frame = DISASSOC;
9190 else if (strcasecmp(val, "deauth") == 0)
9191 frame = DEAUTH;
9192 else if (strcasecmp(val, "saquery") == 0)
9193 frame = SAQUERY;
9194 else {
9195 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9196 "PMFFrameType");
9197 return 0;
9198 }
9199
9200 val = get_param(cmd, "PMFProtected");
9201 if (val == NULL)
9202 val = get_param(cmd, "Protected");
9203 if (val == NULL)
9204 return -1;
9205 if (strcasecmp(val, "Correct-key") == 0 ||
9206 strcasecmp(val, "CorrectKey") == 0)
9207 protected = CORRECT_KEY;
9208 else if (strcasecmp(val, "IncorrectKey") == 0)
9209 protected = INCORRECT_KEY;
9210 else if (strcasecmp(val, "Unprotected") == 0)
9211 protected = UNPROTECTED;
9212 else {
9213 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9214 "PMFProtected");
9215 return 0;
9216 }
9217
9218 val = get_param(cmd, "stationID");
9219 if (val == NULL)
9220 return -1;
9221
9222 if (protected == INCORRECT_KEY ||
9223 (protected == UNPROTECTED && frame == SAQUERY))
9224 return ap_inject_frame(dut, conn, frame, protected, val);
9225
9226 switch (frame) {
9227 case DISASSOC:
9228 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
9229 val, protected == CORRECT_KEY);
9230 break;
9231 case DEAUTH:
9232 snprintf(buf, sizeof(buf), "deauth %s test=%d",
9233 val, protected == CORRECT_KEY);
9234 break;
9235 case SAQUERY:
9236 snprintf(buf, sizeof(buf), "sa_query %s", val);
9237 break;
9238 }
9239
9240 if (run_hostapd_cli(dut, buf) != 0)
9241 return -2;
9242
9243 return 1;
9244}
9245
9246
Jouni Malinenf7222712019-06-13 01:50:21 +03009247static enum sigma_cmd_result cmd_ap_get_mac_address(struct sigma_dut *dut,
9248 struct sigma_conn *conn,
9249 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009250{
9251#if defined( __linux__)
9252 /* const char *name = get_param(cmd, "NAME"); */
9253 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03009254 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009255 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009256 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009257 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009258 int s, wlan_tag = 1;
9259 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009260
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009261 val = get_param(cmd, "WLAN_TAG");
9262 if (val) {
9263 wlan_tag = atoi(val);
9264 if (wlan_tag < 1 || wlan_tag > 3) {
9265 /*
9266 * The only valid WLAN Tags as of now as per the latest
9267 * WFA scripts are 1, 2, and 3.
9268 */
Jouni Malinenf8984642017-10-12 00:02:37 +03009269 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009270 "errorCode,Unsupported WLAN_TAG");
9271 return 0;
9272 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009273 }
9274
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009275 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
9276
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009277 s = socket(AF_INET, SOCK_DGRAM, 0);
9278 if (s < 0)
9279 return -1;
9280 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009281 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009282 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9283 perror("ioctl");
9284 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03009285 snprintf(resp, sizeof(resp),
9286 "errorCode,Could not find interface %s", ifname);
9287 send_resp(dut, conn, SIGMA_ERROR, resp);
9288 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009289 }
9290 close(s);
9291 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
9292
9293 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9294 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9295 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9296 return 0;
9297#elif defined( __QNXNTO__)
9298 char resp[50];
9299 unsigned char addr[6];
9300
9301 if (!sigma_main_ifname) {
9302 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
9303 return 0;
9304 }
9305
9306 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
9307 send_resp(dut, conn, SIGMA_ERROR,
9308 "errorCode,Failed to get address");
9309 return 0;
9310 }
9311 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9312 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9313 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9314 return 0;
9315#else /* __linux__ */
9316 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
9317 "yet supported");
9318 return 0;
9319#endif /* __linux__ */
9320}
9321
9322
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309323int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
9324 struct sigma_cmd *cmd)
9325{
9326 return cmd_ap_get_mac_address(dut, conn, cmd);
9327}
9328
9329
Jouni Malinenf7222712019-06-13 01:50:21 +03009330static enum sigma_cmd_result cmd_ap_set_pmf(struct sigma_dut *dut,
9331 struct sigma_conn *conn,
9332 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009333{
9334 /*
9335 * Ignore the command since the parameters are already handled through
9336 * ap_set_security.
9337 */
9338
9339 return 1;
9340}
9341
9342
Jouni Malinenf7222712019-06-13 01:50:21 +03009343static enum sigma_cmd_result cmd_ap_set_hs2(struct sigma_dut *dut,
9344 struct sigma_conn *conn,
9345 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009346{
9347 /* const char *name = get_param(cmd, "NAME"); */
9348 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9349 const char *val, *dest;
9350 char *pos, buf[100];
9351 int i, wlan_tag = 1;
9352
9353 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
9354 "following parameters");
9355 for (i = 0; i < cmd->count; i++) {
9356 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
9357 (cmd->values[i] ? cmd->values[i] : "NULL"));
9358 }
9359
9360 val = get_param(cmd, "ICMPv4_ECHO");
9361 if (val && atoi(val)) {
9362 snprintf(buf, sizeof(buf), "ebtables -F");
9363 if (system(buf) != 0) {
9364 sigma_dut_print(dut, DUT_MSG_ERROR,
9365 "Failed to set ebtables rules, RULE-12");
9366 }
9367 return 1;
9368 }
9369
9370 val = get_param(cmd, "WLAN_TAG");
9371 if (val) {
9372 wlan_tag = atoi(val);
9373 if (wlan_tag != 1 && wlan_tag != 2) {
9374 send_resp(dut, conn, SIGMA_INVALID,
9375 "errorCode,Invalid WLAN_TAG");
9376 return 0;
9377 }
9378 }
9379
9380 if (wlan_tag == 2) {
9381 val = get_param(cmd, "PROXY_ARP");
9382 if (val)
9383 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02009384
9385 val = get_param(cmd, "OSU");
9386 if (val)
9387 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009388 return 1;
9389 }
9390
9391 dest = get_param(cmd, "STA_MAC");
9392 if (dest) {
9393 /* This is a special/ugly way of using this command.
9394 * If "Dest" MAC is included, assume that this command
9395 * is being issued after ap_config_commit for dynamically
9396 * setting the QoS Map Set.
9397 */
9398 val = get_param(cmd, "QoS_MAP_SET");
9399 if (val) {
9400 dut->ap_qos_map_set = atoi(val);
9401 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9402 dut->ap_qos_map_set);
9403 }
9404
9405 if (dut->ap_qos_map_set == 1)
9406 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9407 else if (dut->ap_qos_map_set == 2)
9408 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9409
9410 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9411 if (run_hostapd_cli(dut, buf) != 0)
9412 return -1;
9413 }
9414
9415 val = get_param(cmd, "DGAF_DISABLE");
9416 if (val)
9417 dut->ap_dgaf_disable = atoi(val);
9418
9419 dut->ap_interworking = 1;
9420
9421 val = get_param(cmd, "INTERWORKING");
9422 if (val == NULL)
9423 val = get_param(cmd, "INTERNETWORKING");
9424 if (val != NULL && atoi(val) == 0) {
9425 dut->ap_interworking = 0;
9426 dut->ap_hs2 = 0;
9427 return 1;
9428 }
9429
9430 val = get_param(cmd, "ACCS_NET_TYPE");
9431 if (val) {
9432 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
9433 strcasecmp(val, "Chargable_Public_Network") == 0 ||
9434 strcasecmp(val, "Chargable Public Network") == 0)
9435 dut->ap_access_net_type = 2;
9436 else
9437 dut->ap_access_net_type = atoi(val);
9438 }
9439
9440 val = get_param(cmd, "INTERNET");
9441 if (val)
9442 dut->ap_internet = atoi(val);
9443
9444 val = get_param(cmd, "VENUE_GRP");
9445 if (val) {
9446 if (strcasecmp(val, "Business") == 0)
9447 dut->ap_venue_group = 2;
9448 else
9449 dut->ap_venue_group = atoi(val);
9450 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9451 dut->ap_venue_name);
9452 }
9453
9454 val = get_param(cmd, "VENUE_TYPE");
9455 if (val) {
9456 if (strcasecmp(val, "R&D") == 0)
9457 dut->ap_venue_type = 8;
9458 else
9459 dut->ap_venue_type = atoi(val);
9460 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
9461 dut->ap_venue_type);
9462 }
9463
9464 val = get_param(cmd, "HESSID");
9465 if (val) {
9466 if (strlen(val) >= sizeof(dut->ap_hessid)) {
9467 send_resp(dut, conn, SIGMA_ERROR,
9468 "errorCode,Invalid HESSID");
9469 return 0;
9470 }
9471 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
9472 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
9473 dut->ap_hessid);
9474 }
9475
9476 val = get_param(cmd, "ROAMING_CONS");
9477 if (val) {
9478 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
9479 send_resp(dut, conn, SIGMA_ERROR,
9480 "errorCode,Invalid ROAMING_CONS");
9481 return 0;
9482 }
9483 if (strcasecmp(val, "Disabled") == 0) {
9484 dut->ap_roaming_cons[0] = '\0';
9485 } else {
9486 snprintf(dut->ap_roaming_cons,
9487 sizeof(dut->ap_roaming_cons), "%s", val);
9488 }
9489 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
9490 dut->ap_roaming_cons);
9491 }
9492
9493 val = get_param(cmd, "ANQP");
9494 if (val)
9495 dut->ap_anqpserver_on = atoi(val);
9496
9497 val = get_param(cmd, "NAI_REALM_LIST");
9498 if (val) {
9499 dut->ap_nai_realm_list = atoi(val);
9500 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
9501 dut->ap_nai_realm_list);
9502 }
9503
9504 val = get_param(cmd, "3GPP_INFO");
9505 if (val) {
9506 /* What kind of encoding format is used?! */
9507 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
9508 "not yet supported (contents not fully defined)");
9509 return 0;
9510 }
9511
9512 val = get_param(cmd, "DOMAIN_LIST");
9513 if (val) {
9514 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
9515 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
9516 "DOMAIN_LIST");
9517 return 0;
9518 }
9519 snprintf(dut->ap_domain_name_list,
9520 sizeof(dut->ap_domain_name_list), "%s", val);
9521 pos = dut->ap_domain_name_list;
9522 while (*pos) {
9523 if (*pos == ';')
9524 *pos = ',';
9525 pos++;
9526 }
9527 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
9528 dut->ap_domain_name_list);
9529 }
9530
9531 val = get_param(cmd, "OPER_NAME");
9532 if (val) {
9533 dut->ap_oper_name = atoi(val);
9534 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
9535 dut->ap_oper_name);
9536 }
9537
9538 val = get_param(cmd, "VENUE_NAME");
9539 if (val) {
9540 dut->ap_venue_name = atoi(val);
9541 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9542 dut->ap_venue_name);
9543 }
9544
9545 val = get_param(cmd, "GAS_CB_DELAY");
9546 if (val) {
9547 dut->ap_gas_cb_delay = atoi(val);
9548 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
9549 dut->ap_gas_cb_delay);
9550 }
9551
9552 val = get_param(cmd, "MIH");
9553 if (val && atoi(val) > 0) {
9554 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
9555 "supported");
9556 return 0;
9557 }
9558
9559 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
9560 if (val) {
9561 dut->ap_l2tif = atoi(val);
9562 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
9563 dut->ap_l2tif);
9564 }
9565
9566 val = get_param(cmd, "BCST_UNCST");
9567 if (val) {
9568 send_resp(dut, conn, SIGMA_ERROR,
9569 "errorCode,BCST_UNCST not yet supported");
9570 return 0;
9571 }
9572
9573 val = get_param(cmd, "PLMN_MCC");
9574 if (val) {
9575 char mcc[100], *start, *end;
9576 int i = 0;
9577 if (strlen(val) >= sizeof(mcc)) {
9578 send_resp(dut, conn, SIGMA_ERROR,
9579 "errorCode,PLMN_MCC too long");
9580 return 0;
9581 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009582 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009583 start = mcc;
9584 while ((end = strchr(start, ';'))) {
9585 /* process all except the last */
9586 *end = '\0';
9587 if (strlen(start) != 3) {
9588 send_resp(dut, conn, SIGMA_ERROR,
9589 "errorCode,Invalid PLMN_MCC");
9590 return 0;
9591 }
9592 snprintf(dut->ap_plmn_mcc[i],
9593 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9594 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9595 dut->ap_plmn_mcc[i]);
9596 i++;
9597 start = end + 1;
9598 *end = ';';
9599 }
9600 if (strlen(start) != 3) {
9601 send_resp(dut, conn, SIGMA_ERROR,
9602 "errorCode,Invalid PLMN_MCC");
9603 return 0;
9604 }
9605 /* process last or only one */
9606 snprintf(dut->ap_plmn_mcc[i],
9607 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9608 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9609 dut->ap_plmn_mcc[i]);
9610 }
9611
9612 val = get_param(cmd, "PLMN_MNC");
9613 if (val) {
9614 char mnc[100], *start, *end;
9615 int i = 0;
9616 if (strlen(val) >= sizeof(mnc)) {
9617 send_resp(dut, conn, SIGMA_ERROR,
9618 "errorCode,PLMN_MNC too long");
9619 return 0;
9620 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009621 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009622 start = mnc;
9623 while ((end = strchr(start, ';'))) {
9624 *end = '\0';
9625 if (strlen(start) != 2 && strlen(start) != 3) {
9626 send_resp(dut, conn, SIGMA_ERROR,
9627 "errorCode,Invalid PLMN_MNC");
9628 return 0;
9629 }
9630 snprintf(dut->ap_plmn_mnc[i],
9631 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9632 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9633 dut->ap_plmn_mnc[i]);
9634 i++;
9635 start = end + 1;
9636 *end = ';';
9637 }
9638 if (strlen(start) != 2 && strlen(start) != 3) {
9639 send_resp(dut, conn, SIGMA_ERROR,
9640 "errorCode,Invalid PLMN_MNC");
9641 return 0;
9642 }
9643 snprintf(dut->ap_plmn_mnc[i],
9644 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9645 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9646 dut->ap_plmn_mnc[i]);
9647 }
9648
9649 val = get_param(cmd, "PROXY_ARP");
9650 if (val) {
9651 dut->ap_proxy_arp = atoi(val);
9652 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
9653 dut->ap_proxy_arp);
9654 }
9655
9656 val = get_param(cmd, "WAN_METRICS");
9657 if (val) {
9658 dut->ap_wan_metrics = atoi(val);
9659 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
9660 dut->ap_wan_metrics);
9661 }
9662
9663 val = get_param(cmd, "CONN_CAP");
9664 if (val) {
9665 dut->ap_conn_capab = atoi(val);
9666 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
9667 dut->ap_conn_capab);
9668 }
9669
9670 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
9671 if (val) {
9672 dut->ap_ip_addr_type_avail = atoi(val);
9673 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
9674 dut->ap_ip_addr_type_avail);
9675 }
9676
9677 val = get_param(cmd, "NET_AUTH_TYPE");
9678 if (val) {
9679 dut->ap_net_auth_type = atoi(val);
9680 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
9681 dut->ap_net_auth_type);
9682 }
9683
9684 val = get_param(cmd, "OP_CLASS");
9685 if (val == NULL)
9686 val = get_param(cmd, "OPER_CLASS");
9687 if (val) {
9688 dut->ap_oper_class = atoi(val);
9689 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
9690 dut->ap_oper_class);
9691 }
9692
9693 val = get_param(cmd, "OSU_PROVIDER_LIST");
9694 if (val) {
9695 dut->ap_osu_provider_list = atoi(val);
9696 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
9697 dut->ap_osu_provider_list);
9698 }
9699
Jouni Malinen93a837f2018-11-01 17:09:22 +02009700 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
9701 if (val) {
9702 dut->ap_osu_provider_nai_list = atoi(val);
9703 sigma_dut_print(dut, DUT_MSG_INFO,
9704 "ap_osu_provider_nai_list %d",
9705 dut->ap_osu_provider_nai_list);
9706 }
9707
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009708 val = get_param(cmd, "OSU_SERVER_URI");
9709 if (val) {
9710 i = 0;
9711 do {
9712 int len;
9713 const char *uri = val;
9714 val = strchr(val, ' ');
9715 len = val ? (val++ - uri) : (int) strlen(uri);
9716 if (len > 0 && len < 256) {
9717 memcpy(dut->ap_osu_server_uri[i], uri, len);
9718 dut->ap_osu_server_uri[i][len] = '\0';
9719 sigma_dut_print(dut, DUT_MSG_INFO,
9720 "ap_osu_server_uri[%d] %s", i,
9721 dut->ap_osu_server_uri[i]);
9722 }
9723 } while (val && ++i < 10);
9724 }
9725
9726 val = get_param(cmd, "OSU_METHOD");
9727 if (val) {
9728 i = 0;
9729 do {
9730 int len;
9731 const char *method = val;
9732 val = strchr(val, ' ');
9733 len = val ? (val++ - method) : (int) strlen(method);
9734 if (len > 0) {
9735 if (strncasecmp(method, "SOAP", len) == 0)
9736 dut->ap_osu_method[i] = 1;
9737 else if (strncasecmp(method, "OMADM", len) == 0)
9738 dut->ap_osu_method[i] = 0;
9739 else
9740 return -2;
9741 }
9742 } while (val && ++i < 10);
9743 }
9744
9745 val = get_param(cmd, "OSU_SSID");
9746 if (val) {
9747 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -07009748 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009749 sizeof(dut->ap_osu_ssid));
9750 sigma_dut_print(dut, DUT_MSG_INFO,
9751 "ap_osu_ssid %s",
9752 dut->ap_osu_ssid);
9753 }
9754 }
9755
9756 val = get_param(cmd, "OSU_ICON_TAG");
9757 if (val)
9758 dut->ap_osu_icon_tag = atoi(val);
9759
9760 val = get_param(cmd, "QoS_MAP_SET");
9761 if (val) {
9762 dut->ap_qos_map_set = atoi(val);
9763 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9764 dut->ap_qos_map_set);
9765 }
9766
9767 val = get_param(cmd, "BSS_LOAD");
9768 if (val) {
9769 dut->ap_bss_load = atoi(val);
9770 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
9771 dut->ap_bss_load);
9772 }
9773
Jouni Malinen54a89b02018-05-01 00:16:26 +03009774 val = get_param(cmd, "Venue_URL");
9775 if (val)
9776 dut->ap_venue_url = atoi(val);
9777
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03009778 val = get_param(cmd, "Advice_of_Charge");
9779 if (val)
9780 dut->ap_advice_of_charge = atoi(val);
9781
Jouni Malinenac104532018-05-01 00:27:37 +03009782 val = get_param(cmd, "Operator_Icon_Metadata");
9783 if (val)
9784 dut->ap_oper_icon_metadata = atoi(val);
9785
Jouni Malinenac367142018-05-01 00:32:24 +03009786 val = get_param(cmd, "TnC_File_Name");
9787 if (val)
9788 dut->ap_tnc_file_name = atoi(val);
9789
9790 val = get_param(cmd, "TnC_File_Time_Stamp");
9791 if (val)
9792 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
9793
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009794 return 1;
9795}
9796
9797
9798void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
9799{
9800 char buf[100];
9801
9802 if (!file_exists("nfc-status"))
9803 return;
9804
9805 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
9806 run_system(dut, buf);
9807}
9808
9809
9810static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
9811 const char *info)
9812{
9813 int res;
9814
9815 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
9816 printf("%s\n\n", info);
9817
9818 nfc_status(dut, "START", info);
9819 res = run_system(dut, cmd);
9820 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
9821 if (res) {
9822 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
9823 cmd, res);
9824 return res;
9825 }
9826
9827 return 0;
9828}
9829
9830
9831static int ap_nfc_write_config_token(struct sigma_dut *dut,
9832 struct sigma_conn *conn,
9833 struct sigma_cmd *cmd)
9834{
9835 int res;
9836 char buf[300];
9837
9838 run_system(dut, "killall wps-ap-nfc.py");
9839 unlink("nfc-success");
9840 snprintf(buf, sizeof(buf),
9841 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
9842 dut->summary_log ? "--summary " : "",
9843 dut->summary_log ? dut->summary_log : "");
9844 res = run_nfc_command(dut, buf,
9845 "Touch NFC Tag to write WPS configuration token");
9846 if (res || !file_exists("nfc-success")) {
9847 send_resp(dut, conn, SIGMA_ERROR,
9848 "ErrorCode,Failed to write tag");
9849 return 0;
9850 }
9851
9852 return 1;
9853}
9854
9855
9856static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
9857 struct sigma_conn *conn,
9858 struct sigma_cmd *cmd)
9859{
9860 int res;
9861 char buf[300];
9862
9863 run_system(dut, "killall wps-ap-nfc.py");
9864
9865 unlink("nfc-success");
9866 snprintf(buf, sizeof(buf),
9867 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9868 dut->summary_log ? "--summary " : "",
9869 dut->summary_log ? dut->summary_log : "");
9870 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
9871 if (res || !file_exists("nfc-success")) {
9872 send_resp(dut, conn, SIGMA_ERROR,
9873 "ErrorCode,Failed to read tag");
9874 return 0;
9875 }
9876
9877 return 1;
9878}
9879
9880
9881static int ap_nfc_write_password_token(struct sigma_dut *dut,
9882 struct sigma_conn *conn,
9883 struct sigma_cmd *cmd)
9884{
9885 int res;
9886 char buf[300];
9887
9888 run_system(dut, "killall wps-ap-nfc.py");
9889 unlink("nfc-success");
9890 snprintf(buf, sizeof(buf),
9891 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
9892 dut->summary_log ? "--summary " : "",
9893 dut->summary_log ? dut->summary_log : "");
9894 res = run_nfc_command(dut, buf,
9895 "Touch NFC Tag to write WPS password token");
9896 if (res || !file_exists("nfc-success")) {
9897 send_resp(dut, conn, SIGMA_ERROR,
9898 "ErrorCode,Failed to write tag");
9899 return 0;
9900 }
9901
9902 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
9903 send_resp(dut, conn, SIGMA_ERROR,
9904 "ErrorCode,Failed to enable NFC password token");
9905 return 0;
9906 }
9907
9908 return 1;
9909}
9910
9911
9912static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
9913 struct sigma_conn *conn,
9914 struct sigma_cmd *cmd)
9915{
9916 int res;
9917 char buf[300];
9918
9919 run_system(dut, "killall wps-ap-nfc.py");
9920 unlink("nfc-success");
9921 snprintf(buf, sizeof(buf),
9922 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
9923 dut->summary_log ? "--summary " : "",
9924 dut->summary_log ? dut->summary_log : "");
9925 res = run_nfc_command(dut, buf,
9926 "Touch NFC Device to respond to WPS connection handover");
9927 if (res) {
9928 send_resp(dut, conn, SIGMA_ERROR,
9929 "ErrorCode,Failed to enable NFC for connection "
9930 "handover");
9931 return 0;
9932 }
9933 if (!file_exists("nfc-success")) {
9934 send_resp(dut, conn, SIGMA_ERROR,
9935 "ErrorCode,Failed to complete NFC connection handover");
9936 return 0;
9937 }
9938
9939 return 1;
9940}
9941
9942
Jouni Malinenf7222712019-06-13 01:50:21 +03009943static enum sigma_cmd_result cmd_ap_nfc_action(struct sigma_dut *dut,
9944 struct sigma_conn *conn,
9945 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009946{
9947 /* const char *name = get_param(cmd, "Name"); */
9948 /* const char *intf = get_param(cmd, "Interface"); */
9949 const char *oper = get_param(cmd, "Operation");
9950
9951 if (oper == NULL)
9952 return -1;
9953
9954 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
9955 return ap_nfc_write_config_token(dut, conn, cmd);
9956 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
9957 return ap_nfc_write_password_token(dut, conn, cmd);
9958 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
9959 return ap_nfc_wps_read_passwd(dut, conn, cmd);
9960 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
9961 return ap_nfc_wps_connection_handover(dut, conn, cmd);
9962
9963 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
9964 return 0;
9965}
9966
9967
Jouni Malinenf7222712019-06-13 01:50:21 +03009968static enum sigma_cmd_result cmd_ap_wps_read_pin(struct sigma_dut *dut,
9969 struct sigma_conn *conn,
9970 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009971{
9972 char *pin = "12345670"; /* TODO: use random PIN */
9973 char resp[100];
9974
9975 snprintf(resp, sizeof(resp), "PIN,%s", pin);
9976 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9977
9978 return 0;
9979}
9980
9981
Jouni Malinenf7222712019-06-13 01:50:21 +03009982static enum sigma_cmd_result cmd_ap_wps_enter_pin(struct sigma_dut *dut,
9983 struct sigma_conn *conn,
9984 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +02009985{
9986 const char *pin = get_param(cmd, "PIN");
9987 char wps_pin[11];
9988
9989 if (!pin)
9990 return -1;
9991
9992 sigma_dut_print(dut, DUT_MSG_DEBUG,
9993 "Authorize a client to join with WPS PIN %s", pin);
9994
9995 strlcpy(wps_pin, pin, sizeof(wps_pin));
9996 /* we need to tolerate extra '-' characters entered */
9997 str_remove_chars(wps_pin, '-');
9998 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
9999 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
10000
10001 return 1;
10002}
10003
10004
Jouni Malinenf7222712019-06-13 01:50:21 +030010005static enum sigma_cmd_result cmd_ap_wps_set_pbc(struct sigma_dut *dut,
10006 struct sigma_conn *conn,
10007 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010008{
10009 sigma_dut_print(dut, DUT_MSG_DEBUG,
10010 "Selecting the push button configuration method");
10011
10012 dut->wps_method = WFA_CS_WPS_PBC;
10013
10014 return 1;
10015}
10016
10017
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020010018int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
10019 struct sigma_cmd *cmd)
10020{
10021 char buf[100], resp[256];
10022 const char *intf = get_param(cmd, "interface");
10023 const char *config_method = get_param(cmd, "WPSConfigMethod");
10024
10025 if (config_method && strcasecmp(config_method, "PBC") == 0)
10026 dut->wps_method = WFA_CS_WPS_PBC;
10027
10028 if (!intf)
10029 intf = get_main_ifname();
10030
10031 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
10032 send_resp(dut, conn, SIGMA_ERROR,
10033 "ErrorCode,WPS parameters not yet set");
10034 return STATUS_SENT;
10035 }
10036
10037 if (dut->wps_method == WFA_CS_WPS_PBC)
10038 snprintf(buf, sizeof(buf), "WPS_PBC");
10039 else /* WFA_CS_WPS_PIN_KEYPAD */
10040 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
10041
10042 /* Run WPS command */
10043 if (hapd_command(intf, buf) < 0) {
10044 /* command fails immediately if overlapped session detected */
10045 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
10046 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10047 return STATUS_SENT;
10048 }
10049
10050 /* In AP mode return immediately and do not wait for WPS registration */
10051 return SUCCESS_SEND_STATUS;
10052}
10053
10054
Jouni Malinenf7222712019-06-13 01:50:21 +030010055static enum sigma_cmd_result cmd_ap_get_parameter(struct sigma_dut *dut,
10056 struct sigma_conn *conn,
10057 struct sigma_cmd *cmd)
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010058{
10059 char value[256], resp[512];
10060 const char *param = get_param(cmd, "parameter");
10061 const char *ifname = get_param(cmd, "Interface");
10062
10063 if (!ifname)
10064 ifname = get_main_ifname();
10065
10066 if (!param) {
10067 send_resp(dut, conn, SIGMA_ERROR,
10068 "ErrorCode,Parameter not specified");
10069 return 0;
10070 }
10071
10072 if (strcasecmp(param, "SSID") == 0) {
10073 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
10074 sigma_dut_print(dut, DUT_MSG_ERROR,
10075 "Failed to get SSID");
10076 return -2;
10077 }
10078 snprintf(resp, sizeof(resp), "SSID,%s", value);
10079 } else if (strcasecmp(param, "PSK") == 0) {
10080 if (get_hapd_config(ifname, "passphrase", value,
10081 sizeof(value))) {
10082 sigma_dut_print(dut, DUT_MSG_ERROR,
10083 "Failed to get PSK");
10084 return -2;
10085 }
10086 snprintf(resp, sizeof(resp), "PSK,%s", value);
10087 } else {
10088 send_resp(dut, conn, SIGMA_ERROR,
10089 "ErrorCode,Unsupported parameter");
10090 return 0;
10091 }
10092
10093 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10094 return 0;
10095}
10096
10097
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010098static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
10099 const char *val)
10100{
10101 char *token, *result;
10102 int nss = 0, chwidth = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010103 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010104
10105 /*
10106 * The following commands should be invoked to generate
10107 * VHT op mode notification
10108 */
10109
10110 /* Extract the NSS info */
10111 token = strdup(val);
10112 if (!token)
10113 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010114 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010115 if (result) {
10116 int count = atoi(result);
10117
10118 /* We do not support NSS > 3 */
10119 if (count < 0 || count > 3) {
10120 free(token);
10121 return -1;
10122 }
10123
10124 /* Convert nss to chainmask */
10125 while (count--)
10126 nss = (nss << 1) | 1;
10127
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010128 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010129 }
10130
10131 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010132 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010133 if (result) {
10134 switch (atoi(result)) {
10135 case 20:
10136 chwidth = 0;
10137 break;
10138 case 40:
10139 chwidth = 1;
10140 break;
10141 case 80:
10142 chwidth = 2;
10143 break;
10144 case 160:
10145 chwidth = 3;
10146 break;
10147 default:
10148 chwidth = 2;
10149 break;
10150 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010151 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010152 }
10153
10154 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010155 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010156 free(token);
10157
10158 return 0;
10159}
10160
10161
10162static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
10163 const char *val)
10164{
10165 /* String (nss_operating_mode; mcs_operating_mode) */
10166 int nss, mcs;
10167 char *token, *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010168 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010169
10170 token = strdup(val);
10171 if (!token)
10172 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010173 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010174 if (!result) {
10175 sigma_dut_print(dut, DUT_MSG_ERROR,
10176 "VHT NSS not specified");
10177 goto end;
10178 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010179 if (strcasecmp(result, "def") != 0) {
10180 nss = atoi(result);
10181
10182 if (nss == 4)
10183 ath_disable_txbf(dut, ifname);
10184
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010185 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010186 } else {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010187 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
10188 run_iwpriv(dut, ifname, "nss 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010189 }
10190
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010191 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010192 if (!result) {
10193 sigma_dut_print(dut, DUT_MSG_ERROR,
10194 "VHT MCS not specified");
10195 goto end;
10196 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010197 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010198 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
10199 run_iwpriv(dut, ifname, "vhtmcs 7");
10200 else
10201 run_iwpriv(dut, ifname, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010202 } else {
10203 mcs = atoi(result);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010204 run_iwpriv(dut, ifname, "vhtmcs %d", mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010205 }
10206
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010207end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010208 free(token);
10209 return 0;
10210}
10211
10212
10213static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10214 const char *val)
10215{
10216 char *token, *result;
10217 int channel = 36;
10218 int chwidth = 80;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010219 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010220
10221 /* Extract the channel info */
10222 token = strdup(val);
10223 if (!token)
10224 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010225 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010226 if (result)
10227 channel = atoi(result);
10228
10229 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010230 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010231 if (result)
10232 chwidth = atoi(result);
10233
10234 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010235 run_iwpriv(dut, ifname, "doth_ch_chwidth %d 10 %d", channel, chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010236
10237 free(token);
10238 return 0;
10239}
10240
10241
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010242static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
10243 const char *val)
10244{
10245 char buf[80];
10246 unsigned char mac_addr[6];
10247
10248 if (parse_mac_address(dut, val, mac_addr) < 0)
10249 return -1;
10250
10251 snprintf(buf, sizeof(buf),
10252 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
10253 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
10254 run_system(dut, buf);
10255
10256 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
10257 ifname, mac_addr[4], mac_addr[5]);
10258 run_system(dut, buf);
10259
10260 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
10261 run_system(dut, buf);
10262
10263 return 0;
10264}
10265
10266
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010267void novap_reset(struct sigma_dut *dut, const char *ifname, int reset)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010268{
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010269 run_iwpriv(dut, ifname, "novap_reset %d", reset);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010270}
10271
10272
Jouni Malinenb4335432019-06-13 02:23:57 +030010273static struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
10274 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010275{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010276 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010277
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010278 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
10279 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
10280 ETH_ALEN) == 0)
10281 return &dut->mbo_pref_aps[i];
10282 }
10283 return NULL;
10284}
10285
10286
10287static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
10288 int ap_ne_class, int ap_ne_op_ch,
10289 int ap_ne_pref)
10290{
10291 struct mbo_pref_ap *entry;
10292 uint8_t self_mac[ETH_ALEN];
10293 char ifname[50];
10294
10295 get_if_name(dut, ifname, sizeof(ifname), 1);
10296 get_hwaddr(ifname, self_mac);
10297
10298 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
10299 entry = &dut->mbo_self_ap_tuple;
10300 else
10301 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
10302
10303 if (!entry) {
10304 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
10305 sigma_dut_print(dut, DUT_MSG_ERROR,
10306 "Nebor AP List is full. Not adding");
10307 return;
10308 }
10309 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
10310 dut->mbo_pref_ap_cnt++;
10311 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
10312 entry->ap_ne_class = -1;
10313 entry->ap_ne_op_ch = -1;
10314 entry->ap_ne_pref = -1;
10315 }
10316 if (ap_ne_class != -1)
10317 entry->ap_ne_class = ap_ne_class;
10318 if (ap_ne_op_ch != -1)
10319 entry->ap_ne_op_ch = ap_ne_op_ch;
10320 if (ap_ne_pref != -1)
10321 entry->ap_ne_pref = ap_ne_pref;
10322}
10323
10324
10325static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
10326 struct sigma_cmd *cmd)
10327{
10328 unsigned char mac_addr[ETH_ALEN];
10329 const char *val;
10330 /*
10331 * -1 is invalid value for the following
10332 * to differentiate between unset and set values
10333 * -1 => implies not set by CAPI
10334 */
10335 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
10336 int list_offset = dut->mbo_pref_ap_cnt;
10337
10338 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
10339 sigma_dut_print(dut, DUT_MSG_ERROR,
10340 "AP Pref Entry list is full");
10341 return -1;
10342 }
10343
10344 val = get_param(cmd, "Nebor_Op_Class");
10345 if (val)
10346 ap_ne_class = atoi(val);
10347
10348 val = get_param(cmd, "Nebor_Op_Ch");
10349 if (val)
10350 ap_ne_op_ch = atoi(val);
10351
10352 val = get_param(cmd, "Nebor_Pref");
10353 if (val)
10354 ap_ne_pref = atoi(val);
10355
10356 val = get_param(cmd, "Nebor_BSSID");
10357 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010358 return -1;
10359
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010360 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
10361 ap_ne_pref);
10362 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010363 return 0;
10364}
10365
10366
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010367static enum sigma_cmd_result he_ltf(struct sigma_dut *dut,
10368 struct sigma_conn *conn,
10369 const char *ifname, const char *val)
10370{
10371 const char *var;
10372
10373 if (dut->ap_he_ulofdma == VALUE_ENABLED)
10374 var = "he_ul_ltf";
10375 else
10376 var = "he_ltf";
10377
10378 if (strcmp(val, "6.4") == 0) {
10379 run_iwpriv(dut, ifname, "%s 2", var);
10380 } else if (strcmp(val, "12.8") == 0) {
10381 run_iwpriv(dut, ifname, "%s 3", var);
10382 } else if (strcmp(val, "3.2") == 0) {
10383 run_iwpriv(dut, ifname, "%s 1", var);
10384 } else {
10385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported LTF");
10386 return STATUS_SENT_ERROR;
10387 }
10388
10389 return SUCCESS_SEND_STATUS;
10390}
10391
10392
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070010393static enum sigma_cmd_result he_shortgi(struct sigma_dut *dut,
10394 struct sigma_conn *conn,
10395 const char *ifname,
10396 const char *val)
10397{
10398 const char *var;
10399
10400 if (dut->ap_he_ulofdma == VALUE_ENABLED)
10401 var = "he_ul_shortgi";
10402 else
10403 var = "shortgi";
10404
10405 if (strcmp(val, "0.8") == 0) {
10406 run_iwpriv(dut, ifname, "%s 0", var);
10407 } else if (strcmp(val, "1.6") == 0) {
10408 run_iwpriv(dut, ifname, "%s 2", var);
10409 } else if (strcmp(val, "3.2") == 0) {
10410 run_iwpriv(dut, ifname, "%s 3", var);
10411 } else {
10412 send_resp(dut, conn, SIGMA_ERROR,
10413 "errorCode,Unsupported shortGI");
10414 return STATUS_SENT_ERROR;
10415 }
10416
10417 return SUCCESS_SEND_STATUS;
10418}
10419
10420
10421static enum sigma_cmd_result he_ar_gi_ltf_mask(struct sigma_dut *dut,
10422 struct sigma_conn *conn,
10423 const char *ifname,
10424 const char *val)
10425{
10426
10427 uint32_t he_ar_gi_ltf;
10428 uint16_t he_ar_gi, he_ar_ltf;
10429
10430 if (strcmp(val, "0.4") == 0) {
10431 he_ar_gi = 0x01;
10432 } else if (strcmp(val, "0.8") == 0) {
10433 he_ar_gi = 0x02;
10434 } else if (strcmp(val, "1.6") == 0) {
10435 he_ar_gi = 0x04;
10436 } else if (strcmp(val, "3.2") == 0) {
10437 he_ar_gi = 0x08;
10438 } else {
10439 send_resp(dut, conn, SIGMA_ERROR,
10440 "errorCode,Unsupported shortGI");
10441 return STATUS_SENT_ERROR;
10442 }
10443
10444 if (dut->ar_ltf && strcmp(dut->ar_ltf, "6.4") == 0) {
10445 he_ar_ltf = 0x02;
10446 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "12.8") == 0) {
10447 he_ar_ltf = 0x04;
10448 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "3.2") == 0) {
10449 he_ar_ltf = 0x01;
10450 } else {
10451 send_resp(dut, conn, SIGMA_ERROR,
10452 "errorCode,Unsupported LTF");
10453 return STATUS_SENT_ERROR;
10454 }
10455
10456 he_ar_gi_ltf = (he_ar_gi << 8) | he_ar_ltf;
10457 run_iwpriv(dut, ifname, "he_ar_gi_ltf %lu", he_ar_gi_ltf);
10458
10459 return SUCCESS_SEND_STATUS;
10460}
10461
10462
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070010463static enum sigma_cmd_result he_rualloctones(struct sigma_dut *dut,
10464 struct sigma_conn *conn,
10465 const char *ifname,
10466 const char *val)
10467{
10468 char *token, *result;
10469 int value;
10470 char *saveptr;
10471 int rualloc_type;
10472 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
10473
10474 token = strdup(val);
10475 if (!token)
10476 return -1;
10477 result = strtok_r(token, ":", &saveptr);
10478 if (!result) {
10479 free(token);
10480 send_resp(dut, conn, SIGMA_ERROR,
10481 "errorCode,RUAllocTones not specified");
10482 return STATUS_SENT_ERROR;
10483 }
10484
10485 /*
10486 * ru_allocation_type can take the values of:
10487 * 1 - DL OFDMA data RU allocation
10488 * 3 - UL OFDMA data RU allocation
10489 */
10490 rualloc_type = dut->ap_he_ulofdma == VALUE_ENABLED ? 3 : 1;
10491
10492
10493 value = atoi(result);
10494 if (value == 106) {
10495 enum value_not_set_enabled_disabled ap_he_rualloc_106_80 =
10496 VALUE_NOT_SET;
10497
10498 result = strtok_r(NULL, ":", &saveptr);
10499 if (result) {
10500 result = strtok_r(NULL, ":", &saveptr);
10501 if (result)
10502 ap_he_rualloc_106_80 = VALUE_ENABLED;
10503 else
10504 ap_he_rualloc_106_80 = VALUE_DISABLED;
10505 }
10506 if (ap_he_rualloc_106_80 == VALUE_ENABLED) {
10507 run_system_wrapper(dut,
10508 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 2 1 2 2 2 3 2",
10509 ifname, rualloc_type);
10510 } else {
10511 run_system_wrapper(dut,
10512 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 2 1 2",
10513 ifname, rualloc_type);
10514 }
10515 } else if (value == 242) {
10516 run_system_wrapper(
10517 dut,
10518 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 3 1 3 2 3 3 3",
10519 ifname, rualloc_type);
10520 } else if (value == 26) {
10521 run_system_wrapper(
10522 dut,
10523 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 0 2 0 5 0 7 0",
10524 ifname, rualloc_type);
10525 } else if (value == 52) {
10526 run_system_wrapper(
10527 dut,
10528 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 1 1 1 2 1 3 1",
10529 ifname, rualloc_type);
10530 } else if (value == 484) {
10531 run_system_wrapper(
10532 dut,
10533 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 4 1 4",
10534 ifname, rualloc_type);
10535 } else if (value == 996) {
10536 run_system_wrapper(dut,
10537 "wifitool %s setUnitTestCmd 0x4b 3 %d 0 5",
10538 ifname, rualloc_type);
10539 } else {
10540 send_resp(dut, conn, SIGMA_ERROR,
10541 "errorCode,Unsupported RUAllocTones");
10542 ret = STATUS_SENT_ERROR;
10543 }
10544
10545 free(token);
10546 return ret;
10547}
10548
10549
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010550static enum sigma_cmd_result ath_ap_set_rfeature(struct sigma_dut *dut,
10551 struct sigma_conn *conn,
10552 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010553{
10554 const char *val;
10555 char *ifname;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010556 enum sigma_cmd_result res;
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070010557 const char *basedev = "wifi0";
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070010558 int trigtype;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070010559 int he_ackpolicymac = 0;
10560 unsigned char mac_addr[ETH_ALEN];
10561
10562 memset(mac_addr, 0x00, ETH_ALEN);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010563
10564 ifname = get_main_ifname();
10565
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070010566 if (sigma_radio_ifname[0])
10567 basedev = sigma_radio_ifname[0];
10568
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010569 /* Disable vap reset between the commands */
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010570 novap_reset(dut, ifname, 1);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010571
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010572 val = get_param(cmd, "Opt_md_notif_ie");
10573 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010574 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010575
10576 /* TODO: Optional arguments */
10577
10578 val = get_param(cmd, "nss_mcs_opt");
10579 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010580 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010581
10582 val = get_param(cmd, "chnum_band");
10583 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010584 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010585
10586 val = get_param(cmd, "RTS_FORCE");
10587 if (val)
10588 ath_config_rts_force(dut, ifname, val);
10589
10590 val = get_param(cmd, "DYN_BW_SGNL");
10591 if (val)
10592 ath_config_dyn_bw_sig(dut, ifname, val);
10593
10594 val = get_param(cmd, "CTS_WIDTH");
10595 if (val)
10596 ath_set_cts_width(dut, ifname, val);
10597
10598 val = get_param(cmd, "Ndpa_stainfo_mac");
10599 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010600 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010601
10602 val = get_param(cmd, "txBandwidth");
10603 if (val && ath_set_width(dut, conn, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010604 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010605
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010606 val = get_param(cmd, "Assoc_Disallow");
10607 if (val)
10608 ath_set_assoc_disallow(dut, ifname, val);
10609
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010610
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010611 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010612 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010613 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010614 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010615 dut->ap_disassoc_timer = 1000;
10616 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010617
10618 val = get_param(cmd, "BTMReq_Term_Bit");
10619 if (val)
10620 dut->ap_btmreq_term_bit = atoi(val);
10621
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010622 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010623 if (val) {
10624 dut->ap_assoc_delay = 1;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010625 run_iwpriv(dut, ifname, "mbo_asoc_ret %s", val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010626 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010627
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010628 val = get_param(cmd, "Disassoc_Timer");
10629 if (val)
10630 dut->ap_disassoc_timer = atoi(val);
10631
10632 val = get_param(cmd, "BSS_Term_Duration");
10633 if (val)
10634 dut->ap_btmreq_bss_term_dur = atoi(val);
10635
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080010636 val = get_param(cmd, "BSS_Term_TSF");
10637 if (val)
10638 dut->ap_btmreq_bss_term_tsf = atoi(val);
10639
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010640 val = get_param(cmd, "TxPower");
10641 if (val)
10642 ath_set_txpower(dut, ifname, val);
10643
10644 val = get_param(cmd, "DownlinkAvailCap");
10645 if (val)
10646 dut->ap_dl_availcap = atoi(val);
10647
10648 val = get_param(cmd, "UplinkAvailCap");
10649 if (val) {
10650 dut->ap_ul_availcap = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010651 run_iwpriv(dut, ifname, "oce_wan_mtr %d %d",
10652 dut->ap_dl_availcap, dut->ap_ul_availcap);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010653 }
10654
10655 val = get_param(cmd, "RSSIthreshold");
10656 if (val) {
10657 int rssithreshold;
10658
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010659 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010660 rssithreshold = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010661 run_iwpriv(dut, ifname, "oce_asoc_rssi %d", rssithreshold);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010662 }
10663
10664 val = get_param(cmd, "RetryDelay");
10665 if (val) {
10666 int retrydelay;
10667
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010668 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010669 retrydelay = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010670 run_iwpriv(dut, ifname, "oce_asoc_dly %d", retrydelay);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080010671 }
10672
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010673 val = get_param(cmd, "LTF");
10674 if (val) {
10675 if (dut->ap_fixed_rate) {
10676 res = he_ltf(dut, conn, ifname, val);
10677 if (res != SUCCESS_SEND_STATUS)
10678 return res;
10679 } else {
10680 free(dut->ar_ltf);
10681 dut->ar_ltf = strdup(val);
10682 if (!dut->ar_ltf)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010683 return ERROR_SEND_STATUS;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010684 }
10685 }
10686
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070010687 val = get_param(cmd, "GI");
10688 if (val) {
10689 if (dut->ap_fixed_rate)
10690 res = he_shortgi(dut, conn, ifname, val);
10691 else
10692 res = he_ar_gi_ltf_mask(dut, conn, ifname, val);
10693 if (res != SUCCESS_SEND_STATUS)
10694 return res;
10695 }
10696
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070010697 val = get_param(cmd, "RUAllocTones");
10698 if (val) {
10699 res = he_rualloctones(dut, conn, ifname, val);
10700 if (res != SUCCESS_SEND_STATUS)
10701 return res;
10702 }
10703
Priyadharshini Gowthaman803fd662019-07-31 14:37:49 -070010704 val = get_param(cmd, "MPDU_MU_SpacingFactor");
10705 if (val)
10706 run_system_wrapper(dut,
10707 "wifitool %s setUnitTestCmd 0x48 2 119, %s",
10708 ifname, val);
10709
10710 val = get_param(cmd, "PPDUTxType");
10711 if (val) {
10712 if (strcasecmp(val, "HE-SU") == 0) {
10713 /* Change PPDU format type to HE-SU MCS 1 */
10714 run_system_wrapper(dut,
10715 "wifitool %s setUnitTestCmd 0x48 2 89 0x401",
10716 ifname);
10717 } else if (strcasecmp(val, "legacy") == 0) {
10718 /* Change PPDU format type to non-HT */
10719 run_system_wrapper(dut,
10720 "wifitool %s setUnitTestCmd 0x48 2 89 3",
10721 ifname);
10722 } else {
10723 send_resp(dut, conn, SIGMA_ERROR,
10724 "errorCode,Unsupported PPDUTxType");
10725 return STATUS_SENT_ERROR;
10726 }
10727 }
10728
10729 val = get_param(cmd, "TXOPDuration");
10730 if (val) {
10731 if (strcasecmp(val, "UNSPECIFIED") == 0) {
10732 /* The hardware is hardcoded with 0x7f; do nothing */
10733 } else {
10734 send_resp(dut, conn, SIGMA_ERROR,
10735 "errorCode,Unsupported TXOPDuration");
10736 return STATUS_SENT_ERROR;
10737 }
10738 }
10739
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070010740 val = get_param(cmd, "Trig_Usrinfo_UL-MCS");
10741 if (val)
10742 run_iwpriv(dut, ifname, "he_ul_mcs %d", atoi(val));
10743
10744 val = get_param(cmd, "Trig_Usrinfo_UL-Target-RSSI");
10745 if (val) {
10746 /* Set target RSSI to -55 dBm */
10747 run_system_wrapper(dut,
10748 "wifitool %s setUnitTestCmd 0x4b 2 7 %d",
10749 ifname, atoi(val) - 110);
10750 }
10751
10752 val = get_param(cmd, "Trig_Interval");
10753 if (val)
10754 run_iwpriv(dut, basedev, "he_ul_trig_int %d", atoi(val));
10755
10756 val = get_param(cmd, "Trig_ComInfo_ULLength");
10757 if (val)
10758 run_system_wrapper(dut,
10759 "wifitool %s setUnitTestCmd 0x48 2 141 %d",
10760 ifname, atoi(val));
10761
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070010762 val = get_param(cmd, "DisableTriggerType");
10763 if (val) {
10764 trigtype = atoi(val);
10765 switch (trigtype) {
10766 case 0:
10767 /* DisableTriggerType "0" for basic trigger */
10768 run_system_wrapper(dut,
10769 "wifitool %s setUnitTestCmd 0x47 2 42 0",
10770 ifname);
10771 break;
10772 default:
10773 /* Nothing to be done for now */
10774 break;
10775 }
10776 }
10777
10778 val = get_param(cmd, "Trigger_TxBF");
10779 if (val) {
10780 if (strcasecmp(val, "enable") == 0) {
10781 run_iwpriv(dut, ifname, "he_sounding_mode 0x9");
10782 } else if (strcasecmp(val, "disable") == 0) {
10783 run_iwpriv(dut, ifname, "he_sounding_mode 0x1");
10784 } else {
10785 send_resp(dut, conn, SIGMA_ERROR,
10786 "errorCode,Unsupported trigger_txbf");
10787 return STATUS_SENT_ERROR;
10788 }
10789 }
10790
Priyadharshini Gowthaman7b94f082019-07-31 14:38:25 -070010791 val = get_param(cmd, "Trig_UsrInfo_RUAlloc");
10792 if (val) {
10793 res = he_rualloctones(dut, conn, ifname, val);
10794 if (res != SUCCESS_SEND_STATUS)
10795 return res;
10796 }
10797
Priyadharshini Gowthaman8701fac2019-07-31 14:38:48 -070010798 val = get_param(cmd, "TriggerCoding");
10799 if (val) {
10800 if (strcasecmp(val, "BCC") == 0) {
10801 /* In case of LDPC enable this command can force BCC if
10802 * RU size <= 242 */
10803 run_iwpriv(dut, ifname, "he_ul_ldpc 0");
10804 } else if (strcasecmp(val, "LDPC") == 0) {
10805 novap_reset(dut, ifname, 0);
10806 run_iwpriv(dut, ifname, "he_ul_ldpc 1");
10807 novap_reset(dut, ifname, 1);
10808 } else {
10809 send_resp(dut, conn, SIGMA_ERROR,
10810 "errorCode,Unsupported TriggerCoding");
10811 return STATUS_SENT_ERROR;
10812 }
10813 }
10814
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070010815 val = get_param(cmd, "AckPolicy_MAC");
10816 if (val) {
10817 if (parse_mac_address(dut, val, mac_addr) < 0) {
10818 send_resp(dut, conn, SIGMA_ERROR,
10819 "errorCode,MAC Address not in proper format");
10820 return STATUS_SENT_ERROR;
10821 }
10822 he_ackpolicymac = 1;
10823 }
10824
10825 val = get_param(cmd, "AckPolicy");
10826 if (val) {
10827 int ap_he_ackpolicy;
10828
10829 ap_he_ackpolicy = atoi(val);
10830 if (ap_he_ackpolicy == 0 && he_ackpolicymac) {
10831 /* Disable all-BAR ackpolicy for MU-MIMO */
10832 run_system_wrapper(dut,
10833 "wifitool %s setUnitTestCmd 0x48 2 62 0",
10834 ifname);
10835 /* Disable all-BAR ackpolicy first */
10836 run_system_wrapper(dut,
10837 "wifitool %s setUnitTestCmd 0x48 2 64 0",
10838 ifname);
10839 /* Set normal ack policy for the STA with the specified
10840 * MAC address in DL-TX case */
10841 run_system_wrapper(dut,
10842 "wifitool %s setUnitTestCmd 0x4b 8 8 1 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
10843 ifname, mac_addr[0], mac_addr[1],
10844 mac_addr[2], mac_addr[3],
10845 mac_addr[4], mac_addr[5]);
10846 } else if (ap_he_ackpolicy == 3) {
10847 /* Enable all-BAR ackpolicy for MU-MIMO DL */
10848 run_system_wrapper(dut,
10849 "wifitool %s setUnitTestCmd 0x48 2 62 1",
10850 ifname);
10851 /* Enable all-BAR ackpolicy */
10852 run_system_wrapper(dut,
10853 "wifitool %s setUnitTestCmd 0x48 2 64 1",
10854 ifname);
10855 } else if (ap_he_ackpolicy == 4) {
10856 /* Enable htp-ack ackpolicy */
10857 run_system_wrapper(dut,
10858 "wifitool %s setUnitTestCmd 0x47 2 99 1",
10859 ifname);
10860 } else {
10861 send_resp(dut, conn, SIGMA_ERROR,
10862 "errorCode,Invalid AckPolicy setting");
10863 return STATUS_SENT_ERROR;
10864 }
10865 }
10866
Priyadharshini Gowthamanc9a88c72019-08-09 12:04:17 -070010867 val = get_param(cmd, "Trig_ComInfo_GI-LTF");
10868 if (val) {
10869 int trig_gi_ltf;
10870
10871 trig_gi_ltf = atoi(val);
10872 if (trig_gi_ltf == 0) {
10873 he_ltf(dut, conn, ifname, "3.2");
10874 he_shortgi(dut, conn, ifname, "1.6");
10875 } else if (trig_gi_ltf == 1) {
10876 he_ltf(dut, conn, ifname, "6.4");
10877 he_shortgi(dut, conn, ifname, "1.6");
10878 } else if (trig_gi_ltf == 2) {
10879 he_ltf(dut, conn, ifname, "12.8");
10880 he_shortgi(dut, conn, ifname, "3.2");
10881 } else {
10882 send_resp(dut, conn, SIGMA_ERROR,
10883 "errorCode,Unsupported Trig_ComInfo_GI-LTF");
10884 return STATUS_SENT_ERROR;
10885 }
10886 }
10887
10888 val = get_param(cmd, "Trig_ComInfo_BW");
10889 if (val) {
10890 int chwidth;
10891
10892 chwidth = atoi(val);
10893 /* Set the channel width */
10894 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
10895 }
10896
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010897 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010898}
10899
10900
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010901static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10902 const char *val)
10903{
10904 char *token, *result;
10905 int channel = 36;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010906 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010907
10908 /* Extract the channel info */
10909 token = strdup(val);
10910 if (!token)
10911 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010912 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010913 if (result)
10914 channel = atoi(result);
10915
10916 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010917 run_iwpriv(dut, ifname, "setChanChange %d", channel);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053010918
10919 free(token);
10920 return 0;
10921}
10922
10923
10924static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10925 struct sigma_cmd *cmd)
10926{
10927 const char *val;
10928 char *ifname;
10929
10930 ifname = get_main_ifname();
10931
10932 val = get_param(cmd, "chnum_band");
10933 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
10934 return -1;
10935
10936 return 1;
10937}
10938
10939
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010940static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10941 const char *val)
10942{
10943 char *token, *result;
10944 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
10945 channel_freq;
10946 char buf[100];
10947 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +030010948 int res;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010949
10950 /* Extract the channel info */
10951 token = strdup(val);
10952 if (!token)
10953 return -1;
10954 result = strtok_r(token, ";", &saveptr);
10955 if (result)
10956 channel = atoi(result);
10957
10958 /* Extract the channel width info */
10959 result = strtok_r(NULL, ";", &saveptr);
10960 if (result)
10961 chwidth = atoi(result);
10962
10963 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
10964 if (center_freq_idx < 0) {
10965 free(token);
10966 return -1;
10967 }
10968
10969 center_freq = get_5g_channel_freq(center_freq_idx);
10970 channel_freq = get_5g_channel_freq(channel);
10971
10972 /* Issue the channel switch command */
Jouni Malinen3aa72862019-05-29 23:14:51 +030010973 res = snprintf(buf, sizeof(buf),
10974 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
10975 ifname, channel_freq, center_freq, chwidth);
10976 if (res < 0 || res >= sizeof(buf) || run_hostapd_cli(dut, buf) != 0) {
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053010977 sigma_dut_print(dut, DUT_MSG_ERROR,
10978 "hostapd_cli chan_switch failed");
10979 }
10980
10981 free(token);
10982 return 0;
10983}
10984
10985
10986static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
10987 struct sigma_conn *conn,
10988 struct sigma_cmd *cmd)
10989{
10990 const char *val;
10991 char *ifname;
10992
10993 ifname = get_main_ifname();
10994 val = get_param(cmd, "chnum_band");
10995 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
10996 return -1;
10997
10998 return 1;
10999}
11000
11001
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011002#ifdef __linux__
11003static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
11004 struct sigma_conn *conn,
11005 struct sigma_cmd *cmd)
11006{
11007 const char *val;
11008
11009 val = get_param(cmd, "ExtSchIE");
11010 if (val && !strcasecmp(val, "Enable")) {
11011 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11012 int count = MAX_ESE_ALLOCS;
11013
11014 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11015 return -1;
11016 if (wil6210_set_ese(dut, count, allocs))
11017 return -1;
11018 return 1;
11019 }
11020
11021 send_resp(dut, conn, SIGMA_ERROR,
11022 "errorCode,Invalid ap_set_rfeature(60G)");
11023 return 0;
11024}
11025#endif /* __linux__ */
11026
11027
Jouni Malinenf7222712019-06-13 01:50:21 +030011028static enum sigma_cmd_result cmd_ap_set_rfeature(struct sigma_dut *dut,
11029 struct sigma_conn *conn,
11030 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011031{
11032 /* const char *name = get_param(cmd, "NAME"); */
11033 /* const char *type = get_param(cmd, "Type"); */
11034
11035 switch (get_driver_type()) {
11036 case DRIVER_ATHEROS:
11037 return ath_ap_set_rfeature(dut, conn, cmd);
11038 case DRIVER_OPENWRT:
11039 switch (get_openwrt_driver_type()) {
11040 case OPENWRT_DRIVER_ATHEROS:
11041 return ath_ap_set_rfeature(dut, conn, cmd);
11042 default:
11043 send_resp(dut, conn, SIGMA_ERROR,
11044 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
11045 return 0;
11046 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053011047 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011048 case DRIVER_WCN:
11049 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053011050 case DRIVER_MAC80211:
11051 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011052#ifdef __linux__
11053 case DRIVER_WIL6210:
11054 return wil6210_ap_set_rfeature(dut, conn, cmd);
11055#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011056 default:
11057 send_resp(dut, conn, SIGMA_ERROR,
11058 "errorCode,Unsupported ap_set_rfeature with the current driver");
11059 return 0;
11060 }
11061}
11062
11063
Jouni Malinenf7222712019-06-13 01:50:21 +030011064static enum sigma_cmd_result cmd_accesspoint(struct sigma_dut *dut,
11065 struct sigma_conn *conn,
11066 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011067{
11068 /* const char *name = get_param(cmd, "NAME"); */
11069 return 1;
11070}
11071
11072
Jouni Malinenf7222712019-06-13 01:50:21 +030011073static enum sigma_cmd_result
11074cmd_ap_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
11075 struct sigma_cmd *cmd)
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080011076{
11077 const char *val;
11078
11079 val = get_param(cmd, "Oper_Chn");
11080 if (val) {
11081 dut->ap_oper_chn = 1;
11082 dut->ap_channel = atoi(val);
11083 }
11084
11085 return 1;
11086}
11087
11088
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011089void ap_register_cmds(void)
11090{
11091 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
11092 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
11093 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
11094 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
11095 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
11096 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053011097 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011098 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
11099 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
11100 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
11101 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
11102 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
11103 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
11104 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
11105 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
11106 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
11107 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
11108 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
11109 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
11110 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
11111 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
11112 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
11113 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020011114 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
11115 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011116 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011117 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080011118 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
11119 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011120}