blob: fdadfdb269bab58ddefaea8713a398bee4d63b09 [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_wpas_ctrl;
103extern char *sigma_hapd_ctrl;
104extern char *ap_inet_addr;
105extern char *ap_inet_mask;
106extern char *sigma_radio_ifname[];
107
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200108static int ath_ap_start_hostapd(struct sigma_dut *dut);
109static void ath_ap_set_params(struct sigma_dut *dut);
110static int kill_process(struct sigma_dut *dut, char *proc_name,
111 unsigned char is_proc_instance_one, int sig);
112
113
Jouni Malinen6be21c82018-08-01 18:47:24 +0300114static int ap_ft_enabled(struct sigma_dut *dut)
115{
116 return dut->ap_ft_oa == 1 ||
Jouni Malinen9f943312019-08-19 23:49:16 +0300117 dut->ap_ft_ds == VALUE_ENABLED ||
Jouni Malinen6be21c82018-08-01 18:47:24 +0300118 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
bings78387032019-12-06 17:50:05 +0800278static void wcn_config_ap_ldpc(struct sigma_dut *dut, const char *ifname)
279{
280 if (dut->ap_ldpc == VALUE_NOT_SET)
281 return;
282 run_iwpriv(dut, ifname, "ldpc %d", dut->ap_ldpc != VALUE_DISABLED);
283}
284
285
Tamizh chelvam638fb472019-08-15 14:00:31 +0530286static void mac80211_config_rts_force(struct sigma_dut *dut, const char *ifname,
287 const char *val)
288{
289 char buf[60];
290 char fname[128], path[128], *pos;
291 ssize_t res;
292
293 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
294 ifname);
295 if (res < 0 || res >= sizeof(fname))
296 return;
297
298 res = readlink(fname, path, sizeof(path));
299 if (res < 0)
300 return;
301
302 if (res >= (int) sizeof(path))
303 res = sizeof(path) - 1;
304 path[res] = '\0';
305
306 pos = strrchr(path, '/');
307 if (!pos)
308 pos = path;
309 else
310 pos++;
311
312 if (strcasecmp(val, "enable") == 0) {
313 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinen77dda642020-01-07 11:21:55 +0200314 res = snprintf(buf, sizeof(buf), "iw %s set rts 64", pos);
315 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Tamizh chelvam638fb472019-08-15 14:00:31 +0530316 sigma_dut_print(dut, DUT_MSG_ERROR,
317 "iw set rts 64 failed");
318 }
319 } else if (strcasecmp(val, "disable") == 0) {
320 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinen77dda642020-01-07 11:21:55 +0200321 res = snprintf(buf, sizeof(buf), "iw %s set rts 2347", pos);
322 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Tamizh chelvam638fb472019-08-15 14:00:31 +0530323 sigma_dut_print(dut, DUT_MSG_ERROR,
324 "iw rts 2347 failed");
325 }
326 } else {
327 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
328 }
329
330}
331
332
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200333static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
334 const char *val)
335{
336 char buf[60];
337
338 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200339 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
341 if (system(buf) != 0) {
342 sigma_dut_print(dut, DUT_MSG_ERROR,
343 "iwconfig rts 64 failed");
344 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800345 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
346 ifname);
347 if (system(buf) != 0) {
348 sigma_dut_print(dut, DUT_MSG_ERROR,
349 "wifitool beeliner_fw_test 100 1 failed");
350 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200351 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200352 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200353 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
354 if (system(buf) != 0) {
355 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700356 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200357 }
358 } else {
359 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
360 }
361}
362
363
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800364static void ath_radio(struct sigma_dut *dut, const char *val)
365{
366 if (strcasecmp(val, "on") == 0) {
367 if (dut->ap_interface_5g == 1) {
368 run_system(dut, "uci set wireless.wifi0.disabled=0");
369 } else if (dut->ap_interface_2g == 1) {
370 run_system(dut, "uci set wireless.wifi1.disabled=0");
371 } else {
372 run_system(dut, "uci set wireless.wifi0.disabled=0");
373 run_system(dut, "uci set wireless.wifi1.disabled=0");
374 }
375 run_system(dut, "uci commit");
376 run_system(dut, "wifi down");
377 run_system(dut, "wifi up");
378 } else if (strcasecmp(val, "off") == 0) {
379 if (dut->ap_interface_5g == 1) {
380 run_system(dut, "uci set wireless.wifi0.disabled=1");
381 } else if (dut->ap_interface_2g == 1) {
382 run_system(dut, "uci set wireless.wifi1.disabled=1");
383 } else {
384 run_system(dut, "uci set wireless.wifi0.disabled=1");
385 run_system(dut, "uci set wireless.wifi1.disabled=1");
386 }
387 run_system(dut, "uci commit");
388 run_system(dut, "wifi down");
389 run_system(dut, "wifi up");
390 }
391}
392
393
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800394static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
395 const char *val)
396{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700397 if (strcasecmp(val, "disable") == 0)
398 run_iwpriv(dut, ifname, "stealthdown 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800399}
400
401
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800402static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
403 const char *val)
404{
405 char buf[60];
406
407 if (strcasecmp(val, "high") == 0)
408 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
409 else if (strcasecmp(val, "low") == 0)
410 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
411 else
412 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
413
414 if (system(buf) != 0)
415 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
416}
417
418
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200419static enum ap_mode get_mode(const char *str)
420{
421 if (strcasecmp(str, "11a") == 0)
422 return AP_11a;
423 else if (strcasecmp(str, "11g") == 0)
424 return AP_11g;
425 else if (strcasecmp(str, "11b") == 0)
426 return AP_11b;
427 else if (strcasecmp(str, "11na") == 0)
428 return AP_11na;
429 else if (strcasecmp(str, "11ng") == 0)
430 return AP_11ng;
431 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
432 return AP_11ac;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200433 else if (strcasecmp(str, "11ad") == 0)
434 return AP_11ad;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -0800435 else if (strcasecmp(str, "11ax") == 0)
436 return AP_11ax;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200437 else
438 return AP_inval;
439}
440
441
442static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
443{
444 char command[1000];
445 const char *bin;
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200446 enum driver_type drv = get_driver_type(dut);
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700447 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200448
449 if (file_exists("hostapd_cli"))
450 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300451 else if (file_exists("../../hostapd/hostapd_cli"))
452 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200453 else
454 bin = "hostapd_cli";
455
456 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700457 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200458
459 if (sigma_radio_ifname[0] &&
460 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700461 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200462 else if (sigma_radio_ifname[0] &&
463 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700464 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200465 }
466
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700467 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200468 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700469 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200470 else
471 snprintf(command, sizeof(command), "%s %s", bin, buf);
472 return run_system(dut, command);
473}
474
475
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700476static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
477 struct sigma_cmd *cmd)
478{
479 FILE *f;
480 int i;
481
482 f = fopen("/tmp/lci_cfg.txt", "w");
483 if (!f) {
484 sigma_dut_print(dut, DUT_MSG_ERROR,
485 "Failed to open /tmp/lci_cfg.txt");
486 return -1;
487 }
488
489 for (i = 2; i < cmd->count; i++)
490 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
491 fprintf(f, "\n");
492 fclose(f);
493
494 return 0;
495}
496
497
hangtian00606622019-04-19 11:15:48 +0800498static void set_ap_country_code(struct sigma_dut *dut)
499{
500#if defined(ANDROID) || defined(LINUX_EMBEDDED)
501 char buf[256];
502
503 if (dut->ap_countrycode[0]) {
504 snprintf(buf, sizeof(buf), "DRIVER COUNTRY %s",
505 dut->ap_countrycode);
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200506 if (wpa_command(get_station_ifname(dut), buf) < 0)
hangtian00606622019-04-19 11:15:48 +0800507 sigma_dut_print(dut, DUT_MSG_ERROR,
508 "Failed to set country code");
509 else
510 sigma_dut_print(dut, DUT_MSG_INFO,
511 "Successfully set country code to %s",
512 dut->ap_countrycode);
513 }
514#endif
515}
516
517
Priyadharshini Gowthamane661f3b2019-11-13 16:24:29 -0800518static void set_vht_mcsmap_nss(struct sigma_dut *dut, int nss, int mcs)
519{
520 switch (nss) {
521 case 1:
522 switch (mcs) {
523 case 7:
524 dut->ap_vhtmcs_map = 0xfffc;
525 break;
526 case 8:
527 dut->ap_vhtmcs_map = 0xfffd;
528 break;
529 case 9:
530 dut->ap_vhtmcs_map = 0xfffe;
531 break;
532 default:
533 dut->ap_vhtmcs_map = 0xfffe;
534 break;
535 }
536 break;
537 case 2:
538 switch (mcs) {
539 case 7:
540 dut->ap_vhtmcs_map = 0xfff0;
541 break;
542 case 8:
543 dut->ap_vhtmcs_map = 0xfff5;
544 break;
545 case 9:
546 dut->ap_vhtmcs_map = 0xfffa;
547 break;
548 default:
549 dut->ap_vhtmcs_map = 0xfffa;
550 break;
551 }
552 break;
553 case 3:
554 switch (mcs) {
555 case 7:
556 dut->ap_vhtmcs_map = 0xffc0;
557 break;
558 case 8:
559 dut->ap_vhtmcs_map = 0xffd5;
560 break;
561 case 9:
562 dut->ap_vhtmcs_map = 0xffea;
563 break;
564 default:
565 dut->ap_vhtmcs_map = 0xffea;
566 break;
567 }
568 default:
569 dut->ap_vhtmcs_map = 0xffea;
570 break;
571 }
572}
573
574
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -0800575/* Get 2*nss bitmask */
576/* We are trying to pack 2-bit MCS values per NSS in a 16-bit wide field.
577 * IEEE P802.11ax/D5.0, 9.4.2.247.4 supported HE-MCS And NSS Set field
578 * defines the following format for the 16 bit value. */
579
580#define HE_GET_MCS_NSS_PACK_MASK(nss) ((1 << ((nss) << 1)) - 1)
581
582static void he_reset_mcs_values_for_unsupported_ss(uint8_t *mcsnssmap,
583 uint8_t nss)
584{
585 uint8_t nssmask;
586
587 if (nss <= 4) {
588 nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss);
589 mcsnssmap[0] |= nssmask;
590 mcsnssmap[1] = 0xff;
591 } else if (nss > 4 && nss <= 8) {
592 nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss - 4);
593 mcsnssmap[0] &= 0xff;
594 mcsnssmap[1] |= nssmask;
595 }
596}
597
598
599static void get_he_mcs_nssmap(uint8_t *mcsnssmap, uint8_t nss,
600 uint8_t mcs)
601{
602 switch (mcs) {
603 case 11:
604 mcsnssmap[0] = 0xaa;
605 mcsnssmap[1] = 0xaa;
606 break;
607 case 9:
608 mcsnssmap[0] = 0x55;
609 mcsnssmap[1] = 0x55;
610 break;
611 case 7:
612 mcsnssmap[0] = 0x0;
613 mcsnssmap[1] = 0x0;
614 break;
615 }
616 he_reset_mcs_values_for_unsupported_ss(mcsnssmap, nss);
617}
618
619
Jouni Malinenf7222712019-06-13 01:50:21 +0300620static enum sigma_cmd_result cmd_ap_set_wireless(struct sigma_dut *dut,
621 struct sigma_conn *conn,
622 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200623{
624 /* const char *name = get_param(cmd, "NAME"); */
625 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200626 const char *val;
627 unsigned int wlan_tag = 1;
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200628 const char *ifname = get_main_ifname(dut);
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +0200629 char buf[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200630
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200631 /* Allow program to be overridden if specified in the ap_set_wireless
632 * to support some 60 GHz test scripts where the program may be 60 GHz
633 * or WPS. */
634 val = get_param(cmd, "PROGRAM");
635 if (val)
636 dut->program = sigma_program_to_enum(val);
637
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200638 val = get_param(cmd, "WLAN_TAG");
639 if (val) {
640 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700641 if (wlan_tag < 1 || wlan_tag > 3) {
642 /*
643 * The only valid WLAN Tags as of now as per the latest
644 * WFA scripts are 1, 2, and 3.
645 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200646 send_resp(dut, conn, SIGMA_INVALID,
647 "errorCode,Invalid WLAN_TAG");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200648 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200649 }
650 }
651
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800652 val = get_param(cmd, "Interface");
653 if (val) {
654 if (strcasecmp(val, "5G") == 0)
655 dut->ap_interface_5g = 1;
656 else
657 dut->ap_interface_2g = 1;
658
659 if (dut->ap_interface_5g && dut->ap_interface_2g)
660 dut->ap_is_dual = 1;
661 }
662
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200663 val = get_param(cmd, "CountryCode");
664 if (val) {
665 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200666 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200667 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
668 "%s", val);
hangtian00606622019-04-19 11:15:48 +0800669
670 /*
671 * Regdomain self-managed driver does not accept hostapd country
672 * code setting in all cases. Try to use wpa_supplicant DRIVER
673 * command first to set the driver to a specific country code
674 * before starting AP functionality. This is targeting cases
675 * where wpa_supplicant is running on the device as well for
676 * non-AP mode functionality.
677 */
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200678 if (get_driver_type(dut) == DRIVER_LINUX_WCN)
hangtian00606622019-04-19 11:15:48 +0800679 set_ap_country_code(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200680 }
681
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530682 val = get_param(cmd, "regulatory_mode");
683 if (val) {
684 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
685 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
686 }
687
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200688 val = get_param(cmd, "SSID");
689 if (val) {
690 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200691 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200692
693 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700694 /*
695 * If tag is not specified, it is deemed to be 1.
696 * Hence tag of 1 is a special case and the values
697 * corresponding to wlan-tag=1 are stored separately
698 * from the values corresponding tags 2 and 3.
699 * This approach minimises the changes to existing code
700 * since most of the sigma_dut code does not deal with
701 * WLAN-TAG CAPI variable.
702 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200703 snprintf(dut->ap_ssid,
704 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700705 } else {
706 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
707 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
708 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200709 }
710 }
711
712 val = get_param(cmd, "CHANNEL");
713 if (val) {
714 const char *pos;
715 dut->ap_channel = atoi(val);
716 pos = strchr(val, ';');
717 if (pos) {
718 pos++;
719 dut->ap_channel_1 = atoi(pos);
720 }
721 }
722
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530723 /* Overwrite the AP channel with DFS channel if configured */
724 val = get_param(cmd, "dfs_chan");
725 if (val) {
726 dut->ap_channel = atoi(val);
727 }
728
729 val = get_param(cmd, "dfs_mode");
730 if (val) {
731 if (strcasecmp(val, "Enable") == 0)
732 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
733 else if (strcasecmp(val, "Disable") == 0)
734 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
735 else
736 sigma_dut_print(dut, DUT_MSG_ERROR,
737 "Unsupported dfs_mode value: %s", val);
738 }
739
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200740 val = get_param(cmd, "MODE");
741 if (val) {
742 char *str, *pos;
743
744 str = strdup(val);
745 if (str == NULL)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200746 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200747 pos = strchr(str, ';');
748 if (pos)
749 *pos++ = '\0';
750
751 dut->ap_is_dual = 0;
752 dut->ap_mode = get_mode(str);
753 if (dut->ap_mode == AP_inval) {
754 send_resp(dut, conn, SIGMA_INVALID,
755 "errorCode,Unsupported MODE");
756 free(str);
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200757 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200758 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800759 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200760 dut->ap_chwidth = AP_80;
761
762 if (pos) {
763 dut->ap_mode_1 = get_mode(pos);
764 if (dut->ap_mode_1 == AP_inval) {
765 send_resp(dut, conn, SIGMA_INVALID,
766 "errorCode,Unsupported MODE");
767 free(str);
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200768 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200769 }
770 if (dut->ap_mode_1 == AP_11ac)
771 dut->ap_chwidth_1 = AP_80;
772 dut->ap_is_dual = 1;
773 }
774
775 free(str);
776 } else if (dut->ap_mode == AP_inval) {
777 if (dut->ap_channel <= 11)
778 dut->ap_mode = AP_11ng;
779 else if (dut->program == PROGRAM_VHT)
780 dut->ap_mode = AP_11ac;
781 else
782 dut->ap_mode = AP_11na;
783 }
784
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200785 /* Override the AP mode in case of 60 GHz */
786 if (dut->program == PROGRAM_60GHZ) {
787 dut->ap_mode = AP_11ad;
788 /* Workaround to force channel 2 if not specified */
789 if (!dut->ap_channel)
790 dut->ap_channel = 2;
791 }
792
Jouni Malinen00535472019-11-06 19:43:35 +0200793 switch (dut->ap_mode) {
794 case AP_11g:
795 case AP_11b:
796 case AP_11ng:
797 dut->use_5g = 0;
798 break;
799 case AP_11a:
800 case AP_11na:
801 case AP_11ac:
802 dut->use_5g = 1;
803 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -0800804 case AP_11ax:
805 if (dut->ap_channel >= 1 && dut->ap_channel <= 14)
806 dut->use_5g = 0;
807 else if (dut->ap_channel >= 36 && dut->ap_channel <= 171)
808 dut->use_5g = 1;
809 break;
Jouni Malinen00535472019-11-06 19:43:35 +0200810 case AP_11ad:
811 case AP_inval:
812 break;
813 }
814
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530815 val = get_param(cmd, "WME");
816 if (val) {
817 if (strcasecmp(val, "on") == 0)
818 dut->ap_wme = AP_WME_ON;
819 else if (strcasecmp(val, "off") == 0)
820 dut->ap_wme = AP_WME_OFF;
821 else
822 sigma_dut_print(dut, DUT_MSG_ERROR,
823 "Unsupported WME value: %s", val);
824 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200825
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530826 val = get_param(cmd, "WMMPS");
827 if (val) {
828 if (strcasecmp(val, "on") == 0)
829 dut->ap_wmmps = AP_WMMPS_ON;
830 else if (strcasecmp(val, "off") == 0)
831 dut->ap_wmmps = AP_WMMPS_OFF;
832 else
833 sigma_dut_print(dut, DUT_MSG_ERROR,
834 "Unsupported WMMPS value: %s", val);
835 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200836
837 val = get_param(cmd, "RTS");
838 if (val)
839 dut->ap_rts = atoi(val);
840
841 val = get_param(cmd, "FRGMNT");
842 if (val)
843 dut->ap_frgmnt = atoi(val);
844
845 /* TODO: PWRSAVE */
846
847 val = get_param(cmd, "BCNINT");
848 if (val)
849 dut->ap_bcnint = atoi(val);
850
851 val = get_param(cmd, "RADIO");
852 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200853 enum driver_type drv = get_driver_type(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530854
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200855 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800856 if (drv == DRIVER_OPENWRT)
857 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200858 if (drv == DRIVER_ATHEROS)
859 ath_ap_start_hostapd(dut);
860 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200861 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530863 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800864 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300865 } else if (dut->use_hostapd_pid_file) {
866 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530867 } else if (kill_process(dut, "(hostapd)", 1,
868 SIGTERM) == 0 ||
869 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200870 sigma_dut_print(dut, DUT_MSG_INFO,
871 "Killed hostapd on radio,off");
872 }
873 } else {
874 send_resp(dut, conn, SIGMA_INVALID,
875 "errorCode,Unsupported RADIO value");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200876 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200877 }
878 }
879
880 val = get_param(cmd, "P2PMgmtBit");
881 if (val)
882 dut->ap_p2p_mgmt = atoi(val);
883
884 /* TODO: ChannelUsage */
885
886 /* TODO: 40_INTOLERANT */
887
888 val = get_param(cmd, "ADDBA_REJECT");
889 if (val) {
890 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200891 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200892 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200893 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200894 }
895
896 val = get_param(cmd, "AMPDU");
897 if (val) {
898 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200899 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200900 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200901 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200902 }
903
904 val = get_param(cmd, "AMPDU_EXP");
905 if (val)
906 dut->ap_ampdu_exp = atoi(val);
907
908 val = get_param(cmd, "AMSDU");
909 if (val) {
910 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200911 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200912 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200913 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200914 }
915
916 val = get_param(cmd, "NoAck");
917 if (val) {
918 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200919 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200920 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200921 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200922 }
923
924 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200925 /* TODO: MCS_32 */
926
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530927 val = get_param(cmd, "OFFSET");
928 if (val) {
929 if (strcasecmp(val, "Above") == 0)
930 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
931 else if (strcasecmp(val, "Below") == 0)
932 dut->ap_chwidth_offset = SEC_CH_40BELOW;
933 }
934
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200935 val = get_param(cmd, "MCS_FIXEDRATE");
936 if (val) {
937 dut->ap_fixed_rate = 1;
938 dut->ap_mcs = atoi(val);
939 }
940
941 val = get_param(cmd, "SPATIAL_RX_STREAM");
942 if (val) {
943 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
944 dut->ap_rx_streams = 1;
945 if (dut->device_type == AP_testbed)
946 dut->ap_vhtmcs_map = 0xfffc;
947 } else if (strcasecmp(val, "2SS") == 0 ||
948 strcasecmp(val, "2") == 0) {
949 dut->ap_rx_streams = 2;
950 if (dut->device_type == AP_testbed)
951 dut->ap_vhtmcs_map = 0xfff0;
952 } else if (strcasecmp(val, "3SS") == 0 ||
953 strcasecmp(val, "3") == 0) {
954 dut->ap_rx_streams = 3;
955 if (dut->device_type == AP_testbed)
956 dut->ap_vhtmcs_map = 0xffc0;
957 } else if (strcasecmp(val, "4SS") == 0 ||
958 strcasecmp(val, "4") == 0) {
959 dut->ap_rx_streams = 4;
960 }
961 }
962
963 val = get_param(cmd, "SPATIAL_TX_STREAM");
964 if (val) {
965 if (strcasecmp(val, "1SS") == 0 ||
966 strcasecmp(val, "1") == 0) {
967 dut->ap_tx_streams = 1;
968 if (dut->device_type == AP_testbed)
969 dut->ap_vhtmcs_map = 0xfffc;
970 } else if (strcasecmp(val, "2SS") == 0 ||
971 strcasecmp(val, "2") == 0) {
972 dut->ap_tx_streams = 2;
973 if (dut->device_type == AP_testbed)
974 dut->ap_vhtmcs_map = 0xfff0;
975 } else if (strcasecmp(val, "3SS") == 0 ||
976 strcasecmp(val, "3") == 0) {
977 dut->ap_tx_streams = 3;
978 if (dut->device_type == AP_testbed)
979 dut->ap_vhtmcs_map = 0xffc0;
980 } else if (strcasecmp(val, "4SS") == 0 ||
981 strcasecmp(val, "4") == 0) {
982 dut->ap_tx_streams = 4;
983 }
984 }
985
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700986 val = get_param(cmd, "BSS_max_idle");
987 if (val) {
988 if (strncasecmp(val, "Enable", 7) == 0) {
989 dut->wnm_bss_max_feature = VALUE_ENABLED;
990 } else if (strncasecmp(val, "Disable", 8) == 0) {
991 dut->wnm_bss_max_feature = VALUE_DISABLED;
992 } else {
993 send_resp(dut, conn, SIGMA_ERROR,
994 "errorCode,Invalid value for BSS_max_Feature");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200995 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700996 }
997 }
998
999 val = get_param(cmd, "BSS_Idle_Protection_options");
1000 if (val) {
1001 int protection = (int) strtol(val, (char **) NULL, 10);
1002
1003 if (protection != 1 && protection != 0) {
1004 send_resp(dut, conn, SIGMA_ERROR,
1005 "errorCode,Invalid value for BSS_Idle_Protection_options");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001006 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001007 }
1008 dut->wnm_bss_max_protection = protection ?
1009 VALUE_ENABLED : VALUE_DISABLED;
1010 }
1011
1012 val = get_param(cmd, "BSS_max_Idle_period");
1013 if (val) {
Jouni Malinen544edf02019-02-25 19:02:33 +02001014 long int idle_time = strtol(val, (char **) NULL, 10);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001015
1016 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
1017 send_resp(dut, conn, SIGMA_ERROR,
1018 "errorCode,Invalid value for BSS_max_Idle_period");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001019 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001020 }
Jouni Malinen544edf02019-02-25 19:02:33 +02001021 dut->wnm_bss_max_idle_time = (int) idle_time;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001022 }
1023
1024 val = get_param(cmd, "PROXY_ARP");
1025 if (val)
1026 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
1027
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001028 val = get_param(cmd, "nss_mcs_cap");
1029 if (val) {
1030 int nss, mcs;
1031 char token[20];
1032 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301033 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001034
1035 if (strlen(val) >= sizeof(token))
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001036 return INVALID_SEND_STATUS;
Jouni Malinen947fdf62017-05-14 22:29:32 +03001037 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301038 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301039 if (!result) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001040 send_resp(dut, conn, SIGMA_ERROR,
1041 "errorCode,VHT NSS not specified");
1042 return STATUS_SENT;
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301043 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001044 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301045 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001046 if (result == NULL) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001047 send_resp(dut, conn, SIGMA_ERROR,
1048 "errorCode,VHTMCS not specified");
1049 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001050 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301051 result = strtok_r(result, "-", &saveptr);
1052 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301053 if (!result) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001054 send_resp(dut, conn, SIGMA_ERROR,
1055 "errorCode,VHT MCS not specified");
1056 return STATUS_SENT;
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301057 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 mcs = atoi(result);
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08001059 if (dut->program == PROGRAM_HE) {
1060 uint16_t mcsnssmap = 0;
1061
1062 get_he_mcs_nssmap((uint8_t *) &mcsnssmap, nss, mcs);
1063 dut->he_mcsnssmap = (mcsnssmap << 16) | mcsnssmap;
1064 dut->he_ul_mcs = mcs;
1065 } else {
1066 set_vht_mcsmap_nss(dut, nss, mcs);
1067 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001068 }
1069
1070 /* TODO: MPDU_MIN_START_SPACING */
1071 /* TODO: RIFS_TEST */
1072 /* TODO: SGI20 */
1073
1074 val = get_param(cmd, "STBC_TX");
1075 if (val)
1076 dut->ap_tx_stbc = atoi(val);
1077
1078 val = get_param(cmd, "WIDTH");
1079 if (val) {
1080 if (strcasecmp(val, "20") == 0)
1081 dut->ap_chwidth = AP_20;
1082 else if (strcasecmp(val, "40") == 0)
1083 dut->ap_chwidth = AP_40;
1084 else if (strcasecmp(val, "80") == 0)
1085 dut->ap_chwidth = AP_80;
1086 else if (strcasecmp(val, "160") == 0)
1087 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08001088 else if (strcasecmp(val, "80plus80") == 0) {
1089 dut->ap_80plus80 = 1;
1090 dut->ap_chwidth = AP_80_80;
1091 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001092 dut->ap_chwidth = AP_AUTO;
1093 else {
1094 send_resp(dut, conn, SIGMA_INVALID,
1095 "errorCode,Unsupported WIDTH");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001096 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001097 }
1098 }
1099
1100 /* TODO: WIDTH_SCAN */
1101
1102 val = get_param(cmd, "TDLSProhibit");
1103 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
1104 val = get_param(cmd, "TDLSChswitchProhibit");
1105 dut->ap_tdls_prohibit_chswitch =
1106 val && strcasecmp(val, "Enabled") == 0;
1107 val = get_param(cmd, "HS2");
1108 if (val && wlan_tag == 1)
1109 dut->ap_hs2 = atoi(val);
1110 val = get_param(cmd, "P2P_CROSS_CONNECT");
1111 if (val)
1112 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
1113
1114 val = get_param(cmd, "FakePubKey");
1115 dut->ap_fake_pkhash = val && atoi(val);
1116
1117 val = get_param(cmd, "vht_tkip");
1118 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
1119 val = get_param(cmd, "vht_wep");
1120 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
1121
1122 val = get_param(cmd, "Protect_mode");
1123 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
1124
1125 val = get_param(cmd, "DYN_BW_SGNL");
1126 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001127 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001128 case DRIVER_OPENWRT:
1129 switch (get_openwrt_driver_type()) {
1130 case OPENWRT_DRIVER_ATHEROS:
1131 ath_config_dyn_bw_sig(dut, ifname, val);
1132 break;
1133 default:
1134 send_resp(dut, conn, SIGMA_ERROR,
1135 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001136 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001137 }
1138 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +05301139 case DRIVER_WCN:
1140 case DRIVER_LINUX_WCN:
1141 ath_config_dyn_bw_sig(dut, ifname, val);
1142 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001143 default:
1144 sigma_dut_print(dut, DUT_MSG_ERROR,
1145 "Unsupported DYN_BW_SGL with the current driver");
1146 break;
1147 }
1148 }
1149
1150 val = get_param(cmd, "SGI80");
1151 if (val) {
1152 if (strcasecmp(val, "enable") == 0)
1153 dut->ap_sgi80 = 1;
1154 else if (strcasecmp(val, "disable") == 0)
1155 dut->ap_sgi80 = 0;
1156 else {
1157 send_resp(dut, conn, SIGMA_INVALID,
1158 "errorCode,Unsupported SGI80");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001159 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001160 }
1161 }
1162
1163 val = get_param(cmd, "LDPC");
1164 if (val) {
1165 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001166 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001167 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001168 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001169 else {
1170 send_resp(dut, conn, SIGMA_INVALID,
1171 "errorCode,Unsupported LDPC");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001172 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001173 }
bings78387032019-12-06 17:50:05 +08001174 switch (get_driver_type(dut)) {
1175 case DRIVER_WCN:
1176 case DRIVER_LINUX_WCN:
1177 wcn_config_ap_ldpc(dut, ifname);
1178 break;
1179 default:
1180 break;
1181 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001182 }
1183
1184 val = get_param(cmd, "BW_SGNL");
1185 if (val) {
1186 /*
1187 * With dynamic bandwidth signaling enabled we should see
1188 * RTS if the threshold is met.
1189 */
1190 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001191 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001192 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001193 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001194 } else {
1195 send_resp(dut, conn, SIGMA_INVALID,
1196 "errorCode,Unsupported BW_SGNL");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001197 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001198 }
1199 }
1200
1201 val = get_param(cmd, "RTS_FORCE");
1202 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001203 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001204 case DRIVER_OPENWRT:
1205 switch (get_openwrt_driver_type()) {
1206 case OPENWRT_DRIVER_ATHEROS:
1207 ath_config_rts_force(dut, ifname, val);
1208 break;
1209 default:
1210 send_resp(dut, conn, SIGMA_ERROR,
1211 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001212 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001213 }
1214 break;
Tamizh chelvam638fb472019-08-15 14:00:31 +05301215 case DRIVER_MAC80211:
1216 mac80211_config_rts_force(dut, ifname, val);
1217 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001218 default:
1219 sigma_dut_print(dut, DUT_MSG_ERROR,
1220 "Unsupported RTS_FORCE with the current driver");
1221 break;
1222 }
1223 }
1224
1225 val = get_param(cmd, "Zero_crc");
1226 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001227 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001228 case DRIVER_ATHEROS:
1229 ath_set_zero_crc(dut, val);
1230 break;
1231 case DRIVER_OPENWRT:
1232 switch (get_openwrt_driver_type()) {
1233 case OPENWRT_DRIVER_ATHEROS:
1234 ath_set_zero_crc(dut, val);
1235 break;
1236 default:
1237 send_resp(dut, conn, SIGMA_ERROR,
1238 "errorCode,Unsupported zero_crc with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001239 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001240 }
1241 break;
1242 default:
1243 send_resp(dut, conn, SIGMA_ERROR,
1244 "errorCode,Unsupported zero_crc with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001245 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001246 }
1247 }
1248
1249 val = get_param(cmd, "TxBF");
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001250 if (val) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001251 dut->ap_txBF = strcasecmp(val, "enable") == 0;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001252 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08001253 dut->he_set_sta_1x1 = VALUE_ENABLED;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001254 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001255
1256 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301257 if (val) {
1258 if (strcasecmp(val, "enable") == 0) {
1259 dut->ap_txBF = 1;
1260 dut->ap_mu_txBF = 1;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001261 dut->he_sounding = VALUE_DISABLED;
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301262 } else if (strcasecmp(val, "disable") == 0) {
1263 dut->ap_txBF = 0;
1264 dut->ap_mu_txBF = 0;
1265 } else {
1266 sigma_dut_print(dut, DUT_MSG_ERROR,
1267 "Unsupported MU_TxBF");
1268 }
1269 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001270
1271 /* UNSUPPORTED: tx_lgi_rate */
1272
1273 val = get_param(cmd, "wpsnfc");
1274 if (val)
1275 dut->ap_wpsnfc = atoi(val);
1276
1277 val = get_param(cmd, "GROUP_ID");
1278 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001279 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001280 case DRIVER_OPENWRT:
1281 switch (get_openwrt_driver_type()) {
1282 case OPENWRT_DRIVER_ATHEROS:
1283 ath_ap_set_group_id(dut, ifname, val);
1284 break;
1285 default:
1286 send_resp(dut, conn, SIGMA_ERROR,
1287 "errorCode,Unsupported group_id with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001288 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001289 }
1290 break;
1291 default:
1292 send_resp(dut, conn, SIGMA_ERROR,
1293 "errorCode,Unsupported group_id with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001294 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001295 }
1296 }
1297
1298 val = get_param(cmd, "CTS_WIDTH");
1299 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001300 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001301 case DRIVER_OPENWRT:
1302 switch (get_openwrt_driver_type()) {
1303 case OPENWRT_DRIVER_ATHEROS:
1304 ath_set_cts_width(dut, ifname, val);
1305 break;
1306 default:
1307 send_resp(dut, conn, SIGMA_ERROR,
1308 "errorCode,Unsupported cts_width with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001309 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001310 }
1311 break;
1312 default:
1313 send_resp(dut, conn, SIGMA_ERROR,
1314 "errorCode,Unsupported cts_width with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001315 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001316 }
1317 }
1318
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001319 val = get_param(cmd, "MU_NDPA_FrameFormat");
1320 if (val)
1321 dut->ap_ndpa_frame = atoi(val);
1322
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001323 val = get_param(cmd, "interworking");
1324 if (val && strcmp(val, "1") == 0)
1325 dut->ap_interworking = 1;
1326
1327 val = get_param(cmd, "GAS_CB_DELAY");
1328 if (val)
1329 dut->ap_gas_cb_delay = atoi(val);
1330
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001331 val = get_param(cmd, "LCI");
1332 if (val) {
1333 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001334 return INVALID_SEND_STATUS;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001335 dut->ap_lci = 1;
1336 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1337 ath_set_lci_config(dut, val, cmd);
1338 }
1339
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001340 val = get_param(cmd, "InfoZ");
1341 if (val) {
1342 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001343 return INVALID_SEND_STATUS;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001344 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1345 }
1346
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001347 val = get_param(cmd, "LocCivicAddr");
1348 if (val) {
1349 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001350 return INVALID_SEND_STATUS;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001351 dut->ap_lcr = 1;
1352 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1353 if (dut->ap_lci == 0)
1354 ath_set_lci_config(dut, val, cmd);
1355 }
1356
1357 val = get_param(cmd, "NeighAPBSSID");
1358 if (val) {
1359 if (dut->ap_neighap < 3) {
1360 if (parse_mac_address(
1361 dut, val,
1362 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1363 send_resp(dut, conn, SIGMA_INVALID,
1364 "Failed to parse MAC address");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001365 return STATUS_SENT;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001366 }
1367 dut->ap_neighap++;
1368 if (dut->ap_lci == 1)
1369 dut->ap_scan = 1;
1370 }
1371 }
1372
1373 val = get_param(cmd, "OpChannel");
1374 if (val) {
1375 if (dut->ap_opchannel < 3) {
1376 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1377 dut->ap_opchannel++;
1378 }
1379 }
1380
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001381 val = get_param(cmd, "URI-FQDNdescriptor");
1382 if (val) {
1383 if (strcasecmp(val, "HELD") == 0) {
1384 dut->ap_fqdn_held = 1;
1385 } else if (strcasecmp(val, "SUPL") == 0) {
1386 dut->ap_fqdn_supl = 1;
1387 } else {
1388 send_resp(dut, conn, SIGMA_INVALID,
1389 "errorCode,Unsupported URI-FQDNdescriptor");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001390 return STATUS_SENT;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001391 }
1392 }
1393
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001394 val = get_param(cmd, "Reg_Domain");
1395 if (val) {
1396 if (strcasecmp(val, "Local") == 0) {
1397 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1398 } else if (strcasecmp(val, "Global") == 0) {
1399 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1400 } else {
1401 send_resp(dut, conn, SIGMA_ERROR,
1402 "errorCode,Wrong value for Reg_Domain");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001403 return STATUS_SENT;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001404 }
1405 }
1406
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001407 val = get_param(cmd, "NAME");
1408 if (val) {
1409 if (strcasecmp(val, "ap1mbo") == 0)
1410 dut->ap_name = 1;
1411 else if (strcasecmp(val, "ap2mbo") == 0)
1412 dut->ap_name = 2;
1413 else
1414 dut->ap_name = 0;
1415 }
1416
1417 val = get_param(cmd, "FT_OA");
1418 if (val) {
1419 if (strcasecmp(val, "Enable") == 0) {
1420 dut->ap_ft_oa = 1;
1421 } else if (strcasecmp(val, "Disable") == 0) {
1422 dut->ap_ft_oa = 0;
1423 } else {
1424 send_resp(dut, conn, SIGMA_ERROR,
1425 "errorCode,Wrong value for FT_OA");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001426 return STATUS_SENT;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001427 }
1428 }
1429
Jouni Malinen9f943312019-08-19 23:49:16 +03001430 val = get_param(cmd, "FT_DS");
1431 if (val) {
1432 if (strcasecmp(val, "Enable") == 0) {
1433 dut->ap_ft_ds = VALUE_ENABLED;
1434 } else if (strcasecmp(val, "Disable") == 0) {
1435 dut->ap_ft_ds = VALUE_DISABLED;
1436 } else {
1437 send_resp(dut, conn, SIGMA_ERROR,
1438 "errorCode,Unsupported value for FT_DS");
1439 return STATUS_SENT_ERROR;
1440 }
1441 }
1442
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001443 val = get_param(cmd, "Cellular_Cap_Pref");
1444 if (val)
1445 dut->ap_cell_cap_pref = atoi(val);
1446
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001447 val = get_param(cmd, "DOMAIN");
1448 if (val) {
1449 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1450 send_resp(dut, conn, SIGMA_ERROR,
1451 "errorCode,Too long DOMAIN");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001452 return STATUS_SENT;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001453 }
1454 snprintf(dut->ap_mobility_domain,
1455 sizeof(dut->ap_mobility_domain), "%s", val);
1456 }
1457
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001458 val = get_param(cmd, "ft_bss_list");
1459 if (val) {
1460 char *mac_str;
1461 int i;
1462 char *saveptr;
1463 char *mac_list_str;
1464
1465 mac_list_str = strdup(val);
1466 if (!mac_list_str)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001467 return INVALID_SEND_STATUS;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001468 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1469 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1470 if (parse_mac_address(dut, mac_str,
1471 dut->ft_bss_mac_list[i]) < 0) {
1472 sigma_dut_print(dut, DUT_MSG_ERROR,
1473 "MAC Address not in proper format");
1474 break;
1475 }
1476 dut->ft_bss_mac_cnt++;
1477 mac_str = strtok_r(NULL, " ", &saveptr);
1478 }
1479 sigma_dut_print(dut, DUT_MSG_DEBUG,
1480 "Storing the following FT BSS MAC List");
1481 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1482 sigma_dut_print(dut, DUT_MSG_DEBUG,
1483 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1484 i,
1485 dut->ft_bss_mac_list[i][0],
1486 dut->ft_bss_mac_list[i][1],
1487 dut->ft_bss_mac_list[i][2],
1488 dut->ft_bss_mac_list[i][3],
1489 dut->ft_bss_mac_list[i][4],
1490 dut->ft_bss_mac_list[i][5]);
1491 }
1492 free(mac_list_str);
1493 }
1494
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001495 val = get_param(cmd, "OCESupport");
1496 if (val) {
1497 if (strcasecmp(val, "enable") == 0) {
1498 dut->ap_oce = VALUE_ENABLED;
1499 } else if (strcasecmp(val, "disable") == 0) {
1500 dut->ap_oce = VALUE_DISABLED;
1501 dut->ap_filsdscv = VALUE_DISABLED;
1502 } else {
1503 send_resp(dut, conn, SIGMA_INVALID,
1504 "errorCode,Unsupported OCE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001505 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001506 }
1507 }
1508
1509 val = get_param(cmd, "FILSDscvInterval");
1510 if (val)
1511 dut->ap_fils_dscv_int = atoi(val);
1512
1513 val = get_param(cmd, "BroadcastSSID");
1514 if (val) {
1515 if (strcasecmp(val, "enable") == 0) {
1516 dut->ap_broadcast_ssid = VALUE_ENABLED;
1517 } else if (strcasecmp(val, "disable") == 0) {
1518 dut->ap_broadcast_ssid = VALUE_DISABLED;
1519 } else {
1520 send_resp(dut, conn, SIGMA_INVALID,
1521 "errorCode,Unsupported hidden SSID");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001522 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001523 }
1524 }
1525
1526 val = get_param(cmd, "FILSDscv");
1527 if (val) {
1528 if (strcasecmp(val, "enable") == 0) {
1529 dut->ap_filsdscv = VALUE_ENABLED;
1530 } else if (strcasecmp(val, "disable") == 0) {
1531 dut->ap_filsdscv = VALUE_DISABLED;
1532 } else {
1533 send_resp(dut, conn, SIGMA_INVALID,
1534 "errorCode,Unsupported FILSDscv");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001535 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001536 }
1537 }
1538
1539 val = get_param(cmd, "FILSHLP");
1540 if (val) {
1541 if (strcasecmp(val, "enable") == 0) {
1542 dut->ap_filshlp = VALUE_ENABLED;
1543 } else if (strcasecmp(val, "disable") == 0) {
1544 dut->ap_filshlp = VALUE_DISABLED;
1545 } else {
1546 send_resp(dut, conn, SIGMA_INVALID,
1547 "errorCode,Unsupported FILSHLP");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001548 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001549 }
1550 }
1551
1552 val = get_param(cmd, "NAIRealm");
1553 if (val) {
1554 dut->ap_nairealm_int = 1;
1555 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001556 return INVALID_SEND_STATUS;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001557 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1558 }
1559
1560 val = get_param(cmd, "DeauthDisassocTx");
1561 if (val) {
1562 if (strcasecmp(val, "disable") == 0) {
1563 deauth_disassoc(dut, ifname, val);
1564 } else {
1565 send_resp(dut, conn, SIGMA_INVALID,
1566 "errorCode,Unsupported DeauthDisassocTx");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001567 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001568 }
1569 }
1570
1571 val = get_param(cmd, "RNR");
1572 if (val) {
1573 if (strcasecmp(val, "enable") == 0) {
1574 dut->ap_rnr = VALUE_ENABLED;
1575 } else if (strcasecmp(val, "disable") == 0) {
1576 dut->ap_rnr = VALUE_DISABLED;
1577 } else {
1578 send_resp(dut, conn, SIGMA_INVALID,
1579 "errorCode,Unsupported RNR");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001580 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001581 }
1582 }
1583
1584 val = get_param(cmd, "BLEChannelUtil");
1585 if (val)
1586 dut->ap_blechanutil = atoi(val);
1587
1588 val = get_param(cmd, "BLEAvailAdminCap");
1589 if (val)
1590 dut->ap_ble_admit_cap = atoi(val);
1591
1592 val = get_param(cmd, "DataPPDUDuration");
1593 if (val)
1594 dut->ap_datappdudura = atoi(val);
1595
1596 val = get_param(cmd, "AirTimeFract");
1597 if (val)
1598 dut->ap_airtimefract = atoi(val);
1599
1600 val = get_param(cmd, "dhcpServIPADDR");
1601 if (val) {
1602 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001603 return INVALID_SEND_STATUS;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001604 snprintf(dut->ap_dhcpserv_ipaddr,
1605 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1606 dut->ap_dhcp_stop = 1;
1607 }
1608
1609 val = get_param(cmd, "ESP_IE");
1610 if (val) {
1611 if (strcasecmp(val, "enable") == 0) {
1612 dut->ap_esp = VALUE_ENABLED;
1613 } else if (strcasecmp(val, "disable") == 0) {
1614 dut->ap_esp = VALUE_DISABLED;
1615 } else {
1616 send_resp(dut, conn, SIGMA_INVALID,
1617 "errorCode,Unsupported ESP_IE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001618 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001619 }
1620 }
1621
1622 val = get_param(cmd, "BAWinSize");
1623 if (val)
1624 dut->ap_bawinsize = atoi(val);
1625
1626 val = get_param(cmd, "BLEStaCount");
1627 if (val)
1628 dut->ap_blestacnt = atoi(val);
1629
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001630 val = get_param(cmd, "PPDUTxType");
1631 if (val) {
1632 if (strcasecmp(val, "MU") == 0) {
1633 dut->ap_he_ppdu = PPDU_MU;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001634 } else if (strcasecmp(val, "HE-SU") == 0) {
1635 /* Do nothing */
1636 } else if (strcasecmp(val, "SU") == 0) {
1637 /* Do nothing */
1638 } else if (strcasecmp(val, "legacy") == 0) {
1639 /* Do nothing */
1640 } else if (strcasecmp(val, "ER") == 0) {
1641 /* Do nothing */
1642 } else if (strcasecmp(val, "TB") == 0) {
1643 /* Do nothing */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001644 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001645 send_resp(dut, conn, SIGMA_ERROR,
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001646 "errorCode,Unsupported PPDUTxType");
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001647 return STATUS_SENT_ERROR;
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001648 }
1649 }
1650
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02001651 val = get_param(cmd, "WscIEFragment");
1652 if (val && strcasecmp(val, "enable") == 0) {
1653 sigma_dut_print(dut, DUT_MSG_DEBUG,
1654 "Enable WSC IE fragmentation");
1655 dut->wsc_fragment = 1;
1656 }
1657
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02001658 val = get_param(cmd, "WpsVersion");
1659 if (val)
1660 dut->wps_forced_version = get_wps_forced_version(dut, val);
1661
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02001662 val = get_param(cmd, "WscEAPFragment");
1663 if (val && strcasecmp(val, "enable") == 0)
1664 dut->eap_fragment = 1;
1665
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001666 val = get_param(cmd, "MSDUSize");
1667 if (val) {
1668 int mtu;
1669
1670 dut->amsdu_size = atoi(val);
1671 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
1672 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
1673 sigma_dut_print(dut, DUT_MSG_ERROR,
1674 "MSDUSize %d is above max %d or below min %d",
1675 dut->amsdu_size,
1676 IEEE80211_MAX_DATA_LEN_DMG,
1677 IEEE80211_SNAP_LEN_DMG);
1678 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001679 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001680 }
1681
1682 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
1683 sigma_dut_print(dut, DUT_MSG_DEBUG,
1684 "Setting amsdu_size to %d", mtu);
1685 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001686 get_station_ifname(dut), mtu);
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001687
1688 if (system(buf) != 0) {
1689 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
1690 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001691 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001692 }
1693 }
1694
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001695 val = get_param(cmd, "BAckRcvBuf");
1696 if (val) {
1697 dut->back_rcv_buf = atoi(val);
1698 if (dut->back_rcv_buf == 0) {
1699 sigma_dut_print(dut, DUT_MSG_ERROR,
1700 "Failed to convert %s or value is 0",
1701 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001702 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001703 }
1704
1705 sigma_dut_print(dut, DUT_MSG_DEBUG,
1706 "Setting BAckRcvBuf to %s", val);
1707 }
1708
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001709 val = get_param(cmd, "ExtSchIE");
1710 if (val && !strcasecmp(val, "Enable")) {
1711 int num_allocs = MAX_ESE_ALLOCS;
1712
1713 if (sta_extract_60g_ese(dut, cmd, dut->ap_ese_allocs,
1714 &num_allocs)) {
1715 send_resp(dut, conn, SIGMA_INVALID,
1716 "errorCode,Invalid ExtSchIE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001717 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001718 }
1719 dut->ap_num_ese_allocs = num_allocs;
1720 }
1721
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02001722 if (is_60g_sigma_dut(dut)) {
1723 unsigned int abft_len = 1; /* default is one slot */
1724
1725 val = get_param(cmd, "ABFTLRang");
1726 if (val) {
1727 sigma_dut_print(dut, DUT_MSG_DEBUG,
1728 "ABFTLRang parameter %s", val);
1729 if (strcasecmp(val, "Gt1") == 0)
1730 abft_len = 2; /* 2 slots in this case */
1731 }
1732
1733 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
1734 send_resp(dut, conn, SIGMA_ERROR,
1735 "ErrorCode,Can't set ABFT length");
1736 return STATUS_SENT;
1737 }
1738 }
1739
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001740 val = get_param(cmd, "OFDMA");
1741 if (val) {
1742 if (strcasecmp(val, "UL") == 0) {
1743 dut->ap_he_ulofdma = VALUE_ENABLED;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001744 } else if (strcasecmp(val, "DL") == 0) {
1745 dut->ap_he_dlofdma = VALUE_ENABLED;
1746 } else if (strcasecmp(val, "DL-20and80") == 0) {
1747 dut->ap_he_dlofdma = VALUE_ENABLED;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001748 } else {
1749 send_resp(dut, conn, SIGMA_ERROR,
1750 "errorCode,Unsupported OFDMA value");
1751 return STATUS_SENT_ERROR;
1752 }
1753 }
1754
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07001755 val = get_param(cmd, "NumSoundDim");
1756 if (val)
1757 dut->ap_numsounddim = atoi(val);
1758
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07001759 val = get_param(cmd, "BCC");
1760 if (val) {
1761 if (strcasecmp(val, "enable") == 0) {
1762 dut->ap_bcc = VALUE_ENABLED;
1763 dut->ap_ldpc = VALUE_DISABLED;
1764 } else if (strcasecmp(val, "disable") == 0) {
1765 dut->ap_ldpc = VALUE_ENABLED;
1766 dut->ap_bcc = VALUE_DISABLED;
1767 } else {
1768 send_resp(dut, conn, SIGMA_ERROR,
1769 "errorCode,Unsupported BCC value");
1770 return STATUS_SENT_ERROR;
1771 }
bings78387032019-12-06 17:50:05 +08001772 switch (get_driver_type(dut)) {
1773 case DRIVER_WCN:
1774 case DRIVER_LINUX_WCN:
1775 wcn_config_ap_ldpc(dut, ifname);
1776 break;
1777 default:
1778 break;
1779 }
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07001780 }
1781
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07001782 val = get_param(cmd, "FrgmntSupport");
1783 if (val) {
1784 if (strcasecmp(val, "enable") == 0) {
1785 dut->ap_he_frag = VALUE_ENABLED;
1786 } else if (strcasecmp(val, "disable") == 0) {
1787 dut->ap_he_frag = VALUE_DISABLED;
1788 } else {
1789 send_resp(dut, conn, SIGMA_ERROR,
1790 "errorCode,Unsupported FrgmntSupport value");
1791 return STATUS_SENT_ERROR;
1792 }
1793 }
1794
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07001795 val = get_param(cmd, "ADDBAReq_BufSize");
1796 if (val) {
1797 if (strcasecmp(val, "le64") == 0) {
1798 dut->ap_ba_bufsize = BA_BUFSIZE_64;
1799 } else if (strcasecmp(val, "gt64") == 0) {
1800 dut->ap_ba_bufsize = BA_BUFSIZE_256;
1801 } else {
1802 send_resp(dut, conn, SIGMA_ERROR,
1803 "errorCode,Unsupported ADDBAReq Buffer Size");
1804 return STATUS_SENT_ERROR;
1805 }
1806 }
1807
1808 val = get_param(cmd, "ADDBAResp_BufSize");
1809 if (val) {
1810 if (strcasecmp(val, "gt64") == 0) {
1811 dut->ap_ba_bufsize = BA_BUFSIZE_256;
1812 } else {
1813 send_resp(dut, conn, SIGMA_ERROR,
1814 "errorCode,Unsupported ADDBAResp Buffer Size");
1815 return STATUS_SENT_ERROR;
1816 }
1817 }
1818
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07001819 val = get_param(cmd, "MU_EDCA");
1820 if (val) {
1821 if (strcasecmp(val, "override") == 0) {
1822 dut->ap_mu_edca = VALUE_ENABLED;
1823 } else if (strcasecmp(val, "disable") == 0) {
1824 dut->ap_mu_edca = VALUE_DISABLED;
1825 } else {
1826 send_resp(dut, conn, SIGMA_ERROR,
1827 "errorCode,Unsupported mu_edca param value");
1828 return STATUS_SENT_ERROR;
1829 }
1830 }
1831
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07001832 val = get_param(cmd, "MIMO");
1833 if (val) {
1834 if (strcasecmp(val, "DL") == 0) {
1835 dut->ap_he_mimo = MIMO_DL;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001836 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07001837 } else if (strcasecmp(val, "UL") == 0) {
1838 dut->ap_he_mimo = MIMO_UL;
1839 } else {
1840 send_resp(dut, conn, SIGMA_ERROR,
1841 "errorCode,Unsupported mimo param value");
1842 return STATUS_SENT_ERROR;
1843 }
1844 }
1845
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07001846 val = get_param(cmd, "HE_TXOPDurRTSThr");
1847 if (val) {
1848 if (strcasecmp(val, "enable") == 0) {
1849 dut->ap_he_rtsthrshld = VALUE_ENABLED;
1850 } else if (strcasecmp(val, "disable") == 0) {
1851 dut->ap_he_rtsthrshld = VALUE_DISABLED;
1852 } else {
1853 send_resp(dut, conn, SIGMA_ERROR,
1854 "errorCode,Unsupported HE_TXOPDurRTSThr value");
1855 return STATUS_SENT_ERROR;
1856 }
1857 }
1858
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07001859 val = get_param(cmd, "MBSSID");
1860 if (val) {
1861 if (strcasecmp(val, "enable") == 0) {
1862 dut->ap_mbssid = VALUE_ENABLED;
1863 } else if (strcasecmp(val, "disable") == 0) {
1864 dut->ap_mbssid = VALUE_DISABLED;
1865 } else {
1866 send_resp(dut, conn, SIGMA_ERROR,
1867 "errorCode,Unsupported MBSSID Value");
1868 return STATUS_SENT_ERROR;
1869 }
1870 }
1871
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07001872 val = get_param(cmd, "TWT_RespSupport");
1873 if (val) {
1874 if (strcasecmp(val, "enable") == 0) {
1875 dut->ap_twtresp = VALUE_ENABLED;
1876 } else if (strcasecmp(val, "disable") == 0) {
1877 dut->ap_twtresp = VALUE_DISABLED;
1878 } else {
1879 send_resp(dut, conn, SIGMA_ERROR,
1880 "errorCode,Unsupported TWT_RespSupport value");
1881 return STATUS_SENT_ERROR;
1882 }
1883 }
1884
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08001885 val = get_param(cmd, "MinMPDUStartSpacing");
1886 if (val)
1887 dut->he_mmss = atoi(val);
1888
Priyadharshini Gowthaman88d55c82019-12-12 14:31:46 -08001889 val = get_param(cmd, "SRCtrl_SRValue15Allowed");
1890 if (val)
1891 dut->he_srctrl_allow = atoi(val);
1892
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001893 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001894}
1895
1896
1897static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1898{
1899 char buf[256];
1900 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1901
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301902 if (tid < 0 ||
1903 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1904 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1905 return;
1906 }
1907
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001908 snprintf(buf, sizeof(buf),
1909 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1910 ifname, VI_QOS_TMP_FILE);
1911 if (system(buf) != 0)
1912 return;
1913
1914 snprintf(buf, sizeof(buf),
1915 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1916 ifname, VI_QOS_TMP_FILE);
1917 if (system(buf) != 0)
1918 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1919
1920 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1921 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1922 if (system(buf) != 0) {
1923 sigma_dut_print(dut, DUT_MSG_ERROR,
1924 "Output redirection to VI_QOS_TMP_FILE failed");
1925 }
1926
1927 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1928 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1929 if (system(buf) != 0) {
1930 sigma_dut_print(dut, DUT_MSG_ERROR,
1931 "Append TID to VI_QOS_FILE failed ");
1932 }
1933
1934 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1935 if (system(buf) != 0)
1936 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1937}
1938
1939
1940static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1941 struct sigma_cmd *cmd)
1942{
1943 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001944 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945 char buf[256];
1946 int tid = 0;
1947
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001948 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001949 val = get_param(cmd, "TID");
1950 if (val) {
1951 tid = atoi(val);
1952 if (tid)
1953 ath_inject_frame(dut, ifname, tid);
1954 }
1955
1956 /* NOTE: This is the command sequence on Peregrine for ADDBA */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07001957 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001958
1959 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1960 ifname, tid);
1961 if (system(buf) != 0) {
1962 sigma_dut_print(dut, DUT_MSG_ERROR,
1963 "wifitool senddelba failed");
1964 }
1965
1966 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1967 ifname, tid);
1968 if (system(buf) != 0) {
1969 sigma_dut_print(dut, DUT_MSG_ERROR,
1970 "wifitool sendaddba failed");
1971 }
1972
1973 return 1;
1974}
1975
1976
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301977static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1978 const char *sta_mac,
1979 const char *dir_path)
1980{
1981 DIR *dir;
1982 struct dirent *entry;
1983 char buf[128], path[128];
Jouni Malinen3aa72862019-05-29 23:14:51 +03001984 int ret = 0, res;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301985
1986 dir = opendir(dir_path);
1987 if (!dir)
1988 return 0;
1989
1990 while ((entry = readdir(dir))) {
1991 ret = 1;
1992
1993 if (strcmp(entry->d_name, ".") == 0 ||
1994 strcmp(entry->d_name, "..") == 0)
1995 continue;
1996
Jouni Malinen3aa72862019-05-29 23:14:51 +03001997 res = snprintf(path, sizeof(path) - 1, "%s/%s",
1998 dir_path, entry->d_name);
1999 if (res < 0 || res >= sizeof(path))
2000 continue;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302001
2002 if (strcmp(entry->d_name, sta_mac) == 0) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002003 res = snprintf(buf, sizeof(buf),
2004 "echo 1 > %s/aggr_mode", path);
2005 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302006 sigma_dut_print(dut, DUT_MSG_ERROR,
2007 "Failed to set aggr mode for ath10k");
2008 }
2009
Jouni Malinen3aa72862019-05-29 23:14:51 +03002010 res = snprintf(buf, sizeof(buf),
2011 "echo %d 32 > %s/addba", tid, path);
2012 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302013 sigma_dut_print(dut, DUT_MSG_ERROR,
2014 "Failed to set addbareq for ath10k");
2015 }
2016
2017 break;
2018 }
2019
2020 /* Recursively search subdirectories */
2021 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
2022 }
2023
2024 closedir(dir);
2025
2026 return ret;
2027}
2028
2029
2030static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
2031 struct sigma_cmd *cmd)
2032{
2033 const char *val;
2034 int tid = 0;
2035
2036 val = get_param(cmd, "TID");
2037 if (val)
2038 tid = atoi(val);
2039
2040 val = get_param(cmd, "sta_mac_address");
2041 if (!val) {
2042 sigma_dut_print(dut, DUT_MSG_ERROR,
2043 "Failed to parse station MAC address");
2044 return 0;
2045 }
2046
2047 return ath10k_debug_enable_addba_req(dut, tid, val,
2048 "/sys/kernel/debug/ieee80211");
2049}
2050
2051
Jouni Malinenf7222712019-06-13 01:50:21 +03002052static enum sigma_cmd_result cmd_ap_send_addba_req(struct sigma_dut *dut,
2053 struct sigma_conn *conn,
2054 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002055{
2056 /* const char *name = get_param(cmd, "NAME"); */
2057 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302058 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002059
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002060 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002061 case DRIVER_ATHEROS:
2062 return ath_ap_send_addba_req(dut, conn, cmd);
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02002063#ifdef __linux__
2064 case DRIVER_WIL6210:
2065 return send_addba_60g(dut, conn, cmd, "sta_mac_address");
2066#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002067 case DRIVER_OPENWRT:
2068 switch (get_openwrt_driver_type()) {
2069 case OPENWRT_DRIVER_ATHEROS:
2070 return ath_ap_send_addba_req(dut, conn, cmd);
2071 default:
2072 send_resp(dut, conn, SIGMA_ERROR,
2073 "errorCode,ap_send_addba_req not supported with this driver");
2074 return 0;
2075 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05302076 case DRIVER_WCN:
2077 case DRIVER_LINUX_WCN:
2078 /* AP automatically sends ADDBA request after association. */
2079 sigma_dut_print(dut, DUT_MSG_INFO,
2080 "ap_send_addba_req command ignored");
2081 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302082 case DRIVER_MAC80211:
2083 if (stat("/sys/module/ath10k_core", &s) == 0)
2084 return ath10k_ap_send_addba_req(dut, cmd);
2085 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002086 default:
2087 send_resp(dut, conn, SIGMA_ERROR,
2088 "errorCode,ap_send_addba_req not supported with this driver");
2089 return 0;
2090 }
2091}
2092
2093
Jouni Malinenf7222712019-06-13 01:50:21 +03002094static enum sigma_cmd_result cmd_ap_set_security(struct sigma_dut *dut,
2095 struct sigma_conn *conn,
2096 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002097{
2098 /* const char *name = get_param(cmd, "NAME"); */
2099 const char *val;
2100 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302101 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002102
2103 val = get_param(cmd, "WLAN_TAG");
2104 if (val)
2105 wlan_tag = atoi(val);
2106
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302107 security = get_param(cmd, "Security");
2108
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002109 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302111 if (!val)
2112 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002113 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002114 if (strcasecmp(val, "NONE") == 0) {
2115 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
2116 } else if (strcasecmp(val, "OSEN") == 0 &&
2117 wlan_tag == 2) {
2118 /*
2119 * OSEN only supported on WLAN_TAG = 2 for now
2120 */
2121 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302122 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
2123 (security &&
2124 strcasecmp(security, "PSK") == 0 &&
2125 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002126 dut->ap_tag_key_mgmt[wlan_tag - 2] =
2127 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02002128 } else if (strcasecmp(val, "OWE") == 0 &&
2129 wlan_tag == 2) {
2130 dut->ap_tag_key_mgmt[wlan_tag - 2] =
2131 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002132 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002133 send_resp(dut, conn, SIGMA_INVALID,
2134 "errorCode,Unsupported KEYMGNT");
2135 return 0;
2136 }
2137 return 1;
2138 }
2139 }
2140
2141 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302142 if (!val)
2143 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002144 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302145 if (strcasecmp(val, "WPA2-PSK") == 0 ||
2146 (security && strcasecmp(security, "PSK") == 0 &&
2147 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002148 dut->ap_key_mgmt = AP_WPA2_PSK;
2149 dut->ap_cipher = AP_CCMP;
2150 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
2151 strcasecmp(val, "WPA2-Ent") == 0) {
2152 dut->ap_key_mgmt = AP_WPA2_EAP;
2153 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03002154 } else if (strcasecmp(val, "SuiteB") == 0) {
2155 dut->ap_key_mgmt = AP_SUITEB;
2156 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02002157 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002158 } else if (strcasecmp(val, "WPA-PSK") == 0) {
2159 dut->ap_key_mgmt = AP_WPA_PSK;
2160 dut->ap_cipher = AP_TKIP;
2161 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
2162 strcasecmp(val, "WPA-Ent") == 0) {
2163 dut->ap_key_mgmt = AP_WPA_EAP;
2164 dut->ap_cipher = AP_TKIP;
2165 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
2166 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
2167 dut->ap_cipher = AP_CCMP_TKIP;
2168 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
2169 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
2170 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02002171 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
2172 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03002173 dut->ap_key_mgmt = AP_WPA2_SAE;
2174 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002175 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03002176 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
2177 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
2178 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002179 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03002180 } else if (strcasecmp(val, "OWE") == 0) {
2181 dut->ap_key_mgmt = AP_WPA2_OWE;
2182 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002183 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03002184 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
2185 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
2186 dut->ap_cipher = AP_CCMP;
2187 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03002188 } else if (strcasecmp(val, "OSEN") == 0) {
2189 dut->ap_key_mgmt = AP_OSEN;
2190 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03002191 } else if (strcasecmp(val, "FT-EAP") == 0) {
2192 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
2193 dut->ap_cipher = AP_CCMP;
2194 dut->ap_pmf = AP_PMF_OPTIONAL;
2195 } else if (strcasecmp(val, "FT-PSK") == 0) {
2196 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
2197 dut->ap_cipher = AP_CCMP;
2198 dut->ap_pmf = AP_PMF_OPTIONAL;
2199 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
2200 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
2201 dut->ap_cipher = AP_CCMP;
2202 dut->ap_pmf = AP_PMF_OPTIONAL;
2203 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
2204 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
2205 dut->ap_cipher = AP_CCMP;
2206 dut->ap_pmf = AP_PMF_OPTIONAL;
2207 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
2208 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
2209 dut->ap_cipher = AP_CCMP;
2210 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002211 } else if (strcasecmp(val, "NONE") == 0) {
2212 dut->ap_key_mgmt = AP_OPEN;
2213 dut->ap_cipher = AP_PLAIN;
2214 } else {
2215 send_resp(dut, conn, SIGMA_INVALID,
2216 "errorCode,Unsupported KEYMGNT");
2217 return 0;
2218 }
2219 }
2220
Jouni Malinen30824df2017-08-22 21:21:38 +03002221 val = get_param(cmd, "ECGroupID");
2222 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03002223 free(dut->ap_sae_groups);
2224 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03002225 }
2226
Jouni Malinen2f524ce2017-08-31 01:43:29 +03002227 val = get_param(cmd, "AntiCloggingThreshold");
2228 if (val)
2229 dut->sae_anti_clogging_threshold = atoi(val);
2230
Jouni Malinenb347db02017-09-02 01:36:03 +03002231 val = get_param(cmd, "Reflection");
2232 if (val)
2233 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
2234
Jouni Malinen68143132017-09-02 02:34:08 +03002235 val = get_param(cmd, "InvalidSAEElement");
2236 if (val) {
2237 free(dut->sae_commit_override);
2238 dut->sae_commit_override = strdup(val);
2239 }
2240
Jouni Malinen09550de2019-03-26 00:24:11 +02002241 val = get_param(cmd, "SAEPasswords");
2242 if (val) {
2243 free(dut->ap_sae_passwords);
2244 dut->ap_sae_passwords = strdup(val);
2245 }
2246
Jouni Malinen3c740ab2019-10-10 15:55:11 +03002247 val = get_param(cmd, "SAE_Confirm_Immediate");
2248 if (val)
2249 dut->sae_confirm_immediate = get_enable_disable(val);
2250
Jouni Malinen11e55212019-11-22 21:46:59 +02002251 val = get_param(cmd, "sae_pwe");
2252 if (val) {
2253 if (strcasecmp(val, "h2e") == 0) {
2254 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002255 } else if (strcasecmp(val, "loop") == 0 ||
2256 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002257 dut->sae_pwe = SAE_PWE_LOOP;
2258 } else {
2259 send_resp(dut, conn, SIGMA_ERROR,
2260 "errorCode,Unsupported sae_pwe value");
2261 return STATUS_SENT_ERROR;
2262 }
2263 }
2264
Jouni Malinen7960e3a2019-12-07 17:04:35 +02002265 val = get_param(cmd, "RSNXE_Content");
2266 if (val) {
2267 if (strncasecmp(val, "EapolM3:", 8) != 0) {
2268 send_resp(dut, conn, SIGMA_ERROR,
2269 "errorCode,Unsupported RSNXE_Content value");
2270 return STATUS_SENT_ERROR;
2271 }
2272 val += 8;
2273 free(dut->rsnxe_override_eapol);
2274 dut->rsnxe_override_eapol = strdup(val);
2275 }
2276
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002277 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302278 if (!val)
2279 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002280 if (val) {
2281 if (strcasecmp(val, "WEP") == 0) {
2282 dut->ap_cipher = AP_WEP;
2283 } else if (strcasecmp(val, "TKIP") == 0) {
2284 dut->ap_cipher = AP_TKIP;
2285 } else if (strcasecmp(val, "AES") == 0 ||
2286 strcasecmp(val, "AES-CCMP") == 0) {
2287 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002288 } else if (strcasecmp(val, "AES-GCMP") == 0) {
2289 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002290 } else {
2291 send_resp(dut, conn, SIGMA_INVALID,
2292 "errorCode,Unsupported ENCRYPT");
2293 return 0;
2294 }
2295 }
2296
Jouni Malinen3d633da2017-09-14 22:19:21 +03002297 val = get_param(cmd, "PairwiseCipher");
2298 if (val) {
2299 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2300 dut->ap_cipher = AP_GCMP_256;
2301 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2302 dut->ap_cipher = AP_CCMP_256;
2303 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2304 dut->ap_cipher = AP_GCMP_128;
2305 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2306 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02002307 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
2308 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
2309 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002310 } else {
2311 send_resp(dut, conn, SIGMA_INVALID,
2312 "errorCode,Unsupported PairwiseCipher");
2313 return 0;
2314 }
2315 }
2316
Jouni Malinen2ba24492017-11-17 12:43:59 +02002317 val = get_param(cmd, "GroupCipher");
2318 if (val) {
2319 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2320 dut->ap_group_cipher = AP_GCMP_256;
2321 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2322 dut->ap_group_cipher = AP_CCMP_256;
2323 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2324 dut->ap_group_cipher = AP_GCMP_128;
2325 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2326 dut->ap_group_cipher = AP_CCMP;
2327 } else {
2328 send_resp(dut, conn, SIGMA_INVALID,
2329 "errorCode,Unsupported GroupCipher");
2330 return 0;
2331 }
2332 }
2333
Jouni Malinen3d633da2017-09-14 22:19:21 +03002334 val = get_param(cmd, "GroupMgntCipher");
2335 if (val) {
2336 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2337 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
2338 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2339 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
2340 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2341 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
2342 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2343 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
2344 } else {
2345 send_resp(dut, conn, SIGMA_INVALID,
2346 "errorCode,Unsupported GroupMgntCipher");
2347 return 0;
2348 }
2349 }
2350
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002351 val = get_param(cmd, "WEPKEY");
2352 if (val) {
2353 size_t len;
2354 if (dut->ap_cipher != AP_WEP) {
2355 send_resp(dut, conn, SIGMA_INVALID,
2356 "errorCode,Unexpected WEPKEY without WEP "
2357 "configuration");
2358 return 0;
2359 }
2360 len = strlen(val);
2361 if (len != 10 && len != 26) {
2362 send_resp(dut, conn, SIGMA_INVALID,
2363 "errorCode,Unexpected WEPKEY length");
2364 return 0;
2365 }
2366 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
2367 }
2368
2369 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302370 if (!val)
2371 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002372 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002373 if (dut->ap_key_mgmt != AP_WPA2_SAE &&
2374 (dut->ap_akm_values & (AKM_WPA_PSK | AKM_SAE)) !=
2375 AKM_SAE &&
2376 strlen(val) > 64) {
2377 sigma_dut_print(dut, DUT_MSG_ERROR,
2378 "Too long PSK/passphtase");
Jouni Malinen2126f422017-10-11 23:24:33 +03002379 return -1;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002380 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002381 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
2382 return -1;
2383 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
2384 "%s", val);
2385 }
2386
Jouni Malinen63370622017-11-18 17:47:13 +02002387 val = get_param(cmd, "PSKHEX");
2388 if (val) {
2389 if (strlen(val) != 64)
2390 return -1;
2391 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
2392 }
2393
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302394 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
2395 dut->ap_pmf = AP_PMF_OPTIONAL;
2396
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002397 val = get_param(cmd, "PMF");
2398 if (val) {
2399 if (strcasecmp(val, "Disabled") == 0) {
2400 dut->ap_pmf = AP_PMF_DISABLED;
2401 } else if (strcasecmp(val, "Optional") == 0) {
2402 dut->ap_pmf = AP_PMF_OPTIONAL;
2403 } else if (strcasecmp(val, "Required") == 0) {
2404 dut->ap_pmf = AP_PMF_REQUIRED;
2405 } else {
2406 send_resp(dut, conn, SIGMA_INVALID,
2407 "errorCode,Unsupported PMF");
2408 return 0;
2409 }
2410 }
2411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412 dut->ap_add_sha256 = 0;
2413 val = get_param(cmd, "SHA256AD");
2414 if (val == NULL)
2415 val = get_param(cmd, "SHA256");
2416 if (val) {
2417 if (strcasecmp(val, "Disabled") == 0) {
2418 } else if (strcasecmp(val, "Enabled") == 0) {
2419 dut->ap_add_sha256 = 1;
2420 } else {
2421 send_resp(dut, conn, SIGMA_INVALID,
Jouni Malinena7fa6202019-03-26 00:22:10 +02002422 "errorCode,Unsupported SHA256");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002423 return 0;
2424 }
2425 }
2426
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302427 val = get_param(cmd, "PreAuthentication");
2428 if (val) {
2429 if (strcasecmp(val, "disabled") == 0) {
2430 dut->ap_rsn_preauth = 0;
2431 } else if (strcasecmp(val, "enabled") == 0) {
2432 dut->ap_rsn_preauth = 1;
2433 } else {
2434 send_resp(dut, conn, SIGMA_INVALID,
2435 "errorCode,Unsupported PreAuthentication value");
2436 return 0;
2437 }
2438 }
2439
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002440 val = get_param(cmd, "AKMSuiteType");
2441 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002442 const char *in_pos = val;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002443
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002444 dut->ap_akm_values = 0;
2445 while (*in_pos) {
2446 int akm = atoi(in_pos);
2447
2448 if (akm < 0 || akm >= 32) {
2449 send_resp(dut, conn, SIGMA_ERROR,
2450 "errorCode,Unsupported AKMSuiteType value");
2451 return STATUS_SENT;
2452 }
2453
2454 dut->ap_akm_values |= 1 << akm;
2455
2456 in_pos = strchr(in_pos, ';');
2457 if (!in_pos)
2458 break;
2459 while (*in_pos == ';')
2460 in_pos++;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002461 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002462 dut->ap_akm = 1;
2463 if (dut->ap_akm_values & (1 << 14))
2464 dut->ap_add_sha384 = 1;
2465 if (dut->ap_akm_values & (1 << 15))
2466 dut->ap_add_sha384 = 1;
2467 }
2468
2469 if (dut->ap_key_mgmt == AP_OPEN && !dut->ap_akm_values) {
2470 dut->ap_hs2 = 0;
2471 dut->ap_pmf = AP_PMF_DISABLED;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002472 }
2473
2474 val = get_param(cmd, "PMKSACaching");
2475 if (val) {
2476 dut->ap_pmksa = 1;
2477 if (strcasecmp(val, "disabled") == 0) {
2478 dut->ap_pmksa_caching = 1;
2479 } else if (strcasecmp(val, "enabled") == 0) {
2480 dut->ap_pmksa_caching = 0;
2481 } else {
2482 send_resp(dut, conn, SIGMA_INVALID,
2483 "errorCode,Unsupported PMKSACaching value");
2484 return 0;
2485 }
2486 }
2487
Jouni Malinen05d005a2020-03-26 12:49:33 +02002488 val = get_param(cmd, "BeaconProtection");
2489 if (val)
2490 dut->ap_beacon_prot = atoi(val);
2491
Jouni Malinenc098c442020-03-26 13:01:50 +02002492 val = get_param(cmd, "Transition_Disable");
2493 if (val) {
2494 if (atoi(val)) {
2495 val = get_param(cmd, "Transition_Disable_Index");
2496 if (!val) {
2497 send_resp(dut, conn, SIGMA_INVALID,
2498 "errorCode,Transition_Disable without Transition_Disable_Index");
2499 return STATUS_SENT;
2500 }
2501 dut->ap_transition_disable = 1 << atoi(val);
2502 } else {
2503 dut->ap_transition_disable = 0;
2504 }
2505 }
2506
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002507 return 1;
2508}
2509
2510
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302511int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2512 struct sigma_cmd *cmd)
2513{
2514 int status;
2515
2516 status = cmd_ap_set_wireless(dut, conn, cmd);
2517 if (status != 1)
2518 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302519 status = cmd_ap_set_security(dut, conn, cmd);
2520 if (status != 1)
2521 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302522 return cmd_ap_config_commit(dut, conn, cmd);
2523}
2524
2525
Jouni Malinenf7222712019-06-13 01:50:21 +03002526static enum sigma_cmd_result cmd_ap_set_radius(struct sigma_dut *dut,
2527 struct sigma_conn *conn,
2528 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002529{
2530 /* const char *name = get_param(cmd, "NAME"); */
2531 const char *val;
2532 unsigned int wlan_tag = 1, radius_port = 0;
2533 char *radius_ipaddr = NULL, *radius_password = NULL;
2534
2535 val = get_param(cmd, "WLAN_TAG");
2536 if (val) {
2537 wlan_tag = atoi(val);
2538 if (wlan_tag != 1 && wlan_tag != 2) {
2539 send_resp(dut, conn, SIGMA_INVALID,
2540 "errorCode,Invalid WLAN_TAG");
2541 return 0;
2542 }
2543 }
2544
2545 val = get_param(cmd, "PORT");
2546 if (val)
2547 radius_port = atoi(val);
2548
2549 if (wlan_tag == 1) {
2550 if (radius_port)
2551 dut->ap_radius_port = radius_port;
2552 radius_ipaddr = dut->ap_radius_ipaddr;
2553 radius_password = dut->ap_radius_password;
2554 } else if (wlan_tag == 2) {
2555 if (radius_port)
2556 dut->ap2_radius_port = radius_port;
2557 radius_ipaddr = dut->ap2_radius_ipaddr;
2558 radius_password = dut->ap2_radius_password;
2559 }
2560
2561 val = get_param(cmd, "IPADDR");
2562 if (val) {
2563 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2564 return -1;
2565 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2566 "%s", val);
2567 }
2568
2569 val = get_param(cmd, "PASSWORD");
2570 if (val) {
2571 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2572 return -1;
2573 snprintf(radius_password,
2574 sizeof(dut->ap_radius_password), "%s", val);
2575 }
2576
2577 return 1;
2578}
2579
2580
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002581static void owrt_ap_set_qcawifi(struct sigma_dut *dut, const char *key,
2582 const char *val)
2583{
2584 if (!val) {
2585 run_system_wrapper(dut, "uci delete wireless.qcawifi.%s", key);
2586 return;
2587 }
2588
2589 run_system(dut, "uci set wireless.qcawifi=qcawifi");
2590 run_system_wrapper(dut, "uci set wireless.qcawifi.%s=%s", key, val);
2591}
2592
2593
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002594static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2595 const char *key, const char *val)
2596{
2597 char buf[100];
2598
2599 if (val == NULL) {
2600 snprintf(buf, sizeof(buf),
2601 "uci delete wireless.wifi%d.%s", id, key);
2602 run_system(dut, buf);
2603 return;
2604 }
2605
2606 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2607 id, key, val);
2608 run_system(dut, buf);
2609}
2610
2611
2612static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2613 const char *key, const char *val)
2614{
2615 char buf[256];
2616
2617 if (val == NULL) {
2618 snprintf(buf, sizeof(buf),
2619 "uci del_list wireless.wifi%d.%s", id, key);
2620 run_system(dut, buf);
2621 return;
2622 }
2623
2624 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2625 id, key, val);
2626 run_system(dut, buf);
2627}
2628
2629
2630static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2631 const char *val)
2632{
2633 char buf[256];
2634
2635 if (val == NULL) {
2636 snprintf(buf, sizeof(buf),
2637 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2638 run_system(dut, buf);
2639 return;
2640 }
2641
2642 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2643 id, key, val);
2644 run_system(dut, buf);
2645}
2646
2647
2648static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2649 const char *key, const char *val)
2650{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002651 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002652
2653 if (val == NULL) {
2654 snprintf(buf, sizeof(buf),
2655 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2656 run_system(dut, buf);
2657 return;
2658 }
2659
2660 snprintf(buf, sizeof(buf),
2661 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2662 id, key, val);
2663 run_system(dut, buf);
2664}
2665
2666
2667static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2668 const char *val)
2669{
2670 char buf[256];
Jouni Malinen3aa72862019-05-29 23:14:51 +03002671 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002672
2673 if (val == NULL) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002674 res = snprintf(buf, sizeof(buf),
2675 "uci delete wireless.@wifi-iface[%d].%s",
2676 id, key);
2677 if (res >= 0 && res < sizeof(buf))
2678 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002679 return;
2680 }
2681
Jouni Malinen3aa72862019-05-29 23:14:51 +03002682 run_system(dut, "uci add wireless wifi-iface");
2683 res = snprintf(buf, sizeof(buf),
2684 "uci set wireless.@wifi-iface[%d].%s=%s",
2685 id, key, val);
2686 if (res >= 0 && res < sizeof(buf))
2687 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002688 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2689 id, "network", "lan");
2690 run_system(dut, buf);
2691 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2692 id, "mode", "ap");
2693 run_system(dut, buf);
2694 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2695 id, "encryption", "none");
2696 run_system(dut, buf);
2697}
2698
2699
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002700#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002701static int owrt_ap_config_radio(struct sigma_dut *dut)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002702{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002703 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002704 int radio_count, radio_no;
2705 char buf[64];
2706
2707 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2708 radio_count++) {
2709 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2710 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2711 if (!sigma_radio_ifname[radio_no] ||
2712 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2713 continue;
2714 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2715 owrt_ap_set_vap(dut, radio_count, "device", buf);
2716 radio_id[radio_no] = radio_count;
2717 }
2718 }
2719
2720 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2721 switch (dut->ap_mode) {
2722 case AP_11g:
2723 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2724 break;
2725 case AP_11b:
2726 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2727 break;
2728 case AP_11ng:
2729 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2730 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2731 break;
2732 case AP_11a:
2733 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2734 break;
2735 case AP_11na:
2736 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2737 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2738 break;
2739 case AP_11ac:
2740 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2741 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2742 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002743 case AP_11ax:
2744 if (dut->ap_channel >= 36) {
2745 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axa");
2746 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2747 } else {
2748 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axg");
2749 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2750 }
2751 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002752 case AP_inval:
2753 sigma_dut_print(dut, DUT_MSG_ERROR,
2754 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002755 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002756 default:
2757 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2758 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2759 break;
2760 }
2761
2762 if (dut->ap_is_dual) {
2763 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2764 switch (dut->ap_mode_1) {
2765 case AP_11g:
2766 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2767 break;
2768 case AP_11b:
2769 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2770 break;
2771 case AP_11ng:
2772 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2773 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2774 break;
2775 case AP_11a:
2776 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2777 break;
2778 case AP_11na:
2779 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2780 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2781 break;
2782 case AP_11ac:
2783 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2784 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2785 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002786 case AP_11ax:
2787 if (dut->ap_channel >= 36) {
2788 owrt_ap_set_radio(dut, radio_id[1],
2789 "hwmode", "11axa");
2790 owrt_ap_set_radio(dut, radio_id[1],
2791 "htmode", "HT80");
2792 } else {
2793 owrt_ap_set_radio(dut, radio_id[1],
2794 "hwmode", "11axg");
2795 owrt_ap_set_radio(dut, radio_id[1],
2796 "htmode", "HT20");
2797 }
2798 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002799 case AP_inval:
2800 sigma_dut_print(dut, DUT_MSG_ERROR,
2801 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002802 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002803 default:
2804 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2805 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2806 break;
2807 }
2808
2809 }
2810
2811 /* Channel */
2812 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2813 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2814
2815 switch (dut->ap_chwidth) {
2816 case AP_20:
2817 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2818 break;
2819 case AP_40:
2820 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2821 break;
2822 case AP_80:
2823 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2824 break;
2825 case AP_160:
2826 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2827 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002828 case AP_80_80:
2829 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2830 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002831 case AP_AUTO:
2832 default:
2833 break;
2834 }
2835
2836 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2837 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2838 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2839 }
2840
2841 if (dut->ap_is_dual) {
2842 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2843 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2844 }
2845
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002846 /* Country Code */
2847 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2848 const char *country;
2849
2850 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2851 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002852 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002853 if (dut->ap_is_dual)
2854 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002855 } else if (dut->ap_countrycode[0]) {
2856 owrt_ap_set_radio(dut, radio_id[0], "country",
2857 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858 }
2859
2860 if (dut->ap_disable_protection == 1) {
2861 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2862 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2863 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2864 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2865 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002866
2867 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002868 get_driver_type(dut) == DRIVER_OPENWRT)
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002869 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002870
2871 if (dut->ap_mbssid == VALUE_ENABLED)
2872 owrt_ap_set_qcawifi(dut, "mbss_ie_enable", "1");
2873
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002874 if (dut->program == PROGRAM_HE) {
2875 owrt_ap_set_radio(dut, radio_id[0], "he_bsscolor", "'1 1'");
2876 if (dut->ap_is_dual)
2877 owrt_ap_set_radio(dut, radio_id[1], "he_bsscolor",
2878 "'2 1'");
Priyadharshini Gowthaman7d07cd02019-11-22 14:26:02 -08002879 owrt_ap_set_qcawifi(dut, "ap_bss_color_collision_detection",
2880 "1");
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002881 }
2882
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002883 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002884}
2885
2886
2887static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2888{
2889 char buf[256];
2890
2891 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2892 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2893 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2894 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2895
2896 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2897 "'eng:Wi-Fi Alliance'");
2898
2899 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2900 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2901
2902 if (dut->ap_wan_metrics == 1)
2903 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2904 "'01:2500:384:0:0:10'");
2905 else if (dut->ap_wan_metrics == 1)
2906 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2907 "'01:1500:384:20:20:10'");
2908 else if (dut->ap_wan_metrics == 2)
2909 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2910 "'01:1500:384:20:20:10'");
2911 else if (dut->ap_wan_metrics == 3)
2912 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2913 "'01:2000:1000:20:20:10'");
2914 else if (dut->ap_wan_metrics == 4)
2915 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2916 "'01:8000:1000:20:20:10'");
2917 else if (dut->ap_wan_metrics == 5)
2918 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2919 "'01:9000:5000:20:20:10'");
2920
2921 if (dut->ap_conn_capab == 1) {
2922 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2923 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2924 "'6:20:1'");
2925 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2926 "'6:22:0'");
2927 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2928 "'6:80:1'");
2929 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2930 "'6:443:1'");
2931 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2932 "'6:1723:0'");
2933 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2934 "'6:5060:0'");
2935 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2936 "'17:500:1'");
2937 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2938 "'17:5060:0'");
2939 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2940 "'17:4500:1'");
2941 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2942 "'50:0:1'");
2943 } else if (dut->ap_conn_capab == 2) {
2944 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2945 "'6:80:1'");
2946 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2947 "'6:443:1'");
2948 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2949 "'17:5060:1'");
2950 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2951 "'6:5060:1'");
2952 } else if (dut->ap_conn_capab == 3) {
2953 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2954 "'6:80:1'");
2955 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2956 "'6:443:1'");
2957 }
2958
2959 if (dut->ap_oper_class == 1)
2960 snprintf(buf, sizeof(buf), "%s", "51");
2961 else if (dut->ap_oper_class == 2)
2962 snprintf(buf, sizeof(buf), "%s", "73");
2963 else if (dut->ap_oper_class == 3)
2964 snprintf(buf, sizeof(buf), "%s", "5173");
2965
2966 if (dut->ap_oper_class)
2967 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2968
2969 if (dut->ap_osu_provider_list) {
2970 char *osu_friendly_name = NULL;
2971 char *osu_icon = NULL;
2972 char *osu_ssid = NULL;
2973 char *osu_nai = NULL;
2974 char *osu_service_desc = NULL;
2975 char *hs20_icon_filename = NULL;
2976 char hs20_icon[150];
2977 int osu_method;
2978
2979 hs20_icon_filename = "icon_red_zxx.png";
2980 if (dut->ap_osu_icon_tag == 2)
2981 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2982 snprintf(hs20_icon, sizeof(hs20_icon),
2983 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2984 hs20_icon_filename);
2985 osu_icon = "icon_red_zxx.png";
2986 osu_ssid = "OSU";
2987 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2988 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2989 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2990 dut->ap_osu_method[0];
2991
2992 if (strlen(dut->ap_osu_server_uri[0]))
2993 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2994 dut->ap_osu_server_uri[0]);
2995 else
2996 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2997 "'https://osu-server.r2-testbed.wi-fi.org/'");
2998 switch (dut->ap_osu_provider_list) {
2999 case 1:
3000 case 101:
3001 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3002 "'eng:SP Red Test Only'");
3003 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3004 "'eng:Free service for test purpose'");
3005 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3006 hs20_icon);
3007
3008 hs20_icon_filename = "icon_red_eng.png";
3009 if (dut->ap_osu_icon_tag == 2)
3010 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3011
3012 snprintf(hs20_icon, sizeof(hs20_icon),
3013 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
3014 hs20_icon_filename);
3015 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3016 "icon_red_eng.png");
3017 break;
3018 case 2:
3019 case 102:
3020 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3021 "'eng:Wireless Broadband Alliance'");
3022 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3023 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003024 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003025 if (dut->ap_osu_icon_tag == 2)
3026 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3027
3028 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003029 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003030 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003031 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003032 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
3033 break;
3034 case 3:
3035 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03003036 osu_friendly_name = "'spa:SP Red Test Only'";
3037 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003038 break;
3039 case 4:
3040 case 104:
3041 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003042 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3044 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003045 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003046 if (dut->ap_osu_icon_tag == 2)
3047 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3048
3049 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003050 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003051 hs20_icon_filename);
3052 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3053 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003054 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003055
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003056 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003057 if (dut->ap_osu_icon_tag == 2)
3058 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3059
3060 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003061 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003062 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003063 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003064 break;
3065 case 5:
3066 case 105:
3067 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003068 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003069 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3070 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003071 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003072
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003073 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003074 if (dut->ap_osu_icon_tag == 2)
3075 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3076
3077 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003078 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003079 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003080 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003081 break;
3082 case 6:
3083 case 106:
3084 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3085 "'eng:SP Green Test Only'");
3086 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3087 "'kor:SP 초록 테스트 전용'");
3088
3089 hs20_icon_filename = "icon_green_zxx.png";
3090 if (dut->ap_osu_icon_tag == 2)
3091 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3092
3093 snprintf(hs20_icon, sizeof(hs20_icon),
3094 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
3095 hs20_icon_filename);
3096 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3097 hs20_icon);
3098
3099 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3100 "'icon_green_zxx.png'");
3101 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
3102 dut->ap_osu_method[0];
3103
3104 snprintf(buf, sizeof(buf), "%d", osu_method);
3105 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
3106
3107 if (strlen(dut->ap_osu_server_uri[1]))
3108 owrt_ap_set_list_vap(dut, vap_id,
3109 "osu_server_uri",
3110 dut->ap_osu_server_uri[1]);
3111 else
3112 owrt_ap_set_list_vap(dut, vap_id,
3113 "osu_server_uri",
3114 "'https://osu-server.r2-testbed.wi-fi.org/'");
3115
3116 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3117 "'eng:SP Orange Test Only'");
3118
3119 hs20_icon_filename = "icon_orange_zxx.png";
3120 if (dut->ap_osu_icon_tag == 2)
3121 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3122
3123 snprintf(hs20_icon, sizeof(hs20_icon),
3124 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3125 hs20_icon_filename);
3126
3127 osu_icon = "icon_orange_zxx.png";
3128 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
3129 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
3130 dut->ap_osu_method[1];
3131 osu_service_desc = NULL;
3132 break;
3133 case 7:
3134 case 107:
3135 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003136 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003137 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3138 "'eng:Free service for test purpose'");
3139
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003140 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003141 if (dut->ap_osu_icon_tag == 2)
3142 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3143
3144 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003145 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003146 hs20_icon_filename);
3147 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3148 hs20_icon);
3149
3150 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003151 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003152 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003153
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003154 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003155 if (dut->ap_osu_icon_tag == 2)
3156 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3157
3158 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003159 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003160 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003161 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003162 break;
3163 case 8:
3164 case 108:
3165 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3166 "'eng:SP Red Test Only'");
3167 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3168 "'eng:Free service for test purpose'");
3169 osu_ssid = "OSU-Encrypted";
3170 osu_nai = "'anonymous@hotspot.net'";
3171 break;
3172 case 9:
3173 case 109:
3174 osu_ssid = "OSU-OSEN";
3175 osu_nai = "'test-anonymous@wi-fi.org'";
3176 osu_friendly_name = "'eng:SP Orange Test Only'";
3177 hs20_icon_filename = "icon_orange_zxx.png";
3178 if (dut->ap_osu_icon_tag == 2)
3179 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3180
3181 snprintf(hs20_icon, sizeof(hs20_icon),
3182 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3183 hs20_icon_filename);
3184 osu_icon = "icon_orange_zxx.png";
3185 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
3186 dut->ap_osu_method[0];
3187 osu_service_desc = NULL;
3188 break;
3189 default:
3190 break;
3191 }
3192
3193 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03003194 if (dut->ap_tag_ssid[0][0] &&
3195 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003196 dut->ap_osu_ssid) != 0 &&
3197 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003198 sigma_dut_print(dut, DUT_MSG_ERROR,
3199 "OSU_SSID and WLAN_TAG2 SSID differ");
3200 return -2;
3201 }
3202
3203 snprintf(buf, sizeof(buf), "'\"%s\"'",
3204 dut->ap_osu_ssid);
3205 } else {
3206 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
3207 }
3208
3209 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
3210
3211
3212 if (osu_friendly_name)
3213 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3214 osu_friendly_name);
3215 if (osu_service_desc)
3216 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3217 osu_service_desc);
3218 if (osu_nai)
3219 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
3220
3221 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
3222
3223 if (osu_icon)
3224 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3225 osu_icon);
3226
3227 if (dut->ap_osu_provider_list > 100) {
3228 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3229 "0");
3230 } else {
3231 snprintf(buf, sizeof(buf), "%d", osu_method);
3232 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3233 buf);
3234 }
3235 }
3236
3237 return 0;
3238}
3239
3240
Jouni Malinen13701222019-02-19 12:10:53 +02003241static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
3242 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003243{
3244 unsigned char bssid[ETH_ALEN];
3245 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
3246 int preference = 0xff;
3247
Jouni Malinen13701222019-02-19 12:10:53 +02003248 if (get_hwaddr(ifname, bssid) < 0)
3249 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003250 snprintf(anqp_string, str_size,
3251 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
3252 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
3253 preference,
3254 dummy_mac[0], dummy_mac[1], dummy_mac[2],
3255 dummy_mac[3], dummy_mac[4], dummy_mac[5],
3256 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02003257 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003258}
3259
3260
Hu Wang8a3b13a2020-03-14 09:56:48 +08003261static const char * get_hostapd_ifname(struct sigma_dut *dut)
3262{
3263 enum driver_type drv;
3264
3265 /* Use the configured hostapd ifname */
3266 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0)
3267 return dut->hostapd_ifname;
3268
3269 /* Use configured main ifname */
3270 if (dut->main_ifname) {
3271 if (dut->use_5g && dut->main_ifname_5g &&
3272 if_nametoindex(dut->main_ifname_5g) > 0)
3273 return dut->main_ifname_5g;
3274 if (!dut->use_5g && dut->main_ifname_2g &&
3275 if_nametoindex(dut->main_ifname_2g) > 0)
3276 return dut->main_ifname_2g;
3277 if (if_nametoindex(dut->main_ifname) > 0)
3278 return dut->main_ifname;
3279 }
3280
3281 /* Return based on driver type (indirectly started hostapd) */
3282 drv = get_driver_type(dut);
3283 if (drv == DRIVER_ATHEROS) {
3284 if (dut->use_5g && if_nametoindex("ath1") > 0)
3285 return "ath1";
3286 return "ath0";
3287 }
3288
3289 if (drv == DRIVER_OPENWRT) {
3290 if (sigma_radio_ifname[0] &&
3291 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3292 return "ath2";
3293 if (sigma_radio_ifname[0] &&
3294 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3295 return "ath1";
3296 return "ath0";
3297 }
3298
3299 /* wlan1-is-likely-5-GHz design */
3300 if (dut->use_5g && if_nametoindex("wlan1") > 0)
3301 return "wlan1";
3302
3303 /* If nothing else matches, hope for the best and guess this is wlan0 */
3304 return "wlan0";
3305}
3306
3307
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003308static void get_if_name(struct sigma_dut *dut, char *ifname_str,
3309 size_t str_size, int wlan_tag)
3310{
Jouni Malinenf8984642017-10-12 00:02:37 +03003311 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003312 enum driver_type drv;
3313
Hu Wang8a3b13a2020-03-14 09:56:48 +08003314 ifname = get_hostapd_ifname(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003315 drv = get_driver_type(dut);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003316
3317 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
3318 /* Handle tagged-ifname only on OPENWRT for now */
3319 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08003320 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
3321 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03003322 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003323 } else {
3324 snprintf(ifname_str, str_size, "%s", ifname);
3325 }
3326}
3327
3328
Jouni Malinen6c882b22020-03-04 21:11:02 +02003329static int sae_pw_id_used(struct sigma_dut *dut)
3330{
3331 return dut->ap_sae_passwords &&
3332 strchr(dut->ap_sae_passwords, ':');
3333}
3334
3335
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003336static int owrt_ap_config_vap(struct sigma_dut *dut)
3337{
3338 char buf[256], *temp;
Jouni Malinen3aa72862019-05-29 23:14:51 +03003339 int vap_id = 0, vap_count, i, j, res;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003340 const char *ifname;
3341 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003342
priyadharshini gowthaman73561262018-02-20 13:24:59 -08003343 if (sigma_radio_ifname[0] &&
3344 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3345 ifname = "ath2";
3346 else if (sigma_radio_ifname[0] &&
3347 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3348 ifname = "ath1";
3349 else
3350 ifname = "ath0";
3351
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003352 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003353 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003354
3355 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
3356 if (sigma_radio_ifname[vap_id] &&
3357 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
3358 break;
3359 }
3360 if (vap_id == MAX_RADIO)
3361 continue;
3362
3363 /* Single VAP configuration */
3364 if (!dut->ap_is_dual)
3365 vap_id = vap_count;
3366
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003367 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
3368 /*
3369 * We keep a separate array of ap_tag_ssid and
3370 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
3371 * So j=0 => WLAN_TAG = 2
3372 */
3373 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003374
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003375 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
3376 (dut->ap_interface_5g || dut->ap_interface_2g)) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03003377 res = snprintf(
3378 dut->ap_tag_ssid[wlan_tag - 2],
3379 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
3380 "%s-owe", dut->ap_ssid);
3381 if (res < 0 ||
3382 res >= sizeof(dut->ap_tag_ssid[wlan_tag -
3383 2]))
3384 dut->ap_tag_ssid[wlan_tag - 2][0] =
3385 '\0';
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003386 }
3387
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003388 if (dut->ap_tag_ssid[j][0] == '\0')
3389 continue;
3390
3391 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
3392 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
3393 "device", buf);
3394 /* SSID */
3395 snprintf(buf, sizeof(buf), "\"%s\"",
3396 dut->ap_tag_ssid[j]);
3397 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3398 "ssid", buf);
3399
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003400 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3401 dut->ap_tag_ssid[0][0] &&
3402 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3403 /* OWE transition mode */
3404 snprintf(buf, sizeof(buf), "%s", ifname);
3405 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3406 "owe_transition_ifname", buf);
3407 }
3408
3409 if (dut->ap_key_mgmt == AP_OPEN &&
3410 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3411 /* OWE transition mode */
3412 snprintf(buf, sizeof(buf), "%s", ifname);
3413 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3414 "owe_transition_ifname", buf);
3415 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3416 "hidden", "1");
3417 }
3418
Jouni Malinen6be21c82018-08-01 18:47:24 +03003419 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003420 unsigned char self_mac[ETH_ALEN];
3421 char mac_str[20];
3422
3423 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3424 "mobility_domain",
3425 dut->ap_mobility_domain);
3426 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Jouni Malinen9f943312019-08-19 23:49:16 +03003427 "ft_over_ds",
3428 dut->ap_ft_ds == VALUE_ENABLED ?
3429 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003430 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3431 "ieee80211r", "1");
3432 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3433 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02003434 if (get_hwaddr(sigma_radio_ifname[0],
3435 self_mac) < 0)
3436 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003437 snprintf(mac_str, sizeof(mac_str),
3438 "%02x:%02x:%02x:%02x:%02x:%02x",
3439 self_mac[0], self_mac[1], self_mac[2],
3440 self_mac[3], self_mac[4], self_mac[5]);
3441 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3442 "ap_macaddr", mac_str);
3443 snprintf(mac_str, sizeof(mac_str),
3444 "%02x%02x%02x%02x%02x%02x",
3445 self_mac[0], self_mac[1], self_mac[2],
3446 self_mac[3], self_mac[4], self_mac[5]);
3447 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3448 "r1_key_holder", mac_str);
3449 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3450 "ft_psk_generate_local", "1");
3451 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3452 "kh_key_hex",
3453 "000102030405060708090a0b0c0d0e0f");
3454 snprintf(mac_str, sizeof(mac_str),
3455 "%02x:%02x:%02x:%02x:%02x:%02x",
3456 dut->ft_bss_mac_list[0][0],
3457 dut->ft_bss_mac_list[0][1],
3458 dut->ft_bss_mac_list[0][2],
3459 dut->ft_bss_mac_list[0][3],
3460 dut->ft_bss_mac_list[0][4],
3461 dut->ft_bss_mac_list[0][5]);
3462 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3463 "ap2_macaddr", mac_str);
3464 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3465 "ap2_r1_key_holder", mac_str);
3466 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3467 "nasid2", "nas2.example.com");
3468 }
3469
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003470 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
3471 wlan_tag == 2) {
3472 /* Only supported for WLAN_TAG=2 */
3473 owrt_ap_set_vap(dut, vap_count + 1, "osen",
3474 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003475 snprintf(buf, sizeof(buf), "wpa2");
3476 owrt_ap_set_vap(dut, vap_count + 1,
3477 "encryption", buf);
3478 snprintf(buf, sizeof(buf), "%s",
3479 dut->ap2_radius_ipaddr);
3480 owrt_ap_set_vap(dut, vap_count + 1,
3481 "auth_server", buf);
3482 snprintf(buf, sizeof(buf), "%d",
3483 dut->ap2_radius_port);
3484 owrt_ap_set_vap(dut, vap_count + 1,
3485 "auth_port", buf);
3486 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003487 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003488 owrt_ap_set_vap(dut, vap_count + 1,
3489 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003490 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
3491 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3492 "encryption", "psk2+ccmp");
3493 snprintf(buf, sizeof(buf), "\"%s\"",
3494 dut->ap_passphrase);
3495 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3496 "key", buf);
3497 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003498 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003499 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003500 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3501 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3502 "owe", "1");
3503 snprintf(buf, sizeof(buf), "ccmp");
3504 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3505 "encryption", buf);
3506 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3507 "ieee80211w", "2");
3508 if (dut->ap_sae_groups) {
3509 snprintf(buf, sizeof(buf), "\'%s\'",
3510 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003511 owrt_ap_set_list_vap(dut, vap_count +
3512 (wlan_tag - 1),
3513 "owe_groups", buf);
Hu Wang6010ce72020-03-05 19:33:53 +08003514 if (dut->owe_ptk_workaround)
3515 owrt_ap_set_list_vap(
3516 dut, vap_count +
3517 (wlan_tag - 1),
3518 "owe_ptk_workaround",
3519 "1");
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003520 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003521 }
3522 }
3523
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003524 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003525 if (dut->program == PROGRAM_MBO &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003526 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003527 unsigned char self_mac[ETH_ALEN];
3528 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003529 char anqp_string[200];
3530
Jouni Malinen13701222019-02-19 12:10:53 +02003531 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3532 anqp_string,
3533 sizeof(anqp_string)) < 0)
3534 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003535 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3536 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003537
Jouni Malinen6be21c82018-08-01 18:47:24 +03003538 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003539 owrt_ap_set_vap(dut, vap_count,
3540 "mobility_domain",
3541 dut->ap_mobility_domain);
3542 owrt_ap_set_vap(dut, vap_count,
Jouni Malinen9f943312019-08-19 23:49:16 +03003543 "ft_over_ds",
3544 dut->ap_ft_ds == VALUE_ENABLED ?
3545 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003546 owrt_ap_set_vap(dut, vap_count,
3547 "ieee80211r", "1");
3548 owrt_ap_set_vap(dut, vap_count,
3549 "nasid", "nas1.example.com");
3550 get_hwaddr(sigma_radio_ifname[0], self_mac);
3551 snprintf(mac_str, sizeof(mac_str),
3552 "%02x:%02x:%02x:%02x:%02x:%02x",
3553 self_mac[0], self_mac[1], self_mac[2],
3554 self_mac[3], self_mac[4], self_mac[5]);
3555 owrt_ap_set_vap(dut, vap_count,
3556 "ap_macaddr", mac_str);
3557 snprintf(mac_str, sizeof(mac_str),
3558 "%02x%02x%02x%02x%02x%02x",
3559 self_mac[0], self_mac[1], self_mac[2],
3560 self_mac[3], self_mac[4], self_mac[5]);
3561 owrt_ap_set_vap(dut, vap_count,
3562 "r1_key_holder", mac_str);
3563 owrt_ap_set_vap(dut, vap_count,
3564 "ft_psk_generate_local", "1");
3565 owrt_ap_set_vap(dut, vap_count,
3566 "kh_key_hex",
3567 "000102030405060708090a0b0c0d0e0f");
3568 snprintf(mac_str, sizeof(mac_str),
3569 "%02x:%02x:%02x:%02x:%02x:%02x",
3570 dut->ft_bss_mac_list[0][0],
3571 dut->ft_bss_mac_list[0][1],
3572 dut->ft_bss_mac_list[0][2],
3573 dut->ft_bss_mac_list[0][3],
3574 dut->ft_bss_mac_list[0][4],
3575 dut->ft_bss_mac_list[0][5]);
3576 owrt_ap_set_vap(dut, vap_count,
3577 "ap2_macaddr", mac_str);
3578 owrt_ap_set_vap(dut, vap_count,
3579 "ap2_r1_key_holder", mac_str);
3580 owrt_ap_set_vap(dut, vap_count,
3581 "nasid2", "nas2.example.com");
3582 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003583 }
3584
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003585 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003586 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003587 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3588 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3589 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3590
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003591 if (dut->ap_80plus80 == 1)
3592 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3593
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003594 if (dut->ap_akm == 1) {
3595 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3596 "3600");
3597 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3598 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3599 "1");
3600 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3601 "1234");
3602 owrt_ap_set_vap(dut, vap_id,
3603 "erp_send_reauth_start", "1");
3604 }
3605
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003606 if (dut->ap_filshlp == VALUE_ENABLED) {
3607 struct ifreq ifr;
3608 char *ifname;
3609 int s;
3610 struct sockaddr_in *ipaddr;
3611
3612 s = socket(AF_INET, SOCK_DGRAM, 0);
3613 if (s < 0) {
3614 sigma_dut_print(dut, DUT_MSG_ERROR,
3615 "Failed to open socket");
3616 return -1;
3617 }
3618 ifr.ifr_addr.sa_family = AF_INET;
3619
3620 memset(&ifr, 0, sizeof(ifr));
3621 ifname = "br-lan";
3622 strlcpy(ifr.ifr_name, ifname,
3623 sizeof(ifr.ifr_name));
3624 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3625 perror("ioctl");
3626 close(s);
3627 return -1;
3628 }
3629
3630 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3631 snprintf(buf, sizeof(buf), "%s",
3632 inet_ntoa(ipaddr->sin_addr));
3633 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3634 buf);
3635 snprintf(buf, sizeof(buf), "%s",
3636 dut->ap_dhcpserv_ipaddr);
3637 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3638 buf);
3639 owrt_ap_set_vap(dut, vap_id,
3640 "dhcp_rapid_commit_proxy", "1");
3641 owrt_ap_set_vap(dut, vap_id,
3642 "fils_hlp_wait_time", "300");
3643 }
3644
3645 if (dut->ap_filsdscv == VALUE_ENABLED) {
3646 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3647 "1");
3648 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3649 "20");
3650 }
3651 }
3652
3653 if (dut->ap_filsdscv == VALUE_DISABLED) {
3654 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3655 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3656 }
3657
3658 if (dut->ap_oce == VALUE_DISABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003659 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003660 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3661 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3662 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3663
3664 if (dut->ap_filsdscv == VALUE_DISABLED) {
3665 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3666 "0");
3667 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3668 "0");
3669 }
3670
3671 if (dut->device_type == AP_testbed)
3672 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3673 }
3674
3675 /* NAIRealm */
3676 if (dut->ap_nairealm_int == 1) {
3677 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3678 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3679 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3680 }
3681
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003682 /* SSID */
3683 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3684 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3685
3686 /* Encryption */
3687 switch (dut->ap_key_mgmt) {
3688 case AP_OPEN:
3689 if (dut->ap_cipher == AP_WEP) {
3690 owrt_ap_set_vap(dut, vap_count, "encryption",
3691 "wep-mixed");
3692 owrt_ap_set_vap(dut, vap_count, "key",
3693 dut->ap_wepkey);
3694 } else {
3695 owrt_ap_set_vap(dut, vap_count, "encryption",
3696 "none");
3697 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003698 if (dut->ap_key_mgmt == AP_OPEN &&
3699 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3700 /* OWE transition mode */
3701 snprintf(ifname2, sizeof(ifname2), "%s1",
3702 ifname);
3703 owrt_ap_set_vap(dut, vap_count,
3704 "owe_transition_ifname",
3705 ifname2);
3706 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003707 break;
3708 case AP_WPA2_PSK:
3709 case AP_WPA2_PSK_MIXED:
3710 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003711 case AP_WPA2_SAE:
3712 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003713 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3714 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003715 snprintf(buf, sizeof(buf), "psk2");
3716 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3717 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003718 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3719 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003720 } else {
3721 snprintf(buf, sizeof(buf), "psk");
3722 }
3723
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003724 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3725 if (dut->ap_cipher == AP_CCMP_TKIP)
3726 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3727 else if (dut->ap_cipher == AP_TKIP)
3728 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003729 else if (dut->ap_cipher == AP_GCMP_128)
3730 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003731 else
3732 strlcat(buf, "+ccmp", sizeof(buf));
3733 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003734
3735 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003736
3737 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3738 snprintf(buf, sizeof(buf), "\"%s\"",
3739 dut->ap_psk);
3740 owrt_ap_set_vap(dut, vap_count, "key", buf);
3741 } else {
3742 snprintf(buf, sizeof(buf), "\"%s\"",
3743 dut->ap_passphrase);
3744 owrt_ap_set_vap(dut, vap_count, "key", buf);
3745 }
3746
3747 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3748 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3749 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3750 else
3751 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3752
3753 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3754 snprintf(buf, sizeof(buf), "%s",
3755 dut->ap_passphrase);
3756 owrt_ap_set_vap(dut, vap_count, "sae_password",
3757 buf);
3758 } else {
3759 snprintf(buf, sizeof(buf), "%s",
3760 dut->ap_passphrase);
3761 owrt_ap_set_vap(dut, vap_count,
3762 "wpa_passphrase", buf);
3763 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003764 break;
3765 case AP_WPA2_EAP:
3766 case AP_WPA2_EAP_MIXED:
3767 case AP_WPA_EAP:
3768 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3769 snprintf(buf, sizeof(buf), "wpa2");
3770 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3771 snprintf(buf, sizeof(buf), "wpa-mixed");
3772 } else {
3773 snprintf(buf, sizeof(buf), "wpa");
3774 }
3775
Peng Xu591be452017-05-10 17:27:28 -07003776 if (dut->ap_cipher == AP_CCMP_TKIP)
3777 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3778 else if (dut->ap_cipher == AP_TKIP)
3779 strlcat(buf, "+tkip", sizeof(buf));
3780 else
3781 strlcat(buf, "+ccmp", sizeof(buf));
3782
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003783 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3784 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3785 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3786 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3787 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3788 snprintf(buf, sizeof(buf), "%s",
3789 dut->ap_radius_password);
3790 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3791 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003792 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003793 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003794 case AP_WPA2_FT_EAP:
3795 case AP_WPA2_FT_PSK:
3796 case AP_WPA2_EAP_SHA256:
3797 case AP_WPA2_PSK_SHA256:
3798 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003799 /* TODO */
3800 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003801 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003802 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3803 snprintf(buf, sizeof(buf), "gcmp");
3804 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3805 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3806 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3807 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3808 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3809 snprintf(buf, sizeof(buf), "%s",
3810 dut->ap_radius_password);
3811 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3812 snprintf(buf, sizeof(buf), "%d",
3813 dut->ap_group_mgmt_cipher);
3814 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3815 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003816 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003817 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003818 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3819 snprintf(buf, sizeof(buf), "ccmp");
3820 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3821 if (dut->ap_sae_groups) {
3822 snprintf(buf, sizeof(buf), "\'%s\'",
3823 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003824 owrt_ap_set_list_vap(dut, vap_count,
3825 "owe_groups", buf);
Hu Wang6010ce72020-03-05 19:33:53 +08003826 if (dut->owe_ptk_workaround)
3827 owrt_ap_set_list_vap(
3828 dut, vap_count,
3829 "owe_ptk_workaround", "1");
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003830 }
3831
3832 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3833 dut->ap_tag_ssid[0][0] &&
3834 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3835 /* OWE transition mode */
3836 snprintf(ifname2, sizeof(ifname2), "%s1",
3837 ifname);
3838 owrt_ap_set_vap(dut, vap_count,
3839 "owe_transition_ifname",
3840 ifname2);
3841 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3842 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003843 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003844 }
3845
3846 if (!dut->ap_is_dual)
3847 break;
3848 }
3849
3850 if (dut->ap_is_dual)
3851 return 1;
3852
3853 /* PMF */
3854 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3855 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3856
3857 /* Add SHA256 */
3858 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3859 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3860
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003861 /* Add SHA384 for akmsuitetype 15 */
3862 if (dut->ap_akm == 1) {
3863 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3864 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3865 }
3866
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303867 /* Enable RSN preauthentication, if asked to */
3868 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3869 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003871 /* Hotspot 2.0 */
3872 if (dut->ap_hs2) {
3873 int ret;
3874
3875 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3876 if (ret)
3877 return ret;
3878 }
3879
3880 /* Interworking */
3881 if (dut->ap_interworking) {
3882 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3883 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3884 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3885 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3886 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3887 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3888 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3889 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3890 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3891 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3892
3893 if (dut->ap_gas_cb_delay > 0) {
3894 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3895 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3896 }
3897
3898 if (dut->ap_roaming_cons[0]) {
3899 char *rcons, *temp_ptr;
3900
3901 rcons = strdup(dut->ap_roaming_cons);
3902 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003903 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003904
3905 temp_ptr = strchr(rcons, ';');
3906
3907 if (temp_ptr)
3908 *temp_ptr++ = '\0';
3909
3910 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3911 rcons);
3912
3913 if (temp_ptr)
3914 owrt_ap_set_list_vap(dut, vap_id,
3915 "roaming_consortium",
3916 temp_ptr);
3917
3918 free(rcons);
3919 }
3920 }
3921
3922 if (dut->ap_venue_name) {
3923 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3924 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3925 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3926 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3927 }
3928
3929 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003930 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3931 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003932 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003933 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003934 }
3935
3936 if (dut->ap_nai_realm_list == 1) {
3937 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3938 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3939 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3940 "'0,wi-fi.org;example.com,13[5:6]'");
3941
3942 } else if (dut->ap_nai_realm_list == 2) {
3943 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3944 "'0,wi-fi.org,21[2:4][5:7]'");
3945 } else if (dut->ap_nai_realm_list == 3) {
3946 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3947 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3948 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3949 "'0,wi-fi.org;example.com,13[5:6]'");
3950 } else if (dut->ap_nai_realm_list == 4) {
3951 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3952 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3953 } else if (dut->ap_nai_realm_list == 5) {
3954 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3955 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3956 } else if (dut->ap_nai_realm_list == 6) {
3957 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3958 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3959 } else if (dut->ap_nai_realm_list == 7) {
3960 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3961 "'0,wi-fi.org,13[5:6]'");
3962 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3963 "'0,wi-fi.org,21[2:4][5:7]'");
3964 }
3965
3966 if (dut->ap_domain_name_list[0])
3967 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3968 dut->ap_domain_name_list);
3969
3970 if (dut->ap_ip_addr_type_avail)
3971 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3972 "'0c'");
3973
3974 temp = buf;
3975
3976 *temp++ = '\'';
3977
3978 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3979 if (i)
3980 *temp++ = ';';
3981
3982 snprintf(temp,
3983 sizeof(dut->ap_plmn_mcc[i]) +
3984 sizeof(dut->ap_plmn_mnc[i]) + 1,
3985 "%s,%s",
3986 dut->ap_plmn_mcc[i],
3987 dut->ap_plmn_mnc[i]);
3988
3989 temp += strlen(dut->ap_plmn_mcc[i]) +
3990 strlen(dut->ap_plmn_mnc[i]) + 1;
3991 }
3992
3993 *temp++ = '\'';
3994 *temp++ = '\0';
3995
3996 if (i)
3997 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3998
3999 if (dut->ap_qos_map_set == 1)
4000 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
4001 else if (dut->ap_qos_map_set == 2)
4002 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
4003
4004 /* Proxy-ARP */
4005 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
4006 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
4007
4008 /* DGAF */
4009 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
4010 /* parse to hostapd */
4011 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
4012 /* parse to wifi driver */
4013 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
4014
4015 /* HCBSSLoad */
4016 if (dut->ap_bss_load) {
4017 unsigned int bssload = 0;
4018
4019 if (dut->ap_bss_load == 1) {
4020 /* STA count: 1, CU: 50, AAC: 65535 */
4021 bssload = 0x0132ffff;
4022 } else if (dut->ap_bss_load == 2) {
4023 /* STA count: 1, CU: 200, AAC: 65535 */
4024 bssload = 0x01c8ffff;
4025 } else if (dut->ap_bss_load == 3) {
4026 /* STA count: 1, CU: 75, AAC: 65535 */
4027 bssload = 0x014bffff;
4028 }
4029
4030 snprintf(buf, sizeof(buf), "%d", bssload);
4031 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
4032 }
4033
4034 /* L2TIF */
4035 if (dut->ap_l2tif)
4036 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
4037
4038 if (dut->ap_disable_protection == 1)
4039 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
4040
Sunil Dutt77b213d2017-09-14 18:24:40 +03004041 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004042 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
4043 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08004044 if (dut->program == PROGRAM_HE) {
4045 owrt_ap_set_vap(dut, vap_id, "he_subfer", "1");
4046 owrt_ap_set_vap(dut, vap_id, "cwmenable", "0");
4047 }
4048 } else {
4049 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
4050 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
4051 if (dut->program == PROGRAM_HE)
4052 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004053 }
4054
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08004055 if (dut->ap_mu_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004056 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08004057 if (dut->program == PROGRAM_HE) {
4058 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "1");
4059 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "1");
4060 }
4061 } else {
4062 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "0");
4063 if (dut->program == PROGRAM_HE) {
4064 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "0");
4065 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "0");
4066 }
4067 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004068
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05304069 if (dut->ap_tx_stbc) {
4070 /* STBC and beamforming are mutually exclusive features */
4071 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
4072 }
4073
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05304074 /* enable dfsmode */
4075 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
4076 owrt_ap_set_vap(dut, vap_id, "doth", buf);
4077
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004078 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
4079 char anqpval[1024];
4080
4081 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
4082
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004083 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304084 snprintf(anqpval, sizeof(anqpval),
4085 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004086 dut->ap_val_lci, dut->ap_infoz);
4087 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4088 }
4089
4090 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304091 snprintf(anqpval, sizeof(anqpval),
4092 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004093 dut->ap_val_lcr);
4094 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4095 }
4096
4097 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
4098 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4099 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
4100 }
4101
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004102 if (dut->program == PROGRAM_MBO) {
4103 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
4104 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
4105 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07004106 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004107
4108 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4109 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07004110 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
4111 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004112 }
4113
Jouni Malinen6be21c82018-08-01 18:47:24 +03004114 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004115 unsigned char self_mac[ETH_ALEN];
4116 char mac_str[20];
4117
Jouni Malinen9f943312019-08-19 23:49:16 +03004118 owrt_ap_set_vap(dut, vap_id, "ft_over_ds",
4119 dut->ap_ft_ds == VALUE_ENABLED ? "1" : "0");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004120 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02004121 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
4122 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004123 snprintf(mac_str, sizeof(mac_str),
4124 "%02x:%02x:%02x:%02x:%02x:%02x",
4125 self_mac[0], self_mac[1], self_mac[2],
4126 self_mac[3], self_mac[4], self_mac[5]);
4127 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004128 snprintf(mac_str, sizeof(mac_str),
4129 "%02x:%02x:%02x:%02x:%02x:%02x",
4130 self_mac[0], self_mac[1], self_mac[2],
4131 self_mac[3], self_mac[4], self_mac[5]);
4132 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004133 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
4134 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
4135 "000102030405060708090a0b0c0d0e0f");
4136 snprintf(mac_str, sizeof(mac_str),
4137 "%02x:%02x:%02x:%02x:%02x:%02x",
4138 dut->ft_bss_mac_list[0][0],
4139 dut->ft_bss_mac_list[0][1],
4140 dut->ft_bss_mac_list[0][2],
4141 dut->ft_bss_mac_list[0][3],
4142 dut->ft_bss_mac_list[0][4],
4143 dut->ft_bss_mac_list[0][5]);
4144 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004145 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
4146 dut->ap_mobility_domain);
4147 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004148 }
4149
Jouni Malinen6be21c82018-08-01 18:47:24 +03004150 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
4151 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004152 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
4153 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004154 }
4155
Jouni Malinen6be21c82018-08-01 18:47:24 +03004156 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004157 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
4158 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004159 }
4160
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08004161 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
4162 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
4163
priyadharshini gowthamande81f392017-12-28 15:28:49 -08004164 /* Enable/disable PMKSA caching, if asked to */
4165 if (dut->ap_pmksa == 1) {
4166 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
4167 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
4168 }
4169
Jouni Malinen05d005a2020-03-26 12:49:33 +02004170 if (dut->ap_beacon_prot)
4171 owrt_ap_set_vap(dut, vap_id, "beacon_prot", "1");
4172
Jouni Malinenc098c442020-03-26 13:01:50 +02004173 if (dut->ap_transition_disable) {
4174 snprintf(buf, sizeof(buf), "0x%02x",
4175 dut->ap_transition_disable);
4176 owrt_ap_set_vap(dut, vap_id, "transition_disable", buf);
4177 }
4178
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004179 if (dut->rsne_override) {
4180 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
4181 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
4182 }
4183
Jouni Malinen7960e3a2019-12-07 17:04:35 +02004184 if (dut->rsnxe_override_eapol)
4185 owrt_ap_set_vap(dut, vap_count, "rsnxe_override_eapol",
4186 dut->rsnxe_override_eapol);
4187
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004188 if (dut->sae_commit_override) {
4189 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
4190 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
4191 }
4192
4193 if (dut->ap_sae_groups) {
4194 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07004195 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004196 }
4197
Jouni Malinen11e55212019-11-22 21:46:59 +02004198 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
4199 const char *sae_pwe = NULL;
4200
Jouni Malinen6c882b22020-03-04 21:11:02 +02004201 if (dut->sae_pwe == SAE_PWE_LOOP && sae_pw_id_used(dut))
4202 sae_pwe = "3";
4203 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02004204 sae_pwe = "0";
4205 else if (dut->sae_pwe == SAE_PWE_H2E)
4206 sae_pwe = "1";
4207 else if (dut->sae_h2e_default)
4208 sae_pwe = "2";
4209 if (sae_pwe)
4210 owrt_ap_set_vap(dut, vap_count, "sae_pwe", sae_pwe);
4211 }
4212
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004213 if (dut->sae_anti_clogging_threshold >= 0) {
4214 snprintf(buf, sizeof(buf), "%d",
4215 dut->sae_anti_clogging_threshold);
4216 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
4217 buf);
4218 }
4219
4220 if (dut->sae_reflection)
4221 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03004222 if (dut->sae_confirm_immediate)
Jouni Malinena6f1db02020-01-23 00:46:12 +02004223 owrt_ap_set_vap(dut, vap_count, "sae_confirm_immediate", "2");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004224
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07004225 if (dut->ap_he_dlofdma == VALUE_ENABLED && dut->ap_he_ppdu == PPDU_MU) {
4226 dut->ap_txBF = 0;
4227 dut->ap_mu_txBF = 0;
4228 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
4229 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
4230 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
4231 }
4232
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07004233 if (dut->program == PROGRAM_HE &&
4234 (dut->ap_txBF || dut->ap_he_ulofdma == VALUE_ENABLED ||
4235 dut->ap_he_mimo == MIMO_DL)) {
4236 switch (dut->ap_chwidth) {
4237 case AP_20:
4238 owrt_ap_set_vap(dut, vap_id, "chwidth", "0");
4239 break;
4240 case AP_40:
4241 owrt_ap_set_vap(dut, vap_id, "chwidth", "1");
4242 break;
4243 case AP_80:
4244 owrt_ap_set_vap(dut, vap_id, "chwidth", "2");
4245 break;
4246 case AP_160:
4247 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4248 break;
4249 case AP_80_80:
4250 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4251 break;
4252 case AP_AUTO:
4253 default:
4254 break;
4255 }
4256 }
4257
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258 return 1;
4259}
4260
4261
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004262static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
4263{
4264 char anqpval[1024];
4265 unsigned char addr[6];
4266 unsigned char addr2[6];
4267 struct ifreq ifr;
4268 char *ifname;
4269 int s;
4270 int vap_id = 0;
4271
4272 s = socket(AF_INET, SOCK_DGRAM, 0);
4273 if (s < 0) {
4274 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
4275 return -1;
4276 }
4277
4278 memset(&ifr, 0, sizeof(ifr));
4279 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004280 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004281 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4282 perror("ioctl");
4283 close(s);
4284 return -1;
4285 }
4286 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
4287
4288 memset(&ifr, 0, sizeof(ifr));
4289 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004290 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004291 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4292 perror("ioctl");
4293 close(s);
4294 return -1;
4295 }
4296 close(s);
4297 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
4298
4299 snprintf(anqpval, sizeof(anqpval),
4300 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
4301 dut->ap_val_lci, dut->ap_infoz,
4302 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
4303 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
4304
4305 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4306 return 0;
4307}
4308
4309
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004310static int owrt_ap_post_config_commit(struct sigma_dut *dut,
4311 struct sigma_conn *conn,
4312 struct sigma_cmd *cmd)
4313{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004314 int ap_security = 0;
4315 int i;
4316
4317 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
4318 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
4319 ap_security = 1;
4320 }
4321 if (dut->ap_key_mgmt != AP_OPEN)
4322 ap_security = 1;
4323 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004324 /* allow some time for hostapd to start before returning
4325 * success */
4326 usleep(500000);
4327
4328 if (run_hostapd_cli(dut, "ping") != 0) {
4329 send_resp(dut, conn, SIGMA_ERROR,
4330 "errorCode,Failed to talk to hostapd");
4331 return 0;
4332 }
4333 }
4334
4335 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
4336 ath_ap_set_params(dut);
4337
4338 /* Send response */
4339 return 1;
4340}
4341
4342
4343static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
4344 struct sigma_conn *conn,
4345 struct sigma_cmd *cmd)
4346{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004347 if (dut->program == PROGRAM_DPP &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004348 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004349 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
4350 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
4351 }
4352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004353 /* Stop the AP */
4354 run_system(dut, "wifi down");
4355
4356 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05304357 run_system(dut, "rm -rf /etc/config/wireless");
4358 switch (get_openwrt_driver_type()) {
4359 case OPENWRT_DRIVER_ATHEROS:
4360 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
4361 break;
4362 default:
4363 run_system(dut, "wifi detect > /etc/config/wireless");
4364 break;
4365 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366
4367 /* Configure Radio & VAP, commit the config */
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07004368 if (owrt_ap_config_radio(dut) < 0)
4369 return ERROR_SEND_STATUS;
Jouni Malinen13701222019-02-19 12:10:53 +02004370 if (owrt_ap_config_vap(dut) < 0)
4371 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004372 run_system(dut, "uci commit");
4373
4374 /* Start AP */
4375 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004376 if (dut->program != PROGRAM_MBO &&
4377 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004378 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004379 /*
4380 * MBO has a different ANQP element value which is set in
4381 * owrt_ap_config_vap().
4382 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004383 owrt_ap_config_vap_anqp(dut);
4384 run_system(dut, "uci commit");
4385 run_system(dut, "wifi");
4386 }
4387
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004388 return owrt_ap_post_config_commit(dut, conn, cmd);
4389}
4390
4391
4392static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
4393{
4394 unsigned char bssid[6];
4395 char buf[100];
4396 char *ifname, *radio_name;
4397 int vap_id = 0;
4398
4399 if (sigma_radio_ifname[0] &&
4400 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4401 ifname = "ath2";
4402 radio_name = "wifi2";
4403 vap_id = 2;
4404 } else if (sigma_radio_ifname[0] &&
4405 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4406 ifname = "ath1";
4407 radio_name = "wifi1";
4408 vap_id = 1;
4409 } else {
4410 ifname = "ath0";
4411 radio_name = "wifi0";
4412 vap_id = 0;
4413 }
4414
4415 if (!get_hwaddr(ifname, bssid)) {
4416 snprintf(buf, sizeof(buf), "%s", bssid);
4417 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4418 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4419 "%02x:%02x:%02x:%02x:%02x:%02x",
4420 bssid[0], bssid[1], bssid[2], bssid[3],
4421 bssid[4], bssid[5]);
4422 } else {
4423 if (!get_hwaddr(radio_name, bssid)) {
4424 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
4425 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4426 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4427 "%02x:%02x:%02x:%02x:%02x:%02x",
4428 bssid[0], bssid[1], bssid[2], bssid[3],
4429 bssid[4], bssid[5]);
4430 } else {
4431 /* Select & enable/disable radios */
4432 if (sigma_radio_ifname[0] &&
4433 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4434 /* We want to use wifi2 */
4435 owrt_ap_set_radio(dut, 0, "disabled", "1");
4436 owrt_ap_set_radio(dut, 1, "disabled", "1");
4437 owrt_ap_set_radio(dut, 2, "disabled", "0");
4438 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
4439 } else if (sigma_radio_ifname[0] &&
4440 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4441 /* We want to use wifi1 */
4442 owrt_ap_set_radio(dut, 0, "disabled", "1");
4443 owrt_ap_set_radio(dut, 1, "disabled", "0");
4444 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
4445 } else {
4446 /* We want to use wifi0 */
4447 owrt_ap_set_radio(dut, 0, "disabled", "0");
4448 owrt_ap_set_radio(dut, 1, "disabled", "1");
4449 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
4450 }
4451
4452 run_system(dut, "uci commit");
4453 run_system(dut, "wifi up");
4454
4455 if (!get_hwaddr(radio_name, bssid)) {
4456 snprintf(buf, sizeof(buf), "%s",
4457 dut->ap_hessid);
4458 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4459 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4460 "%02x:%02x:%02x:%02x:%02x:%02x",
4461 bssid[0], bssid[1], bssid[2], bssid[3],
4462 bssid[4], bssid[5]);
4463 }
4464 }
4465 }
4466}
4467
4468
Jouni Malinenf7222712019-06-13 01:50:21 +03004469static enum sigma_cmd_result cmd_ap_reboot(struct sigma_dut *dut,
4470 struct sigma_conn *conn,
4471 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004472{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004473 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004474 case DRIVER_ATHEROS:
4475 run_system(dut, "apdown");
4476 sleep(1);
4477 run_system(dut, "reboot");
4478 break;
4479 case DRIVER_OPENWRT:
4480 run_system(dut, "wifi down");
4481 sleep(1);
4482 run_system(dut, "reboot");
4483 break;
4484 default:
4485 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
4486 break;
4487 }
4488
4489 return 1;
4490}
4491
4492
4493int ascii2hexstr(const char *str, char *hex)
4494{
4495 int i, length;
4496
4497 length = strlen(str);
4498
4499 for (i = 0; i < length; i++)
4500 snprintf(hex + i * 2, 3, "%X", str[i]);
4501
4502 hex[length * 2] = '\0';
4503 return 1;
4504}
4505
4506
4507static int kill_process(struct sigma_dut *dut, char *proc_name,
4508 unsigned char is_proc_instance_one, int sig)
4509{
4510#ifdef __linux__
4511 struct dirent *dp, *dp_in;
4512 const char *direc = "/proc/";
4513 char buf[100];
4514 DIR *dir = opendir(direc);
4515 DIR *dir_in;
4516 FILE *fp;
4517 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304518 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004519 int ret = -1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004520
4521 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304522 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004523
4524 while ((dp = readdir(dir)) != NULL) {
4525 if (dp->d_type != DT_DIR)
4526 continue;
4527
Jouni Malinen3aa72862019-05-29 23:14:51 +03004528 res = snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
4529 if (res < 0 || res >= sizeof(buf))
4530 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004531 dir_in = opendir(buf);
4532 if (dir_in == NULL)
4533 continue;
4534 dp_in = readdir(dir_in);
4535 closedir(dir_in);
4536 if (dp_in == NULL)
4537 continue;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004538 res = snprintf(buf, sizeof(buf), "%s%s/stat",
4539 direc, dp->d_name);
4540 if (res < 0 || res >= sizeof(buf))
4541 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004542 fp = fopen(buf, "r");
4543 if (fp == NULL)
4544 continue;
4545 if (fgets(buf, 100, fp) == NULL)
4546 buf[0] = '\0';
4547 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304548 pid = strtok_r(buf, " ", &saveptr);
4549 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004550 if (pid && temp &&
4551 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
4552 sigma_dut_print(dut, DUT_MSG_INFO,
4553 "killing %s process with PID %s",
4554 proc_name, pid);
4555 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
4556 atoi(pid));
4557 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304558 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004559 if (is_proc_instance_one)
4560 break;
4561 }
4562 }
4563
4564 closedir(dir);
4565
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304566 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004567#else /* __linux__ */
4568 return -1;
4569#endif /* __linux__ */
4570}
4571
4572
4573static int run_ndc(struct sigma_dut *dut, char *buf)
4574{
4575 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
4576 sleep(2);
4577 return run_system(dut, buf);
4578}
4579
4580
4581static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
4582 const char *field, const char *value)
4583{
4584 FILE *fcfg, *ftmp;
4585 char buf[MAX_CONF_LINE_LEN + 1];
4586 int len, found = 0, res;
4587
4588 /* Open the configuration file */
4589 fcfg = fopen(pfile, "r");
4590 if (!fcfg) {
4591 sigma_dut_print(dut, DUT_MSG_ERROR,
4592 "Failed to open hostapd conf file");
4593 return -1;
4594 }
4595
4596 snprintf(buf, sizeof(buf), "%s~", pfile);
4597 /* Open a temporary file */
4598 ftmp = fopen(buf, "w+");
4599 if (!ftmp) {
4600 fclose(fcfg);
4601 sigma_dut_print(dut, DUT_MSG_ERROR,
4602 "Failed to open temp buf");
4603 return -1;
4604 }
4605
4606 /* Read the values from the configuration file */
4607 len = strlen(field);
4608 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
4609 char *pline = buf;
4610
4611 /* commented line */
4612 if (buf[0] == '#')
4613 pline++;
4614
4615 /* Identify the configuration parameter to be updated */
4616 if (!found && strncmp(pline, field, len) == 0 &&
4617 pline[len] == '=') {
4618 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4619 found = 1;
4620 sigma_dut_print(dut, DUT_MSG_INFO,
4621 "Updated hostapd conf file");
4622 }
4623
4624 fprintf(ftmp, "%s", buf);
4625 }
4626
4627 if (!found) {
4628 /* Configuration line not found */
4629 /* Add the new line at the end of file */
4630 fprintf(ftmp, "%s=%s\n", field, value);
4631 sigma_dut_print(dut, DUT_MSG_INFO,
4632 "Adding a new line in hostapd conf file");
4633 }
4634
4635 fclose(fcfg);
4636 fclose(ftmp);
4637
4638 snprintf(buf, sizeof(buf), "%s~", pfile);
4639
4640 /* Restore the updated configuration file */
4641 res = rename(buf, pfile);
4642
4643 /* Remove the temporary file. Ignore the return value */
4644 unlink(buf);
4645
4646 /* chmod is needed because open() may not set permissions properly
4647 * depending on the current umask */
4648 if (chmod(pfile, 0660) < 0) {
4649 unlink(pfile);
4650 sigma_dut_print(dut, DUT_MSG_ERROR,
4651 "Error changing permissions");
4652 return -1;
4653 }
4654
4655 if (res < 0) {
4656 sigma_dut_print(dut, DUT_MSG_ERROR,
4657 "Error restoring conf file");
4658 return -1;
4659 }
4660
4661 return 0;
4662}
4663
4664
4665static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4666 struct sigma_conn *conn,
4667 struct sigma_cmd *cmd)
4668{
4669 char buf[100];
4670 struct stat s;
4671 int num_tries = 0, ret;
4672
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304673 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4674 system("killall netd") == 0) {
4675 /* Avoid Error: Error connecting (Connection refused)
4676 * Wait some time to allow netd to reinitialize.
4677 */
4678 usleep(1500000);
4679 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004680
4681 while (num_tries < 10) {
4682 ret = run_ndc(dut, "ndc softap stopap");
4683 num_tries++;
4684 if (WIFEXITED(ret))
4685 ret = WEXITSTATUS(ret);
4686 /* On success, NDC exits with 0 */
4687 if (ret == 0)
4688 break;
4689 sigma_dut_print(dut, DUT_MSG_INFO,
4690 "Try No. %d: ndc softap stopap failed, exit code %d",
4691 num_tries, ret);
4692 }
4693
4694 if (ret != 0)
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "ndc softap stopap command failed for 10 times - giving up");
4697
4698#ifdef ANDROID
4699 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304700 system("rmmod -f wlan");
4701 usleep(500000);
4702 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004703#else /* ANDROID */
4704 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4705 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4706#endif /* ANDROID */
4707
4708 switch (dut->ap_mode) {
4709 case AP_11g:
4710 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4711 break;
4712 case AP_11b:
4713 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4714 break;
4715 case AP_11ng:
4716 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4717 break;
4718 case AP_11a:
4719 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4720 break;
4721 case AP_11na:
4722 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4723 break;
4724 case AP_11ac:
4725 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4726 break;
4727 default:
4728 break;
4729 }
4730
4731 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4732 dut->ap_channel);
4733 run_ndc(dut, buf);
4734
4735 /*
4736 * ndc doesn't support double quotes as SSID string, so re-write
4737 * hostapd configuration file to update SSID.
4738 */
4739 if (dut->ap_ssid[0] != '\0')
4740 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4741
4742 switch (dut->ap_key_mgmt) {
4743 case AP_OPEN:
4744 if (dut->ap_cipher == AP_WEP) {
4745 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4746 snprintf(buf, sizeof(buf),
4747 "ndc softap qccmd set wep_key0=%s",
4748 dut->ap_wepkey);
4749 run_ndc(dut, buf);
4750 } else {
4751 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4752 }
4753 break;
4754 case AP_WPA2_PSK:
4755 case AP_WPA2_PSK_MIXED:
4756 case AP_WPA_PSK:
4757 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4758 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4759 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4760 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4761 else
4762 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4763
4764 /*
4765 * ndc doesn't support some special characters as passphrase,
4766 * so re-write hostapd configuration file to update Passphrase.
4767 */
4768 if (dut->ap_passphrase[0] != '\0')
4769 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4770 "wpa_passphrase", dut->ap_passphrase);
4771
4772 if (dut->ap_cipher == AP_CCMP_TKIP)
4773 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4774 "TKIP CCMP");
4775 else if (dut->ap_cipher == AP_TKIP)
4776 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4777 "TKIP");
4778 else
4779 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4780 "CCMP &");
4781 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004782 case AP_WPA2_SAE:
4783 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004784 case AP_WPA2_EAP:
4785 case AP_WPA2_EAP_MIXED:
4786 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004787 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004788 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004789 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004790 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004791 case AP_WPA2_FT_EAP:
4792 case AP_WPA2_FT_PSK:
4793 case AP_WPA2_EAP_SHA256:
4794 case AP_WPA2_PSK_SHA256:
4795 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004796 /* Not supported */
4797 break;
4798 }
4799
4800 switch (dut->ap_pmf) {
4801 case AP_PMF_DISABLED:
4802 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4803 break;
4804 case AP_PMF_OPTIONAL:
4805 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4806 if (dut->ap_add_sha256)
4807 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4808 else
4809 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4810 break;
4811 case AP_PMF_REQUIRED:
4812 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4813 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4814 break;
4815 }
4816
4817 if (dut->ap_countrycode[0]) {
4818 snprintf(buf, sizeof(buf),
4819 "ndc softap qccmd set country_code=%s",
4820 dut->ap_countrycode);
4821 run_ndc(dut, buf);
4822 }
4823
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304824 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4825 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4826
4827 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4828 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4829
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004830 run_ndc(dut, "ndc softap startap");
4831
Jouni Malinen5ea30922019-11-04 17:39:25 +02004832 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl,
4833 get_main_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004834 num_tries = 0;
4835 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4836 run_ndc(dut, "ndc softap stopap");
4837 run_ndc(dut, "ndc softap startap");
4838 num_tries++;
4839 }
4840
4841 if (num_tries == 10) {
4842 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4843 "iface %s :: reboot the APDUT", buf);
4844 return ret;
4845 }
4846
4847 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4848 ap_inet_addr, ap_inet_mask);
4849 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Jouni Malinen5ea30922019-11-04 17:39:25 +02004850 get_main_ifname(dut), ap_inet_addr, ap_inet_mask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004851 if (system(buf) != 0) {
4852 sigma_dut_print(dut, DUT_MSG_ERROR,
4853 "Failed to intialize the interface");
4854 return -1;
4855 }
4856
4857 return 1;
4858}
4859
4860
4861static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4862{
4863 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4864 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4865
4866 if (dut->ap_oper_name) {
4867 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4868 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4869 }
4870
4871 if (dut->ap_wan_metrics == 1)
4872 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4873 else if (dut->ap_wan_metrics == 2)
4874 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4875 else if (dut->ap_wan_metrics == 3)
4876 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4877 else if (dut->ap_wan_metrics == 4)
4878 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4879 else if (dut->ap_wan_metrics == 5)
4880 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4881
4882 if (dut->ap_conn_capab == 1) {
4883 fprintf(f, "hs20_conn_capab=1:0:0\n");
4884 fprintf(f, "hs20_conn_capab=6:20:1\n");
4885 fprintf(f, "hs20_conn_capab=6:22:0\n");
4886 fprintf(f, "hs20_conn_capab=6:80:1\n");
4887 fprintf(f, "hs20_conn_capab=6:443:1\n");
4888 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4889 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4890 fprintf(f, "hs20_conn_capab=17:500:1\n");
4891 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4892 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4893 fprintf(f, "hs20_conn_capab=50:0:1\n");
4894 } else if (dut->ap_conn_capab == 2) {
4895 fprintf(f, "hs20_conn_capab=6:80:1\n");
4896 fprintf(f, "hs20_conn_capab=6:443:1\n");
4897 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4898 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4899 } else if (dut->ap_conn_capab == 3) {
4900 fprintf(f, "hs20_conn_capab=6:80:1\n");
4901 fprintf(f, "hs20_conn_capab=6:443:1\n");
4902 } else if (dut->ap_conn_capab == 4) {
4903 fprintf(f, "hs20_conn_capab=6:80:1\n");
4904 fprintf(f, "hs20_conn_capab=6:443:1\n");
4905 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4906 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4907 }
4908
4909 if (dut->ap_oper_class == 1)
4910 fprintf(f, "hs20_operating_class=51\n");
4911 else if (dut->ap_oper_class == 2)
4912 fprintf(f, "hs20_operating_class=73\n");
4913 else if (dut->ap_oper_class == 3)
4914 fprintf(f, "hs20_operating_class=5173\n");
4915
4916 if (dut->ap_osu_provider_list) {
4917 char *osu_friendly_name = NULL;
4918 char *osu_icon = NULL;
4919 char *osu_ssid = NULL;
4920 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004921 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004922 char *osu_service_desc = NULL;
4923 char *hs20_icon_filename = NULL;
4924 char hs20_icon[150];
4925 int osu_method;
4926
4927 hs20_icon_filename = "icon_red_zxx.png";
4928 if (dut->ap_osu_icon_tag == 2)
4929 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4930 snprintf(hs20_icon, sizeof(hs20_icon),
4931 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4932 hs20_icon_filename);
4933 osu_icon = "icon_red_zxx.png";
4934 osu_ssid = "OSU";
4935 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4936 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4937 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4938
4939 if (strlen(dut->ap_osu_server_uri[0]))
4940 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4941 else
4942 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4943
4944 switch (dut->ap_osu_provider_list) {
4945 case 1:
4946 case 101:
4947 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4948 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4949 hs20_icon_filename = "icon_red_eng.png";
4950 if (dut->ap_osu_icon_tag == 2)
4951 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4952 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4953 hs20_icon_filename);
4954 fprintf(f, "osu_icon=icon_red_eng.png\n");
4955 break;
4956 case 2:
4957 case 102:
4958 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4959 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4960 hs20_icon_filename = "icon_orange_zxx.png";
4961 if (dut->ap_osu_icon_tag == 2)
4962 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4963 snprintf(hs20_icon, sizeof(hs20_icon),
4964 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4965 hs20_icon_filename);
4966 osu_icon = "icon_orange_zxx.png";
4967 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4968 break;
4969 case 3:
4970 case 103:
4971 osu_friendly_name = "spa:SP Red Test Only";
4972 osu_service_desc = "spa:Free service for test purpose";
4973 break;
4974 case 4:
4975 case 104:
4976 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4977 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4978 hs20_icon_filename = "icon_orange_eng.png";
4979 if (dut->ap_osu_icon_tag == 2)
4980 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4981 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4982 hs20_icon_filename);
4983 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4984 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4985
4986 hs20_icon_filename = "icon_orange_zxx.png";
4987 if (dut->ap_osu_icon_tag == 2)
4988 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4989 snprintf(hs20_icon, sizeof(hs20_icon),
4990 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4991 hs20_icon_filename);
4992 osu_icon = "icon_orange_zxx.png";
4993 break;
4994 case 5:
4995 case 105:
4996 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4997 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4998 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4999 hs20_icon_filename = "icon_orange_zxx.png";
5000 if (dut->ap_osu_icon_tag == 2)
5001 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5002 snprintf(hs20_icon, sizeof(hs20_icon),
5003 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
5004 hs20_icon_filename);
5005 osu_icon = "icon_orange_zxx.png";
5006 break;
5007 case 6:
5008 case 106:
5009 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
5010 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
5011 hs20_icon_filename = "icon_green_zxx.png";
5012 if (dut->ap_osu_icon_tag == 2)
5013 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5014 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
5015 hs20_icon_filename);
5016 fprintf(f, "osu_icon=icon_green_zxx.png\n");
5017 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
5018 fprintf(f, "osu_method_list=%d\n", osu_method);
5019
5020 if (strlen(dut->ap_osu_server_uri[1]))
5021 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
5022 else
5023 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
5024 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
5025 hs20_icon_filename = "icon_orange_zxx.png";
5026 if (dut->ap_osu_icon_tag == 2)
5027 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5028 snprintf(hs20_icon, sizeof(hs20_icon),
5029 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
5030 hs20_icon_filename);
5031 osu_icon = "icon_orange_zxx.png";
5032 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
5033 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
5034 osu_service_desc = NULL;
5035 break;
5036 case 7:
5037 case 107:
5038 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
5039 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
5040 hs20_icon_filename = "icon_green_eng.png";
5041 if (dut->ap_osu_icon_tag == 2)
5042 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5043 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
5044 hs20_icon_filename);
5045 fprintf(f, "osu_icon=icon_green_eng.png\n");
5046 osu_friendly_name = "kor:SP 초록 테스트 전용";
5047
5048 hs20_icon_filename = "icon_green_zxx.png";
5049 if (dut->ap_osu_icon_tag == 2)
5050 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5051 snprintf(hs20_icon, sizeof(hs20_icon),
5052 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
5053 hs20_icon_filename);
5054 osu_icon = "icon_green_zxx.png";
5055 break;
5056 case 8:
5057 case 108:
5058 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
5059 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
5060 osu_ssid = "OSU-Encrypted";
5061 osu_nai = "anonymous@hotspot.net";
5062 break;
5063 case 9:
5064 case 109:
5065 osu_ssid = "OSU-OSEN";
5066 osu_nai = "test-anonymous@wi-fi.org";
5067 osu_friendly_name = "eng:SP Orange Test Only";
5068 hs20_icon_filename = "icon_orange_zxx.png";
5069 if (dut->ap_osu_icon_tag == 2)
5070 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5071 snprintf(hs20_icon, sizeof(hs20_icon),
5072 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
5073 hs20_icon_filename);
5074 osu_icon = "icon_orange_zxx.png";
5075 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
5076 osu_service_desc = NULL;
5077 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02005078 case 10:
5079 case 110:
5080 /* OSU Provider #1 */
5081 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
5082 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
5083 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
5084 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
5085 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
5086 1 : dut->ap_osu_method[0];
5087 fprintf(f, "osu_method_list=%d\n", osu_method);
5088 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
5089 switch (dut->ap_osu_provider_nai_list) {
5090 case 3:
5091 fprintf(f,
5092 "osu_nai2=test-anonymous@wi-fi.org\n");
5093 break;
5094 case 4:
5095 fprintf(f, "osu_nai2=random@hotspot.net\n");
5096 break;
5097 }
5098
5099 /* OSU Provider #2 */
5100 /* SP Red from defaults */
5101 if (strlen(dut->ap_osu_server_uri[1]))
5102 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
5103 else
5104 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
5105 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
5106 snprintf(hs20_icon, sizeof(hs20_icon),
5107 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
5108 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
5109 1 : dut->ap_osu_method[1];
5110 osu_service_desc = NULL;
5111 osu_nai = "anonymous@hotspot.net";
5112 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005113 default:
5114 break;
5115 }
5116
Jouni Malinen93a837f2018-11-01 17:09:22 +02005117 switch (dut->ap_osu_provider_nai_list) {
5118 case 1:
5119 osu_nai2 = "anonymous@hotspot.net";
5120 break;
5121 case 2:
5122 osu_nai2 = "test-anonymous@wi-fi.org";
5123 break;
5124 case 3:
5125 /* OSU Provider NAI #1 written above */
5126 /* OSU Provider NAI #2 */
5127 osu_nai2 = "anonymous@hotspot.net";
5128 break;
5129 case 4:
5130 /* OSU Provider NAI #1 written above */
5131 /* OSU Provider NAI #2 */
5132 osu_nai2 = "anonymous@hotspot.net";
5133 break;
5134 }
5135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005136 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03005137 if (dut->ap_tag_ssid[0][0] &&
5138 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005139 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005140 sigma_dut_print(dut, DUT_MSG_ERROR,
5141 "OSU_SSID and "
5142 "WLAN_TAG2 SSID differ");
5143 return -2;
5144 }
5145 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
5146 } else
5147 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
5148
5149
5150 if (osu_friendly_name)
5151 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
5152
5153 if (osu_service_desc)
5154 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
5155
5156 if (osu_nai)
5157 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02005158 if (osu_nai2)
5159 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005160
5161 fprintf(f, "hs20_icon=%s\n", hs20_icon);
5162
5163 if (osu_icon)
5164 fprintf(f, "osu_icon=%s\n", osu_icon);
5165
5166 if (dut->ap_osu_provider_list > 100)
5167 fprintf(f, "osu_method_list=0\n");
5168 else
5169 fprintf(f, "osu_method_list=%d\n", osu_method);
5170 }
5171
Jouni Malinen54a89b02018-05-01 00:16:26 +03005172 switch (dut->ap_venue_url) {
5173 case 1:
5174 fprintf(f,
5175 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5176 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
5177 break;
5178 case 2:
5179 fprintf(f,
5180 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5181 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5182 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5183 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5184 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5185 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5186 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5187 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5188 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5189 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5190 );
5191 break;
5192 }
5193
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03005194 switch (dut->ap_advice_of_charge) {
5195 case 1:
5196 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
5197 break;
5198 }
5199
Jouni Malinenac104532018-05-01 00:27:37 +03005200 switch (dut->ap_oper_icon_metadata) {
5201 case 1:
5202 fprintf(f,
5203 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
5204 "operator_icon=icon_red_eng.png\n");
5205 break;
5206 }
5207
Jouni Malinenac367142018-05-01 00:32:24 +03005208 switch (dut->ap_tnc_file_name) {
5209 case 1:
5210 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
5211 break;
5212 }
5213
5214 if (dut->ap_tnc_time_stamp)
5215 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
5216
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005217 return 0;
5218}
5219
5220
5221static void write_ap_roaming_cons(FILE *f, const char *list)
5222{
5223 char *buf, *pos, *end;
5224
5225 if (list == NULL || list[0] == '\0')
5226 return;
5227
5228 buf = strdup(list);
5229 if (buf == NULL)
5230 return;
5231
5232 pos = buf;
5233 while (pos && *pos) {
5234 end = strchr(pos, ';');
5235 if (end)
5236 *end++ = '\0';
5237 fprintf(f, "roaming_consortium=%s\n", pos);
5238 pos = end;
5239 }
5240
5241 free(buf);
5242}
5243
5244
5245static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
5246{
5247 int i;
5248 char buf[100], *temp;
5249
5250 if (dut->ap_gas_cb_delay > 0)
5251 fprintf(f, "gas_comeback_delay=%d\n",
5252 dut->ap_gas_cb_delay);
5253
5254 fprintf(f, "interworking=1\n"
5255 "access_network_type=%d\n"
5256 "internet=%d\n"
5257 "asra=0\n"
5258 "esr=0\n"
5259 "uesa=0\n"
5260 "venue_group=%d\n"
5261 "venue_type=%d\n",
5262 dut->ap_access_net_type,
5263 dut->ap_internet,
5264 dut->ap_venue_group,
5265 dut->ap_venue_type);
5266 if (dut->ap_hessid[0])
5267 fprintf(f, "hessid=%s\n", dut->ap_hessid);
5268
5269 write_ap_roaming_cons(f, dut->ap_roaming_cons);
5270
5271 if (dut->ap_venue_name) {
5272 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
5273 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
5274 }
5275
5276 if (dut->ap_net_auth_type == 1)
5277 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
5278 else if (dut->ap_net_auth_type == 2)
5279 fprintf(f, "network_auth_type=01\n");
5280
5281 if (dut->ap_nai_realm_list == 1) {
5282 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
5283 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5284 } else if (dut->ap_nai_realm_list == 2) {
5285 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5286 } else if (dut->ap_nai_realm_list == 3) {
5287 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
5288 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5289 } else if (dut->ap_nai_realm_list == 4) {
5290 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
5291 } else if (dut->ap_nai_realm_list == 5) {
5292 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
5293 } else if (dut->ap_nai_realm_list == 6) {
5294 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
5295 } else if (dut->ap_nai_realm_list == 7) {
5296 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
5297 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5298 }
5299
5300 if (dut->ap_domain_name_list[0]) {
5301 fprintf(f, "domain_name=%s\n",
5302 dut->ap_domain_name_list);
5303 }
5304
5305 if (dut->ap_ip_addr_type_avail == 1) {
5306 fprintf(f, "ipaddr_type_availability=0c\n");
5307 }
5308
5309 temp = buf;
5310 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
5311 i++) {
5312 if (i)
5313 *temp++ = ';';
5314
5315 snprintf(temp,
5316 sizeof(dut->ap_plmn_mcc[i]) +
5317 sizeof(dut->ap_plmn_mnc[i]) + 1,
5318 "%s,%s",
5319 dut->ap_plmn_mcc[i],
5320 dut->ap_plmn_mnc[i]);
5321
5322 temp += strlen(dut->ap_plmn_mcc[i]) +
5323 strlen(dut->ap_plmn_mnc[i]) + 1;
5324 }
5325 if (i)
5326 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
5327
5328 if (dut->ap_qos_map_set == 1)
5329 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
5330 else if (dut->ap_qos_map_set == 2)
5331 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
5332
5333 return 0;
5334}
5335
5336
5337static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
5338{
5339 FILE *f;
5340
5341 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
5342 system("killall hostapd") == 0) {
5343 int i;
5344
5345 /* Wait some time to allow hostapd to complete cleanup before
5346 * starting a new process */
5347 for (i = 0; i < 10; i++) {
5348 usleep(500000);
5349 if (system("pidof hostapd") != 0)
5350 break;
5351 }
5352 }
5353
5354 f = fopen("/tmp/secath0", "a");
5355 if (f == NULL)
5356 return -2;
5357
5358 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
5359 fclose(f);
5360 return -2;
5361 }
5362
5363 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
5364 fclose(f);
5365 return -2;
5366 }
5367
5368 fflush(f);
5369 fclose(f);
5370 return ath_ap_start_hostapd(dut);
5371}
5372
5373
5374static int ath_ap_start_hostapd(struct sigma_dut *dut)
5375{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005376 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005377 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
5378 else
5379 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
5380
5381 return 0;
5382}
5383
5384
5385#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
5386
5387static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
5388{
5389 FILE *f;
5390 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
5391 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
5392 char buf[100];
5393 int i;
5394
5395 f = fopen("/root/anqpserver.conf", "w");
5396 if (f == NULL)
5397 return -1;
5398
5399 if (dut->ap_nai_realm_list == 1) {
5400 nai_realm = 1;
5401 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");
5402 } else if (dut->ap_nai_realm_list == 2) {
5403 nai_realm = 1;
5404 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
5405 } else if (dut->ap_nai_realm_list == 3) {
5406 nai_realm = 1;
5407 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");
5408 } else if (dut->ap_nai_realm_list == 4) {
5409 nai_realm = 1;
5410 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");
5411 } else
5412 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
5413
5414 if (dut->ap_domain_name_list[0]) {
5415 char *next, *start, *dnbuf, *dn1, *anqp_dn;
5416 int len, dn_len_max;
5417 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305418 if (dnbuf == NULL) {
5419 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005420 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305421 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005422
5423 len = strlen(dnbuf);
5424 dn_len_max = 50 + len*2;
5425 anqp_dn = malloc(dn_len_max);
5426 if (anqp_dn == NULL) {
5427 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305428 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005429 return -1;
5430 }
5431 start = dnbuf;
5432 dn1 = anqp_dn;
5433 while (start && *start) {
5434 char *hexstr;
5435
5436 next = strchr(start, ',');
5437 if (next)
5438 *next++ = '\0';
5439
5440 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05305441 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005442 if (hexstr == NULL) {
5443 free(dnbuf);
5444 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305445 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005446 return -1;
5447 }
5448 ascii2hexstr(start, hexstr);
5449 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
5450 free(hexstr);
5451 dn1 += 2 + len * 2;
5452 dn_len_max -= 2 + len * 2;
5453 start = next;
5454 }
5455 free(dnbuf);
5456 if (dut->ap_gas_cb_delay) {
5457 fprintf(f, "dyn_domain_name=0c01%04x%s",
5458 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5459 domain_name = 1;
5460 } else
5461 fprintf(f, "domain_name=0c01%04x%s",
5462 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5463 free(anqp_dn);
5464 } else
5465 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
5466
5467 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
5468
5469 if (dut->ap_oper_name) {
5470 if (dut->ap_gas_cb_delay) {
5471 fprintf(f, "dyn_oper_friendly_name="
5472 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5473 oper_name = 1;
5474 } else
5475 fprintf(f, "oper_friendly_name="
5476 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5477 } else
5478 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
5479
5480 if (dut->ap_venue_name) {
5481 if (dut->ap_gas_cb_delay) {
5482 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
5483 venue_name = 1;
5484 } else
5485 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
5486 } else
5487 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
5488
5489 if (dut->ap_wan_metrics) {
5490 if (dut->ap_gas_cb_delay) {
5491 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
5492 wan_metrics = 1;
5493 } else
5494 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
5495 "\n");
5496 } else
5497 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
5498
5499 if (dut->ap_conn_capab) {
5500 if (dut->ap_gas_cb_delay) {
5501 fprintf(f, "dyn_conn_capability="
5502 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5503 conn_cap = 1;
5504 } else
5505 fprintf(f, "conn_capability="
5506 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5507 } else
5508 sigma_dut_print(dut, DUT_MSG_ERROR,
5509 "not setting conn_capability");
5510
5511 if (dut->ap_ip_addr_type_avail) {
5512 if (dut->ap_gas_cb_delay) {
5513 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
5514 "\n");
5515 ipaddr_avail = 1;
5516 } else
5517 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
5518 } else
5519 sigma_dut_print(dut, DUT_MSG_ERROR,
5520 "not setting ipaddr_type_avail");
5521
5522 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
5523 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
5524 dut->ap_plmn_mcc[i][1],
5525 dut->ap_plmn_mcc[i][0],
5526 dut->ap_plmn_mnc[i][2] == '\0' ?
5527 'f' : dut->ap_plmn_mnc[i][2],
5528 dut->ap_plmn_mcc[i][2],
5529 dut->ap_plmn_mnc[i][1],
5530 dut->ap_plmn_mnc[i][0]);
5531 }
5532 if (i) {
5533 uint16_t ie_len = (i * 3) + 5;
5534 if (dut->ap_gas_cb_delay) {
5535 fprintf(f, "dyn_cell_net=0801");
5536 cell_net = 1;
5537 } else
5538 fprintf(f, "cell_net=0801");
5539 fprintf(f, "%04x", LE16(ie_len));
5540 fprintf(f, "00"); /* version */
5541 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
5542 fprintf(f, "00"); /* plmn list */
5543 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
5544 fprintf(f, "%02x", i); /* number of plmns */
5545 fprintf(f, "%s\n", buf); /* plmns */
5546 } else
5547 sigma_dut_print(dut, DUT_MSG_ERROR,
5548 "not setting 3gpp_cellular_network");
5549
5550 if (nai_realm || domain_name || oper_name || venue_name ||
5551 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
5552 fprintf(f, "anqp_attach=");
5553 if (venue_name)
5554 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
5555 if (nai_realm)
5556 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
5557 if (cell_net)
5558 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
5559 if (domain_name)
5560 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
5561 if (oper_name)
5562 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
5563 if (wan_metrics)
5564 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
5565 if (conn_cap)
5566 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
5567 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
5568 fprintf(f, "\n");
5569 }
5570
5571 fclose(f);
5572
5573 run_system(dut, "anqpserver -i ath0 &");
5574 if (!dut->ap_anqpserver_on)
5575 run_system(dut, "killall anqpserver");
5576
5577 return 1;
5578}
5579
5580
5581static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
5582{
5583 char buf[100];
5584
5585 run_system(dut, "cfg -a AP_STARTMODE=standard");
5586
5587 if (sigma_radio_ifname[0] &&
5588 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
5589 run_system(dut, "cfg -a AP_RADIO_ID=1");
5590 switch (dut->ap_mode) {
5591 case AP_11g:
5592 run_system(dut, "cfg -a AP_CHMODE_2=11G");
5593 break;
5594 case AP_11b:
5595 run_system(dut, "cfg -a AP_CHMODE_2=11B");
5596 break;
5597 case AP_11ng:
5598 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
5599 break;
5600 case AP_11a:
5601 run_system(dut, "cfg -a AP_CHMODE_2=11A");
5602 break;
5603 case AP_11na:
5604 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
5605 break;
5606 case AP_11ac:
5607 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5608 break;
5609 default:
5610 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5611 break;
5612 }
5613
5614 switch (dut->ap_rx_streams) {
5615 case 1:
5616 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5617 break;
5618 case 2:
5619 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5620 break;
5621 case 3:
5622 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5623 break;
5624 }
5625
5626 switch (dut->ap_tx_streams) {
5627 case 1:
5628 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5629 break;
5630 case 2:
5631 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5632 break;
5633 case 3:
5634 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5635 break;
5636 }
5637
5638 switch (dut->ap_chwidth) {
5639 case AP_20:
5640 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5641 break;
5642 case AP_40:
5643 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5644 break;
5645 case AP_80:
5646 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5647 break;
5648 case AP_160:
5649 case AP_AUTO:
5650 default:
5651 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5652 break;
5653 }
5654
5655 if (dut->ap_tx_stbc) {
5656 run_system(dut, "cfg -a TX_STBC_2=1");
5657 }
5658
5659 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5660 dut->ap_channel);
5661
5662 if (dut->ap_is_dual) {
5663 switch (dut->ap_mode_1) {
5664 case AP_11g:
5665 run_system(dut, "cfg -a AP_CHMODE=11G");
5666 break;
5667 case AP_11b:
5668 run_system(dut, "cfg -a AP_CHMODE=11B");
5669 break;
5670 case AP_11ng:
5671 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5672 break;
5673 case AP_11a:
5674 run_system(dut, "cfg -a AP_CHMODE=11A");
5675 break;
5676 case AP_11na:
5677 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5678 break;
5679 case AP_11ac:
5680 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5681 break;
5682 default:
5683 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5684 break;
5685 }
5686 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5687 dut->ap_channel_1);
5688 }
5689 run_system(dut, buf);
5690 } else {
5691 run_system(dut, "cfg -a AP_RADIO_ID=0");
5692 switch (dut->ap_mode) {
5693 case AP_11g:
5694 run_system(dut, "cfg -a AP_CHMODE=11G");
5695 break;
5696 case AP_11b:
5697 run_system(dut, "cfg -a AP_CHMODE=11B");
5698 break;
5699 case AP_11ng:
5700 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5701 break;
5702 case AP_11a:
5703 run_system(dut, "cfg -a AP_CHMODE=11A");
5704 break;
5705 case AP_11na:
5706 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5707 break;
5708 case AP_11ac:
5709 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5710 break;
5711 default:
5712 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5713 break;
5714 }
5715 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5716 dut->ap_channel);
5717 run_system(dut, buf);
5718 }
5719
5720 if (dut->ap_sgi80 == 1) {
5721 run_system(dut, "cfg -a SHORTGI=1");
5722 run_system(dut, "cfg -a SHORTGI_2=1");
5723 } else if (dut->ap_sgi80 == 0) {
5724 run_system(dut, "cfg -a SHORTGI=0");
5725 run_system(dut, "cfg -a SHORTGI_2=0");
5726 }
5727
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005728 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005729 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005730 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005731 run_system(dut, "cfg -a LDPC=0");
5732}
5733
5734
5735void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5736{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005737 run_iwpriv(dut, intf, "vhtsubfee 0");
5738 run_iwpriv(dut, intf, "vhtsubfer 0");
5739 run_iwpriv(dut, intf, "vhtmubfee 0");
5740 run_iwpriv(dut, intf, "vhtmubfer 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005741}
5742
5743
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005744static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5745 const char *val)
5746{
5747 if (strcasecmp(val, "enable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005748 run_iwpriv(dut, ifname, "mbo_asoc_dis 1");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005749 } else if (strcasecmp(val, "disable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005750 run_iwpriv(dut, ifname, "mbo_asoc_dis 0");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005751 } else {
5752 sigma_dut_print(dut, DUT_MSG_ERROR,
5753 "Unsupported assoc_disallow");
5754 }
5755}
5756
5757
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005758static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5759{
5760 int i;
5761 int least_pref = 1 << 8;
5762 char ifname[20];
5763 uint8_t self_mac[ETH_ALEN];
5764 char buf[200];
5765 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5766
5767 get_if_name(dut, ifname, sizeof(ifname), 1);
5768 get_hwaddr(ifname, self_mac);
5769
5770 /* Clear off */
5771 snprintf(buf, sizeof(buf),
5772 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5773 ifname);
5774 run_system(dut, buf);
5775
5776 /* Find the least preference number */
5777 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5778 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5779
5780 ap_ne_class = 1;
5781 ap_ne_pref = 255;
5782 ap_ne_op_ch = 1;
5783 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5784 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5785 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5786 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5787 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5788 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5789
5790 if (ap_ne_pref < least_pref)
5791 least_pref = ap_ne_pref;
5792 snprintf(buf, sizeof(buf),
5793 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5794 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5795 mac_addr[3], mac_addr[4], mac_addr[5],
5796 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5797 run_system(dut, buf);
5798 }
5799
5800 /* Now add the self AP Address */
5801 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5802 if (dut->ap_channel <= 11)
5803 ap_ne_class = 81;
5804 else
5805 ap_ne_class = 115;
5806 } else {
5807 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5808 }
5809
5810 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5811 ap_ne_op_ch = dut->ap_channel;
5812 else
5813 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5814
5815 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5816 ap_ne_pref = least_pref - 1;
5817 else
5818 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5819
5820 snprintf(buf, sizeof(buf),
5821 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5822 ifname, self_mac[0], self_mac[1], self_mac[2],
5823 self_mac[3], self_mac[4], self_mac[5],
5824 ap_ne_pref,
5825 ap_ne_class,
5826 ap_ne_op_ch);
5827 run_system(dut, buf);
5828}
5829
5830
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -07005831static void mubrp_commands(struct sigma_dut *dut, const char *ifname)
5832{
5833 run_iwpriv(dut, ifname, "he_subfer 1");
5834 run_iwpriv(dut, ifname, "he_mubfer 1");
5835 /* To enable MU_AX with MU_BRP trigger */
5836 run_iwpriv(dut, ifname, "he_sounding_mode 13");
5837 /* Sets g_force_1x1_peer to 1 which should be reset to zero for non MU
5838 * test cases */
5839 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 118 1",
5840 ifname);
5841 /* Disable DL OFDMA */
5842 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 11 0",
5843 ifname);
5844}
5845
5846
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005847static void ath_ap_set_params(struct sigma_dut *dut)
5848{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005849 const char *basedev = "wifi0";
5850 const char *basedev_radio = "wifi1";
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005851 const char *ifname = get_main_ifname(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005852 char *ifname_dual = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005853 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005854 char buf[300];
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08005855 unsigned int he_mcsnssmap = dut->he_mcsnssmap;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005856
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005857 if (sigma_radio_ifname[0])
5858 basedev = sigma_radio_ifname[0];
5859
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005860 if (dut->ap_is_dual == 1) {
5861 basedev = sigma_radio_ifname[0];
5862 basedev_radio = sigma_radio_ifname[1];
5863 if (sigma_radio_ifname[0] &&
5864 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5865 ifname = "ath0";
5866 ifname_dual = "ath1";
5867 } else {
5868 ifname = "ath1";
5869 ifname_dual = "ath0";
5870 }
5871 }
5872
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005873 if (dut->ap_countrycode[0]) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005874 run_iwpriv(dut, basedev, "setCountry %s", dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005875 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5876 }
5877
5878 for (i = 0; i < NUM_AP_AC; i++) {
5879 if (dut->ap_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005880 run_iwpriv(dut, ifname, "cwmin %d 0 %d", i,
5881 dut->ap_qos[i].cwmin);
5882 run_iwpriv(dut, ifname, "cwmax %d 0 %d", i,
5883 dut->ap_qos[i].cwmax);
5884 run_iwpriv(dut, ifname, "aifs %d 0 %d", i,
5885 dut->ap_qos[i].aifs);
5886 run_iwpriv(dut, ifname, "txoplimit %d 0 %d", i,
5887 dut->ap_qos[i].txop);
5888 run_iwpriv(dut, ifname, "acm %d 0 %d", i,
5889 dut->ap_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005890 }
5891 }
5892
5893 for (i = 0; i < NUM_AP_AC; i++) {
5894 if (dut->ap_sta_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005895 run_iwpriv(dut, ifname, "cwmin %d 1 %d", i,
5896 dut->ap_sta_qos[i].cwmin);
5897 run_iwpriv(dut, ifname, "cwmax %d 1 %d", i,
5898 dut->ap_sta_qos[i].cwmax);
5899 run_iwpriv(dut, ifname, "aifs %d 1 %d", i,
5900 dut->ap_sta_qos[i].aifs);
5901 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", i,
5902 dut->ap_sta_qos[i].txop);
5903 run_iwpriv(dut, ifname, "acm %d 1 %d", i,
5904 dut->ap_sta_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005905 }
5906 }
5907
5908 if (dut->ap_disable_protection == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005909 run_iwpriv(dut, ifname, "enablertscts 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5911 }
5912
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005913 if (dut->ap_ldpc == VALUE_ENABLED)
5914 run_iwpriv(dut, ifname, "ldpc 3");
5915 else if (dut->ap_ldpc == VALUE_DISABLED)
5916 run_iwpriv(dut, ifname, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005917
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005918 if (dut->ap_ampdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005919 run_iwpriv(dut, ifname, "ampdu 1");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005920 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005921 run_iwpriv(dut, ifname, "ampdu 0");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005922 if (dut->program == PROGRAM_HE) {
5923 run_iwpriv(dut, ifname, "setaddbaoper 1");
5924 run_system_wrapper(dut, "wifitool %s refusealladdbas 1",
5925 ifname);
5926 if (dut->ap_amsdu == VALUE_ENABLED) {
5927 /* disable the limit for A-MSDU */
5928 run_system_wrapper(dut,
5929 "wifitool %s setUnitTestCmd 0x48 2 46 1",
5930 ifname);
5931 }
5932 }
5933 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005934
5935 if (dut->ap_ampdu_exp) {
5936 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005937 run_iwpriv(dut, ifname, "vhtmaxampdu %d",
5938 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005939 } else {
5940 /* 11N */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005941 run_iwpriv(dut, ifname, "maxampdu %d",
5942 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 }
5944 }
5945
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005946 if (dut->ap_noack == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005947 run_iwpriv(dut, ifname, "noackpolicy 0 0 1");
5948 run_iwpriv(dut, ifname, "noackpolicy 1 0 1");
5949 run_iwpriv(dut, ifname, "noackpolicy 2 0 1");
5950 run_iwpriv(dut, ifname, "noackpolicy 3 0 1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005951 } else if (dut->ap_noack == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005952 run_iwpriv(dut, ifname, "noackpolicy 0 0 0");
5953 run_iwpriv(dut, ifname, "noackpolicy 1 0 0");
5954 run_iwpriv(dut, ifname, "noackpolicy 2 0 0");
5955 run_iwpriv(dut, ifname, "noackpolicy 3 0 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005956 }
5957
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005958 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map)
5959 run_iwpriv(dut, ifname, "vht_mcsmap 0x%04x",
5960 dut->ap_vhtmcs_map);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005962 if (dut->ap_amsdu == VALUE_ENABLED)
5963 run_iwpriv(dut, ifname, "amsdu 2");
5964 else if (dut->ap_amsdu == VALUE_DISABLED)
5965 run_iwpriv(dut, ifname, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005966
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005967 if (dut->ap_rx_amsdu == VALUE_ENABLED)
5968 run_iwpriv(dut, basedev_radio, "rx_amsdu 1");
5969 else if (dut->ap_rx_amsdu == VALUE_DISABLED)
5970 run_iwpriv(dut, basedev_radio, "rx_amsdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005971
5972 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005973 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5974 dut->ap_ampdu == VALUE_DISABLED &&
5975 dut->ap_amsdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005976 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005977
5978 snprintf(buf, sizeof(buf),
5979 "wifitool %s senddelba 1 0 1 4", ifname);
5980 if (system(buf) != 0) {
5981 sigma_dut_print(dut, DUT_MSG_ERROR,
5982 "wifitool senddelba failed");
5983 }
5984
5985 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5986 ifname);
5987 if (system(buf) != 0) {
5988 sigma_dut_print(dut, DUT_MSG_ERROR,
5989 "wifitool sendsingleamsdu failed");
5990 }
5991
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005992 run_iwpriv(dut, ifname, "amsdu 10");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005993 }
5994
5995 if (dut->ap_mode == AP_11ac) {
5996 int chwidth, nss;
5997
5998 switch (dut->ap_chwidth) {
5999 case AP_20:
6000 chwidth = 0;
6001 break;
6002 case AP_40:
6003 chwidth = 1;
6004 break;
6005 case AP_80:
6006 chwidth = 2;
6007 break;
6008 case AP_160:
6009 chwidth = 3;
6010 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08006011 case AP_80_80:
6012 chwidth = 3;
6013 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006014 default:
6015 chwidth = 0;
6016 break;
6017 }
6018
6019 switch (dut->ap_tx_streams) {
6020 case 1:
6021 nss = 1;
6022 break;
6023 case 2:
6024 nss = 2;
6025 break;
6026 case 3:
6027 nss = 3;
6028 break;
6029 case 4:
6030 nss = 4;
6031 break;
6032 default:
6033 nss = 3;
6034 break;
6035 }
6036
6037 if (dut->ap_fixed_rate) {
6038 if (nss == 4)
6039 ath_disable_txbf(dut, ifname);
6040
6041 /* Set the nss */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006042 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006043
6044 /* Set the channel width */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006045 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046
6047 /* Set the VHT MCS */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006048 run_iwpriv(dut, ifname, "vhtmcs %d", dut->ap_mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006049 }
6050 }
6051
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006052 if (dut->ap_dyn_bw_sig == VALUE_ENABLED)
6053 run_iwpriv(dut, ifname, "cwmenable 1");
6054 else if (dut->ap_dyn_bw_sig == VALUE_DISABLED)
6055 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006056
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006057 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006058 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
6059 if (system(buf) != 0) {
6060 sigma_dut_print(dut, DUT_MSG_ERROR,
6061 "iwconfig rts 64 failed");
6062 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006063 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006064 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
6065 if (system(buf) != 0) {
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006067 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068 }
6069 }
6070
6071 if (dut->ap_hs2) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006072 run_iwpriv(dut, ifname, "qbssload 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
6074 }
6075
6076 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
6077 unsigned int bssload = 0;
6078
6079 if (dut->ap_bss_load == 1) {
6080 /* STA count: 1, CU: 50, AAC: 65535 */
6081 bssload = 0x0132ffff;
6082 } else if (dut->ap_bss_load == 2) {
6083 /* STA count: 1, CU: 200, AAC: 65535 */
6084 bssload = 0x01c8ffff;
6085 } else if (dut->ap_bss_load == 3) {
6086 /* STA count: 1, CU: 75, AAC: 65535 */
6087 bssload = 0x014bffff;
6088 }
6089
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006090 run_iwpriv(dut, ifname, "hcbssload %u", bssload);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006091 } else if (dut->ap_bss_load == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006092 run_iwpriv(dut, ifname, "qbssload 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
6094 }
6095
6096 if (dut->ap_dgaf_disable) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006097 run_iwpriv(dut, ifname, "dgaf_disable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006098 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
6099 }
6100
6101 if (dut->ap_l2tif) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006102 run_iwpriv(dut, ifname, "l2tif 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 snprintf(buf, sizeof(buf),
6104 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
6105 if (system(buf) != 0)
6106 sigma_dut_print(dut, DUT_MSG_ERROR,
6107 "l2tif br failed");
6108
6109 snprintf(buf, sizeof(buf),
6110 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
6111 if (system(buf) != 0)
6112 sigma_dut_print(dut, DUT_MSG_ERROR,
6113 "l2tif brif failed");
6114 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
6115 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08006116
6117 if (dut->ap_ndpa_frame == 0) {
6118 snprintf(buf, sizeof(buf),
6119 "wifitool %s beeliner_fw_test 117 192", ifname);
6120 if (system(buf) != 0) {
6121 sigma_dut_print(dut, DUT_MSG_ERROR,
6122 "wifitool beeliner_fw_test 117 192 failed");
6123 }
6124 snprintf(buf, sizeof(buf),
6125 "wifitool %s beeliner_fw_test 118 192", ifname);
6126 if (system(buf) != 0) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR,
6128 "wifitool beeliner_fw_test 117 192 failed");
6129 }
6130 } else if (dut->ap_ndpa_frame == 1) {
6131 /* Driver default - no changes needed */
6132 } else if (dut->ap_ndpa_frame == 2) {
6133 snprintf(buf, sizeof(buf),
6134 "wifitool %s beeliner_fw_test 115 1", ifname);
6135 if (system(buf) != 0) {
6136 sigma_dut_print(dut, DUT_MSG_ERROR,
6137 "wifitool beeliner_fw_test 117 192 failed");
6138 }
6139 snprintf(buf, sizeof(buf),
6140 "wifitool %s beeliner_fw_test 116 1", ifname);
6141 if (system(buf) != 0) {
6142 sigma_dut_print(dut, DUT_MSG_ERROR,
6143 "wifitool beeliner_fw_test 117 192 failed");
6144 }
6145 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006146
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006147 if (dut->ap_rtt == 1)
6148 run_iwpriv(dut, ifname, "enable_rtt 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006149
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006150 if (dut->ap_lci == 1)
6151 run_iwpriv(dut, ifname, "enable_lci 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006152
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006153 if (dut->ap_lcr == 1)
6154 run_iwpriv(dut, ifname, "enable_lcr 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006155
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006156 if (dut->ap_rrm == 1)
6157 run_iwpriv(dut, ifname, "enable_rmm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006158
6159 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
6160 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
6161 }
6162
6163 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
6164 FILE *f;
6165
6166 f = fopen("/tmp/nbr_report.txt", "w");
6167 if (!f) {
6168 sigma_dut_print(dut, DUT_MSG_ERROR,
6169 "Failed to open /tmp/nbr_report.txt");
6170 return;
6171 }
6172
6173 fprintf(f,
6174 "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",
6175 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6176 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6177 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6178 dut->ap_val_opchannel[0]);
6179 fclose(f);
6180
6181 f = fopen("/tmp/ftmrr.txt", "w");
6182 if (!f) {
6183 sigma_dut_print(dut, DUT_MSG_ERROR,
6184 "Failed to open /tmp/ftmrr.txt");
6185 return;
6186 }
6187
6188 fprintf(f,
6189 "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",
6190 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6191 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6192 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6193 dut->ap_val_opchannel[0]);
6194 fclose(f);
6195 }
6196
6197 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
6198 FILE *f;
6199
6200 f = fopen("/tmp/nbr_report.txt", "a");
6201 if (!f) {
6202 sigma_dut_print(dut, DUT_MSG_ERROR,
6203 "Failed to open /tmp/nbr_report.txt");
6204 return;
6205 }
6206 fprintf(f,
6207 "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",
6208 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6209 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6210 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6211 dut->ap_val_opchannel[1]);
6212 fclose(f);
6213
6214 f = fopen("/tmp/ftmrr.txt", "a");
6215 if (!f) {
6216 sigma_dut_print(dut, DUT_MSG_ERROR,
6217 "Failed to open /tmp/ftmrr.txt");
6218 return;
6219 }
6220 fprintf(f,
6221 "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",
6222 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6223 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6224 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6225 dut->ap_val_opchannel[1]);
6226 fclose(f);
6227 }
6228
6229 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
6230 FILE *f;
6231
6232 f = fopen("/tmp/nbr_report.txt", "a");
6233 if (!f) {
6234 sigma_dut_print(dut, DUT_MSG_ERROR,
6235 "Failed to open /tmp/nbr_report.txt");
6236 return;
6237 }
6238
6239 fprintf(f,
6240 "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",
6241 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6242 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6243 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6244 dut->ap_val_opchannel[2]);
6245 fclose(f);
6246
6247 f = fopen("/tmp/ftmrr.txt", "a");
6248 if (!f) {
6249 sigma_dut_print(dut, DUT_MSG_ERROR,
6250 "Failed to open /tmp/ftmrr.txt");
6251 return;
6252 }
6253
6254 fprintf(f,
6255 "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",
6256 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6257 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6258 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6259 dut->ap_val_opchannel[2]);
6260 fclose(f);
6261 }
6262
6263 if (dut->ap_neighap) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006264 run_iwpriv(dut, ifname, "enable_rtt 1");
6265 run_iwpriv(dut, ifname, "enable_lci 1");
6266 run_iwpriv(dut, ifname, "enable_lcr 1");
6267 run_iwpriv(dut, ifname, "enable_rrm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006268 }
6269
6270 if (dut->ap_scan == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006271 run_iwpriv(dut, ifname, "scanentryage 600");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006272 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
6273 run_system(dut, buf);
6274 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006275
6276 if (dut->ap_set_bssidpref) {
6277 snprintf(buf, sizeof(buf),
6278 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
6279 ifname);
6280 if (system(buf) != 0) {
6281 sigma_dut_print(dut, DUT_MSG_ERROR,
6282 "wifitool clear bssidpref failed");
6283 }
6284 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006285
6286 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
6287 int feature_enable;
6288
6289 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006290 run_iwpriv(dut, ifname, "wnm %d", feature_enable);
6291 run_iwpriv(dut, ifname, "wnm_bss %d", feature_enable);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006292 if (feature_enable) {
6293 const char *extra = "";
6294
6295 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
6296 if (dut->wnm_bss_max_protection ==
6297 VALUE_ENABLED)
6298 extra = " 1";
6299 else
6300 extra = " 0";
6301 }
6302 snprintf(buf, sizeof(buf),
6303 "wlanconfig %s wnm setbssmax %d%s",
6304 ifname, dut->wnm_bss_max_idle_time, extra);
6305 run_system(dut, buf);
6306 }
6307 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006308
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006309 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006310 apply_mbo_pref_ap_list(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006311 run_iwpriv(dut, ifname, "mbo_cel_pref %d",
6312 dut->ap_cell_cap_pref);
6313 run_iwpriv(dut, ifname, "mbocap 0x40");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006314 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006315 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006316
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006317 if (dut->ap_oce == VALUE_ENABLED)
6318 run_iwpriv(dut, ifname, "set_bpr_enable 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006319
6320 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006321 run_iwpriv(dut, ifname, "prb_rate 5500");
6322 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006323 }
6324
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006325 if (dut->ap_oce == VALUE_DISABLED)
6326 run_iwpriv(dut, ifname, "set_bpr_enable 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006327
6328 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006329 run_iwpriv(dut, ifname, "mgmt_rate 1000");
6330 run_iwpriv(dut, ifname, "set_bcn_rate 1000");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006331 }
6332
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006333 if (dut->ap_bcnint)
6334 run_iwpriv(dut, ifname, "bintval %d", dut->ap_bcnint);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006335
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006336 if (dut->ap_filsdscv == VALUE_DISABLED)
6337 run_iwpriv(dut, ifname, "enable_fils 0 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006338
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006339 if (dut->ap_filshlp == VALUE_ENABLED)
6340 run_iwpriv(dut, ifname, "oce_hlp 1");
6341 else if (dut->ap_filshlp == VALUE_DISABLED)
6342 run_iwpriv(dut, ifname, "oce_hlp 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006343
6344 /* When RNR is enabled, also enable apchannelreport, background scan */
6345 if (dut->ap_rnr == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006346 run_iwpriv(dut, ifname, "rnr 1");
6347 run_iwpriv(dut, ifname, "rnr_tbtt 1");
6348 run_iwpriv(dut, ifname, "apchanrpt 1");
6349 run_iwpriv(dut, basedev, "acs_ctrlflags 0x4");
6350 run_iwpriv(dut, basedev, "acs_scanintvl 60");
6351 run_iwpriv(dut, basedev, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006352 if (dut->ap_is_dual == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006353 run_iwpriv(dut, ifname_dual, "rnr 1");
6354 run_iwpriv(dut, ifname_dual, "rnr_tbtt 1");
6355 run_iwpriv(dut, ifname_dual, "apchanrpt 1");
6356 run_iwpriv(dut, basedev_radio, "acs_ctrlflags 0x4");
6357 run_iwpriv(dut, basedev_radio, "acs_scanintvl 60");
6358 run_iwpriv(dut, basedev_radio, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006359 }
6360 }
6361
6362 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006363 run_iwpriv(dut, ifname, "qbssload 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006364 snprintf(buf, sizeof(buf),
6365 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
6366 ifname, dut->ap_blestacnt & 0xFF,
6367 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6368 dut->ap_ble_admit_cap & 0xFF,
6369 dut->ap_ble_admit_cap >> 8);
6370 run_system(dut, buf);
6371 snprintf(buf, sizeof(buf),
6372 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
6373 ifname, dut->ap_blestacnt & 0xFF,
6374 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6375 dut->ap_ble_admit_cap & 0xFF,
6376 dut->ap_ble_admit_cap >> 8);
6377 run_system(dut, buf);
6378 }
6379
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006380 if (dut->ap_esp == VALUE_ENABLED)
6381 run_iwpriv(dut, basedev, "esp_period 5");
6382 else if (dut->ap_esp == VALUE_DISABLED)
6383 run_iwpriv(dut, basedev, "esp_period 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006384
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006385 if (dut->ap_datappdudura)
6386 run_iwpriv(dut, basedev, "esp_ppdu_dur %d",
6387 dut->ap_datappdudura);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006388
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006389 if (dut->ap_airtimefract)
6390 run_iwpriv(dut, basedev, "esp_airtime %d",
6391 dut->ap_airtimefract);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006392
6393 if (dut->ap_dhcp_stop) {
6394 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
6395 run_system(dut, buf);
6396 }
6397
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006398 if (dut->ap_bawinsize)
6399 run_iwpriv(dut, basedev, "esp_ba_window %d", dut->ap_bawinsize);
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006400
6401 if (dut->program == PROGRAM_DPP) {
6402 if (dut->ap_interface_2g == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006403 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
6404 run_iwpriv(dut, ifname, "prb_rate 5500");
6405 run_iwpriv(dut, ifname, "mgmt_rate 5500");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006406 }
6407
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006408 run_iwpriv(dut, basedev, "set_rxfilter 0xffffffff");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006409 dut->hostapd_running = 1;
6410 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006411
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006412 if (dut->program == PROGRAM_HE) {
6413 /* disable sending basic triggers */
6414 run_system_wrapper(dut,
6415 "wifitool %s setUnitTestCmd 0x47 2 42 0",
6416 ifname);
6417 /* disable MU BAR */
6418 run_system_wrapper(dut,
6419 "wifitool %s setUnitTestCmd 0x47 2 64 1",
6420 ifname);
6421 /* disable PSD Boost */
6422 run_system_wrapper(dut,
6423 "wifitool %s setUnitTestCmd 0x48 2 142 1",
6424 ifname);
6425 /* Enable mix bw */
6426 run_system_wrapper(dut,
6427 "wifitool %s setUnitTestCmd 0x47 2 141 1",
6428 ifname);
6429 /* Disable preferred AC */
6430 run_system_wrapper(dut,
6431 "wifitool %s setUnitTestCmd 0x48 2 186 0",
6432 ifname);
6433 run_iwpriv(dut, basedev, "he_muedca_mode 0");
6434 run_iwpriv(dut, ifname, "he_ul_ofdma 0");
6435 run_iwpriv(dut, ifname, "he_dl_ofdma 0");
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08006436 if (dut->he_set_sta_1x1 == VALUE_ENABLED) {
6437 /* sets g_force_1x1_peer to 1 */
6438 run_system_wrapper(dut,
6439 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6440 ifname);
6441 }
Priyadharshini Gowthamand8d5f582019-11-25 15:39:43 -08006442 if (dut->ap_txBF) {
6443 /* Enable SU_AX sounding */
6444 run_iwpriv(dut, ifname, "he_sounding_mode 1");
6445 /* Ignore TBTT for NDP */
6446 run_system_wrapper(dut,
6447 "wifitool %s setUnitTestCmd 0x48 2 2 1",
6448 ifname);
6449 /* g_cv_query_enable=1, i.e., cv query enable */
6450 run_system_wrapper(dut,
6451 "wifitool %s setUnitTestCmd 0x47 2 7 1",
6452 ifname);
6453 /* Override TPC calculations and set TxBF flag to True
6454 */
6455 run_system_wrapper(dut,
6456 "wifitool %s setUnitTestCmd 0x47 2 47 1",
6457 ifname);
6458 }
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006459 if (dut->device_type == AP_testbed) {
6460 run_iwpriv(dut, ifname, "tx_stbc 0");
6461 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6462 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6463 run_iwpriv(dut, ifname, "he_amsdu_in_ampdu_supp 0");
6464 run_iwpriv(dut, ifname, "he_bfee_sts_supp 0 0");
6465 run_iwpriv(dut, ifname, "he_4xltf_800nsgi_rx 0");
6466 run_iwpriv(dut, ifname, "he_1xltf_800nsgi_rx 0");
6467 run_iwpriv(dut, ifname, "he_max_nc 0");
6468 run_iwpriv(dut, ifname, "he_bsr_supp 0");
6469 run_iwpriv(dut, ifname, "rx_stbc 0");
6470 if (dut->ap_he_dlofdma == VALUE_DISABLED)
6471 run_iwpriv(dut, ifname, "he_dlofdma 0");
6472 if (dut->ap_channel <= 11) {
6473 dut->ap_bcc = VALUE_ENABLED;
6474 run_iwpriv(dut, ifname, "vht_11ng 0");
6475 }
6476 if (!dut->ap_txBF) {
6477 run_iwpriv(dut, ifname, "he_subfer 0");
6478 run_iwpriv(dut, ifname, "he_subfee 0");
6479 }
6480 if (!dut->ap_mu_txBF) {
6481 run_iwpriv(dut, ifname, "he_mubfer 0");
6482 run_iwpriv(dut, ifname, "he_mubfee 0");
6483 }
Priyadharshini Gowthamane9d0bfc2019-11-22 14:26:12 -08006484 if (dut->ap_cipher == AP_WEP ||
6485 dut->ap_cipher == AP_TKIP)
6486 run_iwpriv(dut, ifname, "htweptkip 1");
Priyadharshini Gowthaman2e0731b2019-11-25 15:38:58 -08006487 if (dut->ap_rx_streams || dut->ap_tx_streams)
6488 run_iwpriv(dut, ifname, "nss %d",
6489 dut->ap_rx_streams);
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006490 }
6491 }
6492
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006493 if (dut->ap_he_ulofdma == VALUE_ENABLED) {
6494 run_iwpriv(dut, ifname, "he_ul_ofdma 1");
6495 run_iwpriv(dut, ifname, "he_mu_edca 1");
6496
6497 /* Disable sounding for UL OFDMA */
6498 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006499 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006500
6501 if ((dut->ap_rx_streams || dut->ap_tx_streams) &&
6502 dut->device_type == AP_testbed) {
6503 unsigned int txchainmask = 0x00;
6504
6505 switch (dut->ap_rx_streams) {
6506 case 1:
6507 txchainmask = 0x01;
6508 break;
6509 case 2:
6510 txchainmask = 0x03;
6511 break;
6512 case 3:
6513 txchainmask = 0x07;
6514 break;
6515 case 4:
6516 txchainmask = 0x0f;
6517 break;
6518 case 5:
6519 txchainmask = 0x1f;
6520 break;
6521 case 6:
6522 txchainmask = 0x3f;
6523 break;
6524 case 7:
6525 txchainmask = 0x7f;
6526 break;
6527 case 8:
6528 txchainmask = 0xff;
6529 break;
6530 }
6531
6532 run_iwpriv(dut, ifname, "he_ul_nss %d",
6533 dut->ap_rx_streams);
6534 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6535 run_iwpriv(dut, basedev, "rxchainmask %d", txchainmask);
6536 }
6537
6538 if (dut->ap_channel == 100 && dut->device_type == AP_testbed)
6539 run_system_wrapper(dut, "iwpriv %s inact 1000", ifname);
6540
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006541 if (dut->he_ul_mcs)
6542 run_iwpriv(dut, ifname, "he_ul_mcs %d", dut->he_ul_mcs);
6543
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006544 run_iwpriv(dut, ifname, "he_ul_ltf 3");
6545 run_iwpriv(dut, ifname, "he_ul_shortgi 3");
6546 run_iwpriv(dut, basedev, "he_ul_trig_int 2");
6547
Priyadharshini Gowthamana17e6d82019-12-12 14:31:09 -08006548 /* Disable efficiency check for UL OFDMA. We do not send TBPPDU
6549 * for one user. With this command, we would send UL OFDMA even
6550 * for one user to allow testing to be done without requiring
6551 * more than one station. */
6552 run_system_wrapper(dut,
6553 "wifitool %s setUnitTestCmd 0x47 2 131 0",
6554 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006555 /* Set random RU allocation */
6556 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 9 1",
6557 ifname);
6558 /* To set TBTT PPDU duration (us) */
6559 run_system_wrapper(dut,
6560 "wifitool %s setUnitTestCmd 0x48 2 63 1908",
6561 ifname);
6562 }
6563
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006564 if (dut->ap_he_dlofdma == VALUE_ENABLED) {
6565 run_iwpriv(dut, ifname, "he_dl_ofdma 1", ifname);
6566
6567 /* For fixed MCS */
6568 novap_reset(dut, ifname, 0);
6569 run_iwpriv(dut, ifname,
6570 "cfg80211tool %s setratemask 3 0x80f80f80 0x0f80f80f 0xf80f80f8");
6571 }
6572
6573 if (dut->ap_he_ppdu == PPDU_MU && dut->ap_he_dlofdma == VALUE_ENABLED) {
6574 /* Increase the min TX time limit for MU MIMO to disable MU MIMO
6575 * scheduling */
6576 run_system_wrapper(dut,
6577 "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
6578 ifname);
6579 /* Increase the max TX time limit for DL OFDMA to enable OFDMA
6580 * scheduling */
6581 run_system_wrapper(dut,
6582 "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
6583 ifname);
6584 /* Disable 'force SU schedule' to enable MU sch */
6585 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 8 0",
6586 ifname);
6587 /* Enable MU 11ax support in sch algo */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006588 run_system_wrapper(dut,
6589 "wifitool %s setUnitTestCmd 0x47 2 29 0",
6590 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006591 /* Enable to sort RU allocation */
6592 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x4b 2 2 1",
6593 ifname);
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006594 }
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07006595
6596 if (dut->ap_numsounddim) {
6597 unsigned int txchainmask = 0;
6598
6599 switch (dut->ap_numsounddim) {
6600 case 1:
6601 txchainmask = 0x01;
6602 break;
6603 case 2:
6604 txchainmask = 0x03;
6605 break;
6606 case 3:
6607 txchainmask = 0x07;
6608 break;
6609 case 4:
6610 txchainmask = 0x0f;
6611 break;
6612 case 5:
6613 txchainmask = 0x1f;
6614 break;
6615 case 6:
6616 txchainmask = 0x3f;
6617 break;
6618 case 7:
6619 txchainmask = 0x7f;
6620 break;
6621 case 8:
6622 txchainmask = 0xff;
6623 break;
6624 }
6625 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6626 }
6627
6628 if (dut->ap_numsounddim && dut->device_type == AP_testbed) {
6629 /* Sets g_force_1x1_peer to 1 which should be reset to zero
6630 * for non-MU test cases */
6631 run_system_wrapper(dut,
6632 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6633 ifname);
6634 if (dut->ap_mu_txBF) {
6635 /* Disable DL OFDMA */
6636 run_system_wrapper(dut,
6637 "wifitool %s setUnitTestCmd 0x47 2 11 0",
6638 ifname);
6639 }
6640 }
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006641
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006642 if (dut->ap_bcc == VALUE_ENABLED) {
6643 run_iwpriv(dut, ifname, "mode 11AHE20");
6644 run_iwpriv(dut, ifname, "nss 2");
6645 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6646 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6647 }
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07006648
6649 if (dut->ap_he_frag == VALUE_ENABLED)
6650 run_iwpriv(dut, ifname, "he_frag 1");
6651 else if (dut->ap_he_frag == VALUE_DISABLED)
6652 run_iwpriv(dut, ifname, "he_frag 0");
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07006653
6654 if (dut->ap_ba_bufsize != BA_BUFSIZE_NOT_SET) {
6655 if (dut->ap_ba_bufsize == BA_BUFSIZE_64)
6656 run_iwpriv(dut, ifname, "ba_bufsize 0");
6657 else
6658 run_iwpriv(dut, ifname, "ba_bufsize 1");
6659 }
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07006660
6661 if (dut->ap_mu_edca == VALUE_ENABLED)
6662 run_iwpriv(dut, ifname, "he_mu_edca 1");
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07006663
6664 if (dut->ap_he_mimo == MIMO_DL) {
6665 mubrp_commands(dut, ifname);
6666 if (dut->device_type != AP_testbed)
6667 run_system_wrapper(
6668 dut, "wifitool %s setUnitTestCmd 0x48 2 100 2",
6669 ifname);
6670 }
6671
6672 if (dut->ap_he_mimo == MIMO_UL)
6673 run_iwpriv(dut, ifname, "he_mubfee 1");
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07006674
6675 if (dut->ap_he_rtsthrshld == VALUE_ENABLED)
6676 run_iwpriv(dut, ifname, "he_rtsthrshld 512");
6677 else if (dut->ap_he_rtsthrshld == VALUE_DISABLED)
6678 run_iwpriv(dut, ifname, "he_rtsthrshld 1024");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07006679
6680 if (dut->ap_mbssid == VALUE_ENABLED &&
6681 (dut->ap_rx_streams || dut->ap_tx_streams) &&
6682 dut->device_type == AP_testbed) {
6683 const char *ifname_1;
6684
6685 ifname_1= dut->ap_channel >= 36 ? "ath01" : "ath11";
6686
6687 /* NSS is not set in Secondary VAP for MBSSID case,
6688 * hence it is explicitly set here. For primary VAP
6689 * NSS is set during AP configuration */
6690 run_iwpriv(dut, ifname_1, "nss %d", dut->ap_rx_streams);
6691 }
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07006692
6693 if (dut->ap_twtresp == VALUE_ENABLED)
6694 run_iwpriv(dut, ifname, "twt_responder 1");
6695 else if (dut->ap_twtresp == VALUE_DISABLED)
6696 run_iwpriv(dut, ifname, "twt_responder 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006697
6698 if (dut->program == PROGRAM_HE && dut->ap_fixed_rate) {
6699 int nss = 0, mcs = 0;
6700 uint16_t mcsnssmap = 0;
6701
6702 /* MCS 7 is used - set only nss and he_mcs.
6703 * Do not set mcsnssmap unless MCS is 9 or 11. */
6704 if (dut->ap_mcs >= 9) {
6705 if (dut->ap_mcs == 9) {
6706 if (dut->ap_tx_streams == 1) {
6707 nss = 1;
6708 mcs = dut->ap_mcs;
6709 } else if (dut->ap_tx_streams == 2) {
6710 nss = 2;
6711 mcs = dut->ap_mcs;
6712 }
6713 } else if (dut->ap_mcs == 11) {
6714 if (dut->ap_tx_streams == 1) {
6715 nss = 1;
6716 mcs = dut->ap_mcs;
6717 } else if (dut->ap_tx_streams == 2) {
6718 nss = 2;
6719 mcs = dut->ap_mcs;
6720 }
6721 }
6722
6723 get_he_mcs_nssmap((uint8_t *) &mcsnssmap, nss, mcs);
6724 he_mcsnssmap = (mcsnssmap << 16) | mcsnssmap;
6725 }
6726
6727 run_iwpriv(dut, ifname, "nss %d", dut->ap_tx_streams);
6728 run_iwpriv(dut, ifname, "he_mcs %d", dut->ap_mcs);
6729 }
6730
6731 if (he_mcsnssmap) {
6732 run_iwpriv(dut, ifname, "he_rxmcsmap %lu", he_mcsnssmap);
6733 run_iwpriv(dut, ifname, "he_txmcsmap %lu", he_mcsnssmap);
6734 }
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08006735
6736 if (dut->he_sounding == VALUE_ENABLED)
6737 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
6738 ifname);
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08006739
6740 if (dut->he_mmss)
6741 run_iwpriv(dut, ifname, "ampduden_ovrd %d", dut->he_mmss);
Priyadharshini Gowthaman88d55c82019-12-12 14:31:46 -08006742
6743 if (dut->he_srctrl_allow == 0) {
6744 /* This is a special testbed AP case to enable SR for protocol
6745 * testing when SRCtrl_SRValue15Allowed is specified.
6746 */
6747 run_iwpriv(dut, ifname, "he_sr_enable 1");
6748 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006749}
6750
6751
6752static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
6753 struct sigma_conn *conn,
6754 struct sigma_cmd *cmd)
6755{
6756 /* const char *name = get_param(cmd, "NAME"); */
6757 char buf[100];
6758 struct stat s;
6759 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
Jouni Malinen3aa72862019-05-29 23:14:51 +03006760 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006761
6762 if (stat("/proc/athversion", &s) == 0) {
6763 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
6764 run_system(dut, "apdown");
6765 }
6766
6767 cmd_ath_ap_radio_config(dut);
6768
6769 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
6770 run_system(dut, buf);
6771
6772 switch (dut->ap_key_mgmt) {
6773 case AP_OPEN:
6774 if (dut->ap_cipher == AP_WEP) {
6775 run_system(dut, "cfg -a AP_SECMODE=WEP");
6776 run_system(dut, "cfg -a AP_SECFILE=NONE");
6777 /* shared auth mode not supported */
6778 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6779 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6780 snprintf(buf, sizeof(buf),
6781 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6782 dut->ap_wepkey);
6783 run_system(dut, buf);
6784 snprintf(buf, sizeof(buf),
6785 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6786 dut->ap_wepkey);
6787 run_system(dut, buf);
6788 } else {
6789 run_system(dut, "cfg -a AP_SECMODE=None");
6790 }
6791 break;
6792 case AP_WPA2_PSK:
6793 case AP_WPA2_PSK_MIXED:
6794 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006795 case AP_WPA2_SAE:
6796 case AP_WPA2_PSK_SAE:
6797 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6798 dut->ap_key_mgmt == AP_WPA2_SAE ||
6799 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 run_system(dut, "cfg -a AP_WPA=2");
6801 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6802 run_system(dut, "cfg -a AP_WPA=3");
6803 else
6804 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03006805 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806 run_system(dut, "cfg -a AP_SECMODE=WPA");
6807 run_system(dut, "cfg -a AP_SECFILE=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006808 res = snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
6809 dut->ap_passphrase);
6810 if (res < 0 || res >= sizeof(buf))
6811 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812 run_system(dut, buf);
6813 if (dut->ap_cipher == AP_CCMP_TKIP)
6814 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6815 else if (dut->ap_cipher == AP_TKIP)
6816 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6817 else
6818 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6819 break;
6820 case AP_WPA2_EAP:
6821 case AP_WPA2_EAP_MIXED:
6822 case AP_WPA_EAP:
6823 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6824 run_system(dut, "cfg -a AP_WPA=2");
6825 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6826 run_system(dut, "cfg -a AP_WPA=3");
6827 else
6828 run_system(dut, "cfg -a AP_WPA=1");
6829 run_system(dut, "cfg -a AP_SECMODE=WPA");
6830 run_system(dut, "cfg -a AP_SECFILE=EAP");
6831 if (dut->ap_cipher == AP_CCMP_TKIP)
6832 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6833 else if (dut->ap_cipher == AP_TKIP)
6834 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6835 else
6836 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6837 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6838 dut->ap_radius_ipaddr);
6839 run_system(dut, buf);
6840 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6841 dut->ap_radius_port);
6842 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006843 res = snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6844 dut->ap_radius_password);
6845 if (res < 0 || res >= sizeof(buf))
6846 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006847 run_system(dut, buf);
6848 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006849 case AP_WPA2_EAP_OSEN:
6850 /* TODO */
6851 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6852 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006853 case AP_SUITEB:
6854 /* TODO */
6855 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6856 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006857 case AP_WPA2_OWE:
6858 /* TODO */
6859 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6860 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006861 case AP_WPA2_FT_EAP:
6862 case AP_WPA2_FT_PSK:
6863 case AP_WPA2_EAP_SHA256:
6864 case AP_WPA2_PSK_SHA256:
6865 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006866 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006867 /* TODO */
6868 send_resp(dut, conn, SIGMA_ERROR,
6869 "errorCode,Unsupported KeyMgnt value");
6870 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006871 }
6872
6873 if (dut->ap_is_dual) {
6874 /* ath1 settings in case of dual */
6875 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6876 dut->ap_ssid);
6877 run_system(dut, buf);
6878
6879 switch (dut->ap_key_mgmt) {
6880 case AP_OPEN:
6881 if (dut->ap_cipher == AP_WEP) {
6882 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6883 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6884 /* shared auth mode not supported */
6885 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6886 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6887 snprintf(buf, sizeof(buf),
6888 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6889 dut->ap_wepkey);
6890 run_system(dut, buf);
6891 snprintf(buf, sizeof(buf),
6892 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6893 dut->ap_wepkey);
6894 run_system(dut, buf);
6895 } else {
6896 run_system(dut, "cfg -a AP_SECMODE_2=None");
6897 }
6898 break;
6899 case AP_WPA2_PSK:
6900 case AP_WPA2_PSK_MIXED:
6901 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006902 case AP_WPA2_SAE:
6903 case AP_WPA2_PSK_SAE:
6904 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6905 dut->ap_key_mgmt == AP_WPA2_SAE ||
6906 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006907 run_system(dut, "cfg -a AP_WPA_2=2");
6908 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6909 run_system(dut, "cfg -a AP_WPA_2=3");
6910 else
6911 run_system(dut, "cfg -a AP_WPA_2=1");
6912 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006913 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006914 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6915 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006916 res = snprintf(buf, sizeof(buf),
6917 "cfg -a 'PSK_KEY_2=%s'",
6918 dut->ap_passphrase);
6919 if (res < 0 || res >= sizeof(buf))
6920 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006921 run_system(dut, buf);
6922 if (dut->ap_cipher == AP_CCMP_TKIP)
6923 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6924 else if (dut->ap_cipher == AP_TKIP)
6925 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6926 else
6927 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6928 break;
6929 case AP_WPA2_EAP:
6930 case AP_WPA2_EAP_MIXED:
6931 case AP_WPA_EAP:
6932 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6933 run_system(dut, "cfg -a AP_WPA_2=2");
6934 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6935 run_system(dut, "cfg -a AP_WPA_2=3");
6936 else
6937 run_system(dut, "cfg -a AP_WPA_2=1");
6938 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6939 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6940 if (dut->ap_cipher == AP_CCMP_TKIP)
6941 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6942 else if (dut->ap_cipher == AP_TKIP)
6943 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6944 else
6945 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6946
6947 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6948 dut->ap_radius_ipaddr);
6949 run_system(dut, buf);
6950 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6951 dut->ap_radius_port);
6952 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006953 res = snprintf(buf, sizeof(buf),
6954 "cfg -a AP_AUTH_SECRET_2=%s",
6955 dut->ap_radius_password);
6956 if (res < 0 || res >= sizeof(buf))
6957 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006958 run_system(dut, buf);
6959 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006960 case AP_WPA2_EAP_OSEN:
6961 /* TODO */
6962 sigma_dut_print(dut, DUT_MSG_ERROR,
6963 "EAP+OSEN not supported");
6964 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006965 case AP_SUITEB:
6966 /* TODO */
6967 sigma_dut_print(dut, DUT_MSG_ERROR,
6968 "SuiteB not supported");
6969 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006970 case AP_WPA2_OWE:
6971 /* TODO */
6972 sigma_dut_print(dut, DUT_MSG_ERROR,
6973 "OWE not supported");
6974 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006975 case AP_WPA2_FT_EAP:
6976 case AP_WPA2_FT_PSK:
6977 case AP_WPA2_EAP_SHA256:
6978 case AP_WPA2_PSK_SHA256:
6979 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006980 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006981 /* TODO */
6982 send_resp(dut, conn, SIGMA_ERROR,
6983 "errorCode,Unsupported KeyMgnt value");
6984 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006985 }
6986
6987 /* wifi0 settings in case of dual */
6988 run_system(dut, "cfg -a AP_RADIO_ID=0");
6989 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6990 run_system(dut, "cfg -a AP_STARTMODE=dual");
6991 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6992 run_system(dut, "cfg -a TX_CHAINMASK=7");
6993 run_system(dut, "cfg -a RX_CHAINMASK=7");
6994 }
6995
6996 switch (dut->ap_pmf) {
6997 case AP_PMF_DISABLED:
6998 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6999 run_system(dut, buf);
7000 break;
7001 case AP_PMF_OPTIONAL:
7002 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
7003 run_system(dut, buf);
7004 break;
7005 case AP_PMF_REQUIRED:
7006 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
7007 run_system(dut, buf);
7008 break;
7009 }
7010 if (dut->ap_add_sha256) {
7011 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
7012 run_system(dut, buf);
7013 } else {
7014 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
7015 run_system(dut, buf);
7016 }
7017
7018 if (dut->ap_hs2)
7019 run_system(dut, "cfg -a AP_HOTSPOT=1");
7020 else
7021 run_system(dut, "cfg -r AP_HOTSPOT");
7022
7023 if (dut->ap_interworking) {
7024 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
7025 dut->ap_access_net_type);
7026 run_system(dut, buf);
7027 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
7028 dut->ap_internet);
7029 run_system(dut, buf);
7030 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
7031 dut->ap_venue_group);
7032 run_system(dut, buf);
7033 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
7034 dut->ap_venue_type);
7035 run_system(dut, buf);
7036 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
7037 dut->ap_hessid);
7038 run_system(dut, buf);
7039
7040 if (dut->ap_roaming_cons[0]) {
7041 char *second, *rc;
7042 rc = strdup(dut->ap_roaming_cons);
7043 if (rc == NULL)
7044 return 0;
7045
7046 second = strchr(rc, ';');
7047 if (second)
7048 *second++ = '\0';
7049
7050 snprintf(buf, sizeof(buf),
7051 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
7052 run_system(dut, buf);
7053
7054 if (second) {
7055 snprintf(buf, sizeof(buf),
7056 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
7057 "=%s", second);
7058 run_system(dut, buf);
7059 }
7060 free(rc);
7061 } else {
7062 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
7063 run_system(dut,
7064 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
7065 }
7066 } else {
7067 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
7068 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
7069 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
7070 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
7071 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
7072 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
7073 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
7074 }
7075
7076 if (dut->ap_proxy_arp)
7077 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
7078 else
7079 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
7080 if (dut->ap_dgaf_disable)
7081 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
7082 else
7083 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
7084
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007085 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007086 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007087 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007088 run_system(dut, buf);
7089
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007090 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007091 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
7092 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
7093
Jouni Malinen3aa72862019-05-29 23:14:51 +03007094 res = snprintf(buf, sizeof(buf),
7095 "cfg -a AP_AUTH_SERVER_2=%s",
7096 dut->ap2_radius_ipaddr);
7097 if (res < 0 || res >= sizeof(buf))
7098 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 run_system(dut, buf);
7100
Jouni Malinen3aa72862019-05-29 23:14:51 +03007101 res = snprintf(buf, sizeof(buf),
7102 "cfg -a AP_AUTH_PORT_2=%d",
7103 dut->ap2_radius_port);
7104 if (res < 0 || res >= sizeof(buf))
7105 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007106 run_system(dut, buf);
7107
Jouni Malinen3aa72862019-05-29 23:14:51 +03007108 res = snprintf(buf, sizeof(buf),
7109 "cfg -a AP_AUTH_SECRET_2=%s",
7110 dut->ap2_radius_password);
7111 if (res < 0 || res >= sizeof(buf))
7112 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007113 run_system(dut, buf);
7114 } else {
7115 run_system(dut, "cfg -a AP_SECMODE_2=None");
7116 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
7117 run_system(dut, "cfg -r AP_AUTH_PORT_2");
7118 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
7119 }
7120
7121 run_system(dut, "cfg -a AP_STARTMODE=multi");
7122 }
7123
7124 run_system(dut, "cfg -c");
7125
7126 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
7127 if (system("apup") != 0) {
7128 /* to be debugged why apup returns error
7129 send_resp(dut, conn, SIGMA_ERROR,
7130 "errorCode,apup failed");
7131 return 0;
7132 */
7133 }
7134 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
7135
7136 if (dut->ap_key_mgmt != AP_OPEN) {
7137 int res;
7138 /* allow some time for hostapd to start before returning
7139 * success */
7140 usleep(500000);
7141 if (run_hostapd_cli(dut, "ping") != 0) {
7142 send_resp(dut, conn, SIGMA_ERROR,
7143 "errorCode,Failed to talk to hostapd");
7144 return 0;
7145 }
7146
7147 if (dut->ap_hs2 && !dut->ap_anqpserver) {
7148 /* the cfg app doesn't like ";" in the variables */
7149 res = ath_ap_append_hostapd_conf(dut);
7150 if (res < 0)
7151 return res;
7152
7153 /* wait for hostapd to be ready */
7154 usleep(500000);
7155 if (run_hostapd_cli(dut, "ping") != 0) {
7156 send_resp(dut, conn, SIGMA_ERROR,
7157 "errorCode,Failed to talk to "
7158 "hostapd");
7159 return 0;
7160 }
7161 }
7162 }
7163
7164 ath_ap_set_params(dut);
7165
7166 if (dut->ap_anqpserver)
7167 return cmd_ath_ap_anqpserver_start(dut);
7168
7169 if (dut->ap2_proxy_arp)
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007170 run_iwpriv(dut, ifname, "proxy_arp 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007171
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007172 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip)
7173 run_iwpriv(dut, ifname, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007174
7175 return 1;
7176}
7177
7178
7179static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
7180 const char *ifname)
7181{
7182 char buf[200];
7183
7184 if (!chain || !ifname)
7185 return -2;
7186
7187 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7188 if (system(buf) != 0) {
7189 sigma_dut_print(dut, DUT_MSG_ERROR,
7190 "Failed to set ebtables rules, RULE-1, %s",
7191 chain);
7192 return -2;
7193 }
7194
7195 snprintf(buf, sizeof(buf),
7196 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7197 chain, ifname);
7198 if (system(buf) != 0) {
7199 sigma_dut_print(dut, DUT_MSG_ERROR,
7200 "Failed to set ebtables rules, RULE-2, %s",
7201 chain);
7202 return -2;
7203 }
7204
7205 snprintf(buf, sizeof(buf),
7206 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
7207 chain, ifname);
7208 if (system(buf) != 0) {
7209 sigma_dut_print(dut, DUT_MSG_ERROR,
7210 "Failed to set ebtables rules, RULE-3, %s",
7211 chain);
7212 return -2;
7213 }
7214
7215 snprintf(buf, sizeof(buf),
7216 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
7217 chain, ifname);
7218 if (system(buf) != 0) {
7219 sigma_dut_print(dut, DUT_MSG_ERROR,
7220 "Failed to set ebtables rules, RULE-4, %s",
7221 chain);
7222 return -2;
7223 }
7224
7225 return 0;
7226}
7227
7228
7229static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
7230 const char *chain,
7231 const char *ifname)
7232{
7233 char buf[200];
7234
7235 if (!chain || !ifname)
7236 return -2;
7237
7238 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7239 if (system(buf) != 0) {
7240 sigma_dut_print(dut, DUT_MSG_ERROR,
7241 "Failed to set ebtables rules, RULE-5, %s",
7242 chain);
7243 return -2;
7244 }
7245
7246 snprintf(buf, sizeof(buf),
7247 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7248 chain, ifname);
7249 if (system(buf) != 0) {
7250 sigma_dut_print(dut, DUT_MSG_ERROR,
7251 "Failed to set ebtables rules, RULE-6, %s",
7252 chain);
7253 return -2;
7254 }
7255
7256 snprintf(buf, sizeof(buf),
7257 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
7258 chain, ifname);
7259 if (system(buf) != 0) {
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "Failed to set ebtables rules, RULE-7, %s",
7262 chain);
7263 return -2;
7264 }
7265
7266 snprintf(buf, sizeof(buf),
7267 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
7268 chain, ifname);
7269 if (system(buf) != 0) {
7270 sigma_dut_print(dut, DUT_MSG_ERROR,
7271 "Failed to set ebtables rules, RULE-8, %s",
7272 chain);
7273 return -2;
7274 }
7275
7276 return 0;
7277}
7278
7279
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007280static void set_ebtables_forward_drop(struct sigma_dut *dut,
7281 const char *ifname, const char *ifname2)
7282{
7283 char buf[128];
7284
7285 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7286 ifname, ifname2);
7287 if (system(buf) != 0)
7288 sigma_dut_print(dut, DUT_MSG_ERROR,
7289 "Failed to set ebtables rule");
7290
7291 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7292 ifname2, ifname);
7293 if (system(buf) != 0)
7294 sigma_dut_print(dut, DUT_MSG_ERROR,
7295 "Failed to set ebtables rule");
7296}
7297
7298
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007299static int check_channel(int channel)
7300{
7301 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
7302 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
7303 161, 165 };
7304 int num_chan = sizeof(channel_list) / sizeof(int);
7305 int i;
7306
7307 for (i = 0; i < num_chan; i++) {
7308 if (channel == channel_list[i])
7309 return i;
7310 }
7311
7312 return -1;
7313}
7314
7315
7316static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
7317{
7318 int ch_base;
7319 int period;
7320
7321 if (check_channel(channel) < 0)
7322 return -1;
7323
7324 if (channel >= 36 && channel <= 64)
7325 ch_base = 36;
7326 else if (channel >= 100 && channel <= 144)
7327 ch_base = 100;
7328 else
7329 ch_base = 149;
7330
7331 period = channel % ch_base * 5 / chwidth;
7332 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
7333}
7334
7335
7336static int is_ht40plus_chan(int chan)
7337{
7338 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
7339 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
7340 chan == 132 || chan == 149 || chan == 157;
7341}
7342
7343
7344static int is_ht40minus_chan(int chan)
7345{
7346 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
7347 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
Hangtian Zhue4fa84c2020-03-16 23:12:35 +08007348 chan == 136 || chan == 144 || chan == 153 || chan == 161;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007349}
7350
7351
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05307352static int get_5g_channel_freq(int chan)
7353{
7354 return 5000 + chan * 5;
7355}
7356
7357
Jouni Malinen3d633da2017-09-14 22:19:21 +03007358static const char * hostapd_cipher_name(enum ap_cipher cipher)
7359{
7360 switch (cipher) {
7361 case AP_CCMP:
7362 return "CCMP";
7363 case AP_TKIP:
7364 return "TKIP";
7365 case AP_CCMP_TKIP:
7366 return "CCMP TKIP";
7367 case AP_GCMP_256:
7368 return "GCMP-256";
7369 case AP_GCMP_128:
7370 return "GCMP";
7371 case AP_CCMP_256:
7372 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02007373 case AP_CCMP_128_GCMP_256:
7374 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007375 default:
7376 return "UNKNOWN";
7377 }
7378}
7379
7380
7381static const char *
7382hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
7383{
7384 switch (cipher) {
7385 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03007386 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007387 case AP_BIP_CMAC_256:
7388 return "BIP-CMAC-256";
7389 case AP_BIP_GMAC_128:
7390 return "BIP-GMAC-128";
7391 case AP_BIP_CMAC_128:
7392 return "AES-128-CMAC";
7393 default:
7394 return "UNKNOWN";
7395 }
7396}
7397
7398
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007399static int ap_set_60g_ese(struct sigma_dut *dut, int count,
7400 struct sigma_ese_alloc *allocs)
7401{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007402 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007403#ifdef __linux__
7404 case DRIVER_WIL6210:
7405 return wil6210_set_ese(dut, count, allocs);
7406#endif /* __linux__ */
7407 default:
7408 sigma_dut_print(dut, DUT_MSG_ERROR,
7409 "Unsupported ap_set_60g_ese with the current driver");
7410 return -1;
7411 }
7412}
7413
7414
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007415static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
7416{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007417 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007418#ifdef __linux__
7419 case DRIVER_WIL6210:
7420 return wil6210_set_force_mcs(dut, force, mcs);
7421#endif /* __linux__ */
7422 default:
7423 sigma_dut_print(dut, DUT_MSG_ERROR,
7424 "Unsupported ap_set_force_mcs with the current driver");
7425 return -1;
7426 }
7427}
7428
7429
Jouni Malinenf7222712019-06-13 01:50:21 +03007430enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
7431 struct sigma_conn *conn,
7432 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007433{
7434 /* const char *name = get_param(cmd, "NAME"); */
7435 FILE *f;
7436 const char *ifname;
7437 char buf[500];
7438 char path[100];
Alexei Avshalom Lazarc9bc15d2020-01-29 10:52:13 +02007439 char ap_conf_path[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007440 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03007441 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307442#ifdef ANDROID
7443 struct group *gr;
7444#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007445
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007446 drv = get_driver_type(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007447
7448 if (dut->mode == SIGMA_MODE_STATION) {
7449 stop_sta_mode(dut);
7450 sleep(1);
7451 }
7452
7453 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
7454 snprintf(buf, sizeof(buf), "ifconfig %s down",
7455 dut->sniffer_ifname);
7456 if (system(buf) != 0) {
7457 sigma_dut_print(dut, DUT_MSG_INFO,
7458 "Failed to run '%s'", buf);
7459 }
7460 snprintf(buf, sizeof(buf), "iw dev %s set type station",
7461 dut->sniffer_ifname);
7462 if (system(buf) != 0) {
7463 sigma_dut_print(dut, DUT_MSG_INFO,
7464 "Failed to run '%s'", buf);
7465 }
7466 }
7467
7468 dut->mode = SIGMA_MODE_AP;
7469
7470 if (drv == DRIVER_ATHEROS)
7471 return cmd_ath_ap_config_commit(dut, conn, cmd);
7472 if (drv == DRIVER_WCN)
7473 return cmd_wcn_ap_config_commit(dut, conn, cmd);
7474 if (drv == DRIVER_OPENWRT)
7475 return cmd_owrt_ap_config_commit(dut, conn, cmd);
7476
Jouni Malinen6e7ec732020-02-28 19:49:59 +02007477 concat_sigma_tmpdir(dut, "/sigma_dut-ap.conf", ap_conf_path,
7478 sizeof(ap_conf_path));
7479 f = fopen(ap_conf_path, "w");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007480 if (f == NULL) {
7481 sigma_dut_print(dut, DUT_MSG_ERROR,
7482 "%s: Failed to open sigma_dut-ap.conf",
7483 __func__);
7484 return -2;
7485 }
Hu Wang8a3b13a2020-03-14 09:56:48 +08007486
7487 ifname = get_hostapd_ifname(dut);
7488
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007489 switch (dut->ap_mode) {
7490 case AP_11g:
7491 case AP_11b:
7492 case AP_11ng:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007493 fprintf(f, "hw_mode=g\n");
7494 break;
7495 case AP_11a:
7496 case AP_11na:
7497 case AP_11ac:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007498 fprintf(f, "hw_mode=a\n");
7499 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007500 case AP_11ad:
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007501 fprintf(f, "hw_mode=ad\n");
7502 break;
bings7e9914d2019-12-06 17:07:11 +08007503 case AP_11ax:
bings7e9914d2019-12-06 17:07:11 +08007504 if (dut->use_5g)
7505 fprintf(f, "hw_mode=a\n");
7506 else
7507 fprintf(f, "hw_mode=g\n");
7508 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007509 default:
7510 fclose(f);
7511 return -1;
7512 }
7513
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307514 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007515 fprintf(f, "driver=nl80211\n");
7516
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307517 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7518 drv == DRIVER_LINUX_WCN) &&
bings7e9914d2019-12-06 17:07:11 +08007519 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na ||
7520 (dut->ap_mode == AP_11ax && !dut->use_5g))) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05307521 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
7522
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007523 fprintf(f, "ieee80211n=1\n");
bings7e9914d2019-12-06 17:07:11 +08007524 if (dut->ap_mode == AP_11ax)
7525 fprintf(f, "ieee80211ax=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307526 if (dut->ap_mode == AP_11ng &&
7527 (dut->ap_chwidth == AP_40 ||
7528 (dut->ap_chwidth == AP_AUTO &&
7529 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007530 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307531 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007532 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307533 ht40minus = 1;
7534 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007535 }
7536
7537 /* configure ht_capab based on channel width */
7538 if (dut->ap_mode == AP_11na &&
7539 (dut->ap_chwidth == AP_40 ||
7540 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307541 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007542 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307543 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007544 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307545 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007546 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307547
7548 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307549 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307550
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307551 /* Overwrite the ht_capab with offset value if configured */
7552 if (dut->ap_chwidth == AP_40 &&
7553 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
7554 ht40plus = 1;
7555 ht40minus = 0;
7556 } else if (dut->ap_chwidth == AP_40 &&
7557 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
7558 ht40minus = 1;
7559 ht40plus = 0;
7560 }
7561
Tamizh chelvam431c6002017-03-07 17:07:16 +05307562 fprintf(f, "ht_capab=%s%s%s\n",
7563 ht40plus ? "[HT40+]" : "",
7564 ht40minus ? "[HT40-]" : "",
7565 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007566 }
7567
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307568 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7569 drv == DRIVER_LINUX_WCN) &&
bings7e9914d2019-12-06 17:07:11 +08007570 (dut->ap_mode == AP_11ac ||
7571 (dut->ap_mode == AP_11ax && dut->use_5g))) {
Hu Wang29392102019-07-03 15:41:12 +08007572 int ht40plus = 0, ht40minus = 0;
7573
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007574 fprintf(f, "ieee80211ac=1\n"
Hu Wang29392102019-07-03 15:41:12 +08007575 "ieee80211n=1\n");
bings7e9914d2019-12-06 17:07:11 +08007576 if (dut->ap_mode == AP_11ax)
7577 fprintf(f, "ieee80211ax=1\n");
Hu Wang29392102019-07-03 15:41:12 +08007578
7579 /* configure ht_capab based on channel width */
7580 if (dut->ap_chwidth != AP_20) {
7581 if (is_ht40plus_chan(dut->ap_channel))
7582 ht40plus = 1;
7583 else if (is_ht40minus_chan(dut->ap_channel))
7584 ht40minus = 1;
7585
7586 fprintf(f, "ht_capab=%s%s\n",
7587 ht40plus ? "[HT40+]" : "",
7588 ht40minus ? "[HT40-]" : "");
7589 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007590 }
7591
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307592 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7593 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007594 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
7595 if (dut->ap_countrycode[0]) {
7596 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
7597 fprintf(f, "ieee80211d=1\n");
7598 fprintf(f, "ieee80211h=1\n");
7599 }
7600 }
7601
Kiran Kumar Lokere800d39d2020-01-21 15:35:22 -08007602 if (drv == DRIVER_LINUX_WCN && dut->ap_mode == AP_11ax) {
7603 if (dut->ap_txBF) {
7604 fprintf(f, "he_su_beamformer=1\n");
7605 fprintf(f, "he_su_beamformee=1\n");
7606 if (dut->ap_mu_txBF)
7607 fprintf(f, "he_mu_beamformer=1\n");
7608 } else {
7609 fprintf(f, "he_su_beamformer=0\n");
7610 fprintf(f, "he_su_beamformee=0\n");
7611 fprintf(f, "he_mu_beamformer=0\n");
7612 }
7613 }
7614
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007615 fprintf(f, "interface=%s\n", ifname);
7616 if (dut->bridge)
7617 fprintf(f, "bridge=%s\n", dut->bridge);
7618 fprintf(f, "channel=%d\n", dut->ap_channel);
7619
7620 if (sigma_hapd_ctrl)
7621 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
7622 else
7623 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
7624
7625 if (dut->ap_ssid[0])
7626 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7627 else
7628 fprintf(f, "ssid=QCA AP OOB\n");
7629 if (dut->ap_bcnint)
7630 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
7631
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007632 if (dut->ap_akm_values) {
7633 struct {
7634 int akm;
7635 const char *str;
7636 } akms[] = {
7637 { AKM_WPA_EAP, "WPA-EAP" },
7638 { AKM_WPA_PSK, "WPA-PSK" },
7639 { AKM_FT_EAP, "FT-EAP" },
7640 { AKM_FT_PSK, "FT-PSK" },
7641 { AKM_EAP_SHA256, "WPA-EAP-SHA256" },
7642 { AKM_PSK_SHA256, "WPA-PSK-SHA256" },
7643 { AKM_SAE, "SAE" },
7644 { AKM_FT_SAE, "FT-SAE" },
7645 { AKM_SUITE_B, "WPA-EAP-SUITE-B-192" },
7646 { AKM_FT_SUITE_B, "FT-EAP-SHA384" },
7647 { AKM_FILS_SHA256, "FILS-SHA256" },
7648 { AKM_FILS_SHA384, "FILS-SHA384" },
7649 { AKM_FT_FILS_SHA256, "FT-FILS-SHA256" },
7650 { AKM_FT_FILS_SHA384, "FT-FILS-SHA384" },
7651 };
Jouni Malinen8400c082019-04-26 13:26:07 +03007652 int first = 1;
7653 unsigned int i;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007654
7655 fprintf(f, "wpa_key_mgmt=");
7656 for (i = 0; i < ARRAY_SIZE(akms); i++) {
7657 if (dut->ap_akm_values & (1 << akms[i].akm)) {
7658 fprintf(f, "%s%s", first ? "" : " ",
7659 akms[i].str);
7660 first = 0;
7661 }
7662 }
7663 fprintf(f, "\n");
7664 /* TODO: mixed mode and WPAv1 only */
7665 fprintf(f, "wpa=2\n");
7666 fprintf(f, "wpa_pairwise=%s\n",
7667 hostapd_cipher_name(dut->ap_cipher));
7668 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7669 fprintf(f, "group_cipher=%s\n",
7670 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3e255412019-03-28 22:04:08 +02007671 if ((dut->ap_akm_values &
7672 ((1 << AKM_SAE) | (1 << AKM_FT_SAE))) &&
7673 !(dut->ap_akm_values &
7674 ((1 << AKM_WPA_PSK) | (1 << AKM_FT_PSK))) &&
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007675 dut->ap_passphrase[0])
7676 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
7677 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7678 fprintf(f, "wpa_psk=%s", dut->ap_psk);
7679 else if (dut->ap_passphrase[0])
7680 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007681 if (dut->ap_akm_values & ((1 << AKM_WPA_EAP) |
Jouni Malinene5393c32019-06-20 01:34:34 +03007682 (1 << AKM_FT_EAP) |
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007683 (1 << AKM_EAP_SHA256) |
7684 (1 << AKM_SUITE_B) |
7685 (1 << AKM_FT_SUITE_B) |
7686 (1 << AKM_FILS_SHA256) |
7687 (1 << AKM_FILS_SHA384) |
7688 (1 << AKM_FT_FILS_SHA256) |
7689 (1 << AKM_FT_FILS_SHA384))) {
7690 fprintf(f, "ieee8021x=1\n");
7691 fprintf(f, "auth_server_addr=%s\n",
7692 dut->ap_radius_ipaddr);
7693 if (dut->ap_radius_port)
7694 fprintf(f, "auth_server_port=%d\n",
7695 dut->ap_radius_port);
7696 fprintf(f, "auth_server_shared_secret=%s\n",
7697 dut->ap_radius_password);
7698 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007699 goto skip_key_mgmt;
7700 }
7701
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007702 switch (dut->ap_key_mgmt) {
7703 case AP_OPEN:
7704 if (dut->ap_cipher == AP_WEP)
7705 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
7706 break;
7707 case AP_WPA2_PSK:
7708 case AP_WPA2_PSK_MIXED:
7709 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007710 case AP_WPA2_SAE:
7711 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007712 case AP_WPA2_PSK_SHA256:
7713 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007714 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
7715 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007716 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7717 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
7718 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007719 fprintf(f, "wpa=2\n");
7720 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
7721 fprintf(f, "wpa=3\n");
7722 else
7723 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03007724 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7725 key_mgmt = "SAE";
7726 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7727 key_mgmt = "WPA-PSK SAE";
7728 else
7729 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007730 switch (dut->ap_pmf) {
7731 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007732 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007733 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7734 break;
7735 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03007736 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007737 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7738 break;
7739 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007740 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7741 key_mgmt = "SAE";
7742 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7743 key_mgmt = "WPA-PSK-SHA256 SAE";
7744 else
7745 key_mgmt = "WPA-PSK-SHA256";
7746 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007747 break;
7748 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007749 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
7750 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
7751 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
7752 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007753 fprintf(f, "wpa_pairwise=%s\n",
7754 hostapd_cipher_name(dut->ap_cipher));
7755 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7756 fprintf(f, "group_cipher=%s\n",
7757 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03007758 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7759 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02007760 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7761 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03007762 else
7763 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007764 break;
7765 case AP_WPA2_EAP:
7766 case AP_WPA2_EAP_MIXED:
7767 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007768 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007769 case AP_WPA2_EAP_SHA256:
7770 case AP_WPA2_FT_EAP:
7771 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007772 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007773 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007774 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
7775 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
7776 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
7777 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007778 fprintf(f, "wpa=2\n");
7779 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
7780 fprintf(f, "wpa=3\n");
7781 else
7782 fprintf(f, "wpa=1\n");
7783 switch (dut->ap_pmf) {
7784 case AP_PMF_DISABLED:
7785 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
7786 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
7787 break;
7788 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007789 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
7790 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
7791 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7792 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007793 break;
7794 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007795 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
7796 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7797 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007798 break;
7799 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007800 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
7801 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
7802 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
7803 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
7804 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
7805 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007806 fprintf(f, "wpa_pairwise=%s\n",
7807 hostapd_cipher_name(dut->ap_cipher));
7808 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7809 fprintf(f, "group_cipher=%s\n",
7810 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007811 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7812 if (dut->ap_radius_port)
7813 fprintf(f, "auth_server_port=%d\n",
7814 dut->ap_radius_port);
7815 fprintf(f, "auth_server_shared_secret=%s\n",
7816 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03007817 if (dut->program == PROGRAM_HS2_R3) {
7818 fprintf(f, "radius_das_port=3799\n");
7819 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
7820 dut->ap_radius_password);
7821 fprintf(f, "radius_das_require_event_timestamp=1\n");
7822 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007823 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03007824 case AP_SUITEB:
7825 fprintf(f, "ieee8021x=1\n");
7826 fprintf(f, "wpa=2\n");
7827 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03007828 fprintf(f, "wpa_pairwise=%s\n",
7829 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02007830 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7831 fprintf(f, "group_cipher=%s\n",
7832 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03007833 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7834 fprintf(f, "group_mgmt_cipher=%s\n",
7835 hostapd_group_mgmt_cipher_name(
7836 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03007837 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7838 if (dut->ap_radius_port)
7839 fprintf(f, "auth_server_port=%d\n",
7840 dut->ap_radius_port);
7841 fprintf(f, "auth_server_shared_secret=%s\n",
7842 dut->ap_radius_password);
7843 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03007844 case AP_WPA2_OWE:
7845 fprintf(f, "wpa=2\n");
7846 fprintf(f, "wpa_key_mgmt=OWE\n");
7847 fprintf(f, "rsn_pairwise=%s\n",
7848 hostapd_cipher_name(dut->ap_cipher));
Hu Wang6010ce72020-03-05 19:33:53 +08007849 if (dut->ap_sae_groups) {
Jouni Malinen72461d42017-10-10 19:20:45 +03007850 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Hu Wang6010ce72020-03-05 19:33:53 +08007851 if (dut->owe_ptk_workaround)
7852 fprintf(f, "owe_ptk_workaround=1\n");
7853 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03007854 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03007855 case AP_OSEN:
7856 fprintf(f, "osen=1\n");
7857 fprintf(f, "disable_dgaf=1\n");
7858 fprintf(f, "wpa_pairwise=%s\n",
7859 hostapd_cipher_name(dut->ap_cipher));
7860 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7861 fprintf(f, "group_cipher=%s\n",
7862 hostapd_cipher_name(dut->ap_group_cipher));
7863 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7864 if (dut->ap_radius_port)
7865 fprintf(f, "auth_server_port=%d\n",
7866 dut->ap_radius_port);
7867 fprintf(f, "auth_server_shared_secret=%s\n",
7868 dut->ap_radius_password);
7869 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007870 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007871skip_key_mgmt:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007872
Jouni Malinen09550de2019-03-26 00:24:11 +02007873 if (dut->ap_sae_passwords) {
7874 char *tmp, *pos, *end, *id;
7875
7876 tmp = strdup(dut->ap_sae_passwords);
7877 if (!tmp) {
7878 fclose(f);
7879 return ERROR_SEND_STATUS;
7880 }
7881
7882 pos = tmp;
7883 while (*pos) {
7884 end = strchr(pos, ';');
7885 if (end)
7886 *end = '\0';
7887 id = strchr(pos, ':');
7888 if (id)
7889 *id++ = '\0';
7890
7891 fprintf(f, "sae_password=%s%s%s\n",
7892 pos, id ? "|id=" : "", id ? id : "");
7893 if (!end)
7894 break;
7895 pos = end + 1;
7896 }
7897
7898 free(tmp);
7899 }
7900
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05307901 if (dut->ap_rsn_preauth)
7902 fprintf(f, "rsn_preauth=1\n");
7903
Jouni Malinenb75c5322019-06-14 01:47:43 +03007904 if (dut->ap_pmksa && dut->ap_pmksa_caching)
7905 fprintf(f, "disable_pmksa_caching=1\n");
7906
Jouni Malinen05d005a2020-03-26 12:49:33 +02007907 if (dut->ap_beacon_prot)
7908 fprintf(f, "beacon_prot=1\n");
7909
Jouni Malinenc098c442020-03-26 13:01:50 +02007910 if (dut->ap_transition_disable)
7911 fprintf(f, "transition_disable=0x%02x\n",
7912 dut->ap_transition_disable);
7913
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007914 switch (dut->ap_pmf) {
7915 case AP_PMF_DISABLED:
7916 break;
7917 case AP_PMF_OPTIONAL:
7918 fprintf(f, "ieee80211w=1\n");
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007919 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7920 (dut->ap_akm_values & (AKM_SAE | AKM_WPA_PSK)) ==
7921 (AKM_SAE | AKM_WPA_PSK))
Jouni Malinen1287cd72018-01-04 17:08:01 +02007922 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007923 break;
7924 case AP_PMF_REQUIRED:
7925 fprintf(f, "ieee80211w=2\n");
7926 break;
7927 }
7928
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007929 if (dut->ap_pmf != AP_PMF_DISABLED &&
7930 dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7931 fprintf(f, "group_mgmt_cipher=%s\n",
7932 hostapd_group_mgmt_cipher_name(
7933 dut->ap_group_mgmt_cipher));
7934
Jouni Malinen6be21c82018-08-01 18:47:24 +03007935 if (ap_ft_enabled(dut)) {
7936 unsigned char own_addr[ETH_ALEN];
7937
7938 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
Jouni Malinen9f943312019-08-19 23:49:16 +03007939 fprintf(f, "ft_over_ds=%d\n", dut->ap_ft_ds == VALUE_ENABLED);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007940 if (get_hwaddr(ifname, own_addr) < 0) {
7941 memset(own_addr, 0, ETH_ALEN);
7942 own_addr[0] = 0x02;
7943 }
Jouni Malinenc9674462019-03-26 02:40:19 +02007944 fprintf(f,
7945 "nas_identifier=%02x%02x%02x%02x%02x%02x.nas.example.com\n",
7946 own_addr[0], own_addr[1], own_addr[2],
7947 own_addr[3], own_addr[4], own_addr[5]);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007948 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7949 own_addr[0], own_addr[1], own_addr[2],
7950 own_addr[3], own_addr[4], own_addr[5]);
7951 fprintf(f, "ft_psk_generate_local=1\n");
7952 fprintf(f, "pmk_r1_push=0\n");
7953 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007954 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007955 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007956 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007957 }
7958
Jouni Malinen3c367e82017-06-23 17:01:47 +03007959 if (dut->rsne_override)
7960 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
Jouni Malinen7960e3a2019-12-07 17:04:35 +02007961 if (dut->rsnxe_override_eapol)
7962 fprintf(f, "rsnxe_override_eapol=%s\n",
7963 dut->rsnxe_override_eapol);
Jouni Malinen3c367e82017-06-23 17:01:47 +03007964
Jouni Malinen68143132017-09-02 02:34:08 +03007965 if (dut->sae_commit_override)
7966 fprintf(f, "sae_commit_override=%s\n",
7967 dut->sae_commit_override);
7968
Jouni Malinened670f42017-08-31 01:39:28 +03007969 if (dut->ap_sae_groups)
7970 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007971
Jouni Malinen11e55212019-11-22 21:46:59 +02007972 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
7973 const char *sae_pwe = NULL;
7974
Jouni Malinen6c882b22020-03-04 21:11:02 +02007975 if (dut->sae_pwe == SAE_PWE_LOOP && sae_pw_id_used(dut))
7976 sae_pwe = "3";
7977 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02007978 sae_pwe = "0";
7979 else if (dut->sae_pwe == SAE_PWE_H2E)
7980 sae_pwe = "1";
7981 else if (dut->sae_h2e_default)
7982 sae_pwe = "2";
7983 if (sae_pwe)
Jouni Malinen849d8162020-02-28 19:50:50 +02007984 fprintf(f, "sae_pwe=%s\n", sae_pwe);
Jouni Malinen11e55212019-11-22 21:46:59 +02007985 }
7986
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007987 if (dut->sae_anti_clogging_threshold >= 0)
7988 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7989 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007990 if (dut->sae_reflection)
7991 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03007992 if (dut->sae_confirm_immediate)
Jouni Malinena6f1db02020-01-23 00:46:12 +02007993 fprintf(f, "sae_confirm_immediate=2\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007994
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007995 if (dut->ap_p2p_mgmt)
7996 fprintf(f, "manage_p2p=1\n");
7997
7998 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7999 fprintf(f, "tdls_prohibit=1\n");
8000 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
8001 fprintf(f, "tdls_prohibit_chan_switch=1\n");
8002 if (dut->ap_p2p_cross_connect >= 0) {
8003 fprintf(f, "manage_p2p=1\n"
8004 "allow_cross_connection=%d\n",
8005 dut->ap_p2p_cross_connect);
8006 }
8007
Jouni Malinen4d479c92018-11-06 00:43:36 +02008008 if (dut->ap_l2tif || dut->ap_proxy_arp ||
8009 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008010 if (!dut->bridge) {
8011 sigma_dut_print(dut, DUT_MSG_ERROR,
8012 "Bridge must be configured. Run with -b <brname>.");
8013 fclose(f);
8014 return -2;
8015 }
8016 fprintf(f, "ap_isolate=1\n");
8017 }
8018
8019 if (dut->ap_proxy_arp)
8020 fprintf(f, "proxy_arp=1\n");
8021
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308022 if (dut->ap_wme)
8023 fprintf(f, "wmm_enabled=1\n");
8024
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308025 if (dut->ap_wmmps == AP_WMMPS_ON)
8026 fprintf(f, "uapsd_advertisement_enabled=1\n");
8027
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008028 if (dut->ap_hs2) {
8029 if (dut->ap_bss_load) {
8030 char *bss_load;
8031
8032 switch (dut->ap_bss_load) {
8033 case -1:
8034 bss_load = "bss_load_update_period=10";
8035 break;
8036 case 1:
8037 /* STA count: 1, CU: 50, AAC: 65535 */
8038 bss_load = "bss_load_test=1:50:65535";
8039 break;
8040 case 2:
8041 /* STA count: 1, CU: 200, AAC: 65535 */
8042 bss_load = "bss_load_test=1:200:65535";
8043 break;
8044 case 3:
8045 /* STA count: 1, CU: 75, AAC: 65535 */
8046 bss_load = "bss_load_test=1:75:65535";
8047 break;
8048 default:
8049 bss_load = NULL;
8050 break;
8051 }
8052
8053 if (!bss_load) {
8054 fclose(f);
8055 return -2;
8056 }
8057 fprintf(f, "%s\n", bss_load);
8058 }
8059
8060 if (append_hostapd_conf_hs2(dut, f)) {
8061 fclose(f);
8062 return -2;
8063 }
8064 }
8065
8066 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
8067 fclose(f);
8068 return -2;
8069 }
8070
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008071 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008072 unsigned char bssid[6];
8073 char ifname2[50];
8074
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308075 if (get_hwaddr(ifname, bssid)) {
8076 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008077 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308078 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03008079 if (bssid[0] & 0x02)
8080 bssid[5] ^= 0x01;
8081 else
8082 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008083
8084 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03008085 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008086 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008087 if (dut->bridge)
8088 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008089
8090 if (drv == DRIVER_LINUX_WCN)
8091 fprintf(f, "use_driver_iface_addr=1\n");
8092 else
8093 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8094 bssid[0], bssid[1], bssid[2], bssid[3],
8095 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008096
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008097 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008098 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05308099 /* Disable DGAF for OSEN BSS */
8100 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008101 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008102 if (strlen(dut->ap2_radius_ipaddr))
8103 fprintf(f, "auth_server_addr=%s\n",
8104 dut->ap2_radius_ipaddr);
8105 if (dut->ap2_radius_port)
8106 fprintf(f, "auth_server_port=%d\n",
8107 dut->ap2_radius_port);
8108 if (strlen(dut->ap2_radius_password))
8109 fprintf(f, "auth_server_shared_secret=%s\n",
8110 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008111
8112 set_ebtables_forward_drop(dut, ifname, ifname2);
8113 } else if (dut->ap2_osu) {
8114 fprintf(f, "ap_isolate=1\n");
8115 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008116 }
8117
8118 if (dut->ap2_proxy_arp) {
8119 if (!dut->bridge) {
8120 sigma_dut_print(dut, DUT_MSG_ERROR,
8121 "Bridge must be configured. Run with -b <brname>.");
8122 fclose(f);
8123 return -2;
8124 }
8125 fprintf(f, "ap_isolate=1\n");
8126 fprintf(f, "proxy_arp=1\n");
8127
8128 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
8129 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
8130 fclose(f);
8131 return -2;
8132 }
8133
8134 }
8135 }
8136
8137 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008138 /* 60G WPS tests requires wps_state of 2 (configured) */
8139 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
8140
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008141 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008142 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008143 "device_name=QCA AP\n"
8144 "manufacturer=QCA\n"
8145 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008146 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008147 "virtual_push_button keypad%s\n"
8148 "ap_pin=12345670\n"
8149 "friendly_name=QCA Access Point\n"
8150 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008151 wps_state,
8152 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
8154 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008155 if (dut->wsc_fragment) {
8156 fprintf(f, "device_name=%s\n"
8157 "manufacturer=%s\n"
8158 "model_name=%s\n"
8159 "model_number=%s\n"
8160 "serial_number=%s\n",
8161 WPS_LONG_DEVICE_NAME,
8162 WPS_LONG_MANUFACTURER,
8163 WPS_LONG_MODEL_NAME,
8164 WPS_LONG_MODEL_NUMBER,
8165 WPS_LONG_SERIAL_NUMBER);
8166 } else {
8167 fprintf(f, "device_name=QCA AP\n"
8168 "manufacturer=QCA\n");
8169 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008170 if (dut->eap_fragment)
8171 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008172 }
8173
Jouni Malinenba4f2d42019-10-04 16:13:41 +03008174 if (dut->ap_dpp_conf_addr && dut->ap_dpp_conf_pkhash)
8175 fprintf(f, "dpp_controller=ipaddr=%s pkhash=%s\n",
8176 dut->ap_dpp_conf_addr, dut->ap_dpp_conf_pkhash);
8177
Qiwei Cai0bec0602020-01-15 10:38:40 +08008178 if (dut->ap_he_rtsthrshld == VALUE_ENABLED)
8179 fprintf(f, "he_rts_threshold=512\n");
8180 else if (dut->ap_he_rtsthrshld == VALUE_DISABLED)
8181 fprintf(f, "he_rts_threshold=1024\n");
8182
bings7e9914d2019-12-06 17:07:11 +08008183 if ((dut->program == PROGRAM_VHT) ||
8184 (dut->program == PROGRAM_HE && dut->use_5g)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008185 int vht_oper_centr_freq_idx;
8186
8187 if (check_channel(dut->ap_channel) < 0) {
8188 send_resp(dut, conn, SIGMA_INVALID,
8189 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308190 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008191 return 0;
8192 }
8193
8194 switch (dut->ap_chwidth) {
8195 case AP_20:
8196 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8197 vht_oper_centr_freq_idx =
8198 get_oper_centr_freq_seq_idx(20,
8199 dut->ap_channel);
8200 break;
8201 case AP_40:
8202 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8203 vht_oper_centr_freq_idx =
8204 get_oper_centr_freq_seq_idx(40,
8205 dut->ap_channel);
8206 break;
8207 case AP_80:
8208 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
8209 vht_oper_centr_freq_idx =
8210 get_oper_centr_freq_seq_idx(80,
8211 dut->ap_channel);
8212 break;
8213 case AP_160:
8214 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
8215 vht_oper_centr_freq_idx =
8216 get_oper_centr_freq_seq_idx(160,
8217 dut->ap_channel);
8218 break;
8219 default:
8220 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
8221 vht_oper_centr_freq_idx =
8222 get_oper_centr_freq_seq_idx(80,
8223 dut->ap_channel);
8224 break;
8225 }
8226 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
8227 vht_oper_centr_freq_idx);
8228 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
bings7e9914d2019-12-06 17:07:11 +08008229 if (dut->ap_mode == AP_11ax) {
8230 fprintf(f, "he_oper_chwidth=%d\n", dut->ap_vht_chwidth);
8231 fprintf(f, "he_oper_centr_freq_seg0_idx=%d\n",
8232 vht_oper_centr_freq_idx);
8233 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008234
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008235 if (dut->ap_sgi80 || dut->ap_txBF ||
8236 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308237 dut->ap_tx_stbc || dut->ap_mu_txBF) {
8238 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008239 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05308240 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05308241 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008242 (dut->ap_ldpc == VALUE_ENABLED) ?
8243 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308244 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
8245 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008246 }
8247 }
8248
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008249 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
8250 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
8251 /* OWE transition mode */
8252 unsigned char bssid[6];
8253 char ifname2[50];
8254 unsigned long val;
8255 FILE *f2;
8256
8257 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8258
8259 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8260 val = 0x12345678; /* default to something */
8261 f2 = fopen("/dev/urandom", "r");
8262 if (f2) {
8263 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8264 sigma_dut_print(dut, DUT_MSG_ERROR,
8265 "Could not read /dev/urandom");
8266 }
8267 fclose(f2);
8268 }
8269 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008270 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008271
8272 if (get_hwaddr(ifname, bssid)) {
8273 fclose(f);
8274 return -2;
8275 }
8276 if (bssid[0] & 0x02)
8277 bssid[5] ^= 0x01;
8278 else
8279 bssid[0] |= 0x02;
8280
8281 fprintf(f, "bss=%s\n", ifname2);
8282 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8283 if (dut->bridge)
8284 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008285 if (drv == DRIVER_LINUX_WCN)
8286 fprintf(f, "use_driver_iface_addr=1\n");
8287 else
8288 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8289 bssid[0], bssid[1], bssid[2], bssid[3],
8290 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008291 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8292 }
8293
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008294 if (dut->ap_key_mgmt == AP_OPEN &&
8295 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
8296 /* OWE transition mode */
8297 unsigned char bssid[6];
8298 char ifname2[50];
8299 unsigned long val;
8300 FILE *f2;
8301
8302 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8303
8304 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8305 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8306
8307 if (get_hwaddr(ifname, bssid)) {
8308 fclose(f);
8309 return -2;
8310 }
8311 if (bssid[0] & 0x02)
8312 bssid[5] ^= 0x01;
8313 else
8314 bssid[0] |= 0x02;
8315
8316 fprintf(f, "bss=%s\n", ifname2);
8317 val = 0x12345678; /* default to something */
8318 f2 = fopen("/dev/urandom", "r");
8319 if (f2) {
8320 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8321 sigma_dut_print(dut, DUT_MSG_ERROR,
8322 "Could not read /dev/urandom");
8323 }
8324 fclose(f2);
8325 }
8326 fprintf(f, "ssid=owe-%lx\n", val);
8327 if (dut->bridge)
8328 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008329 if (drv == DRIVER_LINUX_WCN)
8330 fprintf(f, "use_driver_iface_addr=1\n");
8331 else
8332 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8333 bssid[0], bssid[1], bssid[2], bssid[3],
8334 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008335 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8336 fprintf(f, "wpa=2\n");
8337 fprintf(f, "wpa_key_mgmt=OWE\n");
8338 fprintf(f, "rsn_pairwise=CCMP\n");
8339 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008340 fprintf(f, "ignore_broadcast_ssid=1\n");
Hu Wang6010ce72020-03-05 19:33:53 +08008341 if (dut->ap_sae_groups) {
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008342 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Hu Wang6010ce72020-03-05 19:33:53 +08008343 if (dut->owe_ptk_workaround)
8344 fprintf(f, "owe_ptk_workaround=1\n");
8345 }
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008346 }
8347
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308348 if (dut->program == PROGRAM_OCE) {
8349 fprintf(f, "oce=%d\n",
8350 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
8351 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008352 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008353 if (dut->use_hostapd_pid_file)
8354 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008355#ifdef __QNXNTO__
8356 if (system("slay hostapd") == 0)
8357#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008358 if (!dut->use_hostapd_pid_file &&
8359 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8360 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008361#endif /* __QNXNTO__ */
8362 {
8363 int i;
8364 /* Wait some time to allow hostapd to complete cleanup before
8365 * starting a new process */
8366 for (i = 0; i < 10; i++) {
8367 usleep(500000);
8368#ifdef __QNXNTO__
8369 if (system("pidin | grep hostapd") != 0)
8370 break;
8371#else /* __QNXNTO__ */
8372 if (system("pidof hostapd") != 0)
8373 break;
8374#endif /* __QNXNTO__ */
8375 }
8376 }
Jouni Malinend86e5822017-08-29 03:55:32 +03008377 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008378
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308379#ifdef ANDROID
8380 /* Set proper conf file permissions so that hostapd process
8381 * can access it.
8382 */
Jouni Malinen6e7ec732020-02-28 19:49:59 +02008383 if (chmod(ap_conf_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308384 sigma_dut_print(dut, DUT_MSG_ERROR,
8385 "Error changing permissions");
8386
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05308387 gr = getgrnam("wifi");
Jouni Malinen6e7ec732020-02-28 19:49:59 +02008388 if (!gr || chown(ap_conf_path, -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308389 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
8390#endif /* ANDROID */
8391
Jouni Malinen6e7ec732020-02-28 19:49:59 +02008392 f = fopen(ap_conf_path, "r");
8393 if (f) {
8394 size_t len;
8395
8396 len = fread(buf, 1, sizeof(buf), f);
8397 fclose(f);
8398 if (len >= sizeof(buf))
8399 len = sizeof(buf) - 1;
8400 buf[len] = '\0';
8401 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd debug log:\n%s",
8402 buf);
8403 }
8404
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008405 if (drv == DRIVER_QNXNTO) {
8406 snprintf(buf, sizeof(buf),
Alexei Avshalom Lazarc9bc15d2020-01-29 10:52:13 +02008407 "hostapd -B %s%s%s %s%s %s/sigma_dut-ap.conf",
Alexei Avshalom Lazar04a17af2020-01-26 16:16:47 +02008408 dut->hostapd_debug_log ? "-dddKt " : "",
8409 (dut->hostapd_debug_log && dut->hostapd_debug_log[0]) ?
8410 "-f " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008411 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008412 dut->hostapd_entropy_log ? " -e" : "",
8413 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Alexei Avshalom Lazarc9bc15d2020-01-29 10:52:13 +02008414 "",
8415 dut->sigma_tmpdir);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008416 } else {
8417 /*
8418 * It looks like a monitor interface can cause some issues for
8419 * beaconing, so remove it (if injection was used) before
8420 * starting hostapd.
8421 */
8422 if (if_nametoindex("sigmadut") > 0 &&
8423 system("iw dev sigmadut del") != 0)
8424 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8425 "monitor interface");
8426
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008427 snprintf(path, sizeof(path), "%shostapd",
8428 file_exists("hostapd") ? "./" : "");
Alexei Avshalom Lazarc9bc15d2020-01-29 10:52:13 +02008429 snprintf(buf, sizeof(buf),
8430 "%s -B%s%s%s%s%s%s %s/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008431 dut->hostapd_bin ? dut->hostapd_bin : path,
Alexei Avshalom Lazar04a17af2020-01-26 16:16:47 +02008432 dut->hostapd_debug_log ? " -dddKt" : "",
8433 (dut->hostapd_debug_log && dut->hostapd_debug_log[0]) ?
8434 " -f " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008435 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
8436 dut->hostapd_entropy_log ? " -e" : "",
8437 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008438 "",
8439 dut->use_hostapd_pid_file ?
Alexei Avshalom Lazarc9bc15d2020-01-29 10:52:13 +02008440 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "",
8441 dut->sigma_tmpdir);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008442 }
8443
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008444 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008445 if (system(buf) != 0) {
8446 send_resp(dut, conn, SIGMA_ERROR,
8447 "errorCode,Failed to start hostapd");
8448 return 0;
8449 }
8450
8451 /* allow some time for hostapd to start before returning success */
8452 usleep(500000);
8453 if (run_hostapd_cli(dut, "ping") != 0) {
8454 send_resp(dut, conn, SIGMA_ERROR,
8455 "errorCode,Failed to talk to hostapd");
8456 return 0;
8457 }
8458
Qiwei Caib6806972020-01-15 13:52:11 +08008459 if (dut->ap_ba_bufsize != BA_BUFSIZE_NOT_SET) {
8460 int buf_size;
8461
8462 if (dut->ap_ba_bufsize == BA_BUFSIZE_256)
8463 buf_size = 256;
8464 else
8465 buf_size = 64;
8466
8467 if ((drv == DRIVER_WCN || drv == DRIVER_LINUX_WCN) &&
8468 sta_set_addba_buf_size(dut, ifname, buf_size)) {
8469 send_resp(dut, conn, SIGMA_ERROR,
8470 "ErrorCode,set_addba_buf_size failed");
8471 return STATUS_SENT_ERROR;
8472 }
8473
8474 sigma_dut_print(dut, DUT_MSG_INFO,
8475 "setting addba buf_size=%d", buf_size);
8476 }
8477
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308478 if (drv == DRIVER_LINUX_WCN) {
Hu Wangf5cb9002019-08-21 14:18:57 +08008479 const char *ifname_ptr = ifname;
8480
8481 if ((dut->ap_key_mgmt == AP_OPEN &&
8482 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) ||
8483 (dut->ap_key_mgmt == AP_WPA2_OWE &&
8484 dut->ap_tag_ssid[0][0] &&
8485 dut->ap_tag_key_mgmt[0] == AP2_OPEN)) {
8486 /* OWE transition mode */
8487 if (dut->bridge)
8488 ifname_ptr = dut->bridge;
8489 }
8490
8491 sigma_dut_print(dut, DUT_MSG_INFO,
8492 "setting ip addr %s mask %s ifname %s",
8493 ap_inet_addr, ap_inet_mask, ifname_ptr);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308494 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Hu Wangf5cb9002019-08-21 14:18:57 +08008495 ifname_ptr, ap_inet_addr, ap_inet_mask);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308496 if (system(buf) != 0) {
8497 sigma_dut_print(dut, DUT_MSG_ERROR,
8498 "Failed to initialize the interface");
8499 return -1;
8500 }
8501 }
8502
Kiran Kumar Lokere6c4cf872020-02-05 22:37:50 -08008503 /* Configure the driver with LDPC setting for AP mode as a new vdev is
8504 * created when hostapd is started.
8505 */
8506 if (drv == DRIVER_WCN || drv == DRIVER_LINUX_WCN)
8507 wcn_config_ap_ldpc(dut, ifname);
8508
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008509 if (dut->ap_l2tif) {
8510 snprintf(path, sizeof(path),
8511 "/sys/class/net/%s/brport/hairpin_mode",
8512 ifname);
8513 if (!file_exists(path)) {
8514 sigma_dut_print(dut, DUT_MSG_ERROR,
8515 "%s must be binded to the bridge for L2TIF",
8516 ifname);
8517 return -2;
8518 }
8519
8520 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
8521 if (system(buf) != 0) {
8522 sigma_dut_print(dut, DUT_MSG_ERROR,
8523 "Failed to enable hairpin_mode for L2TIF");
8524 return -2;
8525 }
8526
8527 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
8528 if (system(buf) != 0) {
8529 sigma_dut_print(dut, DUT_MSG_ERROR,
8530 "Failed to set ebtables rules, RULE-9");
8531 return -2;
8532 }
8533
8534 snprintf(buf, sizeof(buf),
8535 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
8536 ifname);
8537 if (system(buf) != 0) {
8538 sigma_dut_print(dut, DUT_MSG_ERROR,
8539 "Failed to set ebtables rules, RULE-11");
8540 return -2;
8541 }
8542 }
8543
8544 if (dut->ap_proxy_arp) {
8545 if (dut->ap_dgaf_disable) {
8546 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
8547 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
8548 return -2;
8549 } else {
8550 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
8551 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
8552 return -2;
8553 }
8554
8555 /* For 4.5-(c) */
8556 snprintf(buf, sizeof(buf),
8557 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
8558 ifname);
8559 if (system(buf) != 0) {
8560 sigma_dut_print(dut, DUT_MSG_ERROR,
8561 "Failed to set ebtables rules, RULE-10");
8562 return -2;
8563 }
8564 }
8565
8566 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
8567 /* Drop TDLS frames */
8568 snprintf(buf, sizeof(buf),
8569 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
8570 if (system(buf) != 0) {
8571 sigma_dut_print(dut, DUT_MSG_ERROR,
8572 "Failed to set ebtables rules, RULE-13");
8573 return -2;
8574 }
8575 }
8576
8577 if (dut->ap_fake_pkhash &&
8578 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
8579 send_resp(dut, conn, SIGMA_ERROR,
8580 "errorCode,Could not enable FakePubKey");
8581 return 0;
8582 }
8583
Alexei Avshalom Lazar059abce2020-01-21 14:45:14 +02008584 if (dut->program == PROGRAM_60GHZ) {
8585 if (dut->ap_num_ese_allocs > 0) {
8586 /* wait extra time for AP to start */
8587 sleep(2);
8588 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
8589 dut->ap_ese_allocs)) {
8590 send_resp(dut, conn, SIGMA_ERROR,
8591 "errorCode,Could not set ExtSch");
8592 return 0;
8593 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008594 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008595 if (dut->ap_fixed_rate) {
8596 sigma_dut_print(dut, DUT_MSG_DEBUG,
8597 "forcing TX MCS index %d",
8598 dut->ap_mcs);
8599 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
8600 send_resp(dut, conn, SIGMA_ERROR,
8601 "errorCode,Could not force MCS");
8602 return -2;
8603 }
8604 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008605 }
8606
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008607 if (dut->wps_forced_version) {
8608 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
8609 dut->wps_forced_version);
8610 if (hapd_command(ifname, buf) < 0) {
8611 send_resp(dut, conn, SIGMA_ERROR,
8612 "errorCode,Fail to set wps_version_number");
8613 return STATUS_SENT;
8614 }
8615 }
8616
Jouni Malinend86e5822017-08-29 03:55:32 +03008617 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008618 return 1;
8619}
8620
8621
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308622static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
8623 struct qos_params *qos, const char *cwmin,
8624 const char *cwmax, const char *aifs,
8625 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008626{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308627 int val;
8628
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008629 if (cwmin) {
8630 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308631 val = atoi(cwmin);
8632 if (val < 0 || val > 15) {
8633 send_resp(dut, conn, SIGMA_INVALID,
8634 "errorCode,Invalid cwMin");
8635 return 0;
8636 }
8637 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008638 }
8639
8640 if (cwmax) {
8641 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308642 val = atoi(cwmax);
8643 if (val < 0 || val > 15) {
8644 send_resp(dut, conn, SIGMA_INVALID,
8645 "errorCode,Invalid cwMax");
8646 return 0;
8647 }
8648 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008649 }
8650
8651 if (aifs) {
8652 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308653 val = atoi(aifs);
8654 if (val < 1 || val > 255) {
8655 send_resp(dut, conn, SIGMA_INVALID,
8656 "errorCode,Invalid AIFS");
8657 return 0;
8658 }
8659 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008660 }
8661
8662 if (txop) {
8663 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308664 val = atoi(txop);
8665 if (val < 0 || val > 0xffff) {
8666 send_resp(dut, conn, SIGMA_INVALID,
8667 "errorCode,Invalid txop");
8668 return 0;
8669 }
8670 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008671 }
8672
8673 if (acm) {
8674 qos->ac = 1;
8675 qos->acm = strcasecmp(acm, "on") == 0;
8676 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308677
8678 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679}
8680
8681
Jouni Malinenf7222712019-06-13 01:50:21 +03008682static enum sigma_cmd_result cmd_ap_set_apqos(struct sigma_dut *dut,
8683 struct sigma_conn *conn,
8684 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008685{
8686 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308687 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
8688 get_param(cmd, "cwmin_VO"),
8689 get_param(cmd, "cwmax_VO"),
8690 get_param(cmd, "AIFS_VO"),
8691 get_param(cmd, "TXOP_VO"),
8692 get_param(cmd, "ACM_VO")) ||
8693 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
8694 get_param(cmd, "cwmin_VI"),
8695 get_param(cmd, "cwmax_VI"),
8696 get_param(cmd, "AIFS_VI"),
8697 get_param(cmd, "TXOP_VI"),
8698 get_param(cmd, "ACM_VI")) ||
8699 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
8700 get_param(cmd, "cwmin_BE"),
8701 get_param(cmd, "cwmax_BE"),
8702 get_param(cmd, "AIFS_BE"),
8703 get_param(cmd, "TXOP_BE"),
8704 get_param(cmd, "ACM_BE")) ||
8705 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
8706 get_param(cmd, "cwmin_BK"),
8707 get_param(cmd, "cwmax_BK"),
8708 get_param(cmd, "AIFS_BK"),
8709 get_param(cmd, "TXOP_BK"),
8710 get_param(cmd, "ACM_BK")))
8711 return 0;
8712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008713 return 1;
8714}
8715
8716
Jouni Malinenf7222712019-06-13 01:50:21 +03008717static enum sigma_cmd_result cmd_ap_set_staqos(struct sigma_dut *dut,
8718 struct sigma_conn *conn,
8719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308721 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
8722 get_param(cmd, "cwmin_VO"),
8723 get_param(cmd, "cwmax_VO"),
8724 get_param(cmd, "AIFS_VO"),
8725 get_param(cmd, "TXOP_VO"),
8726 get_param(cmd, "ACM_VO")) ||
8727 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
8728 get_param(cmd, "cwmin_VI"),
8729 get_param(cmd, "cwmax_VI"),
8730 get_param(cmd, "AIFS_VI"),
8731 get_param(cmd, "TXOP_VI"),
8732 get_param(cmd, "ACM_VI")) ||
8733 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
8734 get_param(cmd, "cwmin_BE"),
8735 get_param(cmd, "cwmax_BE"),
8736 get_param(cmd, "AIFS_BE"),
8737 get_param(cmd, "TXOP_BE"),
8738 get_param(cmd, "ACM_BE")) ||
8739 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
8740 get_param(cmd, "cwmin_BK"),
8741 get_param(cmd, "cwmax_BK"),
8742 get_param(cmd, "AIFS_BK"),
8743 get_param(cmd, "TXOP_BK"),
8744 get_param(cmd, "ACM_BK")))
8745 return 0;
8746
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008747 return 1;
8748}
8749
8750
8751static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
8752{
8753 unsigned char bssid[6];
8754 char buf[100];
8755 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
8756 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
8757 run_system(dut, "cfg -a AP_SECMODE=WPA");
8758 run_system(dut, "cfg -a AP_SECFILE=EAP");
8759 run_system(dut, "cfg -a AP_WPA=2");
8760 run_system(dut, "cfg -a AP_CYPHER=CCMP");
8761 run_system(dut, "cfg -a AP_HOTSPOT=1");
8762 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
8763 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
8764 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
8765 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
8766 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
8767 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
8768 if (!get_hwaddr("ath0", bssid)) {
8769 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8770 "%02x:%02x:%02x:%02x:%02x:%02x",
8771 bssid[0], bssid[1], bssid[2], bssid[3],
8772 bssid[4], bssid[5]);
8773 run_system(dut, buf);
8774 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8775 "%02x:%02x:%02x:%02x:%02x:%02x",
8776 bssid[0], bssid[1], bssid[2], bssid[3],
8777 bssid[4], bssid[5]);
8778 } else {
8779 if (!get_hwaddr("wifi0", bssid)) {
8780 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8781 "%02x:%02x:%02x:%02x:%02x:%02x",
8782 bssid[0], bssid[1], bssid[2], bssid[3],
8783 bssid[4], bssid[5]);
8784 run_system(dut, buf);
8785 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8786 "%02x:%02x:%02x:%02x:%02x:%02x",
8787 bssid[0], bssid[1], bssid[2], bssid[3],
8788 bssid[4], bssid[5]);
8789 } else {
8790 /* load the driver and try again */
8791 run_system(dut, "/etc/rc.d/rc.wlan up");
8792
8793 if (!get_hwaddr("wifi0", bssid)) {
8794 snprintf(buf, sizeof(buf),
8795 "cfg -a AP_HOTSPOT_HESSID="
8796 "%02x:%02x:%02x:%02x:%02x:%02x",
8797 bssid[0], bssid[1], bssid[2],
8798 bssid[3], bssid[4], bssid[5]);
8799 run_system(dut, buf);
8800 snprintf(dut->ap_hessid,
8801 sizeof(dut->ap_hessid),
8802 "%02x:%02x:%02x:%02x:%02x:%02x",
8803 bssid[0], bssid[1], bssid[2],
8804 bssid[3], bssid[4], bssid[5]);
8805 }
8806 }
8807 }
8808
8809 run_system(dut, "cfg -r AP_SSID_2");
8810 run_system(dut, "cfg -c");
8811 /* run_system(dut, "cfg -s"); */
8812}
8813
8814
8815static void ath_reset_vht_defaults(struct sigma_dut *dut)
8816{
8817 run_system(dut, "cfg -x");
8818 run_system(dut, "cfg -a AP_RADIO_ID=1");
8819 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
8820 run_system(dut, "cfg -a AP_STARTMODE=standard");
8821 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
8822 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
8823 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
8824 run_system(dut, "cfg -a ATH_countrycode=0x348");
8825 /* NOTE: For Beeliner we have to turn off MU-MIMO */
8826 if (system("rm /tmp/secath*") != 0) {
8827 sigma_dut_print(dut, DUT_MSG_ERROR,
8828 "Failed to remove secath file");
8829 }
8830}
8831
8832
Jouni Malinenf7222712019-06-13 01:50:21 +03008833static enum sigma_cmd_result cmd_ap_reset_default(struct sigma_dut *dut,
8834 struct sigma_conn *conn,
8835 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008836{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308837 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308838 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008839 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008840 int i;
8841
8842 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
8843 /*
8844 * Reset all tagged SSIDs to NULL-string and all key management
8845 * to open.
8846 */
8847 dut->ap_tag_ssid[i][0] = '\0';
8848 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
8849 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008850
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008851 drv = get_driver_type(dut);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308852
8853 program = get_param(cmd, "program");
8854 if (!program)
8855 program = get_param(cmd, "prog");
8856 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008857 dut->device_type = AP_unknown;
8858 type = get_param(cmd, "type");
8859 if (type && strcasecmp(type, "Testbed") == 0)
8860 dut->device_type = AP_testbed;
8861 if (type && strcasecmp(type, "DUT") == 0)
8862 dut->device_type = AP_dut;
8863
8864 dut->ap_rts = 0;
8865 dut->ap_frgmnt = 0;
8866 dut->ap_bcnint = 0;
8867 dut->ap_key_mgmt = AP_OPEN;
8868 dut->ap_ssid[0] = '\0';
8869 dut->ap_fake_pkhash = 0;
8870 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
8871 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008872 dut->ap_addba_reject = VALUE_NOT_SET;
8873 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008874 dut->ap_is_dual = 0;
8875 dut->ap_mode = AP_inval;
8876 dut->ap_mode_1 = AP_inval;
8877
8878 dut->ap_allow_vht_wep = 0;
8879 dut->ap_allow_vht_tkip = 0;
8880 dut->ap_disable_protection = 0;
8881 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008882 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
8883 dut->ap_ldpc = VALUE_NOT_SET;
8884 dut->ap_sig_rts = VALUE_NOT_SET;
8885 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008886 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05308887 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008888 dut->ap_chwidth = AP_AUTO;
8889
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05308890 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008891 dut->ap_wpsnfc = 0;
8892 dut->ap_bss_load = -1;
8893 dut->ap_p2p_cross_connect = -1;
8894
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308895 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
8896 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05308897 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308898
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008899 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008900 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08008901 dut->ap_interface_5g = 0;
8902 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08008903 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008904
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008905 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008906 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008907 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008908
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308909 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308910 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308911 dut->ap_wmmps = AP_WMMPS_ON;
8912 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308913 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308914 dut->ap_wmmps = AP_WMMPS_OFF;
8915 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308916
Jouni Malinen54a89b02018-05-01 00:16:26 +03008917 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03008918 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03008919 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03008920 dut->ap_tnc_file_name = 0;
8921 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03008922
Jouni Malinenda5f35b2019-03-26 00:25:53 +02008923 dut->ap_akm_values = 0;
Jouni Malinen09550de2019-03-26 00:24:11 +02008924 free(dut->ap_sae_passwords);
8925 dut->ap_sae_passwords = NULL;
8926
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008927 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008928 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008929 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008930 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008931
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008932 if (drv == DRIVER_ATHEROS)
8933 cmd_ath_ap_hs2_reset(dut);
8934 else if (drv == DRIVER_OPENWRT)
8935 cmd_owrt_ap_hs2_reset(dut);
8936
8937 dut->ap_interworking = 1;
8938 dut->ap_access_net_type = 2;
8939 dut->ap_internet = 0;
8940 dut->ap_venue_group = 2;
8941 dut->ap_venue_type = 8;
8942 dut->ap_domain_name_list[0] = '\0';
8943 dut->ap_hs2 = 1;
8944 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
8945 "506f9a;001bc504bd");
8946 dut->ap_l2tif = 0;
8947 dut->ap_proxy_arp = 0;
8948 if (dut->bridge) {
8949 char buf[50];
8950
8951 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
8952 dut->bridge);
8953 if (system(buf) != 0) {
8954 sigma_dut_print(dut, DUT_MSG_DEBUG,
8955 "%s ip neigh table flushing failed",
8956 dut->bridge);
8957 }
8958
8959 snprintf(buf, sizeof(buf), "ebtables -F");
8960 if (system(buf) != 0) {
8961 sigma_dut_print(dut, DUT_MSG_DEBUG,
8962 "%s ebtables flushing failed",
8963 dut->bridge);
8964 }
8965 }
8966 dut->ap_dgaf_disable = 0;
8967 dut->ap_p2p_cross_connect = 0;
8968 dut->ap_gas_cb_delay = 0;
8969 dut->ap_nai_realm_list = 0;
8970 dut->ap_oper_name = 0;
8971 dut->ap_venue_name = 0;
8972 for (i = 0; i < 10; i++) {
8973 dut->ap_plmn_mcc[i][0] = '\0';
8974 dut->ap_plmn_mnc[i][0] = '\0';
8975 }
8976 dut->ap_wan_metrics = 0;
8977 dut->ap_conn_capab = 0;
8978 dut->ap_ip_addr_type_avail = 0;
8979 dut->ap_net_auth_type = 0;
8980 dut->ap_oper_class = 0;
8981 dut->ap_pmf = 0;
8982 dut->ap_add_sha256 = 0;
8983 }
8984
Jouni Malinenba630452018-06-22 11:49:59 +03008985 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
8986 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008987 int i;
8988 const char hessid[] = "50:6f:9a:00:11:22";
8989
8990 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
8991 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008992 dut->ap_pmf = 1;
8993 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02008994 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008995 for (i = 0; i < 10; i++) {
8996 dut->ap_osu_server_uri[i][0] = '\0';
8997 dut->ap_osu_method[i] = 0xFF;
8998 }
8999 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009000 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009001 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02009002 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009003 dut->ap_osu_icon_tag = 0;
9004 }
9005
9006 if (dut->program == PROGRAM_VHT) {
9007 /* Set up the defaults */
Jouni Malinen00535472019-11-06 19:43:35 +02009008 dut->use_5g = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009009 dut->ap_mode = AP_11ac;
9010 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02009011 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08009012 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009013 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02009014 dut->ap_amsdu = VALUE_DISABLED;
9015 dut->ap_ldpc = VALUE_DISABLED;
9016 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009017 dut->ap_sgi80 = 0;
9018 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02009019 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05309020 /*
9021 * As LDPC is optional, don't enable this by default
9022 * for LINUX-WCN driver. The ap_set_wireless command
9023 * can be used to enable LDPC, when needed.
9024 */
9025 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02009026 dut->ap_ldpc = VALUE_ENABLED;
9027 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009028 dut->ap_sgi80 = 1;
9029 }
9030 dut->ap_fixed_rate = 0;
9031 dut->ap_rx_streams = 3;
9032 dut->ap_tx_streams = 3;
9033 dut->ap_vhtmcs_map = 0;
9034 dut->ap_chwidth = AP_80;
9035 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02009036 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05309037 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9038 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009039 if (get_driver_type(dut) == DRIVER_ATHEROS)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009040 ath_reset_vht_defaults(dut);
9041 }
9042
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07009043 if (dut->program == PROGRAM_IOTLP) {
9044 dut->wnm_bss_max_feature = VALUE_DISABLED;
9045 dut->wnm_bss_max_idle_time = 0;
9046 dut->wnm_bss_max_protection = VALUE_NOT_SET;
9047 dut->ap_proxy_arp = 1;
9048 } else {
9049 /*
9050 * Do not touch the BSS-MAX Idle time feature
9051 * if the program is not IOTLP.
9052 */
9053 dut->wnm_bss_max_feature = VALUE_NOT_SET;
9054 dut->wnm_bss_max_idle_time = 0;
9055 dut->wnm_bss_max_protection = VALUE_NOT_SET;
9056 }
9057
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009058 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07009059 dut->ap_rrm = 1;
9060 dut->ap_rtt = 1;
9061 dut->ap_lci = 0;
9062 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07009063 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07009064 dut->ap_lcr = 0;
9065 dut->ap_val_lcr[0] = '\0';
9066 dut->ap_neighap = 0;
9067 dut->ap_opchannel = 0;
9068 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07009069 dut->ap_fqdn_held = 0;
9070 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07009071 dut->ap_interworking = 0;
9072 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009073 dut->ap_msnt_type = 0;
9074 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07009075 dut->ap_ft_oa = 0;
Jouni Malinen9f943312019-08-19 23:49:16 +03009076 dut->ap_ft_ds = VALUE_NOT_SET;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07009077 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07009078 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009079
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009080 if (dut->program == PROGRAM_MBO) {
9081 dut->ap_mbo = 1;
9082 dut->ap_interworking = 1;
9083 dut->ap_ne_class = 0;
9084 dut->ap_ne_op_ch = 0;
9085 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009086 dut->ap_btmreq_disassoc_imnt = 0;
9087 dut->ap_btmreq_term_bit = 0;
9088 dut->ap_disassoc_timer = 0;
9089 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07009090 dut->ap_channel = 36;
9091 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07009092 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07009093 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009094 dut->mbo_self_ap_tuple.ap_ne_class = -1;
9095 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
9096 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009097 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009098 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009099 }
9100
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08009101 if (dut->program == PROGRAM_OCE) {
9102 if (dut->ap_dhcp_stop)
9103 run_system(dut, "/etc/init.d/dnsmasq start");
9104
9105 dut->ap_dhcp_stop = 0;
9106 dut->ap_oce = VALUE_ENABLED;
9107 dut->ap_broadcast_ssid = VALUE_ENABLED;
9108 dut->ap_fils_dscv_int = 20;
9109 dut->ap_filsdscv = VALUE_ENABLED;
9110 dut->ap_filshlp = VALUE_DISABLED;
9111 dut->ap_rnr = VALUE_DISABLED;
9112 dut->ap_nairealm[0] = '\0';
9113 dut->ap_nairealm_int = 0;
9114 dut->ap_blechanutil = 0;
9115 dut->ap_ble_admit_cap = 0;
9116 dut->ap_esp = VALUE_ENABLED;
9117 dut->ap_datappdudura = 0;
9118 dut->ap_airtimefract = 0;
9119 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08009120 dut->ap_ul_availcap = 0;
9121 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08009122 dut->ap_akm = 0;
9123 dut->ap_add_sha256 = 0;
9124 dut->ap_add_sha384 = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08009125 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08009126 }
9127
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07009128 dut->ap_he_ppdu = PPDU_NOT_SET;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009129 dut->ap_he_ulofdma = VALUE_NOT_SET;
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07009130 dut->ap_numsounddim = 0;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009131 dut->ap_bcc = VALUE_DISABLED;
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07009132 dut->ap_mu_edca = VALUE_DISABLED;
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07009133 dut->ap_he_mimo = MIMO_NOT_SET;
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07009134 dut->ap_he_rtsthrshld = VALUE_NOT_SET;
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07009135 dut->ap_mbssid = VALUE_DISABLED;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08009136 dut->ap_ampdu = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009137 dut->he_mcsnssmap = 0;
9138 dut->ap_fixed_rate = 0;
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08009139 dut->he_mmss = 0;
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08009140 dut->he_set_sta_1x1 = VALUE_DISABLED;
Priyadharshini Gowthaman88d55c82019-12-12 14:31:46 -08009141 dut->he_srctrl_allow = -1;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009142 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009143 dut->ap_he_dlofdma = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009144 dut->ap_he_frag = VALUE_DISABLED;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07009145 dut->ap_twtresp = VALUE_DISABLED;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009146 dut->he_ul_mcs = 7;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009147 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009148 dut->ap_he_dlofdma = VALUE_NOT_SET;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009149 dut->ap_he_frag = VALUE_NOT_SET;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009150 dut->ap_ba_bufsize = BA_BUFSIZE_NOT_SET;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07009151 dut->ap_twtresp = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009152 dut->he_ul_mcs = 0;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009153 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07009154
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009155 if (dut->program == PROGRAM_HE) {
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009156 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009157 dut->ap_ldpc = VALUE_DISABLED;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009158 dut->ap_ba_bufsize = BA_BUFSIZE_64;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08009159 dut->ap_amsdu = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08009160 dut->ap_txBF = 0;
9161 dut->ap_mu_txBF = 0;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08009162 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08009163 } else {
bingsb24b7902019-12-11 14:45:44 +08009164 if (drv == DRIVER_WCN || drv == DRIVER_LINUX_WCN) {
9165 dut->ap_txBF = 0;
9166 dut->ap_mu_txBF = 0;
9167 } else {
9168 dut->ap_txBF = 1;
9169 dut->ap_mu_txBF = 1;
9170 }
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08009171 dut->he_sounding = VALUE_ENABLED;
bings78387032019-12-06 17:50:05 +08009172 if (drv == DRIVER_LINUX_WCN) {
9173 dut->ap_ldpc = VALUE_ENABLED;
9174 wcn_config_ap_ldpc(dut, get_main_ifname(dut));
Kiran Kumar Lokereff979472020-01-22 11:15:59 -08009175#ifdef NL80211_SUPPORT
9176 if (wcn_set_he_ltf(dut, get_main_ifname(dut),
9177 QCA_WLAN_HE_LTF_AUTO)) {
9178 sigma_dut_print(dut, DUT_MSG_ERROR,
9179 "Failed to set LTF in ap_reset_default");
9180 }
9181#endif /* NL80211_SUPPORT */
bings78387032019-12-06 17:50:05 +08009182 }
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009183 }
Priyadharshini Gowthaman115c79d2019-11-13 15:23:08 -08009184 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9185 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009186 }
9187
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08009188 dut->ap_oper_chn = 0;
9189
Jouni Malinenb75c5322019-06-14 01:47:43 +03009190 dut->ap_pmksa = 0;
9191 dut->ap_pmksa_caching = 0;
9192
Jouni Malinen3c367e82017-06-23 17:01:47 +03009193 free(dut->rsne_override);
9194 dut->rsne_override = NULL;
Jouni Malinen7960e3a2019-12-07 17:04:35 +02009195 free(dut->rsnxe_override_eapol);
9196 dut->rsnxe_override_eapol = NULL;
Jouni Malinen3c367e82017-06-23 17:01:47 +03009197
Jouni Malinen68143132017-09-02 02:34:08 +03009198 free(dut->sae_commit_override);
9199 dut->sae_commit_override = NULL;
9200
Jouni Malinened670f42017-08-31 01:39:28 +03009201 free(dut->ap_sae_groups);
9202 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03009203
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009204 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03009205 dut->sae_reflection = 0;
Jouni Malinen3c740ab2019-10-10 15:55:11 +03009206 dut->sae_confirm_immediate = 0;
Jouni Malinen11e55212019-11-22 21:46:59 +02009207 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009208
Jouni Malinen3d633da2017-09-14 22:19:21 +03009209 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02009210 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03009211 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02009212 dut->ap_passphrase[0] = '\0';
9213 dut->ap_psk[0] = '\0';
Jouni Malinen05d005a2020-03-26 12:49:33 +02009214 dut->ap_beacon_prot = 0;
Jouni Malinenc098c442020-03-26 13:01:50 +02009215 dut->ap_transition_disable = 0;
Jouni Malinen3d633da2017-09-14 22:19:21 +03009216
Jouni Malinend86e5822017-08-29 03:55:32 +03009217 dut->dpp_conf_id = -1;
Jouni Malinenba4f2d42019-10-04 16:13:41 +03009218 free(dut->ap_dpp_conf_addr);
9219 dut->ap_dpp_conf_addr = NULL;
9220 free(dut->ap_dpp_conf_pkhash);
9221 dut->ap_dpp_conf_pkhash = NULL;
Jouni Malinend86e5822017-08-29 03:55:32 +03009222
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009223 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009224 dut->ap_mode = AP_11ad;
9225 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009226 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009227 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02009228 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009229 dut->ap_fixed_rate = 0;
9230
9231 dut->dev_role = DEVROLE_AP;
9232
9233 sigma_dut_print(dut, DUT_MSG_DEBUG,
9234 "Setting msdu_size to MAX: 7912");
9235 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009236 get_main_ifname(dut));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009237
9238 if (system(buf) != 0) {
9239 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
9240 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009241 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009242 }
9243
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009244 if (ap_set_force_mcs(dut, 0, 1)) {
9245 sigma_dut_print(dut, DUT_MSG_ERROR,
9246 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009247 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009248 }
9249
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009250 if (set_ps(get_main_ifname(dut), dut, 1)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009251 sigma_dut_print(dut, DUT_MSG_ERROR,
9252 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009253 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009254 }
9255 }
9256
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009257 if (dut->program == PROGRAM_WPS &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009258 get_driver_type(dut) == DRIVER_WIL6210) {
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009259 /*
9260 * In 60 GHz WPS tests, we configure the AP OOB to
9261 * secure connection with a random passphrase.
9262 */
9263 char r[16], passphrase[65];
9264
9265 if (random_get_bytes(r, sizeof(r))) {
9266 sigma_dut_print(dut, DUT_MSG_ERROR,
9267 "Failed to get random bytes");
9268 return ERROR_SEND_STATUS;
9269 }
9270 if (base64_encode(r, sizeof(r),
9271 passphrase, sizeof(passphrase))) {
9272 sigma_dut_print(dut, DUT_MSG_ERROR,
9273 "Failed to generate random passphrase");
9274 return ERROR_SEND_STATUS;
9275 }
9276
9277 dut->ap_key_mgmt = AP_WPA2_PSK;
9278 dut->ap_cipher = AP_GCMP_128;
9279 strlcpy(dut->ap_passphrase, passphrase,
9280 sizeof(dut->ap_passphrase));
9281 sigma_dut_print(dut, DUT_MSG_DEBUG,
9282 "60G WPS: configure secure AP with random passphrase");
9283 }
9284
Jouni Malinend86e5822017-08-29 03:55:32 +03009285 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08009286
9287 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9288 return 1;
9289
Jouni Malinend6bf1b42017-06-23 17:51:01 +03009290 if (dut->use_hostapd_pid_file) {
9291 kill_hostapd_process_pid(dut);
9292 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
9293 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009294 int i;
9295 /* Wait some time to allow hostapd to complete cleanup before
9296 * starting a new process */
9297 for (i = 0; i < 10; i++) {
9298 usleep(500000);
9299 if (system("pidof hostapd") != 0)
9300 break;
9301 }
9302 }
9303
9304 if (if_nametoindex("sigmadut") > 0 &&
9305 system("iw dev sigmadut del") != 0)
9306 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
9307 "monitor interface");
9308
9309 return 1;
9310}
9311
9312
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309313int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
9314 struct sigma_cmd *cmd)
9315{
9316 return cmd_ap_reset_default(dut, conn, cmd);
9317}
9318
9319
Jouni Malinenf7222712019-06-13 01:50:21 +03009320static enum sigma_cmd_result cmd_ap_get_info(struct sigma_dut *dut,
9321 struct sigma_conn *conn,
9322 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009323{
9324 /* const char *name = get_param(cmd, "NAME"); */
9325 struct stat s;
9326 char resp[200];
9327 FILE *f;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009328 enum driver_type drv = get_driver_type(dut);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009329 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009330
9331 switch (drv) {
9332 case DRIVER_ATHEROS: {
9333 /* Atheros AP */
9334 struct utsname uts;
9335 char *version, athver[100];
9336
9337 if (stat("/proc/athversion", &s) != 0) {
9338 if (system("/etc/rc.d/rc.wlan up") != 0) {
9339 }
9340 }
9341
9342 athver[0] = '\0';
9343 f = fopen("/proc/athversion", "r");
9344 if (f) {
9345 if (fgets(athver, sizeof(athver), f)) {
9346 char *pos = strchr(athver, '\n');
9347 if (pos)
9348 *pos = '\0';
9349 }
9350 fclose(f);
9351 }
9352
9353 if (uname(&uts) == 0)
9354 version = uts.release;
9355 else
9356 version = "Unknown";
9357
9358 if (if_nametoindex("ath1") > 0)
Jouni Malinen3aa72862019-05-29 23:14:51 +03009359 res = snprintf(resp, sizeof(resp),
9360 "interface,ath0_24G ath1_5G,agent,1.0,version,%s/drv:%s",
9361 version, athver);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009362 else
Jouni Malinen3aa72862019-05-29 23:14:51 +03009363 res = snprintf(resp, sizeof(resp),
9364 "interface,ath0_24G,agent,1.0,version,%s/drv:%s",
9365 version, athver);
9366 if (res < 0 || res >= sizeof(resp))
9367 send_resp(dut, conn, SIGMA_ERROR, NULL);
9368 else
9369 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009370 return 0;
9371 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05309372 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009373 case DRIVER_MAC80211: {
9374 struct utsname uts;
9375 char *version;
9376
9377 if (uname(&uts) == 0)
9378 version = uts.release;
9379 else
9380 version = "Unknown";
9381
9382 if (if_nametoindex("wlan1") > 0)
9383 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
9384 "wlan1_5G,agent,1.0,version,%s", version);
9385 else
9386 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
9387 "agent,1.0,version,%s", version);
9388
9389 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9390 return 0;
9391 }
9392 case DRIVER_QNXNTO: {
9393 struct utsname uts;
9394 char *version;
9395
9396 if (uname(&uts) == 0)
9397 version = uts.release;
9398 else
9399 version = "Unknown";
9400 snprintf(resp, sizeof(resp),
9401 "interface,%s_any,agent,1.0,version,%s",
Jouni Malinen5ea30922019-11-04 17:39:25 +02009402 dut->main_ifname ? get_main_ifname(dut) : "NA",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009403 version);
9404 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9405 return 0;
9406 }
9407 case DRIVER_OPENWRT: {
9408 switch (get_openwrt_driver_type()) {
9409 case OPENWRT_DRIVER_ATHEROS: {
9410 struct utsname uts;
9411 char *version;
9412
9413 if (uname(&uts) == 0)
9414 version = uts.release;
9415 else
9416 version = "Unknown";
9417
9418 if (if_nametoindex("ath1") > 0)
9419 snprintf(resp, sizeof(resp),
9420 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
9421 version);
9422 else
9423 snprintf(resp, sizeof(resp),
9424 "interface,ath0_any,agent,1.0,version,%s",
9425 version);
9426
9427 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9428 return 0;
9429 }
9430 default:
9431 send_resp(dut, conn, SIGMA_ERROR,
9432 "errorCode,Unsupported openwrt driver");
9433 return 0;
9434 }
9435 }
9436 default:
9437 send_resp(dut, conn, SIGMA_ERROR,
9438 "errorCode,Unsupported driver");
9439 return 0;
9440 }
9441}
9442
9443
Jouni Malinenf7222712019-06-13 01:50:21 +03009444static enum sigma_cmd_result cmd_ap_deauth_sta(struct sigma_dut *dut,
9445 struct sigma_conn *conn,
9446 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009447{
9448 /* const char *name = get_param(cmd, "NAME"); */
9449 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009450 const char *val, *disconnect;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009451 char buf[100];
9452
9453 val = get_param(cmd, "MinorCode");
9454 if (val) {
9455 /* TODO: add support for P2P minor code */
9456 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
9457 "yet supported");
9458 return 0;
9459 }
9460
9461 val = get_param(cmd, "STA_MAC_ADDRESS");
9462 if (val == NULL)
9463 return -1;
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009464 disconnect = get_param(cmd, "disconnect");
9465 if (disconnect && strcasecmp(disconnect, "silent") == 0)
9466 snprintf(buf, sizeof(buf), "deauth %s tx=0", val);
9467 else
9468 snprintf(buf, sizeof(buf), "deauth %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009469 if (run_hostapd_cli(dut, buf) != 0)
9470 return -2;
9471
9472 return 1;
9473}
9474
9475
9476#ifdef __linux__
9477int inject_frame(int s, const void *data, size_t len, int encrypt);
9478int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009479#endif /* __linux__ */
9480
9481enum send_frame_type {
9482 DISASSOC, DEAUTH, SAQUERY
9483};
9484enum send_frame_protection {
9485 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9486};
9487
9488
9489static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9490 enum send_frame_type frame,
9491 enum send_frame_protection protected,
9492 const char *sta_addr)
9493{
9494#ifdef __linux__
9495 unsigned char buf[1000], *pos;
9496 int s, res;
9497 unsigned char addr_sta[6], addr_own[6];
9498 char *ifname;
9499 char cbuf[100];
9500 struct ifreq ifr;
9501
9502 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
9503 dut->ap_mode == AP_11ac) &&
9504 if_nametoindex("wlan1") > 0)
9505 ifname = "wlan1";
9506 else
9507 ifname = "wlan0";
9508
9509 if (hwaddr_aton(sta_addr, addr_sta) < 0)
9510 return -1;
9511
9512 s = socket(AF_INET, SOCK_DGRAM, 0);
9513 if (s < 0)
9514 return -1;
9515 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009516 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009517 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9518 perror("ioctl");
9519 close(s);
9520 return -1;
9521 }
9522 close(s);
9523 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
9524
9525 if (if_nametoindex("sigmadut") == 0) {
9526 snprintf(cbuf, sizeof(cbuf),
9527 "iw dev %s interface add sigmadut type monitor",
9528 ifname);
9529 if (system(cbuf) != 0 ||
9530 if_nametoindex("sigmadut") == 0) {
9531 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9532 "monitor interface with '%s'", cbuf);
9533 return -2;
9534 }
9535 }
9536
9537 if (system("ifconfig sigmadut up") != 0) {
9538 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9539 "monitor interface up");
9540 return -2;
9541 }
9542
9543 pos = buf;
9544
9545 /* Frame Control */
9546 switch (frame) {
9547 case DISASSOC:
9548 *pos++ = 0xa0;
9549 break;
9550 case DEAUTH:
9551 *pos++ = 0xc0;
9552 break;
9553 case SAQUERY:
9554 *pos++ = 0xd0;
9555 break;
9556 }
9557
9558 if (protected == INCORRECT_KEY)
9559 *pos++ = 0x40; /* Set Protected field to 1 */
9560 else
9561 *pos++ = 0x00;
9562
9563 /* Duration */
9564 *pos++ = 0x00;
9565 *pos++ = 0x00;
9566
9567 /* addr1 = DA (station) */
9568 memcpy(pos, addr_sta, 6);
9569 pos += 6;
9570 /* addr2 = SA (own address) */
9571 memcpy(pos, addr_own, 6);
9572 pos += 6;
9573 /* addr3 = BSSID (own address) */
9574 memcpy(pos, addr_own, 6);
9575 pos += 6;
9576
9577 /* Seq# (to be filled by driver/mac80211) */
9578 *pos++ = 0x00;
9579 *pos++ = 0x00;
9580
9581 if (protected == INCORRECT_KEY) {
9582 /* CCMP parameters */
9583 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9584 pos += 8;
9585 }
9586
9587 if (protected == INCORRECT_KEY) {
9588 switch (frame) {
9589 case DEAUTH:
9590 /* Reason code (encrypted) */
9591 memcpy(pos, "\xa7\x39", 2);
9592 pos += 2;
9593 break;
9594 case DISASSOC:
9595 /* Reason code (encrypted) */
9596 memcpy(pos, "\xa7\x39", 2);
9597 pos += 2;
9598 break;
9599 case SAQUERY:
9600 /* Category|Action|TransID (encrypted) */
9601 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9602 pos += 4;
9603 break;
9604 default:
9605 return -1;
9606 }
9607
9608 /* CCMP MIC */
9609 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9610 pos += 8;
9611 } else {
9612 switch (frame) {
9613 case DEAUTH:
9614 /* reason code = 8 */
9615 *pos++ = 0x08;
9616 *pos++ = 0x00;
9617 break;
9618 case DISASSOC:
9619 /* reason code = 8 */
9620 *pos++ = 0x08;
9621 *pos++ = 0x00;
9622 break;
9623 case SAQUERY:
9624 /* Category - SA Query */
9625 *pos++ = 0x08;
9626 /* SA query Action - Request */
9627 *pos++ = 0x00;
9628 /* Transaction ID */
9629 *pos++ = 0x12;
9630 *pos++ = 0x34;
9631 break;
9632 }
9633 }
9634
9635 s = open_monitor("sigmadut");
9636 if (s < 0) {
9637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9638 "monitor socket");
9639 return 0;
9640 }
9641
9642 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9643 if (res < 0) {
9644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9645 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309646 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009647 return 0;
9648 }
9649 if (res < pos - buf) {
9650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9651 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309652 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653 return 0;
9654 }
9655
9656 close(s);
9657
9658 return 1;
9659#else /* __linux__ */
9660 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
9661 "yet supported");
9662 return 0;
9663#endif /* __linux__ */
9664}
9665
9666
9667int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
9668 struct sigma_cmd *cmd)
9669{
9670 const char *val, *dest;
9671 char buf[100];
9672
9673 val = get_param(cmd, "FrameName");
9674 if (val == NULL)
9675 return -1;
9676
9677 if (strcasecmp(val, "QoSMapConfigure") == 0) {
9678 dest = get_param(cmd, "Dest");
9679 if (!dest)
9680 return -1;
9681
9682 val = get_param(cmd, "QoS_MAP_SET");
9683 if (val) {
9684 dut->ap_qos_map_set = atoi(val);
9685 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9686 dut->ap_qos_map_set);
9687 }
9688
9689 if (dut->ap_qos_map_set == 1)
9690 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9691 else if (dut->ap_qos_map_set == 2)
9692 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9693
9694 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9695 if (run_hostapd_cli(dut, buf) != 0)
9696 return -1;
9697 }
9698
9699 return 1;
9700}
9701
9702
9703static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9704 struct sigma_cmd *cmd)
9705{
9706 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009707 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009708 int chwidth, nss;
9709
9710 val = get_param(cmd, "FrameName");
9711 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
9712 send_resp(dut, conn, SIGMA_ERROR,
9713 "errorCode,Unsupported FrameName");
9714 return 0;
9715 }
9716
9717 /*
9718 * Sequence of commands for Opmode notification on
9719 * Peregrine based products
9720 */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009721 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009722
9723 /* Disable STBC */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009724 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009725
9726 /* Check whether optional arg channel width was passed */
9727 val = get_param(cmd, "Channel_width");
9728 if (val) {
9729 switch (atoi(val)) {
9730 case 20:
9731 chwidth = 0;
9732 break;
9733 case 40:
9734 chwidth = 1;
9735 break;
9736 case 80:
9737 chwidth = 2;
9738 break;
9739 case 160:
9740 chwidth = 3;
9741 break;
9742 default:
9743 chwidth = 2;
9744 break;
9745 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009746 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009747 }
9748
9749 /* Check whether optional arg NSS was passed */
9750 val = get_param(cmd, "NSS");
9751 if (val) {
9752 /* Convert nss to chainmask */
9753 switch (atoi(val)) {
9754 case 1:
9755 nss = 1;
9756 break;
9757 case 2:
9758 nss = 3;
9759 break;
9760 case 3:
9761 nss = 7;
9762 break;
9763 default:
9764 /* We do not support NSS > 3 */
9765 nss = 3;
9766 break;
9767 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009768 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009769 }
9770
9771 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009772 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009773
9774 return 1;
9775}
9776
9777
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009778static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9779 struct sigma_cmd *cmd)
9780{
9781 const char *val;
9782 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009783 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009784
9785 val = get_param(cmd, "MsntType");
9786 if (val) {
9787 if (dut->ap_msnt_type == 0)
9788 dut->ap_msnt_type = atoi(val);
9789
9790 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
9791 dut->ap_msnt_type = atoi(val);
9792 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009793 val = get_param(cmd, "RandInterval");
9794 if (val)
9795 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009796 f = fopen("/tmp/ftmrr.txt", "a");
9797 if (!f) {
9798 sigma_dut_print(dut, DUT_MSG_ERROR,
9799 "Failed to open /tmp/ftmrr.txt");
9800 return -1;
9801 }
9802
9803 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009804 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",
9805 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009806 fclose(f);
9807 dut->ap_msnt_type = 5;
9808 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9809 }
9810 } else if (dut->ap_msnt_type == 5) {
9811 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9812 } else if (dut->ap_msnt_type == 2) {
9813 f = fopen("/tmp/wru.txt", "w");
9814 if (!f) {
9815 sigma_dut_print(dut, DUT_MSG_ERROR,
9816 "Failed to open /tmp/wru.txt");
9817 return -1;
9818 }
9819
9820 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
9821 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
9822 fclose(f);
9823 run_system(dut, "wpc -w /tmp/wru.txt");
9824 }
9825 }
9826 return 1;
9827}
9828
9829
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009830/*
9831 * The following functions parse_send_frame_params_int(),
9832 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
9833 * are used by ath_ap_send_frame_bcn_rpt_req().
9834 * Beacon Report Request is a frame used as part of the MBO program.
9835 * The command for sending beacon report has a lot of
9836 * arguments and having these functions reduces code size.
9837 *
9838 */
9839static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
9840 struct sigma_dut *dut,
9841 char *buf, size_t buf_size)
9842{
9843 const char *str_val;
9844 int int_val;
9845 char temp[100];
9846
9847 str_val = get_param(cmd, param);
9848 if (!str_val) {
9849 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9850 return -1;
9851 }
9852 int_val = atoi(str_val);
9853 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07009854 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009855 return 0;
9856}
9857
9858
9859static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
9860 struct sigma_dut *dut,
9861 char *buf, size_t buf_size)
9862{
9863 const char *str_val;
9864 char temp[100];
9865
9866 str_val = get_param(cmd, param);
9867 if (!str_val) {
9868 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9869 return -1;
9870 }
9871 snprintf(temp, sizeof(temp), " %s", str_val);
9872 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07009873 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009874 return 0;
9875}
9876
9877
9878static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
9879 struct sigma_dut *dut,
9880 char *buf, size_t buf_size)
9881{
9882 const char *str_val;
9883 unsigned char mac[6];
9884 char temp[100];
9885
9886 str_val = get_param(cmd, param);
9887 if (!str_val) {
9888 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9889 return -1;
9890 }
9891
9892 if (parse_mac_address(dut, str_val, mac) < 0) {
9893 sigma_dut_print(dut, DUT_MSG_ERROR,
9894 "MAC Address not in proper format");
9895 return -1;
9896 }
9897 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
9898 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07009899 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009900 return 0;
9901}
9902
9903
9904static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
9905 char *buf, size_t buf_size)
9906{
9907 const char *str_val;
9908 char *value = " 1";
9909
9910 str_val = get_param(cmd, param);
9911 if (!str_val || str_val[0] == '\0')
9912 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07009913 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009914
9915}
9916
9917
9918/*
9919 * wifitool athN sendbcnrpt
9920 * <STA MAC - Plugs in from Dest_MAC>
9921 * <regclass - Plugs in from RegClass - int>
9922 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
9923 * <rand_ivl - Plugs in from RandInt - string>
9924 * <duration - Plugs in from MeaDur - integer>
9925 * <mode - Plugs in from MeaMode - string>
9926 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
9927 * <rep_cond - Plugs in from RptCond - integer>
9928 * <rpt_detail - Plugs in from RptDet - integer>
9929 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
9930 * <chanrpt_mode - Plugs in from APChanRpt - integer>
9931 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
9932 * [AP channel numbers]
9933 */
9934static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
9935 struct sigma_cmd *cmd,
9936 const char *ifname)
9937{
9938 char buf[100];
9939 int rpt_det;
9940 const char *str_val;
9941 const char *mea_mode;
9942
9943 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
9944
9945 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
9946 return -1;
9947 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
9948 return -1;
9949 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
9950 return -1;
9951 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
9952 return -1;
9953 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
9954 return -1;
9955
9956 str_val = get_param(cmd, "MeaMode");
9957 if (!str_val) {
9958 sigma_dut_print(dut, DUT_MSG_ERROR,
9959 "MeaMode parameter not present in send bcn-rpt-req");
9960 return -1;
9961 }
9962 if (strcasecmp(str_val, "passive") == 0) {
9963 mea_mode = " 0";
9964 } else if (strcasecmp(str_val, "active") == 0) {
9965 mea_mode = " 1";
9966 } else if (strcasecmp(str_val, "table") == 0) {
9967 mea_mode = " 2";
9968 } else {
9969 sigma_dut_print(dut, DUT_MSG_ERROR,
9970 "MEA-MODE Value not correctly given");
9971 return -1;
9972 }
Peng Xu591be452017-05-10 17:27:28 -07009973 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009974
9975 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
9976
9977 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
9978 return -1;
9979
9980 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
9981 return -1;
9982 str_val = get_param(cmd, "RptDet");
9983 rpt_det = str_val ? atoi(str_val) : 0;
9984
9985 if (rpt_det)
9986 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
9987 else
Peng Xu591be452017-05-10 17:27:28 -07009988 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009989
9990 if (rpt_det)
9991 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
9992 sizeof(buf));
9993 else
Peng Xu591be452017-05-10 17:27:28 -07009994 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009995
9996 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
9997 return -1;
9998
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009999 str_val = get_param(cmd, "APChanRpt");
10000 if (str_val) {
10001 const char *pos;
10002 int ap_chanrpt;
10003 int ap_chanrpt_2 = 0;
10004 char chanrpt[100];
10005
10006 ap_chanrpt = atoi(str_val);
10007 pos = strchr(str_val, '_');
10008 if (pos) {
10009 pos++;
10010 ap_chanrpt_2 = atoi(pos);
10011 }
10012 if (ap_chanrpt) {
10013 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
10014 strlcat(buf, chanrpt, sizeof(buf));
10015 }
10016 if (ap_chanrpt_2) {
10017 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
10018 strlcat(buf, chanrpt, sizeof(buf));
10019 }
10020 }
10021
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010022 run_system(dut, buf);
10023 return 0;
10024}
10025
10026
10027static void inform_and_sleep(struct sigma_dut *dut, int seconds)
10028{
10029 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
10030 sleep(seconds);
10031 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
10032 seconds);
10033}
10034
10035
10036static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
10037 struct sigma_cmd *cmd, const char *ifname)
10038{
10039 unsigned char mac_addr[ETH_ALEN];
10040 int disassoc_timer;
10041 char buf[100];
10042 const char *val;
10043 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010044
10045 val = get_param(cmd, "Dest_MAC");
10046 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
10047 sigma_dut_print(dut, DUT_MSG_ERROR,
10048 "MAC Address not in proper format");
10049 return -1;
10050 }
10051
10052 val = get_param(cmd, "Disassoc_Timer");
10053 if (val)
10054 disassoc_timer = atoi(val);
10055 else
10056 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +020010057 if (disassoc_timer < 0) {
10058 sigma_dut_print(dut, DUT_MSG_ERROR,
10059 "Invalid Disassoc_Timer value %d",
10060 disassoc_timer);
10061 return -1;
10062 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010063
10064 val = get_param(cmd, "Cand_List");
10065 if (val && val[0])
10066 cand_list = atoi(val);
10067
10068 val = get_param(cmd, "BTMQuery_Reason_Code");
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010069 if (val)
10070 run_iwpriv(dut, ifname, "mbo_trans_rs %s", val);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010071
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010072 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay)
10073 run_iwpriv(dut, ifname, "mbo_asoc_ret 1");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010074
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010075 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010076 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010077 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
10078 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
10079 dut->ap_btmreq_disassoc_imnt,
10080 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080010081 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010082 dut->ap_btmreq_bss_term_dur);
10083 run_system(dut, buf);
10084
10085 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080010086 if (dut->ap_btmreq_bss_term_tsf >= 2)
10087 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010088 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
10089 mac_addr[0], mac_addr[1], mac_addr[2],
10090 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010091 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010092 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010093 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010094 run_system_wrapper(dut, "ifconfig %s up", ifname);
10095 } else if (dut->ap_btmreq_disassoc_imnt) {
10096 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010097 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
10098 mac_addr[0], mac_addr[1], mac_addr[2],
10099 mac_addr[3], mac_addr[4], mac_addr[5]);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010100 }
10101 return 0;
10102}
10103
10104
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010105static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
10106 struct sigma_cmd *cmd, const char *ifname)
10107{
10108 unsigned char mac_addr[ETH_ALEN];
10109 const char *val;
10110
10111 val = get_param(cmd, "Dest_MAC");
10112 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
10113 sigma_dut_print(dut, DUT_MSG_ERROR,
10114 "MAC Address not in proper format");
10115 return -1;
10116 }
10117
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010118 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
10119 mac_addr[0], mac_addr[1], mac_addr[2],
10120 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010121 return 0;
10122}
10123
10124
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010125static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
10126 struct sigma_cmd *cmd)
10127{
10128 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010129 const char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010130
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010131 ifname = get_main_ifname(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010132
10133 val = get_param(cmd, "FrameName");
10134 if (!val)
10135 return -1;
10136
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010137 if (strcasecmp(val, "BTMReq") == 0)
10138 ath_ap_send_frame_btm_req(dut, cmd, ifname);
10139 else if (strcasecmp(val, "BcnRptReq") == 0)
10140 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010141 else if (strcasecmp(val, "disassoc") == 0)
10142 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010143 else
10144 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010145
10146 return 1;
10147}
10148
10149
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010150static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
10151 struct sigma_cmd *cmd)
10152{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010153 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010154 case DRIVER_ATHEROS:
10155 return ath_ap_send_frame_vht(dut, conn, cmd);
10156 break;
10157 case DRIVER_OPENWRT:
10158 switch (get_openwrt_driver_type()) {
10159 case OPENWRT_DRIVER_ATHEROS:
10160 return ath_ap_send_frame_vht(dut, conn, cmd);
10161 default:
10162 send_resp(dut, conn, SIGMA_ERROR,
10163 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
10164 return 0;
10165 }
10166 default:
10167 send_resp(dut, conn, SIGMA_ERROR,
10168 "errorCode,Unsupported ap_send_frame with the current driver");
10169 return 0;
10170 }
10171}
10172
10173
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010174static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
10175 struct sigma_cmd *cmd)
10176{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010177 switch (get_driver_type(dut)) {
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010178 case DRIVER_ATHEROS:
10179 return ath_ap_send_frame_loc(dut, conn, cmd);
10180 case DRIVER_OPENWRT:
10181 switch (get_openwrt_driver_type()) {
10182 case OPENWRT_DRIVER_ATHEROS:
10183 return ath_ap_send_frame_loc(dut, conn, cmd);
10184 default:
10185 send_resp(dut, conn, SIGMA_ERROR,
10186 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
10187 return 0;
10188 }
10189 default:
10190 send_resp(dut, conn, SIGMA_ERROR,
10191 "errorCode,Unsupported ap_send_frame_loc with the current driver");
10192 return 0;
10193 }
10194}
10195
10196
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010197static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
10198 struct sigma_cmd *cmd)
10199{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010200 switch (get_driver_type(dut)) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010201 case DRIVER_ATHEROS:
10202 return ath_ap_send_frame_mbo(dut, conn, cmd);
10203 case DRIVER_OPENWRT:
10204 switch (get_openwrt_driver_type()) {
10205 case OPENWRT_DRIVER_ATHEROS:
10206 return ath_ap_send_frame_mbo(dut, conn, cmd);
10207 default:
10208 send_resp(dut, conn, SIGMA_ERROR,
10209 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
10210 return 0;
10211 }
10212 default:
10213 send_resp(dut, conn, SIGMA_ERROR,
10214 "errorCode,Unsupported ap_send_frame with the current driver");
10215 return 0;
10216 }
10217}
10218
10219
Lior David0fe101e2017-03-09 16:09:50 +020010220static int ap_send_frame_60g(struct sigma_dut *dut,
10221 struct sigma_conn *conn,
10222 struct sigma_cmd *cmd)
10223{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010224 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010225#ifdef __linux__
10226 case DRIVER_WIL6210:
10227 return wil6210_send_frame_60g(dut, conn, cmd);
10228#endif /* __linux__ */
10229 default:
10230 send_resp(dut, conn, SIGMA_ERROR,
10231 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10232 return 0;
10233 }
10234}
10235
10236
Jouni Malinenf7222712019-06-13 01:50:21 +030010237enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
10238 struct sigma_conn *conn,
10239 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010240{
10241 /* const char *name = get_param(cmd, "NAME"); */
10242 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10243 const char *val;
10244 enum send_frame_type frame;
10245 enum send_frame_protection protected;
10246 char buf[100];
10247
10248 val = get_param(cmd, "Program");
10249 if (val) {
10250 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070010251 strcasecmp(val, "HS2-R2") == 0 ||
10252 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010253 return ap_send_frame_hs2(dut, conn, cmd);
10254 if (strcasecmp(val, "VHT") == 0)
10255 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010256 if (strcasecmp(val, "LOC") == 0)
10257 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010258 if (strcasecmp(val, "MBO") == 0)
10259 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010260 if (strcasecmp(val, "60GHz") == 0)
10261 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010262 }
10263
10264 val = get_param(cmd, "PMFFrameType");
10265 if (val == NULL)
10266 val = get_param(cmd, "FrameName");
10267 if (val == NULL)
10268 val = get_param(cmd, "Type");
10269 if (val == NULL)
10270 return -1;
10271 if (strcasecmp(val, "disassoc") == 0)
10272 frame = DISASSOC;
10273 else if (strcasecmp(val, "deauth") == 0)
10274 frame = DEAUTH;
10275 else if (strcasecmp(val, "saquery") == 0)
10276 frame = SAQUERY;
10277 else {
10278 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10279 "PMFFrameType");
10280 return 0;
10281 }
10282
10283 val = get_param(cmd, "PMFProtected");
10284 if (val == NULL)
10285 val = get_param(cmd, "Protected");
10286 if (val == NULL)
10287 return -1;
10288 if (strcasecmp(val, "Correct-key") == 0 ||
10289 strcasecmp(val, "CorrectKey") == 0)
10290 protected = CORRECT_KEY;
10291 else if (strcasecmp(val, "IncorrectKey") == 0)
10292 protected = INCORRECT_KEY;
10293 else if (strcasecmp(val, "Unprotected") == 0)
10294 protected = UNPROTECTED;
10295 else {
10296 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10297 "PMFProtected");
10298 return 0;
10299 }
10300
10301 val = get_param(cmd, "stationID");
10302 if (val == NULL)
10303 return -1;
10304
10305 if (protected == INCORRECT_KEY ||
10306 (protected == UNPROTECTED && frame == SAQUERY))
10307 return ap_inject_frame(dut, conn, frame, protected, val);
10308
10309 switch (frame) {
10310 case DISASSOC:
10311 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
10312 val, protected == CORRECT_KEY);
10313 break;
10314 case DEAUTH:
10315 snprintf(buf, sizeof(buf), "deauth %s test=%d",
10316 val, protected == CORRECT_KEY);
10317 break;
10318 case SAQUERY:
10319 snprintf(buf, sizeof(buf), "sa_query %s", val);
10320 break;
10321 }
10322
10323 if (run_hostapd_cli(dut, buf) != 0)
10324 return -2;
10325
10326 return 1;
10327}
10328
10329
Jouni Malinenf7222712019-06-13 01:50:21 +030010330static enum sigma_cmd_result cmd_ap_get_mac_address(struct sigma_dut *dut,
10331 struct sigma_conn *conn,
10332 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010333{
10334#if defined( __linux__)
10335 /* const char *name = get_param(cmd, "NAME"); */
10336 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +030010337 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010338 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010339 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010340 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010341 int s, wlan_tag = 1;
10342 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010343
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010344 val = get_param(cmd, "WLAN_TAG");
10345 if (val) {
10346 wlan_tag = atoi(val);
10347 if (wlan_tag < 1 || wlan_tag > 3) {
10348 /*
10349 * The only valid WLAN Tags as of now as per the latest
10350 * WFA scripts are 1, 2, and 3.
10351 */
Jouni Malinenf8984642017-10-12 00:02:37 +030010352 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010353 "errorCode,Unsupported WLAN_TAG");
10354 return 0;
10355 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010356 }
10357
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010358 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
10359
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010360 s = socket(AF_INET, SOCK_DGRAM, 0);
10361 if (s < 0)
10362 return -1;
10363 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -070010364 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010365 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
10366 perror("ioctl");
10367 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +030010368 snprintf(resp, sizeof(resp),
10369 "errorCode,Could not find interface %s", ifname);
10370 send_resp(dut, conn, SIGMA_ERROR, resp);
10371 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010372 }
10373 close(s);
10374 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
10375
10376 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10377 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10378 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10379 return 0;
10380#elif defined( __QNXNTO__)
10381 char resp[50];
10382 unsigned char addr[6];
10383
Jouni Malinend2095482019-11-04 17:10:43 +020010384 if (!dut->main_ifname) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010385 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
10386 return 0;
10387 }
10388
Jouni Malinen5ea30922019-11-04 17:39:25 +020010389 if (get_hwaddr(get_main_ifname(dut), addr) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010390 send_resp(dut, conn, SIGMA_ERROR,
10391 "errorCode,Failed to get address");
10392 return 0;
10393 }
10394 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10395 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10396 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10397 return 0;
10398#else /* __linux__ */
10399 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
10400 "yet supported");
10401 return 0;
10402#endif /* __linux__ */
10403}
10404
10405
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010406int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
10407 struct sigma_cmd *cmd)
10408{
10409 return cmd_ap_get_mac_address(dut, conn, cmd);
10410}
10411
10412
Jouni Malinenf7222712019-06-13 01:50:21 +030010413static enum sigma_cmd_result cmd_ap_set_pmf(struct sigma_dut *dut,
10414 struct sigma_conn *conn,
10415 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010416{
10417 /*
10418 * Ignore the command since the parameters are already handled through
10419 * ap_set_security.
10420 */
10421
10422 return 1;
10423}
10424
10425
Jouni Malinenf7222712019-06-13 01:50:21 +030010426static enum sigma_cmd_result cmd_ap_set_hs2(struct sigma_dut *dut,
10427 struct sigma_conn *conn,
10428 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010429{
10430 /* const char *name = get_param(cmd, "NAME"); */
10431 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10432 const char *val, *dest;
10433 char *pos, buf[100];
Jouni Malinen77dda642020-01-07 11:21:55 +020010434 int i, wlan_tag = 1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010435
10436 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
10437 "following parameters");
10438 for (i = 0; i < cmd->count; i++) {
10439 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
10440 (cmd->values[i] ? cmd->values[i] : "NULL"));
10441 }
10442
10443 val = get_param(cmd, "ICMPv4_ECHO");
10444 if (val && atoi(val)) {
10445 snprintf(buf, sizeof(buf), "ebtables -F");
10446 if (system(buf) != 0) {
10447 sigma_dut_print(dut, DUT_MSG_ERROR,
10448 "Failed to set ebtables rules, RULE-12");
10449 }
10450 return 1;
10451 }
10452
10453 val = get_param(cmd, "WLAN_TAG");
10454 if (val) {
10455 wlan_tag = atoi(val);
10456 if (wlan_tag != 1 && wlan_tag != 2) {
10457 send_resp(dut, conn, SIGMA_INVALID,
10458 "errorCode,Invalid WLAN_TAG");
10459 return 0;
10460 }
10461 }
10462
10463 if (wlan_tag == 2) {
10464 val = get_param(cmd, "PROXY_ARP");
10465 if (val)
10466 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +020010467
10468 val = get_param(cmd, "OSU");
10469 if (val)
10470 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010471 return 1;
10472 }
10473
10474 dest = get_param(cmd, "STA_MAC");
10475 if (dest) {
10476 /* This is a special/ugly way of using this command.
10477 * If "Dest" MAC is included, assume that this command
10478 * is being issued after ap_config_commit for dynamically
10479 * setting the QoS Map Set.
10480 */
10481 val = get_param(cmd, "QoS_MAP_SET");
10482 if (val) {
10483 dut->ap_qos_map_set = atoi(val);
10484 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10485 dut->ap_qos_map_set);
10486 }
10487
10488 if (dut->ap_qos_map_set == 1)
10489 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
10490 else if (dut->ap_qos_map_set == 2)
10491 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
10492
10493 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
10494 if (run_hostapd_cli(dut, buf) != 0)
10495 return -1;
10496 }
10497
10498 val = get_param(cmd, "DGAF_DISABLE");
10499 if (val)
10500 dut->ap_dgaf_disable = atoi(val);
10501
10502 dut->ap_interworking = 1;
10503
10504 val = get_param(cmd, "INTERWORKING");
10505 if (val == NULL)
10506 val = get_param(cmd, "INTERNETWORKING");
10507 if (val != NULL && atoi(val) == 0) {
10508 dut->ap_interworking = 0;
10509 dut->ap_hs2 = 0;
10510 return 1;
10511 }
10512
10513 val = get_param(cmd, "ACCS_NET_TYPE");
10514 if (val) {
10515 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
10516 strcasecmp(val, "Chargable_Public_Network") == 0 ||
10517 strcasecmp(val, "Chargable Public Network") == 0)
10518 dut->ap_access_net_type = 2;
10519 else
10520 dut->ap_access_net_type = atoi(val);
10521 }
10522
10523 val = get_param(cmd, "INTERNET");
10524 if (val)
10525 dut->ap_internet = atoi(val);
10526
10527 val = get_param(cmd, "VENUE_GRP");
10528 if (val) {
10529 if (strcasecmp(val, "Business") == 0)
10530 dut->ap_venue_group = 2;
10531 else
10532 dut->ap_venue_group = atoi(val);
10533 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10534 dut->ap_venue_name);
10535 }
10536
10537 val = get_param(cmd, "VENUE_TYPE");
10538 if (val) {
10539 if (strcasecmp(val, "R&D") == 0)
10540 dut->ap_venue_type = 8;
10541 else
10542 dut->ap_venue_type = atoi(val);
10543 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
10544 dut->ap_venue_type);
10545 }
10546
10547 val = get_param(cmd, "HESSID");
10548 if (val) {
10549 if (strlen(val) >= sizeof(dut->ap_hessid)) {
10550 send_resp(dut, conn, SIGMA_ERROR,
10551 "errorCode,Invalid HESSID");
10552 return 0;
10553 }
10554 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
10555 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
10556 dut->ap_hessid);
10557 }
10558
10559 val = get_param(cmd, "ROAMING_CONS");
10560 if (val) {
10561 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
10562 send_resp(dut, conn, SIGMA_ERROR,
10563 "errorCode,Invalid ROAMING_CONS");
10564 return 0;
10565 }
10566 if (strcasecmp(val, "Disabled") == 0) {
10567 dut->ap_roaming_cons[0] = '\0';
10568 } else {
10569 snprintf(dut->ap_roaming_cons,
10570 sizeof(dut->ap_roaming_cons), "%s", val);
10571 }
10572 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
10573 dut->ap_roaming_cons);
10574 }
10575
10576 val = get_param(cmd, "ANQP");
10577 if (val)
10578 dut->ap_anqpserver_on = atoi(val);
10579
10580 val = get_param(cmd, "NAI_REALM_LIST");
10581 if (val) {
10582 dut->ap_nai_realm_list = atoi(val);
10583 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
10584 dut->ap_nai_realm_list);
10585 }
10586
10587 val = get_param(cmd, "3GPP_INFO");
10588 if (val) {
10589 /* What kind of encoding format is used?! */
10590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
10591 "not yet supported (contents not fully defined)");
10592 return 0;
10593 }
10594
10595 val = get_param(cmd, "DOMAIN_LIST");
10596 if (val) {
10597 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
10598 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
10599 "DOMAIN_LIST");
10600 return 0;
10601 }
10602 snprintf(dut->ap_domain_name_list,
10603 sizeof(dut->ap_domain_name_list), "%s", val);
10604 pos = dut->ap_domain_name_list;
10605 while (*pos) {
10606 if (*pos == ';')
10607 *pos = ',';
10608 pos++;
10609 }
10610 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
10611 dut->ap_domain_name_list);
10612 }
10613
10614 val = get_param(cmd, "OPER_NAME");
10615 if (val) {
10616 dut->ap_oper_name = atoi(val);
10617 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
10618 dut->ap_oper_name);
10619 }
10620
10621 val = get_param(cmd, "VENUE_NAME");
10622 if (val) {
10623 dut->ap_venue_name = atoi(val);
10624 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10625 dut->ap_venue_name);
10626 }
10627
10628 val = get_param(cmd, "GAS_CB_DELAY");
10629 if (val) {
10630 dut->ap_gas_cb_delay = atoi(val);
10631 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
10632 dut->ap_gas_cb_delay);
10633 }
10634
10635 val = get_param(cmd, "MIH");
10636 if (val && atoi(val) > 0) {
10637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
10638 "supported");
10639 return 0;
10640 }
10641
10642 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
10643 if (val) {
10644 dut->ap_l2tif = atoi(val);
10645 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
10646 dut->ap_l2tif);
10647 }
10648
10649 val = get_param(cmd, "BCST_UNCST");
10650 if (val) {
10651 send_resp(dut, conn, SIGMA_ERROR,
10652 "errorCode,BCST_UNCST not yet supported");
10653 return 0;
10654 }
10655
10656 val = get_param(cmd, "PLMN_MCC");
10657 if (val) {
10658 char mcc[100], *start, *end;
10659 int i = 0;
10660 if (strlen(val) >= sizeof(mcc)) {
10661 send_resp(dut, conn, SIGMA_ERROR,
10662 "errorCode,PLMN_MCC too long");
10663 return 0;
10664 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010665 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010666 start = mcc;
10667 while ((end = strchr(start, ';'))) {
10668 /* process all except the last */
10669 *end = '\0';
10670 if (strlen(start) != 3) {
10671 send_resp(dut, conn, SIGMA_ERROR,
10672 "errorCode,Invalid PLMN_MCC");
10673 return 0;
10674 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010675 res = snprintf(dut->ap_plmn_mcc[i],
10676 sizeof(dut->ap_plmn_mcc[i]), "%s",
10677 start);
10678 if (res < 0 || res >= sizeof(dut->ap_plmn_mcc[i]))
10679 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010680 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10681 dut->ap_plmn_mcc[i]);
10682 i++;
10683 start = end + 1;
10684 *end = ';';
10685 }
10686 if (strlen(start) != 3) {
10687 send_resp(dut, conn, SIGMA_ERROR,
10688 "errorCode,Invalid PLMN_MCC");
10689 return 0;
10690 }
10691 /* process last or only one */
Jouni Malinen77dda642020-01-07 11:21:55 +020010692 res = snprintf(dut->ap_plmn_mcc[i],
10693 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
10694 if (res < 0 || res >= sizeof(dut->ap_plmn_mcc[i]))
10695 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010696 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10697 dut->ap_plmn_mcc[i]);
10698 }
10699
10700 val = get_param(cmd, "PLMN_MNC");
10701 if (val) {
10702 char mnc[100], *start, *end;
10703 int i = 0;
10704 if (strlen(val) >= sizeof(mnc)) {
10705 send_resp(dut, conn, SIGMA_ERROR,
10706 "errorCode,PLMN_MNC too long");
10707 return 0;
10708 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010709 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010710 start = mnc;
10711 while ((end = strchr(start, ';'))) {
10712 *end = '\0';
10713 if (strlen(start) != 2 && strlen(start) != 3) {
10714 send_resp(dut, conn, SIGMA_ERROR,
10715 "errorCode,Invalid PLMN_MNC");
10716 return 0;
10717 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010718 res = snprintf(dut->ap_plmn_mnc[i],
10719 sizeof(dut->ap_plmn_mnc[i]), "%s",
10720 start);
10721 if (res < 0 || res >= sizeof(dut->ap_plmn_mnc[i]))
10722 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010723 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10724 dut->ap_plmn_mnc[i]);
10725 i++;
10726 start = end + 1;
10727 *end = ';';
10728 }
10729 if (strlen(start) != 2 && strlen(start) != 3) {
10730 send_resp(dut, conn, SIGMA_ERROR,
10731 "errorCode,Invalid PLMN_MNC");
10732 return 0;
10733 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010734 res = snprintf(dut->ap_plmn_mnc[i],
10735 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
10736 if (res < 0 || res >= sizeof(dut->ap_plmn_mnc[i]))
10737 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010738 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10739 dut->ap_plmn_mnc[i]);
10740 }
10741
10742 val = get_param(cmd, "PROXY_ARP");
10743 if (val) {
10744 dut->ap_proxy_arp = atoi(val);
10745 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
10746 dut->ap_proxy_arp);
10747 }
10748
10749 val = get_param(cmd, "WAN_METRICS");
10750 if (val) {
10751 dut->ap_wan_metrics = atoi(val);
10752 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
10753 dut->ap_wan_metrics);
10754 }
10755
10756 val = get_param(cmd, "CONN_CAP");
10757 if (val) {
10758 dut->ap_conn_capab = atoi(val);
10759 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
10760 dut->ap_conn_capab);
10761 }
10762
10763 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
10764 if (val) {
10765 dut->ap_ip_addr_type_avail = atoi(val);
10766 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
10767 dut->ap_ip_addr_type_avail);
10768 }
10769
10770 val = get_param(cmd, "NET_AUTH_TYPE");
10771 if (val) {
10772 dut->ap_net_auth_type = atoi(val);
10773 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
10774 dut->ap_net_auth_type);
10775 }
10776
10777 val = get_param(cmd, "OP_CLASS");
10778 if (val == NULL)
10779 val = get_param(cmd, "OPER_CLASS");
10780 if (val) {
10781 dut->ap_oper_class = atoi(val);
10782 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
10783 dut->ap_oper_class);
10784 }
10785
10786 val = get_param(cmd, "OSU_PROVIDER_LIST");
10787 if (val) {
10788 dut->ap_osu_provider_list = atoi(val);
10789 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
10790 dut->ap_osu_provider_list);
10791 }
10792
Jouni Malinen93a837f2018-11-01 17:09:22 +020010793 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
10794 if (val) {
10795 dut->ap_osu_provider_nai_list = atoi(val);
10796 sigma_dut_print(dut, DUT_MSG_INFO,
10797 "ap_osu_provider_nai_list %d",
10798 dut->ap_osu_provider_nai_list);
10799 }
10800
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010801 val = get_param(cmd, "OSU_SERVER_URI");
10802 if (val) {
10803 i = 0;
10804 do {
10805 int len;
10806 const char *uri = val;
10807 val = strchr(val, ' ');
10808 len = val ? (val++ - uri) : (int) strlen(uri);
10809 if (len > 0 && len < 256) {
10810 memcpy(dut->ap_osu_server_uri[i], uri, len);
10811 dut->ap_osu_server_uri[i][len] = '\0';
10812 sigma_dut_print(dut, DUT_MSG_INFO,
10813 "ap_osu_server_uri[%d] %s", i,
10814 dut->ap_osu_server_uri[i]);
10815 }
10816 } while (val && ++i < 10);
10817 }
10818
10819 val = get_param(cmd, "OSU_METHOD");
10820 if (val) {
10821 i = 0;
10822 do {
10823 int len;
10824 const char *method = val;
10825 val = strchr(val, ' ');
10826 len = val ? (val++ - method) : (int) strlen(method);
10827 if (len > 0) {
10828 if (strncasecmp(method, "SOAP", len) == 0)
10829 dut->ap_osu_method[i] = 1;
10830 else if (strncasecmp(method, "OMADM", len) == 0)
10831 dut->ap_osu_method[i] = 0;
10832 else
10833 return -2;
10834 }
10835 } while (val && ++i < 10);
10836 }
10837
10838 val = get_param(cmd, "OSU_SSID");
10839 if (val) {
10840 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -070010841 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010842 sizeof(dut->ap_osu_ssid));
10843 sigma_dut_print(dut, DUT_MSG_INFO,
10844 "ap_osu_ssid %s",
10845 dut->ap_osu_ssid);
10846 }
10847 }
10848
10849 val = get_param(cmd, "OSU_ICON_TAG");
10850 if (val)
10851 dut->ap_osu_icon_tag = atoi(val);
10852
10853 val = get_param(cmd, "QoS_MAP_SET");
10854 if (val) {
10855 dut->ap_qos_map_set = atoi(val);
10856 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10857 dut->ap_qos_map_set);
10858 }
10859
10860 val = get_param(cmd, "BSS_LOAD");
10861 if (val) {
10862 dut->ap_bss_load = atoi(val);
10863 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
10864 dut->ap_bss_load);
10865 }
10866
Jouni Malinen54a89b02018-05-01 00:16:26 +030010867 val = get_param(cmd, "Venue_URL");
10868 if (val)
10869 dut->ap_venue_url = atoi(val);
10870
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030010871 val = get_param(cmd, "Advice_of_Charge");
10872 if (val)
10873 dut->ap_advice_of_charge = atoi(val);
10874
Jouni Malinenac104532018-05-01 00:27:37 +030010875 val = get_param(cmd, "Operator_Icon_Metadata");
10876 if (val)
10877 dut->ap_oper_icon_metadata = atoi(val);
10878
Jouni Malinenac367142018-05-01 00:32:24 +030010879 val = get_param(cmd, "TnC_File_Name");
10880 if (val)
10881 dut->ap_tnc_file_name = atoi(val);
10882
10883 val = get_param(cmd, "TnC_File_Time_Stamp");
10884 if (val)
10885 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
10886
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010887 return 1;
10888}
10889
10890
10891void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
10892{
10893 char buf[100];
10894
10895 if (!file_exists("nfc-status"))
10896 return;
10897
10898 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
10899 run_system(dut, buf);
10900}
10901
10902
10903static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
10904 const char *info)
10905{
10906 int res;
10907
10908 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
10909 printf("%s\n\n", info);
10910
10911 nfc_status(dut, "START", info);
10912 res = run_system(dut, cmd);
10913 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
10914 if (res) {
10915 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
10916 cmd, res);
10917 return res;
10918 }
10919
10920 return 0;
10921}
10922
10923
10924static int ap_nfc_write_config_token(struct sigma_dut *dut,
10925 struct sigma_conn *conn,
10926 struct sigma_cmd *cmd)
10927{
10928 int res;
10929 char buf[300];
10930
10931 run_system(dut, "killall wps-ap-nfc.py");
10932 unlink("nfc-success");
10933 snprintf(buf, sizeof(buf),
10934 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
10935 dut->summary_log ? "--summary " : "",
10936 dut->summary_log ? dut->summary_log : "");
10937 res = run_nfc_command(dut, buf,
10938 "Touch NFC Tag to write WPS configuration token");
10939 if (res || !file_exists("nfc-success")) {
10940 send_resp(dut, conn, SIGMA_ERROR,
10941 "ErrorCode,Failed to write tag");
10942 return 0;
10943 }
10944
10945 return 1;
10946}
10947
10948
10949static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
10950 struct sigma_conn *conn,
10951 struct sigma_cmd *cmd)
10952{
10953 int res;
10954 char buf[300];
10955
10956 run_system(dut, "killall wps-ap-nfc.py");
10957
10958 unlink("nfc-success");
10959 snprintf(buf, sizeof(buf),
10960 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10961 dut->summary_log ? "--summary " : "",
10962 dut->summary_log ? dut->summary_log : "");
10963 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
10964 if (res || !file_exists("nfc-success")) {
10965 send_resp(dut, conn, SIGMA_ERROR,
10966 "ErrorCode,Failed to read tag");
10967 return 0;
10968 }
10969
10970 return 1;
10971}
10972
10973
10974static int ap_nfc_write_password_token(struct sigma_dut *dut,
10975 struct sigma_conn *conn,
10976 struct sigma_cmd *cmd)
10977{
10978 int res;
10979 char buf[300];
10980
10981 run_system(dut, "killall wps-ap-nfc.py");
10982 unlink("nfc-success");
10983 snprintf(buf, sizeof(buf),
10984 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
10985 dut->summary_log ? "--summary " : "",
10986 dut->summary_log ? dut->summary_log : "");
10987 res = run_nfc_command(dut, buf,
10988 "Touch NFC Tag to write WPS password token");
10989 if (res || !file_exists("nfc-success")) {
10990 send_resp(dut, conn, SIGMA_ERROR,
10991 "ErrorCode,Failed to write tag");
10992 return 0;
10993 }
10994
10995 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
10996 send_resp(dut, conn, SIGMA_ERROR,
10997 "ErrorCode,Failed to enable NFC password token");
10998 return 0;
10999 }
11000
11001 return 1;
11002}
11003
11004
11005static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
11006 struct sigma_conn *conn,
11007 struct sigma_cmd *cmd)
11008{
11009 int res;
11010 char buf[300];
11011
11012 run_system(dut, "killall wps-ap-nfc.py");
11013 unlink("nfc-success");
11014 snprintf(buf, sizeof(buf),
11015 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
11016 dut->summary_log ? "--summary " : "",
11017 dut->summary_log ? dut->summary_log : "");
11018 res = run_nfc_command(dut, buf,
11019 "Touch NFC Device to respond to WPS connection handover");
11020 if (res) {
11021 send_resp(dut, conn, SIGMA_ERROR,
11022 "ErrorCode,Failed to enable NFC for connection "
11023 "handover");
11024 return 0;
11025 }
11026 if (!file_exists("nfc-success")) {
11027 send_resp(dut, conn, SIGMA_ERROR,
11028 "ErrorCode,Failed to complete NFC connection handover");
11029 return 0;
11030 }
11031
11032 return 1;
11033}
11034
11035
Jouni Malinenf7222712019-06-13 01:50:21 +030011036static enum sigma_cmd_result cmd_ap_nfc_action(struct sigma_dut *dut,
11037 struct sigma_conn *conn,
11038 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011039{
11040 /* const char *name = get_param(cmd, "Name"); */
11041 /* const char *intf = get_param(cmd, "Interface"); */
11042 const char *oper = get_param(cmd, "Operation");
11043
11044 if (oper == NULL)
11045 return -1;
11046
11047 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
11048 return ap_nfc_write_config_token(dut, conn, cmd);
11049 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
11050 return ap_nfc_write_password_token(dut, conn, cmd);
11051 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
11052 return ap_nfc_wps_read_passwd(dut, conn, cmd);
11053 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
11054 return ap_nfc_wps_connection_handover(dut, conn, cmd);
11055
11056 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
11057 return 0;
11058}
11059
11060
Jouni Malinenf7222712019-06-13 01:50:21 +030011061static enum sigma_cmd_result cmd_ap_wps_read_pin(struct sigma_dut *dut,
11062 struct sigma_conn *conn,
11063 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011064{
11065 char *pin = "12345670"; /* TODO: use random PIN */
11066 char resp[100];
11067
11068 snprintf(resp, sizeof(resp), "PIN,%s", pin);
11069 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11070
11071 return 0;
11072}
11073
11074
Jouni Malinenf7222712019-06-13 01:50:21 +030011075static enum sigma_cmd_result cmd_ap_wps_enter_pin(struct sigma_dut *dut,
11076 struct sigma_conn *conn,
11077 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020011078{
11079 const char *pin = get_param(cmd, "PIN");
11080 char wps_pin[11];
11081
11082 if (!pin)
11083 return -1;
11084
11085 sigma_dut_print(dut, DUT_MSG_DEBUG,
11086 "Authorize a client to join with WPS PIN %s", pin);
11087
11088 strlcpy(wps_pin, pin, sizeof(wps_pin));
11089 /* we need to tolerate extra '-' characters entered */
11090 str_remove_chars(wps_pin, '-');
11091 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
11092 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
11093
11094 return 1;
11095}
11096
11097
Jouni Malinenf7222712019-06-13 01:50:21 +030011098static enum sigma_cmd_result cmd_ap_wps_set_pbc(struct sigma_dut *dut,
11099 struct sigma_conn *conn,
11100 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020011101{
11102 sigma_dut_print(dut, DUT_MSG_DEBUG,
11103 "Selecting the push button configuration method");
11104
11105 dut->wps_method = WFA_CS_WPS_PBC;
11106
11107 return 1;
11108}
11109
11110
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020011111int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
11112 struct sigma_cmd *cmd)
11113{
11114 char buf[100], resp[256];
11115 const char *intf = get_param(cmd, "interface");
11116 const char *config_method = get_param(cmd, "WPSConfigMethod");
11117
11118 if (config_method && strcasecmp(config_method, "PBC") == 0)
11119 dut->wps_method = WFA_CS_WPS_PBC;
11120
11121 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011122 intf = get_main_ifname(dut);
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020011123
11124 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
11125 send_resp(dut, conn, SIGMA_ERROR,
11126 "ErrorCode,WPS parameters not yet set");
11127 return STATUS_SENT;
11128 }
11129
11130 if (dut->wps_method == WFA_CS_WPS_PBC)
11131 snprintf(buf, sizeof(buf), "WPS_PBC");
11132 else /* WFA_CS_WPS_PIN_KEYPAD */
11133 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
11134
11135 /* Run WPS command */
11136 if (hapd_command(intf, buf) < 0) {
11137 /* command fails immediately if overlapped session detected */
11138 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
11139 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11140 return STATUS_SENT;
11141 }
11142
11143 /* In AP mode return immediately and do not wait for WPS registration */
11144 return SUCCESS_SEND_STATUS;
11145}
11146
11147
Jouni Malinenf7222712019-06-13 01:50:21 +030011148static enum sigma_cmd_result cmd_ap_get_parameter(struct sigma_dut *dut,
11149 struct sigma_conn *conn,
11150 struct sigma_cmd *cmd)
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011151{
11152 char value[256], resp[512];
11153 const char *param = get_param(cmd, "parameter");
11154 const char *ifname = get_param(cmd, "Interface");
Jouni Malinena36912a2020-02-10 03:01:31 +020011155 const char *var;
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011156
11157 if (!ifname)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011158 ifname = get_main_ifname(dut);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011159
11160 if (!param) {
11161 send_resp(dut, conn, SIGMA_ERROR,
11162 "ErrorCode,Parameter not specified");
11163 return 0;
11164 }
11165
11166 if (strcasecmp(param, "SSID") == 0) {
11167 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
11168 sigma_dut_print(dut, DUT_MSG_ERROR,
11169 "Failed to get SSID");
11170 return -2;
11171 }
11172 snprintf(resp, sizeof(resp), "SSID,%s", value);
11173 } else if (strcasecmp(param, "PSK") == 0) {
11174 if (get_hapd_config(ifname, "passphrase", value,
11175 sizeof(value))) {
11176 sigma_dut_print(dut, DUT_MSG_ERROR,
11177 "Failed to get PSK");
11178 return -2;
11179 }
11180 snprintf(resp, sizeof(resp), "PSK,%s", value);
Jouni Malinena36912a2020-02-10 03:01:31 +020011181 } else if (strcasecmp(param, "PMK") == 0) {
11182 var = get_param(cmd, "STA_MAC_Address");
11183 if (!var)
11184 return INVALID_SEND_STATUS;
11185 snprintf(resp, sizeof(resp), "GET_PMK %s", var);
11186 if (hapd_command_resp(ifname, resp, &resp[4],
11187 sizeof(resp) - 4) < 0) {
11188 send_resp(dut, conn, SIGMA_ERROR,
11189 "ErrorCode,GET_PMK failed");
11190 return STATUS_SENT_ERROR;
11191 }
11192 memcpy(resp, "PMK,", 4);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011193 } else {
11194 send_resp(dut, conn, SIGMA_ERROR,
11195 "ErrorCode,Unsupported parameter");
11196 return 0;
11197 }
11198
11199 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11200 return 0;
11201}
11202
11203
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011204static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
11205 const char *val)
11206{
11207 char *token, *result;
11208 int nss = 0, chwidth = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011209 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011210
11211 /*
11212 * The following commands should be invoked to generate
11213 * VHT op mode notification
11214 */
11215
11216 /* Extract the NSS info */
11217 token = strdup(val);
11218 if (!token)
11219 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011220 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011221 if (result) {
11222 int count = atoi(result);
11223
11224 /* We do not support NSS > 3 */
11225 if (count < 0 || count > 3) {
11226 free(token);
11227 return -1;
11228 }
11229
11230 /* Convert nss to chainmask */
11231 while (count--)
11232 nss = (nss << 1) | 1;
11233
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011234 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011235 }
11236
11237 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011238 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011239 if (result) {
11240 switch (atoi(result)) {
11241 case 20:
11242 chwidth = 0;
11243 break;
11244 case 40:
11245 chwidth = 1;
11246 break;
11247 case 80:
11248 chwidth = 2;
11249 break;
11250 case 160:
11251 chwidth = 3;
11252 break;
11253 default:
11254 chwidth = 2;
11255 break;
11256 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011257 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011258 }
11259
11260 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011261 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011262 free(token);
11263
11264 return 0;
11265}
11266
11267
11268static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
11269 const char *val)
11270{
11271 /* String (nss_operating_mode; mcs_operating_mode) */
11272 int nss, mcs;
11273 char *token, *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011274 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011275
11276 token = strdup(val);
11277 if (!token)
11278 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011279 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011280 if (!result) {
11281 sigma_dut_print(dut, DUT_MSG_ERROR,
11282 "VHT NSS not specified");
11283 goto end;
11284 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011285 if (strcasecmp(result, "def") != 0) {
11286 nss = atoi(result);
11287
11288 if (nss == 4)
11289 ath_disable_txbf(dut, ifname);
11290
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011291 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011292 } else {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011293 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11294 run_iwpriv(dut, ifname, "nss 1");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011295 if (dut->device_type == AP_testbed &&
11296 dut->program == PROGRAM_HE) {
11297 nss = dut->ap_tx_streams;
11298 run_iwpriv(dut, ifname, "nss %d", nss);
11299 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011300 }
11301
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011302 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011303 if (!result) {
11304 sigma_dut_print(dut, DUT_MSG_ERROR,
11305 "VHT MCS not specified");
11306 goto end;
11307 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011308 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011309 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11310 run_iwpriv(dut, ifname, "vhtmcs 7");
11311 else
11312 run_iwpriv(dut, ifname, "set11NRates 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011313 if (dut->device_type == AP_testbed &&
11314 dut->program == PROGRAM_HE)
11315 run_iwpriv(dut, ifname, "he_mcs 7");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011316 } else {
11317 mcs = atoi(result);
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011318 if (dut->program == PROGRAM_HE)
11319 run_iwpriv(dut, ifname, "he_mcs %d", mcs);
11320 else
11321 run_iwpriv(dut, ifname, "vhtmcs %d", mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011322 }
11323
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011324end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011325 free(token);
11326 return 0;
11327}
11328
11329
11330static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
11331 const char *val)
11332{
11333 char *token, *result;
11334 int channel = 36;
11335 int chwidth = 80;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011336 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011337
11338 /* Extract the channel info */
11339 token = strdup(val);
11340 if (!token)
11341 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011342 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011343 if (result)
11344 channel = atoi(result);
11345
11346 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011347 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011348 if (result)
11349 chwidth = atoi(result);
11350
11351 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011352 run_iwpriv(dut, ifname, "doth_ch_chwidth %d 10 %d", channel, chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011353
11354 free(token);
11355 return 0;
11356}
11357
11358
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011359static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
11360 const char *val)
11361{
11362 char buf[80];
11363 unsigned char mac_addr[6];
11364
11365 if (parse_mac_address(dut, val, mac_addr) < 0)
11366 return -1;
11367
11368 snprintf(buf, sizeof(buf),
11369 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
11370 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
11371 run_system(dut, buf);
11372
11373 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
11374 ifname, mac_addr[4], mac_addr[5]);
11375 run_system(dut, buf);
11376
11377 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
11378 run_system(dut, buf);
11379
11380 return 0;
11381}
11382
11383
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011384void novap_reset(struct sigma_dut *dut, const char *ifname, int reset)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011385{
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011386 run_iwpriv(dut, ifname, "novap_reset %d", reset);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011387}
11388
11389
Jouni Malinenb4335432019-06-13 02:23:57 +030011390static struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
11391 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011392{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011393 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011394
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011395 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
11396 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
11397 ETH_ALEN) == 0)
11398 return &dut->mbo_pref_aps[i];
11399 }
11400 return NULL;
11401}
11402
11403
11404static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
11405 int ap_ne_class, int ap_ne_op_ch,
11406 int ap_ne_pref)
11407{
11408 struct mbo_pref_ap *entry;
11409 uint8_t self_mac[ETH_ALEN];
11410 char ifname[50];
11411
11412 get_if_name(dut, ifname, sizeof(ifname), 1);
11413 get_hwaddr(ifname, self_mac);
11414
11415 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
11416 entry = &dut->mbo_self_ap_tuple;
11417 else
11418 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
11419
11420 if (!entry) {
11421 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
11422 sigma_dut_print(dut, DUT_MSG_ERROR,
11423 "Nebor AP List is full. Not adding");
11424 return;
11425 }
11426 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
11427 dut->mbo_pref_ap_cnt++;
11428 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
11429 entry->ap_ne_class = -1;
11430 entry->ap_ne_op_ch = -1;
11431 entry->ap_ne_pref = -1;
11432 }
11433 if (ap_ne_class != -1)
11434 entry->ap_ne_class = ap_ne_class;
11435 if (ap_ne_op_ch != -1)
11436 entry->ap_ne_op_ch = ap_ne_op_ch;
11437 if (ap_ne_pref != -1)
11438 entry->ap_ne_pref = ap_ne_pref;
11439}
11440
11441
11442static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
11443 struct sigma_cmd *cmd)
11444{
11445 unsigned char mac_addr[ETH_ALEN];
11446 const char *val;
11447 /*
11448 * -1 is invalid value for the following
11449 * to differentiate between unset and set values
11450 * -1 => implies not set by CAPI
11451 */
11452 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
11453 int list_offset = dut->mbo_pref_ap_cnt;
11454
11455 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
11456 sigma_dut_print(dut, DUT_MSG_ERROR,
11457 "AP Pref Entry list is full");
11458 return -1;
11459 }
11460
11461 val = get_param(cmd, "Nebor_Op_Class");
11462 if (val)
11463 ap_ne_class = atoi(val);
11464
11465 val = get_param(cmd, "Nebor_Op_Ch");
11466 if (val)
11467 ap_ne_op_ch = atoi(val);
11468
11469 val = get_param(cmd, "Nebor_Pref");
11470 if (val)
11471 ap_ne_pref = atoi(val);
11472
11473 val = get_param(cmd, "Nebor_BSSID");
11474 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011475 return -1;
11476
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011477 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
11478 ap_ne_pref);
11479 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011480 return 0;
11481}
11482
11483
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011484static enum sigma_cmd_result he_ltf(struct sigma_dut *dut,
11485 struct sigma_conn *conn,
11486 const char *ifname, const char *val)
11487{
11488 const char *var;
11489
11490 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11491 var = "he_ul_ltf";
11492 else
11493 var = "he_ltf";
11494
11495 if (strcmp(val, "6.4") == 0) {
11496 run_iwpriv(dut, ifname, "%s 2", var);
11497 } else if (strcmp(val, "12.8") == 0) {
11498 run_iwpriv(dut, ifname, "%s 3", var);
11499 } else if (strcmp(val, "3.2") == 0) {
11500 run_iwpriv(dut, ifname, "%s 1", var);
11501 } else {
11502 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported LTF");
11503 return STATUS_SENT_ERROR;
11504 }
11505
11506 return SUCCESS_SEND_STATUS;
11507}
11508
11509
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011510static enum sigma_cmd_result he_shortgi(struct sigma_dut *dut,
11511 struct sigma_conn *conn,
11512 const char *ifname,
11513 const char *val)
11514{
11515 const char *var;
11516
11517 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11518 var = "he_ul_shortgi";
11519 else
11520 var = "shortgi";
11521
11522 if (strcmp(val, "0.8") == 0) {
11523 run_iwpriv(dut, ifname, "%s 0", var);
11524 } else if (strcmp(val, "1.6") == 0) {
11525 run_iwpriv(dut, ifname, "%s 2", var);
11526 } else if (strcmp(val, "3.2") == 0) {
11527 run_iwpriv(dut, ifname, "%s 3", var);
11528 } else {
11529 send_resp(dut, conn, SIGMA_ERROR,
11530 "errorCode,Unsupported shortGI");
11531 return STATUS_SENT_ERROR;
11532 }
11533
11534 return SUCCESS_SEND_STATUS;
11535}
11536
11537
11538static enum sigma_cmd_result he_ar_gi_ltf_mask(struct sigma_dut *dut,
11539 struct sigma_conn *conn,
11540 const char *ifname,
11541 const char *val)
11542{
11543
11544 uint32_t he_ar_gi_ltf;
11545 uint16_t he_ar_gi, he_ar_ltf;
11546
11547 if (strcmp(val, "0.4") == 0) {
11548 he_ar_gi = 0x01;
11549 } else if (strcmp(val, "0.8") == 0) {
11550 he_ar_gi = 0x02;
11551 } else if (strcmp(val, "1.6") == 0) {
11552 he_ar_gi = 0x04;
11553 } else if (strcmp(val, "3.2") == 0) {
11554 he_ar_gi = 0x08;
11555 } else {
11556 send_resp(dut, conn, SIGMA_ERROR,
11557 "errorCode,Unsupported shortGI");
11558 return STATUS_SENT_ERROR;
11559 }
11560
11561 if (dut->ar_ltf && strcmp(dut->ar_ltf, "6.4") == 0) {
11562 he_ar_ltf = 0x02;
11563 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "12.8") == 0) {
11564 he_ar_ltf = 0x04;
11565 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "3.2") == 0) {
11566 he_ar_ltf = 0x01;
11567 } else {
11568 send_resp(dut, conn, SIGMA_ERROR,
11569 "errorCode,Unsupported LTF");
11570 return STATUS_SENT_ERROR;
11571 }
11572
11573 he_ar_gi_ltf = (he_ar_gi << 8) | he_ar_ltf;
11574 run_iwpriv(dut, ifname, "he_ar_gi_ltf %lu", he_ar_gi_ltf);
11575
11576 return SUCCESS_SEND_STATUS;
11577}
11578
11579
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011580static enum sigma_cmd_result he_rualloctones(struct sigma_dut *dut,
11581 struct sigma_conn *conn,
11582 const char *ifname,
11583 const char *val)
11584{
11585 char *token, *result;
11586 int value;
11587 char *saveptr;
11588 int rualloc_type;
11589 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
11590
11591 token = strdup(val);
11592 if (!token)
11593 return -1;
11594 result = strtok_r(token, ":", &saveptr);
11595 if (!result) {
11596 free(token);
11597 send_resp(dut, conn, SIGMA_ERROR,
11598 "errorCode,RUAllocTones not specified");
11599 return STATUS_SENT_ERROR;
11600 }
11601
11602 /*
11603 * ru_allocation_type can take the values of:
11604 * 1 - DL OFDMA data RU allocation
11605 * 3 - UL OFDMA data RU allocation
11606 */
11607 rualloc_type = dut->ap_he_ulofdma == VALUE_ENABLED ? 3 : 1;
11608
11609
11610 value = atoi(result);
11611 if (value == 106) {
11612 enum value_not_set_enabled_disabled ap_he_rualloc_106_80 =
11613 VALUE_NOT_SET;
11614
11615 result = strtok_r(NULL, ":", &saveptr);
11616 if (result) {
11617 result = strtok_r(NULL, ":", &saveptr);
11618 if (result)
11619 ap_he_rualloc_106_80 = VALUE_ENABLED;
11620 else
11621 ap_he_rualloc_106_80 = VALUE_DISABLED;
11622 }
11623 if (ap_he_rualloc_106_80 == VALUE_ENABLED) {
11624 run_system_wrapper(dut,
11625 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 2 1 2 2 2 3 2",
11626 ifname, rualloc_type);
11627 } else {
11628 run_system_wrapper(dut,
11629 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 2 1 2",
11630 ifname, rualloc_type);
11631 }
11632 } else if (value == 242) {
11633 run_system_wrapper(
11634 dut,
11635 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 3 1 3 2 3 3 3",
11636 ifname, rualloc_type);
11637 } else if (value == 26) {
11638 run_system_wrapper(
11639 dut,
11640 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 0 2 0 5 0 7 0",
11641 ifname, rualloc_type);
11642 } else if (value == 52) {
11643 run_system_wrapper(
11644 dut,
11645 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 1 1 1 2 1 3 1",
11646 ifname, rualloc_type);
11647 } else if (value == 484) {
11648 run_system_wrapper(
11649 dut,
11650 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 4 1 4",
11651 ifname, rualloc_type);
11652 } else if (value == 996) {
11653 run_system_wrapper(dut,
11654 "wifitool %s setUnitTestCmd 0x4b 3 %d 0 5",
11655 ifname, rualloc_type);
11656 } else {
11657 send_resp(dut, conn, SIGMA_ERROR,
11658 "errorCode,Unsupported RUAllocTones");
11659 ret = STATUS_SENT_ERROR;
11660 }
11661
11662 free(token);
11663 return ret;
11664}
11665
11666
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070011667static void ath_set_trigger_type_0(struct sigma_dut *dut, const char *ifname)
11668{
11669 /* TriggerType "0" for Basic trigger */
11670 if (dut->ap_channel >= 36) {
11671 /* 1 and 2 here is interpreted to 5g and 2g (bitmasks) */
11672 run_system_wrapper(dut,
11673 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11674 ifname);
11675 } else {
11676 run_system_wrapper(dut,
11677 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11678 ifname);
11679 }
11680 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 6",
11681 ifname);
11682}
11683
11684
11685static void ath_set_trigger_type_1(struct sigma_dut *dut, const char *ifname)
11686{
11687 /* TriggerType "1" for MU BRP */
11688 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 1",
11689 ifname);
11690 mubrp_commands(dut, ifname);
11691}
11692
11693
11694static void ath_set_trigger_type_2(struct sigma_dut *dut, const char *ifname)
11695{
11696 /* TriggerType "2" for MU BAR */
11697 if (dut->ap_channel >= 36) {
11698 /* RU allocation RU 242 - DL OFDMA data */
11699 run_system_wrapper(dut,
11700 "wifitool %s setUnitTestCmd 0x4b 5 9 0 3 1 3 2 3 3 3",
11701 ifname);
11702 /* RU allocation RU 52 - UL BA */
11703 run_system_wrapper(dut,
11704 "wifitool %s setUnitTestCmd 0x4b 5 9 0 2 1 2 2 2 3 2",
11705 ifname);
11706 } else {
11707 /* RU allocation RU 52 - DL ofdma data */
11708 run_system_wrapper(dut,
11709 "wifitool %s setUnitTestCmd 0x4b 5 9 0 1 1 1 2 1 3 1",
11710 ifname);
11711 }
11712 /* Force TBPPDU duration to 400 us */
11713 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 400",
11714 ifname);
11715 /* 0 to enable MU BAR, 1 to enable SU BAR */
11716 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 49 0",
11717 ifname);
11718 /* MU BAR */
11719 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 64 0",
11720 ifname);
11721}
11722
11723
11724static void ath_set_trigger_type_3(struct sigma_dut *dut, const char *ifname)
11725{
11726 /* TriggerType "3" for MU RTS */
11727 /* Send MU RTS Trigger - '1' is to enable MU RTS */
11728 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 101 1",
11729 ifname);
11730}
11731
11732
11733static void ath_set_trigger_type_4(struct sigma_dut *dut, const char *ifname,
11734 const char *basedev)
11735{
11736 /* TriggerType "4" for BSRP */
11737 run_system_wrapper(dut, "cfg80211tool %s he_ul_trig_int 200", basedev);
11738 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 1000",
11739 ifname);
11740 if (dut->ap_channel >= 36) {
11741 run_system_wrapper(dut,
11742 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11743 ifname);
11744 } else {
11745 run_system_wrapper(dut,
11746 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11747 ifname);
11748 }
11749 /* Send BSRP command */
11750 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 7",
11751 ifname);
11752}
11753
11754
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011755static enum sigma_cmd_result ath_ap_set_rfeature(struct sigma_dut *dut,
11756 struct sigma_conn *conn,
11757 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011758{
11759 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011760 const char *ifname;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011761 enum sigma_cmd_result res;
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011762 const char *basedev = "wifi0";
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011763 int trigtype;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011764 int he_ackpolicymac = 0;
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070011765 char *num_ss = NULL;
11766 char *nss[4] = { NULL, NULL, NULL, NULL };
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070011767 char *aid[4] = { NULL, NULL, NULL, NULL };
11768 char *aid_ss = NULL;
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070011769 int omctrl_rxnss = 0, omctrl_chwidth = 0;
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070011770 int param;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011771 unsigned char mac_addr[ETH_ALEN];
11772
11773 memset(mac_addr, 0x00, ETH_ALEN);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011774
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011775 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011776
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011777 if (sigma_radio_ifname[0])
11778 basedev = sigma_radio_ifname[0];
11779
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011780 /* Disable vap reset between the commands */
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011781 novap_reset(dut, ifname, 1);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011782
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011783 val = get_param(cmd, "Opt_md_notif_ie");
11784 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011785 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011786
11787 /* TODO: Optional arguments */
11788
11789 val = get_param(cmd, "nss_mcs_opt");
11790 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011791 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011792
11793 val = get_param(cmd, "chnum_band");
11794 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011795 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011796
11797 val = get_param(cmd, "RTS_FORCE");
11798 if (val)
11799 ath_config_rts_force(dut, ifname, val);
11800
11801 val = get_param(cmd, "DYN_BW_SGNL");
11802 if (val)
11803 ath_config_dyn_bw_sig(dut, ifname, val);
11804
11805 val = get_param(cmd, "CTS_WIDTH");
11806 if (val)
11807 ath_set_cts_width(dut, ifname, val);
11808
11809 val = get_param(cmd, "Ndpa_stainfo_mac");
11810 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011811 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011812
11813 val = get_param(cmd, "txBandwidth");
11814 if (val && ath_set_width(dut, conn, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011815 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011816
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011817 val = get_param(cmd, "Assoc_Disallow");
11818 if (val)
11819 ath_set_assoc_disallow(dut, ifname, val);
11820
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011821
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011822 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011823 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011824 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011825 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011826 dut->ap_disassoc_timer = 1000;
11827 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011828
11829 val = get_param(cmd, "BTMReq_Term_Bit");
11830 if (val)
11831 dut->ap_btmreq_term_bit = atoi(val);
11832
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011833 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011834 if (val) {
11835 dut->ap_assoc_delay = 1;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011836 run_iwpriv(dut, ifname, "mbo_asoc_ret %s", val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011837 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011838
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070011839 val = get_param(cmd, "Disassoc_Timer");
11840 if (val)
11841 dut->ap_disassoc_timer = atoi(val);
11842
11843 val = get_param(cmd, "BSS_Term_Duration");
11844 if (val)
11845 dut->ap_btmreq_bss_term_dur = atoi(val);
11846
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080011847 val = get_param(cmd, "BSS_Term_TSF");
11848 if (val)
11849 dut->ap_btmreq_bss_term_tsf = atoi(val);
11850
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011851 val = get_param(cmd, "TxPower");
11852 if (val)
11853 ath_set_txpower(dut, ifname, val);
11854
11855 val = get_param(cmd, "DownlinkAvailCap");
11856 if (val)
11857 dut->ap_dl_availcap = atoi(val);
11858
11859 val = get_param(cmd, "UplinkAvailCap");
11860 if (val) {
11861 dut->ap_ul_availcap = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011862 run_iwpriv(dut, ifname, "oce_wan_mtr %d %d",
11863 dut->ap_dl_availcap, dut->ap_ul_availcap);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011864 }
11865
11866 val = get_param(cmd, "RSSIthreshold");
11867 if (val) {
11868 int rssithreshold;
11869
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011870 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011871 rssithreshold = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011872 run_iwpriv(dut, ifname, "oce_asoc_rssi %d", rssithreshold);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011873 }
11874
11875 val = get_param(cmd, "RetryDelay");
11876 if (val) {
11877 int retrydelay;
11878
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011879 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011880 retrydelay = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011881 run_iwpriv(dut, ifname, "oce_asoc_dly %d", retrydelay);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011882 }
11883
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011884 val = get_param(cmd, "LTF");
11885 if (val) {
11886 if (dut->ap_fixed_rate) {
11887 res = he_ltf(dut, conn, ifname, val);
11888 if (res != SUCCESS_SEND_STATUS)
11889 return res;
11890 } else {
11891 free(dut->ar_ltf);
11892 dut->ar_ltf = strdup(val);
11893 if (!dut->ar_ltf)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011894 return ERROR_SEND_STATUS;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011895 }
11896 }
11897
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011898 val = get_param(cmd, "GI");
11899 if (val) {
11900 if (dut->ap_fixed_rate)
11901 res = he_shortgi(dut, conn, ifname, val);
11902 else
11903 res = he_ar_gi_ltf_mask(dut, conn, ifname, val);
11904 if (res != SUCCESS_SEND_STATUS)
11905 return res;
11906 }
11907
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011908 val = get_param(cmd, "RUAllocTones");
11909 if (val) {
11910 res = he_rualloctones(dut, conn, ifname, val);
11911 if (res != SUCCESS_SEND_STATUS)
11912 return res;
11913 }
11914
Priyadharshini Gowthaman803fd662019-07-31 14:37:49 -070011915 val = get_param(cmd, "MPDU_MU_SpacingFactor");
11916 if (val)
11917 run_system_wrapper(dut,
11918 "wifitool %s setUnitTestCmd 0x48 2 119, %s",
11919 ifname, val);
11920
11921 val = get_param(cmd, "PPDUTxType");
11922 if (val) {
11923 if (strcasecmp(val, "HE-SU") == 0) {
11924 /* Change PPDU format type to HE-SU MCS 1 */
11925 run_system_wrapper(dut,
11926 "wifitool %s setUnitTestCmd 0x48 2 89 0x401",
11927 ifname);
11928 } else if (strcasecmp(val, "legacy") == 0) {
11929 /* Change PPDU format type to non-HT */
11930 run_system_wrapper(dut,
11931 "wifitool %s setUnitTestCmd 0x48 2 89 3",
11932 ifname);
11933 } else {
11934 send_resp(dut, conn, SIGMA_ERROR,
11935 "errorCode,Unsupported PPDUTxType");
11936 return STATUS_SENT_ERROR;
11937 }
11938 }
11939
11940 val = get_param(cmd, "TXOPDuration");
11941 if (val) {
11942 if (strcasecmp(val, "UNSPECIFIED") == 0) {
11943 /* The hardware is hardcoded with 0x7f; do nothing */
11944 } else {
11945 send_resp(dut, conn, SIGMA_ERROR,
11946 "errorCode,Unsupported TXOPDuration");
11947 return STATUS_SENT_ERROR;
11948 }
11949 }
11950
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011951 val = get_param(cmd, "Trig_Usrinfo_UL-MCS");
11952 if (val)
11953 run_iwpriv(dut, ifname, "he_ul_mcs %d", atoi(val));
11954
11955 val = get_param(cmd, "Trig_Usrinfo_UL-Target-RSSI");
11956 if (val) {
11957 /* Set target RSSI to -55 dBm */
11958 run_system_wrapper(dut,
11959 "wifitool %s setUnitTestCmd 0x4b 2 7 %d",
11960 ifname, atoi(val) - 110);
11961 }
11962
11963 val = get_param(cmd, "Trig_Interval");
11964 if (val)
11965 run_iwpriv(dut, basedev, "he_ul_trig_int %d", atoi(val));
11966
11967 val = get_param(cmd, "Trig_ComInfo_ULLength");
11968 if (val)
11969 run_system_wrapper(dut,
11970 "wifitool %s setUnitTestCmd 0x48 2 141 %d",
11971 ifname, atoi(val));
11972
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011973 val = get_param(cmd, "DisableTriggerType");
11974 if (val) {
11975 trigtype = atoi(val);
11976 switch (trigtype) {
11977 case 0:
11978 /* DisableTriggerType "0" for basic trigger */
11979 run_system_wrapper(dut,
11980 "wifitool %s setUnitTestCmd 0x47 2 42 0",
11981 ifname);
11982 break;
11983 default:
11984 /* Nothing to be done for now */
11985 break;
11986 }
11987 }
11988
11989 val = get_param(cmd, "Trigger_TxBF");
11990 if (val) {
11991 if (strcasecmp(val, "enable") == 0) {
11992 run_iwpriv(dut, ifname, "he_sounding_mode 0x9");
11993 } else if (strcasecmp(val, "disable") == 0) {
11994 run_iwpriv(dut, ifname, "he_sounding_mode 0x1");
11995 } else {
11996 send_resp(dut, conn, SIGMA_ERROR,
11997 "errorCode,Unsupported trigger_txbf");
11998 return STATUS_SENT_ERROR;
11999 }
12000 }
12001
Priyadharshini Gowthaman7b94f082019-07-31 14:38:25 -070012002 val = get_param(cmd, "Trig_UsrInfo_RUAlloc");
12003 if (val) {
12004 res = he_rualloctones(dut, conn, ifname, val);
12005 if (res != SUCCESS_SEND_STATUS)
12006 return res;
12007 }
12008
Priyadharshini Gowthaman8701fac2019-07-31 14:38:48 -070012009 val = get_param(cmd, "TriggerCoding");
12010 if (val) {
12011 if (strcasecmp(val, "BCC") == 0) {
12012 /* In case of LDPC enable this command can force BCC if
12013 * RU size <= 242 */
12014 run_iwpriv(dut, ifname, "he_ul_ldpc 0");
12015 } else if (strcasecmp(val, "LDPC") == 0) {
12016 novap_reset(dut, ifname, 0);
12017 run_iwpriv(dut, ifname, "he_ul_ldpc 1");
12018 novap_reset(dut, ifname, 1);
12019 } else {
12020 send_resp(dut, conn, SIGMA_ERROR,
12021 "errorCode,Unsupported TriggerCoding");
12022 return STATUS_SENT_ERROR;
12023 }
12024 }
12025
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070012026 val = get_param(cmd, "AckPolicy_MAC");
12027 if (val) {
12028 if (parse_mac_address(dut, val, mac_addr) < 0) {
12029 send_resp(dut, conn, SIGMA_ERROR,
12030 "errorCode,MAC Address not in proper format");
12031 return STATUS_SENT_ERROR;
12032 }
12033 he_ackpolicymac = 1;
12034 }
12035
12036 val = get_param(cmd, "AckPolicy");
12037 if (val) {
12038 int ap_he_ackpolicy;
12039
12040 ap_he_ackpolicy = atoi(val);
12041 if (ap_he_ackpolicy == 0 && he_ackpolicymac) {
12042 /* Disable all-BAR ackpolicy for MU-MIMO */
12043 run_system_wrapper(dut,
12044 "wifitool %s setUnitTestCmd 0x48 2 62 0",
12045 ifname);
12046 /* Disable all-BAR ackpolicy first */
12047 run_system_wrapper(dut,
12048 "wifitool %s setUnitTestCmd 0x48 2 64 0",
12049 ifname);
12050 /* Set normal ack policy for the STA with the specified
12051 * MAC address in DL-TX case */
12052 run_system_wrapper(dut,
12053 "wifitool %s setUnitTestCmd 0x4b 8 8 1 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
12054 ifname, mac_addr[0], mac_addr[1],
12055 mac_addr[2], mac_addr[3],
12056 mac_addr[4], mac_addr[5]);
12057 } else if (ap_he_ackpolicy == 3) {
12058 /* Enable all-BAR ackpolicy for MU-MIMO DL */
12059 run_system_wrapper(dut,
12060 "wifitool %s setUnitTestCmd 0x48 2 62 1",
12061 ifname);
12062 /* Enable all-BAR ackpolicy */
12063 run_system_wrapper(dut,
12064 "wifitool %s setUnitTestCmd 0x48 2 64 1",
12065 ifname);
12066 } else if (ap_he_ackpolicy == 4) {
12067 /* Enable htp-ack ackpolicy */
12068 run_system_wrapper(dut,
12069 "wifitool %s setUnitTestCmd 0x47 2 99 1",
12070 ifname);
12071 } else {
12072 send_resp(dut, conn, SIGMA_ERROR,
12073 "errorCode,Invalid AckPolicy setting");
12074 return STATUS_SENT_ERROR;
12075 }
12076 }
12077
Priyadharshini Gowthamanc9a88c72019-08-09 12:04:17 -070012078 val = get_param(cmd, "Trig_ComInfo_GI-LTF");
12079 if (val) {
12080 int trig_gi_ltf;
12081
12082 trig_gi_ltf = atoi(val);
12083 if (trig_gi_ltf == 0) {
12084 he_ltf(dut, conn, ifname, "3.2");
12085 he_shortgi(dut, conn, ifname, "1.6");
12086 } else if (trig_gi_ltf == 1) {
12087 he_ltf(dut, conn, ifname, "6.4");
12088 he_shortgi(dut, conn, ifname, "1.6");
12089 } else if (trig_gi_ltf == 2) {
12090 he_ltf(dut, conn, ifname, "12.8");
12091 he_shortgi(dut, conn, ifname, "3.2");
12092 } else {
12093 send_resp(dut, conn, SIGMA_ERROR,
12094 "errorCode,Unsupported Trig_ComInfo_GI-LTF");
12095 return STATUS_SENT_ERROR;
12096 }
12097 }
12098
12099 val = get_param(cmd, "Trig_ComInfo_BW");
12100 if (val) {
12101 int chwidth;
12102
12103 chwidth = atoi(val);
12104 /* Set the channel width */
12105 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
12106 }
12107
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070012108 val = get_param(cmd, "NumSS");
12109 if (val) {
12110 int i = 0;
12111 char *numss_val;
12112 char *saveptr;
12113
12114 num_ss = strdup(val);
12115 if (!num_ss)
12116 return ERROR_SEND_STATUS;
12117
12118 numss_val = strtok_r(num_ss, " ", &saveptr);
12119 for (i = 0; numss_val && i < 4; i++) {
12120 nss[i] = numss_val;
12121 numss_val = strtok_r(NULL, " ", &saveptr);
12122 }
12123 }
12124
12125 val = get_param(cmd, "NumSS_MAC");
12126 if (val) {
12127 char *sta_mac_str;
12128 char *saveptr;
12129 char *sta_mac_list_str;
12130
12131 sta_mac_list_str = strdup(val);
12132 if (!sta_mac_list_str) {
12133 free(num_ss);
12134 return ERROR_SEND_STATUS;
12135 }
12136
12137 sta_mac_str = strtok_r(sta_mac_list_str, " ", &saveptr);
12138 if (sta_mac_str && nss[0]) {
12139 run_system_wrapper(dut,
12140 "wifitool %s chmask_persta %s %s",
12141 ifname, sta_mac_str, nss[0]);
12142 }
12143
12144 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12145 if (sta_mac_str && nss[1]) {
12146 run_system_wrapper(dut,
12147 "wifitool %s chmask_persta %s %s",
12148 ifname, sta_mac_str, nss[1]);
12149 }
12150
12151 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12152 if (sta_mac_str && nss[2]) {
12153 run_system_wrapper(dut,
12154 "wifitool %s chmask_persta %s %s",
12155 ifname, sta_mac_str, nss[2]);
12156 }
12157
12158 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12159 if (sta_mac_str && nss[3]) {
12160 run_system_wrapper(dut,
12161 "wifitool %s chmask_persta %s %s",
12162 ifname, sta_mac_str, nss[3]);
12163 }
12164
12165 free(sta_mac_list_str);
12166 }
12167
12168 free(num_ss);
12169 num_ss = NULL;
12170
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070012171 val = get_param(cmd, "AID");
12172 if (val) {
12173 int i = 0;
12174 char *aid_val;
12175 char *saveptr;
12176
12177 aid_ss = strdup(val);
12178 if (!aid_ss)
12179 return ERROR_SEND_STATUS;
12180
12181 aid_val = strtok_r(aid_ss, " ", &saveptr);
12182 for (i = 0; aid_val && i < 4; i++) {
12183 aid[i] = aid_val;
12184 aid_val = strtok_r(NULL, " ", &saveptr);
12185 }
12186 }
12187
12188 val = get_param(cmd, "AddbaReq");
12189 if (val) {
12190 if (strcasecmp(val, "enable") == 0) {
12191 run_iwpriv(dut, ifname, "setaddbaoper 1");
12192 run_system_wrapper(dut,
12193 "wifitool %s sendaddba %s 0 64",
12194 ifname, aid[0]);
12195 } else {
12196 send_resp(dut, conn, SIGMA_ERROR,
12197 "errorCode,Unsupported AddbaReq value");
12198 free(aid_ss);
12199 return STATUS_SENT_ERROR;
12200 }
12201 }
12202
12203 val = get_param(cmd, "AddbaResp");
12204 if (val) {
12205 if (aid_ss && strcasecmp(val, "accepted") == 0) {
12206 int aid_1 = atoi(aid_ss);
12207
12208 if (aid_1 == 1)
12209 aid_1 = 2;
12210 else
12211 aid_1 = aid_1 - 1;
12212
12213 /* There is no mechanism in place to reject Add BA Req
12214 * from all STAs and selectively accept Add BA Req from
12215 * a specified STA. Instead, it can accept Add BA Req
12216 * from all STAs and selectively reject from specified
12217 * STAs. Make changes for the same using the below
12218 * commands. */
12219 run_system_wrapper(dut, ifname, "setaddbaoper 1");
12220 run_system_wrapper(dut, "wifitool %s refusealladdbas 0",
12221 ifname);
12222 run_system_wrapper(dut,
12223 "wifitool %s setaddbaresp %d 0 37",
12224 ifname, aid_1);
12225 } else {
12226 send_resp(dut, conn, SIGMA_ERROR,
12227 "errorCode,Unsupported Addbaresp value");
12228 free(aid_ss);
12229 return STATUS_SENT_ERROR;
12230 }
12231 }
12232
12233 val = get_param(cmd, "Trig_UsrInfo_SSAlloc_RA-RU");
12234 if (val) {
12235 char *ssalloc_str;
12236 char *saveptr;
12237 char *ssalloc_list_str;
12238
12239 ssalloc_list_str = strdup(val);
12240 if (!ssalloc_list_str) {
12241 free(aid_ss);
12242 return ERROR_SEND_STATUS;
12243 }
12244
12245 ssalloc_str = strtok_r(ssalloc_list_str, ":", &saveptr);
12246 if (ssalloc_str && aid[0]) {
12247 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12248 ifname, aid[0], ssalloc_str);
12249 }
12250
12251 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12252 if (ssalloc_str && aid[1]) {
12253 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12254 ifname, aid[1], ssalloc_str);
12255 }
12256
12257 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12258 if (ssalloc_str && aid[2]) {
12259 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12260 ifname, aid[2], ssalloc_str);
12261 }
12262
12263 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12264 if (ssalloc_str && aid[3]) {
12265 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12266 ifname, aid[3], ssalloc_str);
12267 }
12268
12269 free(ssalloc_list_str);
12270 }
12271
12272 free(aid_ss);
12273 aid_ss = NULL;
12274
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070012275 val = get_param(cmd, "OMCtrl_RxNSS");
12276 if (val)
12277 omctrl_rxnss = atoi(val);
12278
12279 val = get_param(cmd, "OMCtrl_ChnlWidth");
12280 if (val)
12281 omctrl_chwidth = atoi(val);
12282
12283 val = get_param(cmd, "Client_mac");
12284 if (val) {
12285 if (parse_mac_address(dut, val, mac_addr) < 0) {
12286 send_resp(dut, conn, SIGMA_ERROR,
12287 "errorCode,MAC Address not in proper format");
12288 return STATUS_SENT_ERROR;
12289 }
12290
12291 /* setUnitTestCmd 13 7 1 mac3mac2mac1mac0 mac5mac4 <rx_nss>
12292 * <bw> <ulmu> <tx_nss> */
12293 run_system_wrapper(dut,
12294 "wifitool %s setUnitTestCmd 13 7 1 0x%02x%02x%02x%02x 0x%02x%02x %d %d 1 %d",
12295 ifname, mac_addr[3], mac_addr[2],
12296 mac_addr[1], mac_addr[0], mac_addr[5],
12297 mac_addr[4], omctrl_rxnss,
12298 omctrl_chwidth, omctrl_rxnss);
12299 }
12300
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070012301 val = get_param(cmd, "TriggerType");
12302 if (val) {
12303 trigtype = atoi(val);
12304 switch (trigtype) {
12305 case 0:
12306 ath_set_trigger_type_0(dut, ifname);
12307 break;
12308 case 1:
12309 ath_set_trigger_type_1(dut, ifname);
12310 break;
12311 case 2:
12312 ath_set_trigger_type_2(dut, ifname);
12313 break;
12314 case 3:
12315 ath_set_trigger_type_3(dut, ifname);
12316 break;
12317 case 4:
12318 ath_set_trigger_type_4(dut, ifname, basedev);
12319 break;
12320 default:
12321 send_resp(dut, conn, SIGMA_ERROR,
12322 "errorCode,TriggerType not supported");
12323 return STATUS_SENT_ERROR;
12324 }
12325 }
12326
Priyadharshini Gowthamanc352d822019-08-09 12:05:16 -070012327 val = get_param(cmd, "HE_TXOPDurRTSThr");
12328 if (val)
12329 run_iwpriv(dut, ifname, "he_rtsthrshld %d", atoi(val));
12330
12331 val = get_param(cmd, "NAV_Update");
12332 if (val) {
12333 if (strcasecmp(val, "disable") == 0) {
12334 run_iwpriv(dut, basedev, "nav_config 1 0");
12335 } else if (strcasecmp(val, "enable") == 0) {
12336 /* Do nothing */
12337 } else {
12338 send_resp(dut, conn, SIGMA_ERROR,
12339 "errorCode,Unsupported NAV update");
12340 return STATUS_SENT_ERROR;
12341 }
12342 }
12343
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070012344 /* Configure WMM Parameter Elements */
12345 val = get_param(cmd, "STA_WMMPE_ECWmin_BE");
12346 if (val) {
12347 param = atoi(val);
12348 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BE, param);
12349 }
12350
12351 val = get_param(cmd, "STA_WMMPE_ECWmin_BK");
12352 if (val) {
12353 param = atoi(val);
12354 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BK, param);
12355 }
12356
12357 val = get_param(cmd, "STA_WMMPE_ECWmin_VI");
12358 if (val) {
12359 param = atoi(val);
12360 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VI, param);
12361 }
12362
12363 val = get_param(cmd, "STA_WMMPE_ECWmin_VO");
12364 if (val) {
12365 param = atoi(val);
12366 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VO, param);
12367 }
12368
12369 val = get_param(cmd, "STA_WMMPE_ECWmax_BE");
12370 if (val) {
12371 param = atoi(val);
12372 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BE, param);
12373 }
12374
12375 val = get_param(cmd, "STA_WMMPE_ECWmax_BK");
12376 if (val) {
12377 param = atoi(val);
12378 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BK, param);
12379 }
12380
12381 val = get_param(cmd, "STA_WMMPE_ECWmax_VI");
12382 if (val) {
12383 param = atoi(val);
12384 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VI, param);
12385 }
12386
12387 val = get_param(cmd, "STA_WMMPE_ECWmax_VO");
12388 if (val) {
12389 param = atoi(val);
12390 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VO, param);
12391 }
12392
12393 val = get_param(cmd, "STA_WMMPE_AIFSN_BE");
12394 if (val) {
12395 param = atoi(val);
12396 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BE, param);
12397 }
12398
12399 val = get_param(cmd, "STA_WMMPE_AIFSN_BK");
12400 if (val) {
12401 param = atoi(val);
12402 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BK, param);
12403 }
12404
12405 val = get_param(cmd, "STA_WMMPE_AIFSN_VI");
12406 if (val) {
12407 param = atoi(val);
12408 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VI, param);
12409 }
12410
12411 val = get_param(cmd, "STA_WMMPE_AIFSN_VO");
12412 if (val) {
12413 param = atoi(val);
12414 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VO, param);
12415 }
12416
12417
12418 val = get_param(cmd, "STA_WMMPE_TXOP_BE");
12419 if (val) {
12420 param = atoi(val);
12421 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BE, param);
12422 }
12423
12424 val = get_param(cmd, "STA_WMMPE_TOXP_BK");
12425 if (val) {
12426 param = atoi(val);
12427 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BK, param);
12428 }
12429
12430 val = get_param(cmd, "STA_WMMPE_TXOP_VI");
12431 if (val) {
12432 param = atoi(val);
12433 run_iwpriv(dut, ifname, "txoplimit %d %d", AP_AC_VI, param);
12434 }
12435
12436 val = get_param(cmd, "STA_WMMPE_TXOP_VO");
12437 if (val) {
12438 param = atoi(val);
12439 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_VO, param);
12440 }
12441
Priyadharshini Gowthamanc46b7e42019-08-09 12:05:37 -070012442 /* Configure MU EDCA */
12443 val = get_param(cmd, "STA_MUEDCA_ECWmin_BE");
12444 if (val) {
12445 param = atoi(val);
12446 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BE, param);
12447 }
12448
12449 val = get_param(cmd, "STA_MUEDCA_ECWmin_BK");
12450 if (val) {
12451 param = atoi(val);
12452 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BK, param);
12453 }
12454
12455 val = get_param(cmd, "STA_MUEDCA_ECWmin_VI");
12456 if (val) {
12457 param = atoi(val);
12458 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VI, param);
12459 }
12460
12461 val = get_param(cmd, "STA_MUEDCA_ECWmin_VO");
12462 if (val) {
12463 param = atoi(val);
12464 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VO, param);
12465 }
12466
12467 val = get_param(cmd, "STA_MUEDCA_ECWmax_BE");
12468 if (val) {
12469 param = atoi(val);
12470 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BE, param);
12471 }
12472
12473 val = get_param(cmd, "STA_MUEDCA_ECWmax_BK");
12474 if (val) {
12475 param = atoi(val);
12476 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BK, param);
12477 }
12478
12479 val = get_param(cmd, "STA_MUEDCA_ECWmax_VI");
12480 if (val) {
12481 param = atoi(val);
12482 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VI, param);
12483 }
12484
12485 val = get_param(cmd, "STA_MUEDCA_ECWmax_VO");
12486 if (val) {
12487 param = atoi(val);
12488 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VO, param);
12489 }
12490
12491 val = get_param(cmd, "STA_MUEDCA_AIFSN_BE");
12492 if (val) {
12493 param = atoi(val);
12494 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BE, param);
12495 }
12496
12497 val = get_param(cmd, "STA_MUEDCA_AIFSN_BK");
12498 if (val) {
12499 param = atoi(val);
12500 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BK, param);
12501 }
12502
12503 val = get_param(cmd, "STA_MUEDCA_AIFSN_VI");
12504 if (val) {
12505 param = atoi(val);
12506 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VI, param);
12507 }
12508
12509 val = get_param(cmd, "STA_MUEDCA_AIFSN_VO");
12510 if (val) {
12511 param = atoi(val);
12512 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VO, param);
12513 }
12514
12515 val = get_param(cmd, "STA_MUEDCA_Timer_BE");
12516 if (val) {
12517 param = atoi(val);
12518 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BE, param);
12519 }
12520
12521 val = get_param(cmd, "STA_MUEDCA_Timer_BK");
12522 if (val) {
12523 param = atoi(val);
12524 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BK, param);
12525 }
12526
12527 val = get_param(cmd, "STA_MUEDCA_Timer_VI");
12528 if (val) {
12529 param = atoi(val);
12530 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VI, param);
12531 }
12532
12533 val = get_param(cmd, "STA_MUEDCA_Timer_VO");
12534 if (val) {
12535 param = atoi(val);
12536 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VO, param);
12537 }
12538
Jouni Malinen6076ffc2019-08-08 18:18:02 +030012539 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012540}
12541
12542
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012543static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12544 const char *val)
12545{
12546 char *token, *result;
12547 int channel = 36;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012548 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012549
12550 /* Extract the channel info */
12551 token = strdup(val);
12552 if (!token)
12553 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012554 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012555 if (result)
12556 channel = atoi(result);
12557
12558 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070012559 run_iwpriv(dut, ifname, "setChanChange %d", channel);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012560
12561 free(token);
12562 return 0;
12563}
12564
12565
bingsf532f9f2019-12-06 17:59:02 +080012566static enum sigma_cmd_result wcn_ap_set_rfeature(struct sigma_dut *dut,
12567 struct sigma_conn *conn,
12568 struct sigma_cmd *cmd)
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012569{
12570 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012571 const char *ifname;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012572
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012573 ifname = get_main_ifname(dut);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012574
12575 val = get_param(cmd, "chnum_band");
12576 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
bingsf532f9f2019-12-06 17:59:02 +080012577 return ERROR_SEND_STATUS;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012578
bingseca3c192019-12-06 17:59:02 +080012579 val = get_param(cmd, "txBandwidth");
12580 if (val) {
12581 int old_ch_bw = dut->ap_chwidth;
12582
12583 if (strcasecmp(val, "Auto") == 0) {
12584 dut->ap_chwidth = 0;
12585 } else if (strcasecmp(val, "20") == 0) {
12586 dut->ap_chwidth = 0;
12587 } else if (strcasecmp(val, "40") == 0) {
12588 dut->ap_chwidth = 1;
12589 } else if (strcasecmp(val, "80") == 0) {
12590 dut->ap_chwidth = 2;
12591 } else if (strcasecmp(val, "160") == 0) {
12592 dut->ap_chwidth = 3;
12593 } else {
12594 send_resp(dut, conn, SIGMA_ERROR,
12595 "ErrorCode,WIDTH not supported");
12596 return STATUS_SENT_ERROR;
12597 }
12598 if (old_ch_bw != dut->ap_chwidth) {
12599 if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
12600 return STATUS_SENT_ERROR;
12601 } else {
12602 sigma_dut_print(dut, DUT_MSG_DEBUG, "No change in BW");
12603 }
12604 }
12605
bingsf276b822019-12-06 18:29:49 +080012606 val = get_param(cmd, "GI");
12607 if (val) {
12608 int fix_rate_sgi;
12609
12610 if (strcmp(val, "0.8") == 0) {
12611 run_iwpriv(dut, ifname, "enable_short_gi 9");
12612 fix_rate_sgi = 1;
12613 } else if (strcmp(val, "1.6") == 0) {
12614 run_iwpriv(dut, ifname, "enable_short_gi 10");
12615 fix_rate_sgi = 2;
12616 } else if (strcmp(val, "3.2") == 0) {
12617 run_iwpriv(dut, ifname, "enable_short_gi 11");
12618 fix_rate_sgi = 3;
12619 } else {
12620 send_resp(dut, conn, SIGMA_ERROR,
12621 "errorCode,GI value not supported");
12622 return STATUS_SENT_ERROR;
12623 }
12624 run_iwpriv(dut, ifname, "enable_short_gi %d", fix_rate_sgi);
12625 }
12626
Kiran Kumar Lokereff979472020-01-22 11:15:59 -080012627 val = get_param(cmd, "LTF");
12628 if (val) {
12629#ifdef NL80211_SUPPORT
12630 if (strcmp(val, "3.2") == 0) {
12631 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_1X);
12632 } if (strcmp(val, "6.4") == 0) {
12633 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_2X);
12634 } else if (strcmp(val, "12.8") == 0) {
12635 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_4X);
12636 } else {
12637 send_resp(dut, conn, SIGMA_ERROR,
12638 "errorCode,LTF value not supported");
12639 return STATUS_SENT;
12640 }
12641#else /* NL80211_SUPPORT */
12642 sigma_dut_print(dut, DUT_MSG_ERROR,
12643 "LTF cannot be set without NL80211_SUPPORT defined");
12644 return ERROR_SEND_STATUS;
12645#endif /* NL80211_SUPPORT */
12646 }
12647
bingsf532f9f2019-12-06 17:59:02 +080012648 return SUCCESS_SEND_STATUS;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012649}
12650
12651
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012652static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12653 const char *val)
12654{
12655 char *token, *result;
12656 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
12657 channel_freq;
12658 char buf[100];
12659 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012660 int res;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012661
12662 /* Extract the channel info */
12663 token = strdup(val);
12664 if (!token)
12665 return -1;
12666 result = strtok_r(token, ";", &saveptr);
12667 if (result)
12668 channel = atoi(result);
12669
12670 /* Extract the channel width info */
12671 result = strtok_r(NULL, ";", &saveptr);
12672 if (result)
12673 chwidth = atoi(result);
12674
12675 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
12676 if (center_freq_idx < 0) {
12677 free(token);
12678 return -1;
12679 }
12680
12681 center_freq = get_5g_channel_freq(center_freq_idx);
12682 channel_freq = get_5g_channel_freq(channel);
12683
12684 /* Issue the channel switch command */
Jouni Malinen3aa72862019-05-29 23:14:51 +030012685 res = snprintf(buf, sizeof(buf),
12686 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
12687 ifname, channel_freq, center_freq, chwidth);
12688 if (res < 0 || res >= sizeof(buf) || run_hostapd_cli(dut, buf) != 0) {
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012689 sigma_dut_print(dut, DUT_MSG_ERROR,
12690 "hostapd_cli chan_switch failed");
12691 }
12692
12693 free(token);
12694 return 0;
12695}
12696
12697
12698static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
12699 struct sigma_conn *conn,
12700 struct sigma_cmd *cmd)
12701{
12702 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012703 const char *ifname;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012704
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012705 ifname = get_main_ifname(dut);
Tamizh chelvam638fb472019-08-15 14:00:31 +053012706
12707 val = get_param(cmd, "RTS_FORCE");
12708 if (val)
12709 mac80211_config_rts_force(dut, ifname, val);
12710
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012711 val = get_param(cmd, "chnum_band");
12712 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
12713 return -1;
12714
12715 return 1;
12716}
12717
12718
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012719#ifdef __linux__
12720static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
12721 struct sigma_conn *conn,
12722 struct sigma_cmd *cmd)
12723{
12724 const char *val;
12725
12726 val = get_param(cmd, "ExtSchIE");
12727 if (val && !strcasecmp(val, "Enable")) {
12728 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12729 int count = MAX_ESE_ALLOCS;
12730
12731 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12732 return -1;
12733 if (wil6210_set_ese(dut, count, allocs))
12734 return -1;
12735 return 1;
12736 }
12737
12738 send_resp(dut, conn, SIGMA_ERROR,
12739 "errorCode,Invalid ap_set_rfeature(60G)");
12740 return 0;
12741}
12742#endif /* __linux__ */
12743
12744
Jouni Malinenf7222712019-06-13 01:50:21 +030012745static enum sigma_cmd_result cmd_ap_set_rfeature(struct sigma_dut *dut,
12746 struct sigma_conn *conn,
12747 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012748{
12749 /* const char *name = get_param(cmd, "NAME"); */
12750 /* const char *type = get_param(cmd, "Type"); */
12751
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012752 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012753 case DRIVER_ATHEROS:
12754 return ath_ap_set_rfeature(dut, conn, cmd);
12755 case DRIVER_OPENWRT:
12756 switch (get_openwrt_driver_type()) {
12757 case OPENWRT_DRIVER_ATHEROS:
12758 return ath_ap_set_rfeature(dut, conn, cmd);
12759 default:
12760 send_resp(dut, conn, SIGMA_ERROR,
12761 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
12762 return 0;
12763 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053012764 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012765 case DRIVER_WCN:
12766 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012767 case DRIVER_MAC80211:
12768 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012769#ifdef __linux__
12770 case DRIVER_WIL6210:
12771 return wil6210_ap_set_rfeature(dut, conn, cmd);
12772#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012773 default:
12774 send_resp(dut, conn, SIGMA_ERROR,
12775 "errorCode,Unsupported ap_set_rfeature with the current driver");
12776 return 0;
12777 }
12778}
12779
12780
Jouni Malinenf7222712019-06-13 01:50:21 +030012781static enum sigma_cmd_result cmd_accesspoint(struct sigma_dut *dut,
12782 struct sigma_conn *conn,
12783 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012784{
12785 /* const char *name = get_param(cmd, "NAME"); */
12786 return 1;
12787}
12788
12789
Jouni Malinenf7222712019-06-13 01:50:21 +030012790static enum sigma_cmd_result
12791cmd_ap_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
12792 struct sigma_cmd *cmd)
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012793{
12794 const char *val;
12795
12796 val = get_param(cmd, "Oper_Chn");
12797 if (val) {
12798 dut->ap_oper_chn = 1;
12799 dut->ap_channel = atoi(val);
12800 }
12801
Jouni Malinenba4f2d42019-10-04 16:13:41 +030012802 val = get_param(cmd, "DPPConfiguratorAddress");
12803 if (val) {
12804 free(dut->ap_dpp_conf_addr);
12805 dut->ap_dpp_conf_addr = strdup(val);
12806 }
12807
12808 val = get_param(cmd, "DPPConfiguratorPKHash");
12809 if (val) {
12810 free(dut->ap_dpp_conf_pkhash);
12811 dut->ap_dpp_conf_pkhash = strdup(val);
12812 }
12813
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012814 return 1;
12815}
12816
12817
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012818void ap_register_cmds(void)
12819{
12820 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
12821 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
12822 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
12823 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
12824 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
12825 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053012826 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012827 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
12828 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
12829 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
12830 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
12831 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
12832 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
12833 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
12834 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
12835 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
12836 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
12837 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
12838 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
12839 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
12840 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
12841 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
12842 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020012843 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
12844 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020012845 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012846 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012847 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
12848 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012849}