blob: 5047e963e24ed0afb200487a803a19f6bd2498da [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 Malinencd4e3c32015-10-29 12:39:56 +02002488 return 1;
2489}
2490
2491
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302492int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2493 struct sigma_cmd *cmd)
2494{
2495 int status;
2496
2497 status = cmd_ap_set_wireless(dut, conn, cmd);
2498 if (status != 1)
2499 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302500 status = cmd_ap_set_security(dut, conn, cmd);
2501 if (status != 1)
2502 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302503 return cmd_ap_config_commit(dut, conn, cmd);
2504}
2505
2506
Jouni Malinenf7222712019-06-13 01:50:21 +03002507static enum sigma_cmd_result cmd_ap_set_radius(struct sigma_dut *dut,
2508 struct sigma_conn *conn,
2509 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002510{
2511 /* const char *name = get_param(cmd, "NAME"); */
2512 const char *val;
2513 unsigned int wlan_tag = 1, radius_port = 0;
2514 char *radius_ipaddr = NULL, *radius_password = NULL;
2515
2516 val = get_param(cmd, "WLAN_TAG");
2517 if (val) {
2518 wlan_tag = atoi(val);
2519 if (wlan_tag != 1 && wlan_tag != 2) {
2520 send_resp(dut, conn, SIGMA_INVALID,
2521 "errorCode,Invalid WLAN_TAG");
2522 return 0;
2523 }
2524 }
2525
2526 val = get_param(cmd, "PORT");
2527 if (val)
2528 radius_port = atoi(val);
2529
2530 if (wlan_tag == 1) {
2531 if (radius_port)
2532 dut->ap_radius_port = radius_port;
2533 radius_ipaddr = dut->ap_radius_ipaddr;
2534 radius_password = dut->ap_radius_password;
2535 } else if (wlan_tag == 2) {
2536 if (radius_port)
2537 dut->ap2_radius_port = radius_port;
2538 radius_ipaddr = dut->ap2_radius_ipaddr;
2539 radius_password = dut->ap2_radius_password;
2540 }
2541
2542 val = get_param(cmd, "IPADDR");
2543 if (val) {
2544 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2545 return -1;
2546 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2547 "%s", val);
2548 }
2549
2550 val = get_param(cmd, "PASSWORD");
2551 if (val) {
2552 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2553 return -1;
2554 snprintf(radius_password,
2555 sizeof(dut->ap_radius_password), "%s", val);
2556 }
2557
2558 return 1;
2559}
2560
2561
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002562static void owrt_ap_set_qcawifi(struct sigma_dut *dut, const char *key,
2563 const char *val)
2564{
2565 if (!val) {
2566 run_system_wrapper(dut, "uci delete wireless.qcawifi.%s", key);
2567 return;
2568 }
2569
2570 run_system(dut, "uci set wireless.qcawifi=qcawifi");
2571 run_system_wrapper(dut, "uci set wireless.qcawifi.%s=%s", key, val);
2572}
2573
2574
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002575static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2576 const char *key, const char *val)
2577{
2578 char buf[100];
2579
2580 if (val == NULL) {
2581 snprintf(buf, sizeof(buf),
2582 "uci delete wireless.wifi%d.%s", id, key);
2583 run_system(dut, buf);
2584 return;
2585 }
2586
2587 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2588 id, key, val);
2589 run_system(dut, buf);
2590}
2591
2592
2593static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2594 const char *key, const char *val)
2595{
2596 char buf[256];
2597
2598 if (val == NULL) {
2599 snprintf(buf, sizeof(buf),
2600 "uci del_list wireless.wifi%d.%s", id, key);
2601 run_system(dut, buf);
2602 return;
2603 }
2604
2605 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2606 id, key, val);
2607 run_system(dut, buf);
2608}
2609
2610
2611static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2612 const char *val)
2613{
2614 char buf[256];
2615
2616 if (val == NULL) {
2617 snprintf(buf, sizeof(buf),
2618 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2619 run_system(dut, buf);
2620 return;
2621 }
2622
2623 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2624 id, key, val);
2625 run_system(dut, buf);
2626}
2627
2628
2629static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2630 const char *key, const char *val)
2631{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002632 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633
2634 if (val == NULL) {
2635 snprintf(buf, sizeof(buf),
2636 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2637 run_system(dut, buf);
2638 return;
2639 }
2640
2641 snprintf(buf, sizeof(buf),
2642 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2643 id, key, val);
2644 run_system(dut, buf);
2645}
2646
2647
2648static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2649 const char *val)
2650{
2651 char buf[256];
Jouni Malinen3aa72862019-05-29 23:14:51 +03002652 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002653
2654 if (val == NULL) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002655 res = snprintf(buf, sizeof(buf),
2656 "uci delete wireless.@wifi-iface[%d].%s",
2657 id, key);
2658 if (res >= 0 && res < sizeof(buf))
2659 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002660 return;
2661 }
2662
Jouni Malinen3aa72862019-05-29 23:14:51 +03002663 run_system(dut, "uci add wireless wifi-iface");
2664 res = snprintf(buf, sizeof(buf),
2665 "uci set wireless.@wifi-iface[%d].%s=%s",
2666 id, key, val);
2667 if (res >= 0 && res < sizeof(buf))
2668 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002669 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2670 id, "network", "lan");
2671 run_system(dut, buf);
2672 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2673 id, "mode", "ap");
2674 run_system(dut, buf);
2675 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2676 id, "encryption", "none");
2677 run_system(dut, buf);
2678}
2679
2680
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002681#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002682static int owrt_ap_config_radio(struct sigma_dut *dut)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002683{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002684 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002685 int radio_count, radio_no;
2686 char buf[64];
2687
2688 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2689 radio_count++) {
2690 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2691 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2692 if (!sigma_radio_ifname[radio_no] ||
2693 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2694 continue;
2695 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2696 owrt_ap_set_vap(dut, radio_count, "device", buf);
2697 radio_id[radio_no] = radio_count;
2698 }
2699 }
2700
2701 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2702 switch (dut->ap_mode) {
2703 case AP_11g:
2704 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2705 break;
2706 case AP_11b:
2707 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2708 break;
2709 case AP_11ng:
2710 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2711 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2712 break;
2713 case AP_11a:
2714 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2715 break;
2716 case AP_11na:
2717 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2718 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2719 break;
2720 case AP_11ac:
2721 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2722 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2723 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002724 case AP_11ax:
2725 if (dut->ap_channel >= 36) {
2726 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axa");
2727 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2728 } else {
2729 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axg");
2730 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2731 }
2732 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002733 case AP_inval:
2734 sigma_dut_print(dut, DUT_MSG_ERROR,
2735 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002736 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002737 default:
2738 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2739 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2740 break;
2741 }
2742
2743 if (dut->ap_is_dual) {
2744 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2745 switch (dut->ap_mode_1) {
2746 case AP_11g:
2747 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2748 break;
2749 case AP_11b:
2750 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2751 break;
2752 case AP_11ng:
2753 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2754 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2755 break;
2756 case AP_11a:
2757 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2758 break;
2759 case AP_11na:
2760 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2761 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2762 break;
2763 case AP_11ac:
2764 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2765 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2766 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002767 case AP_11ax:
2768 if (dut->ap_channel >= 36) {
2769 owrt_ap_set_radio(dut, radio_id[1],
2770 "hwmode", "11axa");
2771 owrt_ap_set_radio(dut, radio_id[1],
2772 "htmode", "HT80");
2773 } else {
2774 owrt_ap_set_radio(dut, radio_id[1],
2775 "hwmode", "11axg");
2776 owrt_ap_set_radio(dut, radio_id[1],
2777 "htmode", "HT20");
2778 }
2779 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002780 case AP_inval:
2781 sigma_dut_print(dut, DUT_MSG_ERROR,
2782 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002783 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002784 default:
2785 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2786 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2787 break;
2788 }
2789
2790 }
2791
2792 /* Channel */
2793 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2794 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2795
2796 switch (dut->ap_chwidth) {
2797 case AP_20:
2798 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2799 break;
2800 case AP_40:
2801 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2802 break;
2803 case AP_80:
2804 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2805 break;
2806 case AP_160:
2807 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2808 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002809 case AP_80_80:
2810 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2811 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002812 case AP_AUTO:
2813 default:
2814 break;
2815 }
2816
2817 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2818 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2819 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2820 }
2821
2822 if (dut->ap_is_dual) {
2823 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2824 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2825 }
2826
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002827 /* Country Code */
2828 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2829 const char *country;
2830
2831 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2832 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002833 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002834 if (dut->ap_is_dual)
2835 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002836 } else if (dut->ap_countrycode[0]) {
2837 owrt_ap_set_radio(dut, radio_id[0], "country",
2838 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002839 }
2840
2841 if (dut->ap_disable_protection == 1) {
2842 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2843 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2844 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2845 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2846 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002847
2848 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002849 get_driver_type(dut) == DRIVER_OPENWRT)
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002850 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002851
2852 if (dut->ap_mbssid == VALUE_ENABLED)
2853 owrt_ap_set_qcawifi(dut, "mbss_ie_enable", "1");
2854
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002855 if (dut->program == PROGRAM_HE) {
2856 owrt_ap_set_radio(dut, radio_id[0], "he_bsscolor", "'1 1'");
2857 if (dut->ap_is_dual)
2858 owrt_ap_set_radio(dut, radio_id[1], "he_bsscolor",
2859 "'2 1'");
Priyadharshini Gowthaman7d07cd02019-11-22 14:26:02 -08002860 owrt_ap_set_qcawifi(dut, "ap_bss_color_collision_detection",
2861 "1");
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002862 }
2863
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002864 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002865}
2866
2867
2868static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2869{
2870 char buf[256];
2871
2872 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2873 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2874 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2875 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2876
2877 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2878 "'eng:Wi-Fi Alliance'");
2879
2880 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2881 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2882
2883 if (dut->ap_wan_metrics == 1)
2884 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2885 "'01:2500:384:0:0:10'");
2886 else if (dut->ap_wan_metrics == 1)
2887 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2888 "'01:1500:384:20:20:10'");
2889 else if (dut->ap_wan_metrics == 2)
2890 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2891 "'01:1500:384:20:20:10'");
2892 else if (dut->ap_wan_metrics == 3)
2893 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2894 "'01:2000:1000:20:20:10'");
2895 else if (dut->ap_wan_metrics == 4)
2896 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2897 "'01:8000:1000:20:20:10'");
2898 else if (dut->ap_wan_metrics == 5)
2899 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2900 "'01:9000:5000:20:20:10'");
2901
2902 if (dut->ap_conn_capab == 1) {
2903 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2904 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2905 "'6:20:1'");
2906 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2907 "'6:22:0'");
2908 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2909 "'6:80:1'");
2910 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2911 "'6:443:1'");
2912 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2913 "'6:1723:0'");
2914 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2915 "'6:5060:0'");
2916 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2917 "'17:500:1'");
2918 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2919 "'17:5060:0'");
2920 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2921 "'17:4500:1'");
2922 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2923 "'50:0:1'");
2924 } else if (dut->ap_conn_capab == 2) {
2925 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2926 "'6:80:1'");
2927 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2928 "'6:443:1'");
2929 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2930 "'17:5060:1'");
2931 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2932 "'6:5060:1'");
2933 } else if (dut->ap_conn_capab == 3) {
2934 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2935 "'6:80:1'");
2936 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2937 "'6:443:1'");
2938 }
2939
2940 if (dut->ap_oper_class == 1)
2941 snprintf(buf, sizeof(buf), "%s", "51");
2942 else if (dut->ap_oper_class == 2)
2943 snprintf(buf, sizeof(buf), "%s", "73");
2944 else if (dut->ap_oper_class == 3)
2945 snprintf(buf, sizeof(buf), "%s", "5173");
2946
2947 if (dut->ap_oper_class)
2948 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2949
2950 if (dut->ap_osu_provider_list) {
2951 char *osu_friendly_name = NULL;
2952 char *osu_icon = NULL;
2953 char *osu_ssid = NULL;
2954 char *osu_nai = NULL;
2955 char *osu_service_desc = NULL;
2956 char *hs20_icon_filename = NULL;
2957 char hs20_icon[150];
2958 int osu_method;
2959
2960 hs20_icon_filename = "icon_red_zxx.png";
2961 if (dut->ap_osu_icon_tag == 2)
2962 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2963 snprintf(hs20_icon, sizeof(hs20_icon),
2964 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2965 hs20_icon_filename);
2966 osu_icon = "icon_red_zxx.png";
2967 osu_ssid = "OSU";
2968 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2969 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2970 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2971 dut->ap_osu_method[0];
2972
2973 if (strlen(dut->ap_osu_server_uri[0]))
2974 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2975 dut->ap_osu_server_uri[0]);
2976 else
2977 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2978 "'https://osu-server.r2-testbed.wi-fi.org/'");
2979 switch (dut->ap_osu_provider_list) {
2980 case 1:
2981 case 101:
2982 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2983 "'eng:SP Red Test Only'");
2984 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2985 "'eng:Free service for test purpose'");
2986 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2987 hs20_icon);
2988
2989 hs20_icon_filename = "icon_red_eng.png";
2990 if (dut->ap_osu_icon_tag == 2)
2991 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2992
2993 snprintf(hs20_icon, sizeof(hs20_icon),
2994 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2995 hs20_icon_filename);
2996 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2997 "icon_red_eng.png");
2998 break;
2999 case 2:
3000 case 102:
3001 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3002 "'eng:Wireless Broadband Alliance'");
3003 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3004 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003005 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003006 if (dut->ap_osu_icon_tag == 2)
3007 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3008
3009 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003010 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003011 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003012 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003013 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
3014 break;
3015 case 3:
3016 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03003017 osu_friendly_name = "'spa:SP Red Test Only'";
3018 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003019 break;
3020 case 4:
3021 case 104:
3022 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003023 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003024 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3025 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003026 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027 if (dut->ap_osu_icon_tag == 2)
3028 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3029
3030 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003031 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003032 hs20_icon_filename);
3033 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3034 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003035 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003036
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003037 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003038 if (dut->ap_osu_icon_tag == 2)
3039 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3040
3041 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003042 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003044 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003045 break;
3046 case 5:
3047 case 105:
3048 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003049 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003050 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3051 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003052 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003053
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003054 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003055 if (dut->ap_osu_icon_tag == 2)
3056 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3057
3058 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003059 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003060 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003061 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003062 break;
3063 case 6:
3064 case 106:
3065 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3066 "'eng:SP Green Test Only'");
3067 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3068 "'kor:SP 초록 테스트 전용'");
3069
3070 hs20_icon_filename = "icon_green_zxx.png";
3071 if (dut->ap_osu_icon_tag == 2)
3072 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3073
3074 snprintf(hs20_icon, sizeof(hs20_icon),
3075 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
3076 hs20_icon_filename);
3077 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3078 hs20_icon);
3079
3080 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3081 "'icon_green_zxx.png'");
3082 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
3083 dut->ap_osu_method[0];
3084
3085 snprintf(buf, sizeof(buf), "%d", osu_method);
3086 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
3087
3088 if (strlen(dut->ap_osu_server_uri[1]))
3089 owrt_ap_set_list_vap(dut, vap_id,
3090 "osu_server_uri",
3091 dut->ap_osu_server_uri[1]);
3092 else
3093 owrt_ap_set_list_vap(dut, vap_id,
3094 "osu_server_uri",
3095 "'https://osu-server.r2-testbed.wi-fi.org/'");
3096
3097 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3098 "'eng:SP Orange Test Only'");
3099
3100 hs20_icon_filename = "icon_orange_zxx.png";
3101 if (dut->ap_osu_icon_tag == 2)
3102 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3103
3104 snprintf(hs20_icon, sizeof(hs20_icon),
3105 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3106 hs20_icon_filename);
3107
3108 osu_icon = "icon_orange_zxx.png";
3109 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
3110 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
3111 dut->ap_osu_method[1];
3112 osu_service_desc = NULL;
3113 break;
3114 case 7:
3115 case 107:
3116 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003117 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003118 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3119 "'eng:Free service for test purpose'");
3120
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003121 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003122 if (dut->ap_osu_icon_tag == 2)
3123 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3124
3125 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003126 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003127 hs20_icon_filename);
3128 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3129 hs20_icon);
3130
3131 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003132 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003133 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003134
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003135 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003136 if (dut->ap_osu_icon_tag == 2)
3137 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3138
3139 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003140 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003141 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003142 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003143 break;
3144 case 8:
3145 case 108:
3146 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3147 "'eng:SP Red Test Only'");
3148 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3149 "'eng:Free service for test purpose'");
3150 osu_ssid = "OSU-Encrypted";
3151 osu_nai = "'anonymous@hotspot.net'";
3152 break;
3153 case 9:
3154 case 109:
3155 osu_ssid = "OSU-OSEN";
3156 osu_nai = "'test-anonymous@wi-fi.org'";
3157 osu_friendly_name = "'eng:SP Orange Test Only'";
3158 hs20_icon_filename = "icon_orange_zxx.png";
3159 if (dut->ap_osu_icon_tag == 2)
3160 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3161
3162 snprintf(hs20_icon, sizeof(hs20_icon),
3163 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3164 hs20_icon_filename);
3165 osu_icon = "icon_orange_zxx.png";
3166 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
3167 dut->ap_osu_method[0];
3168 osu_service_desc = NULL;
3169 break;
3170 default:
3171 break;
3172 }
3173
3174 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03003175 if (dut->ap_tag_ssid[0][0] &&
3176 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003177 dut->ap_osu_ssid) != 0 &&
3178 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003179 sigma_dut_print(dut, DUT_MSG_ERROR,
3180 "OSU_SSID and WLAN_TAG2 SSID differ");
3181 return -2;
3182 }
3183
3184 snprintf(buf, sizeof(buf), "'\"%s\"'",
3185 dut->ap_osu_ssid);
3186 } else {
3187 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
3188 }
3189
3190 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
3191
3192
3193 if (osu_friendly_name)
3194 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3195 osu_friendly_name);
3196 if (osu_service_desc)
3197 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3198 osu_service_desc);
3199 if (osu_nai)
3200 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
3201
3202 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
3203
3204 if (osu_icon)
3205 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3206 osu_icon);
3207
3208 if (dut->ap_osu_provider_list > 100) {
3209 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3210 "0");
3211 } else {
3212 snprintf(buf, sizeof(buf), "%d", osu_method);
3213 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3214 buf);
3215 }
3216 }
3217
3218 return 0;
3219}
3220
3221
Jouni Malinen13701222019-02-19 12:10:53 +02003222static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
3223 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003224{
3225 unsigned char bssid[ETH_ALEN];
3226 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
3227 int preference = 0xff;
3228
Jouni Malinen13701222019-02-19 12:10:53 +02003229 if (get_hwaddr(ifname, bssid) < 0)
3230 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003231 snprintf(anqp_string, str_size,
3232 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
3233 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
3234 preference,
3235 dummy_mac[0], dummy_mac[1], dummy_mac[2],
3236 dummy_mac[3], dummy_mac[4], dummy_mac[5],
3237 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02003238 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003239}
3240
3241
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003242static void get_if_name(struct sigma_dut *dut, char *ifname_str,
3243 size_t str_size, int wlan_tag)
3244{
Jouni Malinenf8984642017-10-12 00:02:37 +03003245 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003246 enum driver_type drv;
3247
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003248 drv = get_driver_type(dut);
Jouni Malinenf8984642017-10-12 00:02:37 +03003249 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
3250 ifname = dut->hostapd_ifname;
3251 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003252 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
3253 dut->ap_mode == AP_11ac) &&
3254 if_nametoindex("ath1") > 0)
3255 ifname = "ath1";
3256 else
3257 ifname = "ath0";
3258 } else if (drv == DRIVER_OPENWRT) {
3259 if (sigma_radio_ifname[0] &&
3260 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3261 ifname = "ath2";
3262 else if (sigma_radio_ifname[0] &&
3263 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3264 ifname = "ath1";
3265 else
3266 ifname = "ath0";
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003267 } else if (drv == DRIVER_WIL6210) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003268 ifname = get_main_ifname(dut);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003269 } else {
3270 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
3271 dut->ap_mode == AP_11ac) &&
3272 if_nametoindex("wlan1") > 0)
3273 ifname = "wlan1";
3274 else
3275 ifname = "wlan0";
3276 }
3277
3278 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
3279 /* Handle tagged-ifname only on OPENWRT for now */
3280 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08003281 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
3282 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03003283 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003284 } else {
3285 snprintf(ifname_str, str_size, "%s", ifname);
3286 }
3287}
3288
3289
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003290static int owrt_ap_config_vap(struct sigma_dut *dut)
3291{
3292 char buf[256], *temp;
Jouni Malinen3aa72862019-05-29 23:14:51 +03003293 int vap_id = 0, vap_count, i, j, res;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003294 const char *ifname;
3295 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003296
priyadharshini gowthaman73561262018-02-20 13:24:59 -08003297 if (sigma_radio_ifname[0] &&
3298 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3299 ifname = "ath2";
3300 else if (sigma_radio_ifname[0] &&
3301 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3302 ifname = "ath1";
3303 else
3304 ifname = "ath0";
3305
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003306 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003307 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003308
3309 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
3310 if (sigma_radio_ifname[vap_id] &&
3311 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
3312 break;
3313 }
3314 if (vap_id == MAX_RADIO)
3315 continue;
3316
3317 /* Single VAP configuration */
3318 if (!dut->ap_is_dual)
3319 vap_id = vap_count;
3320
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003321 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
3322 /*
3323 * We keep a separate array of ap_tag_ssid and
3324 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
3325 * So j=0 => WLAN_TAG = 2
3326 */
3327 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003328
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003329 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
3330 (dut->ap_interface_5g || dut->ap_interface_2g)) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03003331 res = snprintf(
3332 dut->ap_tag_ssid[wlan_tag - 2],
3333 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
3334 "%s-owe", dut->ap_ssid);
3335 if (res < 0 ||
3336 res >= sizeof(dut->ap_tag_ssid[wlan_tag -
3337 2]))
3338 dut->ap_tag_ssid[wlan_tag - 2][0] =
3339 '\0';
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003340 }
3341
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003342 if (dut->ap_tag_ssid[j][0] == '\0')
3343 continue;
3344
3345 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
3346 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
3347 "device", buf);
3348 /* SSID */
3349 snprintf(buf, sizeof(buf), "\"%s\"",
3350 dut->ap_tag_ssid[j]);
3351 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3352 "ssid", buf);
3353
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003354 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3355 dut->ap_tag_ssid[0][0] &&
3356 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3357 /* OWE transition mode */
3358 snprintf(buf, sizeof(buf), "%s", ifname);
3359 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3360 "owe_transition_ifname", buf);
3361 }
3362
3363 if (dut->ap_key_mgmt == AP_OPEN &&
3364 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3365 /* OWE transition mode */
3366 snprintf(buf, sizeof(buf), "%s", ifname);
3367 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3368 "owe_transition_ifname", buf);
3369 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3370 "hidden", "1");
3371 }
3372
Jouni Malinen6be21c82018-08-01 18:47:24 +03003373 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003374 unsigned char self_mac[ETH_ALEN];
3375 char mac_str[20];
3376
3377 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3378 "mobility_domain",
3379 dut->ap_mobility_domain);
3380 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Jouni Malinen9f943312019-08-19 23:49:16 +03003381 "ft_over_ds",
3382 dut->ap_ft_ds == VALUE_ENABLED ?
3383 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003384 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3385 "ieee80211r", "1");
3386 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3387 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02003388 if (get_hwaddr(sigma_radio_ifname[0],
3389 self_mac) < 0)
3390 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003391 snprintf(mac_str, sizeof(mac_str),
3392 "%02x:%02x:%02x:%02x:%02x:%02x",
3393 self_mac[0], self_mac[1], self_mac[2],
3394 self_mac[3], self_mac[4], self_mac[5]);
3395 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3396 "ap_macaddr", mac_str);
3397 snprintf(mac_str, sizeof(mac_str),
3398 "%02x%02x%02x%02x%02x%02x",
3399 self_mac[0], self_mac[1], self_mac[2],
3400 self_mac[3], self_mac[4], self_mac[5]);
3401 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3402 "r1_key_holder", mac_str);
3403 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3404 "ft_psk_generate_local", "1");
3405 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3406 "kh_key_hex",
3407 "000102030405060708090a0b0c0d0e0f");
3408 snprintf(mac_str, sizeof(mac_str),
3409 "%02x:%02x:%02x:%02x:%02x:%02x",
3410 dut->ft_bss_mac_list[0][0],
3411 dut->ft_bss_mac_list[0][1],
3412 dut->ft_bss_mac_list[0][2],
3413 dut->ft_bss_mac_list[0][3],
3414 dut->ft_bss_mac_list[0][4],
3415 dut->ft_bss_mac_list[0][5]);
3416 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3417 "ap2_macaddr", mac_str);
3418 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3419 "ap2_r1_key_holder", mac_str);
3420 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3421 "nasid2", "nas2.example.com");
3422 }
3423
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003424 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
3425 wlan_tag == 2) {
3426 /* Only supported for WLAN_TAG=2 */
3427 owrt_ap_set_vap(dut, vap_count + 1, "osen",
3428 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003429 snprintf(buf, sizeof(buf), "wpa2");
3430 owrt_ap_set_vap(dut, vap_count + 1,
3431 "encryption", buf);
3432 snprintf(buf, sizeof(buf), "%s",
3433 dut->ap2_radius_ipaddr);
3434 owrt_ap_set_vap(dut, vap_count + 1,
3435 "auth_server", buf);
3436 snprintf(buf, sizeof(buf), "%d",
3437 dut->ap2_radius_port);
3438 owrt_ap_set_vap(dut, vap_count + 1,
3439 "auth_port", buf);
3440 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003441 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003442 owrt_ap_set_vap(dut, vap_count + 1,
3443 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003444 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
3445 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3446 "encryption", "psk2+ccmp");
3447 snprintf(buf, sizeof(buf), "\"%s\"",
3448 dut->ap_passphrase);
3449 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3450 "key", buf);
3451 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003452 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003453 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003454 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3455 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3456 "owe", "1");
3457 snprintf(buf, sizeof(buf), "ccmp");
3458 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3459 "encryption", buf);
3460 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3461 "ieee80211w", "2");
3462 if (dut->ap_sae_groups) {
3463 snprintf(buf, sizeof(buf), "\'%s\'",
3464 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003465 owrt_ap_set_list_vap(dut, vap_count +
3466 (wlan_tag - 1),
3467 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003468 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003469 }
3470 }
3471
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003472 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003473 if (dut->program == PROGRAM_MBO &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003474 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003475 unsigned char self_mac[ETH_ALEN];
3476 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003477 char anqp_string[200];
3478
Jouni Malinen13701222019-02-19 12:10:53 +02003479 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3480 anqp_string,
3481 sizeof(anqp_string)) < 0)
3482 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003483 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3484 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003485
Jouni Malinen6be21c82018-08-01 18:47:24 +03003486 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003487 owrt_ap_set_vap(dut, vap_count,
3488 "mobility_domain",
3489 dut->ap_mobility_domain);
3490 owrt_ap_set_vap(dut, vap_count,
Jouni Malinen9f943312019-08-19 23:49:16 +03003491 "ft_over_ds",
3492 dut->ap_ft_ds == VALUE_ENABLED ?
3493 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003494 owrt_ap_set_vap(dut, vap_count,
3495 "ieee80211r", "1");
3496 owrt_ap_set_vap(dut, vap_count,
3497 "nasid", "nas1.example.com");
3498 get_hwaddr(sigma_radio_ifname[0], self_mac);
3499 snprintf(mac_str, sizeof(mac_str),
3500 "%02x:%02x:%02x:%02x:%02x:%02x",
3501 self_mac[0], self_mac[1], self_mac[2],
3502 self_mac[3], self_mac[4], self_mac[5]);
3503 owrt_ap_set_vap(dut, vap_count,
3504 "ap_macaddr", mac_str);
3505 snprintf(mac_str, sizeof(mac_str),
3506 "%02x%02x%02x%02x%02x%02x",
3507 self_mac[0], self_mac[1], self_mac[2],
3508 self_mac[3], self_mac[4], self_mac[5]);
3509 owrt_ap_set_vap(dut, vap_count,
3510 "r1_key_holder", mac_str);
3511 owrt_ap_set_vap(dut, vap_count,
3512 "ft_psk_generate_local", "1");
3513 owrt_ap_set_vap(dut, vap_count,
3514 "kh_key_hex",
3515 "000102030405060708090a0b0c0d0e0f");
3516 snprintf(mac_str, sizeof(mac_str),
3517 "%02x:%02x:%02x:%02x:%02x:%02x",
3518 dut->ft_bss_mac_list[0][0],
3519 dut->ft_bss_mac_list[0][1],
3520 dut->ft_bss_mac_list[0][2],
3521 dut->ft_bss_mac_list[0][3],
3522 dut->ft_bss_mac_list[0][4],
3523 dut->ft_bss_mac_list[0][5]);
3524 owrt_ap_set_vap(dut, vap_count,
3525 "ap2_macaddr", mac_str);
3526 owrt_ap_set_vap(dut, vap_count,
3527 "ap2_r1_key_holder", mac_str);
3528 owrt_ap_set_vap(dut, vap_count,
3529 "nasid2", "nas2.example.com");
3530 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003531 }
3532
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003533 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003534 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003535 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3536 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3537 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3538
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003539 if (dut->ap_80plus80 == 1)
3540 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3541
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003542 if (dut->ap_akm == 1) {
3543 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3544 "3600");
3545 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3546 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3547 "1");
3548 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3549 "1234");
3550 owrt_ap_set_vap(dut, vap_id,
3551 "erp_send_reauth_start", "1");
3552 }
3553
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003554 if (dut->ap_filshlp == VALUE_ENABLED) {
3555 struct ifreq ifr;
3556 char *ifname;
3557 int s;
3558 struct sockaddr_in *ipaddr;
3559
3560 s = socket(AF_INET, SOCK_DGRAM, 0);
3561 if (s < 0) {
3562 sigma_dut_print(dut, DUT_MSG_ERROR,
3563 "Failed to open socket");
3564 return -1;
3565 }
3566 ifr.ifr_addr.sa_family = AF_INET;
3567
3568 memset(&ifr, 0, sizeof(ifr));
3569 ifname = "br-lan";
3570 strlcpy(ifr.ifr_name, ifname,
3571 sizeof(ifr.ifr_name));
3572 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3573 perror("ioctl");
3574 close(s);
3575 return -1;
3576 }
3577
3578 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3579 snprintf(buf, sizeof(buf), "%s",
3580 inet_ntoa(ipaddr->sin_addr));
3581 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3582 buf);
3583 snprintf(buf, sizeof(buf), "%s",
3584 dut->ap_dhcpserv_ipaddr);
3585 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3586 buf);
3587 owrt_ap_set_vap(dut, vap_id,
3588 "dhcp_rapid_commit_proxy", "1");
3589 owrt_ap_set_vap(dut, vap_id,
3590 "fils_hlp_wait_time", "300");
3591 }
3592
3593 if (dut->ap_filsdscv == VALUE_ENABLED) {
3594 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3595 "1");
3596 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3597 "20");
3598 }
3599 }
3600
3601 if (dut->ap_filsdscv == VALUE_DISABLED) {
3602 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3603 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3604 }
3605
3606 if (dut->ap_oce == VALUE_DISABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003607 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003608 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3609 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3610 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3611
3612 if (dut->ap_filsdscv == VALUE_DISABLED) {
3613 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3614 "0");
3615 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3616 "0");
3617 }
3618
3619 if (dut->device_type == AP_testbed)
3620 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3621 }
3622
3623 /* NAIRealm */
3624 if (dut->ap_nairealm_int == 1) {
3625 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3626 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3627 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3628 }
3629
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003630 /* SSID */
3631 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3632 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3633
3634 /* Encryption */
3635 switch (dut->ap_key_mgmt) {
3636 case AP_OPEN:
3637 if (dut->ap_cipher == AP_WEP) {
3638 owrt_ap_set_vap(dut, vap_count, "encryption",
3639 "wep-mixed");
3640 owrt_ap_set_vap(dut, vap_count, "key",
3641 dut->ap_wepkey);
3642 } else {
3643 owrt_ap_set_vap(dut, vap_count, "encryption",
3644 "none");
3645 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003646 if (dut->ap_key_mgmt == AP_OPEN &&
3647 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3648 /* OWE transition mode */
3649 snprintf(ifname2, sizeof(ifname2), "%s1",
3650 ifname);
3651 owrt_ap_set_vap(dut, vap_count,
3652 "owe_transition_ifname",
3653 ifname2);
3654 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003655 break;
3656 case AP_WPA2_PSK:
3657 case AP_WPA2_PSK_MIXED:
3658 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003659 case AP_WPA2_SAE:
3660 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003661 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3662 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003663 snprintf(buf, sizeof(buf), "psk2");
3664 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3665 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003666 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3667 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003668 } else {
3669 snprintf(buf, sizeof(buf), "psk");
3670 }
3671
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003672 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3673 if (dut->ap_cipher == AP_CCMP_TKIP)
3674 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3675 else if (dut->ap_cipher == AP_TKIP)
3676 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003677 else if (dut->ap_cipher == AP_GCMP_128)
3678 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003679 else
3680 strlcat(buf, "+ccmp", sizeof(buf));
3681 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003682
3683 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003684
3685 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3686 snprintf(buf, sizeof(buf), "\"%s\"",
3687 dut->ap_psk);
3688 owrt_ap_set_vap(dut, vap_count, "key", buf);
3689 } else {
3690 snprintf(buf, sizeof(buf), "\"%s\"",
3691 dut->ap_passphrase);
3692 owrt_ap_set_vap(dut, vap_count, "key", buf);
3693 }
3694
3695 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3696 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3697 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3698 else
3699 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3700
3701 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3702 snprintf(buf, sizeof(buf), "%s",
3703 dut->ap_passphrase);
3704 owrt_ap_set_vap(dut, vap_count, "sae_password",
3705 buf);
3706 } else {
3707 snprintf(buf, sizeof(buf), "%s",
3708 dut->ap_passphrase);
3709 owrt_ap_set_vap(dut, vap_count,
3710 "wpa_passphrase", buf);
3711 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003712 break;
3713 case AP_WPA2_EAP:
3714 case AP_WPA2_EAP_MIXED:
3715 case AP_WPA_EAP:
3716 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3717 snprintf(buf, sizeof(buf), "wpa2");
3718 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3719 snprintf(buf, sizeof(buf), "wpa-mixed");
3720 } else {
3721 snprintf(buf, sizeof(buf), "wpa");
3722 }
3723
Peng Xu591be452017-05-10 17:27:28 -07003724 if (dut->ap_cipher == AP_CCMP_TKIP)
3725 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3726 else if (dut->ap_cipher == AP_TKIP)
3727 strlcat(buf, "+tkip", sizeof(buf));
3728 else
3729 strlcat(buf, "+ccmp", sizeof(buf));
3730
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003731 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3732 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3733 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3734 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3735 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3736 snprintf(buf, sizeof(buf), "%s",
3737 dut->ap_radius_password);
3738 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3739 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003740 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003741 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003742 case AP_WPA2_FT_EAP:
3743 case AP_WPA2_FT_PSK:
3744 case AP_WPA2_EAP_SHA256:
3745 case AP_WPA2_PSK_SHA256:
3746 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003747 /* TODO */
3748 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003749 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003750 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3751 snprintf(buf, sizeof(buf), "gcmp");
3752 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3753 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3754 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3755 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3756 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3757 snprintf(buf, sizeof(buf), "%s",
3758 dut->ap_radius_password);
3759 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3760 snprintf(buf, sizeof(buf), "%d",
3761 dut->ap_group_mgmt_cipher);
3762 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3763 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003764 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003765 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003766 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3767 snprintf(buf, sizeof(buf), "ccmp");
3768 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3769 if (dut->ap_sae_groups) {
3770 snprintf(buf, sizeof(buf), "\'%s\'",
3771 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003772 owrt_ap_set_list_vap(dut, vap_count,
3773 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003774 }
3775
3776 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3777 dut->ap_tag_ssid[0][0] &&
3778 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3779 /* OWE transition mode */
3780 snprintf(ifname2, sizeof(ifname2), "%s1",
3781 ifname);
3782 owrt_ap_set_vap(dut, vap_count,
3783 "owe_transition_ifname",
3784 ifname2);
3785 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3786 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003787 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003788 }
3789
3790 if (!dut->ap_is_dual)
3791 break;
3792 }
3793
3794 if (dut->ap_is_dual)
3795 return 1;
3796
3797 /* PMF */
3798 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3799 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3800
3801 /* Add SHA256 */
3802 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3803 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3804
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003805 /* Add SHA384 for akmsuitetype 15 */
3806 if (dut->ap_akm == 1) {
3807 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3808 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3809 }
3810
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303811 /* Enable RSN preauthentication, if asked to */
3812 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3813 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3814
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003815 /* Hotspot 2.0 */
3816 if (dut->ap_hs2) {
3817 int ret;
3818
3819 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3820 if (ret)
3821 return ret;
3822 }
3823
3824 /* Interworking */
3825 if (dut->ap_interworking) {
3826 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3827 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3828 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3829 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3830 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3831 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3832 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3833 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3834 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3835 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3836
3837 if (dut->ap_gas_cb_delay > 0) {
3838 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3839 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3840 }
3841
3842 if (dut->ap_roaming_cons[0]) {
3843 char *rcons, *temp_ptr;
3844
3845 rcons = strdup(dut->ap_roaming_cons);
3846 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003847 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003848
3849 temp_ptr = strchr(rcons, ';');
3850
3851 if (temp_ptr)
3852 *temp_ptr++ = '\0';
3853
3854 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3855 rcons);
3856
3857 if (temp_ptr)
3858 owrt_ap_set_list_vap(dut, vap_id,
3859 "roaming_consortium",
3860 temp_ptr);
3861
3862 free(rcons);
3863 }
3864 }
3865
3866 if (dut->ap_venue_name) {
3867 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3868 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3869 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3870 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3871 }
3872
3873 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003874 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3875 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003876 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003877 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003878 }
3879
3880 if (dut->ap_nai_realm_list == 1) {
3881 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3882 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3883 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3884 "'0,wi-fi.org;example.com,13[5:6]'");
3885
3886 } else if (dut->ap_nai_realm_list == 2) {
3887 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3888 "'0,wi-fi.org,21[2:4][5:7]'");
3889 } else if (dut->ap_nai_realm_list == 3) {
3890 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3891 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3892 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3893 "'0,wi-fi.org;example.com,13[5:6]'");
3894 } else if (dut->ap_nai_realm_list == 4) {
3895 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3896 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3897 } else if (dut->ap_nai_realm_list == 5) {
3898 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3899 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3900 } else if (dut->ap_nai_realm_list == 6) {
3901 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3902 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3903 } else if (dut->ap_nai_realm_list == 7) {
3904 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3905 "'0,wi-fi.org,13[5:6]'");
3906 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3907 "'0,wi-fi.org,21[2:4][5:7]'");
3908 }
3909
3910 if (dut->ap_domain_name_list[0])
3911 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3912 dut->ap_domain_name_list);
3913
3914 if (dut->ap_ip_addr_type_avail)
3915 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3916 "'0c'");
3917
3918 temp = buf;
3919
3920 *temp++ = '\'';
3921
3922 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3923 if (i)
3924 *temp++ = ';';
3925
3926 snprintf(temp,
3927 sizeof(dut->ap_plmn_mcc[i]) +
3928 sizeof(dut->ap_plmn_mnc[i]) + 1,
3929 "%s,%s",
3930 dut->ap_plmn_mcc[i],
3931 dut->ap_plmn_mnc[i]);
3932
3933 temp += strlen(dut->ap_plmn_mcc[i]) +
3934 strlen(dut->ap_plmn_mnc[i]) + 1;
3935 }
3936
3937 *temp++ = '\'';
3938 *temp++ = '\0';
3939
3940 if (i)
3941 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3942
3943 if (dut->ap_qos_map_set == 1)
3944 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3945 else if (dut->ap_qos_map_set == 2)
3946 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3947
3948 /* Proxy-ARP */
3949 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3950 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3951
3952 /* DGAF */
3953 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3954 /* parse to hostapd */
3955 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3956 /* parse to wifi driver */
3957 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3958
3959 /* HCBSSLoad */
3960 if (dut->ap_bss_load) {
3961 unsigned int bssload = 0;
3962
3963 if (dut->ap_bss_load == 1) {
3964 /* STA count: 1, CU: 50, AAC: 65535 */
3965 bssload = 0x0132ffff;
3966 } else if (dut->ap_bss_load == 2) {
3967 /* STA count: 1, CU: 200, AAC: 65535 */
3968 bssload = 0x01c8ffff;
3969 } else if (dut->ap_bss_load == 3) {
3970 /* STA count: 1, CU: 75, AAC: 65535 */
3971 bssload = 0x014bffff;
3972 }
3973
3974 snprintf(buf, sizeof(buf), "%d", bssload);
3975 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3976 }
3977
3978 /* L2TIF */
3979 if (dut->ap_l2tif)
3980 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3981
3982 if (dut->ap_disable_protection == 1)
3983 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3984
Sunil Dutt77b213d2017-09-14 18:24:40 +03003985 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003986 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3987 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08003988 if (dut->program == PROGRAM_HE) {
3989 owrt_ap_set_vap(dut, vap_id, "he_subfer", "1");
3990 owrt_ap_set_vap(dut, vap_id, "cwmenable", "0");
3991 }
3992 } else {
3993 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
3994 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
3995 if (dut->program == PROGRAM_HE)
3996 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003997 }
3998
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08003999 if (dut->ap_mu_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004000 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08004001 if (dut->program == PROGRAM_HE) {
4002 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "1");
4003 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "1");
4004 }
4005 } else {
4006 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "0");
4007 if (dut->program == PROGRAM_HE) {
4008 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "0");
4009 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "0");
4010 }
4011 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004012
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05304013 if (dut->ap_tx_stbc) {
4014 /* STBC and beamforming are mutually exclusive features */
4015 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
4016 }
4017
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05304018 /* enable dfsmode */
4019 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
4020 owrt_ap_set_vap(dut, vap_id, "doth", buf);
4021
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004022 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
4023 char anqpval[1024];
4024
4025 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
4026
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004027 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304028 snprintf(anqpval, sizeof(anqpval),
4029 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004030 dut->ap_val_lci, dut->ap_infoz);
4031 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4032 }
4033
4034 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304035 snprintf(anqpval, sizeof(anqpval),
4036 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004037 dut->ap_val_lcr);
4038 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4039 }
4040
4041 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
4042 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4043 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
4044 }
4045
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004046 if (dut->program == PROGRAM_MBO) {
4047 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
4048 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
4049 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07004050 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004051
4052 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4053 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07004054 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
4055 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004056 }
4057
Jouni Malinen6be21c82018-08-01 18:47:24 +03004058 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004059 unsigned char self_mac[ETH_ALEN];
4060 char mac_str[20];
4061
Jouni Malinen9f943312019-08-19 23:49:16 +03004062 owrt_ap_set_vap(dut, vap_id, "ft_over_ds",
4063 dut->ap_ft_ds == VALUE_ENABLED ? "1" : "0");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004064 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02004065 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
4066 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004067 snprintf(mac_str, sizeof(mac_str),
4068 "%02x:%02x:%02x:%02x:%02x:%02x",
4069 self_mac[0], self_mac[1], self_mac[2],
4070 self_mac[3], self_mac[4], self_mac[5]);
4071 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004072 snprintf(mac_str, sizeof(mac_str),
4073 "%02x:%02x:%02x:%02x:%02x:%02x",
4074 self_mac[0], self_mac[1], self_mac[2],
4075 self_mac[3], self_mac[4], self_mac[5]);
4076 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004077 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
4078 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
4079 "000102030405060708090a0b0c0d0e0f");
4080 snprintf(mac_str, sizeof(mac_str),
4081 "%02x:%02x:%02x:%02x:%02x:%02x",
4082 dut->ft_bss_mac_list[0][0],
4083 dut->ft_bss_mac_list[0][1],
4084 dut->ft_bss_mac_list[0][2],
4085 dut->ft_bss_mac_list[0][3],
4086 dut->ft_bss_mac_list[0][4],
4087 dut->ft_bss_mac_list[0][5]);
4088 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004089 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
4090 dut->ap_mobility_domain);
4091 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004092 }
4093
Jouni Malinen6be21c82018-08-01 18:47:24 +03004094 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
4095 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004096 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
4097 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004098 }
4099
Jouni Malinen6be21c82018-08-01 18:47:24 +03004100 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004101 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
4102 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004103 }
4104
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08004105 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
4106 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
4107
priyadharshini gowthamande81f392017-12-28 15:28:49 -08004108 /* Enable/disable PMKSA caching, if asked to */
4109 if (dut->ap_pmksa == 1) {
4110 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
4111 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
4112 }
4113
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004114 if (dut->rsne_override) {
4115 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
4116 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
4117 }
4118
Jouni Malinen7960e3a2019-12-07 17:04:35 +02004119 if (dut->rsnxe_override_eapol)
4120 owrt_ap_set_vap(dut, vap_count, "rsnxe_override_eapol",
4121 dut->rsnxe_override_eapol);
4122
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004123 if (dut->sae_commit_override) {
4124 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
4125 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
4126 }
4127
4128 if (dut->ap_sae_groups) {
4129 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07004130 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004131 }
4132
Jouni Malinen11e55212019-11-22 21:46:59 +02004133 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
4134 const char *sae_pwe = NULL;
4135
4136 if (dut->sae_pwe == SAE_PWE_LOOP)
4137 sae_pwe = "0";
4138 else if (dut->sae_pwe == SAE_PWE_H2E)
4139 sae_pwe = "1";
4140 else if (dut->sae_h2e_default)
4141 sae_pwe = "2";
4142 if (sae_pwe)
4143 owrt_ap_set_vap(dut, vap_count, "sae_pwe", sae_pwe);
4144 }
4145
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004146 if (dut->sae_anti_clogging_threshold >= 0) {
4147 snprintf(buf, sizeof(buf), "%d",
4148 dut->sae_anti_clogging_threshold);
4149 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
4150 buf);
4151 }
4152
4153 if (dut->sae_reflection)
4154 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03004155 if (dut->sae_confirm_immediate)
Jouni Malinena6f1db02020-01-23 00:46:12 +02004156 owrt_ap_set_vap(dut, vap_count, "sae_confirm_immediate", "2");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004157
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07004158 if (dut->ap_he_dlofdma == VALUE_ENABLED && dut->ap_he_ppdu == PPDU_MU) {
4159 dut->ap_txBF = 0;
4160 dut->ap_mu_txBF = 0;
4161 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
4162 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
4163 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
4164 }
4165
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07004166 if (dut->program == PROGRAM_HE &&
4167 (dut->ap_txBF || dut->ap_he_ulofdma == VALUE_ENABLED ||
4168 dut->ap_he_mimo == MIMO_DL)) {
4169 switch (dut->ap_chwidth) {
4170 case AP_20:
4171 owrt_ap_set_vap(dut, vap_id, "chwidth", "0");
4172 break;
4173 case AP_40:
4174 owrt_ap_set_vap(dut, vap_id, "chwidth", "1");
4175 break;
4176 case AP_80:
4177 owrt_ap_set_vap(dut, vap_id, "chwidth", "2");
4178 break;
4179 case AP_160:
4180 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4181 break;
4182 case AP_80_80:
4183 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4184 break;
4185 case AP_AUTO:
4186 default:
4187 break;
4188 }
4189 }
4190
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004191 return 1;
4192}
4193
4194
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004195static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
4196{
4197 char anqpval[1024];
4198 unsigned char addr[6];
4199 unsigned char addr2[6];
4200 struct ifreq ifr;
4201 char *ifname;
4202 int s;
4203 int vap_id = 0;
4204
4205 s = socket(AF_INET, SOCK_DGRAM, 0);
4206 if (s < 0) {
4207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
4208 return -1;
4209 }
4210
4211 memset(&ifr, 0, sizeof(ifr));
4212 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004213 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004214 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4215 perror("ioctl");
4216 close(s);
4217 return -1;
4218 }
4219 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
4220
4221 memset(&ifr, 0, sizeof(ifr));
4222 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004223 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004224 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4225 perror("ioctl");
4226 close(s);
4227 return -1;
4228 }
4229 close(s);
4230 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
4231
4232 snprintf(anqpval, sizeof(anqpval),
4233 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
4234 dut->ap_val_lci, dut->ap_infoz,
4235 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
4236 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
4237
4238 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4239 return 0;
4240}
4241
4242
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004243static int owrt_ap_post_config_commit(struct sigma_dut *dut,
4244 struct sigma_conn *conn,
4245 struct sigma_cmd *cmd)
4246{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004247 int ap_security = 0;
4248 int i;
4249
4250 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
4251 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
4252 ap_security = 1;
4253 }
4254 if (dut->ap_key_mgmt != AP_OPEN)
4255 ap_security = 1;
4256 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 /* allow some time for hostapd to start before returning
4258 * success */
4259 usleep(500000);
4260
4261 if (run_hostapd_cli(dut, "ping") != 0) {
4262 send_resp(dut, conn, SIGMA_ERROR,
4263 "errorCode,Failed to talk to hostapd");
4264 return 0;
4265 }
4266 }
4267
4268 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
4269 ath_ap_set_params(dut);
4270
4271 /* Send response */
4272 return 1;
4273}
4274
4275
4276static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
4277 struct sigma_conn *conn,
4278 struct sigma_cmd *cmd)
4279{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004280 if (dut->program == PROGRAM_DPP &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004281 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004282 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
4283 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
4284 }
4285
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004286 /* Stop the AP */
4287 run_system(dut, "wifi down");
4288
4289 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05304290 run_system(dut, "rm -rf /etc/config/wireless");
4291 switch (get_openwrt_driver_type()) {
4292 case OPENWRT_DRIVER_ATHEROS:
4293 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
4294 break;
4295 default:
4296 run_system(dut, "wifi detect > /etc/config/wireless");
4297 break;
4298 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004299
4300 /* Configure Radio & VAP, commit the config */
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07004301 if (owrt_ap_config_radio(dut) < 0)
4302 return ERROR_SEND_STATUS;
Jouni Malinen13701222019-02-19 12:10:53 +02004303 if (owrt_ap_config_vap(dut) < 0)
4304 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004305 run_system(dut, "uci commit");
4306
4307 /* Start AP */
4308 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004309 if (dut->program != PROGRAM_MBO &&
4310 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004311 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004312 /*
4313 * MBO has a different ANQP element value which is set in
4314 * owrt_ap_config_vap().
4315 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004316 owrt_ap_config_vap_anqp(dut);
4317 run_system(dut, "uci commit");
4318 run_system(dut, "wifi");
4319 }
4320
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004321 return owrt_ap_post_config_commit(dut, conn, cmd);
4322}
4323
4324
4325static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
4326{
4327 unsigned char bssid[6];
4328 char buf[100];
4329 char *ifname, *radio_name;
4330 int vap_id = 0;
4331
4332 if (sigma_radio_ifname[0] &&
4333 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4334 ifname = "ath2";
4335 radio_name = "wifi2";
4336 vap_id = 2;
4337 } else if (sigma_radio_ifname[0] &&
4338 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4339 ifname = "ath1";
4340 radio_name = "wifi1";
4341 vap_id = 1;
4342 } else {
4343 ifname = "ath0";
4344 radio_name = "wifi0";
4345 vap_id = 0;
4346 }
4347
4348 if (!get_hwaddr(ifname, bssid)) {
4349 snprintf(buf, sizeof(buf), "%s", bssid);
4350 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4351 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4352 "%02x:%02x:%02x:%02x:%02x:%02x",
4353 bssid[0], bssid[1], bssid[2], bssid[3],
4354 bssid[4], bssid[5]);
4355 } else {
4356 if (!get_hwaddr(radio_name, bssid)) {
4357 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
4358 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4359 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4360 "%02x:%02x:%02x:%02x:%02x:%02x",
4361 bssid[0], bssid[1], bssid[2], bssid[3],
4362 bssid[4], bssid[5]);
4363 } else {
4364 /* Select & enable/disable radios */
4365 if (sigma_radio_ifname[0] &&
4366 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4367 /* We want to use wifi2 */
4368 owrt_ap_set_radio(dut, 0, "disabled", "1");
4369 owrt_ap_set_radio(dut, 1, "disabled", "1");
4370 owrt_ap_set_radio(dut, 2, "disabled", "0");
4371 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
4372 } else if (sigma_radio_ifname[0] &&
4373 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4374 /* We want to use wifi1 */
4375 owrt_ap_set_radio(dut, 0, "disabled", "1");
4376 owrt_ap_set_radio(dut, 1, "disabled", "0");
4377 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
4378 } else {
4379 /* We want to use wifi0 */
4380 owrt_ap_set_radio(dut, 0, "disabled", "0");
4381 owrt_ap_set_radio(dut, 1, "disabled", "1");
4382 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
4383 }
4384
4385 run_system(dut, "uci commit");
4386 run_system(dut, "wifi up");
4387
4388 if (!get_hwaddr(radio_name, bssid)) {
4389 snprintf(buf, sizeof(buf), "%s",
4390 dut->ap_hessid);
4391 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4392 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4393 "%02x:%02x:%02x:%02x:%02x:%02x",
4394 bssid[0], bssid[1], bssid[2], bssid[3],
4395 bssid[4], bssid[5]);
4396 }
4397 }
4398 }
4399}
4400
4401
Jouni Malinenf7222712019-06-13 01:50:21 +03004402static enum sigma_cmd_result cmd_ap_reboot(struct sigma_dut *dut,
4403 struct sigma_conn *conn,
4404 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004406 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 case DRIVER_ATHEROS:
4408 run_system(dut, "apdown");
4409 sleep(1);
4410 run_system(dut, "reboot");
4411 break;
4412 case DRIVER_OPENWRT:
4413 run_system(dut, "wifi down");
4414 sleep(1);
4415 run_system(dut, "reboot");
4416 break;
4417 default:
4418 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
4419 break;
4420 }
4421
4422 return 1;
4423}
4424
4425
4426int ascii2hexstr(const char *str, char *hex)
4427{
4428 int i, length;
4429
4430 length = strlen(str);
4431
4432 for (i = 0; i < length; i++)
4433 snprintf(hex + i * 2, 3, "%X", str[i]);
4434
4435 hex[length * 2] = '\0';
4436 return 1;
4437}
4438
4439
4440static int kill_process(struct sigma_dut *dut, char *proc_name,
4441 unsigned char is_proc_instance_one, int sig)
4442{
4443#ifdef __linux__
4444 struct dirent *dp, *dp_in;
4445 const char *direc = "/proc/";
4446 char buf[100];
4447 DIR *dir = opendir(direc);
4448 DIR *dir_in;
4449 FILE *fp;
4450 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304451 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004452 int ret = -1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004453
4454 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304455 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004456
4457 while ((dp = readdir(dir)) != NULL) {
4458 if (dp->d_type != DT_DIR)
4459 continue;
4460
Jouni Malinen3aa72862019-05-29 23:14:51 +03004461 res = snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
4462 if (res < 0 || res >= sizeof(buf))
4463 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004464 dir_in = opendir(buf);
4465 if (dir_in == NULL)
4466 continue;
4467 dp_in = readdir(dir_in);
4468 closedir(dir_in);
4469 if (dp_in == NULL)
4470 continue;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004471 res = snprintf(buf, sizeof(buf), "%s%s/stat",
4472 direc, dp->d_name);
4473 if (res < 0 || res >= sizeof(buf))
4474 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004475 fp = fopen(buf, "r");
4476 if (fp == NULL)
4477 continue;
4478 if (fgets(buf, 100, fp) == NULL)
4479 buf[0] = '\0';
4480 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304481 pid = strtok_r(buf, " ", &saveptr);
4482 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004483 if (pid && temp &&
4484 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
4485 sigma_dut_print(dut, DUT_MSG_INFO,
4486 "killing %s process with PID %s",
4487 proc_name, pid);
4488 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
4489 atoi(pid));
4490 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304491 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004492 if (is_proc_instance_one)
4493 break;
4494 }
4495 }
4496
4497 closedir(dir);
4498
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304499 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004500#else /* __linux__ */
4501 return -1;
4502#endif /* __linux__ */
4503}
4504
4505
4506static int run_ndc(struct sigma_dut *dut, char *buf)
4507{
4508 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
4509 sleep(2);
4510 return run_system(dut, buf);
4511}
4512
4513
4514static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
4515 const char *field, const char *value)
4516{
4517 FILE *fcfg, *ftmp;
4518 char buf[MAX_CONF_LINE_LEN + 1];
4519 int len, found = 0, res;
4520
4521 /* Open the configuration file */
4522 fcfg = fopen(pfile, "r");
4523 if (!fcfg) {
4524 sigma_dut_print(dut, DUT_MSG_ERROR,
4525 "Failed to open hostapd conf file");
4526 return -1;
4527 }
4528
4529 snprintf(buf, sizeof(buf), "%s~", pfile);
4530 /* Open a temporary file */
4531 ftmp = fopen(buf, "w+");
4532 if (!ftmp) {
4533 fclose(fcfg);
4534 sigma_dut_print(dut, DUT_MSG_ERROR,
4535 "Failed to open temp buf");
4536 return -1;
4537 }
4538
4539 /* Read the values from the configuration file */
4540 len = strlen(field);
4541 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
4542 char *pline = buf;
4543
4544 /* commented line */
4545 if (buf[0] == '#')
4546 pline++;
4547
4548 /* Identify the configuration parameter to be updated */
4549 if (!found && strncmp(pline, field, len) == 0 &&
4550 pline[len] == '=') {
4551 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4552 found = 1;
4553 sigma_dut_print(dut, DUT_MSG_INFO,
4554 "Updated hostapd conf file");
4555 }
4556
4557 fprintf(ftmp, "%s", buf);
4558 }
4559
4560 if (!found) {
4561 /* Configuration line not found */
4562 /* Add the new line at the end of file */
4563 fprintf(ftmp, "%s=%s\n", field, value);
4564 sigma_dut_print(dut, DUT_MSG_INFO,
4565 "Adding a new line in hostapd conf file");
4566 }
4567
4568 fclose(fcfg);
4569 fclose(ftmp);
4570
4571 snprintf(buf, sizeof(buf), "%s~", pfile);
4572
4573 /* Restore the updated configuration file */
4574 res = rename(buf, pfile);
4575
4576 /* Remove the temporary file. Ignore the return value */
4577 unlink(buf);
4578
4579 /* chmod is needed because open() may not set permissions properly
4580 * depending on the current umask */
4581 if (chmod(pfile, 0660) < 0) {
4582 unlink(pfile);
4583 sigma_dut_print(dut, DUT_MSG_ERROR,
4584 "Error changing permissions");
4585 return -1;
4586 }
4587
4588 if (res < 0) {
4589 sigma_dut_print(dut, DUT_MSG_ERROR,
4590 "Error restoring conf file");
4591 return -1;
4592 }
4593
4594 return 0;
4595}
4596
4597
4598static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4599 struct sigma_conn *conn,
4600 struct sigma_cmd *cmd)
4601{
4602 char buf[100];
4603 struct stat s;
4604 int num_tries = 0, ret;
4605
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304606 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4607 system("killall netd") == 0) {
4608 /* Avoid Error: Error connecting (Connection refused)
4609 * Wait some time to allow netd to reinitialize.
4610 */
4611 usleep(1500000);
4612 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004613
4614 while (num_tries < 10) {
4615 ret = run_ndc(dut, "ndc softap stopap");
4616 num_tries++;
4617 if (WIFEXITED(ret))
4618 ret = WEXITSTATUS(ret);
4619 /* On success, NDC exits with 0 */
4620 if (ret == 0)
4621 break;
4622 sigma_dut_print(dut, DUT_MSG_INFO,
4623 "Try No. %d: ndc softap stopap failed, exit code %d",
4624 num_tries, ret);
4625 }
4626
4627 if (ret != 0)
4628 sigma_dut_print(dut, DUT_MSG_ERROR,
4629 "ndc softap stopap command failed for 10 times - giving up");
4630
4631#ifdef ANDROID
4632 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304633 system("rmmod -f wlan");
4634 usleep(500000);
4635 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004636#else /* ANDROID */
4637 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4638 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4639#endif /* ANDROID */
4640
4641 switch (dut->ap_mode) {
4642 case AP_11g:
4643 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4644 break;
4645 case AP_11b:
4646 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4647 break;
4648 case AP_11ng:
4649 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4650 break;
4651 case AP_11a:
4652 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4653 break;
4654 case AP_11na:
4655 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4656 break;
4657 case AP_11ac:
4658 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4659 break;
4660 default:
4661 break;
4662 }
4663
4664 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4665 dut->ap_channel);
4666 run_ndc(dut, buf);
4667
4668 /*
4669 * ndc doesn't support double quotes as SSID string, so re-write
4670 * hostapd configuration file to update SSID.
4671 */
4672 if (dut->ap_ssid[0] != '\0')
4673 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4674
4675 switch (dut->ap_key_mgmt) {
4676 case AP_OPEN:
4677 if (dut->ap_cipher == AP_WEP) {
4678 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4679 snprintf(buf, sizeof(buf),
4680 "ndc softap qccmd set wep_key0=%s",
4681 dut->ap_wepkey);
4682 run_ndc(dut, buf);
4683 } else {
4684 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4685 }
4686 break;
4687 case AP_WPA2_PSK:
4688 case AP_WPA2_PSK_MIXED:
4689 case AP_WPA_PSK:
4690 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4691 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4692 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4693 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4694 else
4695 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4696
4697 /*
4698 * ndc doesn't support some special characters as passphrase,
4699 * so re-write hostapd configuration file to update Passphrase.
4700 */
4701 if (dut->ap_passphrase[0] != '\0')
4702 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4703 "wpa_passphrase", dut->ap_passphrase);
4704
4705 if (dut->ap_cipher == AP_CCMP_TKIP)
4706 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4707 "TKIP CCMP");
4708 else if (dut->ap_cipher == AP_TKIP)
4709 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4710 "TKIP");
4711 else
4712 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4713 "CCMP &");
4714 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004715 case AP_WPA2_SAE:
4716 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004717 case AP_WPA2_EAP:
4718 case AP_WPA2_EAP_MIXED:
4719 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004720 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004721 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004722 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004723 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004724 case AP_WPA2_FT_EAP:
4725 case AP_WPA2_FT_PSK:
4726 case AP_WPA2_EAP_SHA256:
4727 case AP_WPA2_PSK_SHA256:
4728 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004729 /* Not supported */
4730 break;
4731 }
4732
4733 switch (dut->ap_pmf) {
4734 case AP_PMF_DISABLED:
4735 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4736 break;
4737 case AP_PMF_OPTIONAL:
4738 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4739 if (dut->ap_add_sha256)
4740 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4741 else
4742 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4743 break;
4744 case AP_PMF_REQUIRED:
4745 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4746 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4747 break;
4748 }
4749
4750 if (dut->ap_countrycode[0]) {
4751 snprintf(buf, sizeof(buf),
4752 "ndc softap qccmd set country_code=%s",
4753 dut->ap_countrycode);
4754 run_ndc(dut, buf);
4755 }
4756
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304757 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4758 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4759
4760 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4761 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4762
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004763 run_ndc(dut, "ndc softap startap");
4764
Jouni Malinen5ea30922019-11-04 17:39:25 +02004765 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl,
4766 get_main_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004767 num_tries = 0;
4768 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4769 run_ndc(dut, "ndc softap stopap");
4770 run_ndc(dut, "ndc softap startap");
4771 num_tries++;
4772 }
4773
4774 if (num_tries == 10) {
4775 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4776 "iface %s :: reboot the APDUT", buf);
4777 return ret;
4778 }
4779
4780 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4781 ap_inet_addr, ap_inet_mask);
4782 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Jouni Malinen5ea30922019-11-04 17:39:25 +02004783 get_main_ifname(dut), ap_inet_addr, ap_inet_mask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004784 if (system(buf) != 0) {
4785 sigma_dut_print(dut, DUT_MSG_ERROR,
4786 "Failed to intialize the interface");
4787 return -1;
4788 }
4789
4790 return 1;
4791}
4792
4793
4794static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4795{
4796 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4797 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4798
4799 if (dut->ap_oper_name) {
4800 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4801 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4802 }
4803
4804 if (dut->ap_wan_metrics == 1)
4805 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4806 else if (dut->ap_wan_metrics == 2)
4807 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4808 else if (dut->ap_wan_metrics == 3)
4809 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4810 else if (dut->ap_wan_metrics == 4)
4811 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4812 else if (dut->ap_wan_metrics == 5)
4813 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4814
4815 if (dut->ap_conn_capab == 1) {
4816 fprintf(f, "hs20_conn_capab=1:0:0\n");
4817 fprintf(f, "hs20_conn_capab=6:20:1\n");
4818 fprintf(f, "hs20_conn_capab=6:22:0\n");
4819 fprintf(f, "hs20_conn_capab=6:80:1\n");
4820 fprintf(f, "hs20_conn_capab=6:443:1\n");
4821 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4822 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4823 fprintf(f, "hs20_conn_capab=17:500:1\n");
4824 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4825 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4826 fprintf(f, "hs20_conn_capab=50:0:1\n");
4827 } else if (dut->ap_conn_capab == 2) {
4828 fprintf(f, "hs20_conn_capab=6:80:1\n");
4829 fprintf(f, "hs20_conn_capab=6:443:1\n");
4830 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4831 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4832 } else if (dut->ap_conn_capab == 3) {
4833 fprintf(f, "hs20_conn_capab=6:80:1\n");
4834 fprintf(f, "hs20_conn_capab=6:443:1\n");
4835 } else if (dut->ap_conn_capab == 4) {
4836 fprintf(f, "hs20_conn_capab=6:80:1\n");
4837 fprintf(f, "hs20_conn_capab=6:443:1\n");
4838 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4839 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4840 }
4841
4842 if (dut->ap_oper_class == 1)
4843 fprintf(f, "hs20_operating_class=51\n");
4844 else if (dut->ap_oper_class == 2)
4845 fprintf(f, "hs20_operating_class=73\n");
4846 else if (dut->ap_oper_class == 3)
4847 fprintf(f, "hs20_operating_class=5173\n");
4848
4849 if (dut->ap_osu_provider_list) {
4850 char *osu_friendly_name = NULL;
4851 char *osu_icon = NULL;
4852 char *osu_ssid = NULL;
4853 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004854 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004855 char *osu_service_desc = NULL;
4856 char *hs20_icon_filename = NULL;
4857 char hs20_icon[150];
4858 int osu_method;
4859
4860 hs20_icon_filename = "icon_red_zxx.png";
4861 if (dut->ap_osu_icon_tag == 2)
4862 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4863 snprintf(hs20_icon, sizeof(hs20_icon),
4864 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4865 hs20_icon_filename);
4866 osu_icon = "icon_red_zxx.png";
4867 osu_ssid = "OSU";
4868 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4869 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4870 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4871
4872 if (strlen(dut->ap_osu_server_uri[0]))
4873 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4874 else
4875 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4876
4877 switch (dut->ap_osu_provider_list) {
4878 case 1:
4879 case 101:
4880 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4881 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4882 hs20_icon_filename = "icon_red_eng.png";
4883 if (dut->ap_osu_icon_tag == 2)
4884 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4885 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4886 hs20_icon_filename);
4887 fprintf(f, "osu_icon=icon_red_eng.png\n");
4888 break;
4889 case 2:
4890 case 102:
4891 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4892 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4893 hs20_icon_filename = "icon_orange_zxx.png";
4894 if (dut->ap_osu_icon_tag == 2)
4895 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4896 snprintf(hs20_icon, sizeof(hs20_icon),
4897 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4898 hs20_icon_filename);
4899 osu_icon = "icon_orange_zxx.png";
4900 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4901 break;
4902 case 3:
4903 case 103:
4904 osu_friendly_name = "spa:SP Red Test Only";
4905 osu_service_desc = "spa:Free service for test purpose";
4906 break;
4907 case 4:
4908 case 104:
4909 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4910 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4911 hs20_icon_filename = "icon_orange_eng.png";
4912 if (dut->ap_osu_icon_tag == 2)
4913 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4914 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4915 hs20_icon_filename);
4916 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4917 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4918
4919 hs20_icon_filename = "icon_orange_zxx.png";
4920 if (dut->ap_osu_icon_tag == 2)
4921 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4922 snprintf(hs20_icon, sizeof(hs20_icon),
4923 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4924 hs20_icon_filename);
4925 osu_icon = "icon_orange_zxx.png";
4926 break;
4927 case 5:
4928 case 105:
4929 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4930 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4931 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4932 hs20_icon_filename = "icon_orange_zxx.png";
4933 if (dut->ap_osu_icon_tag == 2)
4934 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4935 snprintf(hs20_icon, sizeof(hs20_icon),
4936 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4937 hs20_icon_filename);
4938 osu_icon = "icon_orange_zxx.png";
4939 break;
4940 case 6:
4941 case 106:
4942 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4943 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4944 hs20_icon_filename = "icon_green_zxx.png";
4945 if (dut->ap_osu_icon_tag == 2)
4946 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4947 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4948 hs20_icon_filename);
4949 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4950 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4951 fprintf(f, "osu_method_list=%d\n", osu_method);
4952
4953 if (strlen(dut->ap_osu_server_uri[1]))
4954 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4955 else
4956 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4957 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4958 hs20_icon_filename = "icon_orange_zxx.png";
4959 if (dut->ap_osu_icon_tag == 2)
4960 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4961 snprintf(hs20_icon, sizeof(hs20_icon),
4962 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4963 hs20_icon_filename);
4964 osu_icon = "icon_orange_zxx.png";
4965 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4966 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4967 osu_service_desc = NULL;
4968 break;
4969 case 7:
4970 case 107:
4971 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4972 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4973 hs20_icon_filename = "icon_green_eng.png";
4974 if (dut->ap_osu_icon_tag == 2)
4975 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4976 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4977 hs20_icon_filename);
4978 fprintf(f, "osu_icon=icon_green_eng.png\n");
4979 osu_friendly_name = "kor:SP 초록 테스트 전용";
4980
4981 hs20_icon_filename = "icon_green_zxx.png";
4982 if (dut->ap_osu_icon_tag == 2)
4983 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4984 snprintf(hs20_icon, sizeof(hs20_icon),
4985 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4986 hs20_icon_filename);
4987 osu_icon = "icon_green_zxx.png";
4988 break;
4989 case 8:
4990 case 108:
4991 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4992 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4993 osu_ssid = "OSU-Encrypted";
4994 osu_nai = "anonymous@hotspot.net";
4995 break;
4996 case 9:
4997 case 109:
4998 osu_ssid = "OSU-OSEN";
4999 osu_nai = "test-anonymous@wi-fi.org";
5000 osu_friendly_name = "eng:SP Orange Test Only";
5001 hs20_icon_filename = "icon_orange_zxx.png";
5002 if (dut->ap_osu_icon_tag == 2)
5003 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
5004 snprintf(hs20_icon, sizeof(hs20_icon),
5005 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
5006 hs20_icon_filename);
5007 osu_icon = "icon_orange_zxx.png";
5008 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
5009 osu_service_desc = NULL;
5010 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02005011 case 10:
5012 case 110:
5013 /* OSU Provider #1 */
5014 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
5015 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
5016 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
5017 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
5018 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
5019 1 : dut->ap_osu_method[0];
5020 fprintf(f, "osu_method_list=%d\n", osu_method);
5021 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
5022 switch (dut->ap_osu_provider_nai_list) {
5023 case 3:
5024 fprintf(f,
5025 "osu_nai2=test-anonymous@wi-fi.org\n");
5026 break;
5027 case 4:
5028 fprintf(f, "osu_nai2=random@hotspot.net\n");
5029 break;
5030 }
5031
5032 /* OSU Provider #2 */
5033 /* SP Red from defaults */
5034 if (strlen(dut->ap_osu_server_uri[1]))
5035 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
5036 else
5037 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
5038 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
5039 snprintf(hs20_icon, sizeof(hs20_icon),
5040 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
5041 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
5042 1 : dut->ap_osu_method[1];
5043 osu_service_desc = NULL;
5044 osu_nai = "anonymous@hotspot.net";
5045 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046 default:
5047 break;
5048 }
5049
Jouni Malinen93a837f2018-11-01 17:09:22 +02005050 switch (dut->ap_osu_provider_nai_list) {
5051 case 1:
5052 osu_nai2 = "anonymous@hotspot.net";
5053 break;
5054 case 2:
5055 osu_nai2 = "test-anonymous@wi-fi.org";
5056 break;
5057 case 3:
5058 /* OSU Provider NAI #1 written above */
5059 /* OSU Provider NAI #2 */
5060 osu_nai2 = "anonymous@hotspot.net";
5061 break;
5062 case 4:
5063 /* OSU Provider NAI #1 written above */
5064 /* OSU Provider NAI #2 */
5065 osu_nai2 = "anonymous@hotspot.net";
5066 break;
5067 }
5068
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005069 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03005070 if (dut->ap_tag_ssid[0][0] &&
5071 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005072 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005073 sigma_dut_print(dut, DUT_MSG_ERROR,
5074 "OSU_SSID and "
5075 "WLAN_TAG2 SSID differ");
5076 return -2;
5077 }
5078 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
5079 } else
5080 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
5081
5082
5083 if (osu_friendly_name)
5084 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
5085
5086 if (osu_service_desc)
5087 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
5088
5089 if (osu_nai)
5090 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02005091 if (osu_nai2)
5092 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005093
5094 fprintf(f, "hs20_icon=%s\n", hs20_icon);
5095
5096 if (osu_icon)
5097 fprintf(f, "osu_icon=%s\n", osu_icon);
5098
5099 if (dut->ap_osu_provider_list > 100)
5100 fprintf(f, "osu_method_list=0\n");
5101 else
5102 fprintf(f, "osu_method_list=%d\n", osu_method);
5103 }
5104
Jouni Malinen54a89b02018-05-01 00:16:26 +03005105 switch (dut->ap_venue_url) {
5106 case 1:
5107 fprintf(f,
5108 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5109 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
5110 break;
5111 case 2:
5112 fprintf(f,
5113 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5114 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5115 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5116 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5117 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5118 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5119 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5120 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5121 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5122 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5123 );
5124 break;
5125 }
5126
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03005127 switch (dut->ap_advice_of_charge) {
5128 case 1:
5129 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
5130 break;
5131 }
5132
Jouni Malinenac104532018-05-01 00:27:37 +03005133 switch (dut->ap_oper_icon_metadata) {
5134 case 1:
5135 fprintf(f,
5136 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
5137 "operator_icon=icon_red_eng.png\n");
5138 break;
5139 }
5140
Jouni Malinenac367142018-05-01 00:32:24 +03005141 switch (dut->ap_tnc_file_name) {
5142 case 1:
5143 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
5144 break;
5145 }
5146
5147 if (dut->ap_tnc_time_stamp)
5148 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
5149
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005150 return 0;
5151}
5152
5153
5154static void write_ap_roaming_cons(FILE *f, const char *list)
5155{
5156 char *buf, *pos, *end;
5157
5158 if (list == NULL || list[0] == '\0')
5159 return;
5160
5161 buf = strdup(list);
5162 if (buf == NULL)
5163 return;
5164
5165 pos = buf;
5166 while (pos && *pos) {
5167 end = strchr(pos, ';');
5168 if (end)
5169 *end++ = '\0';
5170 fprintf(f, "roaming_consortium=%s\n", pos);
5171 pos = end;
5172 }
5173
5174 free(buf);
5175}
5176
5177
5178static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
5179{
5180 int i;
5181 char buf[100], *temp;
5182
5183 if (dut->ap_gas_cb_delay > 0)
5184 fprintf(f, "gas_comeback_delay=%d\n",
5185 dut->ap_gas_cb_delay);
5186
5187 fprintf(f, "interworking=1\n"
5188 "access_network_type=%d\n"
5189 "internet=%d\n"
5190 "asra=0\n"
5191 "esr=0\n"
5192 "uesa=0\n"
5193 "venue_group=%d\n"
5194 "venue_type=%d\n",
5195 dut->ap_access_net_type,
5196 dut->ap_internet,
5197 dut->ap_venue_group,
5198 dut->ap_venue_type);
5199 if (dut->ap_hessid[0])
5200 fprintf(f, "hessid=%s\n", dut->ap_hessid);
5201
5202 write_ap_roaming_cons(f, dut->ap_roaming_cons);
5203
5204 if (dut->ap_venue_name) {
5205 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
5206 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
5207 }
5208
5209 if (dut->ap_net_auth_type == 1)
5210 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
5211 else if (dut->ap_net_auth_type == 2)
5212 fprintf(f, "network_auth_type=01\n");
5213
5214 if (dut->ap_nai_realm_list == 1) {
5215 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
5216 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5217 } else if (dut->ap_nai_realm_list == 2) {
5218 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5219 } else if (dut->ap_nai_realm_list == 3) {
5220 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
5221 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5222 } else if (dut->ap_nai_realm_list == 4) {
5223 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
5224 } else if (dut->ap_nai_realm_list == 5) {
5225 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
5226 } else if (dut->ap_nai_realm_list == 6) {
5227 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
5228 } else if (dut->ap_nai_realm_list == 7) {
5229 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
5230 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5231 }
5232
5233 if (dut->ap_domain_name_list[0]) {
5234 fprintf(f, "domain_name=%s\n",
5235 dut->ap_domain_name_list);
5236 }
5237
5238 if (dut->ap_ip_addr_type_avail == 1) {
5239 fprintf(f, "ipaddr_type_availability=0c\n");
5240 }
5241
5242 temp = buf;
5243 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
5244 i++) {
5245 if (i)
5246 *temp++ = ';';
5247
5248 snprintf(temp,
5249 sizeof(dut->ap_plmn_mcc[i]) +
5250 sizeof(dut->ap_plmn_mnc[i]) + 1,
5251 "%s,%s",
5252 dut->ap_plmn_mcc[i],
5253 dut->ap_plmn_mnc[i]);
5254
5255 temp += strlen(dut->ap_plmn_mcc[i]) +
5256 strlen(dut->ap_plmn_mnc[i]) + 1;
5257 }
5258 if (i)
5259 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
5260
5261 if (dut->ap_qos_map_set == 1)
5262 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
5263 else if (dut->ap_qos_map_set == 2)
5264 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
5265
5266 return 0;
5267}
5268
5269
5270static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
5271{
5272 FILE *f;
5273
5274 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
5275 system("killall hostapd") == 0) {
5276 int i;
5277
5278 /* Wait some time to allow hostapd to complete cleanup before
5279 * starting a new process */
5280 for (i = 0; i < 10; i++) {
5281 usleep(500000);
5282 if (system("pidof hostapd") != 0)
5283 break;
5284 }
5285 }
5286
5287 f = fopen("/tmp/secath0", "a");
5288 if (f == NULL)
5289 return -2;
5290
5291 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
5292 fclose(f);
5293 return -2;
5294 }
5295
5296 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
5297 fclose(f);
5298 return -2;
5299 }
5300
5301 fflush(f);
5302 fclose(f);
5303 return ath_ap_start_hostapd(dut);
5304}
5305
5306
5307static int ath_ap_start_hostapd(struct sigma_dut *dut)
5308{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005309 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005310 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
5311 else
5312 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
5313
5314 return 0;
5315}
5316
5317
5318#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
5319
5320static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
5321{
5322 FILE *f;
5323 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
5324 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
5325 char buf[100];
5326 int i;
5327
5328 f = fopen("/root/anqpserver.conf", "w");
5329 if (f == NULL)
5330 return -1;
5331
5332 if (dut->ap_nai_realm_list == 1) {
5333 nai_realm = 1;
5334 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");
5335 } else if (dut->ap_nai_realm_list == 2) {
5336 nai_realm = 1;
5337 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
5338 } else if (dut->ap_nai_realm_list == 3) {
5339 nai_realm = 1;
5340 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");
5341 } else if (dut->ap_nai_realm_list == 4) {
5342 nai_realm = 1;
5343 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");
5344 } else
5345 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
5346
5347 if (dut->ap_domain_name_list[0]) {
5348 char *next, *start, *dnbuf, *dn1, *anqp_dn;
5349 int len, dn_len_max;
5350 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305351 if (dnbuf == NULL) {
5352 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005353 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305354 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005355
5356 len = strlen(dnbuf);
5357 dn_len_max = 50 + len*2;
5358 anqp_dn = malloc(dn_len_max);
5359 if (anqp_dn == NULL) {
5360 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305361 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005362 return -1;
5363 }
5364 start = dnbuf;
5365 dn1 = anqp_dn;
5366 while (start && *start) {
5367 char *hexstr;
5368
5369 next = strchr(start, ',');
5370 if (next)
5371 *next++ = '\0';
5372
5373 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05305374 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005375 if (hexstr == NULL) {
5376 free(dnbuf);
5377 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305378 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005379 return -1;
5380 }
5381 ascii2hexstr(start, hexstr);
5382 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
5383 free(hexstr);
5384 dn1 += 2 + len * 2;
5385 dn_len_max -= 2 + len * 2;
5386 start = next;
5387 }
5388 free(dnbuf);
5389 if (dut->ap_gas_cb_delay) {
5390 fprintf(f, "dyn_domain_name=0c01%04x%s",
5391 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5392 domain_name = 1;
5393 } else
5394 fprintf(f, "domain_name=0c01%04x%s",
5395 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5396 free(anqp_dn);
5397 } else
5398 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
5399
5400 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
5401
5402 if (dut->ap_oper_name) {
5403 if (dut->ap_gas_cb_delay) {
5404 fprintf(f, "dyn_oper_friendly_name="
5405 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5406 oper_name = 1;
5407 } else
5408 fprintf(f, "oper_friendly_name="
5409 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5410 } else
5411 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
5412
5413 if (dut->ap_venue_name) {
5414 if (dut->ap_gas_cb_delay) {
5415 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
5416 venue_name = 1;
5417 } else
5418 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
5419 } else
5420 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
5421
5422 if (dut->ap_wan_metrics) {
5423 if (dut->ap_gas_cb_delay) {
5424 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
5425 wan_metrics = 1;
5426 } else
5427 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
5428 "\n");
5429 } else
5430 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
5431
5432 if (dut->ap_conn_capab) {
5433 if (dut->ap_gas_cb_delay) {
5434 fprintf(f, "dyn_conn_capability="
5435 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5436 conn_cap = 1;
5437 } else
5438 fprintf(f, "conn_capability="
5439 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5440 } else
5441 sigma_dut_print(dut, DUT_MSG_ERROR,
5442 "not setting conn_capability");
5443
5444 if (dut->ap_ip_addr_type_avail) {
5445 if (dut->ap_gas_cb_delay) {
5446 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
5447 "\n");
5448 ipaddr_avail = 1;
5449 } else
5450 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
5451 } else
5452 sigma_dut_print(dut, DUT_MSG_ERROR,
5453 "not setting ipaddr_type_avail");
5454
5455 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
5456 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
5457 dut->ap_plmn_mcc[i][1],
5458 dut->ap_plmn_mcc[i][0],
5459 dut->ap_plmn_mnc[i][2] == '\0' ?
5460 'f' : dut->ap_plmn_mnc[i][2],
5461 dut->ap_plmn_mcc[i][2],
5462 dut->ap_plmn_mnc[i][1],
5463 dut->ap_plmn_mnc[i][0]);
5464 }
5465 if (i) {
5466 uint16_t ie_len = (i * 3) + 5;
5467 if (dut->ap_gas_cb_delay) {
5468 fprintf(f, "dyn_cell_net=0801");
5469 cell_net = 1;
5470 } else
5471 fprintf(f, "cell_net=0801");
5472 fprintf(f, "%04x", LE16(ie_len));
5473 fprintf(f, "00"); /* version */
5474 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
5475 fprintf(f, "00"); /* plmn list */
5476 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
5477 fprintf(f, "%02x", i); /* number of plmns */
5478 fprintf(f, "%s\n", buf); /* plmns */
5479 } else
5480 sigma_dut_print(dut, DUT_MSG_ERROR,
5481 "not setting 3gpp_cellular_network");
5482
5483 if (nai_realm || domain_name || oper_name || venue_name ||
5484 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
5485 fprintf(f, "anqp_attach=");
5486 if (venue_name)
5487 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
5488 if (nai_realm)
5489 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
5490 if (cell_net)
5491 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
5492 if (domain_name)
5493 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
5494 if (oper_name)
5495 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
5496 if (wan_metrics)
5497 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
5498 if (conn_cap)
5499 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
5500 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
5501 fprintf(f, "\n");
5502 }
5503
5504 fclose(f);
5505
5506 run_system(dut, "anqpserver -i ath0 &");
5507 if (!dut->ap_anqpserver_on)
5508 run_system(dut, "killall anqpserver");
5509
5510 return 1;
5511}
5512
5513
5514static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
5515{
5516 char buf[100];
5517
5518 run_system(dut, "cfg -a AP_STARTMODE=standard");
5519
5520 if (sigma_radio_ifname[0] &&
5521 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
5522 run_system(dut, "cfg -a AP_RADIO_ID=1");
5523 switch (dut->ap_mode) {
5524 case AP_11g:
5525 run_system(dut, "cfg -a AP_CHMODE_2=11G");
5526 break;
5527 case AP_11b:
5528 run_system(dut, "cfg -a AP_CHMODE_2=11B");
5529 break;
5530 case AP_11ng:
5531 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
5532 break;
5533 case AP_11a:
5534 run_system(dut, "cfg -a AP_CHMODE_2=11A");
5535 break;
5536 case AP_11na:
5537 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
5538 break;
5539 case AP_11ac:
5540 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5541 break;
5542 default:
5543 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5544 break;
5545 }
5546
5547 switch (dut->ap_rx_streams) {
5548 case 1:
5549 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5550 break;
5551 case 2:
5552 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5553 break;
5554 case 3:
5555 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5556 break;
5557 }
5558
5559 switch (dut->ap_tx_streams) {
5560 case 1:
5561 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5562 break;
5563 case 2:
5564 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5565 break;
5566 case 3:
5567 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5568 break;
5569 }
5570
5571 switch (dut->ap_chwidth) {
5572 case AP_20:
5573 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5574 break;
5575 case AP_40:
5576 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5577 break;
5578 case AP_80:
5579 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5580 break;
5581 case AP_160:
5582 case AP_AUTO:
5583 default:
5584 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5585 break;
5586 }
5587
5588 if (dut->ap_tx_stbc) {
5589 run_system(dut, "cfg -a TX_STBC_2=1");
5590 }
5591
5592 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5593 dut->ap_channel);
5594
5595 if (dut->ap_is_dual) {
5596 switch (dut->ap_mode_1) {
5597 case AP_11g:
5598 run_system(dut, "cfg -a AP_CHMODE=11G");
5599 break;
5600 case AP_11b:
5601 run_system(dut, "cfg -a AP_CHMODE=11B");
5602 break;
5603 case AP_11ng:
5604 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5605 break;
5606 case AP_11a:
5607 run_system(dut, "cfg -a AP_CHMODE=11A");
5608 break;
5609 case AP_11na:
5610 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5611 break;
5612 case AP_11ac:
5613 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5614 break;
5615 default:
5616 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5617 break;
5618 }
5619 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5620 dut->ap_channel_1);
5621 }
5622 run_system(dut, buf);
5623 } else {
5624 run_system(dut, "cfg -a AP_RADIO_ID=0");
5625 switch (dut->ap_mode) {
5626 case AP_11g:
5627 run_system(dut, "cfg -a AP_CHMODE=11G");
5628 break;
5629 case AP_11b:
5630 run_system(dut, "cfg -a AP_CHMODE=11B");
5631 break;
5632 case AP_11ng:
5633 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5634 break;
5635 case AP_11a:
5636 run_system(dut, "cfg -a AP_CHMODE=11A");
5637 break;
5638 case AP_11na:
5639 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5640 break;
5641 case AP_11ac:
5642 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5643 break;
5644 default:
5645 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5646 break;
5647 }
5648 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5649 dut->ap_channel);
5650 run_system(dut, buf);
5651 }
5652
5653 if (dut->ap_sgi80 == 1) {
5654 run_system(dut, "cfg -a SHORTGI=1");
5655 run_system(dut, "cfg -a SHORTGI_2=1");
5656 } else if (dut->ap_sgi80 == 0) {
5657 run_system(dut, "cfg -a SHORTGI=0");
5658 run_system(dut, "cfg -a SHORTGI_2=0");
5659 }
5660
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005661 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005662 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005663 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005664 run_system(dut, "cfg -a LDPC=0");
5665}
5666
5667
5668void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5669{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005670 run_iwpriv(dut, intf, "vhtsubfee 0");
5671 run_iwpriv(dut, intf, "vhtsubfer 0");
5672 run_iwpriv(dut, intf, "vhtmubfee 0");
5673 run_iwpriv(dut, intf, "vhtmubfer 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674}
5675
5676
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005677static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5678 const char *val)
5679{
5680 if (strcasecmp(val, "enable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005681 run_iwpriv(dut, ifname, "mbo_asoc_dis 1");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005682 } else if (strcasecmp(val, "disable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005683 run_iwpriv(dut, ifname, "mbo_asoc_dis 0");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005684 } else {
5685 sigma_dut_print(dut, DUT_MSG_ERROR,
5686 "Unsupported assoc_disallow");
5687 }
5688}
5689
5690
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005691static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5692{
5693 int i;
5694 int least_pref = 1 << 8;
5695 char ifname[20];
5696 uint8_t self_mac[ETH_ALEN];
5697 char buf[200];
5698 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5699
5700 get_if_name(dut, ifname, sizeof(ifname), 1);
5701 get_hwaddr(ifname, self_mac);
5702
5703 /* Clear off */
5704 snprintf(buf, sizeof(buf),
5705 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5706 ifname);
5707 run_system(dut, buf);
5708
5709 /* Find the least preference number */
5710 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5711 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5712
5713 ap_ne_class = 1;
5714 ap_ne_pref = 255;
5715 ap_ne_op_ch = 1;
5716 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5717 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5718 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5719 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5720 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5721 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5722
5723 if (ap_ne_pref < least_pref)
5724 least_pref = ap_ne_pref;
5725 snprintf(buf, sizeof(buf),
5726 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5727 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5728 mac_addr[3], mac_addr[4], mac_addr[5],
5729 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5730 run_system(dut, buf);
5731 }
5732
5733 /* Now add the self AP Address */
5734 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5735 if (dut->ap_channel <= 11)
5736 ap_ne_class = 81;
5737 else
5738 ap_ne_class = 115;
5739 } else {
5740 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5741 }
5742
5743 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5744 ap_ne_op_ch = dut->ap_channel;
5745 else
5746 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5747
5748 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5749 ap_ne_pref = least_pref - 1;
5750 else
5751 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5752
5753 snprintf(buf, sizeof(buf),
5754 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5755 ifname, self_mac[0], self_mac[1], self_mac[2],
5756 self_mac[3], self_mac[4], self_mac[5],
5757 ap_ne_pref,
5758 ap_ne_class,
5759 ap_ne_op_ch);
5760 run_system(dut, buf);
5761}
5762
5763
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -07005764static void mubrp_commands(struct sigma_dut *dut, const char *ifname)
5765{
5766 run_iwpriv(dut, ifname, "he_subfer 1");
5767 run_iwpriv(dut, ifname, "he_mubfer 1");
5768 /* To enable MU_AX with MU_BRP trigger */
5769 run_iwpriv(dut, ifname, "he_sounding_mode 13");
5770 /* Sets g_force_1x1_peer to 1 which should be reset to zero for non MU
5771 * test cases */
5772 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 118 1",
5773 ifname);
5774 /* Disable DL OFDMA */
5775 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 11 0",
5776 ifname);
5777}
5778
5779
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005780static void ath_ap_set_params(struct sigma_dut *dut)
5781{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005782 const char *basedev = "wifi0";
5783 const char *basedev_radio = "wifi1";
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005784 const char *ifname = get_main_ifname(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005785 char *ifname_dual = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005787 char buf[300];
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08005788 unsigned int he_mcsnssmap = dut->he_mcsnssmap;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005790 if (sigma_radio_ifname[0])
5791 basedev = sigma_radio_ifname[0];
5792
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005793 if (dut->ap_is_dual == 1) {
5794 basedev = sigma_radio_ifname[0];
5795 basedev_radio = sigma_radio_ifname[1];
5796 if (sigma_radio_ifname[0] &&
5797 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5798 ifname = "ath0";
5799 ifname_dual = "ath1";
5800 } else {
5801 ifname = "ath1";
5802 ifname_dual = "ath0";
5803 }
5804 }
5805
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005806 if (dut->ap_countrycode[0]) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005807 run_iwpriv(dut, basedev, "setCountry %s", dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005808 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5809 }
5810
5811 for (i = 0; i < NUM_AP_AC; i++) {
5812 if (dut->ap_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005813 run_iwpriv(dut, ifname, "cwmin %d 0 %d", i,
5814 dut->ap_qos[i].cwmin);
5815 run_iwpriv(dut, ifname, "cwmax %d 0 %d", i,
5816 dut->ap_qos[i].cwmax);
5817 run_iwpriv(dut, ifname, "aifs %d 0 %d", i,
5818 dut->ap_qos[i].aifs);
5819 run_iwpriv(dut, ifname, "txoplimit %d 0 %d", i,
5820 dut->ap_qos[i].txop);
5821 run_iwpriv(dut, ifname, "acm %d 0 %d", i,
5822 dut->ap_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005823 }
5824 }
5825
5826 for (i = 0; i < NUM_AP_AC; i++) {
5827 if (dut->ap_sta_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005828 run_iwpriv(dut, ifname, "cwmin %d 1 %d", i,
5829 dut->ap_sta_qos[i].cwmin);
5830 run_iwpriv(dut, ifname, "cwmax %d 1 %d", i,
5831 dut->ap_sta_qos[i].cwmax);
5832 run_iwpriv(dut, ifname, "aifs %d 1 %d", i,
5833 dut->ap_sta_qos[i].aifs);
5834 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", i,
5835 dut->ap_sta_qos[i].txop);
5836 run_iwpriv(dut, ifname, "acm %d 1 %d", i,
5837 dut->ap_sta_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838 }
5839 }
5840
5841 if (dut->ap_disable_protection == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005842 run_iwpriv(dut, ifname, "enablertscts 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005843 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5844 }
5845
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005846 if (dut->ap_ldpc == VALUE_ENABLED)
5847 run_iwpriv(dut, ifname, "ldpc 3");
5848 else if (dut->ap_ldpc == VALUE_DISABLED)
5849 run_iwpriv(dut, ifname, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005850
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005851 if (dut->ap_ampdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005852 run_iwpriv(dut, ifname, "ampdu 1");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005853 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005854 run_iwpriv(dut, ifname, "ampdu 0");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005855 if (dut->program == PROGRAM_HE) {
5856 run_iwpriv(dut, ifname, "setaddbaoper 1");
5857 run_system_wrapper(dut, "wifitool %s refusealladdbas 1",
5858 ifname);
5859 if (dut->ap_amsdu == VALUE_ENABLED) {
5860 /* disable the limit for A-MSDU */
5861 run_system_wrapper(dut,
5862 "wifitool %s setUnitTestCmd 0x48 2 46 1",
5863 ifname);
5864 }
5865 }
5866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867
5868 if (dut->ap_ampdu_exp) {
5869 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005870 run_iwpriv(dut, ifname, "vhtmaxampdu %d",
5871 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872 } else {
5873 /* 11N */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005874 run_iwpriv(dut, ifname, "maxampdu %d",
5875 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005876 }
5877 }
5878
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005879 if (dut->ap_noack == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005880 run_iwpriv(dut, ifname, "noackpolicy 0 0 1");
5881 run_iwpriv(dut, ifname, "noackpolicy 1 0 1");
5882 run_iwpriv(dut, ifname, "noackpolicy 2 0 1");
5883 run_iwpriv(dut, ifname, "noackpolicy 3 0 1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005884 } else if (dut->ap_noack == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005885 run_iwpriv(dut, ifname, "noackpolicy 0 0 0");
5886 run_iwpriv(dut, ifname, "noackpolicy 1 0 0");
5887 run_iwpriv(dut, ifname, "noackpolicy 2 0 0");
5888 run_iwpriv(dut, ifname, "noackpolicy 3 0 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005889 }
5890
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005891 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map)
5892 run_iwpriv(dut, ifname, "vht_mcsmap 0x%04x",
5893 dut->ap_vhtmcs_map);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005895 if (dut->ap_amsdu == VALUE_ENABLED)
5896 run_iwpriv(dut, ifname, "amsdu 2");
5897 else if (dut->ap_amsdu == VALUE_DISABLED)
5898 run_iwpriv(dut, ifname, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005900 if (dut->ap_rx_amsdu == VALUE_ENABLED)
5901 run_iwpriv(dut, basedev_radio, "rx_amsdu 1");
5902 else if (dut->ap_rx_amsdu == VALUE_DISABLED)
5903 run_iwpriv(dut, basedev_radio, "rx_amsdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005904
5905 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005906 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5907 dut->ap_ampdu == VALUE_DISABLED &&
5908 dut->ap_amsdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005909 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910
5911 snprintf(buf, sizeof(buf),
5912 "wifitool %s senddelba 1 0 1 4", ifname);
5913 if (system(buf) != 0) {
5914 sigma_dut_print(dut, DUT_MSG_ERROR,
5915 "wifitool senddelba failed");
5916 }
5917
5918 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5919 ifname);
5920 if (system(buf) != 0) {
5921 sigma_dut_print(dut, DUT_MSG_ERROR,
5922 "wifitool sendsingleamsdu failed");
5923 }
5924
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005925 run_iwpriv(dut, ifname, "amsdu 10");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005926 }
5927
5928 if (dut->ap_mode == AP_11ac) {
5929 int chwidth, nss;
5930
5931 switch (dut->ap_chwidth) {
5932 case AP_20:
5933 chwidth = 0;
5934 break;
5935 case AP_40:
5936 chwidth = 1;
5937 break;
5938 case AP_80:
5939 chwidth = 2;
5940 break;
5941 case AP_160:
5942 chwidth = 3;
5943 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005944 case AP_80_80:
5945 chwidth = 3;
5946 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005947 default:
5948 chwidth = 0;
5949 break;
5950 }
5951
5952 switch (dut->ap_tx_streams) {
5953 case 1:
5954 nss = 1;
5955 break;
5956 case 2:
5957 nss = 2;
5958 break;
5959 case 3:
5960 nss = 3;
5961 break;
5962 case 4:
5963 nss = 4;
5964 break;
5965 default:
5966 nss = 3;
5967 break;
5968 }
5969
5970 if (dut->ap_fixed_rate) {
5971 if (nss == 4)
5972 ath_disable_txbf(dut, ifname);
5973
5974 /* Set the nss */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005975 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005976
5977 /* Set the channel width */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005978 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005979
5980 /* Set the VHT MCS */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005981 run_iwpriv(dut, ifname, "vhtmcs %d", dut->ap_mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005982 }
5983 }
5984
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005985 if (dut->ap_dyn_bw_sig == VALUE_ENABLED)
5986 run_iwpriv(dut, ifname, "cwmenable 1");
5987 else if (dut->ap_dyn_bw_sig == VALUE_DISABLED)
5988 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005989
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005990 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005991 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5992 if (system(buf) != 0) {
5993 sigma_dut_print(dut, DUT_MSG_ERROR,
5994 "iwconfig rts 64 failed");
5995 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005996 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005997 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5998 if (system(buf) != 0) {
5999 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006000 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006001 }
6002 }
6003
6004 if (dut->ap_hs2) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006005 run_iwpriv(dut, ifname, "qbssload 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006006 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
6007 }
6008
6009 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
6010 unsigned int bssload = 0;
6011
6012 if (dut->ap_bss_load == 1) {
6013 /* STA count: 1, CU: 50, AAC: 65535 */
6014 bssload = 0x0132ffff;
6015 } else if (dut->ap_bss_load == 2) {
6016 /* STA count: 1, CU: 200, AAC: 65535 */
6017 bssload = 0x01c8ffff;
6018 } else if (dut->ap_bss_load == 3) {
6019 /* STA count: 1, CU: 75, AAC: 65535 */
6020 bssload = 0x014bffff;
6021 }
6022
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006023 run_iwpriv(dut, ifname, "hcbssload %u", bssload);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006024 } else if (dut->ap_bss_load == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006025 run_iwpriv(dut, ifname, "qbssload 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006026 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
6027 }
6028
6029 if (dut->ap_dgaf_disable) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006030 run_iwpriv(dut, ifname, "dgaf_disable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006031 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
6032 }
6033
6034 if (dut->ap_l2tif) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006035 run_iwpriv(dut, ifname, "l2tif 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006036 snprintf(buf, sizeof(buf),
6037 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
6038 if (system(buf) != 0)
6039 sigma_dut_print(dut, DUT_MSG_ERROR,
6040 "l2tif br failed");
6041
6042 snprintf(buf, sizeof(buf),
6043 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
6044 if (system(buf) != 0)
6045 sigma_dut_print(dut, DUT_MSG_ERROR,
6046 "l2tif brif failed");
6047 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
6048 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08006049
6050 if (dut->ap_ndpa_frame == 0) {
6051 snprintf(buf, sizeof(buf),
6052 "wifitool %s beeliner_fw_test 117 192", ifname);
6053 if (system(buf) != 0) {
6054 sigma_dut_print(dut, DUT_MSG_ERROR,
6055 "wifitool beeliner_fw_test 117 192 failed");
6056 }
6057 snprintf(buf, sizeof(buf),
6058 "wifitool %s beeliner_fw_test 118 192", ifname);
6059 if (system(buf) != 0) {
6060 sigma_dut_print(dut, DUT_MSG_ERROR,
6061 "wifitool beeliner_fw_test 117 192 failed");
6062 }
6063 } else if (dut->ap_ndpa_frame == 1) {
6064 /* Driver default - no changes needed */
6065 } else if (dut->ap_ndpa_frame == 2) {
6066 snprintf(buf, sizeof(buf),
6067 "wifitool %s beeliner_fw_test 115 1", ifname);
6068 if (system(buf) != 0) {
6069 sigma_dut_print(dut, DUT_MSG_ERROR,
6070 "wifitool beeliner_fw_test 117 192 failed");
6071 }
6072 snprintf(buf, sizeof(buf),
6073 "wifitool %s beeliner_fw_test 116 1", ifname);
6074 if (system(buf) != 0) {
6075 sigma_dut_print(dut, DUT_MSG_ERROR,
6076 "wifitool beeliner_fw_test 117 192 failed");
6077 }
6078 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006079
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006080 if (dut->ap_rtt == 1)
6081 run_iwpriv(dut, ifname, "enable_rtt 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006082
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006083 if (dut->ap_lci == 1)
6084 run_iwpriv(dut, ifname, "enable_lci 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006085
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006086 if (dut->ap_lcr == 1)
6087 run_iwpriv(dut, ifname, "enable_lcr 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006088
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006089 if (dut->ap_rrm == 1)
6090 run_iwpriv(dut, ifname, "enable_rmm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006091
6092 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
6093 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
6094 }
6095
6096 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
6097 FILE *f;
6098
6099 f = fopen("/tmp/nbr_report.txt", "w");
6100 if (!f) {
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "Failed to open /tmp/nbr_report.txt");
6103 return;
6104 }
6105
6106 fprintf(f,
6107 "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",
6108 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6109 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6110 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6111 dut->ap_val_opchannel[0]);
6112 fclose(f);
6113
6114 f = fopen("/tmp/ftmrr.txt", "w");
6115 if (!f) {
6116 sigma_dut_print(dut, DUT_MSG_ERROR,
6117 "Failed to open /tmp/ftmrr.txt");
6118 return;
6119 }
6120
6121 fprintf(f,
6122 "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",
6123 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6124 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6125 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6126 dut->ap_val_opchannel[0]);
6127 fclose(f);
6128 }
6129
6130 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
6131 FILE *f;
6132
6133 f = fopen("/tmp/nbr_report.txt", "a");
6134 if (!f) {
6135 sigma_dut_print(dut, DUT_MSG_ERROR,
6136 "Failed to open /tmp/nbr_report.txt");
6137 return;
6138 }
6139 fprintf(f,
6140 "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",
6141 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6142 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6143 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6144 dut->ap_val_opchannel[1]);
6145 fclose(f);
6146
6147 f = fopen("/tmp/ftmrr.txt", "a");
6148 if (!f) {
6149 sigma_dut_print(dut, DUT_MSG_ERROR,
6150 "Failed to open /tmp/ftmrr.txt");
6151 return;
6152 }
6153 fprintf(f,
6154 "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",
6155 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6156 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6157 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6158 dut->ap_val_opchannel[1]);
6159 fclose(f);
6160 }
6161
6162 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
6163 FILE *f;
6164
6165 f = fopen("/tmp/nbr_report.txt", "a");
6166 if (!f) {
6167 sigma_dut_print(dut, DUT_MSG_ERROR,
6168 "Failed to open /tmp/nbr_report.txt");
6169 return;
6170 }
6171
6172 fprintf(f,
6173 "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",
6174 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6175 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6176 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6177 dut->ap_val_opchannel[2]);
6178 fclose(f);
6179
6180 f = fopen("/tmp/ftmrr.txt", "a");
6181 if (!f) {
6182 sigma_dut_print(dut, DUT_MSG_ERROR,
6183 "Failed to open /tmp/ftmrr.txt");
6184 return;
6185 }
6186
6187 fprintf(f,
6188 "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",
6189 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6190 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6191 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6192 dut->ap_val_opchannel[2]);
6193 fclose(f);
6194 }
6195
6196 if (dut->ap_neighap) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006197 run_iwpriv(dut, ifname, "enable_rtt 1");
6198 run_iwpriv(dut, ifname, "enable_lci 1");
6199 run_iwpriv(dut, ifname, "enable_lcr 1");
6200 run_iwpriv(dut, ifname, "enable_rrm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006201 }
6202
6203 if (dut->ap_scan == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006204 run_iwpriv(dut, ifname, "scanentryage 600");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006205 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
6206 run_system(dut, buf);
6207 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006208
6209 if (dut->ap_set_bssidpref) {
6210 snprintf(buf, sizeof(buf),
6211 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
6212 ifname);
6213 if (system(buf) != 0) {
6214 sigma_dut_print(dut, DUT_MSG_ERROR,
6215 "wifitool clear bssidpref failed");
6216 }
6217 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006218
6219 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
6220 int feature_enable;
6221
6222 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006223 run_iwpriv(dut, ifname, "wnm %d", feature_enable);
6224 run_iwpriv(dut, ifname, "wnm_bss %d", feature_enable);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006225 if (feature_enable) {
6226 const char *extra = "";
6227
6228 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
6229 if (dut->wnm_bss_max_protection ==
6230 VALUE_ENABLED)
6231 extra = " 1";
6232 else
6233 extra = " 0";
6234 }
6235 snprintf(buf, sizeof(buf),
6236 "wlanconfig %s wnm setbssmax %d%s",
6237 ifname, dut->wnm_bss_max_idle_time, extra);
6238 run_system(dut, buf);
6239 }
6240 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006241
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006242 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006243 apply_mbo_pref_ap_list(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006244 run_iwpriv(dut, ifname, "mbo_cel_pref %d",
6245 dut->ap_cell_cap_pref);
6246 run_iwpriv(dut, ifname, "mbocap 0x40");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006247 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006248 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006249
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006250 if (dut->ap_oce == VALUE_ENABLED)
6251 run_iwpriv(dut, ifname, "set_bpr_enable 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006252
6253 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006254 run_iwpriv(dut, ifname, "prb_rate 5500");
6255 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006256 }
6257
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006258 if (dut->ap_oce == VALUE_DISABLED)
6259 run_iwpriv(dut, ifname, "set_bpr_enable 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006260
6261 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006262 run_iwpriv(dut, ifname, "mgmt_rate 1000");
6263 run_iwpriv(dut, ifname, "set_bcn_rate 1000");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006264 }
6265
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006266 if (dut->ap_bcnint)
6267 run_iwpriv(dut, ifname, "bintval %d", dut->ap_bcnint);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006268
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006269 if (dut->ap_filsdscv == VALUE_DISABLED)
6270 run_iwpriv(dut, ifname, "enable_fils 0 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006271
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006272 if (dut->ap_filshlp == VALUE_ENABLED)
6273 run_iwpriv(dut, ifname, "oce_hlp 1");
6274 else if (dut->ap_filshlp == VALUE_DISABLED)
6275 run_iwpriv(dut, ifname, "oce_hlp 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006276
6277 /* When RNR is enabled, also enable apchannelreport, background scan */
6278 if (dut->ap_rnr == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006279 run_iwpriv(dut, ifname, "rnr 1");
6280 run_iwpriv(dut, ifname, "rnr_tbtt 1");
6281 run_iwpriv(dut, ifname, "apchanrpt 1");
6282 run_iwpriv(dut, basedev, "acs_ctrlflags 0x4");
6283 run_iwpriv(dut, basedev, "acs_scanintvl 60");
6284 run_iwpriv(dut, basedev, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006285 if (dut->ap_is_dual == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006286 run_iwpriv(dut, ifname_dual, "rnr 1");
6287 run_iwpriv(dut, ifname_dual, "rnr_tbtt 1");
6288 run_iwpriv(dut, ifname_dual, "apchanrpt 1");
6289 run_iwpriv(dut, basedev_radio, "acs_ctrlflags 0x4");
6290 run_iwpriv(dut, basedev_radio, "acs_scanintvl 60");
6291 run_iwpriv(dut, basedev_radio, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006292 }
6293 }
6294
6295 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006296 run_iwpriv(dut, ifname, "qbssload 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006297 snprintf(buf, sizeof(buf),
6298 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
6299 ifname, dut->ap_blestacnt & 0xFF,
6300 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6301 dut->ap_ble_admit_cap & 0xFF,
6302 dut->ap_ble_admit_cap >> 8);
6303 run_system(dut, buf);
6304 snprintf(buf, sizeof(buf),
6305 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
6306 ifname, dut->ap_blestacnt & 0xFF,
6307 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6308 dut->ap_ble_admit_cap & 0xFF,
6309 dut->ap_ble_admit_cap >> 8);
6310 run_system(dut, buf);
6311 }
6312
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006313 if (dut->ap_esp == VALUE_ENABLED)
6314 run_iwpriv(dut, basedev, "esp_period 5");
6315 else if (dut->ap_esp == VALUE_DISABLED)
6316 run_iwpriv(dut, basedev, "esp_period 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006317
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006318 if (dut->ap_datappdudura)
6319 run_iwpriv(dut, basedev, "esp_ppdu_dur %d",
6320 dut->ap_datappdudura);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006321
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006322 if (dut->ap_airtimefract)
6323 run_iwpriv(dut, basedev, "esp_airtime %d",
6324 dut->ap_airtimefract);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006325
6326 if (dut->ap_dhcp_stop) {
6327 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
6328 run_system(dut, buf);
6329 }
6330
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006331 if (dut->ap_bawinsize)
6332 run_iwpriv(dut, basedev, "esp_ba_window %d", dut->ap_bawinsize);
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006333
6334 if (dut->program == PROGRAM_DPP) {
6335 if (dut->ap_interface_2g == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006336 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
6337 run_iwpriv(dut, ifname, "prb_rate 5500");
6338 run_iwpriv(dut, ifname, "mgmt_rate 5500");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006339 }
6340
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006341 run_iwpriv(dut, basedev, "set_rxfilter 0xffffffff");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006342 dut->hostapd_running = 1;
6343 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006344
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006345 if (dut->program == PROGRAM_HE) {
6346 /* disable sending basic triggers */
6347 run_system_wrapper(dut,
6348 "wifitool %s setUnitTestCmd 0x47 2 42 0",
6349 ifname);
6350 /* disable MU BAR */
6351 run_system_wrapper(dut,
6352 "wifitool %s setUnitTestCmd 0x47 2 64 1",
6353 ifname);
6354 /* disable PSD Boost */
6355 run_system_wrapper(dut,
6356 "wifitool %s setUnitTestCmd 0x48 2 142 1",
6357 ifname);
6358 /* Enable mix bw */
6359 run_system_wrapper(dut,
6360 "wifitool %s setUnitTestCmd 0x47 2 141 1",
6361 ifname);
6362 /* Disable preferred AC */
6363 run_system_wrapper(dut,
6364 "wifitool %s setUnitTestCmd 0x48 2 186 0",
6365 ifname);
6366 run_iwpriv(dut, basedev, "he_muedca_mode 0");
6367 run_iwpriv(dut, ifname, "he_ul_ofdma 0");
6368 run_iwpriv(dut, ifname, "he_dl_ofdma 0");
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08006369 if (dut->he_set_sta_1x1 == VALUE_ENABLED) {
6370 /* sets g_force_1x1_peer to 1 */
6371 run_system_wrapper(dut,
6372 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6373 ifname);
6374 }
Priyadharshini Gowthamand8d5f582019-11-25 15:39:43 -08006375 if (dut->ap_txBF) {
6376 /* Enable SU_AX sounding */
6377 run_iwpriv(dut, ifname, "he_sounding_mode 1");
6378 /* Ignore TBTT for NDP */
6379 run_system_wrapper(dut,
6380 "wifitool %s setUnitTestCmd 0x48 2 2 1",
6381 ifname);
6382 /* g_cv_query_enable=1, i.e., cv query enable */
6383 run_system_wrapper(dut,
6384 "wifitool %s setUnitTestCmd 0x47 2 7 1",
6385 ifname);
6386 /* Override TPC calculations and set TxBF flag to True
6387 */
6388 run_system_wrapper(dut,
6389 "wifitool %s setUnitTestCmd 0x47 2 47 1",
6390 ifname);
6391 }
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006392 if (dut->device_type == AP_testbed) {
6393 run_iwpriv(dut, ifname, "tx_stbc 0");
6394 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6395 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6396 run_iwpriv(dut, ifname, "he_amsdu_in_ampdu_supp 0");
6397 run_iwpriv(dut, ifname, "he_bfee_sts_supp 0 0");
6398 run_iwpriv(dut, ifname, "he_4xltf_800nsgi_rx 0");
6399 run_iwpriv(dut, ifname, "he_1xltf_800nsgi_rx 0");
6400 run_iwpriv(dut, ifname, "he_max_nc 0");
6401 run_iwpriv(dut, ifname, "he_bsr_supp 0");
6402 run_iwpriv(dut, ifname, "rx_stbc 0");
6403 if (dut->ap_he_dlofdma == VALUE_DISABLED)
6404 run_iwpriv(dut, ifname, "he_dlofdma 0");
6405 if (dut->ap_channel <= 11) {
6406 dut->ap_bcc = VALUE_ENABLED;
6407 run_iwpriv(dut, ifname, "vht_11ng 0");
6408 }
6409 if (!dut->ap_txBF) {
6410 run_iwpriv(dut, ifname, "he_subfer 0");
6411 run_iwpriv(dut, ifname, "he_subfee 0");
6412 }
6413 if (!dut->ap_mu_txBF) {
6414 run_iwpriv(dut, ifname, "he_mubfer 0");
6415 run_iwpriv(dut, ifname, "he_mubfee 0");
6416 }
Priyadharshini Gowthamane9d0bfc2019-11-22 14:26:12 -08006417 if (dut->ap_cipher == AP_WEP ||
6418 dut->ap_cipher == AP_TKIP)
6419 run_iwpriv(dut, ifname, "htweptkip 1");
Priyadharshini Gowthaman2e0731b2019-11-25 15:38:58 -08006420 if (dut->ap_rx_streams || dut->ap_tx_streams)
6421 run_iwpriv(dut, ifname, "nss %d",
6422 dut->ap_rx_streams);
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006423 }
6424 }
6425
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006426 if (dut->ap_he_ulofdma == VALUE_ENABLED) {
6427 run_iwpriv(dut, ifname, "he_ul_ofdma 1");
6428 run_iwpriv(dut, ifname, "he_mu_edca 1");
6429
6430 /* Disable sounding for UL OFDMA */
6431 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006432 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006433
6434 if ((dut->ap_rx_streams || dut->ap_tx_streams) &&
6435 dut->device_type == AP_testbed) {
6436 unsigned int txchainmask = 0x00;
6437
6438 switch (dut->ap_rx_streams) {
6439 case 1:
6440 txchainmask = 0x01;
6441 break;
6442 case 2:
6443 txchainmask = 0x03;
6444 break;
6445 case 3:
6446 txchainmask = 0x07;
6447 break;
6448 case 4:
6449 txchainmask = 0x0f;
6450 break;
6451 case 5:
6452 txchainmask = 0x1f;
6453 break;
6454 case 6:
6455 txchainmask = 0x3f;
6456 break;
6457 case 7:
6458 txchainmask = 0x7f;
6459 break;
6460 case 8:
6461 txchainmask = 0xff;
6462 break;
6463 }
6464
6465 run_iwpriv(dut, ifname, "he_ul_nss %d",
6466 dut->ap_rx_streams);
6467 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6468 run_iwpriv(dut, basedev, "rxchainmask %d", txchainmask);
6469 }
6470
6471 if (dut->ap_channel == 100 && dut->device_type == AP_testbed)
6472 run_system_wrapper(dut, "iwpriv %s inact 1000", ifname);
6473
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006474 if (dut->he_ul_mcs)
6475 run_iwpriv(dut, ifname, "he_ul_mcs %d", dut->he_ul_mcs);
6476
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006477 run_iwpriv(dut, ifname, "he_ul_ltf 3");
6478 run_iwpriv(dut, ifname, "he_ul_shortgi 3");
6479 run_iwpriv(dut, basedev, "he_ul_trig_int 2");
6480
Priyadharshini Gowthamana17e6d82019-12-12 14:31:09 -08006481 /* Disable efficiency check for UL OFDMA. We do not send TBPPDU
6482 * for one user. With this command, we would send UL OFDMA even
6483 * for one user to allow testing to be done without requiring
6484 * more than one station. */
6485 run_system_wrapper(dut,
6486 "wifitool %s setUnitTestCmd 0x47 2 131 0",
6487 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006488 /* Set random RU allocation */
6489 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 9 1",
6490 ifname);
6491 /* To set TBTT PPDU duration (us) */
6492 run_system_wrapper(dut,
6493 "wifitool %s setUnitTestCmd 0x48 2 63 1908",
6494 ifname);
6495 }
6496
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006497 if (dut->ap_he_dlofdma == VALUE_ENABLED) {
6498 run_iwpriv(dut, ifname, "he_dl_ofdma 1", ifname);
6499
6500 /* For fixed MCS */
6501 novap_reset(dut, ifname, 0);
6502 run_iwpriv(dut, ifname,
6503 "cfg80211tool %s setratemask 3 0x80f80f80 0x0f80f80f 0xf80f80f8");
6504 }
6505
6506 if (dut->ap_he_ppdu == PPDU_MU && dut->ap_he_dlofdma == VALUE_ENABLED) {
6507 /* Increase the min TX time limit for MU MIMO to disable MU MIMO
6508 * scheduling */
6509 run_system_wrapper(dut,
6510 "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
6511 ifname);
6512 /* Increase the max TX time limit for DL OFDMA to enable OFDMA
6513 * scheduling */
6514 run_system_wrapper(dut,
6515 "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
6516 ifname);
6517 /* Disable 'force SU schedule' to enable MU sch */
6518 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 8 0",
6519 ifname);
6520 /* Enable MU 11ax support in sch algo */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006521 run_system_wrapper(dut,
6522 "wifitool %s setUnitTestCmd 0x47 2 29 0",
6523 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006524 /* Enable to sort RU allocation */
6525 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x4b 2 2 1",
6526 ifname);
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006527 }
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07006528
6529 if (dut->ap_numsounddim) {
6530 unsigned int txchainmask = 0;
6531
6532 switch (dut->ap_numsounddim) {
6533 case 1:
6534 txchainmask = 0x01;
6535 break;
6536 case 2:
6537 txchainmask = 0x03;
6538 break;
6539 case 3:
6540 txchainmask = 0x07;
6541 break;
6542 case 4:
6543 txchainmask = 0x0f;
6544 break;
6545 case 5:
6546 txchainmask = 0x1f;
6547 break;
6548 case 6:
6549 txchainmask = 0x3f;
6550 break;
6551 case 7:
6552 txchainmask = 0x7f;
6553 break;
6554 case 8:
6555 txchainmask = 0xff;
6556 break;
6557 }
6558 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6559 }
6560
6561 if (dut->ap_numsounddim && dut->device_type == AP_testbed) {
6562 /* Sets g_force_1x1_peer to 1 which should be reset to zero
6563 * for non-MU test cases */
6564 run_system_wrapper(dut,
6565 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6566 ifname);
6567 if (dut->ap_mu_txBF) {
6568 /* Disable DL OFDMA */
6569 run_system_wrapper(dut,
6570 "wifitool %s setUnitTestCmd 0x47 2 11 0",
6571 ifname);
6572 }
6573 }
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006574
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006575 if (dut->ap_bcc == VALUE_ENABLED) {
6576 run_iwpriv(dut, ifname, "mode 11AHE20");
6577 run_iwpriv(dut, ifname, "nss 2");
6578 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6579 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6580 }
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07006581
6582 if (dut->ap_he_frag == VALUE_ENABLED)
6583 run_iwpriv(dut, ifname, "he_frag 1");
6584 else if (dut->ap_he_frag == VALUE_DISABLED)
6585 run_iwpriv(dut, ifname, "he_frag 0");
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07006586
6587 if (dut->ap_ba_bufsize != BA_BUFSIZE_NOT_SET) {
6588 if (dut->ap_ba_bufsize == BA_BUFSIZE_64)
6589 run_iwpriv(dut, ifname, "ba_bufsize 0");
6590 else
6591 run_iwpriv(dut, ifname, "ba_bufsize 1");
6592 }
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07006593
6594 if (dut->ap_mu_edca == VALUE_ENABLED)
6595 run_iwpriv(dut, ifname, "he_mu_edca 1");
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07006596
6597 if (dut->ap_he_mimo == MIMO_DL) {
6598 mubrp_commands(dut, ifname);
6599 if (dut->device_type != AP_testbed)
6600 run_system_wrapper(
6601 dut, "wifitool %s setUnitTestCmd 0x48 2 100 2",
6602 ifname);
6603 }
6604
6605 if (dut->ap_he_mimo == MIMO_UL)
6606 run_iwpriv(dut, ifname, "he_mubfee 1");
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07006607
6608 if (dut->ap_he_rtsthrshld == VALUE_ENABLED)
6609 run_iwpriv(dut, ifname, "he_rtsthrshld 512");
6610 else if (dut->ap_he_rtsthrshld == VALUE_DISABLED)
6611 run_iwpriv(dut, ifname, "he_rtsthrshld 1024");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07006612
6613 if (dut->ap_mbssid == VALUE_ENABLED &&
6614 (dut->ap_rx_streams || dut->ap_tx_streams) &&
6615 dut->device_type == AP_testbed) {
6616 const char *ifname_1;
6617
6618 ifname_1= dut->ap_channel >= 36 ? "ath01" : "ath11";
6619
6620 /* NSS is not set in Secondary VAP for MBSSID case,
6621 * hence it is explicitly set here. For primary VAP
6622 * NSS is set during AP configuration */
6623 run_iwpriv(dut, ifname_1, "nss %d", dut->ap_rx_streams);
6624 }
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07006625
6626 if (dut->ap_twtresp == VALUE_ENABLED)
6627 run_iwpriv(dut, ifname, "twt_responder 1");
6628 else if (dut->ap_twtresp == VALUE_DISABLED)
6629 run_iwpriv(dut, ifname, "twt_responder 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006630
6631 if (dut->program == PROGRAM_HE && dut->ap_fixed_rate) {
6632 int nss = 0, mcs = 0;
6633 uint16_t mcsnssmap = 0;
6634
6635 /* MCS 7 is used - set only nss and he_mcs.
6636 * Do not set mcsnssmap unless MCS is 9 or 11. */
6637 if (dut->ap_mcs >= 9) {
6638 if (dut->ap_mcs == 9) {
6639 if (dut->ap_tx_streams == 1) {
6640 nss = 1;
6641 mcs = dut->ap_mcs;
6642 } else if (dut->ap_tx_streams == 2) {
6643 nss = 2;
6644 mcs = dut->ap_mcs;
6645 }
6646 } else if (dut->ap_mcs == 11) {
6647 if (dut->ap_tx_streams == 1) {
6648 nss = 1;
6649 mcs = dut->ap_mcs;
6650 } else if (dut->ap_tx_streams == 2) {
6651 nss = 2;
6652 mcs = dut->ap_mcs;
6653 }
6654 }
6655
6656 get_he_mcs_nssmap((uint8_t *) &mcsnssmap, nss, mcs);
6657 he_mcsnssmap = (mcsnssmap << 16) | mcsnssmap;
6658 }
6659
6660 run_iwpriv(dut, ifname, "nss %d", dut->ap_tx_streams);
6661 run_iwpriv(dut, ifname, "he_mcs %d", dut->ap_mcs);
6662 }
6663
6664 if (he_mcsnssmap) {
6665 run_iwpriv(dut, ifname, "he_rxmcsmap %lu", he_mcsnssmap);
6666 run_iwpriv(dut, ifname, "he_txmcsmap %lu", he_mcsnssmap);
6667 }
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08006668
6669 if (dut->he_sounding == VALUE_ENABLED)
6670 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
6671 ifname);
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08006672
6673 if (dut->he_mmss)
6674 run_iwpriv(dut, ifname, "ampduden_ovrd %d", dut->he_mmss);
Priyadharshini Gowthaman88d55c82019-12-12 14:31:46 -08006675
6676 if (dut->he_srctrl_allow == 0) {
6677 /* This is a special testbed AP case to enable SR for protocol
6678 * testing when SRCtrl_SRValue15Allowed is specified.
6679 */
6680 run_iwpriv(dut, ifname, "he_sr_enable 1");
6681 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006682}
6683
6684
6685static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
6686 struct sigma_conn *conn,
6687 struct sigma_cmd *cmd)
6688{
6689 /* const char *name = get_param(cmd, "NAME"); */
6690 char buf[100];
6691 struct stat s;
6692 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
Jouni Malinen3aa72862019-05-29 23:14:51 +03006693 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694
6695 if (stat("/proc/athversion", &s) == 0) {
6696 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
6697 run_system(dut, "apdown");
6698 }
6699
6700 cmd_ath_ap_radio_config(dut);
6701
6702 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
6703 run_system(dut, buf);
6704
6705 switch (dut->ap_key_mgmt) {
6706 case AP_OPEN:
6707 if (dut->ap_cipher == AP_WEP) {
6708 run_system(dut, "cfg -a AP_SECMODE=WEP");
6709 run_system(dut, "cfg -a AP_SECFILE=NONE");
6710 /* shared auth mode not supported */
6711 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6712 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6713 snprintf(buf, sizeof(buf),
6714 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6715 dut->ap_wepkey);
6716 run_system(dut, buf);
6717 snprintf(buf, sizeof(buf),
6718 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6719 dut->ap_wepkey);
6720 run_system(dut, buf);
6721 } else {
6722 run_system(dut, "cfg -a AP_SECMODE=None");
6723 }
6724 break;
6725 case AP_WPA2_PSK:
6726 case AP_WPA2_PSK_MIXED:
6727 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006728 case AP_WPA2_SAE:
6729 case AP_WPA2_PSK_SAE:
6730 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6731 dut->ap_key_mgmt == AP_WPA2_SAE ||
6732 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006733 run_system(dut, "cfg -a AP_WPA=2");
6734 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6735 run_system(dut, "cfg -a AP_WPA=3");
6736 else
6737 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03006738 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006739 run_system(dut, "cfg -a AP_SECMODE=WPA");
6740 run_system(dut, "cfg -a AP_SECFILE=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006741 res = snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
6742 dut->ap_passphrase);
6743 if (res < 0 || res >= sizeof(buf))
6744 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006745 run_system(dut, buf);
6746 if (dut->ap_cipher == AP_CCMP_TKIP)
6747 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6748 else if (dut->ap_cipher == AP_TKIP)
6749 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6750 else
6751 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6752 break;
6753 case AP_WPA2_EAP:
6754 case AP_WPA2_EAP_MIXED:
6755 case AP_WPA_EAP:
6756 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6757 run_system(dut, "cfg -a AP_WPA=2");
6758 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6759 run_system(dut, "cfg -a AP_WPA=3");
6760 else
6761 run_system(dut, "cfg -a AP_WPA=1");
6762 run_system(dut, "cfg -a AP_SECMODE=WPA");
6763 run_system(dut, "cfg -a AP_SECFILE=EAP");
6764 if (dut->ap_cipher == AP_CCMP_TKIP)
6765 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6766 else if (dut->ap_cipher == AP_TKIP)
6767 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6768 else
6769 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6770 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6771 dut->ap_radius_ipaddr);
6772 run_system(dut, buf);
6773 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6774 dut->ap_radius_port);
6775 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006776 res = snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6777 dut->ap_radius_password);
6778 if (res < 0 || res >= sizeof(buf))
6779 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006780 run_system(dut, buf);
6781 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006782 case AP_WPA2_EAP_OSEN:
6783 /* TODO */
6784 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6785 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006786 case AP_SUITEB:
6787 /* TODO */
6788 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6789 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006790 case AP_WPA2_OWE:
6791 /* TODO */
6792 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6793 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006794 case AP_WPA2_FT_EAP:
6795 case AP_WPA2_FT_PSK:
6796 case AP_WPA2_EAP_SHA256:
6797 case AP_WPA2_PSK_SHA256:
6798 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006799 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006800 /* TODO */
6801 send_resp(dut, conn, SIGMA_ERROR,
6802 "errorCode,Unsupported KeyMgnt value");
6803 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006804 }
6805
6806 if (dut->ap_is_dual) {
6807 /* ath1 settings in case of dual */
6808 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6809 dut->ap_ssid);
6810 run_system(dut, buf);
6811
6812 switch (dut->ap_key_mgmt) {
6813 case AP_OPEN:
6814 if (dut->ap_cipher == AP_WEP) {
6815 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6816 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6817 /* shared auth mode not supported */
6818 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6819 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6820 snprintf(buf, sizeof(buf),
6821 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6822 dut->ap_wepkey);
6823 run_system(dut, buf);
6824 snprintf(buf, sizeof(buf),
6825 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6826 dut->ap_wepkey);
6827 run_system(dut, buf);
6828 } else {
6829 run_system(dut, "cfg -a AP_SECMODE_2=None");
6830 }
6831 break;
6832 case AP_WPA2_PSK:
6833 case AP_WPA2_PSK_MIXED:
6834 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006835 case AP_WPA2_SAE:
6836 case AP_WPA2_PSK_SAE:
6837 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6838 dut->ap_key_mgmt == AP_WPA2_SAE ||
6839 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006840 run_system(dut, "cfg -a AP_WPA_2=2");
6841 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6842 run_system(dut, "cfg -a AP_WPA_2=3");
6843 else
6844 run_system(dut, "cfg -a AP_WPA_2=1");
6845 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006846 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006847 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6848 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006849 res = snprintf(buf, sizeof(buf),
6850 "cfg -a 'PSK_KEY_2=%s'",
6851 dut->ap_passphrase);
6852 if (res < 0 || res >= sizeof(buf))
6853 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006854 run_system(dut, buf);
6855 if (dut->ap_cipher == AP_CCMP_TKIP)
6856 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6857 else if (dut->ap_cipher == AP_TKIP)
6858 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6859 else
6860 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6861 break;
6862 case AP_WPA2_EAP:
6863 case AP_WPA2_EAP_MIXED:
6864 case AP_WPA_EAP:
6865 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6866 run_system(dut, "cfg -a AP_WPA_2=2");
6867 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6868 run_system(dut, "cfg -a AP_WPA_2=3");
6869 else
6870 run_system(dut, "cfg -a AP_WPA_2=1");
6871 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6872 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6873 if (dut->ap_cipher == AP_CCMP_TKIP)
6874 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6875 else if (dut->ap_cipher == AP_TKIP)
6876 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6877 else
6878 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6879
6880 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6881 dut->ap_radius_ipaddr);
6882 run_system(dut, buf);
6883 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6884 dut->ap_radius_port);
6885 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006886 res = snprintf(buf, sizeof(buf),
6887 "cfg -a AP_AUTH_SECRET_2=%s",
6888 dut->ap_radius_password);
6889 if (res < 0 || res >= sizeof(buf))
6890 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006891 run_system(dut, buf);
6892 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006893 case AP_WPA2_EAP_OSEN:
6894 /* TODO */
6895 sigma_dut_print(dut, DUT_MSG_ERROR,
6896 "EAP+OSEN not supported");
6897 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006898 case AP_SUITEB:
6899 /* TODO */
6900 sigma_dut_print(dut, DUT_MSG_ERROR,
6901 "SuiteB not supported");
6902 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006903 case AP_WPA2_OWE:
6904 /* TODO */
6905 sigma_dut_print(dut, DUT_MSG_ERROR,
6906 "OWE not supported");
6907 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006908 case AP_WPA2_FT_EAP:
6909 case AP_WPA2_FT_PSK:
6910 case AP_WPA2_EAP_SHA256:
6911 case AP_WPA2_PSK_SHA256:
6912 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006913 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006914 /* TODO */
6915 send_resp(dut, conn, SIGMA_ERROR,
6916 "errorCode,Unsupported KeyMgnt value");
6917 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006918 }
6919
6920 /* wifi0 settings in case of dual */
6921 run_system(dut, "cfg -a AP_RADIO_ID=0");
6922 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6923 run_system(dut, "cfg -a AP_STARTMODE=dual");
6924 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6925 run_system(dut, "cfg -a TX_CHAINMASK=7");
6926 run_system(dut, "cfg -a RX_CHAINMASK=7");
6927 }
6928
6929 switch (dut->ap_pmf) {
6930 case AP_PMF_DISABLED:
6931 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6932 run_system(dut, buf);
6933 break;
6934 case AP_PMF_OPTIONAL:
6935 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6936 run_system(dut, buf);
6937 break;
6938 case AP_PMF_REQUIRED:
6939 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6940 run_system(dut, buf);
6941 break;
6942 }
6943 if (dut->ap_add_sha256) {
6944 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6945 run_system(dut, buf);
6946 } else {
6947 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6948 run_system(dut, buf);
6949 }
6950
6951 if (dut->ap_hs2)
6952 run_system(dut, "cfg -a AP_HOTSPOT=1");
6953 else
6954 run_system(dut, "cfg -r AP_HOTSPOT");
6955
6956 if (dut->ap_interworking) {
6957 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6958 dut->ap_access_net_type);
6959 run_system(dut, buf);
6960 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6961 dut->ap_internet);
6962 run_system(dut, buf);
6963 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6964 dut->ap_venue_group);
6965 run_system(dut, buf);
6966 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6967 dut->ap_venue_type);
6968 run_system(dut, buf);
6969 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6970 dut->ap_hessid);
6971 run_system(dut, buf);
6972
6973 if (dut->ap_roaming_cons[0]) {
6974 char *second, *rc;
6975 rc = strdup(dut->ap_roaming_cons);
6976 if (rc == NULL)
6977 return 0;
6978
6979 second = strchr(rc, ';');
6980 if (second)
6981 *second++ = '\0';
6982
6983 snprintf(buf, sizeof(buf),
6984 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6985 run_system(dut, buf);
6986
6987 if (second) {
6988 snprintf(buf, sizeof(buf),
6989 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6990 "=%s", second);
6991 run_system(dut, buf);
6992 }
6993 free(rc);
6994 } else {
6995 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6996 run_system(dut,
6997 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6998 }
6999 } else {
7000 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
7001 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
7002 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
7003 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
7004 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
7005 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
7006 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
7007 }
7008
7009 if (dut->ap_proxy_arp)
7010 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
7011 else
7012 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
7013 if (dut->ap_dgaf_disable)
7014 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
7015 else
7016 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
7017
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007018 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007019 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007020 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007021 run_system(dut, buf);
7022
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007023 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007024 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
7025 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
7026
Jouni Malinen3aa72862019-05-29 23:14:51 +03007027 res = snprintf(buf, sizeof(buf),
7028 "cfg -a AP_AUTH_SERVER_2=%s",
7029 dut->ap2_radius_ipaddr);
7030 if (res < 0 || res >= sizeof(buf))
7031 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007032 run_system(dut, buf);
7033
Jouni Malinen3aa72862019-05-29 23:14:51 +03007034 res = snprintf(buf, sizeof(buf),
7035 "cfg -a AP_AUTH_PORT_2=%d",
7036 dut->ap2_radius_port);
7037 if (res < 0 || res >= sizeof(buf))
7038 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007039 run_system(dut, buf);
7040
Jouni Malinen3aa72862019-05-29 23:14:51 +03007041 res = snprintf(buf, sizeof(buf),
7042 "cfg -a AP_AUTH_SECRET_2=%s",
7043 dut->ap2_radius_password);
7044 if (res < 0 || res >= sizeof(buf))
7045 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007046 run_system(dut, buf);
7047 } else {
7048 run_system(dut, "cfg -a AP_SECMODE_2=None");
7049 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
7050 run_system(dut, "cfg -r AP_AUTH_PORT_2");
7051 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
7052 }
7053
7054 run_system(dut, "cfg -a AP_STARTMODE=multi");
7055 }
7056
7057 run_system(dut, "cfg -c");
7058
7059 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
7060 if (system("apup") != 0) {
7061 /* to be debugged why apup returns error
7062 send_resp(dut, conn, SIGMA_ERROR,
7063 "errorCode,apup failed");
7064 return 0;
7065 */
7066 }
7067 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
7068
7069 if (dut->ap_key_mgmt != AP_OPEN) {
7070 int res;
7071 /* allow some time for hostapd to start before returning
7072 * success */
7073 usleep(500000);
7074 if (run_hostapd_cli(dut, "ping") != 0) {
7075 send_resp(dut, conn, SIGMA_ERROR,
7076 "errorCode,Failed to talk to hostapd");
7077 return 0;
7078 }
7079
7080 if (dut->ap_hs2 && !dut->ap_anqpserver) {
7081 /* the cfg app doesn't like ";" in the variables */
7082 res = ath_ap_append_hostapd_conf(dut);
7083 if (res < 0)
7084 return res;
7085
7086 /* wait for hostapd to be ready */
7087 usleep(500000);
7088 if (run_hostapd_cli(dut, "ping") != 0) {
7089 send_resp(dut, conn, SIGMA_ERROR,
7090 "errorCode,Failed to talk to "
7091 "hostapd");
7092 return 0;
7093 }
7094 }
7095 }
7096
7097 ath_ap_set_params(dut);
7098
7099 if (dut->ap_anqpserver)
7100 return cmd_ath_ap_anqpserver_start(dut);
7101
7102 if (dut->ap2_proxy_arp)
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007103 run_iwpriv(dut, ifname, "proxy_arp 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007104
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007105 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip)
7106 run_iwpriv(dut, ifname, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007107
7108 return 1;
7109}
7110
7111
7112static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
7113 const char *ifname)
7114{
7115 char buf[200];
7116
7117 if (!chain || !ifname)
7118 return -2;
7119
7120 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7121 if (system(buf) != 0) {
7122 sigma_dut_print(dut, DUT_MSG_ERROR,
7123 "Failed to set ebtables rules, RULE-1, %s",
7124 chain);
7125 return -2;
7126 }
7127
7128 snprintf(buf, sizeof(buf),
7129 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7130 chain, ifname);
7131 if (system(buf) != 0) {
7132 sigma_dut_print(dut, DUT_MSG_ERROR,
7133 "Failed to set ebtables rules, RULE-2, %s",
7134 chain);
7135 return -2;
7136 }
7137
7138 snprintf(buf, sizeof(buf),
7139 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
7140 chain, ifname);
7141 if (system(buf) != 0) {
7142 sigma_dut_print(dut, DUT_MSG_ERROR,
7143 "Failed to set ebtables rules, RULE-3, %s",
7144 chain);
7145 return -2;
7146 }
7147
7148 snprintf(buf, sizeof(buf),
7149 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
7150 chain, ifname);
7151 if (system(buf) != 0) {
7152 sigma_dut_print(dut, DUT_MSG_ERROR,
7153 "Failed to set ebtables rules, RULE-4, %s",
7154 chain);
7155 return -2;
7156 }
7157
7158 return 0;
7159}
7160
7161
7162static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
7163 const char *chain,
7164 const char *ifname)
7165{
7166 char buf[200];
7167
7168 if (!chain || !ifname)
7169 return -2;
7170
7171 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7172 if (system(buf) != 0) {
7173 sigma_dut_print(dut, DUT_MSG_ERROR,
7174 "Failed to set ebtables rules, RULE-5, %s",
7175 chain);
7176 return -2;
7177 }
7178
7179 snprintf(buf, sizeof(buf),
7180 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7181 chain, ifname);
7182 if (system(buf) != 0) {
7183 sigma_dut_print(dut, DUT_MSG_ERROR,
7184 "Failed to set ebtables rules, RULE-6, %s",
7185 chain);
7186 return -2;
7187 }
7188
7189 snprintf(buf, sizeof(buf),
7190 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
7191 chain, ifname);
7192 if (system(buf) != 0) {
7193 sigma_dut_print(dut, DUT_MSG_ERROR,
7194 "Failed to set ebtables rules, RULE-7, %s",
7195 chain);
7196 return -2;
7197 }
7198
7199 snprintf(buf, sizeof(buf),
7200 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
7201 chain, ifname);
7202 if (system(buf) != 0) {
7203 sigma_dut_print(dut, DUT_MSG_ERROR,
7204 "Failed to set ebtables rules, RULE-8, %s",
7205 chain);
7206 return -2;
7207 }
7208
7209 return 0;
7210}
7211
7212
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007213static void set_ebtables_forward_drop(struct sigma_dut *dut,
7214 const char *ifname, const char *ifname2)
7215{
7216 char buf[128];
7217
7218 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7219 ifname, ifname2);
7220 if (system(buf) != 0)
7221 sigma_dut_print(dut, DUT_MSG_ERROR,
7222 "Failed to set ebtables rule");
7223
7224 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7225 ifname2, ifname);
7226 if (system(buf) != 0)
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "Failed to set ebtables rule");
7229}
7230
7231
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007232static int check_channel(int channel)
7233{
7234 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
7235 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
7236 161, 165 };
7237 int num_chan = sizeof(channel_list) / sizeof(int);
7238 int i;
7239
7240 for (i = 0; i < num_chan; i++) {
7241 if (channel == channel_list[i])
7242 return i;
7243 }
7244
7245 return -1;
7246}
7247
7248
7249static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
7250{
7251 int ch_base;
7252 int period;
7253
7254 if (check_channel(channel) < 0)
7255 return -1;
7256
7257 if (channel >= 36 && channel <= 64)
7258 ch_base = 36;
7259 else if (channel >= 100 && channel <= 144)
7260 ch_base = 100;
7261 else
7262 ch_base = 149;
7263
7264 period = channel % ch_base * 5 / chwidth;
7265 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
7266}
7267
7268
7269static int is_ht40plus_chan(int chan)
7270{
7271 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
7272 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
7273 chan == 132 || chan == 149 || chan == 157;
7274}
7275
7276
7277static int is_ht40minus_chan(int chan)
7278{
7279 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
7280 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
7281 chan == 136 || chan == 153 || chan == 161;
7282}
7283
7284
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05307285static int get_5g_channel_freq(int chan)
7286{
7287 return 5000 + chan * 5;
7288}
7289
7290
Jouni Malinen3d633da2017-09-14 22:19:21 +03007291static const char * hostapd_cipher_name(enum ap_cipher cipher)
7292{
7293 switch (cipher) {
7294 case AP_CCMP:
7295 return "CCMP";
7296 case AP_TKIP:
7297 return "TKIP";
7298 case AP_CCMP_TKIP:
7299 return "CCMP TKIP";
7300 case AP_GCMP_256:
7301 return "GCMP-256";
7302 case AP_GCMP_128:
7303 return "GCMP";
7304 case AP_CCMP_256:
7305 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02007306 case AP_CCMP_128_GCMP_256:
7307 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007308 default:
7309 return "UNKNOWN";
7310 }
7311}
7312
7313
7314static const char *
7315hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
7316{
7317 switch (cipher) {
7318 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03007319 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007320 case AP_BIP_CMAC_256:
7321 return "BIP-CMAC-256";
7322 case AP_BIP_GMAC_128:
7323 return "BIP-GMAC-128";
7324 case AP_BIP_CMAC_128:
7325 return "AES-128-CMAC";
7326 default:
7327 return "UNKNOWN";
7328 }
7329}
7330
7331
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007332static int ap_set_60g_ese(struct sigma_dut *dut, int count,
7333 struct sigma_ese_alloc *allocs)
7334{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007335 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007336#ifdef __linux__
7337 case DRIVER_WIL6210:
7338 return wil6210_set_ese(dut, count, allocs);
7339#endif /* __linux__ */
7340 default:
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "Unsupported ap_set_60g_ese with the current driver");
7343 return -1;
7344 }
7345}
7346
7347
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007348static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
7349{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007350 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007351#ifdef __linux__
7352 case DRIVER_WIL6210:
7353 return wil6210_set_force_mcs(dut, force, mcs);
7354#endif /* __linux__ */
7355 default:
7356 sigma_dut_print(dut, DUT_MSG_ERROR,
7357 "Unsupported ap_set_force_mcs with the current driver");
7358 return -1;
7359 }
7360}
7361
7362
Jouni Malinenf7222712019-06-13 01:50:21 +03007363enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
7364 struct sigma_conn *conn,
7365 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007366{
7367 /* const char *name = get_param(cmd, "NAME"); */
7368 FILE *f;
7369 const char *ifname;
7370 char buf[500];
7371 char path[100];
7372 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03007373 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307374#ifdef ANDROID
7375 struct group *gr;
7376#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007377
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007378 drv = get_driver_type(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007379
7380 if (dut->mode == SIGMA_MODE_STATION) {
7381 stop_sta_mode(dut);
7382 sleep(1);
7383 }
7384
7385 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
7386 snprintf(buf, sizeof(buf), "ifconfig %s down",
7387 dut->sniffer_ifname);
7388 if (system(buf) != 0) {
7389 sigma_dut_print(dut, DUT_MSG_INFO,
7390 "Failed to run '%s'", buf);
7391 }
7392 snprintf(buf, sizeof(buf), "iw dev %s set type station",
7393 dut->sniffer_ifname);
7394 if (system(buf) != 0) {
7395 sigma_dut_print(dut, DUT_MSG_INFO,
7396 "Failed to run '%s'", buf);
7397 }
7398 }
7399
7400 dut->mode = SIGMA_MODE_AP;
7401
7402 if (drv == DRIVER_ATHEROS)
7403 return cmd_ath_ap_config_commit(dut, conn, cmd);
7404 if (drv == DRIVER_WCN)
7405 return cmd_wcn_ap_config_commit(dut, conn, cmd);
7406 if (drv == DRIVER_OPENWRT)
7407 return cmd_owrt_ap_config_commit(dut, conn, cmd);
7408
7409 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
7410 if (f == NULL) {
7411 sigma_dut_print(dut, DUT_MSG_ERROR,
7412 "%s: Failed to open sigma_dut-ap.conf",
7413 __func__);
7414 return -2;
7415 }
7416 switch (dut->ap_mode) {
7417 case AP_11g:
7418 case AP_11b:
7419 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05307420 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
7421 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
Jouni Malinend2095482019-11-04 17:10:43 +02007422 dut->main_ifname)
Jouni Malinen5ea30922019-11-04 17:39:25 +02007423 ifname = get_main_ifname(dut);
Jouni Malinen85647462019-11-06 19:38:50 +02007424 if (dut->main_ifname_2g)
7425 ifname = dut->main_ifname_2g;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007426 fprintf(f, "hw_mode=g\n");
7427 break;
7428 case AP_11a:
7429 case AP_11na:
7430 case AP_11ac:
Jouni Malinen85647462019-11-06 19:38:50 +02007431 if (dut->main_ifname_5g) {
7432 ifname = dut->main_ifname_5g;
7433 } else if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinend2095482019-11-04 17:10:43 +02007434 if (dut->main_ifname)
Jouni Malinen5ea30922019-11-04 17:39:25 +02007435 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007436 else
7437 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05307438 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 if (if_nametoindex("wlan1") > 0)
7440 ifname = "wlan1";
7441 else
7442 ifname = "wlan0";
7443 } else {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007444 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007445 }
7446 fprintf(f, "hw_mode=a\n");
7447 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007448 case AP_11ad:
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007449 ifname = get_main_ifname(dut);
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007450 fprintf(f, "hw_mode=ad\n");
7451 break;
bings7e9914d2019-12-06 17:07:11 +08007452 case AP_11ax:
7453 if (dut->use_5g && dut->main_ifname_5g) {
7454 ifname = dut->main_ifname_5g;
7455 } else if (!dut->use_5g && dut->main_ifname_2g) {
7456 ifname = dut->main_ifname_2g;
7457 } else if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
7458 if (dut->main_ifname)
7459 ifname = get_main_ifname(dut);
7460 else
7461 ifname = "wlan0";
7462 } else if (drv == DRIVER_MAC80211) {
7463 if (if_nametoindex("wlan1") > 0)
7464 ifname = "wlan1";
7465 else
7466 ifname = "wlan0";
7467 } else {
7468 ifname = get_main_ifname(dut);
7469 }
7470 if (dut->use_5g)
7471 fprintf(f, "hw_mode=a\n");
7472 else
7473 fprintf(f, "hw_mode=g\n");
7474 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007475 default:
7476 fclose(f);
7477 return -1;
7478 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007479 if (dut->hostapd_ifname)
7480 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007481
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307482 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007483 fprintf(f, "driver=nl80211\n");
7484
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307485 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7486 drv == DRIVER_LINUX_WCN) &&
bings7e9914d2019-12-06 17:07:11 +08007487 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na ||
7488 (dut->ap_mode == AP_11ax && !dut->use_5g))) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05307489 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
7490
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007491 fprintf(f, "ieee80211n=1\n");
bings7e9914d2019-12-06 17:07:11 +08007492 if (dut->ap_mode == AP_11ax)
7493 fprintf(f, "ieee80211ax=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307494 if (dut->ap_mode == AP_11ng &&
7495 (dut->ap_chwidth == AP_40 ||
7496 (dut->ap_chwidth == AP_AUTO &&
7497 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007498 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307499 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007500 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307501 ht40minus = 1;
7502 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007503 }
7504
7505 /* configure ht_capab based on channel width */
7506 if (dut->ap_mode == AP_11na &&
7507 (dut->ap_chwidth == AP_40 ||
7508 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307509 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007510 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307511 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007512 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307513 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007514 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307515
7516 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307517 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307518
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307519 /* Overwrite the ht_capab with offset value if configured */
7520 if (dut->ap_chwidth == AP_40 &&
7521 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
7522 ht40plus = 1;
7523 ht40minus = 0;
7524 } else if (dut->ap_chwidth == AP_40 &&
7525 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
7526 ht40minus = 1;
7527 ht40plus = 0;
7528 }
7529
Tamizh chelvam431c6002017-03-07 17:07:16 +05307530 fprintf(f, "ht_capab=%s%s%s\n",
7531 ht40plus ? "[HT40+]" : "",
7532 ht40minus ? "[HT40-]" : "",
7533 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007534 }
7535
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307536 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7537 drv == DRIVER_LINUX_WCN) &&
bings7e9914d2019-12-06 17:07:11 +08007538 (dut->ap_mode == AP_11ac ||
7539 (dut->ap_mode == AP_11ax && dut->use_5g))) {
Hu Wang29392102019-07-03 15:41:12 +08007540 int ht40plus = 0, ht40minus = 0;
7541
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007542 fprintf(f, "ieee80211ac=1\n"
Hu Wang29392102019-07-03 15:41:12 +08007543 "ieee80211n=1\n");
bings7e9914d2019-12-06 17:07:11 +08007544 if (dut->ap_mode == AP_11ax)
7545 fprintf(f, "ieee80211ax=1\n");
Hu Wang29392102019-07-03 15:41:12 +08007546
7547 /* configure ht_capab based on channel width */
7548 if (dut->ap_chwidth != AP_20) {
7549 if (is_ht40plus_chan(dut->ap_channel))
7550 ht40plus = 1;
7551 else if (is_ht40minus_chan(dut->ap_channel))
7552 ht40minus = 1;
7553
7554 fprintf(f, "ht_capab=%s%s\n",
7555 ht40plus ? "[HT40+]" : "",
7556 ht40minus ? "[HT40-]" : "");
7557 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007558 }
7559
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307560 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7561 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007562 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
7563 if (dut->ap_countrycode[0]) {
7564 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
7565 fprintf(f, "ieee80211d=1\n");
7566 fprintf(f, "ieee80211h=1\n");
7567 }
7568 }
7569
Kiran Kumar Lokere800d39d2020-01-21 15:35:22 -08007570 if (drv == DRIVER_LINUX_WCN && dut->ap_mode == AP_11ax) {
7571 if (dut->ap_txBF) {
7572 fprintf(f, "he_su_beamformer=1\n");
7573 fprintf(f, "he_su_beamformee=1\n");
7574 if (dut->ap_mu_txBF)
7575 fprintf(f, "he_mu_beamformer=1\n");
7576 } else {
7577 fprintf(f, "he_su_beamformer=0\n");
7578 fprintf(f, "he_su_beamformee=0\n");
7579 fprintf(f, "he_mu_beamformer=0\n");
7580 }
7581 }
7582
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007583 fprintf(f, "interface=%s\n", ifname);
7584 if (dut->bridge)
7585 fprintf(f, "bridge=%s\n", dut->bridge);
7586 fprintf(f, "channel=%d\n", dut->ap_channel);
7587
7588 if (sigma_hapd_ctrl)
7589 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
7590 else
7591 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
7592
7593 if (dut->ap_ssid[0])
7594 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7595 else
7596 fprintf(f, "ssid=QCA AP OOB\n");
7597 if (dut->ap_bcnint)
7598 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
7599
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007600 if (dut->ap_akm_values) {
7601 struct {
7602 int akm;
7603 const char *str;
7604 } akms[] = {
7605 { AKM_WPA_EAP, "WPA-EAP" },
7606 { AKM_WPA_PSK, "WPA-PSK" },
7607 { AKM_FT_EAP, "FT-EAP" },
7608 { AKM_FT_PSK, "FT-PSK" },
7609 { AKM_EAP_SHA256, "WPA-EAP-SHA256" },
7610 { AKM_PSK_SHA256, "WPA-PSK-SHA256" },
7611 { AKM_SAE, "SAE" },
7612 { AKM_FT_SAE, "FT-SAE" },
7613 { AKM_SUITE_B, "WPA-EAP-SUITE-B-192" },
7614 { AKM_FT_SUITE_B, "FT-EAP-SHA384" },
7615 { AKM_FILS_SHA256, "FILS-SHA256" },
7616 { AKM_FILS_SHA384, "FILS-SHA384" },
7617 { AKM_FT_FILS_SHA256, "FT-FILS-SHA256" },
7618 { AKM_FT_FILS_SHA384, "FT-FILS-SHA384" },
7619 };
Jouni Malinen8400c082019-04-26 13:26:07 +03007620 int first = 1;
7621 unsigned int i;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007622
7623 fprintf(f, "wpa_key_mgmt=");
7624 for (i = 0; i < ARRAY_SIZE(akms); i++) {
7625 if (dut->ap_akm_values & (1 << akms[i].akm)) {
7626 fprintf(f, "%s%s", first ? "" : " ",
7627 akms[i].str);
7628 first = 0;
7629 }
7630 }
7631 fprintf(f, "\n");
7632 /* TODO: mixed mode and WPAv1 only */
7633 fprintf(f, "wpa=2\n");
7634 fprintf(f, "wpa_pairwise=%s\n",
7635 hostapd_cipher_name(dut->ap_cipher));
7636 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7637 fprintf(f, "group_cipher=%s\n",
7638 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3e255412019-03-28 22:04:08 +02007639 if ((dut->ap_akm_values &
7640 ((1 << AKM_SAE) | (1 << AKM_FT_SAE))) &&
7641 !(dut->ap_akm_values &
7642 ((1 << AKM_WPA_PSK) | (1 << AKM_FT_PSK))) &&
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007643 dut->ap_passphrase[0])
7644 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
7645 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7646 fprintf(f, "wpa_psk=%s", dut->ap_psk);
7647 else if (dut->ap_passphrase[0])
7648 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007649 if (dut->ap_akm_values & ((1 << AKM_WPA_EAP) |
Jouni Malinene5393c32019-06-20 01:34:34 +03007650 (1 << AKM_FT_EAP) |
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007651 (1 << AKM_EAP_SHA256) |
7652 (1 << AKM_SUITE_B) |
7653 (1 << AKM_FT_SUITE_B) |
7654 (1 << AKM_FILS_SHA256) |
7655 (1 << AKM_FILS_SHA384) |
7656 (1 << AKM_FT_FILS_SHA256) |
7657 (1 << AKM_FT_FILS_SHA384))) {
7658 fprintf(f, "ieee8021x=1\n");
7659 fprintf(f, "auth_server_addr=%s\n",
7660 dut->ap_radius_ipaddr);
7661 if (dut->ap_radius_port)
7662 fprintf(f, "auth_server_port=%d\n",
7663 dut->ap_radius_port);
7664 fprintf(f, "auth_server_shared_secret=%s\n",
7665 dut->ap_radius_password);
7666 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007667 goto skip_key_mgmt;
7668 }
7669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007670 switch (dut->ap_key_mgmt) {
7671 case AP_OPEN:
7672 if (dut->ap_cipher == AP_WEP)
7673 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
7674 break;
7675 case AP_WPA2_PSK:
7676 case AP_WPA2_PSK_MIXED:
7677 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007678 case AP_WPA2_SAE:
7679 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007680 case AP_WPA2_PSK_SHA256:
7681 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007682 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
7683 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007684 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7685 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
7686 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007687 fprintf(f, "wpa=2\n");
7688 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
7689 fprintf(f, "wpa=3\n");
7690 else
7691 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03007692 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7693 key_mgmt = "SAE";
7694 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7695 key_mgmt = "WPA-PSK SAE";
7696 else
7697 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007698 switch (dut->ap_pmf) {
7699 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007700 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007701 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7702 break;
7703 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03007704 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007705 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7706 break;
7707 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007708 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7709 key_mgmt = "SAE";
7710 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7711 key_mgmt = "WPA-PSK-SHA256 SAE";
7712 else
7713 key_mgmt = "WPA-PSK-SHA256";
7714 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007715 break;
7716 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007717 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
7718 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
7719 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
7720 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007721 fprintf(f, "wpa_pairwise=%s\n",
7722 hostapd_cipher_name(dut->ap_cipher));
7723 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7724 fprintf(f, "group_cipher=%s\n",
7725 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03007726 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7727 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02007728 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7729 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03007730 else
7731 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007732 break;
7733 case AP_WPA2_EAP:
7734 case AP_WPA2_EAP_MIXED:
7735 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007736 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007737 case AP_WPA2_EAP_SHA256:
7738 case AP_WPA2_FT_EAP:
7739 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007740 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007741 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007742 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
7743 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
7744 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
7745 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007746 fprintf(f, "wpa=2\n");
7747 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
7748 fprintf(f, "wpa=3\n");
7749 else
7750 fprintf(f, "wpa=1\n");
7751 switch (dut->ap_pmf) {
7752 case AP_PMF_DISABLED:
7753 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
7754 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
7755 break;
7756 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007757 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
7758 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
7759 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7760 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007761 break;
7762 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007763 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
7764 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7765 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007766 break;
7767 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007768 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
7769 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
7770 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
7771 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
7772 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
7773 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007774 fprintf(f, "wpa_pairwise=%s\n",
7775 hostapd_cipher_name(dut->ap_cipher));
7776 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7777 fprintf(f, "group_cipher=%s\n",
7778 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007779 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7780 if (dut->ap_radius_port)
7781 fprintf(f, "auth_server_port=%d\n",
7782 dut->ap_radius_port);
7783 fprintf(f, "auth_server_shared_secret=%s\n",
7784 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03007785 if (dut->program == PROGRAM_HS2_R3) {
7786 fprintf(f, "radius_das_port=3799\n");
7787 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
7788 dut->ap_radius_password);
7789 fprintf(f, "radius_das_require_event_timestamp=1\n");
7790 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007791 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03007792 case AP_SUITEB:
7793 fprintf(f, "ieee8021x=1\n");
7794 fprintf(f, "wpa=2\n");
7795 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03007796 fprintf(f, "wpa_pairwise=%s\n",
7797 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02007798 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7799 fprintf(f, "group_cipher=%s\n",
7800 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03007801 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7802 fprintf(f, "group_mgmt_cipher=%s\n",
7803 hostapd_group_mgmt_cipher_name(
7804 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03007805 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7806 if (dut->ap_radius_port)
7807 fprintf(f, "auth_server_port=%d\n",
7808 dut->ap_radius_port);
7809 fprintf(f, "auth_server_shared_secret=%s\n",
7810 dut->ap_radius_password);
7811 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03007812 case AP_WPA2_OWE:
7813 fprintf(f, "wpa=2\n");
7814 fprintf(f, "wpa_key_mgmt=OWE\n");
7815 fprintf(f, "rsn_pairwise=%s\n",
7816 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03007817 if (dut->ap_sae_groups)
7818 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03007819 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03007820 case AP_OSEN:
7821 fprintf(f, "osen=1\n");
7822 fprintf(f, "disable_dgaf=1\n");
7823 fprintf(f, "wpa_pairwise=%s\n",
7824 hostapd_cipher_name(dut->ap_cipher));
7825 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7826 fprintf(f, "group_cipher=%s\n",
7827 hostapd_cipher_name(dut->ap_group_cipher));
7828 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7829 if (dut->ap_radius_port)
7830 fprintf(f, "auth_server_port=%d\n",
7831 dut->ap_radius_port);
7832 fprintf(f, "auth_server_shared_secret=%s\n",
7833 dut->ap_radius_password);
7834 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007835 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007836skip_key_mgmt:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007837
Jouni Malinen09550de2019-03-26 00:24:11 +02007838 if (dut->ap_sae_passwords) {
7839 char *tmp, *pos, *end, *id;
7840
7841 tmp = strdup(dut->ap_sae_passwords);
7842 if (!tmp) {
7843 fclose(f);
7844 return ERROR_SEND_STATUS;
7845 }
7846
7847 pos = tmp;
7848 while (*pos) {
7849 end = strchr(pos, ';');
7850 if (end)
7851 *end = '\0';
7852 id = strchr(pos, ':');
7853 if (id)
7854 *id++ = '\0';
7855
7856 fprintf(f, "sae_password=%s%s%s\n",
7857 pos, id ? "|id=" : "", id ? id : "");
7858 if (!end)
7859 break;
7860 pos = end + 1;
7861 }
7862
7863 free(tmp);
7864 }
7865
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05307866 if (dut->ap_rsn_preauth)
7867 fprintf(f, "rsn_preauth=1\n");
7868
Jouni Malinenb75c5322019-06-14 01:47:43 +03007869 if (dut->ap_pmksa && dut->ap_pmksa_caching)
7870 fprintf(f, "disable_pmksa_caching=1\n");
7871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007872 switch (dut->ap_pmf) {
7873 case AP_PMF_DISABLED:
7874 break;
7875 case AP_PMF_OPTIONAL:
7876 fprintf(f, "ieee80211w=1\n");
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007877 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7878 (dut->ap_akm_values & (AKM_SAE | AKM_WPA_PSK)) ==
7879 (AKM_SAE | AKM_WPA_PSK))
Jouni Malinen1287cd72018-01-04 17:08:01 +02007880 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007881 break;
7882 case AP_PMF_REQUIRED:
7883 fprintf(f, "ieee80211w=2\n");
7884 break;
7885 }
7886
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007887 if (dut->ap_pmf != AP_PMF_DISABLED &&
7888 dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7889 fprintf(f, "group_mgmt_cipher=%s\n",
7890 hostapd_group_mgmt_cipher_name(
7891 dut->ap_group_mgmt_cipher));
7892
Jouni Malinen6be21c82018-08-01 18:47:24 +03007893 if (ap_ft_enabled(dut)) {
7894 unsigned char own_addr[ETH_ALEN];
7895
7896 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
Jouni Malinen9f943312019-08-19 23:49:16 +03007897 fprintf(f, "ft_over_ds=%d\n", dut->ap_ft_ds == VALUE_ENABLED);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007898 if (get_hwaddr(ifname, own_addr) < 0) {
7899 memset(own_addr, 0, ETH_ALEN);
7900 own_addr[0] = 0x02;
7901 }
Jouni Malinenc9674462019-03-26 02:40:19 +02007902 fprintf(f,
7903 "nas_identifier=%02x%02x%02x%02x%02x%02x.nas.example.com\n",
7904 own_addr[0], own_addr[1], own_addr[2],
7905 own_addr[3], own_addr[4], own_addr[5]);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007906 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7907 own_addr[0], own_addr[1], own_addr[2],
7908 own_addr[3], own_addr[4], own_addr[5]);
7909 fprintf(f, "ft_psk_generate_local=1\n");
7910 fprintf(f, "pmk_r1_push=0\n");
7911 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007912 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007913 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007914 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007915 }
7916
Jouni Malinen3c367e82017-06-23 17:01:47 +03007917 if (dut->rsne_override)
7918 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
Jouni Malinen7960e3a2019-12-07 17:04:35 +02007919 if (dut->rsnxe_override_eapol)
7920 fprintf(f, "rsnxe_override_eapol=%s\n",
7921 dut->rsnxe_override_eapol);
Jouni Malinen3c367e82017-06-23 17:01:47 +03007922
Jouni Malinen68143132017-09-02 02:34:08 +03007923 if (dut->sae_commit_override)
7924 fprintf(f, "sae_commit_override=%s\n",
7925 dut->sae_commit_override);
7926
Jouni Malinened670f42017-08-31 01:39:28 +03007927 if (dut->ap_sae_groups)
7928 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007929
Jouni Malinen11e55212019-11-22 21:46:59 +02007930 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
7931 const char *sae_pwe = NULL;
7932
7933 if (dut->sae_pwe == SAE_PWE_LOOP)
7934 sae_pwe = "0";
7935 else if (dut->sae_pwe == SAE_PWE_H2E)
7936 sae_pwe = "1";
7937 else if (dut->sae_h2e_default)
7938 sae_pwe = "2";
7939 if (sae_pwe)
7940 fprintf(f, "sae_pwe=%s", sae_pwe);
7941 }
7942
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007943 if (dut->sae_anti_clogging_threshold >= 0)
7944 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7945 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007946 if (dut->sae_reflection)
7947 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03007948 if (dut->sae_confirm_immediate)
Jouni Malinena6f1db02020-01-23 00:46:12 +02007949 fprintf(f, "sae_confirm_immediate=2\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007950
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007951 if (dut->ap_p2p_mgmt)
7952 fprintf(f, "manage_p2p=1\n");
7953
7954 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7955 fprintf(f, "tdls_prohibit=1\n");
7956 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
7957 fprintf(f, "tdls_prohibit_chan_switch=1\n");
7958 if (dut->ap_p2p_cross_connect >= 0) {
7959 fprintf(f, "manage_p2p=1\n"
7960 "allow_cross_connection=%d\n",
7961 dut->ap_p2p_cross_connect);
7962 }
7963
Jouni Malinen4d479c92018-11-06 00:43:36 +02007964 if (dut->ap_l2tif || dut->ap_proxy_arp ||
7965 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966 if (!dut->bridge) {
7967 sigma_dut_print(dut, DUT_MSG_ERROR,
7968 "Bridge must be configured. Run with -b <brname>.");
7969 fclose(f);
7970 return -2;
7971 }
7972 fprintf(f, "ap_isolate=1\n");
7973 }
7974
7975 if (dut->ap_proxy_arp)
7976 fprintf(f, "proxy_arp=1\n");
7977
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307978 if (dut->ap_wme)
7979 fprintf(f, "wmm_enabled=1\n");
7980
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307981 if (dut->ap_wmmps == AP_WMMPS_ON)
7982 fprintf(f, "uapsd_advertisement_enabled=1\n");
7983
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007984 if (dut->ap_hs2) {
7985 if (dut->ap_bss_load) {
7986 char *bss_load;
7987
7988 switch (dut->ap_bss_load) {
7989 case -1:
7990 bss_load = "bss_load_update_period=10";
7991 break;
7992 case 1:
7993 /* STA count: 1, CU: 50, AAC: 65535 */
7994 bss_load = "bss_load_test=1:50:65535";
7995 break;
7996 case 2:
7997 /* STA count: 1, CU: 200, AAC: 65535 */
7998 bss_load = "bss_load_test=1:200:65535";
7999 break;
8000 case 3:
8001 /* STA count: 1, CU: 75, AAC: 65535 */
8002 bss_load = "bss_load_test=1:75:65535";
8003 break;
8004 default:
8005 bss_load = NULL;
8006 break;
8007 }
8008
8009 if (!bss_load) {
8010 fclose(f);
8011 return -2;
8012 }
8013 fprintf(f, "%s\n", bss_load);
8014 }
8015
8016 if (append_hostapd_conf_hs2(dut, f)) {
8017 fclose(f);
8018 return -2;
8019 }
8020 }
8021
8022 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
8023 fclose(f);
8024 return -2;
8025 }
8026
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008027 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008028 unsigned char bssid[6];
8029 char ifname2[50];
8030
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308031 if (get_hwaddr(ifname, bssid)) {
8032 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008033 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308034 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03008035 if (bssid[0] & 0x02)
8036 bssid[5] ^= 0x01;
8037 else
8038 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008039
8040 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03008041 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008042 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008043 if (dut->bridge)
8044 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008045
8046 if (drv == DRIVER_LINUX_WCN)
8047 fprintf(f, "use_driver_iface_addr=1\n");
8048 else
8049 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8050 bssid[0], bssid[1], bssid[2], bssid[3],
8051 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008052
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008053 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008054 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05308055 /* Disable DGAF for OSEN BSS */
8056 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008057 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008058 if (strlen(dut->ap2_radius_ipaddr))
8059 fprintf(f, "auth_server_addr=%s\n",
8060 dut->ap2_radius_ipaddr);
8061 if (dut->ap2_radius_port)
8062 fprintf(f, "auth_server_port=%d\n",
8063 dut->ap2_radius_port);
8064 if (strlen(dut->ap2_radius_password))
8065 fprintf(f, "auth_server_shared_secret=%s\n",
8066 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008067
8068 set_ebtables_forward_drop(dut, ifname, ifname2);
8069 } else if (dut->ap2_osu) {
8070 fprintf(f, "ap_isolate=1\n");
8071 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008072 }
8073
8074 if (dut->ap2_proxy_arp) {
8075 if (!dut->bridge) {
8076 sigma_dut_print(dut, DUT_MSG_ERROR,
8077 "Bridge must be configured. Run with -b <brname>.");
8078 fclose(f);
8079 return -2;
8080 }
8081 fprintf(f, "ap_isolate=1\n");
8082 fprintf(f, "proxy_arp=1\n");
8083
8084 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
8085 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
8086 fclose(f);
8087 return -2;
8088 }
8089
8090 }
8091 }
8092
8093 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008094 /* 60G WPS tests requires wps_state of 2 (configured) */
8095 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
8096
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008097 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008098 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008099 "device_name=QCA AP\n"
8100 "manufacturer=QCA\n"
8101 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008102 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008103 "virtual_push_button keypad%s\n"
8104 "ap_pin=12345670\n"
8105 "friendly_name=QCA Access Point\n"
8106 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008107 wps_state,
8108 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008109 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
8110 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008111 if (dut->wsc_fragment) {
8112 fprintf(f, "device_name=%s\n"
8113 "manufacturer=%s\n"
8114 "model_name=%s\n"
8115 "model_number=%s\n"
8116 "serial_number=%s\n",
8117 WPS_LONG_DEVICE_NAME,
8118 WPS_LONG_MANUFACTURER,
8119 WPS_LONG_MODEL_NAME,
8120 WPS_LONG_MODEL_NUMBER,
8121 WPS_LONG_SERIAL_NUMBER);
8122 } else {
8123 fprintf(f, "device_name=QCA AP\n"
8124 "manufacturer=QCA\n");
8125 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008126 if (dut->eap_fragment)
8127 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008128 }
8129
Jouni Malinenba4f2d42019-10-04 16:13:41 +03008130 if (dut->ap_dpp_conf_addr && dut->ap_dpp_conf_pkhash)
8131 fprintf(f, "dpp_controller=ipaddr=%s pkhash=%s\n",
8132 dut->ap_dpp_conf_addr, dut->ap_dpp_conf_pkhash);
8133
bings7e9914d2019-12-06 17:07:11 +08008134 if ((dut->program == PROGRAM_VHT) ||
8135 (dut->program == PROGRAM_HE && dut->use_5g)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008136 int vht_oper_centr_freq_idx;
8137
8138 if (check_channel(dut->ap_channel) < 0) {
8139 send_resp(dut, conn, SIGMA_INVALID,
8140 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308141 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008142 return 0;
8143 }
8144
8145 switch (dut->ap_chwidth) {
8146 case AP_20:
8147 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8148 vht_oper_centr_freq_idx =
8149 get_oper_centr_freq_seq_idx(20,
8150 dut->ap_channel);
8151 break;
8152 case AP_40:
8153 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8154 vht_oper_centr_freq_idx =
8155 get_oper_centr_freq_seq_idx(40,
8156 dut->ap_channel);
8157 break;
8158 case AP_80:
8159 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
8160 vht_oper_centr_freq_idx =
8161 get_oper_centr_freq_seq_idx(80,
8162 dut->ap_channel);
8163 break;
8164 case AP_160:
8165 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
8166 vht_oper_centr_freq_idx =
8167 get_oper_centr_freq_seq_idx(160,
8168 dut->ap_channel);
8169 break;
8170 default:
8171 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
8172 vht_oper_centr_freq_idx =
8173 get_oper_centr_freq_seq_idx(80,
8174 dut->ap_channel);
8175 break;
8176 }
8177 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
8178 vht_oper_centr_freq_idx);
8179 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
bings7e9914d2019-12-06 17:07:11 +08008180 if (dut->ap_mode == AP_11ax) {
8181 fprintf(f, "he_oper_chwidth=%d\n", dut->ap_vht_chwidth);
8182 fprintf(f, "he_oper_centr_freq_seg0_idx=%d\n",
8183 vht_oper_centr_freq_idx);
8184 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008185
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008186 if (dut->ap_sgi80 || dut->ap_txBF ||
8187 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308188 dut->ap_tx_stbc || dut->ap_mu_txBF) {
8189 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008190 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05308191 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05308192 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008193 (dut->ap_ldpc == VALUE_ENABLED) ?
8194 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308195 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
8196 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008197 }
8198 }
8199
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008200 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
8201 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
8202 /* OWE transition mode */
8203 unsigned char bssid[6];
8204 char ifname2[50];
8205 unsigned long val;
8206 FILE *f2;
8207
8208 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8209
8210 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8211 val = 0x12345678; /* default to something */
8212 f2 = fopen("/dev/urandom", "r");
8213 if (f2) {
8214 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8215 sigma_dut_print(dut, DUT_MSG_ERROR,
8216 "Could not read /dev/urandom");
8217 }
8218 fclose(f2);
8219 }
8220 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008221 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008222
8223 if (get_hwaddr(ifname, bssid)) {
8224 fclose(f);
8225 return -2;
8226 }
8227 if (bssid[0] & 0x02)
8228 bssid[5] ^= 0x01;
8229 else
8230 bssid[0] |= 0x02;
8231
8232 fprintf(f, "bss=%s\n", ifname2);
8233 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8234 if (dut->bridge)
8235 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008236 if (drv == DRIVER_LINUX_WCN)
8237 fprintf(f, "use_driver_iface_addr=1\n");
8238 else
8239 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8240 bssid[0], bssid[1], bssid[2], bssid[3],
8241 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008242 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8243 }
8244
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008245 if (dut->ap_key_mgmt == AP_OPEN &&
8246 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
8247 /* OWE transition mode */
8248 unsigned char bssid[6];
8249 char ifname2[50];
8250 unsigned long val;
8251 FILE *f2;
8252
8253 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8254
8255 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8256 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8257
8258 if (get_hwaddr(ifname, bssid)) {
8259 fclose(f);
8260 return -2;
8261 }
8262 if (bssid[0] & 0x02)
8263 bssid[5] ^= 0x01;
8264 else
8265 bssid[0] |= 0x02;
8266
8267 fprintf(f, "bss=%s\n", ifname2);
8268 val = 0x12345678; /* default to something */
8269 f2 = fopen("/dev/urandom", "r");
8270 if (f2) {
8271 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8272 sigma_dut_print(dut, DUT_MSG_ERROR,
8273 "Could not read /dev/urandom");
8274 }
8275 fclose(f2);
8276 }
8277 fprintf(f, "ssid=owe-%lx\n", val);
8278 if (dut->bridge)
8279 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008280 if (drv == DRIVER_LINUX_WCN)
8281 fprintf(f, "use_driver_iface_addr=1\n");
8282 else
8283 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8284 bssid[0], bssid[1], bssid[2], bssid[3],
8285 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008286 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8287 fprintf(f, "wpa=2\n");
8288 fprintf(f, "wpa_key_mgmt=OWE\n");
8289 fprintf(f, "rsn_pairwise=CCMP\n");
8290 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008291 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008292 if (dut->ap_sae_groups)
8293 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
8294 }
8295
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308296 if (dut->program == PROGRAM_OCE) {
8297 fprintf(f, "oce=%d\n",
8298 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
8299 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008300 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008301 if (dut->use_hostapd_pid_file)
8302 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008303#ifdef __QNXNTO__
8304 if (system("slay hostapd") == 0)
8305#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008306 if (!dut->use_hostapd_pid_file &&
8307 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8308 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008309#endif /* __QNXNTO__ */
8310 {
8311 int i;
8312 /* Wait some time to allow hostapd to complete cleanup before
8313 * starting a new process */
8314 for (i = 0; i < 10; i++) {
8315 usleep(500000);
8316#ifdef __QNXNTO__
8317 if (system("pidin | grep hostapd") != 0)
8318 break;
8319#else /* __QNXNTO__ */
8320 if (system("pidof hostapd") != 0)
8321 break;
8322#endif /* __QNXNTO__ */
8323 }
8324 }
Jouni Malinend86e5822017-08-29 03:55:32 +03008325 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008326
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308327#ifdef ANDROID
8328 /* Set proper conf file permissions so that hostapd process
8329 * can access it.
8330 */
8331 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
8332 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
8333 sigma_dut_print(dut, DUT_MSG_ERROR,
8334 "Error changing permissions");
8335
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05308336 gr = getgrnam("wifi");
8337 if (!gr ||
8338 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308339 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
8340#endif /* ANDROID */
8341
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008342 if (drv == DRIVER_QNXNTO) {
8343 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05308344 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008345 "/sigma_dut-ap.conf",
8346 dut->hostapd_debug_log ? "-ddKt -f " : "",
8347 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008348 dut->hostapd_entropy_log ? " -e" : "",
8349 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
8350 "");
8351 } else {
8352 /*
8353 * It looks like a monitor interface can cause some issues for
8354 * beaconing, so remove it (if injection was used) before
8355 * starting hostapd.
8356 */
8357 if (if_nametoindex("sigmadut") > 0 &&
8358 system("iw dev sigmadut del") != 0)
8359 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8360 "monitor interface");
8361
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008362 snprintf(path, sizeof(path), "%shostapd",
8363 file_exists("hostapd") ? "./" : "");
8364 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008365 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008366 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008367 dut->hostapd_debug_log ? " -ddKt -f" : "",
8368 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
8369 dut->hostapd_entropy_log ? " -e" : "",
8370 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008371 "",
8372 dut->use_hostapd_pid_file ?
8373 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008374 }
8375
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008376 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008377 if (system(buf) != 0) {
8378 send_resp(dut, conn, SIGMA_ERROR,
8379 "errorCode,Failed to start hostapd");
8380 return 0;
8381 }
8382
8383 /* allow some time for hostapd to start before returning success */
8384 usleep(500000);
8385 if (run_hostapd_cli(dut, "ping") != 0) {
8386 send_resp(dut, conn, SIGMA_ERROR,
8387 "errorCode,Failed to talk to hostapd");
8388 return 0;
8389 }
8390
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308391 if (drv == DRIVER_LINUX_WCN) {
Hu Wangf5cb9002019-08-21 14:18:57 +08008392 const char *ifname_ptr = ifname;
8393
8394 if ((dut->ap_key_mgmt == AP_OPEN &&
8395 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) ||
8396 (dut->ap_key_mgmt == AP_WPA2_OWE &&
8397 dut->ap_tag_ssid[0][0] &&
8398 dut->ap_tag_key_mgmt[0] == AP2_OPEN)) {
8399 /* OWE transition mode */
8400 if (dut->bridge)
8401 ifname_ptr = dut->bridge;
8402 }
8403
8404 sigma_dut_print(dut, DUT_MSG_INFO,
8405 "setting ip addr %s mask %s ifname %s",
8406 ap_inet_addr, ap_inet_mask, ifname_ptr);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308407 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Hu Wangf5cb9002019-08-21 14:18:57 +08008408 ifname_ptr, ap_inet_addr, ap_inet_mask);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308409 if (system(buf) != 0) {
8410 sigma_dut_print(dut, DUT_MSG_ERROR,
8411 "Failed to initialize the interface");
8412 return -1;
8413 }
8414 }
8415
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008416 if (dut->ap_l2tif) {
8417 snprintf(path, sizeof(path),
8418 "/sys/class/net/%s/brport/hairpin_mode",
8419 ifname);
8420 if (!file_exists(path)) {
8421 sigma_dut_print(dut, DUT_MSG_ERROR,
8422 "%s must be binded to the bridge for L2TIF",
8423 ifname);
8424 return -2;
8425 }
8426
8427 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
8428 if (system(buf) != 0) {
8429 sigma_dut_print(dut, DUT_MSG_ERROR,
8430 "Failed to enable hairpin_mode for L2TIF");
8431 return -2;
8432 }
8433
8434 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
8435 if (system(buf) != 0) {
8436 sigma_dut_print(dut, DUT_MSG_ERROR,
8437 "Failed to set ebtables rules, RULE-9");
8438 return -2;
8439 }
8440
8441 snprintf(buf, sizeof(buf),
8442 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
8443 ifname);
8444 if (system(buf) != 0) {
8445 sigma_dut_print(dut, DUT_MSG_ERROR,
8446 "Failed to set ebtables rules, RULE-11");
8447 return -2;
8448 }
8449 }
8450
8451 if (dut->ap_proxy_arp) {
8452 if (dut->ap_dgaf_disable) {
8453 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
8454 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
8455 return -2;
8456 } else {
8457 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
8458 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
8459 return -2;
8460 }
8461
8462 /* For 4.5-(c) */
8463 snprintf(buf, sizeof(buf),
8464 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
8465 ifname);
8466 if (system(buf) != 0) {
8467 sigma_dut_print(dut, DUT_MSG_ERROR,
8468 "Failed to set ebtables rules, RULE-10");
8469 return -2;
8470 }
8471 }
8472
8473 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
8474 /* Drop TDLS frames */
8475 snprintf(buf, sizeof(buf),
8476 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
8477 if (system(buf) != 0) {
8478 sigma_dut_print(dut, DUT_MSG_ERROR,
8479 "Failed to set ebtables rules, RULE-13");
8480 return -2;
8481 }
8482 }
8483
8484 if (dut->ap_fake_pkhash &&
8485 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
8486 send_resp(dut, conn, SIGMA_ERROR,
8487 "errorCode,Could not enable FakePubKey");
8488 return 0;
8489 }
8490
Alexei Avshalom Lazar059abce2020-01-21 14:45:14 +02008491 if (dut->program == PROGRAM_60GHZ) {
8492 if (dut->ap_num_ese_allocs > 0) {
8493 /* wait extra time for AP to start */
8494 sleep(2);
8495 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
8496 dut->ap_ese_allocs)) {
8497 send_resp(dut, conn, SIGMA_ERROR,
8498 "errorCode,Could not set ExtSch");
8499 return 0;
8500 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008501 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008502 if (dut->ap_fixed_rate) {
8503 sigma_dut_print(dut, DUT_MSG_DEBUG,
8504 "forcing TX MCS index %d",
8505 dut->ap_mcs);
8506 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
8507 send_resp(dut, conn, SIGMA_ERROR,
8508 "errorCode,Could not force MCS");
8509 return -2;
8510 }
8511 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008512 }
8513
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008514 if (dut->wps_forced_version) {
8515 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
8516 dut->wps_forced_version);
8517 if (hapd_command(ifname, buf) < 0) {
8518 send_resp(dut, conn, SIGMA_ERROR,
8519 "errorCode,Fail to set wps_version_number");
8520 return STATUS_SENT;
8521 }
8522 }
8523
Jouni Malinend86e5822017-08-29 03:55:32 +03008524 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008525 return 1;
8526}
8527
8528
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308529static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
8530 struct qos_params *qos, const char *cwmin,
8531 const char *cwmax, const char *aifs,
8532 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008533{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308534 int val;
8535
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008536 if (cwmin) {
8537 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308538 val = atoi(cwmin);
8539 if (val < 0 || val > 15) {
8540 send_resp(dut, conn, SIGMA_INVALID,
8541 "errorCode,Invalid cwMin");
8542 return 0;
8543 }
8544 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008545 }
8546
8547 if (cwmax) {
8548 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308549 val = atoi(cwmax);
8550 if (val < 0 || val > 15) {
8551 send_resp(dut, conn, SIGMA_INVALID,
8552 "errorCode,Invalid cwMax");
8553 return 0;
8554 }
8555 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008556 }
8557
8558 if (aifs) {
8559 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308560 val = atoi(aifs);
8561 if (val < 1 || val > 255) {
8562 send_resp(dut, conn, SIGMA_INVALID,
8563 "errorCode,Invalid AIFS");
8564 return 0;
8565 }
8566 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008567 }
8568
8569 if (txop) {
8570 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308571 val = atoi(txop);
8572 if (val < 0 || val > 0xffff) {
8573 send_resp(dut, conn, SIGMA_INVALID,
8574 "errorCode,Invalid txop");
8575 return 0;
8576 }
8577 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008578 }
8579
8580 if (acm) {
8581 qos->ac = 1;
8582 qos->acm = strcasecmp(acm, "on") == 0;
8583 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308584
8585 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008586}
8587
8588
Jouni Malinenf7222712019-06-13 01:50:21 +03008589static enum sigma_cmd_result cmd_ap_set_apqos(struct sigma_dut *dut,
8590 struct sigma_conn *conn,
8591 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008592{
8593 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308594 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
8595 get_param(cmd, "cwmin_VO"),
8596 get_param(cmd, "cwmax_VO"),
8597 get_param(cmd, "AIFS_VO"),
8598 get_param(cmd, "TXOP_VO"),
8599 get_param(cmd, "ACM_VO")) ||
8600 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
8601 get_param(cmd, "cwmin_VI"),
8602 get_param(cmd, "cwmax_VI"),
8603 get_param(cmd, "AIFS_VI"),
8604 get_param(cmd, "TXOP_VI"),
8605 get_param(cmd, "ACM_VI")) ||
8606 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
8607 get_param(cmd, "cwmin_BE"),
8608 get_param(cmd, "cwmax_BE"),
8609 get_param(cmd, "AIFS_BE"),
8610 get_param(cmd, "TXOP_BE"),
8611 get_param(cmd, "ACM_BE")) ||
8612 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
8613 get_param(cmd, "cwmin_BK"),
8614 get_param(cmd, "cwmax_BK"),
8615 get_param(cmd, "AIFS_BK"),
8616 get_param(cmd, "TXOP_BK"),
8617 get_param(cmd, "ACM_BK")))
8618 return 0;
8619
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008620 return 1;
8621}
8622
8623
Jouni Malinenf7222712019-06-13 01:50:21 +03008624static enum sigma_cmd_result cmd_ap_set_staqos(struct sigma_dut *dut,
8625 struct sigma_conn *conn,
8626 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008627{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308628 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
8629 get_param(cmd, "cwmin_VO"),
8630 get_param(cmd, "cwmax_VO"),
8631 get_param(cmd, "AIFS_VO"),
8632 get_param(cmd, "TXOP_VO"),
8633 get_param(cmd, "ACM_VO")) ||
8634 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
8635 get_param(cmd, "cwmin_VI"),
8636 get_param(cmd, "cwmax_VI"),
8637 get_param(cmd, "AIFS_VI"),
8638 get_param(cmd, "TXOP_VI"),
8639 get_param(cmd, "ACM_VI")) ||
8640 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
8641 get_param(cmd, "cwmin_BE"),
8642 get_param(cmd, "cwmax_BE"),
8643 get_param(cmd, "AIFS_BE"),
8644 get_param(cmd, "TXOP_BE"),
8645 get_param(cmd, "ACM_BE")) ||
8646 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
8647 get_param(cmd, "cwmin_BK"),
8648 get_param(cmd, "cwmax_BK"),
8649 get_param(cmd, "AIFS_BK"),
8650 get_param(cmd, "TXOP_BK"),
8651 get_param(cmd, "ACM_BK")))
8652 return 0;
8653
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008654 return 1;
8655}
8656
8657
8658static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
8659{
8660 unsigned char bssid[6];
8661 char buf[100];
8662 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
8663 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
8664 run_system(dut, "cfg -a AP_SECMODE=WPA");
8665 run_system(dut, "cfg -a AP_SECFILE=EAP");
8666 run_system(dut, "cfg -a AP_WPA=2");
8667 run_system(dut, "cfg -a AP_CYPHER=CCMP");
8668 run_system(dut, "cfg -a AP_HOTSPOT=1");
8669 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
8670 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
8671 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
8672 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
8673 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
8674 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
8675 if (!get_hwaddr("ath0", bssid)) {
8676 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8677 "%02x:%02x:%02x:%02x:%02x:%02x",
8678 bssid[0], bssid[1], bssid[2], bssid[3],
8679 bssid[4], bssid[5]);
8680 run_system(dut, buf);
8681 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8682 "%02x:%02x:%02x:%02x:%02x:%02x",
8683 bssid[0], bssid[1], bssid[2], bssid[3],
8684 bssid[4], bssid[5]);
8685 } else {
8686 if (!get_hwaddr("wifi0", bssid)) {
8687 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8688 "%02x:%02x:%02x:%02x:%02x:%02x",
8689 bssid[0], bssid[1], bssid[2], bssid[3],
8690 bssid[4], bssid[5]);
8691 run_system(dut, buf);
8692 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8693 "%02x:%02x:%02x:%02x:%02x:%02x",
8694 bssid[0], bssid[1], bssid[2], bssid[3],
8695 bssid[4], bssid[5]);
8696 } else {
8697 /* load the driver and try again */
8698 run_system(dut, "/etc/rc.d/rc.wlan up");
8699
8700 if (!get_hwaddr("wifi0", bssid)) {
8701 snprintf(buf, sizeof(buf),
8702 "cfg -a AP_HOTSPOT_HESSID="
8703 "%02x:%02x:%02x:%02x:%02x:%02x",
8704 bssid[0], bssid[1], bssid[2],
8705 bssid[3], bssid[4], bssid[5]);
8706 run_system(dut, buf);
8707 snprintf(dut->ap_hessid,
8708 sizeof(dut->ap_hessid),
8709 "%02x:%02x:%02x:%02x:%02x:%02x",
8710 bssid[0], bssid[1], bssid[2],
8711 bssid[3], bssid[4], bssid[5]);
8712 }
8713 }
8714 }
8715
8716 run_system(dut, "cfg -r AP_SSID_2");
8717 run_system(dut, "cfg -c");
8718 /* run_system(dut, "cfg -s"); */
8719}
8720
8721
8722static void ath_reset_vht_defaults(struct sigma_dut *dut)
8723{
8724 run_system(dut, "cfg -x");
8725 run_system(dut, "cfg -a AP_RADIO_ID=1");
8726 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
8727 run_system(dut, "cfg -a AP_STARTMODE=standard");
8728 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
8729 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
8730 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
8731 run_system(dut, "cfg -a ATH_countrycode=0x348");
8732 /* NOTE: For Beeliner we have to turn off MU-MIMO */
8733 if (system("rm /tmp/secath*") != 0) {
8734 sigma_dut_print(dut, DUT_MSG_ERROR,
8735 "Failed to remove secath file");
8736 }
8737}
8738
8739
Jouni Malinenf7222712019-06-13 01:50:21 +03008740static enum sigma_cmd_result cmd_ap_reset_default(struct sigma_dut *dut,
8741 struct sigma_conn *conn,
8742 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008743{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308744 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308745 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008746 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008747 int i;
8748
8749 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
8750 /*
8751 * Reset all tagged SSIDs to NULL-string and all key management
8752 * to open.
8753 */
8754 dut->ap_tag_ssid[i][0] = '\0';
8755 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
8756 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008757
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008758 drv = get_driver_type(dut);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308759
8760 program = get_param(cmd, "program");
8761 if (!program)
8762 program = get_param(cmd, "prog");
8763 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008764 dut->device_type = AP_unknown;
8765 type = get_param(cmd, "type");
8766 if (type && strcasecmp(type, "Testbed") == 0)
8767 dut->device_type = AP_testbed;
8768 if (type && strcasecmp(type, "DUT") == 0)
8769 dut->device_type = AP_dut;
8770
8771 dut->ap_rts = 0;
8772 dut->ap_frgmnt = 0;
8773 dut->ap_bcnint = 0;
8774 dut->ap_key_mgmt = AP_OPEN;
8775 dut->ap_ssid[0] = '\0';
8776 dut->ap_fake_pkhash = 0;
8777 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
8778 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008779 dut->ap_addba_reject = VALUE_NOT_SET;
8780 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008781 dut->ap_is_dual = 0;
8782 dut->ap_mode = AP_inval;
8783 dut->ap_mode_1 = AP_inval;
8784
8785 dut->ap_allow_vht_wep = 0;
8786 dut->ap_allow_vht_tkip = 0;
8787 dut->ap_disable_protection = 0;
8788 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008789 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
8790 dut->ap_ldpc = VALUE_NOT_SET;
8791 dut->ap_sig_rts = VALUE_NOT_SET;
8792 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008793 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05308794 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008795 dut->ap_chwidth = AP_AUTO;
8796
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05308797 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798 dut->ap_wpsnfc = 0;
8799 dut->ap_bss_load = -1;
8800 dut->ap_p2p_cross_connect = -1;
8801
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308802 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
8803 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05308804 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308805
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008806 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008807 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08008808 dut->ap_interface_5g = 0;
8809 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08008810 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008811
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008812 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008813 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008814 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008815
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308816 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308817 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308818 dut->ap_wmmps = AP_WMMPS_ON;
8819 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308820 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308821 dut->ap_wmmps = AP_WMMPS_OFF;
8822 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308823
Jouni Malinen54a89b02018-05-01 00:16:26 +03008824 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03008825 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03008826 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03008827 dut->ap_tnc_file_name = 0;
8828 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03008829
Jouni Malinenda5f35b2019-03-26 00:25:53 +02008830 dut->ap_akm_values = 0;
Jouni Malinen09550de2019-03-26 00:24:11 +02008831 free(dut->ap_sae_passwords);
8832 dut->ap_sae_passwords = NULL;
8833
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008834 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008835 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008836 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008837 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008838
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008839 if (drv == DRIVER_ATHEROS)
8840 cmd_ath_ap_hs2_reset(dut);
8841 else if (drv == DRIVER_OPENWRT)
8842 cmd_owrt_ap_hs2_reset(dut);
8843
8844 dut->ap_interworking = 1;
8845 dut->ap_access_net_type = 2;
8846 dut->ap_internet = 0;
8847 dut->ap_venue_group = 2;
8848 dut->ap_venue_type = 8;
8849 dut->ap_domain_name_list[0] = '\0';
8850 dut->ap_hs2 = 1;
8851 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
8852 "506f9a;001bc504bd");
8853 dut->ap_l2tif = 0;
8854 dut->ap_proxy_arp = 0;
8855 if (dut->bridge) {
8856 char buf[50];
8857
8858 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
8859 dut->bridge);
8860 if (system(buf) != 0) {
8861 sigma_dut_print(dut, DUT_MSG_DEBUG,
8862 "%s ip neigh table flushing failed",
8863 dut->bridge);
8864 }
8865
8866 snprintf(buf, sizeof(buf), "ebtables -F");
8867 if (system(buf) != 0) {
8868 sigma_dut_print(dut, DUT_MSG_DEBUG,
8869 "%s ebtables flushing failed",
8870 dut->bridge);
8871 }
8872 }
8873 dut->ap_dgaf_disable = 0;
8874 dut->ap_p2p_cross_connect = 0;
8875 dut->ap_gas_cb_delay = 0;
8876 dut->ap_nai_realm_list = 0;
8877 dut->ap_oper_name = 0;
8878 dut->ap_venue_name = 0;
8879 for (i = 0; i < 10; i++) {
8880 dut->ap_plmn_mcc[i][0] = '\0';
8881 dut->ap_plmn_mnc[i][0] = '\0';
8882 }
8883 dut->ap_wan_metrics = 0;
8884 dut->ap_conn_capab = 0;
8885 dut->ap_ip_addr_type_avail = 0;
8886 dut->ap_net_auth_type = 0;
8887 dut->ap_oper_class = 0;
8888 dut->ap_pmf = 0;
8889 dut->ap_add_sha256 = 0;
8890 }
8891
Jouni Malinenba630452018-06-22 11:49:59 +03008892 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
8893 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008894 int i;
8895 const char hessid[] = "50:6f:9a:00:11:22";
8896
8897 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
8898 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008899 dut->ap_pmf = 1;
8900 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02008901 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008902 for (i = 0; i < 10; i++) {
8903 dut->ap_osu_server_uri[i][0] = '\0';
8904 dut->ap_osu_method[i] = 0xFF;
8905 }
8906 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008907 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008908 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008909 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008910 dut->ap_osu_icon_tag = 0;
8911 }
8912
8913 if (dut->program == PROGRAM_VHT) {
8914 /* Set up the defaults */
Jouni Malinen00535472019-11-06 19:43:35 +02008915 dut->use_5g = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008916 dut->ap_mode = AP_11ac;
8917 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008918 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08008919 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008920 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008921 dut->ap_amsdu = VALUE_DISABLED;
8922 dut->ap_ldpc = VALUE_DISABLED;
8923 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008924 dut->ap_sgi80 = 0;
8925 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008926 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308927 /*
8928 * As LDPC is optional, don't enable this by default
8929 * for LINUX-WCN driver. The ap_set_wireless command
8930 * can be used to enable LDPC, when needed.
8931 */
8932 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008933 dut->ap_ldpc = VALUE_ENABLED;
8934 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008935 dut->ap_sgi80 = 1;
8936 }
8937 dut->ap_fixed_rate = 0;
8938 dut->ap_rx_streams = 3;
8939 dut->ap_tx_streams = 3;
8940 dut->ap_vhtmcs_map = 0;
8941 dut->ap_chwidth = AP_80;
8942 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008943 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05308944 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8945 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008946 if (get_driver_type(dut) == DRIVER_ATHEROS)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008947 ath_reset_vht_defaults(dut);
8948 }
8949
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008950 if (dut->program == PROGRAM_IOTLP) {
8951 dut->wnm_bss_max_feature = VALUE_DISABLED;
8952 dut->wnm_bss_max_idle_time = 0;
8953 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8954 dut->ap_proxy_arp = 1;
8955 } else {
8956 /*
8957 * Do not touch the BSS-MAX Idle time feature
8958 * if the program is not IOTLP.
8959 */
8960 dut->wnm_bss_max_feature = VALUE_NOT_SET;
8961 dut->wnm_bss_max_idle_time = 0;
8962 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8963 }
8964
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008965 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008966 dut->ap_rrm = 1;
8967 dut->ap_rtt = 1;
8968 dut->ap_lci = 0;
8969 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008970 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008971 dut->ap_lcr = 0;
8972 dut->ap_val_lcr[0] = '\0';
8973 dut->ap_neighap = 0;
8974 dut->ap_opchannel = 0;
8975 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008976 dut->ap_fqdn_held = 0;
8977 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07008978 dut->ap_interworking = 0;
8979 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008980 dut->ap_msnt_type = 0;
8981 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008982 dut->ap_ft_oa = 0;
Jouni Malinen9f943312019-08-19 23:49:16 +03008983 dut->ap_ft_ds = VALUE_NOT_SET;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07008984 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07008985 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008986
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008987 if (dut->program == PROGRAM_MBO) {
8988 dut->ap_mbo = 1;
8989 dut->ap_interworking = 1;
8990 dut->ap_ne_class = 0;
8991 dut->ap_ne_op_ch = 0;
8992 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008993 dut->ap_btmreq_disassoc_imnt = 0;
8994 dut->ap_btmreq_term_bit = 0;
8995 dut->ap_disassoc_timer = 0;
8996 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07008997 dut->ap_channel = 36;
8998 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07008999 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07009000 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07009001 dut->mbo_self_ap_tuple.ap_ne_class = -1;
9002 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
9003 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009004 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009005 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009006 }
9007
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08009008 if (dut->program == PROGRAM_OCE) {
9009 if (dut->ap_dhcp_stop)
9010 run_system(dut, "/etc/init.d/dnsmasq start");
9011
9012 dut->ap_dhcp_stop = 0;
9013 dut->ap_oce = VALUE_ENABLED;
9014 dut->ap_broadcast_ssid = VALUE_ENABLED;
9015 dut->ap_fils_dscv_int = 20;
9016 dut->ap_filsdscv = VALUE_ENABLED;
9017 dut->ap_filshlp = VALUE_DISABLED;
9018 dut->ap_rnr = VALUE_DISABLED;
9019 dut->ap_nairealm[0] = '\0';
9020 dut->ap_nairealm_int = 0;
9021 dut->ap_blechanutil = 0;
9022 dut->ap_ble_admit_cap = 0;
9023 dut->ap_esp = VALUE_ENABLED;
9024 dut->ap_datappdudura = 0;
9025 dut->ap_airtimefract = 0;
9026 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08009027 dut->ap_ul_availcap = 0;
9028 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08009029 dut->ap_akm = 0;
9030 dut->ap_add_sha256 = 0;
9031 dut->ap_add_sha384 = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08009032 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08009033 }
9034
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07009035 dut->ap_he_ppdu = PPDU_NOT_SET;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009036 dut->ap_he_ulofdma = VALUE_NOT_SET;
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07009037 dut->ap_numsounddim = 0;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009038 dut->ap_bcc = VALUE_DISABLED;
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07009039 dut->ap_mu_edca = VALUE_DISABLED;
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07009040 dut->ap_he_mimo = MIMO_NOT_SET;
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07009041 dut->ap_he_rtsthrshld = VALUE_NOT_SET;
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07009042 dut->ap_mbssid = VALUE_DISABLED;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08009043 dut->ap_ampdu = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009044 dut->he_mcsnssmap = 0;
9045 dut->ap_fixed_rate = 0;
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08009046 dut->he_mmss = 0;
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08009047 dut->he_set_sta_1x1 = VALUE_DISABLED;
Priyadharshini Gowthaman88d55c82019-12-12 14:31:46 -08009048 dut->he_srctrl_allow = -1;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009049 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009050 dut->ap_he_dlofdma = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009051 dut->ap_he_frag = VALUE_DISABLED;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07009052 dut->ap_twtresp = VALUE_DISABLED;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009053 dut->he_ul_mcs = 7;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009054 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07009055 dut->ap_he_dlofdma = VALUE_NOT_SET;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009056 dut->ap_he_frag = VALUE_NOT_SET;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009057 dut->ap_ba_bufsize = BA_BUFSIZE_NOT_SET;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07009058 dut->ap_twtresp = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08009059 dut->he_ul_mcs = 0;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07009060 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07009061
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009062 if (dut->program == PROGRAM_HE) {
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009063 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009064 dut->ap_ldpc = VALUE_DISABLED;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009065 dut->ap_ba_bufsize = BA_BUFSIZE_64;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08009066 dut->ap_amsdu = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08009067 dut->ap_txBF = 0;
9068 dut->ap_mu_txBF = 0;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08009069 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08009070 } else {
bingsb24b7902019-12-11 14:45:44 +08009071 if (drv == DRIVER_WCN || drv == DRIVER_LINUX_WCN) {
9072 dut->ap_txBF = 0;
9073 dut->ap_mu_txBF = 0;
9074 } else {
9075 dut->ap_txBF = 1;
9076 dut->ap_mu_txBF = 1;
9077 }
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08009078 dut->he_sounding = VALUE_ENABLED;
bings78387032019-12-06 17:50:05 +08009079 if (drv == DRIVER_LINUX_WCN) {
9080 dut->ap_ldpc = VALUE_ENABLED;
9081 wcn_config_ap_ldpc(dut, get_main_ifname(dut));
Kiran Kumar Lokereff979472020-01-22 11:15:59 -08009082#ifdef NL80211_SUPPORT
9083 if (wcn_set_he_ltf(dut, get_main_ifname(dut),
9084 QCA_WLAN_HE_LTF_AUTO)) {
9085 sigma_dut_print(dut, DUT_MSG_ERROR,
9086 "Failed to set LTF in ap_reset_default");
9087 }
9088#endif /* NL80211_SUPPORT */
bings78387032019-12-06 17:50:05 +08009089 }
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07009090 }
Priyadharshini Gowthaman115c79d2019-11-13 15:23:08 -08009091 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9092 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07009093 }
9094
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08009095 dut->ap_oper_chn = 0;
9096
Jouni Malinenb75c5322019-06-14 01:47:43 +03009097 dut->ap_pmksa = 0;
9098 dut->ap_pmksa_caching = 0;
9099
Jouni Malinen3c367e82017-06-23 17:01:47 +03009100 free(dut->rsne_override);
9101 dut->rsne_override = NULL;
Jouni Malinen7960e3a2019-12-07 17:04:35 +02009102 free(dut->rsnxe_override_eapol);
9103 dut->rsnxe_override_eapol = NULL;
Jouni Malinen3c367e82017-06-23 17:01:47 +03009104
Jouni Malinen68143132017-09-02 02:34:08 +03009105 free(dut->sae_commit_override);
9106 dut->sae_commit_override = NULL;
9107
Jouni Malinened670f42017-08-31 01:39:28 +03009108 free(dut->ap_sae_groups);
9109 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03009110
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009111 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03009112 dut->sae_reflection = 0;
Jouni Malinen3c740ab2019-10-10 15:55:11 +03009113 dut->sae_confirm_immediate = 0;
Jouni Malinen11e55212019-11-22 21:46:59 +02009114 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009115
Jouni Malinen3d633da2017-09-14 22:19:21 +03009116 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02009117 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03009118 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02009119 dut->ap_passphrase[0] = '\0';
9120 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03009121
Jouni Malinend86e5822017-08-29 03:55:32 +03009122 dut->dpp_conf_id = -1;
Jouni Malinenba4f2d42019-10-04 16:13:41 +03009123 free(dut->ap_dpp_conf_addr);
9124 dut->ap_dpp_conf_addr = NULL;
9125 free(dut->ap_dpp_conf_pkhash);
9126 dut->ap_dpp_conf_pkhash = NULL;
Jouni Malinend86e5822017-08-29 03:55:32 +03009127
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009128 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009129 dut->ap_mode = AP_11ad;
9130 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009131 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009132 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02009133 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009134 dut->ap_fixed_rate = 0;
9135
9136 dut->dev_role = DEVROLE_AP;
9137
9138 sigma_dut_print(dut, DUT_MSG_DEBUG,
9139 "Setting msdu_size to MAX: 7912");
9140 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009141 get_main_ifname(dut));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009142
9143 if (system(buf) != 0) {
9144 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
9145 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009146 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009147 }
9148
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009149 if (ap_set_force_mcs(dut, 0, 1)) {
9150 sigma_dut_print(dut, DUT_MSG_ERROR,
9151 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009152 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009153 }
9154
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009155 if (set_ps(get_main_ifname(dut), dut, 1)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009156 sigma_dut_print(dut, DUT_MSG_ERROR,
9157 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009158 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009159 }
9160 }
9161
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009162 if (dut->program == PROGRAM_WPS &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009163 get_driver_type(dut) == DRIVER_WIL6210) {
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009164 /*
9165 * In 60 GHz WPS tests, we configure the AP OOB to
9166 * secure connection with a random passphrase.
9167 */
9168 char r[16], passphrase[65];
9169
9170 if (random_get_bytes(r, sizeof(r))) {
9171 sigma_dut_print(dut, DUT_MSG_ERROR,
9172 "Failed to get random bytes");
9173 return ERROR_SEND_STATUS;
9174 }
9175 if (base64_encode(r, sizeof(r),
9176 passphrase, sizeof(passphrase))) {
9177 sigma_dut_print(dut, DUT_MSG_ERROR,
9178 "Failed to generate random passphrase");
9179 return ERROR_SEND_STATUS;
9180 }
9181
9182 dut->ap_key_mgmt = AP_WPA2_PSK;
9183 dut->ap_cipher = AP_GCMP_128;
9184 strlcpy(dut->ap_passphrase, passphrase,
9185 sizeof(dut->ap_passphrase));
9186 sigma_dut_print(dut, DUT_MSG_DEBUG,
9187 "60G WPS: configure secure AP with random passphrase");
9188 }
9189
Jouni Malinend86e5822017-08-29 03:55:32 +03009190 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08009191
9192 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9193 return 1;
9194
Jouni Malinend6bf1b42017-06-23 17:51:01 +03009195 if (dut->use_hostapd_pid_file) {
9196 kill_hostapd_process_pid(dut);
9197 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
9198 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009199 int i;
9200 /* Wait some time to allow hostapd to complete cleanup before
9201 * starting a new process */
9202 for (i = 0; i < 10; i++) {
9203 usleep(500000);
9204 if (system("pidof hostapd") != 0)
9205 break;
9206 }
9207 }
9208
9209 if (if_nametoindex("sigmadut") > 0 &&
9210 system("iw dev sigmadut del") != 0)
9211 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
9212 "monitor interface");
9213
9214 return 1;
9215}
9216
9217
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309218int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
9219 struct sigma_cmd *cmd)
9220{
9221 return cmd_ap_reset_default(dut, conn, cmd);
9222}
9223
9224
Jouni Malinenf7222712019-06-13 01:50:21 +03009225static enum sigma_cmd_result cmd_ap_get_info(struct sigma_dut *dut,
9226 struct sigma_conn *conn,
9227 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009228{
9229 /* const char *name = get_param(cmd, "NAME"); */
9230 struct stat s;
9231 char resp[200];
9232 FILE *f;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009233 enum driver_type drv = get_driver_type(dut);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009234 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009235
9236 switch (drv) {
9237 case DRIVER_ATHEROS: {
9238 /* Atheros AP */
9239 struct utsname uts;
9240 char *version, athver[100];
9241
9242 if (stat("/proc/athversion", &s) != 0) {
9243 if (system("/etc/rc.d/rc.wlan up") != 0) {
9244 }
9245 }
9246
9247 athver[0] = '\0';
9248 f = fopen("/proc/athversion", "r");
9249 if (f) {
9250 if (fgets(athver, sizeof(athver), f)) {
9251 char *pos = strchr(athver, '\n');
9252 if (pos)
9253 *pos = '\0';
9254 }
9255 fclose(f);
9256 }
9257
9258 if (uname(&uts) == 0)
9259 version = uts.release;
9260 else
9261 version = "Unknown";
9262
9263 if (if_nametoindex("ath1") > 0)
Jouni Malinen3aa72862019-05-29 23:14:51 +03009264 res = snprintf(resp, sizeof(resp),
9265 "interface,ath0_24G ath1_5G,agent,1.0,version,%s/drv:%s",
9266 version, athver);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009267 else
Jouni Malinen3aa72862019-05-29 23:14:51 +03009268 res = snprintf(resp, sizeof(resp),
9269 "interface,ath0_24G,agent,1.0,version,%s/drv:%s",
9270 version, athver);
9271 if (res < 0 || res >= sizeof(resp))
9272 send_resp(dut, conn, SIGMA_ERROR, NULL);
9273 else
9274 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009275 return 0;
9276 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05309277 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009278 case DRIVER_MAC80211: {
9279 struct utsname uts;
9280 char *version;
9281
9282 if (uname(&uts) == 0)
9283 version = uts.release;
9284 else
9285 version = "Unknown";
9286
9287 if (if_nametoindex("wlan1") > 0)
9288 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
9289 "wlan1_5G,agent,1.0,version,%s", version);
9290 else
9291 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
9292 "agent,1.0,version,%s", version);
9293
9294 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9295 return 0;
9296 }
9297 case DRIVER_QNXNTO: {
9298 struct utsname uts;
9299 char *version;
9300
9301 if (uname(&uts) == 0)
9302 version = uts.release;
9303 else
9304 version = "Unknown";
9305 snprintf(resp, sizeof(resp),
9306 "interface,%s_any,agent,1.0,version,%s",
Jouni Malinen5ea30922019-11-04 17:39:25 +02009307 dut->main_ifname ? get_main_ifname(dut) : "NA",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009308 version);
9309 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9310 return 0;
9311 }
9312 case DRIVER_OPENWRT: {
9313 switch (get_openwrt_driver_type()) {
9314 case OPENWRT_DRIVER_ATHEROS: {
9315 struct utsname uts;
9316 char *version;
9317
9318 if (uname(&uts) == 0)
9319 version = uts.release;
9320 else
9321 version = "Unknown";
9322
9323 if (if_nametoindex("ath1") > 0)
9324 snprintf(resp, sizeof(resp),
9325 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
9326 version);
9327 else
9328 snprintf(resp, sizeof(resp),
9329 "interface,ath0_any,agent,1.0,version,%s",
9330 version);
9331
9332 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9333 return 0;
9334 }
9335 default:
9336 send_resp(dut, conn, SIGMA_ERROR,
9337 "errorCode,Unsupported openwrt driver");
9338 return 0;
9339 }
9340 }
9341 default:
9342 send_resp(dut, conn, SIGMA_ERROR,
9343 "errorCode,Unsupported driver");
9344 return 0;
9345 }
9346}
9347
9348
Jouni Malinenf7222712019-06-13 01:50:21 +03009349static enum sigma_cmd_result cmd_ap_deauth_sta(struct sigma_dut *dut,
9350 struct sigma_conn *conn,
9351 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009352{
9353 /* const char *name = get_param(cmd, "NAME"); */
9354 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009355 const char *val, *disconnect;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009356 char buf[100];
9357
9358 val = get_param(cmd, "MinorCode");
9359 if (val) {
9360 /* TODO: add support for P2P minor code */
9361 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
9362 "yet supported");
9363 return 0;
9364 }
9365
9366 val = get_param(cmd, "STA_MAC_ADDRESS");
9367 if (val == NULL)
9368 return -1;
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009369 disconnect = get_param(cmd, "disconnect");
9370 if (disconnect && strcasecmp(disconnect, "silent") == 0)
9371 snprintf(buf, sizeof(buf), "deauth %s tx=0", val);
9372 else
9373 snprintf(buf, sizeof(buf), "deauth %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009374 if (run_hostapd_cli(dut, buf) != 0)
9375 return -2;
9376
9377 return 1;
9378}
9379
9380
9381#ifdef __linux__
9382int inject_frame(int s, const void *data, size_t len, int encrypt);
9383int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009384#endif /* __linux__ */
9385
9386enum send_frame_type {
9387 DISASSOC, DEAUTH, SAQUERY
9388};
9389enum send_frame_protection {
9390 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9391};
9392
9393
9394static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9395 enum send_frame_type frame,
9396 enum send_frame_protection protected,
9397 const char *sta_addr)
9398{
9399#ifdef __linux__
9400 unsigned char buf[1000], *pos;
9401 int s, res;
9402 unsigned char addr_sta[6], addr_own[6];
9403 char *ifname;
9404 char cbuf[100];
9405 struct ifreq ifr;
9406
9407 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
9408 dut->ap_mode == AP_11ac) &&
9409 if_nametoindex("wlan1") > 0)
9410 ifname = "wlan1";
9411 else
9412 ifname = "wlan0";
9413
9414 if (hwaddr_aton(sta_addr, addr_sta) < 0)
9415 return -1;
9416
9417 s = socket(AF_INET, SOCK_DGRAM, 0);
9418 if (s < 0)
9419 return -1;
9420 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009421 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009422 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9423 perror("ioctl");
9424 close(s);
9425 return -1;
9426 }
9427 close(s);
9428 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
9429
9430 if (if_nametoindex("sigmadut") == 0) {
9431 snprintf(cbuf, sizeof(cbuf),
9432 "iw dev %s interface add sigmadut type monitor",
9433 ifname);
9434 if (system(cbuf) != 0 ||
9435 if_nametoindex("sigmadut") == 0) {
9436 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9437 "monitor interface with '%s'", cbuf);
9438 return -2;
9439 }
9440 }
9441
9442 if (system("ifconfig sigmadut up") != 0) {
9443 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9444 "monitor interface up");
9445 return -2;
9446 }
9447
9448 pos = buf;
9449
9450 /* Frame Control */
9451 switch (frame) {
9452 case DISASSOC:
9453 *pos++ = 0xa0;
9454 break;
9455 case DEAUTH:
9456 *pos++ = 0xc0;
9457 break;
9458 case SAQUERY:
9459 *pos++ = 0xd0;
9460 break;
9461 }
9462
9463 if (protected == INCORRECT_KEY)
9464 *pos++ = 0x40; /* Set Protected field to 1 */
9465 else
9466 *pos++ = 0x00;
9467
9468 /* Duration */
9469 *pos++ = 0x00;
9470 *pos++ = 0x00;
9471
9472 /* addr1 = DA (station) */
9473 memcpy(pos, addr_sta, 6);
9474 pos += 6;
9475 /* addr2 = SA (own address) */
9476 memcpy(pos, addr_own, 6);
9477 pos += 6;
9478 /* addr3 = BSSID (own address) */
9479 memcpy(pos, addr_own, 6);
9480 pos += 6;
9481
9482 /* Seq# (to be filled by driver/mac80211) */
9483 *pos++ = 0x00;
9484 *pos++ = 0x00;
9485
9486 if (protected == INCORRECT_KEY) {
9487 /* CCMP parameters */
9488 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9489 pos += 8;
9490 }
9491
9492 if (protected == INCORRECT_KEY) {
9493 switch (frame) {
9494 case DEAUTH:
9495 /* Reason code (encrypted) */
9496 memcpy(pos, "\xa7\x39", 2);
9497 pos += 2;
9498 break;
9499 case DISASSOC:
9500 /* Reason code (encrypted) */
9501 memcpy(pos, "\xa7\x39", 2);
9502 pos += 2;
9503 break;
9504 case SAQUERY:
9505 /* Category|Action|TransID (encrypted) */
9506 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9507 pos += 4;
9508 break;
9509 default:
9510 return -1;
9511 }
9512
9513 /* CCMP MIC */
9514 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9515 pos += 8;
9516 } else {
9517 switch (frame) {
9518 case DEAUTH:
9519 /* reason code = 8 */
9520 *pos++ = 0x08;
9521 *pos++ = 0x00;
9522 break;
9523 case DISASSOC:
9524 /* reason code = 8 */
9525 *pos++ = 0x08;
9526 *pos++ = 0x00;
9527 break;
9528 case SAQUERY:
9529 /* Category - SA Query */
9530 *pos++ = 0x08;
9531 /* SA query Action - Request */
9532 *pos++ = 0x00;
9533 /* Transaction ID */
9534 *pos++ = 0x12;
9535 *pos++ = 0x34;
9536 break;
9537 }
9538 }
9539
9540 s = open_monitor("sigmadut");
9541 if (s < 0) {
9542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9543 "monitor socket");
9544 return 0;
9545 }
9546
9547 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9548 if (res < 0) {
9549 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9550 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309551 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009552 return 0;
9553 }
9554 if (res < pos - buf) {
9555 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9556 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309557 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009558 return 0;
9559 }
9560
9561 close(s);
9562
9563 return 1;
9564#else /* __linux__ */
9565 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
9566 "yet supported");
9567 return 0;
9568#endif /* __linux__ */
9569}
9570
9571
9572int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
9573 struct sigma_cmd *cmd)
9574{
9575 const char *val, *dest;
9576 char buf[100];
9577
9578 val = get_param(cmd, "FrameName");
9579 if (val == NULL)
9580 return -1;
9581
9582 if (strcasecmp(val, "QoSMapConfigure") == 0) {
9583 dest = get_param(cmd, "Dest");
9584 if (!dest)
9585 return -1;
9586
9587 val = get_param(cmd, "QoS_MAP_SET");
9588 if (val) {
9589 dut->ap_qos_map_set = atoi(val);
9590 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9591 dut->ap_qos_map_set);
9592 }
9593
9594 if (dut->ap_qos_map_set == 1)
9595 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9596 else if (dut->ap_qos_map_set == 2)
9597 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9598
9599 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9600 if (run_hostapd_cli(dut, buf) != 0)
9601 return -1;
9602 }
9603
9604 return 1;
9605}
9606
9607
9608static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9609 struct sigma_cmd *cmd)
9610{
9611 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009612 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009613 int chwidth, nss;
9614
9615 val = get_param(cmd, "FrameName");
9616 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
9617 send_resp(dut, conn, SIGMA_ERROR,
9618 "errorCode,Unsupported FrameName");
9619 return 0;
9620 }
9621
9622 /*
9623 * Sequence of commands for Opmode notification on
9624 * Peregrine based products
9625 */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009626 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009627
9628 /* Disable STBC */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009629 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009630
9631 /* Check whether optional arg channel width was passed */
9632 val = get_param(cmd, "Channel_width");
9633 if (val) {
9634 switch (atoi(val)) {
9635 case 20:
9636 chwidth = 0;
9637 break;
9638 case 40:
9639 chwidth = 1;
9640 break;
9641 case 80:
9642 chwidth = 2;
9643 break;
9644 case 160:
9645 chwidth = 3;
9646 break;
9647 default:
9648 chwidth = 2;
9649 break;
9650 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009651 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009652 }
9653
9654 /* Check whether optional arg NSS was passed */
9655 val = get_param(cmd, "NSS");
9656 if (val) {
9657 /* Convert nss to chainmask */
9658 switch (atoi(val)) {
9659 case 1:
9660 nss = 1;
9661 break;
9662 case 2:
9663 nss = 3;
9664 break;
9665 case 3:
9666 nss = 7;
9667 break;
9668 default:
9669 /* We do not support NSS > 3 */
9670 nss = 3;
9671 break;
9672 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009673 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009674 }
9675
9676 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009677 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009678
9679 return 1;
9680}
9681
9682
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009683static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9684 struct sigma_cmd *cmd)
9685{
9686 const char *val;
9687 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009688 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009689
9690 val = get_param(cmd, "MsntType");
9691 if (val) {
9692 if (dut->ap_msnt_type == 0)
9693 dut->ap_msnt_type = atoi(val);
9694
9695 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
9696 dut->ap_msnt_type = atoi(val);
9697 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009698 val = get_param(cmd, "RandInterval");
9699 if (val)
9700 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009701 f = fopen("/tmp/ftmrr.txt", "a");
9702 if (!f) {
9703 sigma_dut_print(dut, DUT_MSG_ERROR,
9704 "Failed to open /tmp/ftmrr.txt");
9705 return -1;
9706 }
9707
9708 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009709 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",
9710 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009711 fclose(f);
9712 dut->ap_msnt_type = 5;
9713 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9714 }
9715 } else if (dut->ap_msnt_type == 5) {
9716 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9717 } else if (dut->ap_msnt_type == 2) {
9718 f = fopen("/tmp/wru.txt", "w");
9719 if (!f) {
9720 sigma_dut_print(dut, DUT_MSG_ERROR,
9721 "Failed to open /tmp/wru.txt");
9722 return -1;
9723 }
9724
9725 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
9726 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
9727 fclose(f);
9728 run_system(dut, "wpc -w /tmp/wru.txt");
9729 }
9730 }
9731 return 1;
9732}
9733
9734
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009735/*
9736 * The following functions parse_send_frame_params_int(),
9737 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
9738 * are used by ath_ap_send_frame_bcn_rpt_req().
9739 * Beacon Report Request is a frame used as part of the MBO program.
9740 * The command for sending beacon report has a lot of
9741 * arguments and having these functions reduces code size.
9742 *
9743 */
9744static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
9745 struct sigma_dut *dut,
9746 char *buf, size_t buf_size)
9747{
9748 const char *str_val;
9749 int int_val;
9750 char temp[100];
9751
9752 str_val = get_param(cmd, param);
9753 if (!str_val) {
9754 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9755 return -1;
9756 }
9757 int_val = atoi(str_val);
9758 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07009759 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009760 return 0;
9761}
9762
9763
9764static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
9765 struct sigma_dut *dut,
9766 char *buf, size_t buf_size)
9767{
9768 const char *str_val;
9769 char temp[100];
9770
9771 str_val = get_param(cmd, param);
9772 if (!str_val) {
9773 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9774 return -1;
9775 }
9776 snprintf(temp, sizeof(temp), " %s", str_val);
9777 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07009778 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009779 return 0;
9780}
9781
9782
9783static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
9784 struct sigma_dut *dut,
9785 char *buf, size_t buf_size)
9786{
9787 const char *str_val;
9788 unsigned char mac[6];
9789 char temp[100];
9790
9791 str_val = get_param(cmd, param);
9792 if (!str_val) {
9793 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9794 return -1;
9795 }
9796
9797 if (parse_mac_address(dut, str_val, mac) < 0) {
9798 sigma_dut_print(dut, DUT_MSG_ERROR,
9799 "MAC Address not in proper format");
9800 return -1;
9801 }
9802 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
9803 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07009804 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009805 return 0;
9806}
9807
9808
9809static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
9810 char *buf, size_t buf_size)
9811{
9812 const char *str_val;
9813 char *value = " 1";
9814
9815 str_val = get_param(cmd, param);
9816 if (!str_val || str_val[0] == '\0')
9817 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07009818 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009819
9820}
9821
9822
9823/*
9824 * wifitool athN sendbcnrpt
9825 * <STA MAC - Plugs in from Dest_MAC>
9826 * <regclass - Plugs in from RegClass - int>
9827 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
9828 * <rand_ivl - Plugs in from RandInt - string>
9829 * <duration - Plugs in from MeaDur - integer>
9830 * <mode - Plugs in from MeaMode - string>
9831 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
9832 * <rep_cond - Plugs in from RptCond - integer>
9833 * <rpt_detail - Plugs in from RptDet - integer>
9834 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
9835 * <chanrpt_mode - Plugs in from APChanRpt - integer>
9836 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
9837 * [AP channel numbers]
9838 */
9839static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
9840 struct sigma_cmd *cmd,
9841 const char *ifname)
9842{
9843 char buf[100];
9844 int rpt_det;
9845 const char *str_val;
9846 const char *mea_mode;
9847
9848 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
9849
9850 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
9851 return -1;
9852 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
9853 return -1;
9854 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
9855 return -1;
9856 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
9857 return -1;
9858 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
9859 return -1;
9860
9861 str_val = get_param(cmd, "MeaMode");
9862 if (!str_val) {
9863 sigma_dut_print(dut, DUT_MSG_ERROR,
9864 "MeaMode parameter not present in send bcn-rpt-req");
9865 return -1;
9866 }
9867 if (strcasecmp(str_val, "passive") == 0) {
9868 mea_mode = " 0";
9869 } else if (strcasecmp(str_val, "active") == 0) {
9870 mea_mode = " 1";
9871 } else if (strcasecmp(str_val, "table") == 0) {
9872 mea_mode = " 2";
9873 } else {
9874 sigma_dut_print(dut, DUT_MSG_ERROR,
9875 "MEA-MODE Value not correctly given");
9876 return -1;
9877 }
Peng Xu591be452017-05-10 17:27:28 -07009878 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009879
9880 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
9881
9882 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
9883 return -1;
9884
9885 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
9886 return -1;
9887 str_val = get_param(cmd, "RptDet");
9888 rpt_det = str_val ? atoi(str_val) : 0;
9889
9890 if (rpt_det)
9891 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
9892 else
Peng Xu591be452017-05-10 17:27:28 -07009893 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009894
9895 if (rpt_det)
9896 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
9897 sizeof(buf));
9898 else
Peng Xu591be452017-05-10 17:27:28 -07009899 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009900
9901 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
9902 return -1;
9903
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009904 str_val = get_param(cmd, "APChanRpt");
9905 if (str_val) {
9906 const char *pos;
9907 int ap_chanrpt;
9908 int ap_chanrpt_2 = 0;
9909 char chanrpt[100];
9910
9911 ap_chanrpt = atoi(str_val);
9912 pos = strchr(str_val, '_');
9913 if (pos) {
9914 pos++;
9915 ap_chanrpt_2 = atoi(pos);
9916 }
9917 if (ap_chanrpt) {
9918 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
9919 strlcat(buf, chanrpt, sizeof(buf));
9920 }
9921 if (ap_chanrpt_2) {
9922 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
9923 strlcat(buf, chanrpt, sizeof(buf));
9924 }
9925 }
9926
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009927 run_system(dut, buf);
9928 return 0;
9929}
9930
9931
9932static void inform_and_sleep(struct sigma_dut *dut, int seconds)
9933{
9934 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
9935 sleep(seconds);
9936 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
9937 seconds);
9938}
9939
9940
9941static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
9942 struct sigma_cmd *cmd, const char *ifname)
9943{
9944 unsigned char mac_addr[ETH_ALEN];
9945 int disassoc_timer;
9946 char buf[100];
9947 const char *val;
9948 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009949
9950 val = get_param(cmd, "Dest_MAC");
9951 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9952 sigma_dut_print(dut, DUT_MSG_ERROR,
9953 "MAC Address not in proper format");
9954 return -1;
9955 }
9956
9957 val = get_param(cmd, "Disassoc_Timer");
9958 if (val)
9959 disassoc_timer = atoi(val);
9960 else
9961 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02009962 if (disassoc_timer < 0) {
9963 sigma_dut_print(dut, DUT_MSG_ERROR,
9964 "Invalid Disassoc_Timer value %d",
9965 disassoc_timer);
9966 return -1;
9967 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009968
9969 val = get_param(cmd, "Cand_List");
9970 if (val && val[0])
9971 cand_list = atoi(val);
9972
9973 val = get_param(cmd, "BTMQuery_Reason_Code");
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009974 if (val)
9975 run_iwpriv(dut, ifname, "mbo_trans_rs %s", val);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009976
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009977 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay)
9978 run_iwpriv(dut, ifname, "mbo_asoc_ret 1");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009979
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009980 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009981 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009982 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
9983 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
9984 dut->ap_btmreq_disassoc_imnt,
9985 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009986 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009987 dut->ap_btmreq_bss_term_dur);
9988 run_system(dut, buf);
9989
9990 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009991 if (dut->ap_btmreq_bss_term_tsf >= 2)
9992 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009993 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9994 mac_addr[0], mac_addr[1], mac_addr[2],
9995 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009996 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009997 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009998 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009999 run_system_wrapper(dut, "ifconfig %s up", ifname);
10000 } else if (dut->ap_btmreq_disassoc_imnt) {
10001 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010002 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
10003 mac_addr[0], mac_addr[1], mac_addr[2],
10004 mac_addr[3], mac_addr[4], mac_addr[5]);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010005 }
10006 return 0;
10007}
10008
10009
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010010static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
10011 struct sigma_cmd *cmd, const char *ifname)
10012{
10013 unsigned char mac_addr[ETH_ALEN];
10014 const char *val;
10015
10016 val = get_param(cmd, "Dest_MAC");
10017 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
10018 sigma_dut_print(dut, DUT_MSG_ERROR,
10019 "MAC Address not in proper format");
10020 return -1;
10021 }
10022
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010023 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
10024 mac_addr[0], mac_addr[1], mac_addr[2],
10025 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010026 return 0;
10027}
10028
10029
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010030static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
10031 struct sigma_cmd *cmd)
10032{
10033 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010034 const char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010035
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010036 ifname = get_main_ifname(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010037
10038 val = get_param(cmd, "FrameName");
10039 if (!val)
10040 return -1;
10041
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010042 if (strcasecmp(val, "BTMReq") == 0)
10043 ath_ap_send_frame_btm_req(dut, cmd, ifname);
10044 else if (strcasecmp(val, "BcnRptReq") == 0)
10045 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -080010046 else if (strcasecmp(val, "disassoc") == 0)
10047 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010048 else
10049 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010050
10051 return 1;
10052}
10053
10054
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010055static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
10056 struct sigma_cmd *cmd)
10057{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010058 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010059 case DRIVER_ATHEROS:
10060 return ath_ap_send_frame_vht(dut, conn, cmd);
10061 break;
10062 case DRIVER_OPENWRT:
10063 switch (get_openwrt_driver_type()) {
10064 case OPENWRT_DRIVER_ATHEROS:
10065 return ath_ap_send_frame_vht(dut, conn, cmd);
10066 default:
10067 send_resp(dut, conn, SIGMA_ERROR,
10068 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
10069 return 0;
10070 }
10071 default:
10072 send_resp(dut, conn, SIGMA_ERROR,
10073 "errorCode,Unsupported ap_send_frame with the current driver");
10074 return 0;
10075 }
10076}
10077
10078
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010079static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
10080 struct sigma_cmd *cmd)
10081{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010082 switch (get_driver_type(dut)) {
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010083 case DRIVER_ATHEROS:
10084 return ath_ap_send_frame_loc(dut, conn, cmd);
10085 case DRIVER_OPENWRT:
10086 switch (get_openwrt_driver_type()) {
10087 case OPENWRT_DRIVER_ATHEROS:
10088 return ath_ap_send_frame_loc(dut, conn, cmd);
10089 default:
10090 send_resp(dut, conn, SIGMA_ERROR,
10091 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
10092 return 0;
10093 }
10094 default:
10095 send_resp(dut, conn, SIGMA_ERROR,
10096 "errorCode,Unsupported ap_send_frame_loc with the current driver");
10097 return 0;
10098 }
10099}
10100
10101
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010102static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
10103 struct sigma_cmd *cmd)
10104{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010105 switch (get_driver_type(dut)) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010106 case DRIVER_ATHEROS:
10107 return ath_ap_send_frame_mbo(dut, conn, cmd);
10108 case DRIVER_OPENWRT:
10109 switch (get_openwrt_driver_type()) {
10110 case OPENWRT_DRIVER_ATHEROS:
10111 return ath_ap_send_frame_mbo(dut, conn, cmd);
10112 default:
10113 send_resp(dut, conn, SIGMA_ERROR,
10114 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
10115 return 0;
10116 }
10117 default:
10118 send_resp(dut, conn, SIGMA_ERROR,
10119 "errorCode,Unsupported ap_send_frame with the current driver");
10120 return 0;
10121 }
10122}
10123
10124
Lior David0fe101e2017-03-09 16:09:50 +020010125static int ap_send_frame_60g(struct sigma_dut *dut,
10126 struct sigma_conn *conn,
10127 struct sigma_cmd *cmd)
10128{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010129 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010130#ifdef __linux__
10131 case DRIVER_WIL6210:
10132 return wil6210_send_frame_60g(dut, conn, cmd);
10133#endif /* __linux__ */
10134 default:
10135 send_resp(dut, conn, SIGMA_ERROR,
10136 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10137 return 0;
10138 }
10139}
10140
10141
Jouni Malinenf7222712019-06-13 01:50:21 +030010142enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
10143 struct sigma_conn *conn,
10144 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010145{
10146 /* const char *name = get_param(cmd, "NAME"); */
10147 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10148 const char *val;
10149 enum send_frame_type frame;
10150 enum send_frame_protection protected;
10151 char buf[100];
10152
10153 val = get_param(cmd, "Program");
10154 if (val) {
10155 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070010156 strcasecmp(val, "HS2-R2") == 0 ||
10157 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010158 return ap_send_frame_hs2(dut, conn, cmd);
10159 if (strcasecmp(val, "VHT") == 0)
10160 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010161 if (strcasecmp(val, "LOC") == 0)
10162 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010163 if (strcasecmp(val, "MBO") == 0)
10164 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010165 if (strcasecmp(val, "60GHz") == 0)
10166 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010167 }
10168
10169 val = get_param(cmd, "PMFFrameType");
10170 if (val == NULL)
10171 val = get_param(cmd, "FrameName");
10172 if (val == NULL)
10173 val = get_param(cmd, "Type");
10174 if (val == NULL)
10175 return -1;
10176 if (strcasecmp(val, "disassoc") == 0)
10177 frame = DISASSOC;
10178 else if (strcasecmp(val, "deauth") == 0)
10179 frame = DEAUTH;
10180 else if (strcasecmp(val, "saquery") == 0)
10181 frame = SAQUERY;
10182 else {
10183 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10184 "PMFFrameType");
10185 return 0;
10186 }
10187
10188 val = get_param(cmd, "PMFProtected");
10189 if (val == NULL)
10190 val = get_param(cmd, "Protected");
10191 if (val == NULL)
10192 return -1;
10193 if (strcasecmp(val, "Correct-key") == 0 ||
10194 strcasecmp(val, "CorrectKey") == 0)
10195 protected = CORRECT_KEY;
10196 else if (strcasecmp(val, "IncorrectKey") == 0)
10197 protected = INCORRECT_KEY;
10198 else if (strcasecmp(val, "Unprotected") == 0)
10199 protected = UNPROTECTED;
10200 else {
10201 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10202 "PMFProtected");
10203 return 0;
10204 }
10205
10206 val = get_param(cmd, "stationID");
10207 if (val == NULL)
10208 return -1;
10209
10210 if (protected == INCORRECT_KEY ||
10211 (protected == UNPROTECTED && frame == SAQUERY))
10212 return ap_inject_frame(dut, conn, frame, protected, val);
10213
10214 switch (frame) {
10215 case DISASSOC:
10216 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
10217 val, protected == CORRECT_KEY);
10218 break;
10219 case DEAUTH:
10220 snprintf(buf, sizeof(buf), "deauth %s test=%d",
10221 val, protected == CORRECT_KEY);
10222 break;
10223 case SAQUERY:
10224 snprintf(buf, sizeof(buf), "sa_query %s", val);
10225 break;
10226 }
10227
10228 if (run_hostapd_cli(dut, buf) != 0)
10229 return -2;
10230
10231 return 1;
10232}
10233
10234
Jouni Malinenf7222712019-06-13 01:50:21 +030010235static enum sigma_cmd_result cmd_ap_get_mac_address(struct sigma_dut *dut,
10236 struct sigma_conn *conn,
10237 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010238{
10239#if defined( __linux__)
10240 /* const char *name = get_param(cmd, "NAME"); */
10241 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +030010242 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010243 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010244 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010245 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010246 int s, wlan_tag = 1;
10247 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010248
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010249 val = get_param(cmd, "WLAN_TAG");
10250 if (val) {
10251 wlan_tag = atoi(val);
10252 if (wlan_tag < 1 || wlan_tag > 3) {
10253 /*
10254 * The only valid WLAN Tags as of now as per the latest
10255 * WFA scripts are 1, 2, and 3.
10256 */
Jouni Malinenf8984642017-10-12 00:02:37 +030010257 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010258 "errorCode,Unsupported WLAN_TAG");
10259 return 0;
10260 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010261 }
10262
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010263 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
10264
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010265 s = socket(AF_INET, SOCK_DGRAM, 0);
10266 if (s < 0)
10267 return -1;
10268 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -070010269 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010270 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
10271 perror("ioctl");
10272 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +030010273 snprintf(resp, sizeof(resp),
10274 "errorCode,Could not find interface %s", ifname);
10275 send_resp(dut, conn, SIGMA_ERROR, resp);
10276 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010277 }
10278 close(s);
10279 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
10280
10281 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10282 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10283 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10284 return 0;
10285#elif defined( __QNXNTO__)
10286 char resp[50];
10287 unsigned char addr[6];
10288
Jouni Malinend2095482019-11-04 17:10:43 +020010289 if (!dut->main_ifname) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010290 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
10291 return 0;
10292 }
10293
Jouni Malinen5ea30922019-11-04 17:39:25 +020010294 if (get_hwaddr(get_main_ifname(dut), addr) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010295 send_resp(dut, conn, SIGMA_ERROR,
10296 "errorCode,Failed to get address");
10297 return 0;
10298 }
10299 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10300 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10301 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10302 return 0;
10303#else /* __linux__ */
10304 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
10305 "yet supported");
10306 return 0;
10307#endif /* __linux__ */
10308}
10309
10310
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010311int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
10312 struct sigma_cmd *cmd)
10313{
10314 return cmd_ap_get_mac_address(dut, conn, cmd);
10315}
10316
10317
Jouni Malinenf7222712019-06-13 01:50:21 +030010318static enum sigma_cmd_result cmd_ap_set_pmf(struct sigma_dut *dut,
10319 struct sigma_conn *conn,
10320 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010321{
10322 /*
10323 * Ignore the command since the parameters are already handled through
10324 * ap_set_security.
10325 */
10326
10327 return 1;
10328}
10329
10330
Jouni Malinenf7222712019-06-13 01:50:21 +030010331static enum sigma_cmd_result cmd_ap_set_hs2(struct sigma_dut *dut,
10332 struct sigma_conn *conn,
10333 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010334{
10335 /* const char *name = get_param(cmd, "NAME"); */
10336 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10337 const char *val, *dest;
10338 char *pos, buf[100];
Jouni Malinen77dda642020-01-07 11:21:55 +020010339 int i, wlan_tag = 1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010340
10341 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
10342 "following parameters");
10343 for (i = 0; i < cmd->count; i++) {
10344 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
10345 (cmd->values[i] ? cmd->values[i] : "NULL"));
10346 }
10347
10348 val = get_param(cmd, "ICMPv4_ECHO");
10349 if (val && atoi(val)) {
10350 snprintf(buf, sizeof(buf), "ebtables -F");
10351 if (system(buf) != 0) {
10352 sigma_dut_print(dut, DUT_MSG_ERROR,
10353 "Failed to set ebtables rules, RULE-12");
10354 }
10355 return 1;
10356 }
10357
10358 val = get_param(cmd, "WLAN_TAG");
10359 if (val) {
10360 wlan_tag = atoi(val);
10361 if (wlan_tag != 1 && wlan_tag != 2) {
10362 send_resp(dut, conn, SIGMA_INVALID,
10363 "errorCode,Invalid WLAN_TAG");
10364 return 0;
10365 }
10366 }
10367
10368 if (wlan_tag == 2) {
10369 val = get_param(cmd, "PROXY_ARP");
10370 if (val)
10371 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +020010372
10373 val = get_param(cmd, "OSU");
10374 if (val)
10375 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010376 return 1;
10377 }
10378
10379 dest = get_param(cmd, "STA_MAC");
10380 if (dest) {
10381 /* This is a special/ugly way of using this command.
10382 * If "Dest" MAC is included, assume that this command
10383 * is being issued after ap_config_commit for dynamically
10384 * setting the QoS Map Set.
10385 */
10386 val = get_param(cmd, "QoS_MAP_SET");
10387 if (val) {
10388 dut->ap_qos_map_set = atoi(val);
10389 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10390 dut->ap_qos_map_set);
10391 }
10392
10393 if (dut->ap_qos_map_set == 1)
10394 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
10395 else if (dut->ap_qos_map_set == 2)
10396 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
10397
10398 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
10399 if (run_hostapd_cli(dut, buf) != 0)
10400 return -1;
10401 }
10402
10403 val = get_param(cmd, "DGAF_DISABLE");
10404 if (val)
10405 dut->ap_dgaf_disable = atoi(val);
10406
10407 dut->ap_interworking = 1;
10408
10409 val = get_param(cmd, "INTERWORKING");
10410 if (val == NULL)
10411 val = get_param(cmd, "INTERNETWORKING");
10412 if (val != NULL && atoi(val) == 0) {
10413 dut->ap_interworking = 0;
10414 dut->ap_hs2 = 0;
10415 return 1;
10416 }
10417
10418 val = get_param(cmd, "ACCS_NET_TYPE");
10419 if (val) {
10420 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
10421 strcasecmp(val, "Chargable_Public_Network") == 0 ||
10422 strcasecmp(val, "Chargable Public Network") == 0)
10423 dut->ap_access_net_type = 2;
10424 else
10425 dut->ap_access_net_type = atoi(val);
10426 }
10427
10428 val = get_param(cmd, "INTERNET");
10429 if (val)
10430 dut->ap_internet = atoi(val);
10431
10432 val = get_param(cmd, "VENUE_GRP");
10433 if (val) {
10434 if (strcasecmp(val, "Business") == 0)
10435 dut->ap_venue_group = 2;
10436 else
10437 dut->ap_venue_group = atoi(val);
10438 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10439 dut->ap_venue_name);
10440 }
10441
10442 val = get_param(cmd, "VENUE_TYPE");
10443 if (val) {
10444 if (strcasecmp(val, "R&D") == 0)
10445 dut->ap_venue_type = 8;
10446 else
10447 dut->ap_venue_type = atoi(val);
10448 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
10449 dut->ap_venue_type);
10450 }
10451
10452 val = get_param(cmd, "HESSID");
10453 if (val) {
10454 if (strlen(val) >= sizeof(dut->ap_hessid)) {
10455 send_resp(dut, conn, SIGMA_ERROR,
10456 "errorCode,Invalid HESSID");
10457 return 0;
10458 }
10459 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
10460 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
10461 dut->ap_hessid);
10462 }
10463
10464 val = get_param(cmd, "ROAMING_CONS");
10465 if (val) {
10466 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
10467 send_resp(dut, conn, SIGMA_ERROR,
10468 "errorCode,Invalid ROAMING_CONS");
10469 return 0;
10470 }
10471 if (strcasecmp(val, "Disabled") == 0) {
10472 dut->ap_roaming_cons[0] = '\0';
10473 } else {
10474 snprintf(dut->ap_roaming_cons,
10475 sizeof(dut->ap_roaming_cons), "%s", val);
10476 }
10477 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
10478 dut->ap_roaming_cons);
10479 }
10480
10481 val = get_param(cmd, "ANQP");
10482 if (val)
10483 dut->ap_anqpserver_on = atoi(val);
10484
10485 val = get_param(cmd, "NAI_REALM_LIST");
10486 if (val) {
10487 dut->ap_nai_realm_list = atoi(val);
10488 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
10489 dut->ap_nai_realm_list);
10490 }
10491
10492 val = get_param(cmd, "3GPP_INFO");
10493 if (val) {
10494 /* What kind of encoding format is used?! */
10495 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
10496 "not yet supported (contents not fully defined)");
10497 return 0;
10498 }
10499
10500 val = get_param(cmd, "DOMAIN_LIST");
10501 if (val) {
10502 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
10503 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
10504 "DOMAIN_LIST");
10505 return 0;
10506 }
10507 snprintf(dut->ap_domain_name_list,
10508 sizeof(dut->ap_domain_name_list), "%s", val);
10509 pos = dut->ap_domain_name_list;
10510 while (*pos) {
10511 if (*pos == ';')
10512 *pos = ',';
10513 pos++;
10514 }
10515 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
10516 dut->ap_domain_name_list);
10517 }
10518
10519 val = get_param(cmd, "OPER_NAME");
10520 if (val) {
10521 dut->ap_oper_name = atoi(val);
10522 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
10523 dut->ap_oper_name);
10524 }
10525
10526 val = get_param(cmd, "VENUE_NAME");
10527 if (val) {
10528 dut->ap_venue_name = atoi(val);
10529 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10530 dut->ap_venue_name);
10531 }
10532
10533 val = get_param(cmd, "GAS_CB_DELAY");
10534 if (val) {
10535 dut->ap_gas_cb_delay = atoi(val);
10536 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
10537 dut->ap_gas_cb_delay);
10538 }
10539
10540 val = get_param(cmd, "MIH");
10541 if (val && atoi(val) > 0) {
10542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
10543 "supported");
10544 return 0;
10545 }
10546
10547 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
10548 if (val) {
10549 dut->ap_l2tif = atoi(val);
10550 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
10551 dut->ap_l2tif);
10552 }
10553
10554 val = get_param(cmd, "BCST_UNCST");
10555 if (val) {
10556 send_resp(dut, conn, SIGMA_ERROR,
10557 "errorCode,BCST_UNCST not yet supported");
10558 return 0;
10559 }
10560
10561 val = get_param(cmd, "PLMN_MCC");
10562 if (val) {
10563 char mcc[100], *start, *end;
10564 int i = 0;
10565 if (strlen(val) >= sizeof(mcc)) {
10566 send_resp(dut, conn, SIGMA_ERROR,
10567 "errorCode,PLMN_MCC too long");
10568 return 0;
10569 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010570 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010571 start = mcc;
10572 while ((end = strchr(start, ';'))) {
10573 /* process all except the last */
10574 *end = '\0';
10575 if (strlen(start) != 3) {
10576 send_resp(dut, conn, SIGMA_ERROR,
10577 "errorCode,Invalid PLMN_MCC");
10578 return 0;
10579 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010580 res = snprintf(dut->ap_plmn_mcc[i],
10581 sizeof(dut->ap_plmn_mcc[i]), "%s",
10582 start);
10583 if (res < 0 || res >= sizeof(dut->ap_plmn_mcc[i]))
10584 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010585 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10586 dut->ap_plmn_mcc[i]);
10587 i++;
10588 start = end + 1;
10589 *end = ';';
10590 }
10591 if (strlen(start) != 3) {
10592 send_resp(dut, conn, SIGMA_ERROR,
10593 "errorCode,Invalid PLMN_MCC");
10594 return 0;
10595 }
10596 /* process last or only one */
Jouni Malinen77dda642020-01-07 11:21:55 +020010597 res = snprintf(dut->ap_plmn_mcc[i],
10598 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
10599 if (res < 0 || res >= sizeof(dut->ap_plmn_mcc[i]))
10600 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010601 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10602 dut->ap_plmn_mcc[i]);
10603 }
10604
10605 val = get_param(cmd, "PLMN_MNC");
10606 if (val) {
10607 char mnc[100], *start, *end;
10608 int i = 0;
10609 if (strlen(val) >= sizeof(mnc)) {
10610 send_resp(dut, conn, SIGMA_ERROR,
10611 "errorCode,PLMN_MNC too long");
10612 return 0;
10613 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010614 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010615 start = mnc;
10616 while ((end = strchr(start, ';'))) {
10617 *end = '\0';
10618 if (strlen(start) != 2 && strlen(start) != 3) {
10619 send_resp(dut, conn, SIGMA_ERROR,
10620 "errorCode,Invalid PLMN_MNC");
10621 return 0;
10622 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010623 res = snprintf(dut->ap_plmn_mnc[i],
10624 sizeof(dut->ap_plmn_mnc[i]), "%s",
10625 start);
10626 if (res < 0 || res >= sizeof(dut->ap_plmn_mnc[i]))
10627 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010628 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10629 dut->ap_plmn_mnc[i]);
10630 i++;
10631 start = end + 1;
10632 *end = ';';
10633 }
10634 if (strlen(start) != 2 && strlen(start) != 3) {
10635 send_resp(dut, conn, SIGMA_ERROR,
10636 "errorCode,Invalid PLMN_MNC");
10637 return 0;
10638 }
Jouni Malinen77dda642020-01-07 11:21:55 +020010639 res = snprintf(dut->ap_plmn_mnc[i],
10640 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
10641 if (res < 0 || res >= sizeof(dut->ap_plmn_mnc[i]))
10642 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010643 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10644 dut->ap_plmn_mnc[i]);
10645 }
10646
10647 val = get_param(cmd, "PROXY_ARP");
10648 if (val) {
10649 dut->ap_proxy_arp = atoi(val);
10650 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
10651 dut->ap_proxy_arp);
10652 }
10653
10654 val = get_param(cmd, "WAN_METRICS");
10655 if (val) {
10656 dut->ap_wan_metrics = atoi(val);
10657 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
10658 dut->ap_wan_metrics);
10659 }
10660
10661 val = get_param(cmd, "CONN_CAP");
10662 if (val) {
10663 dut->ap_conn_capab = atoi(val);
10664 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
10665 dut->ap_conn_capab);
10666 }
10667
10668 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
10669 if (val) {
10670 dut->ap_ip_addr_type_avail = atoi(val);
10671 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
10672 dut->ap_ip_addr_type_avail);
10673 }
10674
10675 val = get_param(cmd, "NET_AUTH_TYPE");
10676 if (val) {
10677 dut->ap_net_auth_type = atoi(val);
10678 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
10679 dut->ap_net_auth_type);
10680 }
10681
10682 val = get_param(cmd, "OP_CLASS");
10683 if (val == NULL)
10684 val = get_param(cmd, "OPER_CLASS");
10685 if (val) {
10686 dut->ap_oper_class = atoi(val);
10687 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
10688 dut->ap_oper_class);
10689 }
10690
10691 val = get_param(cmd, "OSU_PROVIDER_LIST");
10692 if (val) {
10693 dut->ap_osu_provider_list = atoi(val);
10694 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
10695 dut->ap_osu_provider_list);
10696 }
10697
Jouni Malinen93a837f2018-11-01 17:09:22 +020010698 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
10699 if (val) {
10700 dut->ap_osu_provider_nai_list = atoi(val);
10701 sigma_dut_print(dut, DUT_MSG_INFO,
10702 "ap_osu_provider_nai_list %d",
10703 dut->ap_osu_provider_nai_list);
10704 }
10705
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010706 val = get_param(cmd, "OSU_SERVER_URI");
10707 if (val) {
10708 i = 0;
10709 do {
10710 int len;
10711 const char *uri = val;
10712 val = strchr(val, ' ');
10713 len = val ? (val++ - uri) : (int) strlen(uri);
10714 if (len > 0 && len < 256) {
10715 memcpy(dut->ap_osu_server_uri[i], uri, len);
10716 dut->ap_osu_server_uri[i][len] = '\0';
10717 sigma_dut_print(dut, DUT_MSG_INFO,
10718 "ap_osu_server_uri[%d] %s", i,
10719 dut->ap_osu_server_uri[i]);
10720 }
10721 } while (val && ++i < 10);
10722 }
10723
10724 val = get_param(cmd, "OSU_METHOD");
10725 if (val) {
10726 i = 0;
10727 do {
10728 int len;
10729 const char *method = val;
10730 val = strchr(val, ' ');
10731 len = val ? (val++ - method) : (int) strlen(method);
10732 if (len > 0) {
10733 if (strncasecmp(method, "SOAP", len) == 0)
10734 dut->ap_osu_method[i] = 1;
10735 else if (strncasecmp(method, "OMADM", len) == 0)
10736 dut->ap_osu_method[i] = 0;
10737 else
10738 return -2;
10739 }
10740 } while (val && ++i < 10);
10741 }
10742
10743 val = get_param(cmd, "OSU_SSID");
10744 if (val) {
10745 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -070010746 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010747 sizeof(dut->ap_osu_ssid));
10748 sigma_dut_print(dut, DUT_MSG_INFO,
10749 "ap_osu_ssid %s",
10750 dut->ap_osu_ssid);
10751 }
10752 }
10753
10754 val = get_param(cmd, "OSU_ICON_TAG");
10755 if (val)
10756 dut->ap_osu_icon_tag = atoi(val);
10757
10758 val = get_param(cmd, "QoS_MAP_SET");
10759 if (val) {
10760 dut->ap_qos_map_set = atoi(val);
10761 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10762 dut->ap_qos_map_set);
10763 }
10764
10765 val = get_param(cmd, "BSS_LOAD");
10766 if (val) {
10767 dut->ap_bss_load = atoi(val);
10768 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
10769 dut->ap_bss_load);
10770 }
10771
Jouni Malinen54a89b02018-05-01 00:16:26 +030010772 val = get_param(cmd, "Venue_URL");
10773 if (val)
10774 dut->ap_venue_url = atoi(val);
10775
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030010776 val = get_param(cmd, "Advice_of_Charge");
10777 if (val)
10778 dut->ap_advice_of_charge = atoi(val);
10779
Jouni Malinenac104532018-05-01 00:27:37 +030010780 val = get_param(cmd, "Operator_Icon_Metadata");
10781 if (val)
10782 dut->ap_oper_icon_metadata = atoi(val);
10783
Jouni Malinenac367142018-05-01 00:32:24 +030010784 val = get_param(cmd, "TnC_File_Name");
10785 if (val)
10786 dut->ap_tnc_file_name = atoi(val);
10787
10788 val = get_param(cmd, "TnC_File_Time_Stamp");
10789 if (val)
10790 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
10791
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010792 return 1;
10793}
10794
10795
10796void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
10797{
10798 char buf[100];
10799
10800 if (!file_exists("nfc-status"))
10801 return;
10802
10803 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
10804 run_system(dut, buf);
10805}
10806
10807
10808static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
10809 const char *info)
10810{
10811 int res;
10812
10813 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
10814 printf("%s\n\n", info);
10815
10816 nfc_status(dut, "START", info);
10817 res = run_system(dut, cmd);
10818 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
10819 if (res) {
10820 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
10821 cmd, res);
10822 return res;
10823 }
10824
10825 return 0;
10826}
10827
10828
10829static int ap_nfc_write_config_token(struct sigma_dut *dut,
10830 struct sigma_conn *conn,
10831 struct sigma_cmd *cmd)
10832{
10833 int res;
10834 char buf[300];
10835
10836 run_system(dut, "killall wps-ap-nfc.py");
10837 unlink("nfc-success");
10838 snprintf(buf, sizeof(buf),
10839 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
10840 dut->summary_log ? "--summary " : "",
10841 dut->summary_log ? dut->summary_log : "");
10842 res = run_nfc_command(dut, buf,
10843 "Touch NFC Tag to write WPS configuration token");
10844 if (res || !file_exists("nfc-success")) {
10845 send_resp(dut, conn, SIGMA_ERROR,
10846 "ErrorCode,Failed to write tag");
10847 return 0;
10848 }
10849
10850 return 1;
10851}
10852
10853
10854static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
10855 struct sigma_conn *conn,
10856 struct sigma_cmd *cmd)
10857{
10858 int res;
10859 char buf[300];
10860
10861 run_system(dut, "killall wps-ap-nfc.py");
10862
10863 unlink("nfc-success");
10864 snprintf(buf, sizeof(buf),
10865 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10866 dut->summary_log ? "--summary " : "",
10867 dut->summary_log ? dut->summary_log : "");
10868 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
10869 if (res || !file_exists("nfc-success")) {
10870 send_resp(dut, conn, SIGMA_ERROR,
10871 "ErrorCode,Failed to read tag");
10872 return 0;
10873 }
10874
10875 return 1;
10876}
10877
10878
10879static int ap_nfc_write_password_token(struct sigma_dut *dut,
10880 struct sigma_conn *conn,
10881 struct sigma_cmd *cmd)
10882{
10883 int res;
10884 char buf[300];
10885
10886 run_system(dut, "killall wps-ap-nfc.py");
10887 unlink("nfc-success");
10888 snprintf(buf, sizeof(buf),
10889 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
10890 dut->summary_log ? "--summary " : "",
10891 dut->summary_log ? dut->summary_log : "");
10892 res = run_nfc_command(dut, buf,
10893 "Touch NFC Tag to write WPS password token");
10894 if (res || !file_exists("nfc-success")) {
10895 send_resp(dut, conn, SIGMA_ERROR,
10896 "ErrorCode,Failed to write tag");
10897 return 0;
10898 }
10899
10900 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
10901 send_resp(dut, conn, SIGMA_ERROR,
10902 "ErrorCode,Failed to enable NFC password token");
10903 return 0;
10904 }
10905
10906 return 1;
10907}
10908
10909
10910static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
10911 struct sigma_conn *conn,
10912 struct sigma_cmd *cmd)
10913{
10914 int res;
10915 char buf[300];
10916
10917 run_system(dut, "killall wps-ap-nfc.py");
10918 unlink("nfc-success");
10919 snprintf(buf, sizeof(buf),
10920 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10921 dut->summary_log ? "--summary " : "",
10922 dut->summary_log ? dut->summary_log : "");
10923 res = run_nfc_command(dut, buf,
10924 "Touch NFC Device to respond to WPS connection handover");
10925 if (res) {
10926 send_resp(dut, conn, SIGMA_ERROR,
10927 "ErrorCode,Failed to enable NFC for connection "
10928 "handover");
10929 return 0;
10930 }
10931 if (!file_exists("nfc-success")) {
10932 send_resp(dut, conn, SIGMA_ERROR,
10933 "ErrorCode,Failed to complete NFC connection handover");
10934 return 0;
10935 }
10936
10937 return 1;
10938}
10939
10940
Jouni Malinenf7222712019-06-13 01:50:21 +030010941static enum sigma_cmd_result cmd_ap_nfc_action(struct sigma_dut *dut,
10942 struct sigma_conn *conn,
10943 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010944{
10945 /* const char *name = get_param(cmd, "Name"); */
10946 /* const char *intf = get_param(cmd, "Interface"); */
10947 const char *oper = get_param(cmd, "Operation");
10948
10949 if (oper == NULL)
10950 return -1;
10951
10952 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
10953 return ap_nfc_write_config_token(dut, conn, cmd);
10954 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
10955 return ap_nfc_write_password_token(dut, conn, cmd);
10956 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
10957 return ap_nfc_wps_read_passwd(dut, conn, cmd);
10958 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
10959 return ap_nfc_wps_connection_handover(dut, conn, cmd);
10960
10961 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
10962 return 0;
10963}
10964
10965
Jouni Malinenf7222712019-06-13 01:50:21 +030010966static enum sigma_cmd_result cmd_ap_wps_read_pin(struct sigma_dut *dut,
10967 struct sigma_conn *conn,
10968 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010969{
10970 char *pin = "12345670"; /* TODO: use random PIN */
10971 char resp[100];
10972
10973 snprintf(resp, sizeof(resp), "PIN,%s", pin);
10974 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10975
10976 return 0;
10977}
10978
10979
Jouni Malinenf7222712019-06-13 01:50:21 +030010980static enum sigma_cmd_result cmd_ap_wps_enter_pin(struct sigma_dut *dut,
10981 struct sigma_conn *conn,
10982 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010983{
10984 const char *pin = get_param(cmd, "PIN");
10985 char wps_pin[11];
10986
10987 if (!pin)
10988 return -1;
10989
10990 sigma_dut_print(dut, DUT_MSG_DEBUG,
10991 "Authorize a client to join with WPS PIN %s", pin);
10992
10993 strlcpy(wps_pin, pin, sizeof(wps_pin));
10994 /* we need to tolerate extra '-' characters entered */
10995 str_remove_chars(wps_pin, '-');
10996 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
10997 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
10998
10999 return 1;
11000}
11001
11002
Jouni Malinenf7222712019-06-13 01:50:21 +030011003static enum sigma_cmd_result cmd_ap_wps_set_pbc(struct sigma_dut *dut,
11004 struct sigma_conn *conn,
11005 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020011006{
11007 sigma_dut_print(dut, DUT_MSG_DEBUG,
11008 "Selecting the push button configuration method");
11009
11010 dut->wps_method = WFA_CS_WPS_PBC;
11011
11012 return 1;
11013}
11014
11015
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020011016int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
11017 struct sigma_cmd *cmd)
11018{
11019 char buf[100], resp[256];
11020 const char *intf = get_param(cmd, "interface");
11021 const char *config_method = get_param(cmd, "WPSConfigMethod");
11022
11023 if (config_method && strcasecmp(config_method, "PBC") == 0)
11024 dut->wps_method = WFA_CS_WPS_PBC;
11025
11026 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011027 intf = get_main_ifname(dut);
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020011028
11029 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
11030 send_resp(dut, conn, SIGMA_ERROR,
11031 "ErrorCode,WPS parameters not yet set");
11032 return STATUS_SENT;
11033 }
11034
11035 if (dut->wps_method == WFA_CS_WPS_PBC)
11036 snprintf(buf, sizeof(buf), "WPS_PBC");
11037 else /* WFA_CS_WPS_PIN_KEYPAD */
11038 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
11039
11040 /* Run WPS command */
11041 if (hapd_command(intf, buf) < 0) {
11042 /* command fails immediately if overlapped session detected */
11043 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
11044 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11045 return STATUS_SENT;
11046 }
11047
11048 /* In AP mode return immediately and do not wait for WPS registration */
11049 return SUCCESS_SEND_STATUS;
11050}
11051
11052
Jouni Malinenf7222712019-06-13 01:50:21 +030011053static enum sigma_cmd_result cmd_ap_get_parameter(struct sigma_dut *dut,
11054 struct sigma_conn *conn,
11055 struct sigma_cmd *cmd)
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011056{
11057 char value[256], resp[512];
11058 const char *param = get_param(cmd, "parameter");
11059 const char *ifname = get_param(cmd, "Interface");
11060
11061 if (!ifname)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011062 ifname = get_main_ifname(dut);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011063
11064 if (!param) {
11065 send_resp(dut, conn, SIGMA_ERROR,
11066 "ErrorCode,Parameter not specified");
11067 return 0;
11068 }
11069
11070 if (strcasecmp(param, "SSID") == 0) {
11071 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
11072 sigma_dut_print(dut, DUT_MSG_ERROR,
11073 "Failed to get SSID");
11074 return -2;
11075 }
11076 snprintf(resp, sizeof(resp), "SSID,%s", value);
11077 } else if (strcasecmp(param, "PSK") == 0) {
11078 if (get_hapd_config(ifname, "passphrase", value,
11079 sizeof(value))) {
11080 sigma_dut_print(dut, DUT_MSG_ERROR,
11081 "Failed to get PSK");
11082 return -2;
11083 }
11084 snprintf(resp, sizeof(resp), "PSK,%s", value);
11085 } else {
11086 send_resp(dut, conn, SIGMA_ERROR,
11087 "ErrorCode,Unsupported parameter");
11088 return 0;
11089 }
11090
11091 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11092 return 0;
11093}
11094
11095
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011096static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
11097 const char *val)
11098{
11099 char *token, *result;
11100 int nss = 0, chwidth = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011101 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011102
11103 /*
11104 * The following commands should be invoked to generate
11105 * VHT op mode notification
11106 */
11107
11108 /* Extract the NSS info */
11109 token = strdup(val);
11110 if (!token)
11111 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011112 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011113 if (result) {
11114 int count = atoi(result);
11115
11116 /* We do not support NSS > 3 */
11117 if (count < 0 || count > 3) {
11118 free(token);
11119 return -1;
11120 }
11121
11122 /* Convert nss to chainmask */
11123 while (count--)
11124 nss = (nss << 1) | 1;
11125
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011126 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011127 }
11128
11129 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011130 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011131 if (result) {
11132 switch (atoi(result)) {
11133 case 20:
11134 chwidth = 0;
11135 break;
11136 case 40:
11137 chwidth = 1;
11138 break;
11139 case 80:
11140 chwidth = 2;
11141 break;
11142 case 160:
11143 chwidth = 3;
11144 break;
11145 default:
11146 chwidth = 2;
11147 break;
11148 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011149 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011150 }
11151
11152 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011153 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011154 free(token);
11155
11156 return 0;
11157}
11158
11159
11160static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
11161 const char *val)
11162{
11163 /* String (nss_operating_mode; mcs_operating_mode) */
11164 int nss, mcs;
11165 char *token, *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011166 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011167
11168 token = strdup(val);
11169 if (!token)
11170 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011171 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011172 if (!result) {
11173 sigma_dut_print(dut, DUT_MSG_ERROR,
11174 "VHT NSS not specified");
11175 goto end;
11176 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011177 if (strcasecmp(result, "def") != 0) {
11178 nss = atoi(result);
11179
11180 if (nss == 4)
11181 ath_disable_txbf(dut, ifname);
11182
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011183 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011184 } else {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011185 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11186 run_iwpriv(dut, ifname, "nss 1");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011187 if (dut->device_type == AP_testbed &&
11188 dut->program == PROGRAM_HE) {
11189 nss = dut->ap_tx_streams;
11190 run_iwpriv(dut, ifname, "nss %d", nss);
11191 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011192 }
11193
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011194 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011195 if (!result) {
11196 sigma_dut_print(dut, DUT_MSG_ERROR,
11197 "VHT MCS not specified");
11198 goto end;
11199 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011200 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011201 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11202 run_iwpriv(dut, ifname, "vhtmcs 7");
11203 else
11204 run_iwpriv(dut, ifname, "set11NRates 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011205 if (dut->device_type == AP_testbed &&
11206 dut->program == PROGRAM_HE)
11207 run_iwpriv(dut, ifname, "he_mcs 7");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011208 } else {
11209 mcs = atoi(result);
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011210 if (dut->program == PROGRAM_HE)
11211 run_iwpriv(dut, ifname, "he_mcs %d", mcs);
11212 else
11213 run_iwpriv(dut, ifname, "vhtmcs %d", mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011214 }
11215
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011216end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011217 free(token);
11218 return 0;
11219}
11220
11221
11222static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
11223 const char *val)
11224{
11225 char *token, *result;
11226 int channel = 36;
11227 int chwidth = 80;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011228 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011229
11230 /* Extract the channel info */
11231 token = strdup(val);
11232 if (!token)
11233 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011234 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011235 if (result)
11236 channel = atoi(result);
11237
11238 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011239 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011240 if (result)
11241 chwidth = atoi(result);
11242
11243 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011244 run_iwpriv(dut, ifname, "doth_ch_chwidth %d 10 %d", channel, chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011245
11246 free(token);
11247 return 0;
11248}
11249
11250
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011251static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
11252 const char *val)
11253{
11254 char buf[80];
11255 unsigned char mac_addr[6];
11256
11257 if (parse_mac_address(dut, val, mac_addr) < 0)
11258 return -1;
11259
11260 snprintf(buf, sizeof(buf),
11261 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
11262 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
11263 run_system(dut, buf);
11264
11265 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
11266 ifname, mac_addr[4], mac_addr[5]);
11267 run_system(dut, buf);
11268
11269 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
11270 run_system(dut, buf);
11271
11272 return 0;
11273}
11274
11275
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011276void novap_reset(struct sigma_dut *dut, const char *ifname, int reset)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011277{
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011278 run_iwpriv(dut, ifname, "novap_reset %d", reset);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011279}
11280
11281
Jouni Malinenb4335432019-06-13 02:23:57 +030011282static struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
11283 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011284{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011285 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011286
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011287 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
11288 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
11289 ETH_ALEN) == 0)
11290 return &dut->mbo_pref_aps[i];
11291 }
11292 return NULL;
11293}
11294
11295
11296static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
11297 int ap_ne_class, int ap_ne_op_ch,
11298 int ap_ne_pref)
11299{
11300 struct mbo_pref_ap *entry;
11301 uint8_t self_mac[ETH_ALEN];
11302 char ifname[50];
11303
11304 get_if_name(dut, ifname, sizeof(ifname), 1);
11305 get_hwaddr(ifname, self_mac);
11306
11307 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
11308 entry = &dut->mbo_self_ap_tuple;
11309 else
11310 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
11311
11312 if (!entry) {
11313 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
11314 sigma_dut_print(dut, DUT_MSG_ERROR,
11315 "Nebor AP List is full. Not adding");
11316 return;
11317 }
11318 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
11319 dut->mbo_pref_ap_cnt++;
11320 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
11321 entry->ap_ne_class = -1;
11322 entry->ap_ne_op_ch = -1;
11323 entry->ap_ne_pref = -1;
11324 }
11325 if (ap_ne_class != -1)
11326 entry->ap_ne_class = ap_ne_class;
11327 if (ap_ne_op_ch != -1)
11328 entry->ap_ne_op_ch = ap_ne_op_ch;
11329 if (ap_ne_pref != -1)
11330 entry->ap_ne_pref = ap_ne_pref;
11331}
11332
11333
11334static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
11335 struct sigma_cmd *cmd)
11336{
11337 unsigned char mac_addr[ETH_ALEN];
11338 const char *val;
11339 /*
11340 * -1 is invalid value for the following
11341 * to differentiate between unset and set values
11342 * -1 => implies not set by CAPI
11343 */
11344 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
11345 int list_offset = dut->mbo_pref_ap_cnt;
11346
11347 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
11348 sigma_dut_print(dut, DUT_MSG_ERROR,
11349 "AP Pref Entry list is full");
11350 return -1;
11351 }
11352
11353 val = get_param(cmd, "Nebor_Op_Class");
11354 if (val)
11355 ap_ne_class = atoi(val);
11356
11357 val = get_param(cmd, "Nebor_Op_Ch");
11358 if (val)
11359 ap_ne_op_ch = atoi(val);
11360
11361 val = get_param(cmd, "Nebor_Pref");
11362 if (val)
11363 ap_ne_pref = atoi(val);
11364
11365 val = get_param(cmd, "Nebor_BSSID");
11366 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011367 return -1;
11368
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011369 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
11370 ap_ne_pref);
11371 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011372 return 0;
11373}
11374
11375
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011376static enum sigma_cmd_result he_ltf(struct sigma_dut *dut,
11377 struct sigma_conn *conn,
11378 const char *ifname, const char *val)
11379{
11380 const char *var;
11381
11382 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11383 var = "he_ul_ltf";
11384 else
11385 var = "he_ltf";
11386
11387 if (strcmp(val, "6.4") == 0) {
11388 run_iwpriv(dut, ifname, "%s 2", var);
11389 } else if (strcmp(val, "12.8") == 0) {
11390 run_iwpriv(dut, ifname, "%s 3", var);
11391 } else if (strcmp(val, "3.2") == 0) {
11392 run_iwpriv(dut, ifname, "%s 1", var);
11393 } else {
11394 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported LTF");
11395 return STATUS_SENT_ERROR;
11396 }
11397
11398 return SUCCESS_SEND_STATUS;
11399}
11400
11401
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011402static enum sigma_cmd_result he_shortgi(struct sigma_dut *dut,
11403 struct sigma_conn *conn,
11404 const char *ifname,
11405 const char *val)
11406{
11407 const char *var;
11408
11409 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11410 var = "he_ul_shortgi";
11411 else
11412 var = "shortgi";
11413
11414 if (strcmp(val, "0.8") == 0) {
11415 run_iwpriv(dut, ifname, "%s 0", var);
11416 } else if (strcmp(val, "1.6") == 0) {
11417 run_iwpriv(dut, ifname, "%s 2", var);
11418 } else if (strcmp(val, "3.2") == 0) {
11419 run_iwpriv(dut, ifname, "%s 3", var);
11420 } else {
11421 send_resp(dut, conn, SIGMA_ERROR,
11422 "errorCode,Unsupported shortGI");
11423 return STATUS_SENT_ERROR;
11424 }
11425
11426 return SUCCESS_SEND_STATUS;
11427}
11428
11429
11430static enum sigma_cmd_result he_ar_gi_ltf_mask(struct sigma_dut *dut,
11431 struct sigma_conn *conn,
11432 const char *ifname,
11433 const char *val)
11434{
11435
11436 uint32_t he_ar_gi_ltf;
11437 uint16_t he_ar_gi, he_ar_ltf;
11438
11439 if (strcmp(val, "0.4") == 0) {
11440 he_ar_gi = 0x01;
11441 } else if (strcmp(val, "0.8") == 0) {
11442 he_ar_gi = 0x02;
11443 } else if (strcmp(val, "1.6") == 0) {
11444 he_ar_gi = 0x04;
11445 } else if (strcmp(val, "3.2") == 0) {
11446 he_ar_gi = 0x08;
11447 } else {
11448 send_resp(dut, conn, SIGMA_ERROR,
11449 "errorCode,Unsupported shortGI");
11450 return STATUS_SENT_ERROR;
11451 }
11452
11453 if (dut->ar_ltf && strcmp(dut->ar_ltf, "6.4") == 0) {
11454 he_ar_ltf = 0x02;
11455 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "12.8") == 0) {
11456 he_ar_ltf = 0x04;
11457 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "3.2") == 0) {
11458 he_ar_ltf = 0x01;
11459 } else {
11460 send_resp(dut, conn, SIGMA_ERROR,
11461 "errorCode,Unsupported LTF");
11462 return STATUS_SENT_ERROR;
11463 }
11464
11465 he_ar_gi_ltf = (he_ar_gi << 8) | he_ar_ltf;
11466 run_iwpriv(dut, ifname, "he_ar_gi_ltf %lu", he_ar_gi_ltf);
11467
11468 return SUCCESS_SEND_STATUS;
11469}
11470
11471
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011472static enum sigma_cmd_result he_rualloctones(struct sigma_dut *dut,
11473 struct sigma_conn *conn,
11474 const char *ifname,
11475 const char *val)
11476{
11477 char *token, *result;
11478 int value;
11479 char *saveptr;
11480 int rualloc_type;
11481 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
11482
11483 token = strdup(val);
11484 if (!token)
11485 return -1;
11486 result = strtok_r(token, ":", &saveptr);
11487 if (!result) {
11488 free(token);
11489 send_resp(dut, conn, SIGMA_ERROR,
11490 "errorCode,RUAllocTones not specified");
11491 return STATUS_SENT_ERROR;
11492 }
11493
11494 /*
11495 * ru_allocation_type can take the values of:
11496 * 1 - DL OFDMA data RU allocation
11497 * 3 - UL OFDMA data RU allocation
11498 */
11499 rualloc_type = dut->ap_he_ulofdma == VALUE_ENABLED ? 3 : 1;
11500
11501
11502 value = atoi(result);
11503 if (value == 106) {
11504 enum value_not_set_enabled_disabled ap_he_rualloc_106_80 =
11505 VALUE_NOT_SET;
11506
11507 result = strtok_r(NULL, ":", &saveptr);
11508 if (result) {
11509 result = strtok_r(NULL, ":", &saveptr);
11510 if (result)
11511 ap_he_rualloc_106_80 = VALUE_ENABLED;
11512 else
11513 ap_he_rualloc_106_80 = VALUE_DISABLED;
11514 }
11515 if (ap_he_rualloc_106_80 == VALUE_ENABLED) {
11516 run_system_wrapper(dut,
11517 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 2 1 2 2 2 3 2",
11518 ifname, rualloc_type);
11519 } else {
11520 run_system_wrapper(dut,
11521 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 2 1 2",
11522 ifname, rualloc_type);
11523 }
11524 } else if (value == 242) {
11525 run_system_wrapper(
11526 dut,
11527 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 3 1 3 2 3 3 3",
11528 ifname, rualloc_type);
11529 } else if (value == 26) {
11530 run_system_wrapper(
11531 dut,
11532 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 0 2 0 5 0 7 0",
11533 ifname, rualloc_type);
11534 } else if (value == 52) {
11535 run_system_wrapper(
11536 dut,
11537 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 1 1 1 2 1 3 1",
11538 ifname, rualloc_type);
11539 } else if (value == 484) {
11540 run_system_wrapper(
11541 dut,
11542 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 4 1 4",
11543 ifname, rualloc_type);
11544 } else if (value == 996) {
11545 run_system_wrapper(dut,
11546 "wifitool %s setUnitTestCmd 0x4b 3 %d 0 5",
11547 ifname, rualloc_type);
11548 } else {
11549 send_resp(dut, conn, SIGMA_ERROR,
11550 "errorCode,Unsupported RUAllocTones");
11551 ret = STATUS_SENT_ERROR;
11552 }
11553
11554 free(token);
11555 return ret;
11556}
11557
11558
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070011559static void ath_set_trigger_type_0(struct sigma_dut *dut, const char *ifname)
11560{
11561 /* TriggerType "0" for Basic trigger */
11562 if (dut->ap_channel >= 36) {
11563 /* 1 and 2 here is interpreted to 5g and 2g (bitmasks) */
11564 run_system_wrapper(dut,
11565 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11566 ifname);
11567 } else {
11568 run_system_wrapper(dut,
11569 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11570 ifname);
11571 }
11572 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 6",
11573 ifname);
11574}
11575
11576
11577static void ath_set_trigger_type_1(struct sigma_dut *dut, const char *ifname)
11578{
11579 /* TriggerType "1" for MU BRP */
11580 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 1",
11581 ifname);
11582 mubrp_commands(dut, ifname);
11583}
11584
11585
11586static void ath_set_trigger_type_2(struct sigma_dut *dut, const char *ifname)
11587{
11588 /* TriggerType "2" for MU BAR */
11589 if (dut->ap_channel >= 36) {
11590 /* RU allocation RU 242 - DL OFDMA data */
11591 run_system_wrapper(dut,
11592 "wifitool %s setUnitTestCmd 0x4b 5 9 0 3 1 3 2 3 3 3",
11593 ifname);
11594 /* RU allocation RU 52 - UL BA */
11595 run_system_wrapper(dut,
11596 "wifitool %s setUnitTestCmd 0x4b 5 9 0 2 1 2 2 2 3 2",
11597 ifname);
11598 } else {
11599 /* RU allocation RU 52 - DL ofdma data */
11600 run_system_wrapper(dut,
11601 "wifitool %s setUnitTestCmd 0x4b 5 9 0 1 1 1 2 1 3 1",
11602 ifname);
11603 }
11604 /* Force TBPPDU duration to 400 us */
11605 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 400",
11606 ifname);
11607 /* 0 to enable MU BAR, 1 to enable SU BAR */
11608 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 49 0",
11609 ifname);
11610 /* MU BAR */
11611 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 64 0",
11612 ifname);
11613}
11614
11615
11616static void ath_set_trigger_type_3(struct sigma_dut *dut, const char *ifname)
11617{
11618 /* TriggerType "3" for MU RTS */
11619 /* Send MU RTS Trigger - '1' is to enable MU RTS */
11620 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 101 1",
11621 ifname);
11622}
11623
11624
11625static void ath_set_trigger_type_4(struct sigma_dut *dut, const char *ifname,
11626 const char *basedev)
11627{
11628 /* TriggerType "4" for BSRP */
11629 run_system_wrapper(dut, "cfg80211tool %s he_ul_trig_int 200", basedev);
11630 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 1000",
11631 ifname);
11632 if (dut->ap_channel >= 36) {
11633 run_system_wrapper(dut,
11634 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11635 ifname);
11636 } else {
11637 run_system_wrapper(dut,
11638 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11639 ifname);
11640 }
11641 /* Send BSRP command */
11642 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 7",
11643 ifname);
11644}
11645
11646
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011647static enum sigma_cmd_result ath_ap_set_rfeature(struct sigma_dut *dut,
11648 struct sigma_conn *conn,
11649 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011650{
11651 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011652 const char *ifname;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011653 enum sigma_cmd_result res;
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011654 const char *basedev = "wifi0";
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011655 int trigtype;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011656 int he_ackpolicymac = 0;
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070011657 char *num_ss = NULL;
11658 char *nss[4] = { NULL, NULL, NULL, NULL };
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070011659 char *aid[4] = { NULL, NULL, NULL, NULL };
11660 char *aid_ss = NULL;
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070011661 int omctrl_rxnss = 0, omctrl_chwidth = 0;
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070011662 int param;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011663 unsigned char mac_addr[ETH_ALEN];
11664
11665 memset(mac_addr, 0x00, ETH_ALEN);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011666
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011667 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011668
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011669 if (sigma_radio_ifname[0])
11670 basedev = sigma_radio_ifname[0];
11671
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011672 /* Disable vap reset between the commands */
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011673 novap_reset(dut, ifname, 1);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011674
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011675 val = get_param(cmd, "Opt_md_notif_ie");
11676 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011677 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011678
11679 /* TODO: Optional arguments */
11680
11681 val = get_param(cmd, "nss_mcs_opt");
11682 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011683 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011684
11685 val = get_param(cmd, "chnum_band");
11686 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011687 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011688
11689 val = get_param(cmd, "RTS_FORCE");
11690 if (val)
11691 ath_config_rts_force(dut, ifname, val);
11692
11693 val = get_param(cmd, "DYN_BW_SGNL");
11694 if (val)
11695 ath_config_dyn_bw_sig(dut, ifname, val);
11696
11697 val = get_param(cmd, "CTS_WIDTH");
11698 if (val)
11699 ath_set_cts_width(dut, ifname, val);
11700
11701 val = get_param(cmd, "Ndpa_stainfo_mac");
11702 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011703 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011704
11705 val = get_param(cmd, "txBandwidth");
11706 if (val && ath_set_width(dut, conn, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011707 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011708
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011709 val = get_param(cmd, "Assoc_Disallow");
11710 if (val)
11711 ath_set_assoc_disallow(dut, ifname, val);
11712
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011713
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011714 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011715 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011716 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011717 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011718 dut->ap_disassoc_timer = 1000;
11719 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011720
11721 val = get_param(cmd, "BTMReq_Term_Bit");
11722 if (val)
11723 dut->ap_btmreq_term_bit = atoi(val);
11724
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011725 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011726 if (val) {
11727 dut->ap_assoc_delay = 1;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011728 run_iwpriv(dut, ifname, "mbo_asoc_ret %s", val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011729 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011730
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070011731 val = get_param(cmd, "Disassoc_Timer");
11732 if (val)
11733 dut->ap_disassoc_timer = atoi(val);
11734
11735 val = get_param(cmd, "BSS_Term_Duration");
11736 if (val)
11737 dut->ap_btmreq_bss_term_dur = atoi(val);
11738
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080011739 val = get_param(cmd, "BSS_Term_TSF");
11740 if (val)
11741 dut->ap_btmreq_bss_term_tsf = atoi(val);
11742
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011743 val = get_param(cmd, "TxPower");
11744 if (val)
11745 ath_set_txpower(dut, ifname, val);
11746
11747 val = get_param(cmd, "DownlinkAvailCap");
11748 if (val)
11749 dut->ap_dl_availcap = atoi(val);
11750
11751 val = get_param(cmd, "UplinkAvailCap");
11752 if (val) {
11753 dut->ap_ul_availcap = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011754 run_iwpriv(dut, ifname, "oce_wan_mtr %d %d",
11755 dut->ap_dl_availcap, dut->ap_ul_availcap);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011756 }
11757
11758 val = get_param(cmd, "RSSIthreshold");
11759 if (val) {
11760 int rssithreshold;
11761
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011762 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011763 rssithreshold = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011764 run_iwpriv(dut, ifname, "oce_asoc_rssi %d", rssithreshold);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011765 }
11766
11767 val = get_param(cmd, "RetryDelay");
11768 if (val) {
11769 int retrydelay;
11770
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011771 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011772 retrydelay = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011773 run_iwpriv(dut, ifname, "oce_asoc_dly %d", retrydelay);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011774 }
11775
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011776 val = get_param(cmd, "LTF");
11777 if (val) {
11778 if (dut->ap_fixed_rate) {
11779 res = he_ltf(dut, conn, ifname, val);
11780 if (res != SUCCESS_SEND_STATUS)
11781 return res;
11782 } else {
11783 free(dut->ar_ltf);
11784 dut->ar_ltf = strdup(val);
11785 if (!dut->ar_ltf)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011786 return ERROR_SEND_STATUS;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011787 }
11788 }
11789
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011790 val = get_param(cmd, "GI");
11791 if (val) {
11792 if (dut->ap_fixed_rate)
11793 res = he_shortgi(dut, conn, ifname, val);
11794 else
11795 res = he_ar_gi_ltf_mask(dut, conn, ifname, val);
11796 if (res != SUCCESS_SEND_STATUS)
11797 return res;
11798 }
11799
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011800 val = get_param(cmd, "RUAllocTones");
11801 if (val) {
11802 res = he_rualloctones(dut, conn, ifname, val);
11803 if (res != SUCCESS_SEND_STATUS)
11804 return res;
11805 }
11806
Priyadharshini Gowthaman803fd662019-07-31 14:37:49 -070011807 val = get_param(cmd, "MPDU_MU_SpacingFactor");
11808 if (val)
11809 run_system_wrapper(dut,
11810 "wifitool %s setUnitTestCmd 0x48 2 119, %s",
11811 ifname, val);
11812
11813 val = get_param(cmd, "PPDUTxType");
11814 if (val) {
11815 if (strcasecmp(val, "HE-SU") == 0) {
11816 /* Change PPDU format type to HE-SU MCS 1 */
11817 run_system_wrapper(dut,
11818 "wifitool %s setUnitTestCmd 0x48 2 89 0x401",
11819 ifname);
11820 } else if (strcasecmp(val, "legacy") == 0) {
11821 /* Change PPDU format type to non-HT */
11822 run_system_wrapper(dut,
11823 "wifitool %s setUnitTestCmd 0x48 2 89 3",
11824 ifname);
11825 } else {
11826 send_resp(dut, conn, SIGMA_ERROR,
11827 "errorCode,Unsupported PPDUTxType");
11828 return STATUS_SENT_ERROR;
11829 }
11830 }
11831
11832 val = get_param(cmd, "TXOPDuration");
11833 if (val) {
11834 if (strcasecmp(val, "UNSPECIFIED") == 0) {
11835 /* The hardware is hardcoded with 0x7f; do nothing */
11836 } else {
11837 send_resp(dut, conn, SIGMA_ERROR,
11838 "errorCode,Unsupported TXOPDuration");
11839 return STATUS_SENT_ERROR;
11840 }
11841 }
11842
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011843 val = get_param(cmd, "Trig_Usrinfo_UL-MCS");
11844 if (val)
11845 run_iwpriv(dut, ifname, "he_ul_mcs %d", atoi(val));
11846
11847 val = get_param(cmd, "Trig_Usrinfo_UL-Target-RSSI");
11848 if (val) {
11849 /* Set target RSSI to -55 dBm */
11850 run_system_wrapper(dut,
11851 "wifitool %s setUnitTestCmd 0x4b 2 7 %d",
11852 ifname, atoi(val) - 110);
11853 }
11854
11855 val = get_param(cmd, "Trig_Interval");
11856 if (val)
11857 run_iwpriv(dut, basedev, "he_ul_trig_int %d", atoi(val));
11858
11859 val = get_param(cmd, "Trig_ComInfo_ULLength");
11860 if (val)
11861 run_system_wrapper(dut,
11862 "wifitool %s setUnitTestCmd 0x48 2 141 %d",
11863 ifname, atoi(val));
11864
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011865 val = get_param(cmd, "DisableTriggerType");
11866 if (val) {
11867 trigtype = atoi(val);
11868 switch (trigtype) {
11869 case 0:
11870 /* DisableTriggerType "0" for basic trigger */
11871 run_system_wrapper(dut,
11872 "wifitool %s setUnitTestCmd 0x47 2 42 0",
11873 ifname);
11874 break;
11875 default:
11876 /* Nothing to be done for now */
11877 break;
11878 }
11879 }
11880
11881 val = get_param(cmd, "Trigger_TxBF");
11882 if (val) {
11883 if (strcasecmp(val, "enable") == 0) {
11884 run_iwpriv(dut, ifname, "he_sounding_mode 0x9");
11885 } else if (strcasecmp(val, "disable") == 0) {
11886 run_iwpriv(dut, ifname, "he_sounding_mode 0x1");
11887 } else {
11888 send_resp(dut, conn, SIGMA_ERROR,
11889 "errorCode,Unsupported trigger_txbf");
11890 return STATUS_SENT_ERROR;
11891 }
11892 }
11893
Priyadharshini Gowthaman7b94f082019-07-31 14:38:25 -070011894 val = get_param(cmd, "Trig_UsrInfo_RUAlloc");
11895 if (val) {
11896 res = he_rualloctones(dut, conn, ifname, val);
11897 if (res != SUCCESS_SEND_STATUS)
11898 return res;
11899 }
11900
Priyadharshini Gowthaman8701fac2019-07-31 14:38:48 -070011901 val = get_param(cmd, "TriggerCoding");
11902 if (val) {
11903 if (strcasecmp(val, "BCC") == 0) {
11904 /* In case of LDPC enable this command can force BCC if
11905 * RU size <= 242 */
11906 run_iwpriv(dut, ifname, "he_ul_ldpc 0");
11907 } else if (strcasecmp(val, "LDPC") == 0) {
11908 novap_reset(dut, ifname, 0);
11909 run_iwpriv(dut, ifname, "he_ul_ldpc 1");
11910 novap_reset(dut, ifname, 1);
11911 } else {
11912 send_resp(dut, conn, SIGMA_ERROR,
11913 "errorCode,Unsupported TriggerCoding");
11914 return STATUS_SENT_ERROR;
11915 }
11916 }
11917
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011918 val = get_param(cmd, "AckPolicy_MAC");
11919 if (val) {
11920 if (parse_mac_address(dut, val, mac_addr) < 0) {
11921 send_resp(dut, conn, SIGMA_ERROR,
11922 "errorCode,MAC Address not in proper format");
11923 return STATUS_SENT_ERROR;
11924 }
11925 he_ackpolicymac = 1;
11926 }
11927
11928 val = get_param(cmd, "AckPolicy");
11929 if (val) {
11930 int ap_he_ackpolicy;
11931
11932 ap_he_ackpolicy = atoi(val);
11933 if (ap_he_ackpolicy == 0 && he_ackpolicymac) {
11934 /* Disable all-BAR ackpolicy for MU-MIMO */
11935 run_system_wrapper(dut,
11936 "wifitool %s setUnitTestCmd 0x48 2 62 0",
11937 ifname);
11938 /* Disable all-BAR ackpolicy first */
11939 run_system_wrapper(dut,
11940 "wifitool %s setUnitTestCmd 0x48 2 64 0",
11941 ifname);
11942 /* Set normal ack policy for the STA with the specified
11943 * MAC address in DL-TX case */
11944 run_system_wrapper(dut,
11945 "wifitool %s setUnitTestCmd 0x4b 8 8 1 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
11946 ifname, mac_addr[0], mac_addr[1],
11947 mac_addr[2], mac_addr[3],
11948 mac_addr[4], mac_addr[5]);
11949 } else if (ap_he_ackpolicy == 3) {
11950 /* Enable all-BAR ackpolicy for MU-MIMO DL */
11951 run_system_wrapper(dut,
11952 "wifitool %s setUnitTestCmd 0x48 2 62 1",
11953 ifname);
11954 /* Enable all-BAR ackpolicy */
11955 run_system_wrapper(dut,
11956 "wifitool %s setUnitTestCmd 0x48 2 64 1",
11957 ifname);
11958 } else if (ap_he_ackpolicy == 4) {
11959 /* Enable htp-ack ackpolicy */
11960 run_system_wrapper(dut,
11961 "wifitool %s setUnitTestCmd 0x47 2 99 1",
11962 ifname);
11963 } else {
11964 send_resp(dut, conn, SIGMA_ERROR,
11965 "errorCode,Invalid AckPolicy setting");
11966 return STATUS_SENT_ERROR;
11967 }
11968 }
11969
Priyadharshini Gowthamanc9a88c72019-08-09 12:04:17 -070011970 val = get_param(cmd, "Trig_ComInfo_GI-LTF");
11971 if (val) {
11972 int trig_gi_ltf;
11973
11974 trig_gi_ltf = atoi(val);
11975 if (trig_gi_ltf == 0) {
11976 he_ltf(dut, conn, ifname, "3.2");
11977 he_shortgi(dut, conn, ifname, "1.6");
11978 } else if (trig_gi_ltf == 1) {
11979 he_ltf(dut, conn, ifname, "6.4");
11980 he_shortgi(dut, conn, ifname, "1.6");
11981 } else if (trig_gi_ltf == 2) {
11982 he_ltf(dut, conn, ifname, "12.8");
11983 he_shortgi(dut, conn, ifname, "3.2");
11984 } else {
11985 send_resp(dut, conn, SIGMA_ERROR,
11986 "errorCode,Unsupported Trig_ComInfo_GI-LTF");
11987 return STATUS_SENT_ERROR;
11988 }
11989 }
11990
11991 val = get_param(cmd, "Trig_ComInfo_BW");
11992 if (val) {
11993 int chwidth;
11994
11995 chwidth = atoi(val);
11996 /* Set the channel width */
11997 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
11998 }
11999
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070012000 val = get_param(cmd, "NumSS");
12001 if (val) {
12002 int i = 0;
12003 char *numss_val;
12004 char *saveptr;
12005
12006 num_ss = strdup(val);
12007 if (!num_ss)
12008 return ERROR_SEND_STATUS;
12009
12010 numss_val = strtok_r(num_ss, " ", &saveptr);
12011 for (i = 0; numss_val && i < 4; i++) {
12012 nss[i] = numss_val;
12013 numss_val = strtok_r(NULL, " ", &saveptr);
12014 }
12015 }
12016
12017 val = get_param(cmd, "NumSS_MAC");
12018 if (val) {
12019 char *sta_mac_str;
12020 char *saveptr;
12021 char *sta_mac_list_str;
12022
12023 sta_mac_list_str = strdup(val);
12024 if (!sta_mac_list_str) {
12025 free(num_ss);
12026 return ERROR_SEND_STATUS;
12027 }
12028
12029 sta_mac_str = strtok_r(sta_mac_list_str, " ", &saveptr);
12030 if (sta_mac_str && nss[0]) {
12031 run_system_wrapper(dut,
12032 "wifitool %s chmask_persta %s %s",
12033 ifname, sta_mac_str, nss[0]);
12034 }
12035
12036 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12037 if (sta_mac_str && nss[1]) {
12038 run_system_wrapper(dut,
12039 "wifitool %s chmask_persta %s %s",
12040 ifname, sta_mac_str, nss[1]);
12041 }
12042
12043 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12044 if (sta_mac_str && nss[2]) {
12045 run_system_wrapper(dut,
12046 "wifitool %s chmask_persta %s %s",
12047 ifname, sta_mac_str, nss[2]);
12048 }
12049
12050 sta_mac_str = strtok_r(NULL, " ", &saveptr);
12051 if (sta_mac_str && nss[3]) {
12052 run_system_wrapper(dut,
12053 "wifitool %s chmask_persta %s %s",
12054 ifname, sta_mac_str, nss[3]);
12055 }
12056
12057 free(sta_mac_list_str);
12058 }
12059
12060 free(num_ss);
12061 num_ss = NULL;
12062
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070012063 val = get_param(cmd, "AID");
12064 if (val) {
12065 int i = 0;
12066 char *aid_val;
12067 char *saveptr;
12068
12069 aid_ss = strdup(val);
12070 if (!aid_ss)
12071 return ERROR_SEND_STATUS;
12072
12073 aid_val = strtok_r(aid_ss, " ", &saveptr);
12074 for (i = 0; aid_val && i < 4; i++) {
12075 aid[i] = aid_val;
12076 aid_val = strtok_r(NULL, " ", &saveptr);
12077 }
12078 }
12079
12080 val = get_param(cmd, "AddbaReq");
12081 if (val) {
12082 if (strcasecmp(val, "enable") == 0) {
12083 run_iwpriv(dut, ifname, "setaddbaoper 1");
12084 run_system_wrapper(dut,
12085 "wifitool %s sendaddba %s 0 64",
12086 ifname, aid[0]);
12087 } else {
12088 send_resp(dut, conn, SIGMA_ERROR,
12089 "errorCode,Unsupported AddbaReq value");
12090 free(aid_ss);
12091 return STATUS_SENT_ERROR;
12092 }
12093 }
12094
12095 val = get_param(cmd, "AddbaResp");
12096 if (val) {
12097 if (aid_ss && strcasecmp(val, "accepted") == 0) {
12098 int aid_1 = atoi(aid_ss);
12099
12100 if (aid_1 == 1)
12101 aid_1 = 2;
12102 else
12103 aid_1 = aid_1 - 1;
12104
12105 /* There is no mechanism in place to reject Add BA Req
12106 * from all STAs and selectively accept Add BA Req from
12107 * a specified STA. Instead, it can accept Add BA Req
12108 * from all STAs and selectively reject from specified
12109 * STAs. Make changes for the same using the below
12110 * commands. */
12111 run_system_wrapper(dut, ifname, "setaddbaoper 1");
12112 run_system_wrapper(dut, "wifitool %s refusealladdbas 0",
12113 ifname);
12114 run_system_wrapper(dut,
12115 "wifitool %s setaddbaresp %d 0 37",
12116 ifname, aid_1);
12117 } else {
12118 send_resp(dut, conn, SIGMA_ERROR,
12119 "errorCode,Unsupported Addbaresp value");
12120 free(aid_ss);
12121 return STATUS_SENT_ERROR;
12122 }
12123 }
12124
12125 val = get_param(cmd, "Trig_UsrInfo_SSAlloc_RA-RU");
12126 if (val) {
12127 char *ssalloc_str;
12128 char *saveptr;
12129 char *ssalloc_list_str;
12130
12131 ssalloc_list_str = strdup(val);
12132 if (!ssalloc_list_str) {
12133 free(aid_ss);
12134 return ERROR_SEND_STATUS;
12135 }
12136
12137 ssalloc_str = strtok_r(ssalloc_list_str, ":", &saveptr);
12138 if (ssalloc_str && aid[0]) {
12139 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12140 ifname, aid[0], ssalloc_str);
12141 }
12142
12143 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12144 if (ssalloc_str && aid[1]) {
12145 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12146 ifname, aid[1], ssalloc_str);
12147 }
12148
12149 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12150 if (ssalloc_str && aid[2]) {
12151 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12152 ifname, aid[2], ssalloc_str);
12153 }
12154
12155 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12156 if (ssalloc_str && aid[3]) {
12157 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12158 ifname, aid[3], ssalloc_str);
12159 }
12160
12161 free(ssalloc_list_str);
12162 }
12163
12164 free(aid_ss);
12165 aid_ss = NULL;
12166
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070012167 val = get_param(cmd, "OMCtrl_RxNSS");
12168 if (val)
12169 omctrl_rxnss = atoi(val);
12170
12171 val = get_param(cmd, "OMCtrl_ChnlWidth");
12172 if (val)
12173 omctrl_chwidth = atoi(val);
12174
12175 val = get_param(cmd, "Client_mac");
12176 if (val) {
12177 if (parse_mac_address(dut, val, mac_addr) < 0) {
12178 send_resp(dut, conn, SIGMA_ERROR,
12179 "errorCode,MAC Address not in proper format");
12180 return STATUS_SENT_ERROR;
12181 }
12182
12183 /* setUnitTestCmd 13 7 1 mac3mac2mac1mac0 mac5mac4 <rx_nss>
12184 * <bw> <ulmu> <tx_nss> */
12185 run_system_wrapper(dut,
12186 "wifitool %s setUnitTestCmd 13 7 1 0x%02x%02x%02x%02x 0x%02x%02x %d %d 1 %d",
12187 ifname, mac_addr[3], mac_addr[2],
12188 mac_addr[1], mac_addr[0], mac_addr[5],
12189 mac_addr[4], omctrl_rxnss,
12190 omctrl_chwidth, omctrl_rxnss);
12191 }
12192
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070012193 val = get_param(cmd, "TriggerType");
12194 if (val) {
12195 trigtype = atoi(val);
12196 switch (trigtype) {
12197 case 0:
12198 ath_set_trigger_type_0(dut, ifname);
12199 break;
12200 case 1:
12201 ath_set_trigger_type_1(dut, ifname);
12202 break;
12203 case 2:
12204 ath_set_trigger_type_2(dut, ifname);
12205 break;
12206 case 3:
12207 ath_set_trigger_type_3(dut, ifname);
12208 break;
12209 case 4:
12210 ath_set_trigger_type_4(dut, ifname, basedev);
12211 break;
12212 default:
12213 send_resp(dut, conn, SIGMA_ERROR,
12214 "errorCode,TriggerType not supported");
12215 return STATUS_SENT_ERROR;
12216 }
12217 }
12218
Priyadharshini Gowthamanc352d822019-08-09 12:05:16 -070012219 val = get_param(cmd, "HE_TXOPDurRTSThr");
12220 if (val)
12221 run_iwpriv(dut, ifname, "he_rtsthrshld %d", atoi(val));
12222
12223 val = get_param(cmd, "NAV_Update");
12224 if (val) {
12225 if (strcasecmp(val, "disable") == 0) {
12226 run_iwpriv(dut, basedev, "nav_config 1 0");
12227 } else if (strcasecmp(val, "enable") == 0) {
12228 /* Do nothing */
12229 } else {
12230 send_resp(dut, conn, SIGMA_ERROR,
12231 "errorCode,Unsupported NAV update");
12232 return STATUS_SENT_ERROR;
12233 }
12234 }
12235
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070012236 /* Configure WMM Parameter Elements */
12237 val = get_param(cmd, "STA_WMMPE_ECWmin_BE");
12238 if (val) {
12239 param = atoi(val);
12240 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BE, param);
12241 }
12242
12243 val = get_param(cmd, "STA_WMMPE_ECWmin_BK");
12244 if (val) {
12245 param = atoi(val);
12246 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BK, param);
12247 }
12248
12249 val = get_param(cmd, "STA_WMMPE_ECWmin_VI");
12250 if (val) {
12251 param = atoi(val);
12252 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VI, param);
12253 }
12254
12255 val = get_param(cmd, "STA_WMMPE_ECWmin_VO");
12256 if (val) {
12257 param = atoi(val);
12258 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VO, param);
12259 }
12260
12261 val = get_param(cmd, "STA_WMMPE_ECWmax_BE");
12262 if (val) {
12263 param = atoi(val);
12264 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BE, param);
12265 }
12266
12267 val = get_param(cmd, "STA_WMMPE_ECWmax_BK");
12268 if (val) {
12269 param = atoi(val);
12270 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BK, param);
12271 }
12272
12273 val = get_param(cmd, "STA_WMMPE_ECWmax_VI");
12274 if (val) {
12275 param = atoi(val);
12276 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VI, param);
12277 }
12278
12279 val = get_param(cmd, "STA_WMMPE_ECWmax_VO");
12280 if (val) {
12281 param = atoi(val);
12282 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VO, param);
12283 }
12284
12285 val = get_param(cmd, "STA_WMMPE_AIFSN_BE");
12286 if (val) {
12287 param = atoi(val);
12288 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BE, param);
12289 }
12290
12291 val = get_param(cmd, "STA_WMMPE_AIFSN_BK");
12292 if (val) {
12293 param = atoi(val);
12294 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BK, param);
12295 }
12296
12297 val = get_param(cmd, "STA_WMMPE_AIFSN_VI");
12298 if (val) {
12299 param = atoi(val);
12300 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VI, param);
12301 }
12302
12303 val = get_param(cmd, "STA_WMMPE_AIFSN_VO");
12304 if (val) {
12305 param = atoi(val);
12306 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VO, param);
12307 }
12308
12309
12310 val = get_param(cmd, "STA_WMMPE_TXOP_BE");
12311 if (val) {
12312 param = atoi(val);
12313 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BE, param);
12314 }
12315
12316 val = get_param(cmd, "STA_WMMPE_TOXP_BK");
12317 if (val) {
12318 param = atoi(val);
12319 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BK, param);
12320 }
12321
12322 val = get_param(cmd, "STA_WMMPE_TXOP_VI");
12323 if (val) {
12324 param = atoi(val);
12325 run_iwpriv(dut, ifname, "txoplimit %d %d", AP_AC_VI, param);
12326 }
12327
12328 val = get_param(cmd, "STA_WMMPE_TXOP_VO");
12329 if (val) {
12330 param = atoi(val);
12331 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_VO, param);
12332 }
12333
Priyadharshini Gowthamanc46b7e42019-08-09 12:05:37 -070012334 /* Configure MU EDCA */
12335 val = get_param(cmd, "STA_MUEDCA_ECWmin_BE");
12336 if (val) {
12337 param = atoi(val);
12338 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BE, param);
12339 }
12340
12341 val = get_param(cmd, "STA_MUEDCA_ECWmin_BK");
12342 if (val) {
12343 param = atoi(val);
12344 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BK, param);
12345 }
12346
12347 val = get_param(cmd, "STA_MUEDCA_ECWmin_VI");
12348 if (val) {
12349 param = atoi(val);
12350 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VI, param);
12351 }
12352
12353 val = get_param(cmd, "STA_MUEDCA_ECWmin_VO");
12354 if (val) {
12355 param = atoi(val);
12356 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VO, param);
12357 }
12358
12359 val = get_param(cmd, "STA_MUEDCA_ECWmax_BE");
12360 if (val) {
12361 param = atoi(val);
12362 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BE, param);
12363 }
12364
12365 val = get_param(cmd, "STA_MUEDCA_ECWmax_BK");
12366 if (val) {
12367 param = atoi(val);
12368 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BK, param);
12369 }
12370
12371 val = get_param(cmd, "STA_MUEDCA_ECWmax_VI");
12372 if (val) {
12373 param = atoi(val);
12374 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VI, param);
12375 }
12376
12377 val = get_param(cmd, "STA_MUEDCA_ECWmax_VO");
12378 if (val) {
12379 param = atoi(val);
12380 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VO, param);
12381 }
12382
12383 val = get_param(cmd, "STA_MUEDCA_AIFSN_BE");
12384 if (val) {
12385 param = atoi(val);
12386 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BE, param);
12387 }
12388
12389 val = get_param(cmd, "STA_MUEDCA_AIFSN_BK");
12390 if (val) {
12391 param = atoi(val);
12392 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BK, param);
12393 }
12394
12395 val = get_param(cmd, "STA_MUEDCA_AIFSN_VI");
12396 if (val) {
12397 param = atoi(val);
12398 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VI, param);
12399 }
12400
12401 val = get_param(cmd, "STA_MUEDCA_AIFSN_VO");
12402 if (val) {
12403 param = atoi(val);
12404 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VO, param);
12405 }
12406
12407 val = get_param(cmd, "STA_MUEDCA_Timer_BE");
12408 if (val) {
12409 param = atoi(val);
12410 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BE, param);
12411 }
12412
12413 val = get_param(cmd, "STA_MUEDCA_Timer_BK");
12414 if (val) {
12415 param = atoi(val);
12416 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BK, param);
12417 }
12418
12419 val = get_param(cmd, "STA_MUEDCA_Timer_VI");
12420 if (val) {
12421 param = atoi(val);
12422 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VI, param);
12423 }
12424
12425 val = get_param(cmd, "STA_MUEDCA_Timer_VO");
12426 if (val) {
12427 param = atoi(val);
12428 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VO, param);
12429 }
12430
Jouni Malinen6076ffc2019-08-08 18:18:02 +030012431 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012432}
12433
12434
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012435static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12436 const char *val)
12437{
12438 char *token, *result;
12439 int channel = 36;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012440 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012441
12442 /* Extract the channel info */
12443 token = strdup(val);
12444 if (!token)
12445 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012446 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012447 if (result)
12448 channel = atoi(result);
12449
12450 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070012451 run_iwpriv(dut, ifname, "setChanChange %d", channel);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012452
12453 free(token);
12454 return 0;
12455}
12456
12457
bingsf532f9f2019-12-06 17:59:02 +080012458static enum sigma_cmd_result wcn_ap_set_rfeature(struct sigma_dut *dut,
12459 struct sigma_conn *conn,
12460 struct sigma_cmd *cmd)
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012461{
12462 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012463 const char *ifname;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012464
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012465 ifname = get_main_ifname(dut);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012466
12467 val = get_param(cmd, "chnum_band");
12468 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
bingsf532f9f2019-12-06 17:59:02 +080012469 return ERROR_SEND_STATUS;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012470
bingseca3c192019-12-06 17:59:02 +080012471 val = get_param(cmd, "txBandwidth");
12472 if (val) {
12473 int old_ch_bw = dut->ap_chwidth;
12474
12475 if (strcasecmp(val, "Auto") == 0) {
12476 dut->ap_chwidth = 0;
12477 } else if (strcasecmp(val, "20") == 0) {
12478 dut->ap_chwidth = 0;
12479 } else if (strcasecmp(val, "40") == 0) {
12480 dut->ap_chwidth = 1;
12481 } else if (strcasecmp(val, "80") == 0) {
12482 dut->ap_chwidth = 2;
12483 } else if (strcasecmp(val, "160") == 0) {
12484 dut->ap_chwidth = 3;
12485 } else {
12486 send_resp(dut, conn, SIGMA_ERROR,
12487 "ErrorCode,WIDTH not supported");
12488 return STATUS_SENT_ERROR;
12489 }
12490 if (old_ch_bw != dut->ap_chwidth) {
12491 if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
12492 return STATUS_SENT_ERROR;
12493 } else {
12494 sigma_dut_print(dut, DUT_MSG_DEBUG, "No change in BW");
12495 }
12496 }
12497
bingsf276b822019-12-06 18:29:49 +080012498 val = get_param(cmd, "GI");
12499 if (val) {
12500 int fix_rate_sgi;
12501
12502 if (strcmp(val, "0.8") == 0) {
12503 run_iwpriv(dut, ifname, "enable_short_gi 9");
12504 fix_rate_sgi = 1;
12505 } else if (strcmp(val, "1.6") == 0) {
12506 run_iwpriv(dut, ifname, "enable_short_gi 10");
12507 fix_rate_sgi = 2;
12508 } else if (strcmp(val, "3.2") == 0) {
12509 run_iwpriv(dut, ifname, "enable_short_gi 11");
12510 fix_rate_sgi = 3;
12511 } else {
12512 send_resp(dut, conn, SIGMA_ERROR,
12513 "errorCode,GI value not supported");
12514 return STATUS_SENT_ERROR;
12515 }
12516 run_iwpriv(dut, ifname, "enable_short_gi %d", fix_rate_sgi);
12517 }
12518
Kiran Kumar Lokereff979472020-01-22 11:15:59 -080012519 val = get_param(cmd, "LTF");
12520 if (val) {
12521#ifdef NL80211_SUPPORT
12522 if (strcmp(val, "3.2") == 0) {
12523 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_1X);
12524 } if (strcmp(val, "6.4") == 0) {
12525 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_2X);
12526 } else if (strcmp(val, "12.8") == 0) {
12527 wcn_set_he_ltf(dut, ifname, QCA_WLAN_HE_LTF_4X);
12528 } else {
12529 send_resp(dut, conn, SIGMA_ERROR,
12530 "errorCode,LTF value not supported");
12531 return STATUS_SENT;
12532 }
12533#else /* NL80211_SUPPORT */
12534 sigma_dut_print(dut, DUT_MSG_ERROR,
12535 "LTF cannot be set without NL80211_SUPPORT defined");
12536 return ERROR_SEND_STATUS;
12537#endif /* NL80211_SUPPORT */
12538 }
12539
bingsf532f9f2019-12-06 17:59:02 +080012540 return SUCCESS_SEND_STATUS;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012541}
12542
12543
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012544static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12545 const char *val)
12546{
12547 char *token, *result;
12548 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
12549 channel_freq;
12550 char buf[100];
12551 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012552 int res;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012553
12554 /* Extract the channel info */
12555 token = strdup(val);
12556 if (!token)
12557 return -1;
12558 result = strtok_r(token, ";", &saveptr);
12559 if (result)
12560 channel = atoi(result);
12561
12562 /* Extract the channel width info */
12563 result = strtok_r(NULL, ";", &saveptr);
12564 if (result)
12565 chwidth = atoi(result);
12566
12567 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
12568 if (center_freq_idx < 0) {
12569 free(token);
12570 return -1;
12571 }
12572
12573 center_freq = get_5g_channel_freq(center_freq_idx);
12574 channel_freq = get_5g_channel_freq(channel);
12575
12576 /* Issue the channel switch command */
Jouni Malinen3aa72862019-05-29 23:14:51 +030012577 res = snprintf(buf, sizeof(buf),
12578 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
12579 ifname, channel_freq, center_freq, chwidth);
12580 if (res < 0 || res >= sizeof(buf) || run_hostapd_cli(dut, buf) != 0) {
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012581 sigma_dut_print(dut, DUT_MSG_ERROR,
12582 "hostapd_cli chan_switch failed");
12583 }
12584
12585 free(token);
12586 return 0;
12587}
12588
12589
12590static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
12591 struct sigma_conn *conn,
12592 struct sigma_cmd *cmd)
12593{
12594 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012595 const char *ifname;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012596
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012597 ifname = get_main_ifname(dut);
Tamizh chelvam638fb472019-08-15 14:00:31 +053012598
12599 val = get_param(cmd, "RTS_FORCE");
12600 if (val)
12601 mac80211_config_rts_force(dut, ifname, val);
12602
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012603 val = get_param(cmd, "chnum_band");
12604 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
12605 return -1;
12606
12607 return 1;
12608}
12609
12610
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012611#ifdef __linux__
12612static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
12613 struct sigma_conn *conn,
12614 struct sigma_cmd *cmd)
12615{
12616 const char *val;
12617
12618 val = get_param(cmd, "ExtSchIE");
12619 if (val && !strcasecmp(val, "Enable")) {
12620 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12621 int count = MAX_ESE_ALLOCS;
12622
12623 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12624 return -1;
12625 if (wil6210_set_ese(dut, count, allocs))
12626 return -1;
12627 return 1;
12628 }
12629
12630 send_resp(dut, conn, SIGMA_ERROR,
12631 "errorCode,Invalid ap_set_rfeature(60G)");
12632 return 0;
12633}
12634#endif /* __linux__ */
12635
12636
Jouni Malinenf7222712019-06-13 01:50:21 +030012637static enum sigma_cmd_result cmd_ap_set_rfeature(struct sigma_dut *dut,
12638 struct sigma_conn *conn,
12639 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012640{
12641 /* const char *name = get_param(cmd, "NAME"); */
12642 /* const char *type = get_param(cmd, "Type"); */
12643
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012644 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012645 case DRIVER_ATHEROS:
12646 return ath_ap_set_rfeature(dut, conn, cmd);
12647 case DRIVER_OPENWRT:
12648 switch (get_openwrt_driver_type()) {
12649 case OPENWRT_DRIVER_ATHEROS:
12650 return ath_ap_set_rfeature(dut, conn, cmd);
12651 default:
12652 send_resp(dut, conn, SIGMA_ERROR,
12653 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
12654 return 0;
12655 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053012656 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012657 case DRIVER_WCN:
12658 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012659 case DRIVER_MAC80211:
12660 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012661#ifdef __linux__
12662 case DRIVER_WIL6210:
12663 return wil6210_ap_set_rfeature(dut, conn, cmd);
12664#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012665 default:
12666 send_resp(dut, conn, SIGMA_ERROR,
12667 "errorCode,Unsupported ap_set_rfeature with the current driver");
12668 return 0;
12669 }
12670}
12671
12672
Jouni Malinenf7222712019-06-13 01:50:21 +030012673static enum sigma_cmd_result cmd_accesspoint(struct sigma_dut *dut,
12674 struct sigma_conn *conn,
12675 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012676{
12677 /* const char *name = get_param(cmd, "NAME"); */
12678 return 1;
12679}
12680
12681
Jouni Malinenf7222712019-06-13 01:50:21 +030012682static enum sigma_cmd_result
12683cmd_ap_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
12684 struct sigma_cmd *cmd)
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012685{
12686 const char *val;
12687
12688 val = get_param(cmd, "Oper_Chn");
12689 if (val) {
12690 dut->ap_oper_chn = 1;
12691 dut->ap_channel = atoi(val);
12692 }
12693
Jouni Malinenba4f2d42019-10-04 16:13:41 +030012694 val = get_param(cmd, "DPPConfiguratorAddress");
12695 if (val) {
12696 free(dut->ap_dpp_conf_addr);
12697 dut->ap_dpp_conf_addr = strdup(val);
12698 }
12699
12700 val = get_param(cmd, "DPPConfiguratorPKHash");
12701 if (val) {
12702 free(dut->ap_dpp_conf_pkhash);
12703 dut->ap_dpp_conf_pkhash = strdup(val);
12704 }
12705
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012706 return 1;
12707}
12708
12709
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012710void ap_register_cmds(void)
12711{
12712 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
12713 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
12714 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
12715 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
12716 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
12717 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053012718 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012719 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
12720 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
12721 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
12722 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
12723 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
12724 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
12725 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
12726 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
12727 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
12728 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
12729 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
12730 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
12731 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
12732 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
12733 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
12734 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020012735 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
12736 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020012737 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012738 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012739 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
12740 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012741}