blob: da34bb2052628f71f1fdc3dc06b26134bb16ab3f [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
Tamizh chelvam638fb472019-08-15 14:00:31 +0530278static void mac80211_config_rts_force(struct sigma_dut *dut, const char *ifname,
279 const char *val)
280{
281 char buf[60];
282 char fname[128], path[128], *pos;
283 ssize_t res;
284
285 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
286 ifname);
287 if (res < 0 || res >= sizeof(fname))
288 return;
289
290 res = readlink(fname, path, sizeof(path));
291 if (res < 0)
292 return;
293
294 if (res >= (int) sizeof(path))
295 res = sizeof(path) - 1;
296 path[res] = '\0';
297
298 pos = strrchr(path, '/');
299 if (!pos)
300 pos = path;
301 else
302 pos++;
303
304 if (strcasecmp(val, "enable") == 0) {
305 dut->ap_sig_rts = VALUE_ENABLED;
306 snprintf(buf, sizeof(buf), "iw %s set rts 64", pos);
307 if (system(buf) != 0) {
308 sigma_dut_print(dut, DUT_MSG_ERROR,
309 "iw set rts 64 failed");
310 }
311 } else if (strcasecmp(val, "disable") == 0) {
312 dut->ap_sig_rts = VALUE_DISABLED;
313 snprintf(buf, sizeof(buf), "iw %s set rts 2347", pos);
314 if (system(buf) != 0) {
315 sigma_dut_print(dut, DUT_MSG_ERROR,
316 "iw rts 2347 failed");
317 }
318 } else {
319 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
320 }
321
322}
323
324
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200325static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
326 const char *val)
327{
328 char buf[60];
329
330 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200331 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200332 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
333 if (system(buf) != 0) {
334 sigma_dut_print(dut, DUT_MSG_ERROR,
335 "iwconfig rts 64 failed");
336 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800337 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
338 ifname);
339 if (system(buf) != 0) {
340 sigma_dut_print(dut, DUT_MSG_ERROR,
341 "wifitool beeliner_fw_test 100 1 failed");
342 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200343 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200344 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200345 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
346 if (system(buf) != 0) {
347 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700348 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200349 }
350 } else {
351 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
352 }
353}
354
355
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800356static void ath_radio(struct sigma_dut *dut, const char *val)
357{
358 if (strcasecmp(val, "on") == 0) {
359 if (dut->ap_interface_5g == 1) {
360 run_system(dut, "uci set wireless.wifi0.disabled=0");
361 } else if (dut->ap_interface_2g == 1) {
362 run_system(dut, "uci set wireless.wifi1.disabled=0");
363 } else {
364 run_system(dut, "uci set wireless.wifi0.disabled=0");
365 run_system(dut, "uci set wireless.wifi1.disabled=0");
366 }
367 run_system(dut, "uci commit");
368 run_system(dut, "wifi down");
369 run_system(dut, "wifi up");
370 } else if (strcasecmp(val, "off") == 0) {
371 if (dut->ap_interface_5g == 1) {
372 run_system(dut, "uci set wireless.wifi0.disabled=1");
373 } else if (dut->ap_interface_2g == 1) {
374 run_system(dut, "uci set wireless.wifi1.disabled=1");
375 } else {
376 run_system(dut, "uci set wireless.wifi0.disabled=1");
377 run_system(dut, "uci set wireless.wifi1.disabled=1");
378 }
379 run_system(dut, "uci commit");
380 run_system(dut, "wifi down");
381 run_system(dut, "wifi up");
382 }
383}
384
385
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800386static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
387 const char *val)
388{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700389 if (strcasecmp(val, "disable") == 0)
390 run_iwpriv(dut, ifname, "stealthdown 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800391}
392
393
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800394static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
395 const char *val)
396{
397 char buf[60];
398
399 if (strcasecmp(val, "high") == 0)
400 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
401 else if (strcasecmp(val, "low") == 0)
402 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
403 else
404 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
405
406 if (system(buf) != 0)
407 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
408}
409
410
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200411static enum ap_mode get_mode(const char *str)
412{
413 if (strcasecmp(str, "11a") == 0)
414 return AP_11a;
415 else if (strcasecmp(str, "11g") == 0)
416 return AP_11g;
417 else if (strcasecmp(str, "11b") == 0)
418 return AP_11b;
419 else if (strcasecmp(str, "11na") == 0)
420 return AP_11na;
421 else if (strcasecmp(str, "11ng") == 0)
422 return AP_11ng;
423 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
424 return AP_11ac;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200425 else if (strcasecmp(str, "11ad") == 0)
426 return AP_11ad;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -0800427 else if (strcasecmp(str, "11ax") == 0)
428 return AP_11ax;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200429 else
430 return AP_inval;
431}
432
433
434static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
435{
436 char command[1000];
437 const char *bin;
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200438 enum driver_type drv = get_driver_type(dut);
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700439 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200440
441 if (file_exists("hostapd_cli"))
442 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300443 else if (file_exists("../../hostapd/hostapd_cli"))
444 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200445 else
446 bin = "hostapd_cli";
447
448 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700449 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200450
451 if (sigma_radio_ifname[0] &&
452 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700453 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200454 else if (sigma_radio_ifname[0] &&
455 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700456 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200457 }
458
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700459 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200460 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700461 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200462 else
463 snprintf(command, sizeof(command), "%s %s", bin, buf);
464 return run_system(dut, command);
465}
466
467
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700468static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
469 struct sigma_cmd *cmd)
470{
471 FILE *f;
472 int i;
473
474 f = fopen("/tmp/lci_cfg.txt", "w");
475 if (!f) {
476 sigma_dut_print(dut, DUT_MSG_ERROR,
477 "Failed to open /tmp/lci_cfg.txt");
478 return -1;
479 }
480
481 for (i = 2; i < cmd->count; i++)
482 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
483 fprintf(f, "\n");
484 fclose(f);
485
486 return 0;
487}
488
489
hangtian00606622019-04-19 11:15:48 +0800490static void set_ap_country_code(struct sigma_dut *dut)
491{
492#if defined(ANDROID) || defined(LINUX_EMBEDDED)
493 char buf[256];
494
495 if (dut->ap_countrycode[0]) {
496 snprintf(buf, sizeof(buf), "DRIVER COUNTRY %s",
497 dut->ap_countrycode);
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200498 if (wpa_command(get_station_ifname(dut), buf) < 0)
hangtian00606622019-04-19 11:15:48 +0800499 sigma_dut_print(dut, DUT_MSG_ERROR,
500 "Failed to set country code");
501 else
502 sigma_dut_print(dut, DUT_MSG_INFO,
503 "Successfully set country code to %s",
504 dut->ap_countrycode);
505 }
506#endif
507}
508
509
Priyadharshini Gowthamane661f3b2019-11-13 16:24:29 -0800510static void set_vht_mcsmap_nss(struct sigma_dut *dut, int nss, int mcs)
511{
512 switch (nss) {
513 case 1:
514 switch (mcs) {
515 case 7:
516 dut->ap_vhtmcs_map = 0xfffc;
517 break;
518 case 8:
519 dut->ap_vhtmcs_map = 0xfffd;
520 break;
521 case 9:
522 dut->ap_vhtmcs_map = 0xfffe;
523 break;
524 default:
525 dut->ap_vhtmcs_map = 0xfffe;
526 break;
527 }
528 break;
529 case 2:
530 switch (mcs) {
531 case 7:
532 dut->ap_vhtmcs_map = 0xfff0;
533 break;
534 case 8:
535 dut->ap_vhtmcs_map = 0xfff5;
536 break;
537 case 9:
538 dut->ap_vhtmcs_map = 0xfffa;
539 break;
540 default:
541 dut->ap_vhtmcs_map = 0xfffa;
542 break;
543 }
544 break;
545 case 3:
546 switch (mcs) {
547 case 7:
548 dut->ap_vhtmcs_map = 0xffc0;
549 break;
550 case 8:
551 dut->ap_vhtmcs_map = 0xffd5;
552 break;
553 case 9:
554 dut->ap_vhtmcs_map = 0xffea;
555 break;
556 default:
557 dut->ap_vhtmcs_map = 0xffea;
558 break;
559 }
560 default:
561 dut->ap_vhtmcs_map = 0xffea;
562 break;
563 }
564}
565
566
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -0800567/* Get 2*nss bitmask */
568/* We are trying to pack 2-bit MCS values per NSS in a 16-bit wide field.
569 * IEEE P802.11ax/D5.0, 9.4.2.247.4 supported HE-MCS And NSS Set field
570 * defines the following format for the 16 bit value. */
571
572#define HE_GET_MCS_NSS_PACK_MASK(nss) ((1 << ((nss) << 1)) - 1)
573
574static void he_reset_mcs_values_for_unsupported_ss(uint8_t *mcsnssmap,
575 uint8_t nss)
576{
577 uint8_t nssmask;
578
579 if (nss <= 4) {
580 nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss);
581 mcsnssmap[0] |= nssmask;
582 mcsnssmap[1] = 0xff;
583 } else if (nss > 4 && nss <= 8) {
584 nssmask = ~HE_GET_MCS_NSS_PACK_MASK(nss - 4);
585 mcsnssmap[0] &= 0xff;
586 mcsnssmap[1] |= nssmask;
587 }
588}
589
590
591static void get_he_mcs_nssmap(uint8_t *mcsnssmap, uint8_t nss,
592 uint8_t mcs)
593{
594 switch (mcs) {
595 case 11:
596 mcsnssmap[0] = 0xaa;
597 mcsnssmap[1] = 0xaa;
598 break;
599 case 9:
600 mcsnssmap[0] = 0x55;
601 mcsnssmap[1] = 0x55;
602 break;
603 case 7:
604 mcsnssmap[0] = 0x0;
605 mcsnssmap[1] = 0x0;
606 break;
607 }
608 he_reset_mcs_values_for_unsupported_ss(mcsnssmap, nss);
609}
610
611
Jouni Malinenf7222712019-06-13 01:50:21 +0300612static enum sigma_cmd_result cmd_ap_set_wireless(struct sigma_dut *dut,
613 struct sigma_conn *conn,
614 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200615{
616 /* const char *name = get_param(cmd, "NAME"); */
617 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200618 const char *val;
619 unsigned int wlan_tag = 1;
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200620 const char *ifname = get_main_ifname(dut);
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +0200621 char buf[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200622
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200623 /* Allow program to be overridden if specified in the ap_set_wireless
624 * to support some 60 GHz test scripts where the program may be 60 GHz
625 * or WPS. */
626 val = get_param(cmd, "PROGRAM");
627 if (val)
628 dut->program = sigma_program_to_enum(val);
629
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200630 val = get_param(cmd, "WLAN_TAG");
631 if (val) {
632 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700633 if (wlan_tag < 1 || wlan_tag > 3) {
634 /*
635 * The only valid WLAN Tags as of now as per the latest
636 * WFA scripts are 1, 2, and 3.
637 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200638 send_resp(dut, conn, SIGMA_INVALID,
639 "errorCode,Invalid WLAN_TAG");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200640 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200641 }
642 }
643
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800644 val = get_param(cmd, "Interface");
645 if (val) {
646 if (strcasecmp(val, "5G") == 0)
647 dut->ap_interface_5g = 1;
648 else
649 dut->ap_interface_2g = 1;
650
651 if (dut->ap_interface_5g && dut->ap_interface_2g)
652 dut->ap_is_dual = 1;
653 }
654
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200655 val = get_param(cmd, "CountryCode");
656 if (val) {
657 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200658 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200659 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
660 "%s", val);
hangtian00606622019-04-19 11:15:48 +0800661
662 /*
663 * Regdomain self-managed driver does not accept hostapd country
664 * code setting in all cases. Try to use wpa_supplicant DRIVER
665 * command first to set the driver to a specific country code
666 * before starting AP functionality. This is targeting cases
667 * where wpa_supplicant is running on the device as well for
668 * non-AP mode functionality.
669 */
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200670 if (get_driver_type(dut) == DRIVER_LINUX_WCN)
hangtian00606622019-04-19 11:15:48 +0800671 set_ap_country_code(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200672 }
673
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530674 val = get_param(cmd, "regulatory_mode");
675 if (val) {
676 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
677 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
678 }
679
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200680 val = get_param(cmd, "SSID");
681 if (val) {
682 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200683 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200684
685 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700686 /*
687 * If tag is not specified, it is deemed to be 1.
688 * Hence tag of 1 is a special case and the values
689 * corresponding to wlan-tag=1 are stored separately
690 * from the values corresponding tags 2 and 3.
691 * This approach minimises the changes to existing code
692 * since most of the sigma_dut code does not deal with
693 * WLAN-TAG CAPI variable.
694 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200695 snprintf(dut->ap_ssid,
696 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700697 } else {
698 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
699 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
700 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200701 }
702 }
703
704 val = get_param(cmd, "CHANNEL");
705 if (val) {
706 const char *pos;
707 dut->ap_channel = atoi(val);
708 pos = strchr(val, ';');
709 if (pos) {
710 pos++;
711 dut->ap_channel_1 = atoi(pos);
712 }
713 }
714
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530715 /* Overwrite the AP channel with DFS channel if configured */
716 val = get_param(cmd, "dfs_chan");
717 if (val) {
718 dut->ap_channel = atoi(val);
719 }
720
721 val = get_param(cmd, "dfs_mode");
722 if (val) {
723 if (strcasecmp(val, "Enable") == 0)
724 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
725 else if (strcasecmp(val, "Disable") == 0)
726 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
727 else
728 sigma_dut_print(dut, DUT_MSG_ERROR,
729 "Unsupported dfs_mode value: %s", val);
730 }
731
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200732 val = get_param(cmd, "MODE");
733 if (val) {
734 char *str, *pos;
735
736 str = strdup(val);
737 if (str == NULL)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200738 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200739 pos = strchr(str, ';');
740 if (pos)
741 *pos++ = '\0';
742
743 dut->ap_is_dual = 0;
744 dut->ap_mode = get_mode(str);
745 if (dut->ap_mode == AP_inval) {
746 send_resp(dut, conn, SIGMA_INVALID,
747 "errorCode,Unsupported MODE");
748 free(str);
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200749 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200750 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800751 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200752 dut->ap_chwidth = AP_80;
753
754 if (pos) {
755 dut->ap_mode_1 = get_mode(pos);
756 if (dut->ap_mode_1 == AP_inval) {
757 send_resp(dut, conn, SIGMA_INVALID,
758 "errorCode,Unsupported MODE");
759 free(str);
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200760 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200761 }
762 if (dut->ap_mode_1 == AP_11ac)
763 dut->ap_chwidth_1 = AP_80;
764 dut->ap_is_dual = 1;
765 }
766
767 free(str);
768 } else if (dut->ap_mode == AP_inval) {
769 if (dut->ap_channel <= 11)
770 dut->ap_mode = AP_11ng;
771 else if (dut->program == PROGRAM_VHT)
772 dut->ap_mode = AP_11ac;
773 else
774 dut->ap_mode = AP_11na;
775 }
776
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200777 /* Override the AP mode in case of 60 GHz */
778 if (dut->program == PROGRAM_60GHZ) {
779 dut->ap_mode = AP_11ad;
780 /* Workaround to force channel 2 if not specified */
781 if (!dut->ap_channel)
782 dut->ap_channel = 2;
783 }
784
Jouni Malinen00535472019-11-06 19:43:35 +0200785 switch (dut->ap_mode) {
786 case AP_11g:
787 case AP_11b:
788 case AP_11ng:
789 dut->use_5g = 0;
790 break;
791 case AP_11a:
792 case AP_11na:
793 case AP_11ac:
794 dut->use_5g = 1;
795 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -0800796 case AP_11ax:
797 if (dut->ap_channel >= 1 && dut->ap_channel <= 14)
798 dut->use_5g = 0;
799 else if (dut->ap_channel >= 36 && dut->ap_channel <= 171)
800 dut->use_5g = 1;
801 break;
Jouni Malinen00535472019-11-06 19:43:35 +0200802 case AP_11ad:
803 case AP_inval:
804 break;
805 }
806
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530807 val = get_param(cmd, "WME");
808 if (val) {
809 if (strcasecmp(val, "on") == 0)
810 dut->ap_wme = AP_WME_ON;
811 else if (strcasecmp(val, "off") == 0)
812 dut->ap_wme = AP_WME_OFF;
813 else
814 sigma_dut_print(dut, DUT_MSG_ERROR,
815 "Unsupported WME value: %s", val);
816 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200817
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530818 val = get_param(cmd, "WMMPS");
819 if (val) {
820 if (strcasecmp(val, "on") == 0)
821 dut->ap_wmmps = AP_WMMPS_ON;
822 else if (strcasecmp(val, "off") == 0)
823 dut->ap_wmmps = AP_WMMPS_OFF;
824 else
825 sigma_dut_print(dut, DUT_MSG_ERROR,
826 "Unsupported WMMPS value: %s", val);
827 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200828
829 val = get_param(cmd, "RTS");
830 if (val)
831 dut->ap_rts = atoi(val);
832
833 val = get_param(cmd, "FRGMNT");
834 if (val)
835 dut->ap_frgmnt = atoi(val);
836
837 /* TODO: PWRSAVE */
838
839 val = get_param(cmd, "BCNINT");
840 if (val)
841 dut->ap_bcnint = atoi(val);
842
843 val = get_param(cmd, "RADIO");
844 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200845 enum driver_type drv = get_driver_type(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530846
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200847 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800848 if (drv == DRIVER_OPENWRT)
849 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200850 if (drv == DRIVER_ATHEROS)
851 ath_ap_start_hostapd(dut);
852 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200853 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200854 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530855 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800856 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300857 } else if (dut->use_hostapd_pid_file) {
858 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530859 } else if (kill_process(dut, "(hostapd)", 1,
860 SIGTERM) == 0 ||
861 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200862 sigma_dut_print(dut, DUT_MSG_INFO,
863 "Killed hostapd on radio,off");
864 }
865 } else {
866 send_resp(dut, conn, SIGMA_INVALID,
867 "errorCode,Unsupported RADIO value");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200868 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200869 }
870 }
871
872 val = get_param(cmd, "P2PMgmtBit");
873 if (val)
874 dut->ap_p2p_mgmt = atoi(val);
875
876 /* TODO: ChannelUsage */
877
878 /* TODO: 40_INTOLERANT */
879
880 val = get_param(cmd, "ADDBA_REJECT");
881 if (val) {
882 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200883 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200884 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200885 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200886 }
887
888 val = get_param(cmd, "AMPDU");
889 if (val) {
890 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200891 dut->ap_ampdu = 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_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200894 }
895
896 val = get_param(cmd, "AMPDU_EXP");
897 if (val)
898 dut->ap_ampdu_exp = atoi(val);
899
900 val = get_param(cmd, "AMSDU");
901 if (val) {
902 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200903 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200904 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200905 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200906 }
907
908 val = get_param(cmd, "NoAck");
909 if (val) {
910 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200911 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200912 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200913 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200914 }
915
916 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200917 /* TODO: MCS_32 */
918
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530919 val = get_param(cmd, "OFFSET");
920 if (val) {
921 if (strcasecmp(val, "Above") == 0)
922 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
923 else if (strcasecmp(val, "Below") == 0)
924 dut->ap_chwidth_offset = SEC_CH_40BELOW;
925 }
926
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200927 val = get_param(cmd, "MCS_FIXEDRATE");
928 if (val) {
929 dut->ap_fixed_rate = 1;
930 dut->ap_mcs = atoi(val);
931 }
932
933 val = get_param(cmd, "SPATIAL_RX_STREAM");
934 if (val) {
935 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
936 dut->ap_rx_streams = 1;
937 if (dut->device_type == AP_testbed)
938 dut->ap_vhtmcs_map = 0xfffc;
939 } else if (strcasecmp(val, "2SS") == 0 ||
940 strcasecmp(val, "2") == 0) {
941 dut->ap_rx_streams = 2;
942 if (dut->device_type == AP_testbed)
943 dut->ap_vhtmcs_map = 0xfff0;
944 } else if (strcasecmp(val, "3SS") == 0 ||
945 strcasecmp(val, "3") == 0) {
946 dut->ap_rx_streams = 3;
947 if (dut->device_type == AP_testbed)
948 dut->ap_vhtmcs_map = 0xffc0;
949 } else if (strcasecmp(val, "4SS") == 0 ||
950 strcasecmp(val, "4") == 0) {
951 dut->ap_rx_streams = 4;
952 }
953 }
954
955 val = get_param(cmd, "SPATIAL_TX_STREAM");
956 if (val) {
957 if (strcasecmp(val, "1SS") == 0 ||
958 strcasecmp(val, "1") == 0) {
959 dut->ap_tx_streams = 1;
960 if (dut->device_type == AP_testbed)
961 dut->ap_vhtmcs_map = 0xfffc;
962 } else if (strcasecmp(val, "2SS") == 0 ||
963 strcasecmp(val, "2") == 0) {
964 dut->ap_tx_streams = 2;
965 if (dut->device_type == AP_testbed)
966 dut->ap_vhtmcs_map = 0xfff0;
967 } else if (strcasecmp(val, "3SS") == 0 ||
968 strcasecmp(val, "3") == 0) {
969 dut->ap_tx_streams = 3;
970 if (dut->device_type == AP_testbed)
971 dut->ap_vhtmcs_map = 0xffc0;
972 } else if (strcasecmp(val, "4SS") == 0 ||
973 strcasecmp(val, "4") == 0) {
974 dut->ap_tx_streams = 4;
975 }
976 }
977
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700978 val = get_param(cmd, "BSS_max_idle");
979 if (val) {
980 if (strncasecmp(val, "Enable", 7) == 0) {
981 dut->wnm_bss_max_feature = VALUE_ENABLED;
982 } else if (strncasecmp(val, "Disable", 8) == 0) {
983 dut->wnm_bss_max_feature = VALUE_DISABLED;
984 } else {
985 send_resp(dut, conn, SIGMA_ERROR,
986 "errorCode,Invalid value for BSS_max_Feature");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200987 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700988 }
989 }
990
991 val = get_param(cmd, "BSS_Idle_Protection_options");
992 if (val) {
993 int protection = (int) strtol(val, (char **) NULL, 10);
994
995 if (protection != 1 && protection != 0) {
996 send_resp(dut, conn, SIGMA_ERROR,
997 "errorCode,Invalid value for BSS_Idle_Protection_options");
Jouni Malinendccfd0c2019-10-30 12:05:59 +0200998 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700999 }
1000 dut->wnm_bss_max_protection = protection ?
1001 VALUE_ENABLED : VALUE_DISABLED;
1002 }
1003
1004 val = get_param(cmd, "BSS_max_Idle_period");
1005 if (val) {
Jouni Malinen544edf02019-02-25 19:02:33 +02001006 long int idle_time = strtol(val, (char **) NULL, 10);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001007
1008 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
1009 send_resp(dut, conn, SIGMA_ERROR,
1010 "errorCode,Invalid value for BSS_max_Idle_period");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001011 return STATUS_SENT;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001012 }
Jouni Malinen544edf02019-02-25 19:02:33 +02001013 dut->wnm_bss_max_idle_time = (int) idle_time;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07001014 }
1015
1016 val = get_param(cmd, "PROXY_ARP");
1017 if (val)
1018 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
1019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001020 val = get_param(cmd, "nss_mcs_cap");
1021 if (val) {
1022 int nss, mcs;
1023 char token[20];
1024 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301025 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001026
1027 if (strlen(val) >= sizeof(token))
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001028 return INVALID_SEND_STATUS;
Jouni Malinen947fdf62017-05-14 22:29:32 +03001029 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301030 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301031 if (!result) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001032 send_resp(dut, conn, SIGMA_ERROR,
1033 "errorCode,VHT NSS not specified");
1034 return STATUS_SENT;
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301035 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001036 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301037 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001038 if (result == NULL) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001039 send_resp(dut, conn, SIGMA_ERROR,
1040 "errorCode,VHTMCS not specified");
1041 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001042 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05301043 result = strtok_r(result, "-", &saveptr);
1044 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301045 if (!result) {
Jouni Malinen9aa4b372019-10-30 12:08:15 +02001046 send_resp(dut, conn, SIGMA_ERROR,
1047 "errorCode,VHT MCS not specified");
1048 return STATUS_SENT;
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05301049 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001050 mcs = atoi(result);
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08001051 if (dut->program == PROGRAM_HE) {
1052 uint16_t mcsnssmap = 0;
1053
1054 get_he_mcs_nssmap((uint8_t *) &mcsnssmap, nss, mcs);
1055 dut->he_mcsnssmap = (mcsnssmap << 16) | mcsnssmap;
1056 dut->he_ul_mcs = mcs;
1057 } else {
1058 set_vht_mcsmap_nss(dut, nss, mcs);
1059 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001060 }
1061
1062 /* TODO: MPDU_MIN_START_SPACING */
1063 /* TODO: RIFS_TEST */
1064 /* TODO: SGI20 */
1065
1066 val = get_param(cmd, "STBC_TX");
1067 if (val)
1068 dut->ap_tx_stbc = atoi(val);
1069
1070 val = get_param(cmd, "WIDTH");
1071 if (val) {
1072 if (strcasecmp(val, "20") == 0)
1073 dut->ap_chwidth = AP_20;
1074 else if (strcasecmp(val, "40") == 0)
1075 dut->ap_chwidth = AP_40;
1076 else if (strcasecmp(val, "80") == 0)
1077 dut->ap_chwidth = AP_80;
1078 else if (strcasecmp(val, "160") == 0)
1079 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08001080 else if (strcasecmp(val, "80plus80") == 0) {
1081 dut->ap_80plus80 = 1;
1082 dut->ap_chwidth = AP_80_80;
1083 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001084 dut->ap_chwidth = AP_AUTO;
1085 else {
1086 send_resp(dut, conn, SIGMA_INVALID,
1087 "errorCode,Unsupported WIDTH");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001088 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001089 }
1090 }
1091
1092 /* TODO: WIDTH_SCAN */
1093
1094 val = get_param(cmd, "TDLSProhibit");
1095 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
1096 val = get_param(cmd, "TDLSChswitchProhibit");
1097 dut->ap_tdls_prohibit_chswitch =
1098 val && strcasecmp(val, "Enabled") == 0;
1099 val = get_param(cmd, "HS2");
1100 if (val && wlan_tag == 1)
1101 dut->ap_hs2 = atoi(val);
1102 val = get_param(cmd, "P2P_CROSS_CONNECT");
1103 if (val)
1104 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
1105
1106 val = get_param(cmd, "FakePubKey");
1107 dut->ap_fake_pkhash = val && atoi(val);
1108
1109 val = get_param(cmd, "vht_tkip");
1110 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
1111 val = get_param(cmd, "vht_wep");
1112 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
1113
1114 val = get_param(cmd, "Protect_mode");
1115 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
1116
1117 val = get_param(cmd, "DYN_BW_SGNL");
1118 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001119 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001120 case DRIVER_OPENWRT:
1121 switch (get_openwrt_driver_type()) {
1122 case OPENWRT_DRIVER_ATHEROS:
1123 ath_config_dyn_bw_sig(dut, ifname, val);
1124 break;
1125 default:
1126 send_resp(dut, conn, SIGMA_ERROR,
1127 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001128 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001129 }
1130 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +05301131 case DRIVER_WCN:
1132 case DRIVER_LINUX_WCN:
1133 ath_config_dyn_bw_sig(dut, ifname, val);
1134 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001135 default:
1136 sigma_dut_print(dut, DUT_MSG_ERROR,
1137 "Unsupported DYN_BW_SGL with the current driver");
1138 break;
1139 }
1140 }
1141
1142 val = get_param(cmd, "SGI80");
1143 if (val) {
1144 if (strcasecmp(val, "enable") == 0)
1145 dut->ap_sgi80 = 1;
1146 else if (strcasecmp(val, "disable") == 0)
1147 dut->ap_sgi80 = 0;
1148 else {
1149 send_resp(dut, conn, SIGMA_INVALID,
1150 "errorCode,Unsupported SGI80");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001151 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001152 }
1153 }
1154
1155 val = get_param(cmd, "LDPC");
1156 if (val) {
1157 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001158 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001159 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001160 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001161 else {
1162 send_resp(dut, conn, SIGMA_INVALID,
1163 "errorCode,Unsupported LDPC");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001164 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001165 }
1166 }
1167
1168 val = get_param(cmd, "BW_SGNL");
1169 if (val) {
1170 /*
1171 * With dynamic bandwidth signaling enabled we should see
1172 * RTS if the threshold is met.
1173 */
1174 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001175 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001176 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001177 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001178 } else {
1179 send_resp(dut, conn, SIGMA_INVALID,
1180 "errorCode,Unsupported BW_SGNL");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001181 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001182 }
1183 }
1184
1185 val = get_param(cmd, "RTS_FORCE");
1186 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001187 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001188 case DRIVER_OPENWRT:
1189 switch (get_openwrt_driver_type()) {
1190 case OPENWRT_DRIVER_ATHEROS:
1191 ath_config_rts_force(dut, ifname, val);
1192 break;
1193 default:
1194 send_resp(dut, conn, SIGMA_ERROR,
1195 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001196 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001197 }
1198 break;
Tamizh chelvam638fb472019-08-15 14:00:31 +05301199 case DRIVER_MAC80211:
1200 mac80211_config_rts_force(dut, ifname, val);
1201 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001202 default:
1203 sigma_dut_print(dut, DUT_MSG_ERROR,
1204 "Unsupported RTS_FORCE with the current driver");
1205 break;
1206 }
1207 }
1208
1209 val = get_param(cmd, "Zero_crc");
1210 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001211 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001212 case DRIVER_ATHEROS:
1213 ath_set_zero_crc(dut, val);
1214 break;
1215 case DRIVER_OPENWRT:
1216 switch (get_openwrt_driver_type()) {
1217 case OPENWRT_DRIVER_ATHEROS:
1218 ath_set_zero_crc(dut, val);
1219 break;
1220 default:
1221 send_resp(dut, conn, SIGMA_ERROR,
1222 "errorCode,Unsupported zero_crc with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001223 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001224 }
1225 break;
1226 default:
1227 send_resp(dut, conn, SIGMA_ERROR,
1228 "errorCode,Unsupported zero_crc with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001229 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001230 }
1231 }
1232
1233 val = get_param(cmd, "TxBF");
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001234 if (val) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001235 dut->ap_txBF = strcasecmp(val, "enable") == 0;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001236 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08001237 dut->he_set_sta_1x1 = VALUE_ENABLED;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001238 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001239
1240 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301241 if (val) {
1242 if (strcasecmp(val, "enable") == 0) {
1243 dut->ap_txBF = 1;
1244 dut->ap_mu_txBF = 1;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001245 dut->he_sounding = VALUE_DISABLED;
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301246 } else if (strcasecmp(val, "disable") == 0) {
1247 dut->ap_txBF = 0;
1248 dut->ap_mu_txBF = 0;
1249 } else {
1250 sigma_dut_print(dut, DUT_MSG_ERROR,
1251 "Unsupported MU_TxBF");
1252 }
1253 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001254
1255 /* UNSUPPORTED: tx_lgi_rate */
1256
1257 val = get_param(cmd, "wpsnfc");
1258 if (val)
1259 dut->ap_wpsnfc = atoi(val);
1260
1261 val = get_param(cmd, "GROUP_ID");
1262 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001263 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001264 case DRIVER_OPENWRT:
1265 switch (get_openwrt_driver_type()) {
1266 case OPENWRT_DRIVER_ATHEROS:
1267 ath_ap_set_group_id(dut, ifname, val);
1268 break;
1269 default:
1270 send_resp(dut, conn, SIGMA_ERROR,
1271 "errorCode,Unsupported group_id with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001272 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001273 }
1274 break;
1275 default:
1276 send_resp(dut, conn, SIGMA_ERROR,
1277 "errorCode,Unsupported group_id with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001278 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001279 }
1280 }
1281
1282 val = get_param(cmd, "CTS_WIDTH");
1283 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001284 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001285 case DRIVER_OPENWRT:
1286 switch (get_openwrt_driver_type()) {
1287 case OPENWRT_DRIVER_ATHEROS:
1288 ath_set_cts_width(dut, ifname, val);
1289 break;
1290 default:
1291 send_resp(dut, conn, SIGMA_ERROR,
1292 "errorCode,Unsupported cts_width with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001293 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001294 }
1295 break;
1296 default:
1297 send_resp(dut, conn, SIGMA_ERROR,
1298 "errorCode,Unsupported cts_width with the current driver");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001299 return STATUS_SENT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001300 }
1301 }
1302
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001303 val = get_param(cmd, "MU_NDPA_FrameFormat");
1304 if (val)
1305 dut->ap_ndpa_frame = atoi(val);
1306
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001307 val = get_param(cmd, "interworking");
1308 if (val && strcmp(val, "1") == 0)
1309 dut->ap_interworking = 1;
1310
1311 val = get_param(cmd, "GAS_CB_DELAY");
1312 if (val)
1313 dut->ap_gas_cb_delay = atoi(val);
1314
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001315 val = get_param(cmd, "LCI");
1316 if (val) {
1317 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001318 return INVALID_SEND_STATUS;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001319 dut->ap_lci = 1;
1320 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1321 ath_set_lci_config(dut, val, cmd);
1322 }
1323
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001324 val = get_param(cmd, "InfoZ");
1325 if (val) {
1326 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001327 return INVALID_SEND_STATUS;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001328 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1329 }
1330
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001331 val = get_param(cmd, "LocCivicAddr");
1332 if (val) {
1333 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001334 return INVALID_SEND_STATUS;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001335 dut->ap_lcr = 1;
1336 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1337 if (dut->ap_lci == 0)
1338 ath_set_lci_config(dut, val, cmd);
1339 }
1340
1341 val = get_param(cmd, "NeighAPBSSID");
1342 if (val) {
1343 if (dut->ap_neighap < 3) {
1344 if (parse_mac_address(
1345 dut, val,
1346 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1347 send_resp(dut, conn, SIGMA_INVALID,
1348 "Failed to parse MAC address");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001349 return STATUS_SENT;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001350 }
1351 dut->ap_neighap++;
1352 if (dut->ap_lci == 1)
1353 dut->ap_scan = 1;
1354 }
1355 }
1356
1357 val = get_param(cmd, "OpChannel");
1358 if (val) {
1359 if (dut->ap_opchannel < 3) {
1360 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1361 dut->ap_opchannel++;
1362 }
1363 }
1364
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001365 val = get_param(cmd, "URI-FQDNdescriptor");
1366 if (val) {
1367 if (strcasecmp(val, "HELD") == 0) {
1368 dut->ap_fqdn_held = 1;
1369 } else if (strcasecmp(val, "SUPL") == 0) {
1370 dut->ap_fqdn_supl = 1;
1371 } else {
1372 send_resp(dut, conn, SIGMA_INVALID,
1373 "errorCode,Unsupported URI-FQDNdescriptor");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001374 return STATUS_SENT;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001375 }
1376 }
1377
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001378 val = get_param(cmd, "Reg_Domain");
1379 if (val) {
1380 if (strcasecmp(val, "Local") == 0) {
1381 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1382 } else if (strcasecmp(val, "Global") == 0) {
1383 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1384 } else {
1385 send_resp(dut, conn, SIGMA_ERROR,
1386 "errorCode,Wrong value for Reg_Domain");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001387 return STATUS_SENT;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001388 }
1389 }
1390
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001391 val = get_param(cmd, "NAME");
1392 if (val) {
1393 if (strcasecmp(val, "ap1mbo") == 0)
1394 dut->ap_name = 1;
1395 else if (strcasecmp(val, "ap2mbo") == 0)
1396 dut->ap_name = 2;
1397 else
1398 dut->ap_name = 0;
1399 }
1400
1401 val = get_param(cmd, "FT_OA");
1402 if (val) {
1403 if (strcasecmp(val, "Enable") == 0) {
1404 dut->ap_ft_oa = 1;
1405 } else if (strcasecmp(val, "Disable") == 0) {
1406 dut->ap_ft_oa = 0;
1407 } else {
1408 send_resp(dut, conn, SIGMA_ERROR,
1409 "errorCode,Wrong value for FT_OA");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001410 return STATUS_SENT;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001411 }
1412 }
1413
Jouni Malinen9f943312019-08-19 23:49:16 +03001414 val = get_param(cmd, "FT_DS");
1415 if (val) {
1416 if (strcasecmp(val, "Enable") == 0) {
1417 dut->ap_ft_ds = VALUE_ENABLED;
1418 } else if (strcasecmp(val, "Disable") == 0) {
1419 dut->ap_ft_ds = VALUE_DISABLED;
1420 } else {
1421 send_resp(dut, conn, SIGMA_ERROR,
1422 "errorCode,Unsupported value for FT_DS");
1423 return STATUS_SENT_ERROR;
1424 }
1425 }
1426
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001427 val = get_param(cmd, "Cellular_Cap_Pref");
1428 if (val)
1429 dut->ap_cell_cap_pref = atoi(val);
1430
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001431 val = get_param(cmd, "DOMAIN");
1432 if (val) {
1433 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1434 send_resp(dut, conn, SIGMA_ERROR,
1435 "errorCode,Too long DOMAIN");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001436 return STATUS_SENT;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001437 }
1438 snprintf(dut->ap_mobility_domain,
1439 sizeof(dut->ap_mobility_domain), "%s", val);
1440 }
1441
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001442 val = get_param(cmd, "ft_bss_list");
1443 if (val) {
1444 char *mac_str;
1445 int i;
1446 char *saveptr;
1447 char *mac_list_str;
1448
1449 mac_list_str = strdup(val);
1450 if (!mac_list_str)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001451 return INVALID_SEND_STATUS;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001452 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1453 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1454 if (parse_mac_address(dut, mac_str,
1455 dut->ft_bss_mac_list[i]) < 0) {
1456 sigma_dut_print(dut, DUT_MSG_ERROR,
1457 "MAC Address not in proper format");
1458 break;
1459 }
1460 dut->ft_bss_mac_cnt++;
1461 mac_str = strtok_r(NULL, " ", &saveptr);
1462 }
1463 sigma_dut_print(dut, DUT_MSG_DEBUG,
1464 "Storing the following FT BSS MAC List");
1465 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1466 sigma_dut_print(dut, DUT_MSG_DEBUG,
1467 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1468 i,
1469 dut->ft_bss_mac_list[i][0],
1470 dut->ft_bss_mac_list[i][1],
1471 dut->ft_bss_mac_list[i][2],
1472 dut->ft_bss_mac_list[i][3],
1473 dut->ft_bss_mac_list[i][4],
1474 dut->ft_bss_mac_list[i][5]);
1475 }
1476 free(mac_list_str);
1477 }
1478
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001479 val = get_param(cmd, "OCESupport");
1480 if (val) {
1481 if (strcasecmp(val, "enable") == 0) {
1482 dut->ap_oce = VALUE_ENABLED;
1483 } else if (strcasecmp(val, "disable") == 0) {
1484 dut->ap_oce = VALUE_DISABLED;
1485 dut->ap_filsdscv = VALUE_DISABLED;
1486 } else {
1487 send_resp(dut, conn, SIGMA_INVALID,
1488 "errorCode,Unsupported OCE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001489 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001490 }
1491 }
1492
1493 val = get_param(cmd, "FILSDscvInterval");
1494 if (val)
1495 dut->ap_fils_dscv_int = atoi(val);
1496
1497 val = get_param(cmd, "BroadcastSSID");
1498 if (val) {
1499 if (strcasecmp(val, "enable") == 0) {
1500 dut->ap_broadcast_ssid = VALUE_ENABLED;
1501 } else if (strcasecmp(val, "disable") == 0) {
1502 dut->ap_broadcast_ssid = VALUE_DISABLED;
1503 } else {
1504 send_resp(dut, conn, SIGMA_INVALID,
1505 "errorCode,Unsupported hidden SSID");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001506 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001507 }
1508 }
1509
1510 val = get_param(cmd, "FILSDscv");
1511 if (val) {
1512 if (strcasecmp(val, "enable") == 0) {
1513 dut->ap_filsdscv = VALUE_ENABLED;
1514 } else if (strcasecmp(val, "disable") == 0) {
1515 dut->ap_filsdscv = VALUE_DISABLED;
1516 } else {
1517 send_resp(dut, conn, SIGMA_INVALID,
1518 "errorCode,Unsupported FILSDscv");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001519 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001520 }
1521 }
1522
1523 val = get_param(cmd, "FILSHLP");
1524 if (val) {
1525 if (strcasecmp(val, "enable") == 0) {
1526 dut->ap_filshlp = VALUE_ENABLED;
1527 } else if (strcasecmp(val, "disable") == 0) {
1528 dut->ap_filshlp = VALUE_DISABLED;
1529 } else {
1530 send_resp(dut, conn, SIGMA_INVALID,
1531 "errorCode,Unsupported FILSHLP");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001532 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001533 }
1534 }
1535
1536 val = get_param(cmd, "NAIRealm");
1537 if (val) {
1538 dut->ap_nairealm_int = 1;
1539 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001540 return INVALID_SEND_STATUS;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001541 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1542 }
1543
1544 val = get_param(cmd, "DeauthDisassocTx");
1545 if (val) {
1546 if (strcasecmp(val, "disable") == 0) {
1547 deauth_disassoc(dut, ifname, val);
1548 } else {
1549 send_resp(dut, conn, SIGMA_INVALID,
1550 "errorCode,Unsupported DeauthDisassocTx");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001551 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001552 }
1553 }
1554
1555 val = get_param(cmd, "RNR");
1556 if (val) {
1557 if (strcasecmp(val, "enable") == 0) {
1558 dut->ap_rnr = VALUE_ENABLED;
1559 } else if (strcasecmp(val, "disable") == 0) {
1560 dut->ap_rnr = VALUE_DISABLED;
1561 } else {
1562 send_resp(dut, conn, SIGMA_INVALID,
1563 "errorCode,Unsupported RNR");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001564 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001565 }
1566 }
1567
1568 val = get_param(cmd, "BLEChannelUtil");
1569 if (val)
1570 dut->ap_blechanutil = atoi(val);
1571
1572 val = get_param(cmd, "BLEAvailAdminCap");
1573 if (val)
1574 dut->ap_ble_admit_cap = atoi(val);
1575
1576 val = get_param(cmd, "DataPPDUDuration");
1577 if (val)
1578 dut->ap_datappdudura = atoi(val);
1579
1580 val = get_param(cmd, "AirTimeFract");
1581 if (val)
1582 dut->ap_airtimefract = atoi(val);
1583
1584 val = get_param(cmd, "dhcpServIPADDR");
1585 if (val) {
1586 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001587 return INVALID_SEND_STATUS;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001588 snprintf(dut->ap_dhcpserv_ipaddr,
1589 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1590 dut->ap_dhcp_stop = 1;
1591 }
1592
1593 val = get_param(cmd, "ESP_IE");
1594 if (val) {
1595 if (strcasecmp(val, "enable") == 0) {
1596 dut->ap_esp = VALUE_ENABLED;
1597 } else if (strcasecmp(val, "disable") == 0) {
1598 dut->ap_esp = VALUE_DISABLED;
1599 } else {
1600 send_resp(dut, conn, SIGMA_INVALID,
1601 "errorCode,Unsupported ESP_IE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001602 return STATUS_SENT;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001603 }
1604 }
1605
1606 val = get_param(cmd, "BAWinSize");
1607 if (val)
1608 dut->ap_bawinsize = atoi(val);
1609
1610 val = get_param(cmd, "BLEStaCount");
1611 if (val)
1612 dut->ap_blestacnt = atoi(val);
1613
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001614 val = get_param(cmd, "PPDUTxType");
1615 if (val) {
1616 if (strcasecmp(val, "MU") == 0) {
1617 dut->ap_he_ppdu = PPDU_MU;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001618 } else if (strcasecmp(val, "HE-SU") == 0) {
1619 /* Do nothing */
1620 } else if (strcasecmp(val, "SU") == 0) {
1621 /* Do nothing */
1622 } else if (strcasecmp(val, "legacy") == 0) {
1623 /* Do nothing */
1624 } else if (strcasecmp(val, "ER") == 0) {
1625 /* Do nothing */
1626 } else if (strcasecmp(val, "TB") == 0) {
1627 /* Do nothing */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001628 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001629 send_resp(dut, conn, SIGMA_ERROR,
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001630 "errorCode,Unsupported PPDUTxType");
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001631 return STATUS_SENT_ERROR;
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001632 }
1633 }
1634
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02001635 val = get_param(cmd, "WscIEFragment");
1636 if (val && strcasecmp(val, "enable") == 0) {
1637 sigma_dut_print(dut, DUT_MSG_DEBUG,
1638 "Enable WSC IE fragmentation");
1639 dut->wsc_fragment = 1;
1640 }
1641
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02001642 val = get_param(cmd, "WpsVersion");
1643 if (val)
1644 dut->wps_forced_version = get_wps_forced_version(dut, val);
1645
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02001646 val = get_param(cmd, "WscEAPFragment");
1647 if (val && strcasecmp(val, "enable") == 0)
1648 dut->eap_fragment = 1;
1649
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001650 val = get_param(cmd, "MSDUSize");
1651 if (val) {
1652 int mtu;
1653
1654 dut->amsdu_size = atoi(val);
1655 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
1656 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
1657 sigma_dut_print(dut, DUT_MSG_ERROR,
1658 "MSDUSize %d is above max %d or below min %d",
1659 dut->amsdu_size,
1660 IEEE80211_MAX_DATA_LEN_DMG,
1661 IEEE80211_SNAP_LEN_DMG);
1662 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001663 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001664 }
1665
1666 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
1667 sigma_dut_print(dut, DUT_MSG_DEBUG,
1668 "Setting amsdu_size to %d", mtu);
1669 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001670 get_station_ifname(dut), mtu);
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001671
1672 if (system(buf) != 0) {
1673 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
1674 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001675 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001676 }
1677 }
1678
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001679 val = get_param(cmd, "BAckRcvBuf");
1680 if (val) {
1681 dut->back_rcv_buf = atoi(val);
1682 if (dut->back_rcv_buf == 0) {
1683 sigma_dut_print(dut, DUT_MSG_ERROR,
1684 "Failed to convert %s or value is 0",
1685 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001686 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001687 }
1688
1689 sigma_dut_print(dut, DUT_MSG_DEBUG,
1690 "Setting BAckRcvBuf to %s", val);
1691 }
1692
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001693 val = get_param(cmd, "ExtSchIE");
1694 if (val && !strcasecmp(val, "Enable")) {
1695 int num_allocs = MAX_ESE_ALLOCS;
1696
1697 if (sta_extract_60g_ese(dut, cmd, dut->ap_ese_allocs,
1698 &num_allocs)) {
1699 send_resp(dut, conn, SIGMA_INVALID,
1700 "errorCode,Invalid ExtSchIE");
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001701 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001702 }
1703 dut->ap_num_ese_allocs = num_allocs;
1704 }
1705
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02001706 if (is_60g_sigma_dut(dut)) {
1707 unsigned int abft_len = 1; /* default is one slot */
1708
1709 val = get_param(cmd, "ABFTLRang");
1710 if (val) {
1711 sigma_dut_print(dut, DUT_MSG_DEBUG,
1712 "ABFTLRang parameter %s", val);
1713 if (strcasecmp(val, "Gt1") == 0)
1714 abft_len = 2; /* 2 slots in this case */
1715 }
1716
1717 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
1718 send_resp(dut, conn, SIGMA_ERROR,
1719 "ErrorCode,Can't set ABFT length");
1720 return STATUS_SENT;
1721 }
1722 }
1723
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001724 val = get_param(cmd, "OFDMA");
1725 if (val) {
1726 if (strcasecmp(val, "UL") == 0) {
1727 dut->ap_he_ulofdma = VALUE_ENABLED;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001728 } else if (strcasecmp(val, "DL") == 0) {
1729 dut->ap_he_dlofdma = VALUE_ENABLED;
1730 } else if (strcasecmp(val, "DL-20and80") == 0) {
1731 dut->ap_he_dlofdma = VALUE_ENABLED;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001732 } else {
1733 send_resp(dut, conn, SIGMA_ERROR,
1734 "errorCode,Unsupported OFDMA value");
1735 return STATUS_SENT_ERROR;
1736 }
1737 }
1738
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07001739 val = get_param(cmd, "NumSoundDim");
1740 if (val)
1741 dut->ap_numsounddim = atoi(val);
1742
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07001743 val = get_param(cmd, "BCC");
1744 if (val) {
1745 if (strcasecmp(val, "enable") == 0) {
1746 dut->ap_bcc = VALUE_ENABLED;
1747 dut->ap_ldpc = VALUE_DISABLED;
1748 } else if (strcasecmp(val, "disable") == 0) {
1749 dut->ap_ldpc = VALUE_ENABLED;
1750 dut->ap_bcc = VALUE_DISABLED;
1751 } else {
1752 send_resp(dut, conn, SIGMA_ERROR,
1753 "errorCode,Unsupported BCC value");
1754 return STATUS_SENT_ERROR;
1755 }
1756 }
1757
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07001758 val = get_param(cmd, "FrgmntSupport");
1759 if (val) {
1760 if (strcasecmp(val, "enable") == 0) {
1761 dut->ap_he_frag = VALUE_ENABLED;
1762 } else if (strcasecmp(val, "disable") == 0) {
1763 dut->ap_he_frag = VALUE_DISABLED;
1764 } else {
1765 send_resp(dut, conn, SIGMA_ERROR,
1766 "errorCode,Unsupported FrgmntSupport value");
1767 return STATUS_SENT_ERROR;
1768 }
1769 }
1770
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07001771 val = get_param(cmd, "ADDBAReq_BufSize");
1772 if (val) {
1773 if (strcasecmp(val, "le64") == 0) {
1774 dut->ap_ba_bufsize = BA_BUFSIZE_64;
1775 } else if (strcasecmp(val, "gt64") == 0) {
1776 dut->ap_ba_bufsize = BA_BUFSIZE_256;
1777 } else {
1778 send_resp(dut, conn, SIGMA_ERROR,
1779 "errorCode,Unsupported ADDBAReq Buffer Size");
1780 return STATUS_SENT_ERROR;
1781 }
1782 }
1783
1784 val = get_param(cmd, "ADDBAResp_BufSize");
1785 if (val) {
1786 if (strcasecmp(val, "gt64") == 0) {
1787 dut->ap_ba_bufsize = BA_BUFSIZE_256;
1788 } else {
1789 send_resp(dut, conn, SIGMA_ERROR,
1790 "errorCode,Unsupported ADDBAResp Buffer Size");
1791 return STATUS_SENT_ERROR;
1792 }
1793 }
1794
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07001795 val = get_param(cmd, "MU_EDCA");
1796 if (val) {
1797 if (strcasecmp(val, "override") == 0) {
1798 dut->ap_mu_edca = VALUE_ENABLED;
1799 } else if (strcasecmp(val, "disable") == 0) {
1800 dut->ap_mu_edca = VALUE_DISABLED;
1801 } else {
1802 send_resp(dut, conn, SIGMA_ERROR,
1803 "errorCode,Unsupported mu_edca param value");
1804 return STATUS_SENT_ERROR;
1805 }
1806 }
1807
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07001808 val = get_param(cmd, "MIMO");
1809 if (val) {
1810 if (strcasecmp(val, "DL") == 0) {
1811 dut->ap_he_mimo = MIMO_DL;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08001812 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07001813 } else if (strcasecmp(val, "UL") == 0) {
1814 dut->ap_he_mimo = MIMO_UL;
1815 } else {
1816 send_resp(dut, conn, SIGMA_ERROR,
1817 "errorCode,Unsupported mimo param value");
1818 return STATUS_SENT_ERROR;
1819 }
1820 }
1821
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07001822 val = get_param(cmd, "HE_TXOPDurRTSThr");
1823 if (val) {
1824 if (strcasecmp(val, "enable") == 0) {
1825 dut->ap_he_rtsthrshld = VALUE_ENABLED;
1826 } else if (strcasecmp(val, "disable") == 0) {
1827 dut->ap_he_rtsthrshld = VALUE_DISABLED;
1828 } else {
1829 send_resp(dut, conn, SIGMA_ERROR,
1830 "errorCode,Unsupported HE_TXOPDurRTSThr value");
1831 return STATUS_SENT_ERROR;
1832 }
1833 }
1834
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07001835 val = get_param(cmd, "MBSSID");
1836 if (val) {
1837 if (strcasecmp(val, "enable") == 0) {
1838 dut->ap_mbssid = VALUE_ENABLED;
1839 } else if (strcasecmp(val, "disable") == 0) {
1840 dut->ap_mbssid = VALUE_DISABLED;
1841 } else {
1842 send_resp(dut, conn, SIGMA_ERROR,
1843 "errorCode,Unsupported MBSSID Value");
1844 return STATUS_SENT_ERROR;
1845 }
1846 }
1847
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07001848 val = get_param(cmd, "TWT_RespSupport");
1849 if (val) {
1850 if (strcasecmp(val, "enable") == 0) {
1851 dut->ap_twtresp = VALUE_ENABLED;
1852 } else if (strcasecmp(val, "disable") == 0) {
1853 dut->ap_twtresp = VALUE_DISABLED;
1854 } else {
1855 send_resp(dut, conn, SIGMA_ERROR,
1856 "errorCode,Unsupported TWT_RespSupport value");
1857 return STATUS_SENT_ERROR;
1858 }
1859 }
1860
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08001861 val = get_param(cmd, "MinMPDUStartSpacing");
1862 if (val)
1863 dut->he_mmss = atoi(val);
1864
Jouni Malinendccfd0c2019-10-30 12:05:59 +02001865 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001866}
1867
1868
1869static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1870{
1871 char buf[256];
1872 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1873
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301874 if (tid < 0 ||
1875 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1876 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1877 return;
1878 }
1879
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001880 snprintf(buf, sizeof(buf),
1881 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1882 ifname, VI_QOS_TMP_FILE);
1883 if (system(buf) != 0)
1884 return;
1885
1886 snprintf(buf, sizeof(buf),
1887 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1888 ifname, VI_QOS_TMP_FILE);
1889 if (system(buf) != 0)
1890 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1891
1892 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1893 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1894 if (system(buf) != 0) {
1895 sigma_dut_print(dut, DUT_MSG_ERROR,
1896 "Output redirection to VI_QOS_TMP_FILE failed");
1897 }
1898
1899 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1900 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1901 if (system(buf) != 0) {
1902 sigma_dut_print(dut, DUT_MSG_ERROR,
1903 "Append TID to VI_QOS_FILE failed ");
1904 }
1905
1906 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1907 if (system(buf) != 0)
1908 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1909}
1910
1911
1912static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1913 struct sigma_cmd *cmd)
1914{
1915 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001916 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001917 char buf[256];
1918 int tid = 0;
1919
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001920 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921 val = get_param(cmd, "TID");
1922 if (val) {
1923 tid = atoi(val);
1924 if (tid)
1925 ath_inject_frame(dut, ifname, tid);
1926 }
1927
1928 /* NOTE: This is the command sequence on Peregrine for ADDBA */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07001929 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001930
1931 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1932 ifname, tid);
1933 if (system(buf) != 0) {
1934 sigma_dut_print(dut, DUT_MSG_ERROR,
1935 "wifitool senddelba failed");
1936 }
1937
1938 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1939 ifname, tid);
1940 if (system(buf) != 0) {
1941 sigma_dut_print(dut, DUT_MSG_ERROR,
1942 "wifitool sendaddba failed");
1943 }
1944
1945 return 1;
1946}
1947
1948
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301949static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1950 const char *sta_mac,
1951 const char *dir_path)
1952{
1953 DIR *dir;
1954 struct dirent *entry;
1955 char buf[128], path[128];
Jouni Malinen3aa72862019-05-29 23:14:51 +03001956 int ret = 0, res;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301957
1958 dir = opendir(dir_path);
1959 if (!dir)
1960 return 0;
1961
1962 while ((entry = readdir(dir))) {
1963 ret = 1;
1964
1965 if (strcmp(entry->d_name, ".") == 0 ||
1966 strcmp(entry->d_name, "..") == 0)
1967 continue;
1968
Jouni Malinen3aa72862019-05-29 23:14:51 +03001969 res = snprintf(path, sizeof(path) - 1, "%s/%s",
1970 dir_path, entry->d_name);
1971 if (res < 0 || res >= sizeof(path))
1972 continue;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301973
1974 if (strcmp(entry->d_name, sta_mac) == 0) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03001975 res = snprintf(buf, sizeof(buf),
1976 "echo 1 > %s/aggr_mode", path);
1977 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301978 sigma_dut_print(dut, DUT_MSG_ERROR,
1979 "Failed to set aggr mode for ath10k");
1980 }
1981
Jouni Malinen3aa72862019-05-29 23:14:51 +03001982 res = snprintf(buf, sizeof(buf),
1983 "echo %d 32 > %s/addba", tid, path);
1984 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301985 sigma_dut_print(dut, DUT_MSG_ERROR,
1986 "Failed to set addbareq for ath10k");
1987 }
1988
1989 break;
1990 }
1991
1992 /* Recursively search subdirectories */
1993 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1994 }
1995
1996 closedir(dir);
1997
1998 return ret;
1999}
2000
2001
2002static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
2003 struct sigma_cmd *cmd)
2004{
2005 const char *val;
2006 int tid = 0;
2007
2008 val = get_param(cmd, "TID");
2009 if (val)
2010 tid = atoi(val);
2011
2012 val = get_param(cmd, "sta_mac_address");
2013 if (!val) {
2014 sigma_dut_print(dut, DUT_MSG_ERROR,
2015 "Failed to parse station MAC address");
2016 return 0;
2017 }
2018
2019 return ath10k_debug_enable_addba_req(dut, tid, val,
2020 "/sys/kernel/debug/ieee80211");
2021}
2022
2023
Jouni Malinenf7222712019-06-13 01:50:21 +03002024static enum sigma_cmd_result cmd_ap_send_addba_req(struct sigma_dut *dut,
2025 struct sigma_conn *conn,
2026 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002027{
2028 /* const char *name = get_param(cmd, "NAME"); */
2029 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302030 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002031
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002032 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002033 case DRIVER_ATHEROS:
2034 return ath_ap_send_addba_req(dut, conn, cmd);
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02002035#ifdef __linux__
2036 case DRIVER_WIL6210:
2037 return send_addba_60g(dut, conn, cmd, "sta_mac_address");
2038#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002039 case DRIVER_OPENWRT:
2040 switch (get_openwrt_driver_type()) {
2041 case OPENWRT_DRIVER_ATHEROS:
2042 return ath_ap_send_addba_req(dut, conn, cmd);
2043 default:
2044 send_resp(dut, conn, SIGMA_ERROR,
2045 "errorCode,ap_send_addba_req not supported with this driver");
2046 return 0;
2047 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05302048 case DRIVER_WCN:
2049 case DRIVER_LINUX_WCN:
2050 /* AP automatically sends ADDBA request after association. */
2051 sigma_dut_print(dut, DUT_MSG_INFO,
2052 "ap_send_addba_req command ignored");
2053 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05302054 case DRIVER_MAC80211:
2055 if (stat("/sys/module/ath10k_core", &s) == 0)
2056 return ath10k_ap_send_addba_req(dut, cmd);
2057 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002058 default:
2059 send_resp(dut, conn, SIGMA_ERROR,
2060 "errorCode,ap_send_addba_req not supported with this driver");
2061 return 0;
2062 }
2063}
2064
2065
Jouni Malinenf7222712019-06-13 01:50:21 +03002066static enum sigma_cmd_result cmd_ap_set_security(struct sigma_dut *dut,
2067 struct sigma_conn *conn,
2068 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002069{
2070 /* const char *name = get_param(cmd, "NAME"); */
2071 const char *val;
2072 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302073 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002074
2075 val = get_param(cmd, "WLAN_TAG");
2076 if (val)
2077 wlan_tag = atoi(val);
2078
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302079 security = get_param(cmd, "Security");
2080
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002081 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302083 if (!val)
2084 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002085 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002086 if (strcasecmp(val, "NONE") == 0) {
2087 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
2088 } else if (strcasecmp(val, "OSEN") == 0 &&
2089 wlan_tag == 2) {
2090 /*
2091 * OSEN only supported on WLAN_TAG = 2 for now
2092 */
2093 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302094 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
2095 (security &&
2096 strcasecmp(security, "PSK") == 0 &&
2097 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002098 dut->ap_tag_key_mgmt[wlan_tag - 2] =
2099 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02002100 } else if (strcasecmp(val, "OWE") == 0 &&
2101 wlan_tag == 2) {
2102 dut->ap_tag_key_mgmt[wlan_tag - 2] =
2103 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002104 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002105 send_resp(dut, conn, SIGMA_INVALID,
2106 "errorCode,Unsupported KEYMGNT");
2107 return 0;
2108 }
2109 return 1;
2110 }
2111 }
2112
2113 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302114 if (!val)
2115 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002116 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302117 if (strcasecmp(val, "WPA2-PSK") == 0 ||
2118 (security && strcasecmp(security, "PSK") == 0 &&
2119 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002120 dut->ap_key_mgmt = AP_WPA2_PSK;
2121 dut->ap_cipher = AP_CCMP;
2122 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
2123 strcasecmp(val, "WPA2-Ent") == 0) {
2124 dut->ap_key_mgmt = AP_WPA2_EAP;
2125 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03002126 } else if (strcasecmp(val, "SuiteB") == 0) {
2127 dut->ap_key_mgmt = AP_SUITEB;
2128 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02002129 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 } else if (strcasecmp(val, "WPA-PSK") == 0) {
2131 dut->ap_key_mgmt = AP_WPA_PSK;
2132 dut->ap_cipher = AP_TKIP;
2133 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
2134 strcasecmp(val, "WPA-Ent") == 0) {
2135 dut->ap_key_mgmt = AP_WPA_EAP;
2136 dut->ap_cipher = AP_TKIP;
2137 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
2138 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
2139 dut->ap_cipher = AP_CCMP_TKIP;
2140 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
2141 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
2142 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02002143 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
2144 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03002145 dut->ap_key_mgmt = AP_WPA2_SAE;
2146 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002147 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03002148 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
2149 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
2150 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002151 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03002152 } else if (strcasecmp(val, "OWE") == 0) {
2153 dut->ap_key_mgmt = AP_WPA2_OWE;
2154 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02002155 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03002156 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
2157 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
2158 dut->ap_cipher = AP_CCMP;
2159 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03002160 } else if (strcasecmp(val, "OSEN") == 0) {
2161 dut->ap_key_mgmt = AP_OSEN;
2162 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03002163 } else if (strcasecmp(val, "FT-EAP") == 0) {
2164 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
2165 dut->ap_cipher = AP_CCMP;
2166 dut->ap_pmf = AP_PMF_OPTIONAL;
2167 } else if (strcasecmp(val, "FT-PSK") == 0) {
2168 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
2169 dut->ap_cipher = AP_CCMP;
2170 dut->ap_pmf = AP_PMF_OPTIONAL;
2171 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
2172 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
2173 dut->ap_cipher = AP_CCMP;
2174 dut->ap_pmf = AP_PMF_OPTIONAL;
2175 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
2176 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
2177 dut->ap_cipher = AP_CCMP;
2178 dut->ap_pmf = AP_PMF_OPTIONAL;
2179 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
2180 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
2181 dut->ap_cipher = AP_CCMP;
2182 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002183 } else if (strcasecmp(val, "NONE") == 0) {
2184 dut->ap_key_mgmt = AP_OPEN;
2185 dut->ap_cipher = AP_PLAIN;
2186 } else {
2187 send_resp(dut, conn, SIGMA_INVALID,
2188 "errorCode,Unsupported KEYMGNT");
2189 return 0;
2190 }
2191 }
2192
Jouni Malinen30824df2017-08-22 21:21:38 +03002193 val = get_param(cmd, "ECGroupID");
2194 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03002195 free(dut->ap_sae_groups);
2196 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03002197 }
2198
Jouni Malinen2f524ce2017-08-31 01:43:29 +03002199 val = get_param(cmd, "AntiCloggingThreshold");
2200 if (val)
2201 dut->sae_anti_clogging_threshold = atoi(val);
2202
Jouni Malinenb347db02017-09-02 01:36:03 +03002203 val = get_param(cmd, "Reflection");
2204 if (val)
2205 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
2206
Jouni Malinen68143132017-09-02 02:34:08 +03002207 val = get_param(cmd, "InvalidSAEElement");
2208 if (val) {
2209 free(dut->sae_commit_override);
2210 dut->sae_commit_override = strdup(val);
2211 }
2212
Jouni Malinen09550de2019-03-26 00:24:11 +02002213 val = get_param(cmd, "SAEPasswords");
2214 if (val) {
2215 free(dut->ap_sae_passwords);
2216 dut->ap_sae_passwords = strdup(val);
2217 }
2218
Jouni Malinen3c740ab2019-10-10 15:55:11 +03002219 val = get_param(cmd, "SAE_Confirm_Immediate");
2220 if (val)
2221 dut->sae_confirm_immediate = get_enable_disable(val);
2222
Jouni Malinen11e55212019-11-22 21:46:59 +02002223 val = get_param(cmd, "sae_pwe");
2224 if (val) {
2225 if (strcasecmp(val, "h2e") == 0) {
2226 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002227 } else if (strcasecmp(val, "loop") == 0 ||
2228 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002229 dut->sae_pwe = SAE_PWE_LOOP;
2230 } else {
2231 send_resp(dut, conn, SIGMA_ERROR,
2232 "errorCode,Unsupported sae_pwe value");
2233 return STATUS_SENT_ERROR;
2234 }
2235 }
2236
Jouni Malinen7960e3a2019-12-07 17:04:35 +02002237 val = get_param(cmd, "RSNXE_Content");
2238 if (val) {
2239 if (strncasecmp(val, "EapolM3:", 8) != 0) {
2240 send_resp(dut, conn, SIGMA_ERROR,
2241 "errorCode,Unsupported RSNXE_Content value");
2242 return STATUS_SENT_ERROR;
2243 }
2244 val += 8;
2245 free(dut->rsnxe_override_eapol);
2246 dut->rsnxe_override_eapol = strdup(val);
2247 }
2248
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002249 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302250 if (!val)
2251 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002252 if (val) {
2253 if (strcasecmp(val, "WEP") == 0) {
2254 dut->ap_cipher = AP_WEP;
2255 } else if (strcasecmp(val, "TKIP") == 0) {
2256 dut->ap_cipher = AP_TKIP;
2257 } else if (strcasecmp(val, "AES") == 0 ||
2258 strcasecmp(val, "AES-CCMP") == 0) {
2259 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002260 } else if (strcasecmp(val, "AES-GCMP") == 0) {
2261 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002262 } else {
2263 send_resp(dut, conn, SIGMA_INVALID,
2264 "errorCode,Unsupported ENCRYPT");
2265 return 0;
2266 }
2267 }
2268
Jouni Malinen3d633da2017-09-14 22:19:21 +03002269 val = get_param(cmd, "PairwiseCipher");
2270 if (val) {
2271 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2272 dut->ap_cipher = AP_GCMP_256;
2273 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2274 dut->ap_cipher = AP_CCMP_256;
2275 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2276 dut->ap_cipher = AP_GCMP_128;
2277 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2278 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02002279 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
2280 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
2281 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002282 } else {
2283 send_resp(dut, conn, SIGMA_INVALID,
2284 "errorCode,Unsupported PairwiseCipher");
2285 return 0;
2286 }
2287 }
2288
Jouni Malinen2ba24492017-11-17 12:43:59 +02002289 val = get_param(cmd, "GroupCipher");
2290 if (val) {
2291 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2292 dut->ap_group_cipher = AP_GCMP_256;
2293 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2294 dut->ap_group_cipher = AP_CCMP_256;
2295 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2296 dut->ap_group_cipher = AP_GCMP_128;
2297 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2298 dut->ap_group_cipher = AP_CCMP;
2299 } else {
2300 send_resp(dut, conn, SIGMA_INVALID,
2301 "errorCode,Unsupported GroupCipher");
2302 return 0;
2303 }
2304 }
2305
Jouni Malinen3d633da2017-09-14 22:19:21 +03002306 val = get_param(cmd, "GroupMgntCipher");
2307 if (val) {
2308 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2309 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
2310 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2311 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
2312 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2313 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
2314 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2315 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
2316 } else {
2317 send_resp(dut, conn, SIGMA_INVALID,
2318 "errorCode,Unsupported GroupMgntCipher");
2319 return 0;
2320 }
2321 }
2322
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002323 val = get_param(cmd, "WEPKEY");
2324 if (val) {
2325 size_t len;
2326 if (dut->ap_cipher != AP_WEP) {
2327 send_resp(dut, conn, SIGMA_INVALID,
2328 "errorCode,Unexpected WEPKEY without WEP "
2329 "configuration");
2330 return 0;
2331 }
2332 len = strlen(val);
2333 if (len != 10 && len != 26) {
2334 send_resp(dut, conn, SIGMA_INVALID,
2335 "errorCode,Unexpected WEPKEY length");
2336 return 0;
2337 }
2338 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
2339 }
2340
2341 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302342 if (!val)
2343 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002344 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002345 if (dut->ap_key_mgmt != AP_WPA2_SAE &&
2346 (dut->ap_akm_values & (AKM_WPA_PSK | AKM_SAE)) !=
2347 AKM_SAE &&
2348 strlen(val) > 64) {
2349 sigma_dut_print(dut, DUT_MSG_ERROR,
2350 "Too long PSK/passphtase");
Jouni Malinen2126f422017-10-11 23:24:33 +03002351 return -1;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002352 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002353 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
2354 return -1;
2355 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
2356 "%s", val);
2357 }
2358
Jouni Malinen63370622017-11-18 17:47:13 +02002359 val = get_param(cmd, "PSKHEX");
2360 if (val) {
2361 if (strlen(val) != 64)
2362 return -1;
2363 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
2364 }
2365
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302366 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
2367 dut->ap_pmf = AP_PMF_OPTIONAL;
2368
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002369 val = get_param(cmd, "PMF");
2370 if (val) {
2371 if (strcasecmp(val, "Disabled") == 0) {
2372 dut->ap_pmf = AP_PMF_DISABLED;
2373 } else if (strcasecmp(val, "Optional") == 0) {
2374 dut->ap_pmf = AP_PMF_OPTIONAL;
2375 } else if (strcasecmp(val, "Required") == 0) {
2376 dut->ap_pmf = AP_PMF_REQUIRED;
2377 } else {
2378 send_resp(dut, conn, SIGMA_INVALID,
2379 "errorCode,Unsupported PMF");
2380 return 0;
2381 }
2382 }
2383
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002384 dut->ap_add_sha256 = 0;
2385 val = get_param(cmd, "SHA256AD");
2386 if (val == NULL)
2387 val = get_param(cmd, "SHA256");
2388 if (val) {
2389 if (strcasecmp(val, "Disabled") == 0) {
2390 } else if (strcasecmp(val, "Enabled") == 0) {
2391 dut->ap_add_sha256 = 1;
2392 } else {
2393 send_resp(dut, conn, SIGMA_INVALID,
Jouni Malinena7fa6202019-03-26 00:22:10 +02002394 "errorCode,Unsupported SHA256");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002395 return 0;
2396 }
2397 }
2398
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302399 val = get_param(cmd, "PreAuthentication");
2400 if (val) {
2401 if (strcasecmp(val, "disabled") == 0) {
2402 dut->ap_rsn_preauth = 0;
2403 } else if (strcasecmp(val, "enabled") == 0) {
2404 dut->ap_rsn_preauth = 1;
2405 } else {
2406 send_resp(dut, conn, SIGMA_INVALID,
2407 "errorCode,Unsupported PreAuthentication value");
2408 return 0;
2409 }
2410 }
2411
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002412 val = get_param(cmd, "AKMSuiteType");
2413 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002414 const char *in_pos = val;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002415
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002416 dut->ap_akm_values = 0;
2417 while (*in_pos) {
2418 int akm = atoi(in_pos);
2419
2420 if (akm < 0 || akm >= 32) {
2421 send_resp(dut, conn, SIGMA_ERROR,
2422 "errorCode,Unsupported AKMSuiteType value");
2423 return STATUS_SENT;
2424 }
2425
2426 dut->ap_akm_values |= 1 << akm;
2427
2428 in_pos = strchr(in_pos, ';');
2429 if (!in_pos)
2430 break;
2431 while (*in_pos == ';')
2432 in_pos++;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002433 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002434 dut->ap_akm = 1;
2435 if (dut->ap_akm_values & (1 << 14))
2436 dut->ap_add_sha384 = 1;
2437 if (dut->ap_akm_values & (1 << 15))
2438 dut->ap_add_sha384 = 1;
2439 }
2440
2441 if (dut->ap_key_mgmt == AP_OPEN && !dut->ap_akm_values) {
2442 dut->ap_hs2 = 0;
2443 dut->ap_pmf = AP_PMF_DISABLED;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002444 }
2445
2446 val = get_param(cmd, "PMKSACaching");
2447 if (val) {
2448 dut->ap_pmksa = 1;
2449 if (strcasecmp(val, "disabled") == 0) {
2450 dut->ap_pmksa_caching = 1;
2451 } else if (strcasecmp(val, "enabled") == 0) {
2452 dut->ap_pmksa_caching = 0;
2453 } else {
2454 send_resp(dut, conn, SIGMA_INVALID,
2455 "errorCode,Unsupported PMKSACaching value");
2456 return 0;
2457 }
2458 }
2459
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002460 return 1;
2461}
2462
2463
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302464int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2465 struct sigma_cmd *cmd)
2466{
2467 int status;
2468
2469 status = cmd_ap_set_wireless(dut, conn, cmd);
2470 if (status != 1)
2471 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302472 status = cmd_ap_set_security(dut, conn, cmd);
2473 if (status != 1)
2474 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302475 return cmd_ap_config_commit(dut, conn, cmd);
2476}
2477
2478
Jouni Malinenf7222712019-06-13 01:50:21 +03002479static enum sigma_cmd_result cmd_ap_set_radius(struct sigma_dut *dut,
2480 struct sigma_conn *conn,
2481 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482{
2483 /* const char *name = get_param(cmd, "NAME"); */
2484 const char *val;
2485 unsigned int wlan_tag = 1, radius_port = 0;
2486 char *radius_ipaddr = NULL, *radius_password = NULL;
2487
2488 val = get_param(cmd, "WLAN_TAG");
2489 if (val) {
2490 wlan_tag = atoi(val);
2491 if (wlan_tag != 1 && wlan_tag != 2) {
2492 send_resp(dut, conn, SIGMA_INVALID,
2493 "errorCode,Invalid WLAN_TAG");
2494 return 0;
2495 }
2496 }
2497
2498 val = get_param(cmd, "PORT");
2499 if (val)
2500 radius_port = atoi(val);
2501
2502 if (wlan_tag == 1) {
2503 if (radius_port)
2504 dut->ap_radius_port = radius_port;
2505 radius_ipaddr = dut->ap_radius_ipaddr;
2506 radius_password = dut->ap_radius_password;
2507 } else if (wlan_tag == 2) {
2508 if (radius_port)
2509 dut->ap2_radius_port = radius_port;
2510 radius_ipaddr = dut->ap2_radius_ipaddr;
2511 radius_password = dut->ap2_radius_password;
2512 }
2513
2514 val = get_param(cmd, "IPADDR");
2515 if (val) {
2516 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2517 return -1;
2518 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2519 "%s", val);
2520 }
2521
2522 val = get_param(cmd, "PASSWORD");
2523 if (val) {
2524 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2525 return -1;
2526 snprintf(radius_password,
2527 sizeof(dut->ap_radius_password), "%s", val);
2528 }
2529
2530 return 1;
2531}
2532
2533
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002534static void owrt_ap_set_qcawifi(struct sigma_dut *dut, const char *key,
2535 const char *val)
2536{
2537 if (!val) {
2538 run_system_wrapper(dut, "uci delete wireless.qcawifi.%s", key);
2539 return;
2540 }
2541
2542 run_system(dut, "uci set wireless.qcawifi=qcawifi");
2543 run_system_wrapper(dut, "uci set wireless.qcawifi.%s=%s", key, val);
2544}
2545
2546
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2548 const char *key, const char *val)
2549{
2550 char buf[100];
2551
2552 if (val == NULL) {
2553 snprintf(buf, sizeof(buf),
2554 "uci delete wireless.wifi%d.%s", id, key);
2555 run_system(dut, buf);
2556 return;
2557 }
2558
2559 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2560 id, key, val);
2561 run_system(dut, buf);
2562}
2563
2564
2565static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2566 const char *key, const char *val)
2567{
2568 char buf[256];
2569
2570 if (val == NULL) {
2571 snprintf(buf, sizeof(buf),
2572 "uci del_list wireless.wifi%d.%s", id, key);
2573 run_system(dut, buf);
2574 return;
2575 }
2576
2577 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2578 id, key, val);
2579 run_system(dut, buf);
2580}
2581
2582
2583static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2584 const char *val)
2585{
2586 char buf[256];
2587
2588 if (val == NULL) {
2589 snprintf(buf, sizeof(buf),
2590 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2591 run_system(dut, buf);
2592 return;
2593 }
2594
2595 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2596 id, key, val);
2597 run_system(dut, buf);
2598}
2599
2600
2601static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2602 const char *key, const char *val)
2603{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002604 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002605
2606 if (val == NULL) {
2607 snprintf(buf, sizeof(buf),
2608 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2609 run_system(dut, buf);
2610 return;
2611 }
2612
2613 snprintf(buf, sizeof(buf),
2614 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2615 id, key, val);
2616 run_system(dut, buf);
2617}
2618
2619
2620static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2621 const char *val)
2622{
2623 char buf[256];
Jouni Malinen3aa72862019-05-29 23:14:51 +03002624 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002625
2626 if (val == NULL) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002627 res = snprintf(buf, sizeof(buf),
2628 "uci delete wireless.@wifi-iface[%d].%s",
2629 id, key);
2630 if (res >= 0 && res < sizeof(buf))
2631 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002632 return;
2633 }
2634
Jouni Malinen3aa72862019-05-29 23:14:51 +03002635 run_system(dut, "uci add wireless wifi-iface");
2636 res = snprintf(buf, sizeof(buf),
2637 "uci set wireless.@wifi-iface[%d].%s=%s",
2638 id, key, val);
2639 if (res >= 0 && res < sizeof(buf))
2640 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002641 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2642 id, "network", "lan");
2643 run_system(dut, buf);
2644 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2645 id, "mode", "ap");
2646 run_system(dut, buf);
2647 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2648 id, "encryption", "none");
2649 run_system(dut, buf);
2650}
2651
2652
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002653#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002654static int owrt_ap_config_radio(struct sigma_dut *dut)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002655{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002656 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002657 int radio_count, radio_no;
2658 char buf[64];
2659
2660 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2661 radio_count++) {
2662 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2663 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2664 if (!sigma_radio_ifname[radio_no] ||
2665 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2666 continue;
2667 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2668 owrt_ap_set_vap(dut, radio_count, "device", buf);
2669 radio_id[radio_no] = radio_count;
2670 }
2671 }
2672
2673 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2674 switch (dut->ap_mode) {
2675 case AP_11g:
2676 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2677 break;
2678 case AP_11b:
2679 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2680 break;
2681 case AP_11ng:
2682 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2683 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2684 break;
2685 case AP_11a:
2686 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2687 break;
2688 case AP_11na:
2689 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2690 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2691 break;
2692 case AP_11ac:
2693 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2694 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2695 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002696 case AP_11ax:
2697 if (dut->ap_channel >= 36) {
2698 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axa");
2699 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2700 } else {
2701 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11axg");
2702 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2703 }
2704 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002705 case AP_inval:
2706 sigma_dut_print(dut, DUT_MSG_ERROR,
2707 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002708 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002709 default:
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 }
2714
2715 if (dut->ap_is_dual) {
2716 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2717 switch (dut->ap_mode_1) {
2718 case AP_11g:
2719 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2720 break;
2721 case AP_11b:
2722 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2723 break;
2724 case AP_11ng:
2725 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2726 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2727 break;
2728 case AP_11a:
2729 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2730 break;
2731 case AP_11na:
2732 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2733 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2734 break;
2735 case AP_11ac:
2736 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2737 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2738 break;
Priyadharshini Gowthaman4401cee2019-11-21 14:38:33 -08002739 case AP_11ax:
2740 if (dut->ap_channel >= 36) {
2741 owrt_ap_set_radio(dut, radio_id[1],
2742 "hwmode", "11axa");
2743 owrt_ap_set_radio(dut, radio_id[1],
2744 "htmode", "HT80");
2745 } else {
2746 owrt_ap_set_radio(dut, radio_id[1],
2747 "hwmode", "11axg");
2748 owrt_ap_set_radio(dut, radio_id[1],
2749 "htmode", "HT20");
2750 }
2751 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002752 case AP_inval:
2753 sigma_dut_print(dut, DUT_MSG_ERROR,
2754 "MODE NOT SPECIFIED!");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002755 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002756 default:
2757 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2758 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2759 break;
2760 }
2761
2762 }
2763
2764 /* Channel */
2765 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2766 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2767
2768 switch (dut->ap_chwidth) {
2769 case AP_20:
2770 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2771 break;
2772 case AP_40:
2773 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2774 break;
2775 case AP_80:
2776 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2777 break;
2778 case AP_160:
2779 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2780 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002781 case AP_80_80:
2782 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2783 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002784 case AP_AUTO:
2785 default:
2786 break;
2787 }
2788
2789 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2790 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2791 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2792 }
2793
2794 if (dut->ap_is_dual) {
2795 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2796 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2797 }
2798
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002799 /* Country Code */
2800 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2801 const char *country;
2802
2803 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2804 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002805 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002806 if (dut->ap_is_dual)
2807 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002808 } else if (dut->ap_countrycode[0]) {
2809 owrt_ap_set_radio(dut, radio_id[0], "country",
2810 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002811 }
2812
2813 if (dut->ap_disable_protection == 1) {
2814 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2815 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2816 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2817 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2818 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002819
2820 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002821 get_driver_type(dut) == DRIVER_OPENWRT)
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002822 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002823
2824 if (dut->ap_mbssid == VALUE_ENABLED)
2825 owrt_ap_set_qcawifi(dut, "mbss_ie_enable", "1");
2826
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002827 if (dut->program == PROGRAM_HE) {
2828 owrt_ap_set_radio(dut, radio_id[0], "he_bsscolor", "'1 1'");
2829 if (dut->ap_is_dual)
2830 owrt_ap_set_radio(dut, radio_id[1], "he_bsscolor",
2831 "'2 1'");
Priyadharshini Gowthaman7d07cd02019-11-22 14:26:02 -08002832 owrt_ap_set_qcawifi(dut, "ap_bss_color_collision_detection",
2833 "1");
Priyadharshini Gowthamanb8c93582019-11-13 15:31:46 -08002834 }
2835
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07002836 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002837}
2838
2839
2840static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2841{
2842 char buf[256];
2843
2844 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2845 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2846 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2847 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2848
2849 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2850 "'eng:Wi-Fi Alliance'");
2851
2852 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2853 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2854
2855 if (dut->ap_wan_metrics == 1)
2856 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2857 "'01:2500:384:0:0:10'");
2858 else if (dut->ap_wan_metrics == 1)
2859 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2860 "'01:1500:384:20:20:10'");
2861 else if (dut->ap_wan_metrics == 2)
2862 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2863 "'01:1500:384:20:20:10'");
2864 else if (dut->ap_wan_metrics == 3)
2865 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2866 "'01:2000:1000:20:20:10'");
2867 else if (dut->ap_wan_metrics == 4)
2868 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2869 "'01:8000:1000:20:20:10'");
2870 else if (dut->ap_wan_metrics == 5)
2871 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2872 "'01:9000:5000:20:20:10'");
2873
2874 if (dut->ap_conn_capab == 1) {
2875 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2876 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2877 "'6:20:1'");
2878 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2879 "'6:22:0'");
2880 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2881 "'6:80:1'");
2882 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2883 "'6:443:1'");
2884 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2885 "'6:1723:0'");
2886 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2887 "'6:5060:0'");
2888 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2889 "'17:500:1'");
2890 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2891 "'17:5060:0'");
2892 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2893 "'17:4500:1'");
2894 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2895 "'50:0:1'");
2896 } else if (dut->ap_conn_capab == 2) {
2897 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2898 "'6:80:1'");
2899 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2900 "'6:443:1'");
2901 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2902 "'17:5060:1'");
2903 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2904 "'6:5060:1'");
2905 } else if (dut->ap_conn_capab == 3) {
2906 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2907 "'6:80:1'");
2908 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2909 "'6:443:1'");
2910 }
2911
2912 if (dut->ap_oper_class == 1)
2913 snprintf(buf, sizeof(buf), "%s", "51");
2914 else if (dut->ap_oper_class == 2)
2915 snprintf(buf, sizeof(buf), "%s", "73");
2916 else if (dut->ap_oper_class == 3)
2917 snprintf(buf, sizeof(buf), "%s", "5173");
2918
2919 if (dut->ap_oper_class)
2920 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2921
2922 if (dut->ap_osu_provider_list) {
2923 char *osu_friendly_name = NULL;
2924 char *osu_icon = NULL;
2925 char *osu_ssid = NULL;
2926 char *osu_nai = NULL;
2927 char *osu_service_desc = NULL;
2928 char *hs20_icon_filename = NULL;
2929 char hs20_icon[150];
2930 int osu_method;
2931
2932 hs20_icon_filename = "icon_red_zxx.png";
2933 if (dut->ap_osu_icon_tag == 2)
2934 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2935 snprintf(hs20_icon, sizeof(hs20_icon),
2936 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2937 hs20_icon_filename);
2938 osu_icon = "icon_red_zxx.png";
2939 osu_ssid = "OSU";
2940 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2941 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2942 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2943 dut->ap_osu_method[0];
2944
2945 if (strlen(dut->ap_osu_server_uri[0]))
2946 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2947 dut->ap_osu_server_uri[0]);
2948 else
2949 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2950 "'https://osu-server.r2-testbed.wi-fi.org/'");
2951 switch (dut->ap_osu_provider_list) {
2952 case 1:
2953 case 101:
2954 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2955 "'eng:SP Red Test Only'");
2956 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2957 "'eng:Free service for test purpose'");
2958 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2959 hs20_icon);
2960
2961 hs20_icon_filename = "icon_red_eng.png";
2962 if (dut->ap_osu_icon_tag == 2)
2963 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2964
2965 snprintf(hs20_icon, sizeof(hs20_icon),
2966 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2967 hs20_icon_filename);
2968 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2969 "icon_red_eng.png");
2970 break;
2971 case 2:
2972 case 102:
2973 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2974 "'eng:Wireless Broadband Alliance'");
2975 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2976 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002977 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002978 if (dut->ap_osu_icon_tag == 2)
2979 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2980
2981 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002982 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002983 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002984 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002985 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2986 break;
2987 case 3:
2988 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03002989 osu_friendly_name = "'spa:SP Red Test Only'";
2990 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002991 break;
2992 case 4:
2993 case 104:
2994 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002995 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002996 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2997 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002998 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002999 if (dut->ap_osu_icon_tag == 2)
3000 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3001
3002 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003003 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003004 hs20_icon_filename);
3005 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3006 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003007 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003008
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003009 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003010 if (dut->ap_osu_icon_tag == 2)
3011 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3012
3013 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003014 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003015 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003016 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003017 break;
3018 case 5:
3019 case 105:
3020 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003021 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003022 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3023 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003024 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003025
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003026 hs20_icon_filename = "icon_orange_zxx.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 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003032 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003033 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003034 break;
3035 case 6:
3036 case 106:
3037 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3038 "'eng:SP Green Test Only'");
3039 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3040 "'kor:SP 초록 테스트 전용'");
3041
3042 hs20_icon_filename = "icon_green_zxx.png";
3043 if (dut->ap_osu_icon_tag == 2)
3044 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3045
3046 snprintf(hs20_icon, sizeof(hs20_icon),
3047 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
3048 hs20_icon_filename);
3049 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3050 hs20_icon);
3051
3052 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3053 "'icon_green_zxx.png'");
3054 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
3055 dut->ap_osu_method[0];
3056
3057 snprintf(buf, sizeof(buf), "%d", osu_method);
3058 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
3059
3060 if (strlen(dut->ap_osu_server_uri[1]))
3061 owrt_ap_set_list_vap(dut, vap_id,
3062 "osu_server_uri",
3063 dut->ap_osu_server_uri[1]);
3064 else
3065 owrt_ap_set_list_vap(dut, vap_id,
3066 "osu_server_uri",
3067 "'https://osu-server.r2-testbed.wi-fi.org/'");
3068
3069 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3070 "'eng:SP Orange Test Only'");
3071
3072 hs20_icon_filename = "icon_orange_zxx.png";
3073 if (dut->ap_osu_icon_tag == 2)
3074 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3075
3076 snprintf(hs20_icon, sizeof(hs20_icon),
3077 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3078 hs20_icon_filename);
3079
3080 osu_icon = "icon_orange_zxx.png";
3081 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
3082 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
3083 dut->ap_osu_method[1];
3084 osu_service_desc = NULL;
3085 break;
3086 case 7:
3087 case 107:
3088 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003089 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003090 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3091 "'eng:Free service for test purpose'");
3092
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003093 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003094 if (dut->ap_osu_icon_tag == 2)
3095 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3096
3097 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003098 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003099 hs20_icon_filename);
3100 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
3101 hs20_icon);
3102
3103 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003104 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03003105 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003106
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003107 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003108 if (dut->ap_osu_icon_tag == 2)
3109 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3110
3111 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003112 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003113 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03003114 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003115 break;
3116 case 8:
3117 case 108:
3118 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3119 "'eng:SP Red Test Only'");
3120 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3121 "'eng:Free service for test purpose'");
3122 osu_ssid = "OSU-Encrypted";
3123 osu_nai = "'anonymous@hotspot.net'";
3124 break;
3125 case 9:
3126 case 109:
3127 osu_ssid = "OSU-OSEN";
3128 osu_nai = "'test-anonymous@wi-fi.org'";
3129 osu_friendly_name = "'eng:SP Orange Test Only'";
3130 hs20_icon_filename = "icon_orange_zxx.png";
3131 if (dut->ap_osu_icon_tag == 2)
3132 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3133
3134 snprintf(hs20_icon, sizeof(hs20_icon),
3135 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
3136 hs20_icon_filename);
3137 osu_icon = "icon_orange_zxx.png";
3138 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
3139 dut->ap_osu_method[0];
3140 osu_service_desc = NULL;
3141 break;
3142 default:
3143 break;
3144 }
3145
3146 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03003147 if (dut->ap_tag_ssid[0][0] &&
3148 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003149 dut->ap_osu_ssid) != 0 &&
3150 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003151 sigma_dut_print(dut, DUT_MSG_ERROR,
3152 "OSU_SSID and WLAN_TAG2 SSID differ");
3153 return -2;
3154 }
3155
3156 snprintf(buf, sizeof(buf), "'\"%s\"'",
3157 dut->ap_osu_ssid);
3158 } else {
3159 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
3160 }
3161
3162 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
3163
3164
3165 if (osu_friendly_name)
3166 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
3167 osu_friendly_name);
3168 if (osu_service_desc)
3169 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
3170 osu_service_desc);
3171 if (osu_nai)
3172 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
3173
3174 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
3175
3176 if (osu_icon)
3177 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
3178 osu_icon);
3179
3180 if (dut->ap_osu_provider_list > 100) {
3181 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3182 "0");
3183 } else {
3184 snprintf(buf, sizeof(buf), "%d", osu_method);
3185 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
3186 buf);
3187 }
3188 }
3189
3190 return 0;
3191}
3192
3193
Jouni Malinen13701222019-02-19 12:10:53 +02003194static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
3195 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003196{
3197 unsigned char bssid[ETH_ALEN];
3198 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
3199 int preference = 0xff;
3200
Jouni Malinen13701222019-02-19 12:10:53 +02003201 if (get_hwaddr(ifname, bssid) < 0)
3202 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003203 snprintf(anqp_string, str_size,
3204 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
3205 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
3206 preference,
3207 dummy_mac[0], dummy_mac[1], dummy_mac[2],
3208 dummy_mac[3], dummy_mac[4], dummy_mac[5],
3209 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02003210 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003211}
3212
3213
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003214static void get_if_name(struct sigma_dut *dut, char *ifname_str,
3215 size_t str_size, int wlan_tag)
3216{
Jouni Malinenf8984642017-10-12 00:02:37 +03003217 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003218 enum driver_type drv;
3219
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003220 drv = get_driver_type(dut);
Jouni Malinenf8984642017-10-12 00:02:37 +03003221 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
3222 ifname = dut->hostapd_ifname;
3223 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003224 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
3225 dut->ap_mode == AP_11ac) &&
3226 if_nametoindex("ath1") > 0)
3227 ifname = "ath1";
3228 else
3229 ifname = "ath0";
3230 } else if (drv == DRIVER_OPENWRT) {
3231 if (sigma_radio_ifname[0] &&
3232 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3233 ifname = "ath2";
3234 else if (sigma_radio_ifname[0] &&
3235 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3236 ifname = "ath1";
3237 else
3238 ifname = "ath0";
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003239 } else if (drv == DRIVER_WIL6210) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003240 ifname = get_main_ifname(dut);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003241 } else {
3242 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
3243 dut->ap_mode == AP_11ac) &&
3244 if_nametoindex("wlan1") > 0)
3245 ifname = "wlan1";
3246 else
3247 ifname = "wlan0";
3248 }
3249
3250 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
3251 /* Handle tagged-ifname only on OPENWRT for now */
3252 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08003253 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
3254 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03003255 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003256 } else {
3257 snprintf(ifname_str, str_size, "%s", ifname);
3258 }
3259}
3260
3261
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003262static int owrt_ap_config_vap(struct sigma_dut *dut)
3263{
3264 char buf[256], *temp;
Jouni Malinen3aa72862019-05-29 23:14:51 +03003265 int vap_id = 0, vap_count, i, j, res;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003266 const char *ifname;
3267 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003268
priyadharshini gowthaman73561262018-02-20 13:24:59 -08003269 if (sigma_radio_ifname[0] &&
3270 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
3271 ifname = "ath2";
3272 else if (sigma_radio_ifname[0] &&
3273 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
3274 ifname = "ath1";
3275 else
3276 ifname = "ath0";
3277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003278 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003279 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003280
3281 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
3282 if (sigma_radio_ifname[vap_id] &&
3283 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
3284 break;
3285 }
3286 if (vap_id == MAX_RADIO)
3287 continue;
3288
3289 /* Single VAP configuration */
3290 if (!dut->ap_is_dual)
3291 vap_id = vap_count;
3292
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003293 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
3294 /*
3295 * We keep a separate array of ap_tag_ssid and
3296 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
3297 * So j=0 => WLAN_TAG = 2
3298 */
3299 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003300
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003301 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
3302 (dut->ap_interface_5g || dut->ap_interface_2g)) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03003303 res = snprintf(
3304 dut->ap_tag_ssid[wlan_tag - 2],
3305 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
3306 "%s-owe", dut->ap_ssid);
3307 if (res < 0 ||
3308 res >= sizeof(dut->ap_tag_ssid[wlan_tag -
3309 2]))
3310 dut->ap_tag_ssid[wlan_tag - 2][0] =
3311 '\0';
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003312 }
3313
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003314 if (dut->ap_tag_ssid[j][0] == '\0')
3315 continue;
3316
3317 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
3318 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
3319 "device", buf);
3320 /* SSID */
3321 snprintf(buf, sizeof(buf), "\"%s\"",
3322 dut->ap_tag_ssid[j]);
3323 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3324 "ssid", buf);
3325
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003326 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3327 dut->ap_tag_ssid[0][0] &&
3328 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3329 /* OWE transition mode */
3330 snprintf(buf, sizeof(buf), "%s", ifname);
3331 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3332 "owe_transition_ifname", buf);
3333 }
3334
3335 if (dut->ap_key_mgmt == AP_OPEN &&
3336 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3337 /* OWE transition mode */
3338 snprintf(buf, sizeof(buf), "%s", ifname);
3339 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3340 "owe_transition_ifname", buf);
3341 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3342 "hidden", "1");
3343 }
3344
Jouni Malinen6be21c82018-08-01 18:47:24 +03003345 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003346 unsigned char self_mac[ETH_ALEN];
3347 char mac_str[20];
3348
3349 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3350 "mobility_domain",
3351 dut->ap_mobility_domain);
3352 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Jouni Malinen9f943312019-08-19 23:49:16 +03003353 "ft_over_ds",
3354 dut->ap_ft_ds == VALUE_ENABLED ?
3355 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003356 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3357 "ieee80211r", "1");
3358 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3359 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02003360 if (get_hwaddr(sigma_radio_ifname[0],
3361 self_mac) < 0)
3362 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003363 snprintf(mac_str, sizeof(mac_str),
3364 "%02x:%02x:%02x:%02x:%02x:%02x",
3365 self_mac[0], self_mac[1], self_mac[2],
3366 self_mac[3], self_mac[4], self_mac[5]);
3367 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3368 "ap_macaddr", mac_str);
3369 snprintf(mac_str, sizeof(mac_str),
3370 "%02x%02x%02x%02x%02x%02x",
3371 self_mac[0], self_mac[1], self_mac[2],
3372 self_mac[3], self_mac[4], self_mac[5]);
3373 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3374 "r1_key_holder", mac_str);
3375 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3376 "ft_psk_generate_local", "1");
3377 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3378 "kh_key_hex",
3379 "000102030405060708090a0b0c0d0e0f");
3380 snprintf(mac_str, sizeof(mac_str),
3381 "%02x:%02x:%02x:%02x:%02x:%02x",
3382 dut->ft_bss_mac_list[0][0],
3383 dut->ft_bss_mac_list[0][1],
3384 dut->ft_bss_mac_list[0][2],
3385 dut->ft_bss_mac_list[0][3],
3386 dut->ft_bss_mac_list[0][4],
3387 dut->ft_bss_mac_list[0][5]);
3388 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3389 "ap2_macaddr", mac_str);
3390 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3391 "ap2_r1_key_holder", mac_str);
3392 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3393 "nasid2", "nas2.example.com");
3394 }
3395
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003396 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
3397 wlan_tag == 2) {
3398 /* Only supported for WLAN_TAG=2 */
3399 owrt_ap_set_vap(dut, vap_count + 1, "osen",
3400 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003401 snprintf(buf, sizeof(buf), "wpa2");
3402 owrt_ap_set_vap(dut, vap_count + 1,
3403 "encryption", buf);
3404 snprintf(buf, sizeof(buf), "%s",
3405 dut->ap2_radius_ipaddr);
3406 owrt_ap_set_vap(dut, vap_count + 1,
3407 "auth_server", buf);
3408 snprintf(buf, sizeof(buf), "%d",
3409 dut->ap2_radius_port);
3410 owrt_ap_set_vap(dut, vap_count + 1,
3411 "auth_port", buf);
3412 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003413 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003414 owrt_ap_set_vap(dut, vap_count + 1,
3415 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003416 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
3417 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3418 "encryption", "psk2+ccmp");
3419 snprintf(buf, sizeof(buf), "\"%s\"",
3420 dut->ap_passphrase);
3421 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3422 "key", buf);
3423 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003424 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003425 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003426 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3427 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3428 "owe", "1");
3429 snprintf(buf, sizeof(buf), "ccmp");
3430 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3431 "encryption", buf);
3432 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3433 "ieee80211w", "2");
3434 if (dut->ap_sae_groups) {
3435 snprintf(buf, sizeof(buf), "\'%s\'",
3436 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003437 owrt_ap_set_list_vap(dut, vap_count +
3438 (wlan_tag - 1),
3439 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003440 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003441 }
3442 }
3443
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003444 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003445 if (dut->program == PROGRAM_MBO &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003446 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003447 unsigned char self_mac[ETH_ALEN];
3448 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003449 char anqp_string[200];
3450
Jouni Malinen13701222019-02-19 12:10:53 +02003451 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3452 anqp_string,
3453 sizeof(anqp_string)) < 0)
3454 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003455 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3456 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003457
Jouni Malinen6be21c82018-08-01 18:47:24 +03003458 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003459 owrt_ap_set_vap(dut, vap_count,
3460 "mobility_domain",
3461 dut->ap_mobility_domain);
3462 owrt_ap_set_vap(dut, vap_count,
Jouni Malinen9f943312019-08-19 23:49:16 +03003463 "ft_over_ds",
3464 dut->ap_ft_ds == VALUE_ENABLED ?
3465 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003466 owrt_ap_set_vap(dut, vap_count,
3467 "ieee80211r", "1");
3468 owrt_ap_set_vap(dut, vap_count,
3469 "nasid", "nas1.example.com");
3470 get_hwaddr(sigma_radio_ifname[0], self_mac);
3471 snprintf(mac_str, sizeof(mac_str),
3472 "%02x:%02x:%02x:%02x:%02x:%02x",
3473 self_mac[0], self_mac[1], self_mac[2],
3474 self_mac[3], self_mac[4], self_mac[5]);
3475 owrt_ap_set_vap(dut, vap_count,
3476 "ap_macaddr", mac_str);
3477 snprintf(mac_str, sizeof(mac_str),
3478 "%02x%02x%02x%02x%02x%02x",
3479 self_mac[0], self_mac[1], self_mac[2],
3480 self_mac[3], self_mac[4], self_mac[5]);
3481 owrt_ap_set_vap(dut, vap_count,
3482 "r1_key_holder", mac_str);
3483 owrt_ap_set_vap(dut, vap_count,
3484 "ft_psk_generate_local", "1");
3485 owrt_ap_set_vap(dut, vap_count,
3486 "kh_key_hex",
3487 "000102030405060708090a0b0c0d0e0f");
3488 snprintf(mac_str, sizeof(mac_str),
3489 "%02x:%02x:%02x:%02x:%02x:%02x",
3490 dut->ft_bss_mac_list[0][0],
3491 dut->ft_bss_mac_list[0][1],
3492 dut->ft_bss_mac_list[0][2],
3493 dut->ft_bss_mac_list[0][3],
3494 dut->ft_bss_mac_list[0][4],
3495 dut->ft_bss_mac_list[0][5]);
3496 owrt_ap_set_vap(dut, vap_count,
3497 "ap2_macaddr", mac_str);
3498 owrt_ap_set_vap(dut, vap_count,
3499 "ap2_r1_key_holder", mac_str);
3500 owrt_ap_set_vap(dut, vap_count,
3501 "nasid2", "nas2.example.com");
3502 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003503 }
3504
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003505 if (dut->ap_oce == VALUE_ENABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003506 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003507 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3508 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3509 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3510
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003511 if (dut->ap_80plus80 == 1)
3512 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3513
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003514 if (dut->ap_akm == 1) {
3515 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3516 "3600");
3517 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3518 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3519 "1");
3520 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3521 "1234");
3522 owrt_ap_set_vap(dut, vap_id,
3523 "erp_send_reauth_start", "1");
3524 }
3525
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003526 if (dut->ap_filshlp == VALUE_ENABLED) {
3527 struct ifreq ifr;
3528 char *ifname;
3529 int s;
3530 struct sockaddr_in *ipaddr;
3531
3532 s = socket(AF_INET, SOCK_DGRAM, 0);
3533 if (s < 0) {
3534 sigma_dut_print(dut, DUT_MSG_ERROR,
3535 "Failed to open socket");
3536 return -1;
3537 }
3538 ifr.ifr_addr.sa_family = AF_INET;
3539
3540 memset(&ifr, 0, sizeof(ifr));
3541 ifname = "br-lan";
3542 strlcpy(ifr.ifr_name, ifname,
3543 sizeof(ifr.ifr_name));
3544 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3545 perror("ioctl");
3546 close(s);
3547 return -1;
3548 }
3549
3550 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3551 snprintf(buf, sizeof(buf), "%s",
3552 inet_ntoa(ipaddr->sin_addr));
3553 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3554 buf);
3555 snprintf(buf, sizeof(buf), "%s",
3556 dut->ap_dhcpserv_ipaddr);
3557 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3558 buf);
3559 owrt_ap_set_vap(dut, vap_id,
3560 "dhcp_rapid_commit_proxy", "1");
3561 owrt_ap_set_vap(dut, vap_id,
3562 "fils_hlp_wait_time", "300");
3563 }
3564
3565 if (dut->ap_filsdscv == VALUE_ENABLED) {
3566 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3567 "1");
3568 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3569 "20");
3570 }
3571 }
3572
3573 if (dut->ap_filsdscv == VALUE_DISABLED) {
3574 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3575 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3576 }
3577
3578 if (dut->ap_oce == VALUE_DISABLED &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003579 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003580 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3581 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3582 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3583
3584 if (dut->ap_filsdscv == VALUE_DISABLED) {
3585 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3586 "0");
3587 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3588 "0");
3589 }
3590
3591 if (dut->device_type == AP_testbed)
3592 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3593 }
3594
3595 /* NAIRealm */
3596 if (dut->ap_nairealm_int == 1) {
3597 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3598 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3599 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3600 }
3601
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003602 /* SSID */
3603 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3604 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3605
3606 /* Encryption */
3607 switch (dut->ap_key_mgmt) {
3608 case AP_OPEN:
3609 if (dut->ap_cipher == AP_WEP) {
3610 owrt_ap_set_vap(dut, vap_count, "encryption",
3611 "wep-mixed");
3612 owrt_ap_set_vap(dut, vap_count, "key",
3613 dut->ap_wepkey);
3614 } else {
3615 owrt_ap_set_vap(dut, vap_count, "encryption",
3616 "none");
3617 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003618 if (dut->ap_key_mgmt == AP_OPEN &&
3619 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3620 /* OWE transition mode */
3621 snprintf(ifname2, sizeof(ifname2), "%s1",
3622 ifname);
3623 owrt_ap_set_vap(dut, vap_count,
3624 "owe_transition_ifname",
3625 ifname2);
3626 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003627 break;
3628 case AP_WPA2_PSK:
3629 case AP_WPA2_PSK_MIXED:
3630 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003631 case AP_WPA2_SAE:
3632 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003633 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3634 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003635 snprintf(buf, sizeof(buf), "psk2");
3636 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3637 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003638 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3639 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003640 } else {
3641 snprintf(buf, sizeof(buf), "psk");
3642 }
3643
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003644 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3645 if (dut->ap_cipher == AP_CCMP_TKIP)
3646 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3647 else if (dut->ap_cipher == AP_TKIP)
3648 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003649 else if (dut->ap_cipher == AP_GCMP_128)
3650 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003651 else
3652 strlcat(buf, "+ccmp", sizeof(buf));
3653 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003654
3655 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003656
3657 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3658 snprintf(buf, sizeof(buf), "\"%s\"",
3659 dut->ap_psk);
3660 owrt_ap_set_vap(dut, vap_count, "key", buf);
3661 } else {
3662 snprintf(buf, sizeof(buf), "\"%s\"",
3663 dut->ap_passphrase);
3664 owrt_ap_set_vap(dut, vap_count, "key", buf);
3665 }
3666
3667 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3668 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3669 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3670 else
3671 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3672
3673 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3674 snprintf(buf, sizeof(buf), "%s",
3675 dut->ap_passphrase);
3676 owrt_ap_set_vap(dut, vap_count, "sae_password",
3677 buf);
3678 } else {
3679 snprintf(buf, sizeof(buf), "%s",
3680 dut->ap_passphrase);
3681 owrt_ap_set_vap(dut, vap_count,
3682 "wpa_passphrase", buf);
3683 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003684 break;
3685 case AP_WPA2_EAP:
3686 case AP_WPA2_EAP_MIXED:
3687 case AP_WPA_EAP:
3688 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3689 snprintf(buf, sizeof(buf), "wpa2");
3690 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3691 snprintf(buf, sizeof(buf), "wpa-mixed");
3692 } else {
3693 snprintf(buf, sizeof(buf), "wpa");
3694 }
3695
Peng Xu591be452017-05-10 17:27:28 -07003696 if (dut->ap_cipher == AP_CCMP_TKIP)
3697 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3698 else if (dut->ap_cipher == AP_TKIP)
3699 strlcat(buf, "+tkip", sizeof(buf));
3700 else
3701 strlcat(buf, "+ccmp", sizeof(buf));
3702
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003703 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3704 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3705 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3706 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3707 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3708 snprintf(buf, sizeof(buf), "%s",
3709 dut->ap_radius_password);
3710 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3711 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003712 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003713 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003714 case AP_WPA2_FT_EAP:
3715 case AP_WPA2_FT_PSK:
3716 case AP_WPA2_EAP_SHA256:
3717 case AP_WPA2_PSK_SHA256:
3718 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003719 /* TODO */
3720 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003721 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003722 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3723 snprintf(buf, sizeof(buf), "gcmp");
3724 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3725 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3726 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3727 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3728 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3729 snprintf(buf, sizeof(buf), "%s",
3730 dut->ap_radius_password);
3731 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3732 snprintf(buf, sizeof(buf), "%d",
3733 dut->ap_group_mgmt_cipher);
3734 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3735 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003736 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003737 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003738 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3739 snprintf(buf, sizeof(buf), "ccmp");
3740 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3741 if (dut->ap_sae_groups) {
3742 snprintf(buf, sizeof(buf), "\'%s\'",
3743 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003744 owrt_ap_set_list_vap(dut, vap_count,
3745 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003746 }
3747
3748 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3749 dut->ap_tag_ssid[0][0] &&
3750 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3751 /* OWE transition mode */
3752 snprintf(ifname2, sizeof(ifname2), "%s1",
3753 ifname);
3754 owrt_ap_set_vap(dut, vap_count,
3755 "owe_transition_ifname",
3756 ifname2);
3757 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3758 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003759 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003760 }
3761
3762 if (!dut->ap_is_dual)
3763 break;
3764 }
3765
3766 if (dut->ap_is_dual)
3767 return 1;
3768
3769 /* PMF */
3770 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3771 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3772
3773 /* Add SHA256 */
3774 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3775 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3776
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003777 /* Add SHA384 for akmsuitetype 15 */
3778 if (dut->ap_akm == 1) {
3779 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3780 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3781 }
3782
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303783 /* Enable RSN preauthentication, if asked to */
3784 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3785 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3786
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003787 /* Hotspot 2.0 */
3788 if (dut->ap_hs2) {
3789 int ret;
3790
3791 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3792 if (ret)
3793 return ret;
3794 }
3795
3796 /* Interworking */
3797 if (dut->ap_interworking) {
3798 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3799 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3800 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3801 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3802 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3803 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3804 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3805 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3806 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3807 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3808
3809 if (dut->ap_gas_cb_delay > 0) {
3810 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3811 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3812 }
3813
3814 if (dut->ap_roaming_cons[0]) {
3815 char *rcons, *temp_ptr;
3816
3817 rcons = strdup(dut->ap_roaming_cons);
3818 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003819 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003820
3821 temp_ptr = strchr(rcons, ';');
3822
3823 if (temp_ptr)
3824 *temp_ptr++ = '\0';
3825
3826 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3827 rcons);
3828
3829 if (temp_ptr)
3830 owrt_ap_set_list_vap(dut, vap_id,
3831 "roaming_consortium",
3832 temp_ptr);
3833
3834 free(rcons);
3835 }
3836 }
3837
3838 if (dut->ap_venue_name) {
3839 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3840 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3841 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3842 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3843 }
3844
3845 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003846 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3847 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003848 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003849 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003850 }
3851
3852 if (dut->ap_nai_realm_list == 1) {
3853 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3854 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3855 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3856 "'0,wi-fi.org;example.com,13[5:6]'");
3857
3858 } else if (dut->ap_nai_realm_list == 2) {
3859 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3860 "'0,wi-fi.org,21[2:4][5:7]'");
3861 } else if (dut->ap_nai_realm_list == 3) {
3862 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3863 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3864 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3865 "'0,wi-fi.org;example.com,13[5:6]'");
3866 } else if (dut->ap_nai_realm_list == 4) {
3867 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3868 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3869 } else if (dut->ap_nai_realm_list == 5) {
3870 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3871 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3872 } else if (dut->ap_nai_realm_list == 6) {
3873 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3874 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3875 } else if (dut->ap_nai_realm_list == 7) {
3876 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3877 "'0,wi-fi.org,13[5:6]'");
3878 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3879 "'0,wi-fi.org,21[2:4][5:7]'");
3880 }
3881
3882 if (dut->ap_domain_name_list[0])
3883 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3884 dut->ap_domain_name_list);
3885
3886 if (dut->ap_ip_addr_type_avail)
3887 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3888 "'0c'");
3889
3890 temp = buf;
3891
3892 *temp++ = '\'';
3893
3894 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3895 if (i)
3896 *temp++ = ';';
3897
3898 snprintf(temp,
3899 sizeof(dut->ap_plmn_mcc[i]) +
3900 sizeof(dut->ap_plmn_mnc[i]) + 1,
3901 "%s,%s",
3902 dut->ap_plmn_mcc[i],
3903 dut->ap_plmn_mnc[i]);
3904
3905 temp += strlen(dut->ap_plmn_mcc[i]) +
3906 strlen(dut->ap_plmn_mnc[i]) + 1;
3907 }
3908
3909 *temp++ = '\'';
3910 *temp++ = '\0';
3911
3912 if (i)
3913 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3914
3915 if (dut->ap_qos_map_set == 1)
3916 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3917 else if (dut->ap_qos_map_set == 2)
3918 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3919
3920 /* Proxy-ARP */
3921 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3922 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3923
3924 /* DGAF */
3925 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3926 /* parse to hostapd */
3927 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3928 /* parse to wifi driver */
3929 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3930
3931 /* HCBSSLoad */
3932 if (dut->ap_bss_load) {
3933 unsigned int bssload = 0;
3934
3935 if (dut->ap_bss_load == 1) {
3936 /* STA count: 1, CU: 50, AAC: 65535 */
3937 bssload = 0x0132ffff;
3938 } else if (dut->ap_bss_load == 2) {
3939 /* STA count: 1, CU: 200, AAC: 65535 */
3940 bssload = 0x01c8ffff;
3941 } else if (dut->ap_bss_load == 3) {
3942 /* STA count: 1, CU: 75, AAC: 65535 */
3943 bssload = 0x014bffff;
3944 }
3945
3946 snprintf(buf, sizeof(buf), "%d", bssload);
3947 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3948 }
3949
3950 /* L2TIF */
3951 if (dut->ap_l2tif)
3952 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3953
3954 if (dut->ap_disable_protection == 1)
3955 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3956
Sunil Dutt77b213d2017-09-14 18:24:40 +03003957 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003958 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3959 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08003960 if (dut->program == PROGRAM_HE) {
3961 owrt_ap_set_vap(dut, vap_id, "he_subfer", "1");
3962 owrt_ap_set_vap(dut, vap_id, "cwmenable", "0");
3963 }
3964 } else {
3965 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
3966 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
3967 if (dut->program == PROGRAM_HE)
3968 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003969 }
3970
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08003971 if (dut->ap_mu_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003972 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08003973 if (dut->program == PROGRAM_HE) {
3974 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "1");
3975 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "1");
3976 }
3977 } else {
3978 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "0");
3979 if (dut->program == PROGRAM_HE) {
3980 owrt_ap_set_vap(dut, vap_id, "he_mubfer", "0");
3981 owrt_ap_set_vap(dut, vap_id, "he_mubfee", "0");
3982 }
3983 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003984
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303985 if (dut->ap_tx_stbc) {
3986 /* STBC and beamforming are mutually exclusive features */
3987 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3988 }
3989
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303990 /* enable dfsmode */
3991 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3992 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3993
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003994 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3995 char anqpval[1024];
3996
3997 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3998
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003999 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304000 snprintf(anqpval, sizeof(anqpval),
4001 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004002 dut->ap_val_lci, dut->ap_infoz);
4003 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4004 }
4005
4006 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05304007 snprintf(anqpval, sizeof(anqpval),
4008 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07004009 dut->ap_val_lcr);
4010 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4011 }
4012
4013 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
4014 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4015 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
4016 }
4017
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004018 if (dut->program == PROGRAM_MBO) {
4019 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
4020 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
4021 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07004022 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004023
4024 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
4025 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07004026 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
4027 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004028 }
4029
Jouni Malinen6be21c82018-08-01 18:47:24 +03004030 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004031 unsigned char self_mac[ETH_ALEN];
4032 char mac_str[20];
4033
Jouni Malinen9f943312019-08-19 23:49:16 +03004034 owrt_ap_set_vap(dut, vap_id, "ft_over_ds",
4035 dut->ap_ft_ds == VALUE_ENABLED ? "1" : "0");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004036 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02004037 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
4038 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004039 snprintf(mac_str, sizeof(mac_str),
4040 "%02x:%02x:%02x:%02x:%02x:%02x",
4041 self_mac[0], self_mac[1], self_mac[2],
4042 self_mac[3], self_mac[4], self_mac[5]);
4043 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004044 snprintf(mac_str, sizeof(mac_str),
4045 "%02x:%02x:%02x:%02x:%02x:%02x",
4046 self_mac[0], self_mac[1], self_mac[2],
4047 self_mac[3], self_mac[4], self_mac[5]);
4048 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004049 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
4050 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
4051 "000102030405060708090a0b0c0d0e0f");
4052 snprintf(mac_str, sizeof(mac_str),
4053 "%02x:%02x:%02x:%02x:%02x:%02x",
4054 dut->ft_bss_mac_list[0][0],
4055 dut->ft_bss_mac_list[0][1],
4056 dut->ft_bss_mac_list[0][2],
4057 dut->ft_bss_mac_list[0][3],
4058 dut->ft_bss_mac_list[0][4],
4059 dut->ft_bss_mac_list[0][5]);
4060 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08004061 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
4062 dut->ap_mobility_domain);
4063 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004064 }
4065
Jouni Malinen6be21c82018-08-01 18:47:24 +03004066 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
4067 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004068 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
4069 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004070 }
4071
Jouni Malinen6be21c82018-08-01 18:47:24 +03004072 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004073 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
4074 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07004075 }
4076
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08004077 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
4078 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
4079
priyadharshini gowthamande81f392017-12-28 15:28:49 -08004080 /* Enable/disable PMKSA caching, if asked to */
4081 if (dut->ap_pmksa == 1) {
4082 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
4083 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
4084 }
4085
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004086 if (dut->rsne_override) {
4087 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
4088 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
4089 }
4090
Jouni Malinen7960e3a2019-12-07 17:04:35 +02004091 if (dut->rsnxe_override_eapol)
4092 owrt_ap_set_vap(dut, vap_count, "rsnxe_override_eapol",
4093 dut->rsnxe_override_eapol);
4094
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004095 if (dut->sae_commit_override) {
4096 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
4097 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
4098 }
4099
4100 if (dut->ap_sae_groups) {
4101 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07004102 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004103 }
4104
Jouni Malinen11e55212019-11-22 21:46:59 +02004105 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
4106 const char *sae_pwe = NULL;
4107
4108 if (dut->sae_pwe == SAE_PWE_LOOP)
4109 sae_pwe = "0";
4110 else if (dut->sae_pwe == SAE_PWE_H2E)
4111 sae_pwe = "1";
4112 else if (dut->sae_h2e_default)
4113 sae_pwe = "2";
4114 if (sae_pwe)
4115 owrt_ap_set_vap(dut, vap_count, "sae_pwe", sae_pwe);
4116 }
4117
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004118 if (dut->sae_anti_clogging_threshold >= 0) {
4119 snprintf(buf, sizeof(buf), "%d",
4120 dut->sae_anti_clogging_threshold);
4121 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
4122 buf);
4123 }
4124
4125 if (dut->sae_reflection)
4126 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03004127 if (dut->sae_confirm_immediate)
4128 owrt_ap_set_vap(dut, vap_count, "sae_confirm_immediate", "1");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08004129
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07004130 if (dut->ap_he_dlofdma == VALUE_ENABLED && dut->ap_he_ppdu == PPDU_MU) {
4131 dut->ap_txBF = 0;
4132 dut->ap_mu_txBF = 0;
4133 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
4134 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
4135 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
4136 }
4137
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07004138 if (dut->program == PROGRAM_HE &&
4139 (dut->ap_txBF || dut->ap_he_ulofdma == VALUE_ENABLED ||
4140 dut->ap_he_mimo == MIMO_DL)) {
4141 switch (dut->ap_chwidth) {
4142 case AP_20:
4143 owrt_ap_set_vap(dut, vap_id, "chwidth", "0");
4144 break;
4145 case AP_40:
4146 owrt_ap_set_vap(dut, vap_id, "chwidth", "1");
4147 break;
4148 case AP_80:
4149 owrt_ap_set_vap(dut, vap_id, "chwidth", "2");
4150 break;
4151 case AP_160:
4152 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4153 break;
4154 case AP_80_80:
4155 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
4156 break;
4157 case AP_AUTO:
4158 default:
4159 break;
4160 }
4161 }
4162
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004163 return 1;
4164}
4165
4166
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004167static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
4168{
4169 char anqpval[1024];
4170 unsigned char addr[6];
4171 unsigned char addr2[6];
4172 struct ifreq ifr;
4173 char *ifname;
4174 int s;
4175 int vap_id = 0;
4176
4177 s = socket(AF_INET, SOCK_DGRAM, 0);
4178 if (s < 0) {
4179 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
4180 return -1;
4181 }
4182
4183 memset(&ifr, 0, sizeof(ifr));
4184 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004185 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004186 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4187 perror("ioctl");
4188 close(s);
4189 return -1;
4190 }
4191 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
4192
4193 memset(&ifr, 0, sizeof(ifr));
4194 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07004195 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004196 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
4197 perror("ioctl");
4198 close(s);
4199 return -1;
4200 }
4201 close(s);
4202 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
4203
4204 snprintf(anqpval, sizeof(anqpval),
4205 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
4206 dut->ap_val_lci, dut->ap_infoz,
4207 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
4208 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
4209
4210 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
4211 return 0;
4212}
4213
4214
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004215static int owrt_ap_post_config_commit(struct sigma_dut *dut,
4216 struct sigma_conn *conn,
4217 struct sigma_cmd *cmd)
4218{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004219 int ap_security = 0;
4220 int i;
4221
4222 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
4223 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
4224 ap_security = 1;
4225 }
4226 if (dut->ap_key_mgmt != AP_OPEN)
4227 ap_security = 1;
4228 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 /* allow some time for hostapd to start before returning
4230 * success */
4231 usleep(500000);
4232
4233 if (run_hostapd_cli(dut, "ping") != 0) {
4234 send_resp(dut, conn, SIGMA_ERROR,
4235 "errorCode,Failed to talk to hostapd");
4236 return 0;
4237 }
4238 }
4239
4240 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
4241 ath_ap_set_params(dut);
4242
4243 /* Send response */
4244 return 1;
4245}
4246
4247
4248static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
4249 struct sigma_conn *conn,
4250 struct sigma_cmd *cmd)
4251{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004252 if (dut->program == PROGRAM_DPP &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004253 get_driver_type(dut) == DRIVER_OPENWRT) {
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08004254 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
4255 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
4256 }
4257
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258 /* Stop the AP */
4259 run_system(dut, "wifi down");
4260
4261 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05304262 run_system(dut, "rm -rf /etc/config/wireless");
4263 switch (get_openwrt_driver_type()) {
4264 case OPENWRT_DRIVER_ATHEROS:
4265 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
4266 break;
4267 default:
4268 run_system(dut, "wifi detect > /etc/config/wireless");
4269 break;
4270 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004271
4272 /* Configure Radio & VAP, commit the config */
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07004273 if (owrt_ap_config_radio(dut) < 0)
4274 return ERROR_SEND_STATUS;
Jouni Malinen13701222019-02-19 12:10:53 +02004275 if (owrt_ap_config_vap(dut) < 0)
4276 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004277 run_system(dut, "uci commit");
4278
4279 /* Start AP */
4280 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004281 if (dut->program != PROGRAM_MBO &&
4282 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004283 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07004284 /*
4285 * MBO has a different ANQP element value which is set in
4286 * owrt_ap_config_vap().
4287 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07004288 owrt_ap_config_vap_anqp(dut);
4289 run_system(dut, "uci commit");
4290 run_system(dut, "wifi");
4291 }
4292
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004293 return owrt_ap_post_config_commit(dut, conn, cmd);
4294}
4295
4296
4297static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
4298{
4299 unsigned char bssid[6];
4300 char buf[100];
4301 char *ifname, *radio_name;
4302 int vap_id = 0;
4303
4304 if (sigma_radio_ifname[0] &&
4305 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4306 ifname = "ath2";
4307 radio_name = "wifi2";
4308 vap_id = 2;
4309 } else if (sigma_radio_ifname[0] &&
4310 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4311 ifname = "ath1";
4312 radio_name = "wifi1";
4313 vap_id = 1;
4314 } else {
4315 ifname = "ath0";
4316 radio_name = "wifi0";
4317 vap_id = 0;
4318 }
4319
4320 if (!get_hwaddr(ifname, bssid)) {
4321 snprintf(buf, sizeof(buf), "%s", bssid);
4322 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4323 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4324 "%02x:%02x:%02x:%02x:%02x:%02x",
4325 bssid[0], bssid[1], bssid[2], bssid[3],
4326 bssid[4], bssid[5]);
4327 } else {
4328 if (!get_hwaddr(radio_name, bssid)) {
4329 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
4330 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4331 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4332 "%02x:%02x:%02x:%02x:%02x:%02x",
4333 bssid[0], bssid[1], bssid[2], bssid[3],
4334 bssid[4], bssid[5]);
4335 } else {
4336 /* Select & enable/disable radios */
4337 if (sigma_radio_ifname[0] &&
4338 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
4339 /* We want to use wifi2 */
4340 owrt_ap_set_radio(dut, 0, "disabled", "1");
4341 owrt_ap_set_radio(dut, 1, "disabled", "1");
4342 owrt_ap_set_radio(dut, 2, "disabled", "0");
4343 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
4344 } else if (sigma_radio_ifname[0] &&
4345 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4346 /* We want to use wifi1 */
4347 owrt_ap_set_radio(dut, 0, "disabled", "1");
4348 owrt_ap_set_radio(dut, 1, "disabled", "0");
4349 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
4350 } else {
4351 /* We want to use wifi0 */
4352 owrt_ap_set_radio(dut, 0, "disabled", "0");
4353 owrt_ap_set_radio(dut, 1, "disabled", "1");
4354 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
4355 }
4356
4357 run_system(dut, "uci commit");
4358 run_system(dut, "wifi up");
4359
4360 if (!get_hwaddr(radio_name, bssid)) {
4361 snprintf(buf, sizeof(buf), "%s",
4362 dut->ap_hessid);
4363 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4364 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4365 "%02x:%02x:%02x:%02x:%02x:%02x",
4366 bssid[0], bssid[1], bssid[2], bssid[3],
4367 bssid[4], bssid[5]);
4368 }
4369 }
4370 }
4371}
4372
4373
Jouni Malinenf7222712019-06-13 01:50:21 +03004374static enum sigma_cmd_result cmd_ap_reboot(struct sigma_dut *dut,
4375 struct sigma_conn *conn,
4376 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004378 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004379 case DRIVER_ATHEROS:
4380 run_system(dut, "apdown");
4381 sleep(1);
4382 run_system(dut, "reboot");
4383 break;
4384 case DRIVER_OPENWRT:
4385 run_system(dut, "wifi down");
4386 sleep(1);
4387 run_system(dut, "reboot");
4388 break;
4389 default:
4390 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
4391 break;
4392 }
4393
4394 return 1;
4395}
4396
4397
4398int ascii2hexstr(const char *str, char *hex)
4399{
4400 int i, length;
4401
4402 length = strlen(str);
4403
4404 for (i = 0; i < length; i++)
4405 snprintf(hex + i * 2, 3, "%X", str[i]);
4406
4407 hex[length * 2] = '\0';
4408 return 1;
4409}
4410
4411
4412static int kill_process(struct sigma_dut *dut, char *proc_name,
4413 unsigned char is_proc_instance_one, int sig)
4414{
4415#ifdef __linux__
4416 struct dirent *dp, *dp_in;
4417 const char *direc = "/proc/";
4418 char buf[100];
4419 DIR *dir = opendir(direc);
4420 DIR *dir_in;
4421 FILE *fp;
4422 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304423 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004424 int ret = -1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004425
4426 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304427 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004428
4429 while ((dp = readdir(dir)) != NULL) {
4430 if (dp->d_type != DT_DIR)
4431 continue;
4432
Jouni Malinen3aa72862019-05-29 23:14:51 +03004433 res = snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
4434 if (res < 0 || res >= sizeof(buf))
4435 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004436 dir_in = opendir(buf);
4437 if (dir_in == NULL)
4438 continue;
4439 dp_in = readdir(dir_in);
4440 closedir(dir_in);
4441 if (dp_in == NULL)
4442 continue;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004443 res = snprintf(buf, sizeof(buf), "%s%s/stat",
4444 direc, dp->d_name);
4445 if (res < 0 || res >= sizeof(buf))
4446 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004447 fp = fopen(buf, "r");
4448 if (fp == NULL)
4449 continue;
4450 if (fgets(buf, 100, fp) == NULL)
4451 buf[0] = '\0';
4452 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304453 pid = strtok_r(buf, " ", &saveptr);
4454 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004455 if (pid && temp &&
4456 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
4457 sigma_dut_print(dut, DUT_MSG_INFO,
4458 "killing %s process with PID %s",
4459 proc_name, pid);
4460 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
4461 atoi(pid));
4462 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304463 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004464 if (is_proc_instance_one)
4465 break;
4466 }
4467 }
4468
4469 closedir(dir);
4470
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304471 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004472#else /* __linux__ */
4473 return -1;
4474#endif /* __linux__ */
4475}
4476
4477
4478static int run_ndc(struct sigma_dut *dut, char *buf)
4479{
4480 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
4481 sleep(2);
4482 return run_system(dut, buf);
4483}
4484
4485
4486static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
4487 const char *field, const char *value)
4488{
4489 FILE *fcfg, *ftmp;
4490 char buf[MAX_CONF_LINE_LEN + 1];
4491 int len, found = 0, res;
4492
4493 /* Open the configuration file */
4494 fcfg = fopen(pfile, "r");
4495 if (!fcfg) {
4496 sigma_dut_print(dut, DUT_MSG_ERROR,
4497 "Failed to open hostapd conf file");
4498 return -1;
4499 }
4500
4501 snprintf(buf, sizeof(buf), "%s~", pfile);
4502 /* Open a temporary file */
4503 ftmp = fopen(buf, "w+");
4504 if (!ftmp) {
4505 fclose(fcfg);
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "Failed to open temp buf");
4508 return -1;
4509 }
4510
4511 /* Read the values from the configuration file */
4512 len = strlen(field);
4513 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
4514 char *pline = buf;
4515
4516 /* commented line */
4517 if (buf[0] == '#')
4518 pline++;
4519
4520 /* Identify the configuration parameter to be updated */
4521 if (!found && strncmp(pline, field, len) == 0 &&
4522 pline[len] == '=') {
4523 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4524 found = 1;
4525 sigma_dut_print(dut, DUT_MSG_INFO,
4526 "Updated hostapd conf file");
4527 }
4528
4529 fprintf(ftmp, "%s", buf);
4530 }
4531
4532 if (!found) {
4533 /* Configuration line not found */
4534 /* Add the new line at the end of file */
4535 fprintf(ftmp, "%s=%s\n", field, value);
4536 sigma_dut_print(dut, DUT_MSG_INFO,
4537 "Adding a new line in hostapd conf file");
4538 }
4539
4540 fclose(fcfg);
4541 fclose(ftmp);
4542
4543 snprintf(buf, sizeof(buf), "%s~", pfile);
4544
4545 /* Restore the updated configuration file */
4546 res = rename(buf, pfile);
4547
4548 /* Remove the temporary file. Ignore the return value */
4549 unlink(buf);
4550
4551 /* chmod is needed because open() may not set permissions properly
4552 * depending on the current umask */
4553 if (chmod(pfile, 0660) < 0) {
4554 unlink(pfile);
4555 sigma_dut_print(dut, DUT_MSG_ERROR,
4556 "Error changing permissions");
4557 return -1;
4558 }
4559
4560 if (res < 0) {
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Error restoring conf file");
4563 return -1;
4564 }
4565
4566 return 0;
4567}
4568
4569
4570static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4571 struct sigma_conn *conn,
4572 struct sigma_cmd *cmd)
4573{
4574 char buf[100];
4575 struct stat s;
4576 int num_tries = 0, ret;
4577
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304578 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4579 system("killall netd") == 0) {
4580 /* Avoid Error: Error connecting (Connection refused)
4581 * Wait some time to allow netd to reinitialize.
4582 */
4583 usleep(1500000);
4584 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004585
4586 while (num_tries < 10) {
4587 ret = run_ndc(dut, "ndc softap stopap");
4588 num_tries++;
4589 if (WIFEXITED(ret))
4590 ret = WEXITSTATUS(ret);
4591 /* On success, NDC exits with 0 */
4592 if (ret == 0)
4593 break;
4594 sigma_dut_print(dut, DUT_MSG_INFO,
4595 "Try No. %d: ndc softap stopap failed, exit code %d",
4596 num_tries, ret);
4597 }
4598
4599 if (ret != 0)
4600 sigma_dut_print(dut, DUT_MSG_ERROR,
4601 "ndc softap stopap command failed for 10 times - giving up");
4602
4603#ifdef ANDROID
4604 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304605 system("rmmod -f wlan");
4606 usleep(500000);
4607 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004608#else /* ANDROID */
4609 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4610 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4611#endif /* ANDROID */
4612
4613 switch (dut->ap_mode) {
4614 case AP_11g:
4615 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4616 break;
4617 case AP_11b:
4618 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4619 break;
4620 case AP_11ng:
4621 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4622 break;
4623 case AP_11a:
4624 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4625 break;
4626 case AP_11na:
4627 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4628 break;
4629 case AP_11ac:
4630 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4631 break;
4632 default:
4633 break;
4634 }
4635
4636 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4637 dut->ap_channel);
4638 run_ndc(dut, buf);
4639
4640 /*
4641 * ndc doesn't support double quotes as SSID string, so re-write
4642 * hostapd configuration file to update SSID.
4643 */
4644 if (dut->ap_ssid[0] != '\0')
4645 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4646
4647 switch (dut->ap_key_mgmt) {
4648 case AP_OPEN:
4649 if (dut->ap_cipher == AP_WEP) {
4650 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4651 snprintf(buf, sizeof(buf),
4652 "ndc softap qccmd set wep_key0=%s",
4653 dut->ap_wepkey);
4654 run_ndc(dut, buf);
4655 } else {
4656 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4657 }
4658 break;
4659 case AP_WPA2_PSK:
4660 case AP_WPA2_PSK_MIXED:
4661 case AP_WPA_PSK:
4662 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4663 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4664 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4665 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4666 else
4667 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4668
4669 /*
4670 * ndc doesn't support some special characters as passphrase,
4671 * so re-write hostapd configuration file to update Passphrase.
4672 */
4673 if (dut->ap_passphrase[0] != '\0')
4674 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4675 "wpa_passphrase", dut->ap_passphrase);
4676
4677 if (dut->ap_cipher == AP_CCMP_TKIP)
4678 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4679 "TKIP CCMP");
4680 else if (dut->ap_cipher == AP_TKIP)
4681 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4682 "TKIP");
4683 else
4684 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4685 "CCMP &");
4686 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004687 case AP_WPA2_SAE:
4688 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004689 case AP_WPA2_EAP:
4690 case AP_WPA2_EAP_MIXED:
4691 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004692 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004693 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004694 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004695 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004696 case AP_WPA2_FT_EAP:
4697 case AP_WPA2_FT_PSK:
4698 case AP_WPA2_EAP_SHA256:
4699 case AP_WPA2_PSK_SHA256:
4700 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004701 /* Not supported */
4702 break;
4703 }
4704
4705 switch (dut->ap_pmf) {
4706 case AP_PMF_DISABLED:
4707 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4708 break;
4709 case AP_PMF_OPTIONAL:
4710 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4711 if (dut->ap_add_sha256)
4712 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4713 else
4714 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4715 break;
4716 case AP_PMF_REQUIRED:
4717 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4718 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4719 break;
4720 }
4721
4722 if (dut->ap_countrycode[0]) {
4723 snprintf(buf, sizeof(buf),
4724 "ndc softap qccmd set country_code=%s",
4725 dut->ap_countrycode);
4726 run_ndc(dut, buf);
4727 }
4728
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304729 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4730 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4731
4732 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4733 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004735 run_ndc(dut, "ndc softap startap");
4736
Jouni Malinen5ea30922019-11-04 17:39:25 +02004737 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl,
4738 get_main_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004739 num_tries = 0;
4740 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4741 run_ndc(dut, "ndc softap stopap");
4742 run_ndc(dut, "ndc softap startap");
4743 num_tries++;
4744 }
4745
4746 if (num_tries == 10) {
4747 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4748 "iface %s :: reboot the APDUT", buf);
4749 return ret;
4750 }
4751
4752 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4753 ap_inet_addr, ap_inet_mask);
4754 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Jouni Malinen5ea30922019-11-04 17:39:25 +02004755 get_main_ifname(dut), ap_inet_addr, ap_inet_mask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004756 if (system(buf) != 0) {
4757 sigma_dut_print(dut, DUT_MSG_ERROR,
4758 "Failed to intialize the interface");
4759 return -1;
4760 }
4761
4762 return 1;
4763}
4764
4765
4766static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4767{
4768 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4769 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4770
4771 if (dut->ap_oper_name) {
4772 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4773 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4774 }
4775
4776 if (dut->ap_wan_metrics == 1)
4777 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4778 else if (dut->ap_wan_metrics == 2)
4779 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4780 else if (dut->ap_wan_metrics == 3)
4781 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4782 else if (dut->ap_wan_metrics == 4)
4783 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4784 else if (dut->ap_wan_metrics == 5)
4785 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4786
4787 if (dut->ap_conn_capab == 1) {
4788 fprintf(f, "hs20_conn_capab=1:0:0\n");
4789 fprintf(f, "hs20_conn_capab=6:20:1\n");
4790 fprintf(f, "hs20_conn_capab=6:22:0\n");
4791 fprintf(f, "hs20_conn_capab=6:80:1\n");
4792 fprintf(f, "hs20_conn_capab=6:443:1\n");
4793 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4794 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4795 fprintf(f, "hs20_conn_capab=17:500:1\n");
4796 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4797 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4798 fprintf(f, "hs20_conn_capab=50:0:1\n");
4799 } else if (dut->ap_conn_capab == 2) {
4800 fprintf(f, "hs20_conn_capab=6:80:1\n");
4801 fprintf(f, "hs20_conn_capab=6:443:1\n");
4802 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4803 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4804 } else if (dut->ap_conn_capab == 3) {
4805 fprintf(f, "hs20_conn_capab=6:80:1\n");
4806 fprintf(f, "hs20_conn_capab=6:443:1\n");
4807 } else if (dut->ap_conn_capab == 4) {
4808 fprintf(f, "hs20_conn_capab=6:80:1\n");
4809 fprintf(f, "hs20_conn_capab=6:443:1\n");
4810 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4811 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4812 }
4813
4814 if (dut->ap_oper_class == 1)
4815 fprintf(f, "hs20_operating_class=51\n");
4816 else if (dut->ap_oper_class == 2)
4817 fprintf(f, "hs20_operating_class=73\n");
4818 else if (dut->ap_oper_class == 3)
4819 fprintf(f, "hs20_operating_class=5173\n");
4820
4821 if (dut->ap_osu_provider_list) {
4822 char *osu_friendly_name = NULL;
4823 char *osu_icon = NULL;
4824 char *osu_ssid = NULL;
4825 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004826 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004827 char *osu_service_desc = NULL;
4828 char *hs20_icon_filename = NULL;
4829 char hs20_icon[150];
4830 int osu_method;
4831
4832 hs20_icon_filename = "icon_red_zxx.png";
4833 if (dut->ap_osu_icon_tag == 2)
4834 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4835 snprintf(hs20_icon, sizeof(hs20_icon),
4836 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4837 hs20_icon_filename);
4838 osu_icon = "icon_red_zxx.png";
4839 osu_ssid = "OSU";
4840 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4841 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4842 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4843
4844 if (strlen(dut->ap_osu_server_uri[0]))
4845 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4846 else
4847 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4848
4849 switch (dut->ap_osu_provider_list) {
4850 case 1:
4851 case 101:
4852 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4853 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4854 hs20_icon_filename = "icon_red_eng.png";
4855 if (dut->ap_osu_icon_tag == 2)
4856 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4857 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4858 hs20_icon_filename);
4859 fprintf(f, "osu_icon=icon_red_eng.png\n");
4860 break;
4861 case 2:
4862 case 102:
4863 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4864 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4865 hs20_icon_filename = "icon_orange_zxx.png";
4866 if (dut->ap_osu_icon_tag == 2)
4867 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4868 snprintf(hs20_icon, sizeof(hs20_icon),
4869 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4870 hs20_icon_filename);
4871 osu_icon = "icon_orange_zxx.png";
4872 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4873 break;
4874 case 3:
4875 case 103:
4876 osu_friendly_name = "spa:SP Red Test Only";
4877 osu_service_desc = "spa:Free service for test purpose";
4878 break;
4879 case 4:
4880 case 104:
4881 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4882 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4883 hs20_icon_filename = "icon_orange_eng.png";
4884 if (dut->ap_osu_icon_tag == 2)
4885 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4886 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4887 hs20_icon_filename);
4888 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4889 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4890
4891 hs20_icon_filename = "icon_orange_zxx.png";
4892 if (dut->ap_osu_icon_tag == 2)
4893 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4894 snprintf(hs20_icon, sizeof(hs20_icon),
4895 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4896 hs20_icon_filename);
4897 osu_icon = "icon_orange_zxx.png";
4898 break;
4899 case 5:
4900 case 105:
4901 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4902 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4903 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4904 hs20_icon_filename = "icon_orange_zxx.png";
4905 if (dut->ap_osu_icon_tag == 2)
4906 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4907 snprintf(hs20_icon, sizeof(hs20_icon),
4908 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4909 hs20_icon_filename);
4910 osu_icon = "icon_orange_zxx.png";
4911 break;
4912 case 6:
4913 case 106:
4914 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4915 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4916 hs20_icon_filename = "icon_green_zxx.png";
4917 if (dut->ap_osu_icon_tag == 2)
4918 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4919 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4920 hs20_icon_filename);
4921 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4922 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4923 fprintf(f, "osu_method_list=%d\n", osu_method);
4924
4925 if (strlen(dut->ap_osu_server_uri[1]))
4926 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4927 else
4928 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4929 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4930 hs20_icon_filename = "icon_orange_zxx.png";
4931 if (dut->ap_osu_icon_tag == 2)
4932 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4933 snprintf(hs20_icon, sizeof(hs20_icon),
4934 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4935 hs20_icon_filename);
4936 osu_icon = "icon_orange_zxx.png";
4937 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4938 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4939 osu_service_desc = NULL;
4940 break;
4941 case 7:
4942 case 107:
4943 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4944 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4945 hs20_icon_filename = "icon_green_eng.png";
4946 if (dut->ap_osu_icon_tag == 2)
4947 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4948 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4949 hs20_icon_filename);
4950 fprintf(f, "osu_icon=icon_green_eng.png\n");
4951 osu_friendly_name = "kor:SP 초록 테스트 전용";
4952
4953 hs20_icon_filename = "icon_green_zxx.png";
4954 if (dut->ap_osu_icon_tag == 2)
4955 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4956 snprintf(hs20_icon, sizeof(hs20_icon),
4957 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4958 hs20_icon_filename);
4959 osu_icon = "icon_green_zxx.png";
4960 break;
4961 case 8:
4962 case 108:
4963 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4964 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4965 osu_ssid = "OSU-Encrypted";
4966 osu_nai = "anonymous@hotspot.net";
4967 break;
4968 case 9:
4969 case 109:
4970 osu_ssid = "OSU-OSEN";
4971 osu_nai = "test-anonymous@wi-fi.org";
4972 osu_friendly_name = "eng:SP Orange Test Only";
4973 hs20_icon_filename = "icon_orange_zxx.png";
4974 if (dut->ap_osu_icon_tag == 2)
4975 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4976 snprintf(hs20_icon, sizeof(hs20_icon),
4977 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4978 hs20_icon_filename);
4979 osu_icon = "icon_orange_zxx.png";
4980 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4981 osu_service_desc = NULL;
4982 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004983 case 10:
4984 case 110:
4985 /* OSU Provider #1 */
4986 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4987 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
4988 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
4989 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
4990 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
4991 1 : dut->ap_osu_method[0];
4992 fprintf(f, "osu_method_list=%d\n", osu_method);
4993 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
4994 switch (dut->ap_osu_provider_nai_list) {
4995 case 3:
4996 fprintf(f,
4997 "osu_nai2=test-anonymous@wi-fi.org\n");
4998 break;
4999 case 4:
5000 fprintf(f, "osu_nai2=random@hotspot.net\n");
5001 break;
5002 }
5003
5004 /* OSU Provider #2 */
5005 /* SP Red from defaults */
5006 if (strlen(dut->ap_osu_server_uri[1]))
5007 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
5008 else
5009 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
5010 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
5011 snprintf(hs20_icon, sizeof(hs20_icon),
5012 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
5013 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
5014 1 : dut->ap_osu_method[1];
5015 osu_service_desc = NULL;
5016 osu_nai = "anonymous@hotspot.net";
5017 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005018 default:
5019 break;
5020 }
5021
Jouni Malinen93a837f2018-11-01 17:09:22 +02005022 switch (dut->ap_osu_provider_nai_list) {
5023 case 1:
5024 osu_nai2 = "anonymous@hotspot.net";
5025 break;
5026 case 2:
5027 osu_nai2 = "test-anonymous@wi-fi.org";
5028 break;
5029 case 3:
5030 /* OSU Provider NAI #1 written above */
5031 /* OSU Provider NAI #2 */
5032 osu_nai2 = "anonymous@hotspot.net";
5033 break;
5034 case 4:
5035 /* OSU Provider NAI #1 written above */
5036 /* OSU Provider NAI #2 */
5037 osu_nai2 = "anonymous@hotspot.net";
5038 break;
5039 }
5040
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005041 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03005042 if (dut->ap_tag_ssid[0][0] &&
5043 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005044 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005045 sigma_dut_print(dut, DUT_MSG_ERROR,
5046 "OSU_SSID and "
5047 "WLAN_TAG2 SSID differ");
5048 return -2;
5049 }
5050 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
5051 } else
5052 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
5053
5054
5055 if (osu_friendly_name)
5056 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
5057
5058 if (osu_service_desc)
5059 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
5060
5061 if (osu_nai)
5062 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02005063 if (osu_nai2)
5064 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005065
5066 fprintf(f, "hs20_icon=%s\n", hs20_icon);
5067
5068 if (osu_icon)
5069 fprintf(f, "osu_icon=%s\n", osu_icon);
5070
5071 if (dut->ap_osu_provider_list > 100)
5072 fprintf(f, "osu_method_list=0\n");
5073 else
5074 fprintf(f, "osu_method_list=%d\n", osu_method);
5075 }
5076
Jouni Malinen54a89b02018-05-01 00:16:26 +03005077 switch (dut->ap_venue_url) {
5078 case 1:
5079 fprintf(f,
5080 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5081 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
5082 break;
5083 case 2:
5084 fprintf(f,
5085 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5086 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5087 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5088 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5089 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5090 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5091 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5092 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5093 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5094 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
5095 );
5096 break;
5097 }
5098
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03005099 switch (dut->ap_advice_of_charge) {
5100 case 1:
5101 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
5102 break;
5103 }
5104
Jouni Malinenac104532018-05-01 00:27:37 +03005105 switch (dut->ap_oper_icon_metadata) {
5106 case 1:
5107 fprintf(f,
5108 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
5109 "operator_icon=icon_red_eng.png\n");
5110 break;
5111 }
5112
Jouni Malinenac367142018-05-01 00:32:24 +03005113 switch (dut->ap_tnc_file_name) {
5114 case 1:
5115 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
5116 break;
5117 }
5118
5119 if (dut->ap_tnc_time_stamp)
5120 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
5121
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005122 return 0;
5123}
5124
5125
5126static void write_ap_roaming_cons(FILE *f, const char *list)
5127{
5128 char *buf, *pos, *end;
5129
5130 if (list == NULL || list[0] == '\0')
5131 return;
5132
5133 buf = strdup(list);
5134 if (buf == NULL)
5135 return;
5136
5137 pos = buf;
5138 while (pos && *pos) {
5139 end = strchr(pos, ';');
5140 if (end)
5141 *end++ = '\0';
5142 fprintf(f, "roaming_consortium=%s\n", pos);
5143 pos = end;
5144 }
5145
5146 free(buf);
5147}
5148
5149
5150static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
5151{
5152 int i;
5153 char buf[100], *temp;
5154
5155 if (dut->ap_gas_cb_delay > 0)
5156 fprintf(f, "gas_comeback_delay=%d\n",
5157 dut->ap_gas_cb_delay);
5158
5159 fprintf(f, "interworking=1\n"
5160 "access_network_type=%d\n"
5161 "internet=%d\n"
5162 "asra=0\n"
5163 "esr=0\n"
5164 "uesa=0\n"
5165 "venue_group=%d\n"
5166 "venue_type=%d\n",
5167 dut->ap_access_net_type,
5168 dut->ap_internet,
5169 dut->ap_venue_group,
5170 dut->ap_venue_type);
5171 if (dut->ap_hessid[0])
5172 fprintf(f, "hessid=%s\n", dut->ap_hessid);
5173
5174 write_ap_roaming_cons(f, dut->ap_roaming_cons);
5175
5176 if (dut->ap_venue_name) {
5177 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
5178 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
5179 }
5180
5181 if (dut->ap_net_auth_type == 1)
5182 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
5183 else if (dut->ap_net_auth_type == 2)
5184 fprintf(f, "network_auth_type=01\n");
5185
5186 if (dut->ap_nai_realm_list == 1) {
5187 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
5188 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5189 } else if (dut->ap_nai_realm_list == 2) {
5190 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5191 } else if (dut->ap_nai_realm_list == 3) {
5192 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
5193 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
5194 } else if (dut->ap_nai_realm_list == 4) {
5195 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
5196 } else if (dut->ap_nai_realm_list == 5) {
5197 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
5198 } else if (dut->ap_nai_realm_list == 6) {
5199 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
5200 } else if (dut->ap_nai_realm_list == 7) {
5201 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
5202 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
5203 }
5204
5205 if (dut->ap_domain_name_list[0]) {
5206 fprintf(f, "domain_name=%s\n",
5207 dut->ap_domain_name_list);
5208 }
5209
5210 if (dut->ap_ip_addr_type_avail == 1) {
5211 fprintf(f, "ipaddr_type_availability=0c\n");
5212 }
5213
5214 temp = buf;
5215 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
5216 i++) {
5217 if (i)
5218 *temp++ = ';';
5219
5220 snprintf(temp,
5221 sizeof(dut->ap_plmn_mcc[i]) +
5222 sizeof(dut->ap_plmn_mnc[i]) + 1,
5223 "%s,%s",
5224 dut->ap_plmn_mcc[i],
5225 dut->ap_plmn_mnc[i]);
5226
5227 temp += strlen(dut->ap_plmn_mcc[i]) +
5228 strlen(dut->ap_plmn_mnc[i]) + 1;
5229 }
5230 if (i)
5231 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
5232
5233 if (dut->ap_qos_map_set == 1)
5234 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
5235 else if (dut->ap_qos_map_set == 2)
5236 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
5237
5238 return 0;
5239}
5240
5241
5242static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
5243{
5244 FILE *f;
5245
5246 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
5247 system("killall hostapd") == 0) {
5248 int i;
5249
5250 /* Wait some time to allow hostapd to complete cleanup before
5251 * starting a new process */
5252 for (i = 0; i < 10; i++) {
5253 usleep(500000);
5254 if (system("pidof hostapd") != 0)
5255 break;
5256 }
5257 }
5258
5259 f = fopen("/tmp/secath0", "a");
5260 if (f == NULL)
5261 return -2;
5262
5263 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
5264 fclose(f);
5265 return -2;
5266 }
5267
5268 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
5269 fclose(f);
5270 return -2;
5271 }
5272
5273 fflush(f);
5274 fclose(f);
5275 return ath_ap_start_hostapd(dut);
5276}
5277
5278
5279static int ath_ap_start_hostapd(struct sigma_dut *dut)
5280{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005281 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005282 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
5283 else
5284 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
5285
5286 return 0;
5287}
5288
5289
5290#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
5291
5292static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
5293{
5294 FILE *f;
5295 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
5296 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
5297 char buf[100];
5298 int i;
5299
5300 f = fopen("/root/anqpserver.conf", "w");
5301 if (f == NULL)
5302 return -1;
5303
5304 if (dut->ap_nai_realm_list == 1) {
5305 nai_realm = 1;
5306 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");
5307 } else if (dut->ap_nai_realm_list == 2) {
5308 nai_realm = 1;
5309 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
5310 } else if (dut->ap_nai_realm_list == 3) {
5311 nai_realm = 1;
5312 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");
5313 } else if (dut->ap_nai_realm_list == 4) {
5314 nai_realm = 1;
5315 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");
5316 } else
5317 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
5318
5319 if (dut->ap_domain_name_list[0]) {
5320 char *next, *start, *dnbuf, *dn1, *anqp_dn;
5321 int len, dn_len_max;
5322 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305323 if (dnbuf == NULL) {
5324 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005325 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305326 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005327
5328 len = strlen(dnbuf);
5329 dn_len_max = 50 + len*2;
5330 anqp_dn = malloc(dn_len_max);
5331 if (anqp_dn == NULL) {
5332 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305333 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005334 return -1;
5335 }
5336 start = dnbuf;
5337 dn1 = anqp_dn;
5338 while (start && *start) {
5339 char *hexstr;
5340
5341 next = strchr(start, ',');
5342 if (next)
5343 *next++ = '\0';
5344
5345 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05305346 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005347 if (hexstr == NULL) {
5348 free(dnbuf);
5349 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305350 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005351 return -1;
5352 }
5353 ascii2hexstr(start, hexstr);
5354 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
5355 free(hexstr);
5356 dn1 += 2 + len * 2;
5357 dn_len_max -= 2 + len * 2;
5358 start = next;
5359 }
5360 free(dnbuf);
5361 if (dut->ap_gas_cb_delay) {
5362 fprintf(f, "dyn_domain_name=0c01%04x%s",
5363 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5364 domain_name = 1;
5365 } else
5366 fprintf(f, "domain_name=0c01%04x%s",
5367 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5368 free(anqp_dn);
5369 } else
5370 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
5371
5372 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
5373
5374 if (dut->ap_oper_name) {
5375 if (dut->ap_gas_cb_delay) {
5376 fprintf(f, "dyn_oper_friendly_name="
5377 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5378 oper_name = 1;
5379 } else
5380 fprintf(f, "oper_friendly_name="
5381 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5382 } else
5383 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
5384
5385 if (dut->ap_venue_name) {
5386 if (dut->ap_gas_cb_delay) {
5387 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
5388 venue_name = 1;
5389 } else
5390 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
5391 } else
5392 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
5393
5394 if (dut->ap_wan_metrics) {
5395 if (dut->ap_gas_cb_delay) {
5396 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
5397 wan_metrics = 1;
5398 } else
5399 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
5400 "\n");
5401 } else
5402 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
5403
5404 if (dut->ap_conn_capab) {
5405 if (dut->ap_gas_cb_delay) {
5406 fprintf(f, "dyn_conn_capability="
5407 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5408 conn_cap = 1;
5409 } else
5410 fprintf(f, "conn_capability="
5411 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5412 } else
5413 sigma_dut_print(dut, DUT_MSG_ERROR,
5414 "not setting conn_capability");
5415
5416 if (dut->ap_ip_addr_type_avail) {
5417 if (dut->ap_gas_cb_delay) {
5418 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
5419 "\n");
5420 ipaddr_avail = 1;
5421 } else
5422 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
5423 } else
5424 sigma_dut_print(dut, DUT_MSG_ERROR,
5425 "not setting ipaddr_type_avail");
5426
5427 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
5428 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
5429 dut->ap_plmn_mcc[i][1],
5430 dut->ap_plmn_mcc[i][0],
5431 dut->ap_plmn_mnc[i][2] == '\0' ?
5432 'f' : dut->ap_plmn_mnc[i][2],
5433 dut->ap_plmn_mcc[i][2],
5434 dut->ap_plmn_mnc[i][1],
5435 dut->ap_plmn_mnc[i][0]);
5436 }
5437 if (i) {
5438 uint16_t ie_len = (i * 3) + 5;
5439 if (dut->ap_gas_cb_delay) {
5440 fprintf(f, "dyn_cell_net=0801");
5441 cell_net = 1;
5442 } else
5443 fprintf(f, "cell_net=0801");
5444 fprintf(f, "%04x", LE16(ie_len));
5445 fprintf(f, "00"); /* version */
5446 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
5447 fprintf(f, "00"); /* plmn list */
5448 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
5449 fprintf(f, "%02x", i); /* number of plmns */
5450 fprintf(f, "%s\n", buf); /* plmns */
5451 } else
5452 sigma_dut_print(dut, DUT_MSG_ERROR,
5453 "not setting 3gpp_cellular_network");
5454
5455 if (nai_realm || domain_name || oper_name || venue_name ||
5456 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
5457 fprintf(f, "anqp_attach=");
5458 if (venue_name)
5459 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
5460 if (nai_realm)
5461 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
5462 if (cell_net)
5463 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
5464 if (domain_name)
5465 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
5466 if (oper_name)
5467 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
5468 if (wan_metrics)
5469 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
5470 if (conn_cap)
5471 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
5472 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
5473 fprintf(f, "\n");
5474 }
5475
5476 fclose(f);
5477
5478 run_system(dut, "anqpserver -i ath0 &");
5479 if (!dut->ap_anqpserver_on)
5480 run_system(dut, "killall anqpserver");
5481
5482 return 1;
5483}
5484
5485
5486static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
5487{
5488 char buf[100];
5489
5490 run_system(dut, "cfg -a AP_STARTMODE=standard");
5491
5492 if (sigma_radio_ifname[0] &&
5493 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
5494 run_system(dut, "cfg -a AP_RADIO_ID=1");
5495 switch (dut->ap_mode) {
5496 case AP_11g:
5497 run_system(dut, "cfg -a AP_CHMODE_2=11G");
5498 break;
5499 case AP_11b:
5500 run_system(dut, "cfg -a AP_CHMODE_2=11B");
5501 break;
5502 case AP_11ng:
5503 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
5504 break;
5505 case AP_11a:
5506 run_system(dut, "cfg -a AP_CHMODE_2=11A");
5507 break;
5508 case AP_11na:
5509 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
5510 break;
5511 case AP_11ac:
5512 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5513 break;
5514 default:
5515 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5516 break;
5517 }
5518
5519 switch (dut->ap_rx_streams) {
5520 case 1:
5521 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5522 break;
5523 case 2:
5524 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5525 break;
5526 case 3:
5527 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5528 break;
5529 }
5530
5531 switch (dut->ap_tx_streams) {
5532 case 1:
5533 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5534 break;
5535 case 2:
5536 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5537 break;
5538 case 3:
5539 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5540 break;
5541 }
5542
5543 switch (dut->ap_chwidth) {
5544 case AP_20:
5545 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5546 break;
5547 case AP_40:
5548 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5549 break;
5550 case AP_80:
5551 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5552 break;
5553 case AP_160:
5554 case AP_AUTO:
5555 default:
5556 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5557 break;
5558 }
5559
5560 if (dut->ap_tx_stbc) {
5561 run_system(dut, "cfg -a TX_STBC_2=1");
5562 }
5563
5564 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5565 dut->ap_channel);
5566
5567 if (dut->ap_is_dual) {
5568 switch (dut->ap_mode_1) {
5569 case AP_11g:
5570 run_system(dut, "cfg -a AP_CHMODE=11G");
5571 break;
5572 case AP_11b:
5573 run_system(dut, "cfg -a AP_CHMODE=11B");
5574 break;
5575 case AP_11ng:
5576 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5577 break;
5578 case AP_11a:
5579 run_system(dut, "cfg -a AP_CHMODE=11A");
5580 break;
5581 case AP_11na:
5582 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5583 break;
5584 case AP_11ac:
5585 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5586 break;
5587 default:
5588 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5589 break;
5590 }
5591 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5592 dut->ap_channel_1);
5593 }
5594 run_system(dut, buf);
5595 } else {
5596 run_system(dut, "cfg -a AP_RADIO_ID=0");
5597 switch (dut->ap_mode) {
5598 case AP_11g:
5599 run_system(dut, "cfg -a AP_CHMODE=11G");
5600 break;
5601 case AP_11b:
5602 run_system(dut, "cfg -a AP_CHMODE=11B");
5603 break;
5604 case AP_11ng:
5605 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5606 break;
5607 case AP_11a:
5608 run_system(dut, "cfg -a AP_CHMODE=11A");
5609 break;
5610 case AP_11na:
5611 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5612 break;
5613 case AP_11ac:
5614 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5615 break;
5616 default:
5617 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5618 break;
5619 }
5620 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5621 dut->ap_channel);
5622 run_system(dut, buf);
5623 }
5624
5625 if (dut->ap_sgi80 == 1) {
5626 run_system(dut, "cfg -a SHORTGI=1");
5627 run_system(dut, "cfg -a SHORTGI_2=1");
5628 } else if (dut->ap_sgi80 == 0) {
5629 run_system(dut, "cfg -a SHORTGI=0");
5630 run_system(dut, "cfg -a SHORTGI_2=0");
5631 }
5632
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005633 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005635 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636 run_system(dut, "cfg -a LDPC=0");
5637}
5638
5639
5640void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5641{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005642 run_iwpriv(dut, intf, "vhtsubfee 0");
5643 run_iwpriv(dut, intf, "vhtsubfer 0");
5644 run_iwpriv(dut, intf, "vhtmubfee 0");
5645 run_iwpriv(dut, intf, "vhtmubfer 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005646}
5647
5648
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005649static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5650 const char *val)
5651{
5652 if (strcasecmp(val, "enable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005653 run_iwpriv(dut, ifname, "mbo_asoc_dis 1");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005654 } else if (strcasecmp(val, "disable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005655 run_iwpriv(dut, ifname, "mbo_asoc_dis 0");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005656 } else {
5657 sigma_dut_print(dut, DUT_MSG_ERROR,
5658 "Unsupported assoc_disallow");
5659 }
5660}
5661
5662
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005663static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5664{
5665 int i;
5666 int least_pref = 1 << 8;
5667 char ifname[20];
5668 uint8_t self_mac[ETH_ALEN];
5669 char buf[200];
5670 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5671
5672 get_if_name(dut, ifname, sizeof(ifname), 1);
5673 get_hwaddr(ifname, self_mac);
5674
5675 /* Clear off */
5676 snprintf(buf, sizeof(buf),
5677 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5678 ifname);
5679 run_system(dut, buf);
5680
5681 /* Find the least preference number */
5682 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5683 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5684
5685 ap_ne_class = 1;
5686 ap_ne_pref = 255;
5687 ap_ne_op_ch = 1;
5688 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5689 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5690 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5691 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5692 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5693 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5694
5695 if (ap_ne_pref < least_pref)
5696 least_pref = ap_ne_pref;
5697 snprintf(buf, sizeof(buf),
5698 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5699 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5700 mac_addr[3], mac_addr[4], mac_addr[5],
5701 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5702 run_system(dut, buf);
5703 }
5704
5705 /* Now add the self AP Address */
5706 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5707 if (dut->ap_channel <= 11)
5708 ap_ne_class = 81;
5709 else
5710 ap_ne_class = 115;
5711 } else {
5712 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5713 }
5714
5715 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5716 ap_ne_op_ch = dut->ap_channel;
5717 else
5718 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5719
5720 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5721 ap_ne_pref = least_pref - 1;
5722 else
5723 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5724
5725 snprintf(buf, sizeof(buf),
5726 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5727 ifname, self_mac[0], self_mac[1], self_mac[2],
5728 self_mac[3], self_mac[4], self_mac[5],
5729 ap_ne_pref,
5730 ap_ne_class,
5731 ap_ne_op_ch);
5732 run_system(dut, buf);
5733}
5734
5735
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -07005736static void mubrp_commands(struct sigma_dut *dut, const char *ifname)
5737{
5738 run_iwpriv(dut, ifname, "he_subfer 1");
5739 run_iwpriv(dut, ifname, "he_mubfer 1");
5740 /* To enable MU_AX with MU_BRP trigger */
5741 run_iwpriv(dut, ifname, "he_sounding_mode 13");
5742 /* Sets g_force_1x1_peer to 1 which should be reset to zero for non MU
5743 * test cases */
5744 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 118 1",
5745 ifname);
5746 /* Disable DL OFDMA */
5747 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 11 0",
5748 ifname);
5749}
5750
5751
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005752static void ath_ap_set_params(struct sigma_dut *dut)
5753{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005754 const char *basedev = "wifi0";
5755 const char *basedev_radio = "wifi1";
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005756 const char *ifname = get_main_ifname(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005757 char *ifname_dual = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005758 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005759 char buf[300];
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08005760 unsigned int he_mcsnssmap = dut->he_mcsnssmap;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005761
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005762 if (sigma_radio_ifname[0])
5763 basedev = sigma_radio_ifname[0];
5764
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005765 if (dut->ap_is_dual == 1) {
5766 basedev = sigma_radio_ifname[0];
5767 basedev_radio = sigma_radio_ifname[1];
5768 if (sigma_radio_ifname[0] &&
5769 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5770 ifname = "ath0";
5771 ifname_dual = "ath1";
5772 } else {
5773 ifname = "ath1";
5774 ifname_dual = "ath0";
5775 }
5776 }
5777
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005778 if (dut->ap_countrycode[0]) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005779 run_iwpriv(dut, basedev, "setCountry %s", dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005780 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5781 }
5782
5783 for (i = 0; i < NUM_AP_AC; i++) {
5784 if (dut->ap_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005785 run_iwpriv(dut, ifname, "cwmin %d 0 %d", i,
5786 dut->ap_qos[i].cwmin);
5787 run_iwpriv(dut, ifname, "cwmax %d 0 %d", i,
5788 dut->ap_qos[i].cwmax);
5789 run_iwpriv(dut, ifname, "aifs %d 0 %d", i,
5790 dut->ap_qos[i].aifs);
5791 run_iwpriv(dut, ifname, "txoplimit %d 0 %d", i,
5792 dut->ap_qos[i].txop);
5793 run_iwpriv(dut, ifname, "acm %d 0 %d", i,
5794 dut->ap_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005795 }
5796 }
5797
5798 for (i = 0; i < NUM_AP_AC; i++) {
5799 if (dut->ap_sta_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005800 run_iwpriv(dut, ifname, "cwmin %d 1 %d", i,
5801 dut->ap_sta_qos[i].cwmin);
5802 run_iwpriv(dut, ifname, "cwmax %d 1 %d", i,
5803 dut->ap_sta_qos[i].cwmax);
5804 run_iwpriv(dut, ifname, "aifs %d 1 %d", i,
5805 dut->ap_sta_qos[i].aifs);
5806 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", i,
5807 dut->ap_sta_qos[i].txop);
5808 run_iwpriv(dut, ifname, "acm %d 1 %d", i,
5809 dut->ap_sta_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005810 }
5811 }
5812
5813 if (dut->ap_disable_protection == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005814 run_iwpriv(dut, ifname, "enablertscts 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005815 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5816 }
5817
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005818 if (dut->ap_ldpc == VALUE_ENABLED)
5819 run_iwpriv(dut, ifname, "ldpc 3");
5820 else if (dut->ap_ldpc == VALUE_DISABLED)
5821 run_iwpriv(dut, ifname, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005822
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005823 if (dut->ap_ampdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005824 run_iwpriv(dut, ifname, "ampdu 1");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005825 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005826 run_iwpriv(dut, ifname, "ampdu 0");
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08005827 if (dut->program == PROGRAM_HE) {
5828 run_iwpriv(dut, ifname, "setaddbaoper 1");
5829 run_system_wrapper(dut, "wifitool %s refusealladdbas 1",
5830 ifname);
5831 if (dut->ap_amsdu == VALUE_ENABLED) {
5832 /* disable the limit for A-MSDU */
5833 run_system_wrapper(dut,
5834 "wifitool %s setUnitTestCmd 0x48 2 46 1",
5835 ifname);
5836 }
5837 }
5838 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005839
5840 if (dut->ap_ampdu_exp) {
5841 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005842 run_iwpriv(dut, ifname, "vhtmaxampdu %d",
5843 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005844 } else {
5845 /* 11N */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005846 run_iwpriv(dut, ifname, "maxampdu %d",
5847 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005848 }
5849 }
5850
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005851 if (dut->ap_noack == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005852 run_iwpriv(dut, ifname, "noackpolicy 0 0 1");
5853 run_iwpriv(dut, ifname, "noackpolicy 1 0 1");
5854 run_iwpriv(dut, ifname, "noackpolicy 2 0 1");
5855 run_iwpriv(dut, ifname, "noackpolicy 3 0 1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005856 } else if (dut->ap_noack == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005857 run_iwpriv(dut, ifname, "noackpolicy 0 0 0");
5858 run_iwpriv(dut, ifname, "noackpolicy 1 0 0");
5859 run_iwpriv(dut, ifname, "noackpolicy 2 0 0");
5860 run_iwpriv(dut, ifname, "noackpolicy 3 0 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005861 }
5862
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005863 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map)
5864 run_iwpriv(dut, ifname, "vht_mcsmap 0x%04x",
5865 dut->ap_vhtmcs_map);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005867 if (dut->ap_amsdu == VALUE_ENABLED)
5868 run_iwpriv(dut, ifname, "amsdu 2");
5869 else if (dut->ap_amsdu == VALUE_DISABLED)
5870 run_iwpriv(dut, ifname, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005872 if (dut->ap_rx_amsdu == VALUE_ENABLED)
5873 run_iwpriv(dut, basedev_radio, "rx_amsdu 1");
5874 else if (dut->ap_rx_amsdu == VALUE_DISABLED)
5875 run_iwpriv(dut, basedev_radio, "rx_amsdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005876
5877 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005878 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5879 dut->ap_ampdu == VALUE_DISABLED &&
5880 dut->ap_amsdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005881 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005882
5883 snprintf(buf, sizeof(buf),
5884 "wifitool %s senddelba 1 0 1 4", ifname);
5885 if (system(buf) != 0) {
5886 sigma_dut_print(dut, DUT_MSG_ERROR,
5887 "wifitool senddelba failed");
5888 }
5889
5890 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5891 ifname);
5892 if (system(buf) != 0) {
5893 sigma_dut_print(dut, DUT_MSG_ERROR,
5894 "wifitool sendsingleamsdu failed");
5895 }
5896
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005897 run_iwpriv(dut, ifname, "amsdu 10");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005898 }
5899
5900 if (dut->ap_mode == AP_11ac) {
5901 int chwidth, nss;
5902
5903 switch (dut->ap_chwidth) {
5904 case AP_20:
5905 chwidth = 0;
5906 break;
5907 case AP_40:
5908 chwidth = 1;
5909 break;
5910 case AP_80:
5911 chwidth = 2;
5912 break;
5913 case AP_160:
5914 chwidth = 3;
5915 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005916 case AP_80_80:
5917 chwidth = 3;
5918 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 default:
5920 chwidth = 0;
5921 break;
5922 }
5923
5924 switch (dut->ap_tx_streams) {
5925 case 1:
5926 nss = 1;
5927 break;
5928 case 2:
5929 nss = 2;
5930 break;
5931 case 3:
5932 nss = 3;
5933 break;
5934 case 4:
5935 nss = 4;
5936 break;
5937 default:
5938 nss = 3;
5939 break;
5940 }
5941
5942 if (dut->ap_fixed_rate) {
5943 if (nss == 4)
5944 ath_disable_txbf(dut, ifname);
5945
5946 /* Set the nss */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005947 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005948
5949 /* Set the channel width */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005950 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005951
5952 /* Set the VHT MCS */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005953 run_iwpriv(dut, ifname, "vhtmcs %d", dut->ap_mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954 }
5955 }
5956
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005957 if (dut->ap_dyn_bw_sig == VALUE_ENABLED)
5958 run_iwpriv(dut, ifname, "cwmenable 1");
5959 else if (dut->ap_dyn_bw_sig == VALUE_DISABLED)
5960 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005962 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005963 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5964 if (system(buf) != 0) {
5965 sigma_dut_print(dut, DUT_MSG_ERROR,
5966 "iwconfig rts 64 failed");
5967 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005968 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005969 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5970 if (system(buf) != 0) {
5971 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005972 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005973 }
5974 }
5975
5976 if (dut->ap_hs2) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005977 run_iwpriv(dut, ifname, "qbssload 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005978 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5979 }
5980
5981 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5982 unsigned int bssload = 0;
5983
5984 if (dut->ap_bss_load == 1) {
5985 /* STA count: 1, CU: 50, AAC: 65535 */
5986 bssload = 0x0132ffff;
5987 } else if (dut->ap_bss_load == 2) {
5988 /* STA count: 1, CU: 200, AAC: 65535 */
5989 bssload = 0x01c8ffff;
5990 } else if (dut->ap_bss_load == 3) {
5991 /* STA count: 1, CU: 75, AAC: 65535 */
5992 bssload = 0x014bffff;
5993 }
5994
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005995 run_iwpriv(dut, ifname, "hcbssload %u", bssload);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005996 } else if (dut->ap_bss_load == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005997 run_iwpriv(dut, ifname, "qbssload 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005998 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5999 }
6000
6001 if (dut->ap_dgaf_disable) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006002 run_iwpriv(dut, ifname, "dgaf_disable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006003 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
6004 }
6005
6006 if (dut->ap_l2tif) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006007 run_iwpriv(dut, ifname, "l2tif 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006008 snprintf(buf, sizeof(buf),
6009 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
6010 if (system(buf) != 0)
6011 sigma_dut_print(dut, DUT_MSG_ERROR,
6012 "l2tif br failed");
6013
6014 snprintf(buf, sizeof(buf),
6015 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
6016 if (system(buf) != 0)
6017 sigma_dut_print(dut, DUT_MSG_ERROR,
6018 "l2tif brif failed");
6019 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
6020 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08006021
6022 if (dut->ap_ndpa_frame == 0) {
6023 snprintf(buf, sizeof(buf),
6024 "wifitool %s beeliner_fw_test 117 192", ifname);
6025 if (system(buf) != 0) {
6026 sigma_dut_print(dut, DUT_MSG_ERROR,
6027 "wifitool beeliner_fw_test 117 192 failed");
6028 }
6029 snprintf(buf, sizeof(buf),
6030 "wifitool %s beeliner_fw_test 118 192", ifname);
6031 if (system(buf) != 0) {
6032 sigma_dut_print(dut, DUT_MSG_ERROR,
6033 "wifitool beeliner_fw_test 117 192 failed");
6034 }
6035 } else if (dut->ap_ndpa_frame == 1) {
6036 /* Driver default - no changes needed */
6037 } else if (dut->ap_ndpa_frame == 2) {
6038 snprintf(buf, sizeof(buf),
6039 "wifitool %s beeliner_fw_test 115 1", ifname);
6040 if (system(buf) != 0) {
6041 sigma_dut_print(dut, DUT_MSG_ERROR,
6042 "wifitool beeliner_fw_test 117 192 failed");
6043 }
6044 snprintf(buf, sizeof(buf),
6045 "wifitool %s beeliner_fw_test 116 1", ifname);
6046 if (system(buf) != 0) {
6047 sigma_dut_print(dut, DUT_MSG_ERROR,
6048 "wifitool beeliner_fw_test 117 192 failed");
6049 }
6050 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006051
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006052 if (dut->ap_rtt == 1)
6053 run_iwpriv(dut, ifname, "enable_rtt 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006054
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006055 if (dut->ap_lci == 1)
6056 run_iwpriv(dut, ifname, "enable_lci 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006057
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006058 if (dut->ap_lcr == 1)
6059 run_iwpriv(dut, ifname, "enable_lcr 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006060
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006061 if (dut->ap_rrm == 1)
6062 run_iwpriv(dut, ifname, "enable_rmm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006063
6064 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
6065 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
6066 }
6067
6068 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
6069 FILE *f;
6070
6071 f = fopen("/tmp/nbr_report.txt", "w");
6072 if (!f) {
6073 sigma_dut_print(dut, DUT_MSG_ERROR,
6074 "Failed to open /tmp/nbr_report.txt");
6075 return;
6076 }
6077
6078 fprintf(f,
6079 "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",
6080 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6081 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6082 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6083 dut->ap_val_opchannel[0]);
6084 fclose(f);
6085
6086 f = fopen("/tmp/ftmrr.txt", "w");
6087 if (!f) {
6088 sigma_dut_print(dut, DUT_MSG_ERROR,
6089 "Failed to open /tmp/ftmrr.txt");
6090 return;
6091 }
6092
6093 fprintf(f,
6094 "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",
6095 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
6096 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
6097 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
6098 dut->ap_val_opchannel[0]);
6099 fclose(f);
6100 }
6101
6102 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
6103 FILE *f;
6104
6105 f = fopen("/tmp/nbr_report.txt", "a");
6106 if (!f) {
6107 sigma_dut_print(dut, DUT_MSG_ERROR,
6108 "Failed to open /tmp/nbr_report.txt");
6109 return;
6110 }
6111 fprintf(f,
6112 "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",
6113 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6114 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6115 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6116 dut->ap_val_opchannel[1]);
6117 fclose(f);
6118
6119 f = fopen("/tmp/ftmrr.txt", "a");
6120 if (!f) {
6121 sigma_dut_print(dut, DUT_MSG_ERROR,
6122 "Failed to open /tmp/ftmrr.txt");
6123 return;
6124 }
6125 fprintf(f,
6126 "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",
6127 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
6128 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
6129 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
6130 dut->ap_val_opchannel[1]);
6131 fclose(f);
6132 }
6133
6134 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
6135 FILE *f;
6136
6137 f = fopen("/tmp/nbr_report.txt", "a");
6138 if (!f) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR,
6140 "Failed to open /tmp/nbr_report.txt");
6141 return;
6142 }
6143
6144 fprintf(f,
6145 "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",
6146 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6147 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6148 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6149 dut->ap_val_opchannel[2]);
6150 fclose(f);
6151
6152 f = fopen("/tmp/ftmrr.txt", "a");
6153 if (!f) {
6154 sigma_dut_print(dut, DUT_MSG_ERROR,
6155 "Failed to open /tmp/ftmrr.txt");
6156 return;
6157 }
6158
6159 fprintf(f,
6160 "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",
6161 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
6162 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
6163 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
6164 dut->ap_val_opchannel[2]);
6165 fclose(f);
6166 }
6167
6168 if (dut->ap_neighap) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006169 run_iwpriv(dut, ifname, "enable_rtt 1");
6170 run_iwpriv(dut, ifname, "enable_lci 1");
6171 run_iwpriv(dut, ifname, "enable_lcr 1");
6172 run_iwpriv(dut, ifname, "enable_rrm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006173 }
6174
6175 if (dut->ap_scan == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006176 run_iwpriv(dut, ifname, "scanentryage 600");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006177 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
6178 run_system(dut, buf);
6179 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006180
6181 if (dut->ap_set_bssidpref) {
6182 snprintf(buf, sizeof(buf),
6183 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
6184 ifname);
6185 if (system(buf) != 0) {
6186 sigma_dut_print(dut, DUT_MSG_ERROR,
6187 "wifitool clear bssidpref failed");
6188 }
6189 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006190
6191 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
6192 int feature_enable;
6193
6194 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006195 run_iwpriv(dut, ifname, "wnm %d", feature_enable);
6196 run_iwpriv(dut, ifname, "wnm_bss %d", feature_enable);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006197 if (feature_enable) {
6198 const char *extra = "";
6199
6200 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
6201 if (dut->wnm_bss_max_protection ==
6202 VALUE_ENABLED)
6203 extra = " 1";
6204 else
6205 extra = " 0";
6206 }
6207 snprintf(buf, sizeof(buf),
6208 "wlanconfig %s wnm setbssmax %d%s",
6209 ifname, dut->wnm_bss_max_idle_time, extra);
6210 run_system(dut, buf);
6211 }
6212 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006213
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006214 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006215 apply_mbo_pref_ap_list(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006216 run_iwpriv(dut, ifname, "mbo_cel_pref %d",
6217 dut->ap_cell_cap_pref);
6218 run_iwpriv(dut, ifname, "mbocap 0x40");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07006219 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006220 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006221
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006222 if (dut->ap_oce == VALUE_ENABLED)
6223 run_iwpriv(dut, ifname, "set_bpr_enable 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006224
6225 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006226 run_iwpriv(dut, ifname, "prb_rate 5500");
6227 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006228 }
6229
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006230 if (dut->ap_oce == VALUE_DISABLED)
6231 run_iwpriv(dut, ifname, "set_bpr_enable 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006232
6233 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006234 run_iwpriv(dut, ifname, "mgmt_rate 1000");
6235 run_iwpriv(dut, ifname, "set_bcn_rate 1000");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006236 }
6237
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006238 if (dut->ap_bcnint)
6239 run_iwpriv(dut, ifname, "bintval %d", dut->ap_bcnint);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006240
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006241 if (dut->ap_filsdscv == VALUE_DISABLED)
6242 run_iwpriv(dut, ifname, "enable_fils 0 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006243
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006244 if (dut->ap_filshlp == VALUE_ENABLED)
6245 run_iwpriv(dut, ifname, "oce_hlp 1");
6246 else if (dut->ap_filshlp == VALUE_DISABLED)
6247 run_iwpriv(dut, ifname, "oce_hlp 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006248
6249 /* When RNR is enabled, also enable apchannelreport, background scan */
6250 if (dut->ap_rnr == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006251 run_iwpriv(dut, ifname, "rnr 1");
6252 run_iwpriv(dut, ifname, "rnr_tbtt 1");
6253 run_iwpriv(dut, ifname, "apchanrpt 1");
6254 run_iwpriv(dut, basedev, "acs_ctrlflags 0x4");
6255 run_iwpriv(dut, basedev, "acs_scanintvl 60");
6256 run_iwpriv(dut, basedev, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006257 if (dut->ap_is_dual == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006258 run_iwpriv(dut, ifname_dual, "rnr 1");
6259 run_iwpriv(dut, ifname_dual, "rnr_tbtt 1");
6260 run_iwpriv(dut, ifname_dual, "apchanrpt 1");
6261 run_iwpriv(dut, basedev_radio, "acs_ctrlflags 0x4");
6262 run_iwpriv(dut, basedev_radio, "acs_scanintvl 60");
6263 run_iwpriv(dut, basedev_radio, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006264 }
6265 }
6266
6267 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006268 run_iwpriv(dut, ifname, "qbssload 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006269 snprintf(buf, sizeof(buf),
6270 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
6271 ifname, dut->ap_blestacnt & 0xFF,
6272 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6273 dut->ap_ble_admit_cap & 0xFF,
6274 dut->ap_ble_admit_cap >> 8);
6275 run_system(dut, buf);
6276 snprintf(buf, sizeof(buf),
6277 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
6278 ifname, dut->ap_blestacnt & 0xFF,
6279 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
6280 dut->ap_ble_admit_cap & 0xFF,
6281 dut->ap_ble_admit_cap >> 8);
6282 run_system(dut, buf);
6283 }
6284
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006285 if (dut->ap_esp == VALUE_ENABLED)
6286 run_iwpriv(dut, basedev, "esp_period 5");
6287 else if (dut->ap_esp == VALUE_DISABLED)
6288 run_iwpriv(dut, basedev, "esp_period 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006289
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006290 if (dut->ap_datappdudura)
6291 run_iwpriv(dut, basedev, "esp_ppdu_dur %d",
6292 dut->ap_datappdudura);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006293
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006294 if (dut->ap_airtimefract)
6295 run_iwpriv(dut, basedev, "esp_airtime %d",
6296 dut->ap_airtimefract);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08006297
6298 if (dut->ap_dhcp_stop) {
6299 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
6300 run_system(dut, buf);
6301 }
6302
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006303 if (dut->ap_bawinsize)
6304 run_iwpriv(dut, basedev, "esp_ba_window %d", dut->ap_bawinsize);
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006305
6306 if (dut->program == PROGRAM_DPP) {
6307 if (dut->ap_interface_2g == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006308 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
6309 run_iwpriv(dut, ifname, "prb_rate 5500");
6310 run_iwpriv(dut, ifname, "mgmt_rate 5500");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006311 }
6312
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006313 run_iwpriv(dut, basedev, "set_rxfilter 0xffffffff");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08006314 dut->hostapd_running = 1;
6315 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006316
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006317 if (dut->program == PROGRAM_HE) {
6318 /* disable sending basic triggers */
6319 run_system_wrapper(dut,
6320 "wifitool %s setUnitTestCmd 0x47 2 42 0",
6321 ifname);
6322 /* disable MU BAR */
6323 run_system_wrapper(dut,
6324 "wifitool %s setUnitTestCmd 0x47 2 64 1",
6325 ifname);
6326 /* disable PSD Boost */
6327 run_system_wrapper(dut,
6328 "wifitool %s setUnitTestCmd 0x48 2 142 1",
6329 ifname);
6330 /* Enable mix bw */
6331 run_system_wrapper(dut,
6332 "wifitool %s setUnitTestCmd 0x47 2 141 1",
6333 ifname);
6334 /* Disable preferred AC */
6335 run_system_wrapper(dut,
6336 "wifitool %s setUnitTestCmd 0x48 2 186 0",
6337 ifname);
6338 run_iwpriv(dut, basedev, "he_muedca_mode 0");
6339 run_iwpriv(dut, ifname, "he_ul_ofdma 0");
6340 run_iwpriv(dut, ifname, "he_dl_ofdma 0");
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08006341 if (dut->he_set_sta_1x1 == VALUE_ENABLED) {
6342 /* sets g_force_1x1_peer to 1 */
6343 run_system_wrapper(dut,
6344 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6345 ifname);
6346 }
Priyadharshini Gowthamand8d5f582019-11-25 15:39:43 -08006347 if (dut->ap_txBF) {
6348 /* Enable SU_AX sounding */
6349 run_iwpriv(dut, ifname, "he_sounding_mode 1");
6350 /* Ignore TBTT for NDP */
6351 run_system_wrapper(dut,
6352 "wifitool %s setUnitTestCmd 0x48 2 2 1",
6353 ifname);
6354 /* g_cv_query_enable=1, i.e., cv query enable */
6355 run_system_wrapper(dut,
6356 "wifitool %s setUnitTestCmd 0x47 2 7 1",
6357 ifname);
6358 /* Override TPC calculations and set TxBF flag to True
6359 */
6360 run_system_wrapper(dut,
6361 "wifitool %s setUnitTestCmd 0x47 2 47 1",
6362 ifname);
6363 }
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006364 if (dut->device_type == AP_testbed) {
6365 run_iwpriv(dut, ifname, "tx_stbc 0");
6366 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6367 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6368 run_iwpriv(dut, ifname, "he_amsdu_in_ampdu_supp 0");
6369 run_iwpriv(dut, ifname, "he_bfee_sts_supp 0 0");
6370 run_iwpriv(dut, ifname, "he_4xltf_800nsgi_rx 0");
6371 run_iwpriv(dut, ifname, "he_1xltf_800nsgi_rx 0");
6372 run_iwpriv(dut, ifname, "he_max_nc 0");
6373 run_iwpriv(dut, ifname, "he_bsr_supp 0");
6374 run_iwpriv(dut, ifname, "rx_stbc 0");
6375 if (dut->ap_he_dlofdma == VALUE_DISABLED)
6376 run_iwpriv(dut, ifname, "he_dlofdma 0");
6377 if (dut->ap_channel <= 11) {
6378 dut->ap_bcc = VALUE_ENABLED;
6379 run_iwpriv(dut, ifname, "vht_11ng 0");
6380 }
6381 if (!dut->ap_txBF) {
6382 run_iwpriv(dut, ifname, "he_subfer 0");
6383 run_iwpriv(dut, ifname, "he_subfee 0");
6384 }
6385 if (!dut->ap_mu_txBF) {
6386 run_iwpriv(dut, ifname, "he_mubfer 0");
6387 run_iwpriv(dut, ifname, "he_mubfee 0");
6388 }
Priyadharshini Gowthamane9d0bfc2019-11-22 14:26:12 -08006389 if (dut->ap_cipher == AP_WEP ||
6390 dut->ap_cipher == AP_TKIP)
6391 run_iwpriv(dut, ifname, "htweptkip 1");
Priyadharshini Gowthaman2e0731b2019-11-25 15:38:58 -08006392 if (dut->ap_rx_streams || dut->ap_tx_streams)
6393 run_iwpriv(dut, ifname, "nss %d",
6394 dut->ap_rx_streams);
Priyadharshini Gowthamanb8fe0532019-11-21 16:15:38 -08006395 }
6396 }
6397
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006398 if (dut->ap_he_ulofdma == VALUE_ENABLED) {
6399 run_iwpriv(dut, ifname, "he_ul_ofdma 1");
6400 run_iwpriv(dut, ifname, "he_mu_edca 1");
6401
6402 /* Disable sounding for UL OFDMA */
6403 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006404 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006405
6406 if ((dut->ap_rx_streams || dut->ap_tx_streams) &&
6407 dut->device_type == AP_testbed) {
6408 unsigned int txchainmask = 0x00;
6409
6410 switch (dut->ap_rx_streams) {
6411 case 1:
6412 txchainmask = 0x01;
6413 break;
6414 case 2:
6415 txchainmask = 0x03;
6416 break;
6417 case 3:
6418 txchainmask = 0x07;
6419 break;
6420 case 4:
6421 txchainmask = 0x0f;
6422 break;
6423 case 5:
6424 txchainmask = 0x1f;
6425 break;
6426 case 6:
6427 txchainmask = 0x3f;
6428 break;
6429 case 7:
6430 txchainmask = 0x7f;
6431 break;
6432 case 8:
6433 txchainmask = 0xff;
6434 break;
6435 }
6436
6437 run_iwpriv(dut, ifname, "he_ul_nss %d",
6438 dut->ap_rx_streams);
6439 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6440 run_iwpriv(dut, basedev, "rxchainmask %d", txchainmask);
6441 }
6442
6443 if (dut->ap_channel == 100 && dut->device_type == AP_testbed)
6444 run_system_wrapper(dut, "iwpriv %s inact 1000", ifname);
6445
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006446 if (dut->he_ul_mcs)
6447 run_iwpriv(dut, ifname, "he_ul_mcs %d", dut->he_ul_mcs);
6448
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006449 run_iwpriv(dut, ifname, "he_ul_ltf 3");
6450 run_iwpriv(dut, ifname, "he_ul_shortgi 3");
6451 run_iwpriv(dut, basedev, "he_ul_trig_int 2");
6452
Priyadharshini Gowthamana17e6d82019-12-12 14:31:09 -08006453 /* Disable efficiency check for UL OFDMA. We do not send TBPPDU
6454 * for one user. With this command, we would send UL OFDMA even
6455 * for one user to allow testing to be done without requiring
6456 * more than one station. */
6457 run_system_wrapper(dut,
6458 "wifitool %s setUnitTestCmd 0x47 2 131 0",
6459 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006460 /* Set random RU allocation */
6461 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 9 1",
6462 ifname);
6463 /* To set TBTT PPDU duration (us) */
6464 run_system_wrapper(dut,
6465 "wifitool %s setUnitTestCmd 0x48 2 63 1908",
6466 ifname);
6467 }
6468
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006469 if (dut->ap_he_dlofdma == VALUE_ENABLED) {
6470 run_iwpriv(dut, ifname, "he_dl_ofdma 1", ifname);
6471
6472 /* For fixed MCS */
6473 novap_reset(dut, ifname, 0);
6474 run_iwpriv(dut, ifname,
6475 "cfg80211tool %s setratemask 3 0x80f80f80 0x0f80f80f 0xf80f80f8");
6476 }
6477
6478 if (dut->ap_he_ppdu == PPDU_MU && dut->ap_he_dlofdma == VALUE_ENABLED) {
6479 /* Increase the min TX time limit for MU MIMO to disable MU MIMO
6480 * scheduling */
6481 run_system_wrapper(dut,
6482 "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
6483 ifname);
6484 /* Increase the max TX time limit for DL OFDMA to enable OFDMA
6485 * scheduling */
6486 run_system_wrapper(dut,
6487 "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
6488 ifname);
6489 /* Disable 'force SU schedule' to enable MU sch */
6490 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 8 0",
6491 ifname);
6492 /* Enable MU 11ax support in sch algo */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006493 run_system_wrapper(dut,
6494 "wifitool %s setUnitTestCmd 0x47 2 29 0",
6495 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006496 /* Enable to sort RU allocation */
6497 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x4b 2 2 1",
6498 ifname);
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006499 }
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07006500
6501 if (dut->ap_numsounddim) {
6502 unsigned int txchainmask = 0;
6503
6504 switch (dut->ap_numsounddim) {
6505 case 1:
6506 txchainmask = 0x01;
6507 break;
6508 case 2:
6509 txchainmask = 0x03;
6510 break;
6511 case 3:
6512 txchainmask = 0x07;
6513 break;
6514 case 4:
6515 txchainmask = 0x0f;
6516 break;
6517 case 5:
6518 txchainmask = 0x1f;
6519 break;
6520 case 6:
6521 txchainmask = 0x3f;
6522 break;
6523 case 7:
6524 txchainmask = 0x7f;
6525 break;
6526 case 8:
6527 txchainmask = 0xff;
6528 break;
6529 }
6530 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6531 }
6532
6533 if (dut->ap_numsounddim && dut->device_type == AP_testbed) {
6534 /* Sets g_force_1x1_peer to 1 which should be reset to zero
6535 * for non-MU test cases */
6536 run_system_wrapper(dut,
6537 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6538 ifname);
6539 if (dut->ap_mu_txBF) {
6540 /* Disable DL OFDMA */
6541 run_system_wrapper(dut,
6542 "wifitool %s setUnitTestCmd 0x47 2 11 0",
6543 ifname);
6544 }
6545 }
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006546
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006547 if (dut->ap_bcc == VALUE_ENABLED) {
6548 run_iwpriv(dut, ifname, "mode 11AHE20");
6549 run_iwpriv(dut, ifname, "nss 2");
6550 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6551 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6552 }
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07006553
6554 if (dut->ap_he_frag == VALUE_ENABLED)
6555 run_iwpriv(dut, ifname, "he_frag 1");
6556 else if (dut->ap_he_frag == VALUE_DISABLED)
6557 run_iwpriv(dut, ifname, "he_frag 0");
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07006558
6559 if (dut->ap_ba_bufsize != BA_BUFSIZE_NOT_SET) {
6560 if (dut->ap_ba_bufsize == BA_BUFSIZE_64)
6561 run_iwpriv(dut, ifname, "ba_bufsize 0");
6562 else
6563 run_iwpriv(dut, ifname, "ba_bufsize 1");
6564 }
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07006565
6566 if (dut->ap_mu_edca == VALUE_ENABLED)
6567 run_iwpriv(dut, ifname, "he_mu_edca 1");
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07006568
6569 if (dut->ap_he_mimo == MIMO_DL) {
6570 mubrp_commands(dut, ifname);
6571 if (dut->device_type != AP_testbed)
6572 run_system_wrapper(
6573 dut, "wifitool %s setUnitTestCmd 0x48 2 100 2",
6574 ifname);
6575 }
6576
6577 if (dut->ap_he_mimo == MIMO_UL)
6578 run_iwpriv(dut, ifname, "he_mubfee 1");
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07006579
6580 if (dut->ap_he_rtsthrshld == VALUE_ENABLED)
6581 run_iwpriv(dut, ifname, "he_rtsthrshld 512");
6582 else if (dut->ap_he_rtsthrshld == VALUE_DISABLED)
6583 run_iwpriv(dut, ifname, "he_rtsthrshld 1024");
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07006584
6585 if (dut->ap_mbssid == VALUE_ENABLED &&
6586 (dut->ap_rx_streams || dut->ap_tx_streams) &&
6587 dut->device_type == AP_testbed) {
6588 const char *ifname_1;
6589
6590 ifname_1= dut->ap_channel >= 36 ? "ath01" : "ath11";
6591
6592 /* NSS is not set in Secondary VAP for MBSSID case,
6593 * hence it is explicitly set here. For primary VAP
6594 * NSS is set during AP configuration */
6595 run_iwpriv(dut, ifname_1, "nss %d", dut->ap_rx_streams);
6596 }
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07006597
6598 if (dut->ap_twtresp == VALUE_ENABLED)
6599 run_iwpriv(dut, ifname, "twt_responder 1");
6600 else if (dut->ap_twtresp == VALUE_DISABLED)
6601 run_iwpriv(dut, ifname, "twt_responder 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08006602
6603 if (dut->program == PROGRAM_HE && dut->ap_fixed_rate) {
6604 int nss = 0, mcs = 0;
6605 uint16_t mcsnssmap = 0;
6606
6607 /* MCS 7 is used - set only nss and he_mcs.
6608 * Do not set mcsnssmap unless MCS is 9 or 11. */
6609 if (dut->ap_mcs >= 9) {
6610 if (dut->ap_mcs == 9) {
6611 if (dut->ap_tx_streams == 1) {
6612 nss = 1;
6613 mcs = dut->ap_mcs;
6614 } else if (dut->ap_tx_streams == 2) {
6615 nss = 2;
6616 mcs = dut->ap_mcs;
6617 }
6618 } else if (dut->ap_mcs == 11) {
6619 if (dut->ap_tx_streams == 1) {
6620 nss = 1;
6621 mcs = dut->ap_mcs;
6622 } else if (dut->ap_tx_streams == 2) {
6623 nss = 2;
6624 mcs = dut->ap_mcs;
6625 }
6626 }
6627
6628 get_he_mcs_nssmap((uint8_t *) &mcsnssmap, nss, mcs);
6629 he_mcsnssmap = (mcsnssmap << 16) | mcsnssmap;
6630 }
6631
6632 run_iwpriv(dut, ifname, "nss %d", dut->ap_tx_streams);
6633 run_iwpriv(dut, ifname, "he_mcs %d", dut->ap_mcs);
6634 }
6635
6636 if (he_mcsnssmap) {
6637 run_iwpriv(dut, ifname, "he_rxmcsmap %lu", he_mcsnssmap);
6638 run_iwpriv(dut, ifname, "he_txmcsmap %lu", he_mcsnssmap);
6639 }
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08006640
6641 if (dut->he_sounding == VALUE_ENABLED)
6642 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
6643 ifname);
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08006644
6645 if (dut->he_mmss)
6646 run_iwpriv(dut, ifname, "ampduden_ovrd %d", dut->he_mmss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006647}
6648
6649
6650static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
6651 struct sigma_conn *conn,
6652 struct sigma_cmd *cmd)
6653{
6654 /* const char *name = get_param(cmd, "NAME"); */
6655 char buf[100];
6656 struct stat s;
6657 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
Jouni Malinen3aa72862019-05-29 23:14:51 +03006658 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006659
6660 if (stat("/proc/athversion", &s) == 0) {
6661 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
6662 run_system(dut, "apdown");
6663 }
6664
6665 cmd_ath_ap_radio_config(dut);
6666
6667 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
6668 run_system(dut, buf);
6669
6670 switch (dut->ap_key_mgmt) {
6671 case AP_OPEN:
6672 if (dut->ap_cipher == AP_WEP) {
6673 run_system(dut, "cfg -a AP_SECMODE=WEP");
6674 run_system(dut, "cfg -a AP_SECFILE=NONE");
6675 /* shared auth mode not supported */
6676 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6677 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6678 snprintf(buf, sizeof(buf),
6679 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6680 dut->ap_wepkey);
6681 run_system(dut, buf);
6682 snprintf(buf, sizeof(buf),
6683 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6684 dut->ap_wepkey);
6685 run_system(dut, buf);
6686 } else {
6687 run_system(dut, "cfg -a AP_SECMODE=None");
6688 }
6689 break;
6690 case AP_WPA2_PSK:
6691 case AP_WPA2_PSK_MIXED:
6692 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006693 case AP_WPA2_SAE:
6694 case AP_WPA2_PSK_SAE:
6695 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6696 dut->ap_key_mgmt == AP_WPA2_SAE ||
6697 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006698 run_system(dut, "cfg -a AP_WPA=2");
6699 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6700 run_system(dut, "cfg -a AP_WPA=3");
6701 else
6702 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03006703 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006704 run_system(dut, "cfg -a AP_SECMODE=WPA");
6705 run_system(dut, "cfg -a AP_SECFILE=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006706 res = snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
6707 dut->ap_passphrase);
6708 if (res < 0 || res >= sizeof(buf))
6709 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006710 run_system(dut, buf);
6711 if (dut->ap_cipher == AP_CCMP_TKIP)
6712 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6713 else if (dut->ap_cipher == AP_TKIP)
6714 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6715 else
6716 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6717 break;
6718 case AP_WPA2_EAP:
6719 case AP_WPA2_EAP_MIXED:
6720 case AP_WPA_EAP:
6721 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6722 run_system(dut, "cfg -a AP_WPA=2");
6723 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6724 run_system(dut, "cfg -a AP_WPA=3");
6725 else
6726 run_system(dut, "cfg -a AP_WPA=1");
6727 run_system(dut, "cfg -a AP_SECMODE=WPA");
6728 run_system(dut, "cfg -a AP_SECFILE=EAP");
6729 if (dut->ap_cipher == AP_CCMP_TKIP)
6730 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6731 else if (dut->ap_cipher == AP_TKIP)
6732 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6733 else
6734 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6735 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6736 dut->ap_radius_ipaddr);
6737 run_system(dut, buf);
6738 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6739 dut->ap_radius_port);
6740 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006741 res = snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6742 dut->ap_radius_password);
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 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006747 case AP_WPA2_EAP_OSEN:
6748 /* TODO */
6749 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6750 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006751 case AP_SUITEB:
6752 /* TODO */
6753 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6754 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006755 case AP_WPA2_OWE:
6756 /* TODO */
6757 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6758 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006759 case AP_WPA2_FT_EAP:
6760 case AP_WPA2_FT_PSK:
6761 case AP_WPA2_EAP_SHA256:
6762 case AP_WPA2_PSK_SHA256:
6763 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006764 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006765 /* TODO */
6766 send_resp(dut, conn, SIGMA_ERROR,
6767 "errorCode,Unsupported KeyMgnt value");
6768 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006769 }
6770
6771 if (dut->ap_is_dual) {
6772 /* ath1 settings in case of dual */
6773 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6774 dut->ap_ssid);
6775 run_system(dut, buf);
6776
6777 switch (dut->ap_key_mgmt) {
6778 case AP_OPEN:
6779 if (dut->ap_cipher == AP_WEP) {
6780 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6781 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6782 /* shared auth mode not supported */
6783 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6784 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6785 snprintf(buf, sizeof(buf),
6786 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6787 dut->ap_wepkey);
6788 run_system(dut, buf);
6789 snprintf(buf, sizeof(buf),
6790 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6791 dut->ap_wepkey);
6792 run_system(dut, buf);
6793 } else {
6794 run_system(dut, "cfg -a AP_SECMODE_2=None");
6795 }
6796 break;
6797 case AP_WPA2_PSK:
6798 case AP_WPA2_PSK_MIXED:
6799 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006800 case AP_WPA2_SAE:
6801 case AP_WPA2_PSK_SAE:
6802 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6803 dut->ap_key_mgmt == AP_WPA2_SAE ||
6804 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006805 run_system(dut, "cfg -a AP_WPA_2=2");
6806 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6807 run_system(dut, "cfg -a AP_WPA_2=3");
6808 else
6809 run_system(dut, "cfg -a AP_WPA_2=1");
6810 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006811 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006812 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6813 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006814 res = snprintf(buf, sizeof(buf),
6815 "cfg -a 'PSK_KEY_2=%s'",
6816 dut->ap_passphrase);
6817 if (res < 0 || res >= sizeof(buf))
6818 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006819 run_system(dut, buf);
6820 if (dut->ap_cipher == AP_CCMP_TKIP)
6821 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6822 else if (dut->ap_cipher == AP_TKIP)
6823 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6824 else
6825 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6826 break;
6827 case AP_WPA2_EAP:
6828 case AP_WPA2_EAP_MIXED:
6829 case AP_WPA_EAP:
6830 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6831 run_system(dut, "cfg -a AP_WPA_2=2");
6832 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6833 run_system(dut, "cfg -a AP_WPA_2=3");
6834 else
6835 run_system(dut, "cfg -a AP_WPA_2=1");
6836 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6837 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6838 if (dut->ap_cipher == AP_CCMP_TKIP)
6839 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6840 else if (dut->ap_cipher == AP_TKIP)
6841 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6842 else
6843 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6844
6845 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6846 dut->ap_radius_ipaddr);
6847 run_system(dut, buf);
6848 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6849 dut->ap_radius_port);
6850 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006851 res = snprintf(buf, sizeof(buf),
6852 "cfg -a AP_AUTH_SECRET_2=%s",
6853 dut->ap_radius_password);
6854 if (res < 0 || res >= sizeof(buf))
6855 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006856 run_system(dut, buf);
6857 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006858 case AP_WPA2_EAP_OSEN:
6859 /* TODO */
6860 sigma_dut_print(dut, DUT_MSG_ERROR,
6861 "EAP+OSEN not supported");
6862 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006863 case AP_SUITEB:
6864 /* TODO */
6865 sigma_dut_print(dut, DUT_MSG_ERROR,
6866 "SuiteB not supported");
6867 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006868 case AP_WPA2_OWE:
6869 /* TODO */
6870 sigma_dut_print(dut, DUT_MSG_ERROR,
6871 "OWE not supported");
6872 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006873 case AP_WPA2_FT_EAP:
6874 case AP_WPA2_FT_PSK:
6875 case AP_WPA2_EAP_SHA256:
6876 case AP_WPA2_PSK_SHA256:
6877 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006878 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006879 /* TODO */
6880 send_resp(dut, conn, SIGMA_ERROR,
6881 "errorCode,Unsupported KeyMgnt value");
6882 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006883 }
6884
6885 /* wifi0 settings in case of dual */
6886 run_system(dut, "cfg -a AP_RADIO_ID=0");
6887 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6888 run_system(dut, "cfg -a AP_STARTMODE=dual");
6889 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6890 run_system(dut, "cfg -a TX_CHAINMASK=7");
6891 run_system(dut, "cfg -a RX_CHAINMASK=7");
6892 }
6893
6894 switch (dut->ap_pmf) {
6895 case AP_PMF_DISABLED:
6896 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6897 run_system(dut, buf);
6898 break;
6899 case AP_PMF_OPTIONAL:
6900 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6901 run_system(dut, buf);
6902 break;
6903 case AP_PMF_REQUIRED:
6904 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6905 run_system(dut, buf);
6906 break;
6907 }
6908 if (dut->ap_add_sha256) {
6909 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6910 run_system(dut, buf);
6911 } else {
6912 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6913 run_system(dut, buf);
6914 }
6915
6916 if (dut->ap_hs2)
6917 run_system(dut, "cfg -a AP_HOTSPOT=1");
6918 else
6919 run_system(dut, "cfg -r AP_HOTSPOT");
6920
6921 if (dut->ap_interworking) {
6922 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6923 dut->ap_access_net_type);
6924 run_system(dut, buf);
6925 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6926 dut->ap_internet);
6927 run_system(dut, buf);
6928 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6929 dut->ap_venue_group);
6930 run_system(dut, buf);
6931 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6932 dut->ap_venue_type);
6933 run_system(dut, buf);
6934 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6935 dut->ap_hessid);
6936 run_system(dut, buf);
6937
6938 if (dut->ap_roaming_cons[0]) {
6939 char *second, *rc;
6940 rc = strdup(dut->ap_roaming_cons);
6941 if (rc == NULL)
6942 return 0;
6943
6944 second = strchr(rc, ';');
6945 if (second)
6946 *second++ = '\0';
6947
6948 snprintf(buf, sizeof(buf),
6949 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6950 run_system(dut, buf);
6951
6952 if (second) {
6953 snprintf(buf, sizeof(buf),
6954 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6955 "=%s", second);
6956 run_system(dut, buf);
6957 }
6958 free(rc);
6959 } else {
6960 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6961 run_system(dut,
6962 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6963 }
6964 } else {
6965 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6966 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6967 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6968 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6969 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6970 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6971 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6972 }
6973
6974 if (dut->ap_proxy_arp)
6975 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6976 else
6977 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6978 if (dut->ap_dgaf_disable)
6979 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6980 else
6981 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6982
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006983 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006984 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006985 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006986 run_system(dut, buf);
6987
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006988 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006989 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6990 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6991
Jouni Malinen3aa72862019-05-29 23:14:51 +03006992 res = snprintf(buf, sizeof(buf),
6993 "cfg -a AP_AUTH_SERVER_2=%s",
6994 dut->ap2_radius_ipaddr);
6995 if (res < 0 || res >= sizeof(buf))
6996 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006997 run_system(dut, buf);
6998
Jouni Malinen3aa72862019-05-29 23:14:51 +03006999 res = snprintf(buf, sizeof(buf),
7000 "cfg -a AP_AUTH_PORT_2=%d",
7001 dut->ap2_radius_port);
7002 if (res < 0 || res >= sizeof(buf))
7003 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007004 run_system(dut, buf);
7005
Jouni Malinen3aa72862019-05-29 23:14:51 +03007006 res = snprintf(buf, sizeof(buf),
7007 "cfg -a AP_AUTH_SECRET_2=%s",
7008 dut->ap2_radius_password);
7009 if (res < 0 || res >= sizeof(buf))
7010 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007011 run_system(dut, buf);
7012 } else {
7013 run_system(dut, "cfg -a AP_SECMODE_2=None");
7014 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
7015 run_system(dut, "cfg -r AP_AUTH_PORT_2");
7016 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
7017 }
7018
7019 run_system(dut, "cfg -a AP_STARTMODE=multi");
7020 }
7021
7022 run_system(dut, "cfg -c");
7023
7024 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
7025 if (system("apup") != 0) {
7026 /* to be debugged why apup returns error
7027 send_resp(dut, conn, SIGMA_ERROR,
7028 "errorCode,apup failed");
7029 return 0;
7030 */
7031 }
7032 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
7033
7034 if (dut->ap_key_mgmt != AP_OPEN) {
7035 int res;
7036 /* allow some time for hostapd to start before returning
7037 * success */
7038 usleep(500000);
7039 if (run_hostapd_cli(dut, "ping") != 0) {
7040 send_resp(dut, conn, SIGMA_ERROR,
7041 "errorCode,Failed to talk to hostapd");
7042 return 0;
7043 }
7044
7045 if (dut->ap_hs2 && !dut->ap_anqpserver) {
7046 /* the cfg app doesn't like ";" in the variables */
7047 res = ath_ap_append_hostapd_conf(dut);
7048 if (res < 0)
7049 return res;
7050
7051 /* wait for hostapd to be ready */
7052 usleep(500000);
7053 if (run_hostapd_cli(dut, "ping") != 0) {
7054 send_resp(dut, conn, SIGMA_ERROR,
7055 "errorCode,Failed to talk to "
7056 "hostapd");
7057 return 0;
7058 }
7059 }
7060 }
7061
7062 ath_ap_set_params(dut);
7063
7064 if (dut->ap_anqpserver)
7065 return cmd_ath_ap_anqpserver_start(dut);
7066
7067 if (dut->ap2_proxy_arp)
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007068 run_iwpriv(dut, ifname, "proxy_arp 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007069
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07007070 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip)
7071 run_iwpriv(dut, ifname, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072
7073 return 1;
7074}
7075
7076
7077static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
7078 const char *ifname)
7079{
7080 char buf[200];
7081
7082 if (!chain || !ifname)
7083 return -2;
7084
7085 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7086 if (system(buf) != 0) {
7087 sigma_dut_print(dut, DUT_MSG_ERROR,
7088 "Failed to set ebtables rules, RULE-1, %s",
7089 chain);
7090 return -2;
7091 }
7092
7093 snprintf(buf, sizeof(buf),
7094 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7095 chain, ifname);
7096 if (system(buf) != 0) {
7097 sigma_dut_print(dut, DUT_MSG_ERROR,
7098 "Failed to set ebtables rules, RULE-2, %s",
7099 chain);
7100 return -2;
7101 }
7102
7103 snprintf(buf, sizeof(buf),
7104 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
7105 chain, ifname);
7106 if (system(buf) != 0) {
7107 sigma_dut_print(dut, DUT_MSG_ERROR,
7108 "Failed to set ebtables rules, RULE-3, %s",
7109 chain);
7110 return -2;
7111 }
7112
7113 snprintf(buf, sizeof(buf),
7114 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
7115 chain, ifname);
7116 if (system(buf) != 0) {
7117 sigma_dut_print(dut, DUT_MSG_ERROR,
7118 "Failed to set ebtables rules, RULE-4, %s",
7119 chain);
7120 return -2;
7121 }
7122
7123 return 0;
7124}
7125
7126
7127static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
7128 const char *chain,
7129 const char *ifname)
7130{
7131 char buf[200];
7132
7133 if (!chain || !ifname)
7134 return -2;
7135
7136 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
7137 if (system(buf) != 0) {
7138 sigma_dut_print(dut, DUT_MSG_ERROR,
7139 "Failed to set ebtables rules, RULE-5, %s",
7140 chain);
7141 return -2;
7142 }
7143
7144 snprintf(buf, sizeof(buf),
7145 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
7146 chain, ifname);
7147 if (system(buf) != 0) {
7148 sigma_dut_print(dut, DUT_MSG_ERROR,
7149 "Failed to set ebtables rules, RULE-6, %s",
7150 chain);
7151 return -2;
7152 }
7153
7154 snprintf(buf, sizeof(buf),
7155 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
7156 chain, ifname);
7157 if (system(buf) != 0) {
7158 sigma_dut_print(dut, DUT_MSG_ERROR,
7159 "Failed to set ebtables rules, RULE-7, %s",
7160 chain);
7161 return -2;
7162 }
7163
7164 snprintf(buf, sizeof(buf),
7165 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
7166 chain, ifname);
7167 if (system(buf) != 0) {
7168 sigma_dut_print(dut, DUT_MSG_ERROR,
7169 "Failed to set ebtables rules, RULE-8, %s",
7170 chain);
7171 return -2;
7172 }
7173
7174 return 0;
7175}
7176
7177
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007178static void set_ebtables_forward_drop(struct sigma_dut *dut,
7179 const char *ifname, const char *ifname2)
7180{
7181 char buf[128];
7182
7183 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7184 ifname, ifname2);
7185 if (system(buf) != 0)
7186 sigma_dut_print(dut, DUT_MSG_ERROR,
7187 "Failed to set ebtables rule");
7188
7189 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
7190 ifname2, ifname);
7191 if (system(buf) != 0)
7192 sigma_dut_print(dut, DUT_MSG_ERROR,
7193 "Failed to set ebtables rule");
7194}
7195
7196
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007197static int check_channel(int channel)
7198{
7199 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
7200 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
7201 161, 165 };
7202 int num_chan = sizeof(channel_list) / sizeof(int);
7203 int i;
7204
7205 for (i = 0; i < num_chan; i++) {
7206 if (channel == channel_list[i])
7207 return i;
7208 }
7209
7210 return -1;
7211}
7212
7213
7214static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
7215{
7216 int ch_base;
7217 int period;
7218
7219 if (check_channel(channel) < 0)
7220 return -1;
7221
7222 if (channel >= 36 && channel <= 64)
7223 ch_base = 36;
7224 else if (channel >= 100 && channel <= 144)
7225 ch_base = 100;
7226 else
7227 ch_base = 149;
7228
7229 period = channel % ch_base * 5 / chwidth;
7230 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
7231}
7232
7233
7234static int is_ht40plus_chan(int chan)
7235{
7236 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
7237 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
7238 chan == 132 || chan == 149 || chan == 157;
7239}
7240
7241
7242static int is_ht40minus_chan(int chan)
7243{
7244 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
7245 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
7246 chan == 136 || chan == 153 || chan == 161;
7247}
7248
7249
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05307250static int get_5g_channel_freq(int chan)
7251{
7252 return 5000 + chan * 5;
7253}
7254
7255
Jouni Malinen3d633da2017-09-14 22:19:21 +03007256static const char * hostapd_cipher_name(enum ap_cipher cipher)
7257{
7258 switch (cipher) {
7259 case AP_CCMP:
7260 return "CCMP";
7261 case AP_TKIP:
7262 return "TKIP";
7263 case AP_CCMP_TKIP:
7264 return "CCMP TKIP";
7265 case AP_GCMP_256:
7266 return "GCMP-256";
7267 case AP_GCMP_128:
7268 return "GCMP";
7269 case AP_CCMP_256:
7270 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02007271 case AP_CCMP_128_GCMP_256:
7272 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007273 default:
7274 return "UNKNOWN";
7275 }
7276}
7277
7278
7279static const char *
7280hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
7281{
7282 switch (cipher) {
7283 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03007284 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03007285 case AP_BIP_CMAC_256:
7286 return "BIP-CMAC-256";
7287 case AP_BIP_GMAC_128:
7288 return "BIP-GMAC-128";
7289 case AP_BIP_CMAC_128:
7290 return "AES-128-CMAC";
7291 default:
7292 return "UNKNOWN";
7293 }
7294}
7295
7296
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007297static int ap_set_60g_ese(struct sigma_dut *dut, int count,
7298 struct sigma_ese_alloc *allocs)
7299{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007300 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007301#ifdef __linux__
7302 case DRIVER_WIL6210:
7303 return wil6210_set_ese(dut, count, allocs);
7304#endif /* __linux__ */
7305 default:
7306 sigma_dut_print(dut, DUT_MSG_ERROR,
7307 "Unsupported ap_set_60g_ese with the current driver");
7308 return -1;
7309 }
7310}
7311
7312
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007313static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
7314{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007315 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007316#ifdef __linux__
7317 case DRIVER_WIL6210:
7318 return wil6210_set_force_mcs(dut, force, mcs);
7319#endif /* __linux__ */
7320 default:
7321 sigma_dut_print(dut, DUT_MSG_ERROR,
7322 "Unsupported ap_set_force_mcs with the current driver");
7323 return -1;
7324 }
7325}
7326
7327
Jouni Malinenf7222712019-06-13 01:50:21 +03007328enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
7329 struct sigma_conn *conn,
7330 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007331{
7332 /* const char *name = get_param(cmd, "NAME"); */
7333 FILE *f;
7334 const char *ifname;
7335 char buf[500];
7336 char path[100];
7337 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03007338 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307339#ifdef ANDROID
7340 struct group *gr;
7341#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007342
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007343 drv = get_driver_type(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007344
7345 if (dut->mode == SIGMA_MODE_STATION) {
7346 stop_sta_mode(dut);
7347 sleep(1);
7348 }
7349
7350 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
7351 snprintf(buf, sizeof(buf), "ifconfig %s down",
7352 dut->sniffer_ifname);
7353 if (system(buf) != 0) {
7354 sigma_dut_print(dut, DUT_MSG_INFO,
7355 "Failed to run '%s'", buf);
7356 }
7357 snprintf(buf, sizeof(buf), "iw dev %s set type station",
7358 dut->sniffer_ifname);
7359 if (system(buf) != 0) {
7360 sigma_dut_print(dut, DUT_MSG_INFO,
7361 "Failed to run '%s'", buf);
7362 }
7363 }
7364
7365 dut->mode = SIGMA_MODE_AP;
7366
7367 if (drv == DRIVER_ATHEROS)
7368 return cmd_ath_ap_config_commit(dut, conn, cmd);
7369 if (drv == DRIVER_WCN)
7370 return cmd_wcn_ap_config_commit(dut, conn, cmd);
7371 if (drv == DRIVER_OPENWRT)
7372 return cmd_owrt_ap_config_commit(dut, conn, cmd);
7373
7374 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
7375 if (f == NULL) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "%s: Failed to open sigma_dut-ap.conf",
7378 __func__);
7379 return -2;
7380 }
7381 switch (dut->ap_mode) {
7382 case AP_11g:
7383 case AP_11b:
7384 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05307385 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
7386 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
Jouni Malinend2095482019-11-04 17:10:43 +02007387 dut->main_ifname)
Jouni Malinen5ea30922019-11-04 17:39:25 +02007388 ifname = get_main_ifname(dut);
Jouni Malinen85647462019-11-06 19:38:50 +02007389 if (dut->main_ifname_2g)
7390 ifname = dut->main_ifname_2g;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007391 fprintf(f, "hw_mode=g\n");
7392 break;
7393 case AP_11a:
7394 case AP_11na:
7395 case AP_11ac:
Jouni Malinen85647462019-11-06 19:38:50 +02007396 if (dut->main_ifname_5g) {
7397 ifname = dut->main_ifname_5g;
7398 } else if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinend2095482019-11-04 17:10:43 +02007399 if (dut->main_ifname)
Jouni Malinen5ea30922019-11-04 17:39:25 +02007400 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007401 else
7402 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05307403 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007404 if (if_nametoindex("wlan1") > 0)
7405 ifname = "wlan1";
7406 else
7407 ifname = "wlan0";
7408 } else {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007409 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007410 }
7411 fprintf(f, "hw_mode=a\n");
7412 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007413 case AP_11ad:
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007414 ifname = get_main_ifname(dut);
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02007415 fprintf(f, "hw_mode=ad\n");
7416 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007417 default:
7418 fclose(f);
7419 return -1;
7420 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007421 if (dut->hostapd_ifname)
7422 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007423
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307424 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007425 fprintf(f, "driver=nl80211\n");
7426
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307427 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7428 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007429 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05307430 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
7431
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007432 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307433 if (dut->ap_mode == AP_11ng &&
7434 (dut->ap_chwidth == AP_40 ||
7435 (dut->ap_chwidth == AP_AUTO &&
7436 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007437 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307438 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307440 ht40minus = 1;
7441 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007442 }
7443
7444 /* configure ht_capab based on channel width */
7445 if (dut->ap_mode == AP_11na &&
7446 (dut->ap_chwidth == AP_40 ||
7447 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05307448 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007449 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307450 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007451 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05307452 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007453 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307454
7455 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05307456 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05307457
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05307458 /* Overwrite the ht_capab with offset value if configured */
7459 if (dut->ap_chwidth == AP_40 &&
7460 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
7461 ht40plus = 1;
7462 ht40minus = 0;
7463 } else if (dut->ap_chwidth == AP_40 &&
7464 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
7465 ht40minus = 1;
7466 ht40plus = 0;
7467 }
7468
Tamizh chelvam431c6002017-03-07 17:07:16 +05307469 fprintf(f, "ht_capab=%s%s%s\n",
7470 ht40plus ? "[HT40+]" : "",
7471 ht40minus ? "[HT40-]" : "",
7472 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007473 }
7474
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307475 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7476 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007477 dut->ap_mode == AP_11ac) {
Hu Wang29392102019-07-03 15:41:12 +08007478 int ht40plus = 0, ht40minus = 0;
7479
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007480 fprintf(f, "ieee80211ac=1\n"
Hu Wang29392102019-07-03 15:41:12 +08007481 "ieee80211n=1\n");
7482
7483 /* configure ht_capab based on channel width */
7484 if (dut->ap_chwidth != AP_20) {
7485 if (is_ht40plus_chan(dut->ap_channel))
7486 ht40plus = 1;
7487 else if (is_ht40minus_chan(dut->ap_channel))
7488 ht40minus = 1;
7489
7490 fprintf(f, "ht_capab=%s%s\n",
7491 ht40plus ? "[HT40+]" : "",
7492 ht40minus ? "[HT40-]" : "");
7493 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007494 }
7495
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05307496 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
7497 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007498 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
7499 if (dut->ap_countrycode[0]) {
7500 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
7501 fprintf(f, "ieee80211d=1\n");
7502 fprintf(f, "ieee80211h=1\n");
7503 }
7504 }
7505
7506 fprintf(f, "interface=%s\n", ifname);
7507 if (dut->bridge)
7508 fprintf(f, "bridge=%s\n", dut->bridge);
7509 fprintf(f, "channel=%d\n", dut->ap_channel);
7510
7511 if (sigma_hapd_ctrl)
7512 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
7513 else
7514 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
7515
7516 if (dut->ap_ssid[0])
7517 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7518 else
7519 fprintf(f, "ssid=QCA AP OOB\n");
7520 if (dut->ap_bcnint)
7521 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
7522
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007523 if (dut->ap_akm_values) {
7524 struct {
7525 int akm;
7526 const char *str;
7527 } akms[] = {
7528 { AKM_WPA_EAP, "WPA-EAP" },
7529 { AKM_WPA_PSK, "WPA-PSK" },
7530 { AKM_FT_EAP, "FT-EAP" },
7531 { AKM_FT_PSK, "FT-PSK" },
7532 { AKM_EAP_SHA256, "WPA-EAP-SHA256" },
7533 { AKM_PSK_SHA256, "WPA-PSK-SHA256" },
7534 { AKM_SAE, "SAE" },
7535 { AKM_FT_SAE, "FT-SAE" },
7536 { AKM_SUITE_B, "WPA-EAP-SUITE-B-192" },
7537 { AKM_FT_SUITE_B, "FT-EAP-SHA384" },
7538 { AKM_FILS_SHA256, "FILS-SHA256" },
7539 { AKM_FILS_SHA384, "FILS-SHA384" },
7540 { AKM_FT_FILS_SHA256, "FT-FILS-SHA256" },
7541 { AKM_FT_FILS_SHA384, "FT-FILS-SHA384" },
7542 };
Jouni Malinen8400c082019-04-26 13:26:07 +03007543 int first = 1;
7544 unsigned int i;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007545
7546 fprintf(f, "wpa_key_mgmt=");
7547 for (i = 0; i < ARRAY_SIZE(akms); i++) {
7548 if (dut->ap_akm_values & (1 << akms[i].akm)) {
7549 fprintf(f, "%s%s", first ? "" : " ",
7550 akms[i].str);
7551 first = 0;
7552 }
7553 }
7554 fprintf(f, "\n");
7555 /* TODO: mixed mode and WPAv1 only */
7556 fprintf(f, "wpa=2\n");
7557 fprintf(f, "wpa_pairwise=%s\n",
7558 hostapd_cipher_name(dut->ap_cipher));
7559 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7560 fprintf(f, "group_cipher=%s\n",
7561 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3e255412019-03-28 22:04:08 +02007562 if ((dut->ap_akm_values &
7563 ((1 << AKM_SAE) | (1 << AKM_FT_SAE))) &&
7564 !(dut->ap_akm_values &
7565 ((1 << AKM_WPA_PSK) | (1 << AKM_FT_PSK))) &&
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007566 dut->ap_passphrase[0])
7567 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
7568 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7569 fprintf(f, "wpa_psk=%s", dut->ap_psk);
7570 else if (dut->ap_passphrase[0])
7571 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007572 if (dut->ap_akm_values & ((1 << AKM_WPA_EAP) |
Jouni Malinene5393c32019-06-20 01:34:34 +03007573 (1 << AKM_FT_EAP) |
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007574 (1 << AKM_EAP_SHA256) |
7575 (1 << AKM_SUITE_B) |
7576 (1 << AKM_FT_SUITE_B) |
7577 (1 << AKM_FILS_SHA256) |
7578 (1 << AKM_FILS_SHA384) |
7579 (1 << AKM_FT_FILS_SHA256) |
7580 (1 << AKM_FT_FILS_SHA384))) {
7581 fprintf(f, "ieee8021x=1\n");
7582 fprintf(f, "auth_server_addr=%s\n",
7583 dut->ap_radius_ipaddr);
7584 if (dut->ap_radius_port)
7585 fprintf(f, "auth_server_port=%d\n",
7586 dut->ap_radius_port);
7587 fprintf(f, "auth_server_shared_secret=%s\n",
7588 dut->ap_radius_password);
7589 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007590 goto skip_key_mgmt;
7591 }
7592
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007593 switch (dut->ap_key_mgmt) {
7594 case AP_OPEN:
7595 if (dut->ap_cipher == AP_WEP)
7596 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
7597 break;
7598 case AP_WPA2_PSK:
7599 case AP_WPA2_PSK_MIXED:
7600 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007601 case AP_WPA2_SAE:
7602 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007603 case AP_WPA2_PSK_SHA256:
7604 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007605 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
7606 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007607 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7608 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
7609 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007610 fprintf(f, "wpa=2\n");
7611 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
7612 fprintf(f, "wpa=3\n");
7613 else
7614 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03007615 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7616 key_mgmt = "SAE";
7617 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7618 key_mgmt = "WPA-PSK SAE";
7619 else
7620 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007621 switch (dut->ap_pmf) {
7622 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007623 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007624 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7625 break;
7626 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03007627 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7629 break;
7630 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007631 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7632 key_mgmt = "SAE";
7633 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7634 key_mgmt = "WPA-PSK-SHA256 SAE";
7635 else
7636 key_mgmt = "WPA-PSK-SHA256";
7637 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007638 break;
7639 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007640 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
7641 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
7642 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
7643 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007644 fprintf(f, "wpa_pairwise=%s\n",
7645 hostapd_cipher_name(dut->ap_cipher));
7646 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7647 fprintf(f, "group_cipher=%s\n",
7648 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03007649 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7650 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02007651 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7652 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03007653 else
7654 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007655 break;
7656 case AP_WPA2_EAP:
7657 case AP_WPA2_EAP_MIXED:
7658 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007659 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007660 case AP_WPA2_EAP_SHA256:
7661 case AP_WPA2_FT_EAP:
7662 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007663 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007664 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007665 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
7666 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
7667 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
7668 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007669 fprintf(f, "wpa=2\n");
7670 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
7671 fprintf(f, "wpa=3\n");
7672 else
7673 fprintf(f, "wpa=1\n");
7674 switch (dut->ap_pmf) {
7675 case AP_PMF_DISABLED:
7676 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
7677 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
7678 break;
7679 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007680 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
7681 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
7682 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7683 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007684 break;
7685 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007686 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
7687 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7688 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007689 break;
7690 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007691 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
7692 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
7693 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
7694 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
7695 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
7696 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007697 fprintf(f, "wpa_pairwise=%s\n",
7698 hostapd_cipher_name(dut->ap_cipher));
7699 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7700 fprintf(f, "group_cipher=%s\n",
7701 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007702 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7703 if (dut->ap_radius_port)
7704 fprintf(f, "auth_server_port=%d\n",
7705 dut->ap_radius_port);
7706 fprintf(f, "auth_server_shared_secret=%s\n",
7707 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03007708 if (dut->program == PROGRAM_HS2_R3) {
7709 fprintf(f, "radius_das_port=3799\n");
7710 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
7711 dut->ap_radius_password);
7712 fprintf(f, "radius_das_require_event_timestamp=1\n");
7713 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007714 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03007715 case AP_SUITEB:
7716 fprintf(f, "ieee8021x=1\n");
7717 fprintf(f, "wpa=2\n");
7718 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03007719 fprintf(f, "wpa_pairwise=%s\n",
7720 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02007721 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7722 fprintf(f, "group_cipher=%s\n",
7723 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03007724 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7725 fprintf(f, "group_mgmt_cipher=%s\n",
7726 hostapd_group_mgmt_cipher_name(
7727 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03007728 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7729 if (dut->ap_radius_port)
7730 fprintf(f, "auth_server_port=%d\n",
7731 dut->ap_radius_port);
7732 fprintf(f, "auth_server_shared_secret=%s\n",
7733 dut->ap_radius_password);
7734 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03007735 case AP_WPA2_OWE:
7736 fprintf(f, "wpa=2\n");
7737 fprintf(f, "wpa_key_mgmt=OWE\n");
7738 fprintf(f, "rsn_pairwise=%s\n",
7739 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03007740 if (dut->ap_sae_groups)
7741 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03007742 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03007743 case AP_OSEN:
7744 fprintf(f, "osen=1\n");
7745 fprintf(f, "disable_dgaf=1\n");
7746 fprintf(f, "wpa_pairwise=%s\n",
7747 hostapd_cipher_name(dut->ap_cipher));
7748 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7749 fprintf(f, "group_cipher=%s\n",
7750 hostapd_cipher_name(dut->ap_group_cipher));
7751 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7752 if (dut->ap_radius_port)
7753 fprintf(f, "auth_server_port=%d\n",
7754 dut->ap_radius_port);
7755 fprintf(f, "auth_server_shared_secret=%s\n",
7756 dut->ap_radius_password);
7757 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007758 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007759skip_key_mgmt:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760
Jouni Malinen09550de2019-03-26 00:24:11 +02007761 if (dut->ap_sae_passwords) {
7762 char *tmp, *pos, *end, *id;
7763
7764 tmp = strdup(dut->ap_sae_passwords);
7765 if (!tmp) {
7766 fclose(f);
7767 return ERROR_SEND_STATUS;
7768 }
7769
7770 pos = tmp;
7771 while (*pos) {
7772 end = strchr(pos, ';');
7773 if (end)
7774 *end = '\0';
7775 id = strchr(pos, ':');
7776 if (id)
7777 *id++ = '\0';
7778
7779 fprintf(f, "sae_password=%s%s%s\n",
7780 pos, id ? "|id=" : "", id ? id : "");
7781 if (!end)
7782 break;
7783 pos = end + 1;
7784 }
7785
7786 free(tmp);
7787 }
7788
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05307789 if (dut->ap_rsn_preauth)
7790 fprintf(f, "rsn_preauth=1\n");
7791
Jouni Malinenb75c5322019-06-14 01:47:43 +03007792 if (dut->ap_pmksa && dut->ap_pmksa_caching)
7793 fprintf(f, "disable_pmksa_caching=1\n");
7794
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007795 switch (dut->ap_pmf) {
7796 case AP_PMF_DISABLED:
7797 break;
7798 case AP_PMF_OPTIONAL:
7799 fprintf(f, "ieee80211w=1\n");
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007800 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7801 (dut->ap_akm_values & (AKM_SAE | AKM_WPA_PSK)) ==
7802 (AKM_SAE | AKM_WPA_PSK))
Jouni Malinen1287cd72018-01-04 17:08:01 +02007803 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007804 break;
7805 case AP_PMF_REQUIRED:
7806 fprintf(f, "ieee80211w=2\n");
7807 break;
7808 }
7809
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007810 if (dut->ap_pmf != AP_PMF_DISABLED &&
7811 dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7812 fprintf(f, "group_mgmt_cipher=%s\n",
7813 hostapd_group_mgmt_cipher_name(
7814 dut->ap_group_mgmt_cipher));
7815
Jouni Malinen6be21c82018-08-01 18:47:24 +03007816 if (ap_ft_enabled(dut)) {
7817 unsigned char own_addr[ETH_ALEN];
7818
7819 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
Jouni Malinen9f943312019-08-19 23:49:16 +03007820 fprintf(f, "ft_over_ds=%d\n", dut->ap_ft_ds == VALUE_ENABLED);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007821 if (get_hwaddr(ifname, own_addr) < 0) {
7822 memset(own_addr, 0, ETH_ALEN);
7823 own_addr[0] = 0x02;
7824 }
Jouni Malinenc9674462019-03-26 02:40:19 +02007825 fprintf(f,
7826 "nas_identifier=%02x%02x%02x%02x%02x%02x.nas.example.com\n",
7827 own_addr[0], own_addr[1], own_addr[2],
7828 own_addr[3], own_addr[4], own_addr[5]);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007829 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7830 own_addr[0], own_addr[1], own_addr[2],
7831 own_addr[3], own_addr[4], own_addr[5]);
7832 fprintf(f, "ft_psk_generate_local=1\n");
7833 fprintf(f, "pmk_r1_push=0\n");
7834 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007835 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007836 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007837 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007838 }
7839
Jouni Malinen3c367e82017-06-23 17:01:47 +03007840 if (dut->rsne_override)
7841 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
Jouni Malinen7960e3a2019-12-07 17:04:35 +02007842 if (dut->rsnxe_override_eapol)
7843 fprintf(f, "rsnxe_override_eapol=%s\n",
7844 dut->rsnxe_override_eapol);
Jouni Malinen3c367e82017-06-23 17:01:47 +03007845
Jouni Malinen68143132017-09-02 02:34:08 +03007846 if (dut->sae_commit_override)
7847 fprintf(f, "sae_commit_override=%s\n",
7848 dut->sae_commit_override);
7849
Jouni Malinened670f42017-08-31 01:39:28 +03007850 if (dut->ap_sae_groups)
7851 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007852
Jouni Malinen11e55212019-11-22 21:46:59 +02007853 if (dut->sae_pwe != SAE_PWE_DEFAULT || dut->sae_h2e_default) {
7854 const char *sae_pwe = NULL;
7855
7856 if (dut->sae_pwe == SAE_PWE_LOOP)
7857 sae_pwe = "0";
7858 else if (dut->sae_pwe == SAE_PWE_H2E)
7859 sae_pwe = "1";
7860 else if (dut->sae_h2e_default)
7861 sae_pwe = "2";
7862 if (sae_pwe)
7863 fprintf(f, "sae_pwe=%s", sae_pwe);
7864 }
7865
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007866 if (dut->sae_anti_clogging_threshold >= 0)
7867 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7868 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007869 if (dut->sae_reflection)
7870 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen3c740ab2019-10-10 15:55:11 +03007871 if (dut->sae_confirm_immediate)
7872 fprintf(f, "sae_confirm_immediate=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007873
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007874 if (dut->ap_p2p_mgmt)
7875 fprintf(f, "manage_p2p=1\n");
7876
7877 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7878 fprintf(f, "tdls_prohibit=1\n");
7879 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
7880 fprintf(f, "tdls_prohibit_chan_switch=1\n");
7881 if (dut->ap_p2p_cross_connect >= 0) {
7882 fprintf(f, "manage_p2p=1\n"
7883 "allow_cross_connection=%d\n",
7884 dut->ap_p2p_cross_connect);
7885 }
7886
Jouni Malinen4d479c92018-11-06 00:43:36 +02007887 if (dut->ap_l2tif || dut->ap_proxy_arp ||
7888 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007889 if (!dut->bridge) {
7890 sigma_dut_print(dut, DUT_MSG_ERROR,
7891 "Bridge must be configured. Run with -b <brname>.");
7892 fclose(f);
7893 return -2;
7894 }
7895 fprintf(f, "ap_isolate=1\n");
7896 }
7897
7898 if (dut->ap_proxy_arp)
7899 fprintf(f, "proxy_arp=1\n");
7900
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307901 if (dut->ap_wme)
7902 fprintf(f, "wmm_enabled=1\n");
7903
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307904 if (dut->ap_wmmps == AP_WMMPS_ON)
7905 fprintf(f, "uapsd_advertisement_enabled=1\n");
7906
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007907 if (dut->ap_hs2) {
7908 if (dut->ap_bss_load) {
7909 char *bss_load;
7910
7911 switch (dut->ap_bss_load) {
7912 case -1:
7913 bss_load = "bss_load_update_period=10";
7914 break;
7915 case 1:
7916 /* STA count: 1, CU: 50, AAC: 65535 */
7917 bss_load = "bss_load_test=1:50:65535";
7918 break;
7919 case 2:
7920 /* STA count: 1, CU: 200, AAC: 65535 */
7921 bss_load = "bss_load_test=1:200:65535";
7922 break;
7923 case 3:
7924 /* STA count: 1, CU: 75, AAC: 65535 */
7925 bss_load = "bss_load_test=1:75:65535";
7926 break;
7927 default:
7928 bss_load = NULL;
7929 break;
7930 }
7931
7932 if (!bss_load) {
7933 fclose(f);
7934 return -2;
7935 }
7936 fprintf(f, "%s\n", bss_load);
7937 }
7938
7939 if (append_hostapd_conf_hs2(dut, f)) {
7940 fclose(f);
7941 return -2;
7942 }
7943 }
7944
7945 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
7946 fclose(f);
7947 return -2;
7948 }
7949
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007950 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007951 unsigned char bssid[6];
7952 char ifname2[50];
7953
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307954 if (get_hwaddr(ifname, bssid)) {
7955 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007956 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307957 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03007958 if (bssid[0] & 0x02)
7959 bssid[5] ^= 0x01;
7960 else
7961 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007962
7963 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03007964 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007965 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966 if (dut->bridge)
7967 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007968
7969 if (drv == DRIVER_LINUX_WCN)
7970 fprintf(f, "use_driver_iface_addr=1\n");
7971 else
7972 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7973 bssid[0], bssid[1], bssid[2], bssid[3],
7974 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007975
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007976 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007977 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05307978 /* Disable DGAF for OSEN BSS */
7979 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007980 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007981 if (strlen(dut->ap2_radius_ipaddr))
7982 fprintf(f, "auth_server_addr=%s\n",
7983 dut->ap2_radius_ipaddr);
7984 if (dut->ap2_radius_port)
7985 fprintf(f, "auth_server_port=%d\n",
7986 dut->ap2_radius_port);
7987 if (strlen(dut->ap2_radius_password))
7988 fprintf(f, "auth_server_shared_secret=%s\n",
7989 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007990
7991 set_ebtables_forward_drop(dut, ifname, ifname2);
7992 } else if (dut->ap2_osu) {
7993 fprintf(f, "ap_isolate=1\n");
7994 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007995 }
7996
7997 if (dut->ap2_proxy_arp) {
7998 if (!dut->bridge) {
7999 sigma_dut_print(dut, DUT_MSG_ERROR,
8000 "Bridge must be configured. Run with -b <brname>.");
8001 fclose(f);
8002 return -2;
8003 }
8004 fprintf(f, "ap_isolate=1\n");
8005 fprintf(f, "proxy_arp=1\n");
8006
8007 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
8008 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
8009 fclose(f);
8010 return -2;
8011 }
8012
8013 }
8014 }
8015
8016 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008017 /* 60G WPS tests requires wps_state of 2 (configured) */
8018 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
8019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008020 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008021 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008022 "device_name=QCA AP\n"
8023 "manufacturer=QCA\n"
8024 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008025 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008026 "virtual_push_button keypad%s\n"
8027 "ap_pin=12345670\n"
8028 "friendly_name=QCA Access Point\n"
8029 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02008030 wps_state,
8031 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008032 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
8033 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008034 if (dut->wsc_fragment) {
8035 fprintf(f, "device_name=%s\n"
8036 "manufacturer=%s\n"
8037 "model_name=%s\n"
8038 "model_number=%s\n"
8039 "serial_number=%s\n",
8040 WPS_LONG_DEVICE_NAME,
8041 WPS_LONG_MANUFACTURER,
8042 WPS_LONG_MODEL_NAME,
8043 WPS_LONG_MODEL_NUMBER,
8044 WPS_LONG_SERIAL_NUMBER);
8045 } else {
8046 fprintf(f, "device_name=QCA AP\n"
8047 "manufacturer=QCA\n");
8048 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008049 if (dut->eap_fragment)
8050 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008051 }
8052
Jouni Malinenba4f2d42019-10-04 16:13:41 +03008053 if (dut->ap_dpp_conf_addr && dut->ap_dpp_conf_pkhash)
8054 fprintf(f, "dpp_controller=ipaddr=%s pkhash=%s\n",
8055 dut->ap_dpp_conf_addr, dut->ap_dpp_conf_pkhash);
8056
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008057 if (dut->program == PROGRAM_VHT) {
8058 int vht_oper_centr_freq_idx;
8059
8060 if (check_channel(dut->ap_channel) < 0) {
8061 send_resp(dut, conn, SIGMA_INVALID,
8062 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308063 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008064 return 0;
8065 }
8066
8067 switch (dut->ap_chwidth) {
8068 case AP_20:
8069 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8070 vht_oper_centr_freq_idx =
8071 get_oper_centr_freq_seq_idx(20,
8072 dut->ap_channel);
8073 break;
8074 case AP_40:
8075 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
8076 vht_oper_centr_freq_idx =
8077 get_oper_centr_freq_seq_idx(40,
8078 dut->ap_channel);
8079 break;
8080 case AP_80:
8081 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
8082 vht_oper_centr_freq_idx =
8083 get_oper_centr_freq_seq_idx(80,
8084 dut->ap_channel);
8085 break;
8086 case AP_160:
8087 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
8088 vht_oper_centr_freq_idx =
8089 get_oper_centr_freq_seq_idx(160,
8090 dut->ap_channel);
8091 break;
8092 default:
8093 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
8094 vht_oper_centr_freq_idx =
8095 get_oper_centr_freq_seq_idx(80,
8096 dut->ap_channel);
8097 break;
8098 }
8099 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
8100 vht_oper_centr_freq_idx);
8101 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
8102
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008103 if (dut->ap_sgi80 || dut->ap_txBF ||
8104 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308105 dut->ap_tx_stbc || dut->ap_mu_txBF) {
8106 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008107 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05308108 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05308109 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008110 (dut->ap_ldpc == VALUE_ENABLED) ?
8111 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05308112 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
8113 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008114 }
8115 }
8116
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008117 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
8118 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
8119 /* OWE transition mode */
8120 unsigned char bssid[6];
8121 char ifname2[50];
8122 unsigned long val;
8123 FILE *f2;
8124
8125 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8126
8127 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8128 val = 0x12345678; /* default to something */
8129 f2 = fopen("/dev/urandom", "r");
8130 if (f2) {
8131 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8132 sigma_dut_print(dut, DUT_MSG_ERROR,
8133 "Could not read /dev/urandom");
8134 }
8135 fclose(f2);
8136 }
8137 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008138 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008139
8140 if (get_hwaddr(ifname, bssid)) {
8141 fclose(f);
8142 return -2;
8143 }
8144 if (bssid[0] & 0x02)
8145 bssid[5] ^= 0x01;
8146 else
8147 bssid[0] |= 0x02;
8148
8149 fprintf(f, "bss=%s\n", ifname2);
8150 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8151 if (dut->bridge)
8152 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008153 if (drv == DRIVER_LINUX_WCN)
8154 fprintf(f, "use_driver_iface_addr=1\n");
8155 else
8156 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8157 bssid[0], bssid[1], bssid[2], bssid[3],
8158 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03008159 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8160 }
8161
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008162 if (dut->ap_key_mgmt == AP_OPEN &&
8163 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
8164 /* OWE transition mode */
8165 unsigned char bssid[6];
8166 char ifname2[50];
8167 unsigned long val;
8168 FILE *f2;
8169
8170 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
8171
8172 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
8173 fprintf(f, "ssid=%s\n", dut->ap_ssid);
8174
8175 if (get_hwaddr(ifname, bssid)) {
8176 fclose(f);
8177 return -2;
8178 }
8179 if (bssid[0] & 0x02)
8180 bssid[5] ^= 0x01;
8181 else
8182 bssid[0] |= 0x02;
8183
8184 fprintf(f, "bss=%s\n", ifname2);
8185 val = 0x12345678; /* default to something */
8186 f2 = fopen("/dev/urandom", "r");
8187 if (f2) {
8188 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
8189 sigma_dut_print(dut, DUT_MSG_ERROR,
8190 "Could not read /dev/urandom");
8191 }
8192 fclose(f2);
8193 }
8194 fprintf(f, "ssid=owe-%lx\n", val);
8195 if (dut->bridge)
8196 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08008197 if (drv == DRIVER_LINUX_WCN)
8198 fprintf(f, "use_driver_iface_addr=1\n");
8199 else
8200 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
8201 bssid[0], bssid[1], bssid[2], bssid[3],
8202 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008203 fprintf(f, "owe_transition_ifname=%s\n", ifname);
8204 fprintf(f, "wpa=2\n");
8205 fprintf(f, "wpa_key_mgmt=OWE\n");
8206 fprintf(f, "rsn_pairwise=CCMP\n");
8207 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08008208 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen353ba8b2018-01-10 17:04:12 +02008209 if (dut->ap_sae_groups)
8210 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
8211 }
8212
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308213 if (dut->program == PROGRAM_OCE) {
8214 fprintf(f, "oce=%d\n",
8215 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
8216 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008217 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008218 if (dut->use_hostapd_pid_file)
8219 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008220#ifdef __QNXNTO__
8221 if (system("slay hostapd") == 0)
8222#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008223 if (!dut->use_hostapd_pid_file &&
8224 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8225 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008226#endif /* __QNXNTO__ */
8227 {
8228 int i;
8229 /* Wait some time to allow hostapd to complete cleanup before
8230 * starting a new process */
8231 for (i = 0; i < 10; i++) {
8232 usleep(500000);
8233#ifdef __QNXNTO__
8234 if (system("pidin | grep hostapd") != 0)
8235 break;
8236#else /* __QNXNTO__ */
8237 if (system("pidof hostapd") != 0)
8238 break;
8239#endif /* __QNXNTO__ */
8240 }
8241 }
Jouni Malinend86e5822017-08-29 03:55:32 +03008242 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008243
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308244#ifdef ANDROID
8245 /* Set proper conf file permissions so that hostapd process
8246 * can access it.
8247 */
8248 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
8249 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
8250 sigma_dut_print(dut, DUT_MSG_ERROR,
8251 "Error changing permissions");
8252
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05308253 gr = getgrnam("wifi");
8254 if (!gr ||
8255 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05308256 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
8257#endif /* ANDROID */
8258
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008259 if (drv == DRIVER_QNXNTO) {
8260 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05308261 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008262 "/sigma_dut-ap.conf",
8263 dut->hostapd_debug_log ? "-ddKt -f " : "",
8264 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008265 dut->hostapd_entropy_log ? " -e" : "",
8266 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
8267 "");
8268 } else {
8269 /*
8270 * It looks like a monitor interface can cause some issues for
8271 * beaconing, so remove it (if injection was used) before
8272 * starting hostapd.
8273 */
8274 if (if_nametoindex("sigmadut") > 0 &&
8275 system("iw dev sigmadut del") != 0)
8276 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8277 "monitor interface");
8278
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008279 snprintf(path, sizeof(path), "%shostapd",
8280 file_exists("hostapd") ? "./" : "");
8281 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008282 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008283 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008284 dut->hostapd_debug_log ? " -ddKt -f" : "",
8285 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
8286 dut->hostapd_entropy_log ? " -e" : "",
8287 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008288 "",
8289 dut->use_hostapd_pid_file ?
8290 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008291 }
8292
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008293 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008294 if (system(buf) != 0) {
8295 send_resp(dut, conn, SIGMA_ERROR,
8296 "errorCode,Failed to start hostapd");
8297 return 0;
8298 }
8299
8300 /* allow some time for hostapd to start before returning success */
8301 usleep(500000);
8302 if (run_hostapd_cli(dut, "ping") != 0) {
8303 send_resp(dut, conn, SIGMA_ERROR,
8304 "errorCode,Failed to talk to hostapd");
8305 return 0;
8306 }
8307
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308308 if (drv == DRIVER_LINUX_WCN) {
Hu Wangf5cb9002019-08-21 14:18:57 +08008309 const char *ifname_ptr = ifname;
8310
8311 if ((dut->ap_key_mgmt == AP_OPEN &&
8312 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) ||
8313 (dut->ap_key_mgmt == AP_WPA2_OWE &&
8314 dut->ap_tag_ssid[0][0] &&
8315 dut->ap_tag_key_mgmt[0] == AP2_OPEN)) {
8316 /* OWE transition mode */
8317 if (dut->bridge)
8318 ifname_ptr = dut->bridge;
8319 }
8320
8321 sigma_dut_print(dut, DUT_MSG_INFO,
8322 "setting ip addr %s mask %s ifname %s",
8323 ap_inet_addr, ap_inet_mask, ifname_ptr);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308324 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
Hu Wangf5cb9002019-08-21 14:18:57 +08008325 ifname_ptr, ap_inet_addr, ap_inet_mask);
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05308326 if (system(buf) != 0) {
8327 sigma_dut_print(dut, DUT_MSG_ERROR,
8328 "Failed to initialize the interface");
8329 return -1;
8330 }
8331 }
8332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008333 if (dut->ap_l2tif) {
8334 snprintf(path, sizeof(path),
8335 "/sys/class/net/%s/brport/hairpin_mode",
8336 ifname);
8337 if (!file_exists(path)) {
8338 sigma_dut_print(dut, DUT_MSG_ERROR,
8339 "%s must be binded to the bridge for L2TIF",
8340 ifname);
8341 return -2;
8342 }
8343
8344 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
8345 if (system(buf) != 0) {
8346 sigma_dut_print(dut, DUT_MSG_ERROR,
8347 "Failed to enable hairpin_mode for L2TIF");
8348 return -2;
8349 }
8350
8351 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
8352 if (system(buf) != 0) {
8353 sigma_dut_print(dut, DUT_MSG_ERROR,
8354 "Failed to set ebtables rules, RULE-9");
8355 return -2;
8356 }
8357
8358 snprintf(buf, sizeof(buf),
8359 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
8360 ifname);
8361 if (system(buf) != 0) {
8362 sigma_dut_print(dut, DUT_MSG_ERROR,
8363 "Failed to set ebtables rules, RULE-11");
8364 return -2;
8365 }
8366 }
8367
8368 if (dut->ap_proxy_arp) {
8369 if (dut->ap_dgaf_disable) {
8370 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
8371 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
8372 return -2;
8373 } else {
8374 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
8375 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
8376 return -2;
8377 }
8378
8379 /* For 4.5-(c) */
8380 snprintf(buf, sizeof(buf),
8381 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
8382 ifname);
8383 if (system(buf) != 0) {
8384 sigma_dut_print(dut, DUT_MSG_ERROR,
8385 "Failed to set ebtables rules, RULE-10");
8386 return -2;
8387 }
8388 }
8389
8390 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
8391 /* Drop TDLS frames */
8392 snprintf(buf, sizeof(buf),
8393 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
8394 if (system(buf) != 0) {
8395 sigma_dut_print(dut, DUT_MSG_ERROR,
8396 "Failed to set ebtables rules, RULE-13");
8397 return -2;
8398 }
8399 }
8400
8401 if (dut->ap_fake_pkhash &&
8402 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
8403 send_resp(dut, conn, SIGMA_ERROR,
8404 "errorCode,Could not enable FakePubKey");
8405 return 0;
8406 }
8407
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008408 if (dut->program == PROGRAM_60GHZ && dut->ap_num_ese_allocs > 0) {
8409 /* wait extra time for AP to start */
8410 sleep(2);
8411 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
8412 dut->ap_ese_allocs)) {
8413 send_resp(dut, conn, SIGMA_ERROR,
8414 "errorCode,Could not set ExtSch");
8415 return 0;
8416 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008417 if (dut->ap_fixed_rate) {
8418 sigma_dut_print(dut, DUT_MSG_DEBUG,
8419 "forcing TX MCS index %d",
8420 dut->ap_mcs);
8421 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
8422 send_resp(dut, conn, SIGMA_ERROR,
8423 "errorCode,Could not force MCS");
8424 return -2;
8425 }
8426 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008427 }
8428
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008429 if (dut->wps_forced_version) {
8430 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
8431 dut->wps_forced_version);
8432 if (hapd_command(ifname, buf) < 0) {
8433 send_resp(dut, conn, SIGMA_ERROR,
8434 "errorCode,Fail to set wps_version_number");
8435 return STATUS_SENT;
8436 }
8437 }
8438
Jouni Malinend86e5822017-08-29 03:55:32 +03008439 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008440 return 1;
8441}
8442
8443
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308444static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
8445 struct qos_params *qos, const char *cwmin,
8446 const char *cwmax, const char *aifs,
8447 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008448{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308449 int val;
8450
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008451 if (cwmin) {
8452 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308453 val = atoi(cwmin);
8454 if (val < 0 || val > 15) {
8455 send_resp(dut, conn, SIGMA_INVALID,
8456 "errorCode,Invalid cwMin");
8457 return 0;
8458 }
8459 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008460 }
8461
8462 if (cwmax) {
8463 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308464 val = atoi(cwmax);
8465 if (val < 0 || val > 15) {
8466 send_resp(dut, conn, SIGMA_INVALID,
8467 "errorCode,Invalid cwMax");
8468 return 0;
8469 }
8470 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008471 }
8472
8473 if (aifs) {
8474 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308475 val = atoi(aifs);
8476 if (val < 1 || val > 255) {
8477 send_resp(dut, conn, SIGMA_INVALID,
8478 "errorCode,Invalid AIFS");
8479 return 0;
8480 }
8481 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008482 }
8483
8484 if (txop) {
8485 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308486 val = atoi(txop);
8487 if (val < 0 || val > 0xffff) {
8488 send_resp(dut, conn, SIGMA_INVALID,
8489 "errorCode,Invalid txop");
8490 return 0;
8491 }
8492 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008493 }
8494
8495 if (acm) {
8496 qos->ac = 1;
8497 qos->acm = strcasecmp(acm, "on") == 0;
8498 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308499
8500 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008501}
8502
8503
Jouni Malinenf7222712019-06-13 01:50:21 +03008504static enum sigma_cmd_result cmd_ap_set_apqos(struct sigma_dut *dut,
8505 struct sigma_conn *conn,
8506 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008507{
8508 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308509 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
8510 get_param(cmd, "cwmin_VO"),
8511 get_param(cmd, "cwmax_VO"),
8512 get_param(cmd, "AIFS_VO"),
8513 get_param(cmd, "TXOP_VO"),
8514 get_param(cmd, "ACM_VO")) ||
8515 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
8516 get_param(cmd, "cwmin_VI"),
8517 get_param(cmd, "cwmax_VI"),
8518 get_param(cmd, "AIFS_VI"),
8519 get_param(cmd, "TXOP_VI"),
8520 get_param(cmd, "ACM_VI")) ||
8521 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
8522 get_param(cmd, "cwmin_BE"),
8523 get_param(cmd, "cwmax_BE"),
8524 get_param(cmd, "AIFS_BE"),
8525 get_param(cmd, "TXOP_BE"),
8526 get_param(cmd, "ACM_BE")) ||
8527 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
8528 get_param(cmd, "cwmin_BK"),
8529 get_param(cmd, "cwmax_BK"),
8530 get_param(cmd, "AIFS_BK"),
8531 get_param(cmd, "TXOP_BK"),
8532 get_param(cmd, "ACM_BK")))
8533 return 0;
8534
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008535 return 1;
8536}
8537
8538
Jouni Malinenf7222712019-06-13 01:50:21 +03008539static enum sigma_cmd_result cmd_ap_set_staqos(struct sigma_dut *dut,
8540 struct sigma_conn *conn,
8541 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008542{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05308543 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
8544 get_param(cmd, "cwmin_VO"),
8545 get_param(cmd, "cwmax_VO"),
8546 get_param(cmd, "AIFS_VO"),
8547 get_param(cmd, "TXOP_VO"),
8548 get_param(cmd, "ACM_VO")) ||
8549 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
8550 get_param(cmd, "cwmin_VI"),
8551 get_param(cmd, "cwmax_VI"),
8552 get_param(cmd, "AIFS_VI"),
8553 get_param(cmd, "TXOP_VI"),
8554 get_param(cmd, "ACM_VI")) ||
8555 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
8556 get_param(cmd, "cwmin_BE"),
8557 get_param(cmd, "cwmax_BE"),
8558 get_param(cmd, "AIFS_BE"),
8559 get_param(cmd, "TXOP_BE"),
8560 get_param(cmd, "ACM_BE")) ||
8561 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
8562 get_param(cmd, "cwmin_BK"),
8563 get_param(cmd, "cwmax_BK"),
8564 get_param(cmd, "AIFS_BK"),
8565 get_param(cmd, "TXOP_BK"),
8566 get_param(cmd, "ACM_BK")))
8567 return 0;
8568
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008569 return 1;
8570}
8571
8572
8573static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
8574{
8575 unsigned char bssid[6];
8576 char buf[100];
8577 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
8578 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
8579 run_system(dut, "cfg -a AP_SECMODE=WPA");
8580 run_system(dut, "cfg -a AP_SECFILE=EAP");
8581 run_system(dut, "cfg -a AP_WPA=2");
8582 run_system(dut, "cfg -a AP_CYPHER=CCMP");
8583 run_system(dut, "cfg -a AP_HOTSPOT=1");
8584 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
8585 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
8586 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
8587 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
8588 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
8589 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
8590 if (!get_hwaddr("ath0", bssid)) {
8591 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8592 "%02x:%02x:%02x:%02x:%02x:%02x",
8593 bssid[0], bssid[1], bssid[2], bssid[3],
8594 bssid[4], bssid[5]);
8595 run_system(dut, buf);
8596 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8597 "%02x:%02x:%02x:%02x:%02x:%02x",
8598 bssid[0], bssid[1], bssid[2], bssid[3],
8599 bssid[4], bssid[5]);
8600 } else {
8601 if (!get_hwaddr("wifi0", bssid)) {
8602 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8603 "%02x:%02x:%02x:%02x:%02x:%02x",
8604 bssid[0], bssid[1], bssid[2], bssid[3],
8605 bssid[4], bssid[5]);
8606 run_system(dut, buf);
8607 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8608 "%02x:%02x:%02x:%02x:%02x:%02x",
8609 bssid[0], bssid[1], bssid[2], bssid[3],
8610 bssid[4], bssid[5]);
8611 } else {
8612 /* load the driver and try again */
8613 run_system(dut, "/etc/rc.d/rc.wlan up");
8614
8615 if (!get_hwaddr("wifi0", bssid)) {
8616 snprintf(buf, sizeof(buf),
8617 "cfg -a AP_HOTSPOT_HESSID="
8618 "%02x:%02x:%02x:%02x:%02x:%02x",
8619 bssid[0], bssid[1], bssid[2],
8620 bssid[3], bssid[4], bssid[5]);
8621 run_system(dut, buf);
8622 snprintf(dut->ap_hessid,
8623 sizeof(dut->ap_hessid),
8624 "%02x:%02x:%02x:%02x:%02x:%02x",
8625 bssid[0], bssid[1], bssid[2],
8626 bssid[3], bssid[4], bssid[5]);
8627 }
8628 }
8629 }
8630
8631 run_system(dut, "cfg -r AP_SSID_2");
8632 run_system(dut, "cfg -c");
8633 /* run_system(dut, "cfg -s"); */
8634}
8635
8636
8637static void ath_reset_vht_defaults(struct sigma_dut *dut)
8638{
8639 run_system(dut, "cfg -x");
8640 run_system(dut, "cfg -a AP_RADIO_ID=1");
8641 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
8642 run_system(dut, "cfg -a AP_STARTMODE=standard");
8643 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
8644 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
8645 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
8646 run_system(dut, "cfg -a ATH_countrycode=0x348");
8647 /* NOTE: For Beeliner we have to turn off MU-MIMO */
8648 if (system("rm /tmp/secath*") != 0) {
8649 sigma_dut_print(dut, DUT_MSG_ERROR,
8650 "Failed to remove secath file");
8651 }
8652}
8653
8654
Jouni Malinenf7222712019-06-13 01:50:21 +03008655static enum sigma_cmd_result cmd_ap_reset_default(struct sigma_dut *dut,
8656 struct sigma_conn *conn,
8657 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008658{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308659 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308660 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008661 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008662 int i;
8663
8664 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
8665 /*
8666 * Reset all tagged SSIDs to NULL-string and all key management
8667 * to open.
8668 */
8669 dut->ap_tag_ssid[i][0] = '\0';
8670 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
8671 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008672
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008673 drv = get_driver_type(dut);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308674
8675 program = get_param(cmd, "program");
8676 if (!program)
8677 program = get_param(cmd, "prog");
8678 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679 dut->device_type = AP_unknown;
8680 type = get_param(cmd, "type");
8681 if (type && strcasecmp(type, "Testbed") == 0)
8682 dut->device_type = AP_testbed;
8683 if (type && strcasecmp(type, "DUT") == 0)
8684 dut->device_type = AP_dut;
8685
8686 dut->ap_rts = 0;
8687 dut->ap_frgmnt = 0;
8688 dut->ap_bcnint = 0;
8689 dut->ap_key_mgmt = AP_OPEN;
8690 dut->ap_ssid[0] = '\0';
8691 dut->ap_fake_pkhash = 0;
8692 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
8693 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008694 dut->ap_addba_reject = VALUE_NOT_SET;
8695 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008696 dut->ap_is_dual = 0;
8697 dut->ap_mode = AP_inval;
8698 dut->ap_mode_1 = AP_inval;
8699
8700 dut->ap_allow_vht_wep = 0;
8701 dut->ap_allow_vht_tkip = 0;
8702 dut->ap_disable_protection = 0;
8703 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008704 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
8705 dut->ap_ldpc = VALUE_NOT_SET;
8706 dut->ap_sig_rts = VALUE_NOT_SET;
8707 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008708 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05308709 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008710 dut->ap_chwidth = AP_AUTO;
8711
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05308712 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008713 dut->ap_wpsnfc = 0;
8714 dut->ap_bss_load = -1;
8715 dut->ap_p2p_cross_connect = -1;
8716
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308717 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
8718 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05308719 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308720
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008721 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008722 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08008723 dut->ap_interface_5g = 0;
8724 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08008725 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008726
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008727 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008728 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008729 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008730
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308731 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308732 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308733 dut->ap_wmmps = AP_WMMPS_ON;
8734 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308735 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308736 dut->ap_wmmps = AP_WMMPS_OFF;
8737 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308738
Jouni Malinen54a89b02018-05-01 00:16:26 +03008739 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03008740 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03008741 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03008742 dut->ap_tnc_file_name = 0;
8743 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03008744
Jouni Malinenda5f35b2019-03-26 00:25:53 +02008745 dut->ap_akm_values = 0;
Jouni Malinen09550de2019-03-26 00:24:11 +02008746 free(dut->ap_sae_passwords);
8747 dut->ap_sae_passwords = NULL;
8748
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008749 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008750 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008751 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008752 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008753
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008754 if (drv == DRIVER_ATHEROS)
8755 cmd_ath_ap_hs2_reset(dut);
8756 else if (drv == DRIVER_OPENWRT)
8757 cmd_owrt_ap_hs2_reset(dut);
8758
8759 dut->ap_interworking = 1;
8760 dut->ap_access_net_type = 2;
8761 dut->ap_internet = 0;
8762 dut->ap_venue_group = 2;
8763 dut->ap_venue_type = 8;
8764 dut->ap_domain_name_list[0] = '\0';
8765 dut->ap_hs2 = 1;
8766 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
8767 "506f9a;001bc504bd");
8768 dut->ap_l2tif = 0;
8769 dut->ap_proxy_arp = 0;
8770 if (dut->bridge) {
8771 char buf[50];
8772
8773 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
8774 dut->bridge);
8775 if (system(buf) != 0) {
8776 sigma_dut_print(dut, DUT_MSG_DEBUG,
8777 "%s ip neigh table flushing failed",
8778 dut->bridge);
8779 }
8780
8781 snprintf(buf, sizeof(buf), "ebtables -F");
8782 if (system(buf) != 0) {
8783 sigma_dut_print(dut, DUT_MSG_DEBUG,
8784 "%s ebtables flushing failed",
8785 dut->bridge);
8786 }
8787 }
8788 dut->ap_dgaf_disable = 0;
8789 dut->ap_p2p_cross_connect = 0;
8790 dut->ap_gas_cb_delay = 0;
8791 dut->ap_nai_realm_list = 0;
8792 dut->ap_oper_name = 0;
8793 dut->ap_venue_name = 0;
8794 for (i = 0; i < 10; i++) {
8795 dut->ap_plmn_mcc[i][0] = '\0';
8796 dut->ap_plmn_mnc[i][0] = '\0';
8797 }
8798 dut->ap_wan_metrics = 0;
8799 dut->ap_conn_capab = 0;
8800 dut->ap_ip_addr_type_avail = 0;
8801 dut->ap_net_auth_type = 0;
8802 dut->ap_oper_class = 0;
8803 dut->ap_pmf = 0;
8804 dut->ap_add_sha256 = 0;
8805 }
8806
Jouni Malinenba630452018-06-22 11:49:59 +03008807 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
8808 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008809 int i;
8810 const char hessid[] = "50:6f:9a:00:11:22";
8811
8812 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
8813 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008814 dut->ap_pmf = 1;
8815 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02008816 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008817 for (i = 0; i < 10; i++) {
8818 dut->ap_osu_server_uri[i][0] = '\0';
8819 dut->ap_osu_method[i] = 0xFF;
8820 }
8821 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008822 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008823 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008824 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008825 dut->ap_osu_icon_tag = 0;
8826 }
8827
8828 if (dut->program == PROGRAM_VHT) {
8829 /* Set up the defaults */
Jouni Malinen00535472019-11-06 19:43:35 +02008830 dut->use_5g = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008831 dut->ap_mode = AP_11ac;
8832 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008833 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08008834 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008835 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008836 dut->ap_amsdu = VALUE_DISABLED;
8837 dut->ap_ldpc = VALUE_DISABLED;
8838 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008839 dut->ap_sgi80 = 0;
8840 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008841 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308842 /*
8843 * As LDPC is optional, don't enable this by default
8844 * for LINUX-WCN driver. The ap_set_wireless command
8845 * can be used to enable LDPC, when needed.
8846 */
8847 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008848 dut->ap_ldpc = VALUE_ENABLED;
8849 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008850 dut->ap_sgi80 = 1;
8851 }
8852 dut->ap_fixed_rate = 0;
8853 dut->ap_rx_streams = 3;
8854 dut->ap_tx_streams = 3;
8855 dut->ap_vhtmcs_map = 0;
8856 dut->ap_chwidth = AP_80;
8857 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008858 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05308859 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8860 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008861 if (get_driver_type(dut) == DRIVER_ATHEROS)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008862 ath_reset_vht_defaults(dut);
8863 }
8864
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008865 if (dut->program == PROGRAM_IOTLP) {
8866 dut->wnm_bss_max_feature = VALUE_DISABLED;
8867 dut->wnm_bss_max_idle_time = 0;
8868 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8869 dut->ap_proxy_arp = 1;
8870 } else {
8871 /*
8872 * Do not touch the BSS-MAX Idle time feature
8873 * if the program is not IOTLP.
8874 */
8875 dut->wnm_bss_max_feature = VALUE_NOT_SET;
8876 dut->wnm_bss_max_idle_time = 0;
8877 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8878 }
8879
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008880 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008881 dut->ap_rrm = 1;
8882 dut->ap_rtt = 1;
8883 dut->ap_lci = 0;
8884 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008885 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008886 dut->ap_lcr = 0;
8887 dut->ap_val_lcr[0] = '\0';
8888 dut->ap_neighap = 0;
8889 dut->ap_opchannel = 0;
8890 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008891 dut->ap_fqdn_held = 0;
8892 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07008893 dut->ap_interworking = 0;
8894 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008895 dut->ap_msnt_type = 0;
8896 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008897 dut->ap_ft_oa = 0;
Jouni Malinen9f943312019-08-19 23:49:16 +03008898 dut->ap_ft_ds = VALUE_NOT_SET;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07008899 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07008900 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008901
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008902 if (dut->program == PROGRAM_MBO) {
8903 dut->ap_mbo = 1;
8904 dut->ap_interworking = 1;
8905 dut->ap_ne_class = 0;
8906 dut->ap_ne_op_ch = 0;
8907 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008908 dut->ap_btmreq_disassoc_imnt = 0;
8909 dut->ap_btmreq_term_bit = 0;
8910 dut->ap_disassoc_timer = 0;
8911 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07008912 dut->ap_channel = 36;
8913 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07008914 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07008915 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008916 dut->mbo_self_ap_tuple.ap_ne_class = -1;
8917 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
8918 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008919 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008920 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008921 }
8922
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008923 if (dut->program == PROGRAM_OCE) {
8924 if (dut->ap_dhcp_stop)
8925 run_system(dut, "/etc/init.d/dnsmasq start");
8926
8927 dut->ap_dhcp_stop = 0;
8928 dut->ap_oce = VALUE_ENABLED;
8929 dut->ap_broadcast_ssid = VALUE_ENABLED;
8930 dut->ap_fils_dscv_int = 20;
8931 dut->ap_filsdscv = VALUE_ENABLED;
8932 dut->ap_filshlp = VALUE_DISABLED;
8933 dut->ap_rnr = VALUE_DISABLED;
8934 dut->ap_nairealm[0] = '\0';
8935 dut->ap_nairealm_int = 0;
8936 dut->ap_blechanutil = 0;
8937 dut->ap_ble_admit_cap = 0;
8938 dut->ap_esp = VALUE_ENABLED;
8939 dut->ap_datappdudura = 0;
8940 dut->ap_airtimefract = 0;
8941 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08008942 dut->ap_ul_availcap = 0;
8943 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08008944 dut->ap_akm = 0;
8945 dut->ap_add_sha256 = 0;
8946 dut->ap_add_sha384 = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08008947 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008948 }
8949
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008950 dut->ap_he_ppdu = PPDU_NOT_SET;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008951 dut->ap_he_ulofdma = VALUE_NOT_SET;
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07008952 dut->ap_numsounddim = 0;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008953 dut->ap_bcc = VALUE_DISABLED;
Priyadharshini Gowthaman21895a52019-10-07 16:56:16 -07008954 dut->ap_mu_edca = VALUE_DISABLED;
Priyadharshini Gowthamandee79e22019-10-07 16:56:27 -07008955 dut->ap_he_mimo = MIMO_NOT_SET;
Priyadharshini Gowthaman43d6b412019-10-07 16:56:37 -07008956 dut->ap_he_rtsthrshld = VALUE_NOT_SET;
Priyadharshini Gowthaman8018c982019-10-31 15:14:37 -07008957 dut->ap_mbssid = VALUE_DISABLED;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08008958 dut->ap_ampdu = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08008959 dut->he_mcsnssmap = 0;
8960 dut->ap_fixed_rate = 0;
Priyadharshini Gowthaman21f74402019-11-25 15:39:09 -08008961 dut->he_mmss = 0;
Priyadharshini Gowthaman9b7dbe12019-12-04 12:17:32 -08008962 dut->he_set_sta_1x1 = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008963 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008964 dut->ap_he_dlofdma = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008965 dut->ap_he_frag = VALUE_DISABLED;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07008966 dut->ap_twtresp = VALUE_DISABLED;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08008967 dut->he_ul_mcs = 7;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008968 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008969 dut->ap_he_dlofdma = VALUE_NOT_SET;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008970 dut->ap_he_frag = VALUE_NOT_SET;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07008971 dut->ap_ba_bufsize = BA_BUFSIZE_NOT_SET;
Priyadharshini Gowthamanae0a6052019-11-01 15:26:38 -07008972 dut->ap_twtresp = VALUE_NOT_SET;
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -08008973 dut->he_ul_mcs = 0;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008974 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008975
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008976 if (dut->program == PROGRAM_HE) {
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07008977 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008978 dut->ap_ldpc = VALUE_DISABLED;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07008979 dut->ap_ba_bufsize = BA_BUFSIZE_64;
Priyadharshini Gowthamanb58b51b2019-11-04 14:02:51 -08008980 dut->ap_amsdu = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08008981 dut->ap_txBF = 0;
8982 dut->ap_mu_txBF = 0;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08008983 dut->he_sounding = VALUE_DISABLED;
Priyadharshini Gowthamane216dc52019-11-08 14:22:16 -08008984 } else {
8985 dut->ap_txBF = 1;
8986 dut->ap_mu_txBF = 1;
Priyadharshini Gowthaman96d542e2019-11-21 14:25:21 -08008987 dut->he_sounding = VALUE_ENABLED;
Priyadharshini Gowthaman1a686bd2019-09-19 14:41:40 -07008988 }
Priyadharshini Gowthaman115c79d2019-11-13 15:23:08 -08008989 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8990 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008991 }
8992
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08008993 dut->ap_oper_chn = 0;
8994
Jouni Malinenb75c5322019-06-14 01:47:43 +03008995 dut->ap_pmksa = 0;
8996 dut->ap_pmksa_caching = 0;
8997
Jouni Malinen3c367e82017-06-23 17:01:47 +03008998 free(dut->rsne_override);
8999 dut->rsne_override = NULL;
Jouni Malinen7960e3a2019-12-07 17:04:35 +02009000 free(dut->rsnxe_override_eapol);
9001 dut->rsnxe_override_eapol = NULL;
Jouni Malinen3c367e82017-06-23 17:01:47 +03009002
Jouni Malinen68143132017-09-02 02:34:08 +03009003 free(dut->sae_commit_override);
9004 dut->sae_commit_override = NULL;
9005
Jouni Malinened670f42017-08-31 01:39:28 +03009006 free(dut->ap_sae_groups);
9007 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03009008
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009009 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03009010 dut->sae_reflection = 0;
Jouni Malinen3c740ab2019-10-10 15:55:11 +03009011 dut->sae_confirm_immediate = 0;
Jouni Malinen11e55212019-11-22 21:46:59 +02009012 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03009013
Jouni Malinen3d633da2017-09-14 22:19:21 +03009014 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02009015 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03009016 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02009017 dut->ap_passphrase[0] = '\0';
9018 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03009019
Jouni Malinend86e5822017-08-29 03:55:32 +03009020 dut->dpp_conf_id = -1;
Jouni Malinenba4f2d42019-10-04 16:13:41 +03009021 free(dut->ap_dpp_conf_addr);
9022 dut->ap_dpp_conf_addr = NULL;
9023 free(dut->ap_dpp_conf_pkhash);
9024 dut->ap_dpp_conf_pkhash = NULL;
Jouni Malinend86e5822017-08-29 03:55:32 +03009025
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009026 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009027 dut->ap_mode = AP_11ad;
9028 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02009029 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009030 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02009031 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009032 dut->ap_fixed_rate = 0;
9033
9034 dut->dev_role = DEVROLE_AP;
9035
9036 sigma_dut_print(dut, DUT_MSG_DEBUG,
9037 "Setting msdu_size to MAX: 7912");
9038 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009039 get_main_ifname(dut));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009040
9041 if (system(buf) != 0) {
9042 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
9043 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009044 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009045 }
9046
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009047 if (ap_set_force_mcs(dut, 0, 1)) {
9048 sigma_dut_print(dut, DUT_MSG_ERROR,
9049 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009050 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02009051 }
9052
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009053 if (set_ps(get_main_ifname(dut), dut, 1)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009054 sigma_dut_print(dut, DUT_MSG_ERROR,
9055 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009056 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02009057 }
9058 }
9059
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009060 if (dut->program == PROGRAM_WPS &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009061 get_driver_type(dut) == DRIVER_WIL6210) {
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02009062 /*
9063 * In 60 GHz WPS tests, we configure the AP OOB to
9064 * secure connection with a random passphrase.
9065 */
9066 char r[16], passphrase[65];
9067
9068 if (random_get_bytes(r, sizeof(r))) {
9069 sigma_dut_print(dut, DUT_MSG_ERROR,
9070 "Failed to get random bytes");
9071 return ERROR_SEND_STATUS;
9072 }
9073 if (base64_encode(r, sizeof(r),
9074 passphrase, sizeof(passphrase))) {
9075 sigma_dut_print(dut, DUT_MSG_ERROR,
9076 "Failed to generate random passphrase");
9077 return ERROR_SEND_STATUS;
9078 }
9079
9080 dut->ap_key_mgmt = AP_WPA2_PSK;
9081 dut->ap_cipher = AP_GCMP_128;
9082 strlcpy(dut->ap_passphrase, passphrase,
9083 sizeof(dut->ap_passphrase));
9084 sigma_dut_print(dut, DUT_MSG_DEBUG,
9085 "60G WPS: configure secure AP with random passphrase");
9086 }
9087
Jouni Malinend86e5822017-08-29 03:55:32 +03009088 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08009089
9090 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
9091 return 1;
9092
Jouni Malinend6bf1b42017-06-23 17:51:01 +03009093 if (dut->use_hostapd_pid_file) {
9094 kill_hostapd_process_pid(dut);
9095 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
9096 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009097 int i;
9098 /* Wait some time to allow hostapd to complete cleanup before
9099 * starting a new process */
9100 for (i = 0; i < 10; i++) {
9101 usleep(500000);
9102 if (system("pidof hostapd") != 0)
9103 break;
9104 }
9105 }
9106
9107 if (if_nametoindex("sigmadut") > 0 &&
9108 system("iw dev sigmadut del") != 0)
9109 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
9110 "monitor interface");
9111
9112 return 1;
9113}
9114
9115
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309116int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
9117 struct sigma_cmd *cmd)
9118{
9119 return cmd_ap_reset_default(dut, conn, cmd);
9120}
9121
9122
Jouni Malinenf7222712019-06-13 01:50:21 +03009123static enum sigma_cmd_result cmd_ap_get_info(struct sigma_dut *dut,
9124 struct sigma_conn *conn,
9125 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009126{
9127 /* const char *name = get_param(cmd, "NAME"); */
9128 struct stat s;
9129 char resp[200];
9130 FILE *f;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009131 enum driver_type drv = get_driver_type(dut);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009132 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009133
9134 switch (drv) {
9135 case DRIVER_ATHEROS: {
9136 /* Atheros AP */
9137 struct utsname uts;
9138 char *version, athver[100];
9139
9140 if (stat("/proc/athversion", &s) != 0) {
9141 if (system("/etc/rc.d/rc.wlan up") != 0) {
9142 }
9143 }
9144
9145 athver[0] = '\0';
9146 f = fopen("/proc/athversion", "r");
9147 if (f) {
9148 if (fgets(athver, sizeof(athver), f)) {
9149 char *pos = strchr(athver, '\n');
9150 if (pos)
9151 *pos = '\0';
9152 }
9153 fclose(f);
9154 }
9155
9156 if (uname(&uts) == 0)
9157 version = uts.release;
9158 else
9159 version = "Unknown";
9160
9161 if (if_nametoindex("ath1") > 0)
Jouni Malinen3aa72862019-05-29 23:14:51 +03009162 res = snprintf(resp, sizeof(resp),
9163 "interface,ath0_24G ath1_5G,agent,1.0,version,%s/drv:%s",
9164 version, athver);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009165 else
Jouni Malinen3aa72862019-05-29 23:14:51 +03009166 res = snprintf(resp, sizeof(resp),
9167 "interface,ath0_24G,agent,1.0,version,%s/drv:%s",
9168 version, athver);
9169 if (res < 0 || res >= sizeof(resp))
9170 send_resp(dut, conn, SIGMA_ERROR, NULL);
9171 else
9172 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009173 return 0;
9174 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05309175 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009176 case DRIVER_MAC80211: {
9177 struct utsname uts;
9178 char *version;
9179
9180 if (uname(&uts) == 0)
9181 version = uts.release;
9182 else
9183 version = "Unknown";
9184
9185 if (if_nametoindex("wlan1") > 0)
9186 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
9187 "wlan1_5G,agent,1.0,version,%s", version);
9188 else
9189 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
9190 "agent,1.0,version,%s", version);
9191
9192 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9193 return 0;
9194 }
9195 case DRIVER_QNXNTO: {
9196 struct utsname uts;
9197 char *version;
9198
9199 if (uname(&uts) == 0)
9200 version = uts.release;
9201 else
9202 version = "Unknown";
9203 snprintf(resp, sizeof(resp),
9204 "interface,%s_any,agent,1.0,version,%s",
Jouni Malinen5ea30922019-11-04 17:39:25 +02009205 dut->main_ifname ? get_main_ifname(dut) : "NA",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009206 version);
9207 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9208 return 0;
9209 }
9210 case DRIVER_OPENWRT: {
9211 switch (get_openwrt_driver_type()) {
9212 case OPENWRT_DRIVER_ATHEROS: {
9213 struct utsname uts;
9214 char *version;
9215
9216 if (uname(&uts) == 0)
9217 version = uts.release;
9218 else
9219 version = "Unknown";
9220
9221 if (if_nametoindex("ath1") > 0)
9222 snprintf(resp, sizeof(resp),
9223 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
9224 version);
9225 else
9226 snprintf(resp, sizeof(resp),
9227 "interface,ath0_any,agent,1.0,version,%s",
9228 version);
9229
9230 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9231 return 0;
9232 }
9233 default:
9234 send_resp(dut, conn, SIGMA_ERROR,
9235 "errorCode,Unsupported openwrt driver");
9236 return 0;
9237 }
9238 }
9239 default:
9240 send_resp(dut, conn, SIGMA_ERROR,
9241 "errorCode,Unsupported driver");
9242 return 0;
9243 }
9244}
9245
9246
Jouni Malinenf7222712019-06-13 01:50:21 +03009247static enum sigma_cmd_result cmd_ap_deauth_sta(struct sigma_dut *dut,
9248 struct sigma_conn *conn,
9249 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009250{
9251 /* const char *name = get_param(cmd, "NAME"); */
9252 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009253 const char *val, *disconnect;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009254 char buf[100];
9255
9256 val = get_param(cmd, "MinorCode");
9257 if (val) {
9258 /* TODO: add support for P2P minor code */
9259 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
9260 "yet supported");
9261 return 0;
9262 }
9263
9264 val = get_param(cmd, "STA_MAC_ADDRESS");
9265 if (val == NULL)
9266 return -1;
Jouni Malinen0ac588d2019-11-06 18:57:01 +02009267 disconnect = get_param(cmd, "disconnect");
9268 if (disconnect && strcasecmp(disconnect, "silent") == 0)
9269 snprintf(buf, sizeof(buf), "deauth %s tx=0", val);
9270 else
9271 snprintf(buf, sizeof(buf), "deauth %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009272 if (run_hostapd_cli(dut, buf) != 0)
9273 return -2;
9274
9275 return 1;
9276}
9277
9278
9279#ifdef __linux__
9280int inject_frame(int s, const void *data, size_t len, int encrypt);
9281int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009282#endif /* __linux__ */
9283
9284enum send_frame_type {
9285 DISASSOC, DEAUTH, SAQUERY
9286};
9287enum send_frame_protection {
9288 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9289};
9290
9291
9292static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9293 enum send_frame_type frame,
9294 enum send_frame_protection protected,
9295 const char *sta_addr)
9296{
9297#ifdef __linux__
9298 unsigned char buf[1000], *pos;
9299 int s, res;
9300 unsigned char addr_sta[6], addr_own[6];
9301 char *ifname;
9302 char cbuf[100];
9303 struct ifreq ifr;
9304
9305 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
9306 dut->ap_mode == AP_11ac) &&
9307 if_nametoindex("wlan1") > 0)
9308 ifname = "wlan1";
9309 else
9310 ifname = "wlan0";
9311
9312 if (hwaddr_aton(sta_addr, addr_sta) < 0)
9313 return -1;
9314
9315 s = socket(AF_INET, SOCK_DGRAM, 0);
9316 if (s < 0)
9317 return -1;
9318 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009319 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009320 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9321 perror("ioctl");
9322 close(s);
9323 return -1;
9324 }
9325 close(s);
9326 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
9327
9328 if (if_nametoindex("sigmadut") == 0) {
9329 snprintf(cbuf, sizeof(cbuf),
9330 "iw dev %s interface add sigmadut type monitor",
9331 ifname);
9332 if (system(cbuf) != 0 ||
9333 if_nametoindex("sigmadut") == 0) {
9334 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9335 "monitor interface with '%s'", cbuf);
9336 return -2;
9337 }
9338 }
9339
9340 if (system("ifconfig sigmadut up") != 0) {
9341 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9342 "monitor interface up");
9343 return -2;
9344 }
9345
9346 pos = buf;
9347
9348 /* Frame Control */
9349 switch (frame) {
9350 case DISASSOC:
9351 *pos++ = 0xa0;
9352 break;
9353 case DEAUTH:
9354 *pos++ = 0xc0;
9355 break;
9356 case SAQUERY:
9357 *pos++ = 0xd0;
9358 break;
9359 }
9360
9361 if (protected == INCORRECT_KEY)
9362 *pos++ = 0x40; /* Set Protected field to 1 */
9363 else
9364 *pos++ = 0x00;
9365
9366 /* Duration */
9367 *pos++ = 0x00;
9368 *pos++ = 0x00;
9369
9370 /* addr1 = DA (station) */
9371 memcpy(pos, addr_sta, 6);
9372 pos += 6;
9373 /* addr2 = SA (own address) */
9374 memcpy(pos, addr_own, 6);
9375 pos += 6;
9376 /* addr3 = BSSID (own address) */
9377 memcpy(pos, addr_own, 6);
9378 pos += 6;
9379
9380 /* Seq# (to be filled by driver/mac80211) */
9381 *pos++ = 0x00;
9382 *pos++ = 0x00;
9383
9384 if (protected == INCORRECT_KEY) {
9385 /* CCMP parameters */
9386 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9387 pos += 8;
9388 }
9389
9390 if (protected == INCORRECT_KEY) {
9391 switch (frame) {
9392 case DEAUTH:
9393 /* Reason code (encrypted) */
9394 memcpy(pos, "\xa7\x39", 2);
9395 pos += 2;
9396 break;
9397 case DISASSOC:
9398 /* Reason code (encrypted) */
9399 memcpy(pos, "\xa7\x39", 2);
9400 pos += 2;
9401 break;
9402 case SAQUERY:
9403 /* Category|Action|TransID (encrypted) */
9404 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9405 pos += 4;
9406 break;
9407 default:
9408 return -1;
9409 }
9410
9411 /* CCMP MIC */
9412 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9413 pos += 8;
9414 } else {
9415 switch (frame) {
9416 case DEAUTH:
9417 /* reason code = 8 */
9418 *pos++ = 0x08;
9419 *pos++ = 0x00;
9420 break;
9421 case DISASSOC:
9422 /* reason code = 8 */
9423 *pos++ = 0x08;
9424 *pos++ = 0x00;
9425 break;
9426 case SAQUERY:
9427 /* Category - SA Query */
9428 *pos++ = 0x08;
9429 /* SA query Action - Request */
9430 *pos++ = 0x00;
9431 /* Transaction ID */
9432 *pos++ = 0x12;
9433 *pos++ = 0x34;
9434 break;
9435 }
9436 }
9437
9438 s = open_monitor("sigmadut");
9439 if (s < 0) {
9440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9441 "monitor socket");
9442 return 0;
9443 }
9444
9445 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9446 if (res < 0) {
9447 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9448 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309449 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009450 return 0;
9451 }
9452 if (res < pos - buf) {
9453 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9454 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309455 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009456 return 0;
9457 }
9458
9459 close(s);
9460
9461 return 1;
9462#else /* __linux__ */
9463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
9464 "yet supported");
9465 return 0;
9466#endif /* __linux__ */
9467}
9468
9469
9470int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
9471 struct sigma_cmd *cmd)
9472{
9473 const char *val, *dest;
9474 char buf[100];
9475
9476 val = get_param(cmd, "FrameName");
9477 if (val == NULL)
9478 return -1;
9479
9480 if (strcasecmp(val, "QoSMapConfigure") == 0) {
9481 dest = get_param(cmd, "Dest");
9482 if (!dest)
9483 return -1;
9484
9485 val = get_param(cmd, "QoS_MAP_SET");
9486 if (val) {
9487 dut->ap_qos_map_set = atoi(val);
9488 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9489 dut->ap_qos_map_set);
9490 }
9491
9492 if (dut->ap_qos_map_set == 1)
9493 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9494 else if (dut->ap_qos_map_set == 2)
9495 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9496
9497 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9498 if (run_hostapd_cli(dut, buf) != 0)
9499 return -1;
9500 }
9501
9502 return 1;
9503}
9504
9505
9506static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9507 struct sigma_cmd *cmd)
9508{
9509 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009510 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009511 int chwidth, nss;
9512
9513 val = get_param(cmd, "FrameName");
9514 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
9515 send_resp(dut, conn, SIGMA_ERROR,
9516 "errorCode,Unsupported FrameName");
9517 return 0;
9518 }
9519
9520 /*
9521 * Sequence of commands for Opmode notification on
9522 * Peregrine based products
9523 */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009524 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009525
9526 /* Disable STBC */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009527 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009528
9529 /* Check whether optional arg channel width was passed */
9530 val = get_param(cmd, "Channel_width");
9531 if (val) {
9532 switch (atoi(val)) {
9533 case 20:
9534 chwidth = 0;
9535 break;
9536 case 40:
9537 chwidth = 1;
9538 break;
9539 case 80:
9540 chwidth = 2;
9541 break;
9542 case 160:
9543 chwidth = 3;
9544 break;
9545 default:
9546 chwidth = 2;
9547 break;
9548 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009549 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009550 }
9551
9552 /* Check whether optional arg NSS was passed */
9553 val = get_param(cmd, "NSS");
9554 if (val) {
9555 /* Convert nss to chainmask */
9556 switch (atoi(val)) {
9557 case 1:
9558 nss = 1;
9559 break;
9560 case 2:
9561 nss = 3;
9562 break;
9563 case 3:
9564 nss = 7;
9565 break;
9566 default:
9567 /* We do not support NSS > 3 */
9568 nss = 3;
9569 break;
9570 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009571 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009572 }
9573
9574 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009575 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009576
9577 return 1;
9578}
9579
9580
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009581static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9582 struct sigma_cmd *cmd)
9583{
9584 const char *val;
9585 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009586 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009587
9588 val = get_param(cmd, "MsntType");
9589 if (val) {
9590 if (dut->ap_msnt_type == 0)
9591 dut->ap_msnt_type = atoi(val);
9592
9593 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
9594 dut->ap_msnt_type = atoi(val);
9595 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009596 val = get_param(cmd, "RandInterval");
9597 if (val)
9598 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009599 f = fopen("/tmp/ftmrr.txt", "a");
9600 if (!f) {
9601 sigma_dut_print(dut, DUT_MSG_ERROR,
9602 "Failed to open /tmp/ftmrr.txt");
9603 return -1;
9604 }
9605
9606 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07009607 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",
9608 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009609 fclose(f);
9610 dut->ap_msnt_type = 5;
9611 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9612 }
9613 } else if (dut->ap_msnt_type == 5) {
9614 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9615 } else if (dut->ap_msnt_type == 2) {
9616 f = fopen("/tmp/wru.txt", "w");
9617 if (!f) {
9618 sigma_dut_print(dut, DUT_MSG_ERROR,
9619 "Failed to open /tmp/wru.txt");
9620 return -1;
9621 }
9622
9623 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
9624 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
9625 fclose(f);
9626 run_system(dut, "wpc -w /tmp/wru.txt");
9627 }
9628 }
9629 return 1;
9630}
9631
9632
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009633/*
9634 * The following functions parse_send_frame_params_int(),
9635 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
9636 * are used by ath_ap_send_frame_bcn_rpt_req().
9637 * Beacon Report Request is a frame used as part of the MBO program.
9638 * The command for sending beacon report has a lot of
9639 * arguments and having these functions reduces code size.
9640 *
9641 */
9642static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
9643 struct sigma_dut *dut,
9644 char *buf, size_t buf_size)
9645{
9646 const char *str_val;
9647 int int_val;
9648 char temp[100];
9649
9650 str_val = get_param(cmd, param);
9651 if (!str_val) {
9652 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9653 return -1;
9654 }
9655 int_val = atoi(str_val);
9656 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07009657 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009658 return 0;
9659}
9660
9661
9662static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
9663 struct sigma_dut *dut,
9664 char *buf, size_t buf_size)
9665{
9666 const char *str_val;
9667 char temp[100];
9668
9669 str_val = get_param(cmd, param);
9670 if (!str_val) {
9671 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9672 return -1;
9673 }
9674 snprintf(temp, sizeof(temp), " %s", str_val);
9675 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07009676 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009677 return 0;
9678}
9679
9680
9681static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
9682 struct sigma_dut *dut,
9683 char *buf, size_t buf_size)
9684{
9685 const char *str_val;
9686 unsigned char mac[6];
9687 char temp[100];
9688
9689 str_val = get_param(cmd, param);
9690 if (!str_val) {
9691 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9692 return -1;
9693 }
9694
9695 if (parse_mac_address(dut, str_val, mac) < 0) {
9696 sigma_dut_print(dut, DUT_MSG_ERROR,
9697 "MAC Address not in proper format");
9698 return -1;
9699 }
9700 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
9701 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07009702 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009703 return 0;
9704}
9705
9706
9707static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
9708 char *buf, size_t buf_size)
9709{
9710 const char *str_val;
9711 char *value = " 1";
9712
9713 str_val = get_param(cmd, param);
9714 if (!str_val || str_val[0] == '\0')
9715 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07009716 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009717
9718}
9719
9720
9721/*
9722 * wifitool athN sendbcnrpt
9723 * <STA MAC - Plugs in from Dest_MAC>
9724 * <regclass - Plugs in from RegClass - int>
9725 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
9726 * <rand_ivl - Plugs in from RandInt - string>
9727 * <duration - Plugs in from MeaDur - integer>
9728 * <mode - Plugs in from MeaMode - string>
9729 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
9730 * <rep_cond - Plugs in from RptCond - integer>
9731 * <rpt_detail - Plugs in from RptDet - integer>
9732 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
9733 * <chanrpt_mode - Plugs in from APChanRpt - integer>
9734 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
9735 * [AP channel numbers]
9736 */
9737static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
9738 struct sigma_cmd *cmd,
9739 const char *ifname)
9740{
9741 char buf[100];
9742 int rpt_det;
9743 const char *str_val;
9744 const char *mea_mode;
9745
9746 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
9747
9748 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
9749 return -1;
9750 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
9751 return -1;
9752 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
9753 return -1;
9754 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
9755 return -1;
9756 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
9757 return -1;
9758
9759 str_val = get_param(cmd, "MeaMode");
9760 if (!str_val) {
9761 sigma_dut_print(dut, DUT_MSG_ERROR,
9762 "MeaMode parameter not present in send bcn-rpt-req");
9763 return -1;
9764 }
9765 if (strcasecmp(str_val, "passive") == 0) {
9766 mea_mode = " 0";
9767 } else if (strcasecmp(str_val, "active") == 0) {
9768 mea_mode = " 1";
9769 } else if (strcasecmp(str_val, "table") == 0) {
9770 mea_mode = " 2";
9771 } else {
9772 sigma_dut_print(dut, DUT_MSG_ERROR,
9773 "MEA-MODE Value not correctly given");
9774 return -1;
9775 }
Peng Xu591be452017-05-10 17:27:28 -07009776 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009777
9778 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
9779
9780 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
9781 return -1;
9782
9783 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
9784 return -1;
9785 str_val = get_param(cmd, "RptDet");
9786 rpt_det = str_val ? atoi(str_val) : 0;
9787
9788 if (rpt_det)
9789 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
9790 else
Peng Xu591be452017-05-10 17:27:28 -07009791 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009792
9793 if (rpt_det)
9794 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
9795 sizeof(buf));
9796 else
Peng Xu591be452017-05-10 17:27:28 -07009797 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009798
9799 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
9800 return -1;
9801
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009802 str_val = get_param(cmd, "APChanRpt");
9803 if (str_val) {
9804 const char *pos;
9805 int ap_chanrpt;
9806 int ap_chanrpt_2 = 0;
9807 char chanrpt[100];
9808
9809 ap_chanrpt = atoi(str_val);
9810 pos = strchr(str_val, '_');
9811 if (pos) {
9812 pos++;
9813 ap_chanrpt_2 = atoi(pos);
9814 }
9815 if (ap_chanrpt) {
9816 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
9817 strlcat(buf, chanrpt, sizeof(buf));
9818 }
9819 if (ap_chanrpt_2) {
9820 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
9821 strlcat(buf, chanrpt, sizeof(buf));
9822 }
9823 }
9824
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009825 run_system(dut, buf);
9826 return 0;
9827}
9828
9829
9830static void inform_and_sleep(struct sigma_dut *dut, int seconds)
9831{
9832 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
9833 sleep(seconds);
9834 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
9835 seconds);
9836}
9837
9838
9839static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
9840 struct sigma_cmd *cmd, const char *ifname)
9841{
9842 unsigned char mac_addr[ETH_ALEN];
9843 int disassoc_timer;
9844 char buf[100];
9845 const char *val;
9846 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009847
9848 val = get_param(cmd, "Dest_MAC");
9849 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9850 sigma_dut_print(dut, DUT_MSG_ERROR,
9851 "MAC Address not in proper format");
9852 return -1;
9853 }
9854
9855 val = get_param(cmd, "Disassoc_Timer");
9856 if (val)
9857 disassoc_timer = atoi(val);
9858 else
9859 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02009860 if (disassoc_timer < 0) {
9861 sigma_dut_print(dut, DUT_MSG_ERROR,
9862 "Invalid Disassoc_Timer value %d",
9863 disassoc_timer);
9864 return -1;
9865 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009866
9867 val = get_param(cmd, "Cand_List");
9868 if (val && val[0])
9869 cand_list = atoi(val);
9870
9871 val = get_param(cmd, "BTMQuery_Reason_Code");
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009872 if (val)
9873 run_iwpriv(dut, ifname, "mbo_trans_rs %s", val);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009874
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009875 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay)
9876 run_iwpriv(dut, ifname, "mbo_asoc_ret 1");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009877
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009878 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009879 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009880 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
9881 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
9882 dut->ap_btmreq_disassoc_imnt,
9883 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009884 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009885 dut->ap_btmreq_bss_term_dur);
9886 run_system(dut, buf);
9887
9888 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009889 if (dut->ap_btmreq_bss_term_tsf >= 2)
9890 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009891 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9892 mac_addr[0], mac_addr[1], mac_addr[2],
9893 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009894 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009895 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009896 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009897 run_system_wrapper(dut, "ifconfig %s up", ifname);
9898 } else if (dut->ap_btmreq_disassoc_imnt) {
9899 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009900 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9901 mac_addr[0], mac_addr[1], mac_addr[2],
9902 mac_addr[3], mac_addr[4], mac_addr[5]);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009903 }
9904 return 0;
9905}
9906
9907
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009908static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
9909 struct sigma_cmd *cmd, const char *ifname)
9910{
9911 unsigned char mac_addr[ETH_ALEN];
9912 const char *val;
9913
9914 val = get_param(cmd, "Dest_MAC");
9915 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9916 sigma_dut_print(dut, DUT_MSG_ERROR,
9917 "MAC Address not in proper format");
9918 return -1;
9919 }
9920
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009921 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9922 mac_addr[0], mac_addr[1], mac_addr[2],
9923 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009924 return 0;
9925}
9926
9927
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009928static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9929 struct sigma_cmd *cmd)
9930{
9931 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009932 const char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009933
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009934 ifname = get_main_ifname(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009935
9936 val = get_param(cmd, "FrameName");
9937 if (!val)
9938 return -1;
9939
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009940 if (strcasecmp(val, "BTMReq") == 0)
9941 ath_ap_send_frame_btm_req(dut, cmd, ifname);
9942 else if (strcasecmp(val, "BcnRptReq") == 0)
9943 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009944 else if (strcasecmp(val, "disassoc") == 0)
9945 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009946 else
9947 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009948
9949 return 1;
9950}
9951
9952
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009953static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9954 struct sigma_cmd *cmd)
9955{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009956 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009957 case DRIVER_ATHEROS:
9958 return ath_ap_send_frame_vht(dut, conn, cmd);
9959 break;
9960 case DRIVER_OPENWRT:
9961 switch (get_openwrt_driver_type()) {
9962 case OPENWRT_DRIVER_ATHEROS:
9963 return ath_ap_send_frame_vht(dut, conn, cmd);
9964 default:
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9967 return 0;
9968 }
9969 default:
9970 send_resp(dut, conn, SIGMA_ERROR,
9971 "errorCode,Unsupported ap_send_frame with the current driver");
9972 return 0;
9973 }
9974}
9975
9976
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009977static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9978 struct sigma_cmd *cmd)
9979{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009980 switch (get_driver_type(dut)) {
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009981 case DRIVER_ATHEROS:
9982 return ath_ap_send_frame_loc(dut, conn, cmd);
9983 case DRIVER_OPENWRT:
9984 switch (get_openwrt_driver_type()) {
9985 case OPENWRT_DRIVER_ATHEROS:
9986 return ath_ap_send_frame_loc(dut, conn, cmd);
9987 default:
9988 send_resp(dut, conn, SIGMA_ERROR,
9989 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
9990 return 0;
9991 }
9992 default:
9993 send_resp(dut, conn, SIGMA_ERROR,
9994 "errorCode,Unsupported ap_send_frame_loc with the current driver");
9995 return 0;
9996 }
9997}
9998
9999
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010000static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
10001 struct sigma_cmd *cmd)
10002{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010003 switch (get_driver_type(dut)) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010004 case DRIVER_ATHEROS:
10005 return ath_ap_send_frame_mbo(dut, conn, cmd);
10006 case DRIVER_OPENWRT:
10007 switch (get_openwrt_driver_type()) {
10008 case OPENWRT_DRIVER_ATHEROS:
10009 return ath_ap_send_frame_mbo(dut, conn, cmd);
10010 default:
10011 send_resp(dut, conn, SIGMA_ERROR,
10012 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
10013 return 0;
10014 }
10015 default:
10016 send_resp(dut, conn, SIGMA_ERROR,
10017 "errorCode,Unsupported ap_send_frame with the current driver");
10018 return 0;
10019 }
10020}
10021
10022
Lior David0fe101e2017-03-09 16:09:50 +020010023static int ap_send_frame_60g(struct sigma_dut *dut,
10024 struct sigma_conn *conn,
10025 struct sigma_cmd *cmd)
10026{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010027 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010028#ifdef __linux__
10029 case DRIVER_WIL6210:
10030 return wil6210_send_frame_60g(dut, conn, cmd);
10031#endif /* __linux__ */
10032 default:
10033 send_resp(dut, conn, SIGMA_ERROR,
10034 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10035 return 0;
10036 }
10037}
10038
10039
Jouni Malinenf7222712019-06-13 01:50:21 +030010040enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
10041 struct sigma_conn *conn,
10042 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010043{
10044 /* const char *name = get_param(cmd, "NAME"); */
10045 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10046 const char *val;
10047 enum send_frame_type frame;
10048 enum send_frame_protection protected;
10049 char buf[100];
10050
10051 val = get_param(cmd, "Program");
10052 if (val) {
10053 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070010054 strcasecmp(val, "HS2-R2") == 0 ||
10055 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010056 return ap_send_frame_hs2(dut, conn, cmd);
10057 if (strcasecmp(val, "VHT") == 0)
10058 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -070010059 if (strcasecmp(val, "LOC") == 0)
10060 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010061 if (strcasecmp(val, "MBO") == 0)
10062 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010063 if (strcasecmp(val, "60GHz") == 0)
10064 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010065 }
10066
10067 val = get_param(cmd, "PMFFrameType");
10068 if (val == NULL)
10069 val = get_param(cmd, "FrameName");
10070 if (val == NULL)
10071 val = get_param(cmd, "Type");
10072 if (val == NULL)
10073 return -1;
10074 if (strcasecmp(val, "disassoc") == 0)
10075 frame = DISASSOC;
10076 else if (strcasecmp(val, "deauth") == 0)
10077 frame = DEAUTH;
10078 else if (strcasecmp(val, "saquery") == 0)
10079 frame = SAQUERY;
10080 else {
10081 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10082 "PMFFrameType");
10083 return 0;
10084 }
10085
10086 val = get_param(cmd, "PMFProtected");
10087 if (val == NULL)
10088 val = get_param(cmd, "Protected");
10089 if (val == NULL)
10090 return -1;
10091 if (strcasecmp(val, "Correct-key") == 0 ||
10092 strcasecmp(val, "CorrectKey") == 0)
10093 protected = CORRECT_KEY;
10094 else if (strcasecmp(val, "IncorrectKey") == 0)
10095 protected = INCORRECT_KEY;
10096 else if (strcasecmp(val, "Unprotected") == 0)
10097 protected = UNPROTECTED;
10098 else {
10099 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10100 "PMFProtected");
10101 return 0;
10102 }
10103
10104 val = get_param(cmd, "stationID");
10105 if (val == NULL)
10106 return -1;
10107
10108 if (protected == INCORRECT_KEY ||
10109 (protected == UNPROTECTED && frame == SAQUERY))
10110 return ap_inject_frame(dut, conn, frame, protected, val);
10111
10112 switch (frame) {
10113 case DISASSOC:
10114 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
10115 val, protected == CORRECT_KEY);
10116 break;
10117 case DEAUTH:
10118 snprintf(buf, sizeof(buf), "deauth %s test=%d",
10119 val, protected == CORRECT_KEY);
10120 break;
10121 case SAQUERY:
10122 snprintf(buf, sizeof(buf), "sa_query %s", val);
10123 break;
10124 }
10125
10126 if (run_hostapd_cli(dut, buf) != 0)
10127 return -2;
10128
10129 return 1;
10130}
10131
10132
Jouni Malinenf7222712019-06-13 01:50:21 +030010133static enum sigma_cmd_result cmd_ap_get_mac_address(struct sigma_dut *dut,
10134 struct sigma_conn *conn,
10135 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010136{
10137#if defined( __linux__)
10138 /* const char *name = get_param(cmd, "NAME"); */
10139 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +030010140 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010141 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010142 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010143 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010144 int s, wlan_tag = 1;
10145 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010146
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010147 val = get_param(cmd, "WLAN_TAG");
10148 if (val) {
10149 wlan_tag = atoi(val);
10150 if (wlan_tag < 1 || wlan_tag > 3) {
10151 /*
10152 * The only valid WLAN Tags as of now as per the latest
10153 * WFA scripts are 1, 2, and 3.
10154 */
Jouni Malinenf8984642017-10-12 00:02:37 +030010155 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010156 "errorCode,Unsupported WLAN_TAG");
10157 return 0;
10158 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010159 }
10160
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -070010161 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
10162
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010163 s = socket(AF_INET, SOCK_DGRAM, 0);
10164 if (s < 0)
10165 return -1;
10166 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -070010167 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010168 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
10169 perror("ioctl");
10170 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +030010171 snprintf(resp, sizeof(resp),
10172 "errorCode,Could not find interface %s", ifname);
10173 send_resp(dut, conn, SIGMA_ERROR, resp);
10174 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010175 }
10176 close(s);
10177 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
10178
10179 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10180 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10181 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10182 return 0;
10183#elif defined( __QNXNTO__)
10184 char resp[50];
10185 unsigned char addr[6];
10186
Jouni Malinend2095482019-11-04 17:10:43 +020010187 if (!dut->main_ifname) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010188 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
10189 return 0;
10190 }
10191
Jouni Malinen5ea30922019-11-04 17:39:25 +020010192 if (get_hwaddr(get_main_ifname(dut), addr) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010193 send_resp(dut, conn, SIGMA_ERROR,
10194 "errorCode,Failed to get address");
10195 return 0;
10196 }
10197 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
10198 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
10199 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10200 return 0;
10201#else /* __linux__ */
10202 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
10203 "yet supported");
10204 return 0;
10205#endif /* __linux__ */
10206}
10207
10208
Ankita Bajaj0d5825b2017-10-25 16:20:17 +053010209int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
10210 struct sigma_cmd *cmd)
10211{
10212 return cmd_ap_get_mac_address(dut, conn, cmd);
10213}
10214
10215
Jouni Malinenf7222712019-06-13 01:50:21 +030010216static enum sigma_cmd_result cmd_ap_set_pmf(struct sigma_dut *dut,
10217 struct sigma_conn *conn,
10218 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010219{
10220 /*
10221 * Ignore the command since the parameters are already handled through
10222 * ap_set_security.
10223 */
10224
10225 return 1;
10226}
10227
10228
Jouni Malinenf7222712019-06-13 01:50:21 +030010229static enum sigma_cmd_result cmd_ap_set_hs2(struct sigma_dut *dut,
10230 struct sigma_conn *conn,
10231 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010232{
10233 /* const char *name = get_param(cmd, "NAME"); */
10234 /* const char *ifname = get_param(cmd, "INTERFACE"); */
10235 const char *val, *dest;
10236 char *pos, buf[100];
10237 int i, wlan_tag = 1;
10238
10239 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
10240 "following parameters");
10241 for (i = 0; i < cmd->count; i++) {
10242 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
10243 (cmd->values[i] ? cmd->values[i] : "NULL"));
10244 }
10245
10246 val = get_param(cmd, "ICMPv4_ECHO");
10247 if (val && atoi(val)) {
10248 snprintf(buf, sizeof(buf), "ebtables -F");
10249 if (system(buf) != 0) {
10250 sigma_dut_print(dut, DUT_MSG_ERROR,
10251 "Failed to set ebtables rules, RULE-12");
10252 }
10253 return 1;
10254 }
10255
10256 val = get_param(cmd, "WLAN_TAG");
10257 if (val) {
10258 wlan_tag = atoi(val);
10259 if (wlan_tag != 1 && wlan_tag != 2) {
10260 send_resp(dut, conn, SIGMA_INVALID,
10261 "errorCode,Invalid WLAN_TAG");
10262 return 0;
10263 }
10264 }
10265
10266 if (wlan_tag == 2) {
10267 val = get_param(cmd, "PROXY_ARP");
10268 if (val)
10269 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +020010270
10271 val = get_param(cmd, "OSU");
10272 if (val)
10273 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010274 return 1;
10275 }
10276
10277 dest = get_param(cmd, "STA_MAC");
10278 if (dest) {
10279 /* This is a special/ugly way of using this command.
10280 * If "Dest" MAC is included, assume that this command
10281 * is being issued after ap_config_commit for dynamically
10282 * setting the QoS Map Set.
10283 */
10284 val = get_param(cmd, "QoS_MAP_SET");
10285 if (val) {
10286 dut->ap_qos_map_set = atoi(val);
10287 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10288 dut->ap_qos_map_set);
10289 }
10290
10291 if (dut->ap_qos_map_set == 1)
10292 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
10293 else if (dut->ap_qos_map_set == 2)
10294 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
10295
10296 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
10297 if (run_hostapd_cli(dut, buf) != 0)
10298 return -1;
10299 }
10300
10301 val = get_param(cmd, "DGAF_DISABLE");
10302 if (val)
10303 dut->ap_dgaf_disable = atoi(val);
10304
10305 dut->ap_interworking = 1;
10306
10307 val = get_param(cmd, "INTERWORKING");
10308 if (val == NULL)
10309 val = get_param(cmd, "INTERNETWORKING");
10310 if (val != NULL && atoi(val) == 0) {
10311 dut->ap_interworking = 0;
10312 dut->ap_hs2 = 0;
10313 return 1;
10314 }
10315
10316 val = get_param(cmd, "ACCS_NET_TYPE");
10317 if (val) {
10318 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
10319 strcasecmp(val, "Chargable_Public_Network") == 0 ||
10320 strcasecmp(val, "Chargable Public Network") == 0)
10321 dut->ap_access_net_type = 2;
10322 else
10323 dut->ap_access_net_type = atoi(val);
10324 }
10325
10326 val = get_param(cmd, "INTERNET");
10327 if (val)
10328 dut->ap_internet = atoi(val);
10329
10330 val = get_param(cmd, "VENUE_GRP");
10331 if (val) {
10332 if (strcasecmp(val, "Business") == 0)
10333 dut->ap_venue_group = 2;
10334 else
10335 dut->ap_venue_group = atoi(val);
10336 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10337 dut->ap_venue_name);
10338 }
10339
10340 val = get_param(cmd, "VENUE_TYPE");
10341 if (val) {
10342 if (strcasecmp(val, "R&D") == 0)
10343 dut->ap_venue_type = 8;
10344 else
10345 dut->ap_venue_type = atoi(val);
10346 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
10347 dut->ap_venue_type);
10348 }
10349
10350 val = get_param(cmd, "HESSID");
10351 if (val) {
10352 if (strlen(val) >= sizeof(dut->ap_hessid)) {
10353 send_resp(dut, conn, SIGMA_ERROR,
10354 "errorCode,Invalid HESSID");
10355 return 0;
10356 }
10357 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
10358 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
10359 dut->ap_hessid);
10360 }
10361
10362 val = get_param(cmd, "ROAMING_CONS");
10363 if (val) {
10364 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
10365 send_resp(dut, conn, SIGMA_ERROR,
10366 "errorCode,Invalid ROAMING_CONS");
10367 return 0;
10368 }
10369 if (strcasecmp(val, "Disabled") == 0) {
10370 dut->ap_roaming_cons[0] = '\0';
10371 } else {
10372 snprintf(dut->ap_roaming_cons,
10373 sizeof(dut->ap_roaming_cons), "%s", val);
10374 }
10375 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
10376 dut->ap_roaming_cons);
10377 }
10378
10379 val = get_param(cmd, "ANQP");
10380 if (val)
10381 dut->ap_anqpserver_on = atoi(val);
10382
10383 val = get_param(cmd, "NAI_REALM_LIST");
10384 if (val) {
10385 dut->ap_nai_realm_list = atoi(val);
10386 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
10387 dut->ap_nai_realm_list);
10388 }
10389
10390 val = get_param(cmd, "3GPP_INFO");
10391 if (val) {
10392 /* What kind of encoding format is used?! */
10393 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
10394 "not yet supported (contents not fully defined)");
10395 return 0;
10396 }
10397
10398 val = get_param(cmd, "DOMAIN_LIST");
10399 if (val) {
10400 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
10401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
10402 "DOMAIN_LIST");
10403 return 0;
10404 }
10405 snprintf(dut->ap_domain_name_list,
10406 sizeof(dut->ap_domain_name_list), "%s", val);
10407 pos = dut->ap_domain_name_list;
10408 while (*pos) {
10409 if (*pos == ';')
10410 *pos = ',';
10411 pos++;
10412 }
10413 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
10414 dut->ap_domain_name_list);
10415 }
10416
10417 val = get_param(cmd, "OPER_NAME");
10418 if (val) {
10419 dut->ap_oper_name = atoi(val);
10420 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
10421 dut->ap_oper_name);
10422 }
10423
10424 val = get_param(cmd, "VENUE_NAME");
10425 if (val) {
10426 dut->ap_venue_name = atoi(val);
10427 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
10428 dut->ap_venue_name);
10429 }
10430
10431 val = get_param(cmd, "GAS_CB_DELAY");
10432 if (val) {
10433 dut->ap_gas_cb_delay = atoi(val);
10434 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
10435 dut->ap_gas_cb_delay);
10436 }
10437
10438 val = get_param(cmd, "MIH");
10439 if (val && atoi(val) > 0) {
10440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
10441 "supported");
10442 return 0;
10443 }
10444
10445 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
10446 if (val) {
10447 dut->ap_l2tif = atoi(val);
10448 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
10449 dut->ap_l2tif);
10450 }
10451
10452 val = get_param(cmd, "BCST_UNCST");
10453 if (val) {
10454 send_resp(dut, conn, SIGMA_ERROR,
10455 "errorCode,BCST_UNCST not yet supported");
10456 return 0;
10457 }
10458
10459 val = get_param(cmd, "PLMN_MCC");
10460 if (val) {
10461 char mcc[100], *start, *end;
10462 int i = 0;
10463 if (strlen(val) >= sizeof(mcc)) {
10464 send_resp(dut, conn, SIGMA_ERROR,
10465 "errorCode,PLMN_MCC too long");
10466 return 0;
10467 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010468 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010469 start = mcc;
10470 while ((end = strchr(start, ';'))) {
10471 /* process all except the last */
10472 *end = '\0';
10473 if (strlen(start) != 3) {
10474 send_resp(dut, conn, SIGMA_ERROR,
10475 "errorCode,Invalid PLMN_MCC");
10476 return 0;
10477 }
10478 snprintf(dut->ap_plmn_mcc[i],
10479 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
10480 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10481 dut->ap_plmn_mcc[i]);
10482 i++;
10483 start = end + 1;
10484 *end = ';';
10485 }
10486 if (strlen(start) != 3) {
10487 send_resp(dut, conn, SIGMA_ERROR,
10488 "errorCode,Invalid PLMN_MCC");
10489 return 0;
10490 }
10491 /* process last or only one */
10492 snprintf(dut->ap_plmn_mcc[i],
10493 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
10494 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
10495 dut->ap_plmn_mcc[i]);
10496 }
10497
10498 val = get_param(cmd, "PLMN_MNC");
10499 if (val) {
10500 char mnc[100], *start, *end;
10501 int i = 0;
10502 if (strlen(val) >= sizeof(mnc)) {
10503 send_resp(dut, conn, SIGMA_ERROR,
10504 "errorCode,PLMN_MNC too long");
10505 return 0;
10506 }
Peng Xub8fc5cc2017-05-10 17:27:28 -070010507 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010508 start = mnc;
10509 while ((end = strchr(start, ';'))) {
10510 *end = '\0';
10511 if (strlen(start) != 2 && strlen(start) != 3) {
10512 send_resp(dut, conn, SIGMA_ERROR,
10513 "errorCode,Invalid PLMN_MNC");
10514 return 0;
10515 }
10516 snprintf(dut->ap_plmn_mnc[i],
10517 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
10518 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10519 dut->ap_plmn_mnc[i]);
10520 i++;
10521 start = end + 1;
10522 *end = ';';
10523 }
10524 if (strlen(start) != 2 && strlen(start) != 3) {
10525 send_resp(dut, conn, SIGMA_ERROR,
10526 "errorCode,Invalid PLMN_MNC");
10527 return 0;
10528 }
10529 snprintf(dut->ap_plmn_mnc[i],
10530 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
10531 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
10532 dut->ap_plmn_mnc[i]);
10533 }
10534
10535 val = get_param(cmd, "PROXY_ARP");
10536 if (val) {
10537 dut->ap_proxy_arp = atoi(val);
10538 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
10539 dut->ap_proxy_arp);
10540 }
10541
10542 val = get_param(cmd, "WAN_METRICS");
10543 if (val) {
10544 dut->ap_wan_metrics = atoi(val);
10545 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
10546 dut->ap_wan_metrics);
10547 }
10548
10549 val = get_param(cmd, "CONN_CAP");
10550 if (val) {
10551 dut->ap_conn_capab = atoi(val);
10552 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
10553 dut->ap_conn_capab);
10554 }
10555
10556 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
10557 if (val) {
10558 dut->ap_ip_addr_type_avail = atoi(val);
10559 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
10560 dut->ap_ip_addr_type_avail);
10561 }
10562
10563 val = get_param(cmd, "NET_AUTH_TYPE");
10564 if (val) {
10565 dut->ap_net_auth_type = atoi(val);
10566 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
10567 dut->ap_net_auth_type);
10568 }
10569
10570 val = get_param(cmd, "OP_CLASS");
10571 if (val == NULL)
10572 val = get_param(cmd, "OPER_CLASS");
10573 if (val) {
10574 dut->ap_oper_class = atoi(val);
10575 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
10576 dut->ap_oper_class);
10577 }
10578
10579 val = get_param(cmd, "OSU_PROVIDER_LIST");
10580 if (val) {
10581 dut->ap_osu_provider_list = atoi(val);
10582 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
10583 dut->ap_osu_provider_list);
10584 }
10585
Jouni Malinen93a837f2018-11-01 17:09:22 +020010586 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
10587 if (val) {
10588 dut->ap_osu_provider_nai_list = atoi(val);
10589 sigma_dut_print(dut, DUT_MSG_INFO,
10590 "ap_osu_provider_nai_list %d",
10591 dut->ap_osu_provider_nai_list);
10592 }
10593
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010594 val = get_param(cmd, "OSU_SERVER_URI");
10595 if (val) {
10596 i = 0;
10597 do {
10598 int len;
10599 const char *uri = val;
10600 val = strchr(val, ' ');
10601 len = val ? (val++ - uri) : (int) strlen(uri);
10602 if (len > 0 && len < 256) {
10603 memcpy(dut->ap_osu_server_uri[i], uri, len);
10604 dut->ap_osu_server_uri[i][len] = '\0';
10605 sigma_dut_print(dut, DUT_MSG_INFO,
10606 "ap_osu_server_uri[%d] %s", i,
10607 dut->ap_osu_server_uri[i]);
10608 }
10609 } while (val && ++i < 10);
10610 }
10611
10612 val = get_param(cmd, "OSU_METHOD");
10613 if (val) {
10614 i = 0;
10615 do {
10616 int len;
10617 const char *method = val;
10618 val = strchr(val, ' ');
10619 len = val ? (val++ - method) : (int) strlen(method);
10620 if (len > 0) {
10621 if (strncasecmp(method, "SOAP", len) == 0)
10622 dut->ap_osu_method[i] = 1;
10623 else if (strncasecmp(method, "OMADM", len) == 0)
10624 dut->ap_osu_method[i] = 0;
10625 else
10626 return -2;
10627 }
10628 } while (val && ++i < 10);
10629 }
10630
10631 val = get_param(cmd, "OSU_SSID");
10632 if (val) {
10633 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -070010634 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010635 sizeof(dut->ap_osu_ssid));
10636 sigma_dut_print(dut, DUT_MSG_INFO,
10637 "ap_osu_ssid %s",
10638 dut->ap_osu_ssid);
10639 }
10640 }
10641
10642 val = get_param(cmd, "OSU_ICON_TAG");
10643 if (val)
10644 dut->ap_osu_icon_tag = atoi(val);
10645
10646 val = get_param(cmd, "QoS_MAP_SET");
10647 if (val) {
10648 dut->ap_qos_map_set = atoi(val);
10649 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10650 dut->ap_qos_map_set);
10651 }
10652
10653 val = get_param(cmd, "BSS_LOAD");
10654 if (val) {
10655 dut->ap_bss_load = atoi(val);
10656 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
10657 dut->ap_bss_load);
10658 }
10659
Jouni Malinen54a89b02018-05-01 00:16:26 +030010660 val = get_param(cmd, "Venue_URL");
10661 if (val)
10662 dut->ap_venue_url = atoi(val);
10663
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030010664 val = get_param(cmd, "Advice_of_Charge");
10665 if (val)
10666 dut->ap_advice_of_charge = atoi(val);
10667
Jouni Malinenac104532018-05-01 00:27:37 +030010668 val = get_param(cmd, "Operator_Icon_Metadata");
10669 if (val)
10670 dut->ap_oper_icon_metadata = atoi(val);
10671
Jouni Malinenac367142018-05-01 00:32:24 +030010672 val = get_param(cmd, "TnC_File_Name");
10673 if (val)
10674 dut->ap_tnc_file_name = atoi(val);
10675
10676 val = get_param(cmd, "TnC_File_Time_Stamp");
10677 if (val)
10678 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
10679
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010680 return 1;
10681}
10682
10683
10684void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
10685{
10686 char buf[100];
10687
10688 if (!file_exists("nfc-status"))
10689 return;
10690
10691 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
10692 run_system(dut, buf);
10693}
10694
10695
10696static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
10697 const char *info)
10698{
10699 int res;
10700
10701 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
10702 printf("%s\n\n", info);
10703
10704 nfc_status(dut, "START", info);
10705 res = run_system(dut, cmd);
10706 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
10707 if (res) {
10708 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
10709 cmd, res);
10710 return res;
10711 }
10712
10713 return 0;
10714}
10715
10716
10717static int ap_nfc_write_config_token(struct sigma_dut *dut,
10718 struct sigma_conn *conn,
10719 struct sigma_cmd *cmd)
10720{
10721 int res;
10722 char buf[300];
10723
10724 run_system(dut, "killall wps-ap-nfc.py");
10725 unlink("nfc-success");
10726 snprintf(buf, sizeof(buf),
10727 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
10728 dut->summary_log ? "--summary " : "",
10729 dut->summary_log ? dut->summary_log : "");
10730 res = run_nfc_command(dut, buf,
10731 "Touch NFC Tag to write WPS configuration token");
10732 if (res || !file_exists("nfc-success")) {
10733 send_resp(dut, conn, SIGMA_ERROR,
10734 "ErrorCode,Failed to write tag");
10735 return 0;
10736 }
10737
10738 return 1;
10739}
10740
10741
10742static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
10743 struct sigma_conn *conn,
10744 struct sigma_cmd *cmd)
10745{
10746 int res;
10747 char buf[300];
10748
10749 run_system(dut, "killall wps-ap-nfc.py");
10750
10751 unlink("nfc-success");
10752 snprintf(buf, sizeof(buf),
10753 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10754 dut->summary_log ? "--summary " : "",
10755 dut->summary_log ? dut->summary_log : "");
10756 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
10757 if (res || !file_exists("nfc-success")) {
10758 send_resp(dut, conn, SIGMA_ERROR,
10759 "ErrorCode,Failed to read tag");
10760 return 0;
10761 }
10762
10763 return 1;
10764}
10765
10766
10767static int ap_nfc_write_password_token(struct sigma_dut *dut,
10768 struct sigma_conn *conn,
10769 struct sigma_cmd *cmd)
10770{
10771 int res;
10772 char buf[300];
10773
10774 run_system(dut, "killall wps-ap-nfc.py");
10775 unlink("nfc-success");
10776 snprintf(buf, sizeof(buf),
10777 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
10778 dut->summary_log ? "--summary " : "",
10779 dut->summary_log ? dut->summary_log : "");
10780 res = run_nfc_command(dut, buf,
10781 "Touch NFC Tag to write WPS password token");
10782 if (res || !file_exists("nfc-success")) {
10783 send_resp(dut, conn, SIGMA_ERROR,
10784 "ErrorCode,Failed to write tag");
10785 return 0;
10786 }
10787
10788 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
10789 send_resp(dut, conn, SIGMA_ERROR,
10790 "ErrorCode,Failed to enable NFC password token");
10791 return 0;
10792 }
10793
10794 return 1;
10795}
10796
10797
10798static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
10799 struct sigma_conn *conn,
10800 struct sigma_cmd *cmd)
10801{
10802 int res;
10803 char buf[300];
10804
10805 run_system(dut, "killall wps-ap-nfc.py");
10806 unlink("nfc-success");
10807 snprintf(buf, sizeof(buf),
10808 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10809 dut->summary_log ? "--summary " : "",
10810 dut->summary_log ? dut->summary_log : "");
10811 res = run_nfc_command(dut, buf,
10812 "Touch NFC Device to respond to WPS connection handover");
10813 if (res) {
10814 send_resp(dut, conn, SIGMA_ERROR,
10815 "ErrorCode,Failed to enable NFC for connection "
10816 "handover");
10817 return 0;
10818 }
10819 if (!file_exists("nfc-success")) {
10820 send_resp(dut, conn, SIGMA_ERROR,
10821 "ErrorCode,Failed to complete NFC connection handover");
10822 return 0;
10823 }
10824
10825 return 1;
10826}
10827
10828
Jouni Malinenf7222712019-06-13 01:50:21 +030010829static enum sigma_cmd_result cmd_ap_nfc_action(struct sigma_dut *dut,
10830 struct sigma_conn *conn,
10831 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010832{
10833 /* const char *name = get_param(cmd, "Name"); */
10834 /* const char *intf = get_param(cmd, "Interface"); */
10835 const char *oper = get_param(cmd, "Operation");
10836
10837 if (oper == NULL)
10838 return -1;
10839
10840 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
10841 return ap_nfc_write_config_token(dut, conn, cmd);
10842 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
10843 return ap_nfc_write_password_token(dut, conn, cmd);
10844 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
10845 return ap_nfc_wps_read_passwd(dut, conn, cmd);
10846 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
10847 return ap_nfc_wps_connection_handover(dut, conn, cmd);
10848
10849 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
10850 return 0;
10851}
10852
10853
Jouni Malinenf7222712019-06-13 01:50:21 +030010854static enum sigma_cmd_result cmd_ap_wps_read_pin(struct sigma_dut *dut,
10855 struct sigma_conn *conn,
10856 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010857{
10858 char *pin = "12345670"; /* TODO: use random PIN */
10859 char resp[100];
10860
10861 snprintf(resp, sizeof(resp), "PIN,%s", pin);
10862 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10863
10864 return 0;
10865}
10866
10867
Jouni Malinenf7222712019-06-13 01:50:21 +030010868static enum sigma_cmd_result cmd_ap_wps_enter_pin(struct sigma_dut *dut,
10869 struct sigma_conn *conn,
10870 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010871{
10872 const char *pin = get_param(cmd, "PIN");
10873 char wps_pin[11];
10874
10875 if (!pin)
10876 return -1;
10877
10878 sigma_dut_print(dut, DUT_MSG_DEBUG,
10879 "Authorize a client to join with WPS PIN %s", pin);
10880
10881 strlcpy(wps_pin, pin, sizeof(wps_pin));
10882 /* we need to tolerate extra '-' characters entered */
10883 str_remove_chars(wps_pin, '-');
10884 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
10885 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
10886
10887 return 1;
10888}
10889
10890
Jouni Malinenf7222712019-06-13 01:50:21 +030010891static enum sigma_cmd_result cmd_ap_wps_set_pbc(struct sigma_dut *dut,
10892 struct sigma_conn *conn,
10893 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010894{
10895 sigma_dut_print(dut, DUT_MSG_DEBUG,
10896 "Selecting the push button configuration method");
10897
10898 dut->wps_method = WFA_CS_WPS_PBC;
10899
10900 return 1;
10901}
10902
10903
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020010904int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
10905 struct sigma_cmd *cmd)
10906{
10907 char buf[100], resp[256];
10908 const char *intf = get_param(cmd, "interface");
10909 const char *config_method = get_param(cmd, "WPSConfigMethod");
10910
10911 if (config_method && strcasecmp(config_method, "PBC") == 0)
10912 dut->wps_method = WFA_CS_WPS_PBC;
10913
10914 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010915 intf = get_main_ifname(dut);
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020010916
10917 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
10918 send_resp(dut, conn, SIGMA_ERROR,
10919 "ErrorCode,WPS parameters not yet set");
10920 return STATUS_SENT;
10921 }
10922
10923 if (dut->wps_method == WFA_CS_WPS_PBC)
10924 snprintf(buf, sizeof(buf), "WPS_PBC");
10925 else /* WFA_CS_WPS_PIN_KEYPAD */
10926 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
10927
10928 /* Run WPS command */
10929 if (hapd_command(intf, buf) < 0) {
10930 /* command fails immediately if overlapped session detected */
10931 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
10932 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10933 return STATUS_SENT;
10934 }
10935
10936 /* In AP mode return immediately and do not wait for WPS registration */
10937 return SUCCESS_SEND_STATUS;
10938}
10939
10940
Jouni Malinenf7222712019-06-13 01:50:21 +030010941static enum sigma_cmd_result cmd_ap_get_parameter(struct sigma_dut *dut,
10942 struct sigma_conn *conn,
10943 struct sigma_cmd *cmd)
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010944{
10945 char value[256], resp[512];
10946 const char *param = get_param(cmd, "parameter");
10947 const char *ifname = get_param(cmd, "Interface");
10948
10949 if (!ifname)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010950 ifname = get_main_ifname(dut);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010951
10952 if (!param) {
10953 send_resp(dut, conn, SIGMA_ERROR,
10954 "ErrorCode,Parameter not specified");
10955 return 0;
10956 }
10957
10958 if (strcasecmp(param, "SSID") == 0) {
10959 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
10960 sigma_dut_print(dut, DUT_MSG_ERROR,
10961 "Failed to get SSID");
10962 return -2;
10963 }
10964 snprintf(resp, sizeof(resp), "SSID,%s", value);
10965 } else if (strcasecmp(param, "PSK") == 0) {
10966 if (get_hapd_config(ifname, "passphrase", value,
10967 sizeof(value))) {
10968 sigma_dut_print(dut, DUT_MSG_ERROR,
10969 "Failed to get PSK");
10970 return -2;
10971 }
10972 snprintf(resp, sizeof(resp), "PSK,%s", value);
10973 } else {
10974 send_resp(dut, conn, SIGMA_ERROR,
10975 "ErrorCode,Unsupported parameter");
10976 return 0;
10977 }
10978
10979 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10980 return 0;
10981}
10982
10983
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010984static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
10985 const char *val)
10986{
10987 char *token, *result;
10988 int nss = 0, chwidth = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010989 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010990
10991 /*
10992 * The following commands should be invoked to generate
10993 * VHT op mode notification
10994 */
10995
10996 /* Extract the NSS info */
10997 token = strdup(val);
10998 if (!token)
10999 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011000 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011001 if (result) {
11002 int count = atoi(result);
11003
11004 /* We do not support NSS > 3 */
11005 if (count < 0 || count > 3) {
11006 free(token);
11007 return -1;
11008 }
11009
11010 /* Convert nss to chainmask */
11011 while (count--)
11012 nss = (nss << 1) | 1;
11013
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011014 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011015 }
11016
11017 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011018 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011019 if (result) {
11020 switch (atoi(result)) {
11021 case 20:
11022 chwidth = 0;
11023 break;
11024 case 40:
11025 chwidth = 1;
11026 break;
11027 case 80:
11028 chwidth = 2;
11029 break;
11030 case 160:
11031 chwidth = 3;
11032 break;
11033 default:
11034 chwidth = 2;
11035 break;
11036 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011037 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011038 }
11039
11040 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011041 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011042 free(token);
11043
11044 return 0;
11045}
11046
11047
11048static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
11049 const char *val)
11050{
11051 /* String (nss_operating_mode; mcs_operating_mode) */
11052 int nss, mcs;
11053 char *token, *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011054 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011055
11056 token = strdup(val);
11057 if (!token)
11058 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011059 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011060 if (!result) {
11061 sigma_dut_print(dut, DUT_MSG_ERROR,
11062 "VHT NSS not specified");
11063 goto end;
11064 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011065 if (strcasecmp(result, "def") != 0) {
11066 nss = atoi(result);
11067
11068 if (nss == 4)
11069 ath_disable_txbf(dut, ifname);
11070
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011071 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011072 } else {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011073 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11074 run_iwpriv(dut, ifname, "nss 1");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011075 if (dut->device_type == AP_testbed &&
11076 dut->program == PROGRAM_HE) {
11077 nss = dut->ap_tx_streams;
11078 run_iwpriv(dut, ifname, "nss %d", nss);
11079 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011080 }
11081
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011082 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011083 if (!result) {
11084 sigma_dut_print(dut, DUT_MSG_ERROR,
11085 "VHT MCS not specified");
11086 goto end;
11087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011088 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011089 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
11090 run_iwpriv(dut, ifname, "vhtmcs 7");
11091 else
11092 run_iwpriv(dut, ifname, "set11NRates 0");
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011093 if (dut->device_type == AP_testbed &&
11094 dut->program == PROGRAM_HE)
11095 run_iwpriv(dut, ifname, "he_mcs 7");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011096 } else {
11097 mcs = atoi(result);
Priyadharshini Gowthaman78ee2ef2019-11-15 16:08:28 -080011098 if (dut->program == PROGRAM_HE)
11099 run_iwpriv(dut, ifname, "he_mcs %d", mcs);
11100 else
11101 run_iwpriv(dut, ifname, "vhtmcs %d", mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011102 }
11103
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011104end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011105 free(token);
11106 return 0;
11107}
11108
11109
11110static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
11111 const char *val)
11112{
11113 char *token, *result;
11114 int channel = 36;
11115 int chwidth = 80;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011116 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011117
11118 /* Extract the channel info */
11119 token = strdup(val);
11120 if (!token)
11121 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011122 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011123 if (result)
11124 channel = atoi(result);
11125
11126 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011127 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011128 if (result)
11129 chwidth = atoi(result);
11130
11131 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011132 run_iwpriv(dut, ifname, "doth_ch_chwidth %d 10 %d", channel, chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011133
11134 free(token);
11135 return 0;
11136}
11137
11138
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011139static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
11140 const char *val)
11141{
11142 char buf[80];
11143 unsigned char mac_addr[6];
11144
11145 if (parse_mac_address(dut, val, mac_addr) < 0)
11146 return -1;
11147
11148 snprintf(buf, sizeof(buf),
11149 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
11150 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
11151 run_system(dut, buf);
11152
11153 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
11154 ifname, mac_addr[4], mac_addr[5]);
11155 run_system(dut, buf);
11156
11157 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
11158 run_system(dut, buf);
11159
11160 return 0;
11161}
11162
11163
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011164void novap_reset(struct sigma_dut *dut, const char *ifname, int reset)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011165{
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011166 run_iwpriv(dut, ifname, "novap_reset %d", reset);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011167}
11168
11169
Jouni Malinenb4335432019-06-13 02:23:57 +030011170static struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
11171 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011172{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011173 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011174
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011175 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
11176 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
11177 ETH_ALEN) == 0)
11178 return &dut->mbo_pref_aps[i];
11179 }
11180 return NULL;
11181}
11182
11183
11184static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
11185 int ap_ne_class, int ap_ne_op_ch,
11186 int ap_ne_pref)
11187{
11188 struct mbo_pref_ap *entry;
11189 uint8_t self_mac[ETH_ALEN];
11190 char ifname[50];
11191
11192 get_if_name(dut, ifname, sizeof(ifname), 1);
11193 get_hwaddr(ifname, self_mac);
11194
11195 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
11196 entry = &dut->mbo_self_ap_tuple;
11197 else
11198 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
11199
11200 if (!entry) {
11201 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
11202 sigma_dut_print(dut, DUT_MSG_ERROR,
11203 "Nebor AP List is full. Not adding");
11204 return;
11205 }
11206 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
11207 dut->mbo_pref_ap_cnt++;
11208 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
11209 entry->ap_ne_class = -1;
11210 entry->ap_ne_op_ch = -1;
11211 entry->ap_ne_pref = -1;
11212 }
11213 if (ap_ne_class != -1)
11214 entry->ap_ne_class = ap_ne_class;
11215 if (ap_ne_op_ch != -1)
11216 entry->ap_ne_op_ch = ap_ne_op_ch;
11217 if (ap_ne_pref != -1)
11218 entry->ap_ne_pref = ap_ne_pref;
11219}
11220
11221
11222static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
11223 struct sigma_cmd *cmd)
11224{
11225 unsigned char mac_addr[ETH_ALEN];
11226 const char *val;
11227 /*
11228 * -1 is invalid value for the following
11229 * to differentiate between unset and set values
11230 * -1 => implies not set by CAPI
11231 */
11232 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
11233 int list_offset = dut->mbo_pref_ap_cnt;
11234
11235 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
11236 sigma_dut_print(dut, DUT_MSG_ERROR,
11237 "AP Pref Entry list is full");
11238 return -1;
11239 }
11240
11241 val = get_param(cmd, "Nebor_Op_Class");
11242 if (val)
11243 ap_ne_class = atoi(val);
11244
11245 val = get_param(cmd, "Nebor_Op_Ch");
11246 if (val)
11247 ap_ne_op_ch = atoi(val);
11248
11249 val = get_param(cmd, "Nebor_Pref");
11250 if (val)
11251 ap_ne_pref = atoi(val);
11252
11253 val = get_param(cmd, "Nebor_BSSID");
11254 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011255 return -1;
11256
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011257 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
11258 ap_ne_pref);
11259 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011260 return 0;
11261}
11262
11263
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011264static enum sigma_cmd_result he_ltf(struct sigma_dut *dut,
11265 struct sigma_conn *conn,
11266 const char *ifname, const char *val)
11267{
11268 const char *var;
11269
11270 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11271 var = "he_ul_ltf";
11272 else
11273 var = "he_ltf";
11274
11275 if (strcmp(val, "6.4") == 0) {
11276 run_iwpriv(dut, ifname, "%s 2", var);
11277 } else if (strcmp(val, "12.8") == 0) {
11278 run_iwpriv(dut, ifname, "%s 3", var);
11279 } else if (strcmp(val, "3.2") == 0) {
11280 run_iwpriv(dut, ifname, "%s 1", var);
11281 } else {
11282 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported LTF");
11283 return STATUS_SENT_ERROR;
11284 }
11285
11286 return SUCCESS_SEND_STATUS;
11287}
11288
11289
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011290static enum sigma_cmd_result he_shortgi(struct sigma_dut *dut,
11291 struct sigma_conn *conn,
11292 const char *ifname,
11293 const char *val)
11294{
11295 const char *var;
11296
11297 if (dut->ap_he_ulofdma == VALUE_ENABLED)
11298 var = "he_ul_shortgi";
11299 else
11300 var = "shortgi";
11301
11302 if (strcmp(val, "0.8") == 0) {
11303 run_iwpriv(dut, ifname, "%s 0", var);
11304 } else if (strcmp(val, "1.6") == 0) {
11305 run_iwpriv(dut, ifname, "%s 2", var);
11306 } else if (strcmp(val, "3.2") == 0) {
11307 run_iwpriv(dut, ifname, "%s 3", var);
11308 } else {
11309 send_resp(dut, conn, SIGMA_ERROR,
11310 "errorCode,Unsupported shortGI");
11311 return STATUS_SENT_ERROR;
11312 }
11313
11314 return SUCCESS_SEND_STATUS;
11315}
11316
11317
11318static enum sigma_cmd_result he_ar_gi_ltf_mask(struct sigma_dut *dut,
11319 struct sigma_conn *conn,
11320 const char *ifname,
11321 const char *val)
11322{
11323
11324 uint32_t he_ar_gi_ltf;
11325 uint16_t he_ar_gi, he_ar_ltf;
11326
11327 if (strcmp(val, "0.4") == 0) {
11328 he_ar_gi = 0x01;
11329 } else if (strcmp(val, "0.8") == 0) {
11330 he_ar_gi = 0x02;
11331 } else if (strcmp(val, "1.6") == 0) {
11332 he_ar_gi = 0x04;
11333 } else if (strcmp(val, "3.2") == 0) {
11334 he_ar_gi = 0x08;
11335 } else {
11336 send_resp(dut, conn, SIGMA_ERROR,
11337 "errorCode,Unsupported shortGI");
11338 return STATUS_SENT_ERROR;
11339 }
11340
11341 if (dut->ar_ltf && strcmp(dut->ar_ltf, "6.4") == 0) {
11342 he_ar_ltf = 0x02;
11343 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "12.8") == 0) {
11344 he_ar_ltf = 0x04;
11345 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "3.2") == 0) {
11346 he_ar_ltf = 0x01;
11347 } else {
11348 send_resp(dut, conn, SIGMA_ERROR,
11349 "errorCode,Unsupported LTF");
11350 return STATUS_SENT_ERROR;
11351 }
11352
11353 he_ar_gi_ltf = (he_ar_gi << 8) | he_ar_ltf;
11354 run_iwpriv(dut, ifname, "he_ar_gi_ltf %lu", he_ar_gi_ltf);
11355
11356 return SUCCESS_SEND_STATUS;
11357}
11358
11359
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011360static enum sigma_cmd_result he_rualloctones(struct sigma_dut *dut,
11361 struct sigma_conn *conn,
11362 const char *ifname,
11363 const char *val)
11364{
11365 char *token, *result;
11366 int value;
11367 char *saveptr;
11368 int rualloc_type;
11369 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
11370
11371 token = strdup(val);
11372 if (!token)
11373 return -1;
11374 result = strtok_r(token, ":", &saveptr);
11375 if (!result) {
11376 free(token);
11377 send_resp(dut, conn, SIGMA_ERROR,
11378 "errorCode,RUAllocTones not specified");
11379 return STATUS_SENT_ERROR;
11380 }
11381
11382 /*
11383 * ru_allocation_type can take the values of:
11384 * 1 - DL OFDMA data RU allocation
11385 * 3 - UL OFDMA data RU allocation
11386 */
11387 rualloc_type = dut->ap_he_ulofdma == VALUE_ENABLED ? 3 : 1;
11388
11389
11390 value = atoi(result);
11391 if (value == 106) {
11392 enum value_not_set_enabled_disabled ap_he_rualloc_106_80 =
11393 VALUE_NOT_SET;
11394
11395 result = strtok_r(NULL, ":", &saveptr);
11396 if (result) {
11397 result = strtok_r(NULL, ":", &saveptr);
11398 if (result)
11399 ap_he_rualloc_106_80 = VALUE_ENABLED;
11400 else
11401 ap_he_rualloc_106_80 = VALUE_DISABLED;
11402 }
11403 if (ap_he_rualloc_106_80 == VALUE_ENABLED) {
11404 run_system_wrapper(dut,
11405 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 2 1 2 2 2 3 2",
11406 ifname, rualloc_type);
11407 } else {
11408 run_system_wrapper(dut,
11409 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 2 1 2",
11410 ifname, rualloc_type);
11411 }
11412 } else if (value == 242) {
11413 run_system_wrapper(
11414 dut,
11415 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 3 1 3 2 3 3 3",
11416 ifname, rualloc_type);
11417 } else if (value == 26) {
11418 run_system_wrapper(
11419 dut,
11420 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 0 2 0 5 0 7 0",
11421 ifname, rualloc_type);
11422 } else if (value == 52) {
11423 run_system_wrapper(
11424 dut,
11425 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 1 1 1 2 1 3 1",
11426 ifname, rualloc_type);
11427 } else if (value == 484) {
11428 run_system_wrapper(
11429 dut,
11430 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 4 1 4",
11431 ifname, rualloc_type);
11432 } else if (value == 996) {
11433 run_system_wrapper(dut,
11434 "wifitool %s setUnitTestCmd 0x4b 3 %d 0 5",
11435 ifname, rualloc_type);
11436 } else {
11437 send_resp(dut, conn, SIGMA_ERROR,
11438 "errorCode,Unsupported RUAllocTones");
11439 ret = STATUS_SENT_ERROR;
11440 }
11441
11442 free(token);
11443 return ret;
11444}
11445
11446
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070011447static void ath_set_trigger_type_0(struct sigma_dut *dut, const char *ifname)
11448{
11449 /* TriggerType "0" for Basic trigger */
11450 if (dut->ap_channel >= 36) {
11451 /* 1 and 2 here is interpreted to 5g and 2g (bitmasks) */
11452 run_system_wrapper(dut,
11453 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11454 ifname);
11455 } else {
11456 run_system_wrapper(dut,
11457 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11458 ifname);
11459 }
11460 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 6",
11461 ifname);
11462}
11463
11464
11465static void ath_set_trigger_type_1(struct sigma_dut *dut, const char *ifname)
11466{
11467 /* TriggerType "1" for MU BRP */
11468 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 1",
11469 ifname);
11470 mubrp_commands(dut, ifname);
11471}
11472
11473
11474static void ath_set_trigger_type_2(struct sigma_dut *dut, const char *ifname)
11475{
11476 /* TriggerType "2" for MU BAR */
11477 if (dut->ap_channel >= 36) {
11478 /* RU allocation RU 242 - DL OFDMA data */
11479 run_system_wrapper(dut,
11480 "wifitool %s setUnitTestCmd 0x4b 5 9 0 3 1 3 2 3 3 3",
11481 ifname);
11482 /* RU allocation RU 52 - UL BA */
11483 run_system_wrapper(dut,
11484 "wifitool %s setUnitTestCmd 0x4b 5 9 0 2 1 2 2 2 3 2",
11485 ifname);
11486 } else {
11487 /* RU allocation RU 52 - DL ofdma data */
11488 run_system_wrapper(dut,
11489 "wifitool %s setUnitTestCmd 0x4b 5 9 0 1 1 1 2 1 3 1",
11490 ifname);
11491 }
11492 /* Force TBPPDU duration to 400 us */
11493 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 400",
11494 ifname);
11495 /* 0 to enable MU BAR, 1 to enable SU BAR */
11496 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 49 0",
11497 ifname);
11498 /* MU BAR */
11499 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 64 0",
11500 ifname);
11501}
11502
11503
11504static void ath_set_trigger_type_3(struct sigma_dut *dut, const char *ifname)
11505{
11506 /* TriggerType "3" for MU RTS */
11507 /* Send MU RTS Trigger - '1' is to enable MU RTS */
11508 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 101 1",
11509 ifname);
11510}
11511
11512
11513static void ath_set_trigger_type_4(struct sigma_dut *dut, const char *ifname,
11514 const char *basedev)
11515{
11516 /* TriggerType "4" for BSRP */
11517 run_system_wrapper(dut, "cfg80211tool %s he_ul_trig_int 200", basedev);
11518 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 1000",
11519 ifname);
11520 if (dut->ap_channel >= 36) {
11521 run_system_wrapper(dut,
11522 "wifitool %s setUnitTestCmd 0x47 2 42 1",
11523 ifname);
11524 } else {
11525 run_system_wrapper(dut,
11526 "wifitool %s setUnitTestCmd 0x47 2 42 2",
11527 ifname);
11528 }
11529 /* Send BSRP command */
11530 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 7",
11531 ifname);
11532}
11533
11534
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011535static enum sigma_cmd_result ath_ap_set_rfeature(struct sigma_dut *dut,
11536 struct sigma_conn *conn,
11537 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011538{
11539 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011540 const char *ifname;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011541 enum sigma_cmd_result res;
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011542 const char *basedev = "wifi0";
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011543 int trigtype;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011544 int he_ackpolicymac = 0;
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070011545 char *num_ss = NULL;
11546 char *nss[4] = { NULL, NULL, NULL, NULL };
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070011547 char *aid[4] = { NULL, NULL, NULL, NULL };
11548 char *aid_ss = NULL;
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070011549 int omctrl_rxnss = 0, omctrl_chwidth = 0;
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070011550 int param;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011551 unsigned char mac_addr[ETH_ALEN];
11552
11553 memset(mac_addr, 0x00, ETH_ALEN);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011554
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011555 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011556
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011557 if (sigma_radio_ifname[0])
11558 basedev = sigma_radio_ifname[0];
11559
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011560 /* Disable vap reset between the commands */
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011561 novap_reset(dut, ifname, 1);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080011562
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011563 val = get_param(cmd, "Opt_md_notif_ie");
11564 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011565 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011566
11567 /* TODO: Optional arguments */
11568
11569 val = get_param(cmd, "nss_mcs_opt");
11570 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011571 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011572
11573 val = get_param(cmd, "chnum_band");
11574 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011575 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011576
11577 val = get_param(cmd, "RTS_FORCE");
11578 if (val)
11579 ath_config_rts_force(dut, ifname, val);
11580
11581 val = get_param(cmd, "DYN_BW_SGNL");
11582 if (val)
11583 ath_config_dyn_bw_sig(dut, ifname, val);
11584
11585 val = get_param(cmd, "CTS_WIDTH");
11586 if (val)
11587 ath_set_cts_width(dut, ifname, val);
11588
11589 val = get_param(cmd, "Ndpa_stainfo_mac");
11590 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011591 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011592
11593 val = get_param(cmd, "txBandwidth");
11594 if (val && ath_set_width(dut, conn, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011595 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011596
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011597 val = get_param(cmd, "Assoc_Disallow");
11598 if (val)
11599 ath_set_assoc_disallow(dut, ifname, val);
11600
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011601
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070011602 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011603 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011604 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011605 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011606 dut->ap_disassoc_timer = 1000;
11607 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070011608
11609 val = get_param(cmd, "BTMReq_Term_Bit");
11610 if (val)
11611 dut->ap_btmreq_term_bit = atoi(val);
11612
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011613 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011614 if (val) {
11615 dut->ap_assoc_delay = 1;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011616 run_iwpriv(dut, ifname, "mbo_asoc_ret %s", val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080011617 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070011618
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070011619 val = get_param(cmd, "Disassoc_Timer");
11620 if (val)
11621 dut->ap_disassoc_timer = atoi(val);
11622
11623 val = get_param(cmd, "BSS_Term_Duration");
11624 if (val)
11625 dut->ap_btmreq_bss_term_dur = atoi(val);
11626
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080011627 val = get_param(cmd, "BSS_Term_TSF");
11628 if (val)
11629 dut->ap_btmreq_bss_term_tsf = atoi(val);
11630
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011631 val = get_param(cmd, "TxPower");
11632 if (val)
11633 ath_set_txpower(dut, ifname, val);
11634
11635 val = get_param(cmd, "DownlinkAvailCap");
11636 if (val)
11637 dut->ap_dl_availcap = atoi(val);
11638
11639 val = get_param(cmd, "UplinkAvailCap");
11640 if (val) {
11641 dut->ap_ul_availcap = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011642 run_iwpriv(dut, ifname, "oce_wan_mtr %d %d",
11643 dut->ap_dl_availcap, dut->ap_ul_availcap);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011644 }
11645
11646 val = get_param(cmd, "RSSIthreshold");
11647 if (val) {
11648 int rssithreshold;
11649
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011650 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011651 rssithreshold = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011652 run_iwpriv(dut, ifname, "oce_asoc_rssi %d", rssithreshold);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011653 }
11654
11655 val = get_param(cmd, "RetryDelay");
11656 if (val) {
11657 int retrydelay;
11658
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011659 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011660 retrydelay = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011661 run_iwpriv(dut, ifname, "oce_asoc_dly %d", retrydelay);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011662 }
11663
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011664 val = get_param(cmd, "LTF");
11665 if (val) {
11666 if (dut->ap_fixed_rate) {
11667 res = he_ltf(dut, conn, ifname, val);
11668 if (res != SUCCESS_SEND_STATUS)
11669 return res;
11670 } else {
11671 free(dut->ar_ltf);
11672 dut->ar_ltf = strdup(val);
11673 if (!dut->ar_ltf)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011674 return ERROR_SEND_STATUS;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011675 }
11676 }
11677
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011678 val = get_param(cmd, "GI");
11679 if (val) {
11680 if (dut->ap_fixed_rate)
11681 res = he_shortgi(dut, conn, ifname, val);
11682 else
11683 res = he_ar_gi_ltf_mask(dut, conn, ifname, val);
11684 if (res != SUCCESS_SEND_STATUS)
11685 return res;
11686 }
11687
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011688 val = get_param(cmd, "RUAllocTones");
11689 if (val) {
11690 res = he_rualloctones(dut, conn, ifname, val);
11691 if (res != SUCCESS_SEND_STATUS)
11692 return res;
11693 }
11694
Priyadharshini Gowthaman803fd662019-07-31 14:37:49 -070011695 val = get_param(cmd, "MPDU_MU_SpacingFactor");
11696 if (val)
11697 run_system_wrapper(dut,
11698 "wifitool %s setUnitTestCmd 0x48 2 119, %s",
11699 ifname, val);
11700
11701 val = get_param(cmd, "PPDUTxType");
11702 if (val) {
11703 if (strcasecmp(val, "HE-SU") == 0) {
11704 /* Change PPDU format type to HE-SU MCS 1 */
11705 run_system_wrapper(dut,
11706 "wifitool %s setUnitTestCmd 0x48 2 89 0x401",
11707 ifname);
11708 } else if (strcasecmp(val, "legacy") == 0) {
11709 /* Change PPDU format type to non-HT */
11710 run_system_wrapper(dut,
11711 "wifitool %s setUnitTestCmd 0x48 2 89 3",
11712 ifname);
11713 } else {
11714 send_resp(dut, conn, SIGMA_ERROR,
11715 "errorCode,Unsupported PPDUTxType");
11716 return STATUS_SENT_ERROR;
11717 }
11718 }
11719
11720 val = get_param(cmd, "TXOPDuration");
11721 if (val) {
11722 if (strcasecmp(val, "UNSPECIFIED") == 0) {
11723 /* The hardware is hardcoded with 0x7f; do nothing */
11724 } else {
11725 send_resp(dut, conn, SIGMA_ERROR,
11726 "errorCode,Unsupported TXOPDuration");
11727 return STATUS_SENT_ERROR;
11728 }
11729 }
11730
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011731 val = get_param(cmd, "Trig_Usrinfo_UL-MCS");
11732 if (val)
11733 run_iwpriv(dut, ifname, "he_ul_mcs %d", atoi(val));
11734
11735 val = get_param(cmd, "Trig_Usrinfo_UL-Target-RSSI");
11736 if (val) {
11737 /* Set target RSSI to -55 dBm */
11738 run_system_wrapper(dut,
11739 "wifitool %s setUnitTestCmd 0x4b 2 7 %d",
11740 ifname, atoi(val) - 110);
11741 }
11742
11743 val = get_param(cmd, "Trig_Interval");
11744 if (val)
11745 run_iwpriv(dut, basedev, "he_ul_trig_int %d", atoi(val));
11746
11747 val = get_param(cmd, "Trig_ComInfo_ULLength");
11748 if (val)
11749 run_system_wrapper(dut,
11750 "wifitool %s setUnitTestCmd 0x48 2 141 %d",
11751 ifname, atoi(val));
11752
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011753 val = get_param(cmd, "DisableTriggerType");
11754 if (val) {
11755 trigtype = atoi(val);
11756 switch (trigtype) {
11757 case 0:
11758 /* DisableTriggerType "0" for basic trigger */
11759 run_system_wrapper(dut,
11760 "wifitool %s setUnitTestCmd 0x47 2 42 0",
11761 ifname);
11762 break;
11763 default:
11764 /* Nothing to be done for now */
11765 break;
11766 }
11767 }
11768
11769 val = get_param(cmd, "Trigger_TxBF");
11770 if (val) {
11771 if (strcasecmp(val, "enable") == 0) {
11772 run_iwpriv(dut, ifname, "he_sounding_mode 0x9");
11773 } else if (strcasecmp(val, "disable") == 0) {
11774 run_iwpriv(dut, ifname, "he_sounding_mode 0x1");
11775 } else {
11776 send_resp(dut, conn, SIGMA_ERROR,
11777 "errorCode,Unsupported trigger_txbf");
11778 return STATUS_SENT_ERROR;
11779 }
11780 }
11781
Priyadharshini Gowthaman7b94f082019-07-31 14:38:25 -070011782 val = get_param(cmd, "Trig_UsrInfo_RUAlloc");
11783 if (val) {
11784 res = he_rualloctones(dut, conn, ifname, val);
11785 if (res != SUCCESS_SEND_STATUS)
11786 return res;
11787 }
11788
Priyadharshini Gowthaman8701fac2019-07-31 14:38:48 -070011789 val = get_param(cmd, "TriggerCoding");
11790 if (val) {
11791 if (strcasecmp(val, "BCC") == 0) {
11792 /* In case of LDPC enable this command can force BCC if
11793 * RU size <= 242 */
11794 run_iwpriv(dut, ifname, "he_ul_ldpc 0");
11795 } else if (strcasecmp(val, "LDPC") == 0) {
11796 novap_reset(dut, ifname, 0);
11797 run_iwpriv(dut, ifname, "he_ul_ldpc 1");
11798 novap_reset(dut, ifname, 1);
11799 } else {
11800 send_resp(dut, conn, SIGMA_ERROR,
11801 "errorCode,Unsupported TriggerCoding");
11802 return STATUS_SENT_ERROR;
11803 }
11804 }
11805
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011806 val = get_param(cmd, "AckPolicy_MAC");
11807 if (val) {
11808 if (parse_mac_address(dut, val, mac_addr) < 0) {
11809 send_resp(dut, conn, SIGMA_ERROR,
11810 "errorCode,MAC Address not in proper format");
11811 return STATUS_SENT_ERROR;
11812 }
11813 he_ackpolicymac = 1;
11814 }
11815
11816 val = get_param(cmd, "AckPolicy");
11817 if (val) {
11818 int ap_he_ackpolicy;
11819
11820 ap_he_ackpolicy = atoi(val);
11821 if (ap_he_ackpolicy == 0 && he_ackpolicymac) {
11822 /* Disable all-BAR ackpolicy for MU-MIMO */
11823 run_system_wrapper(dut,
11824 "wifitool %s setUnitTestCmd 0x48 2 62 0",
11825 ifname);
11826 /* Disable all-BAR ackpolicy first */
11827 run_system_wrapper(dut,
11828 "wifitool %s setUnitTestCmd 0x48 2 64 0",
11829 ifname);
11830 /* Set normal ack policy for the STA with the specified
11831 * MAC address in DL-TX case */
11832 run_system_wrapper(dut,
11833 "wifitool %s setUnitTestCmd 0x4b 8 8 1 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
11834 ifname, mac_addr[0], mac_addr[1],
11835 mac_addr[2], mac_addr[3],
11836 mac_addr[4], mac_addr[5]);
11837 } else if (ap_he_ackpolicy == 3) {
11838 /* Enable all-BAR ackpolicy for MU-MIMO DL */
11839 run_system_wrapper(dut,
11840 "wifitool %s setUnitTestCmd 0x48 2 62 1",
11841 ifname);
11842 /* Enable all-BAR ackpolicy */
11843 run_system_wrapper(dut,
11844 "wifitool %s setUnitTestCmd 0x48 2 64 1",
11845 ifname);
11846 } else if (ap_he_ackpolicy == 4) {
11847 /* Enable htp-ack ackpolicy */
11848 run_system_wrapper(dut,
11849 "wifitool %s setUnitTestCmd 0x47 2 99 1",
11850 ifname);
11851 } else {
11852 send_resp(dut, conn, SIGMA_ERROR,
11853 "errorCode,Invalid AckPolicy setting");
11854 return STATUS_SENT_ERROR;
11855 }
11856 }
11857
Priyadharshini Gowthamanc9a88c72019-08-09 12:04:17 -070011858 val = get_param(cmd, "Trig_ComInfo_GI-LTF");
11859 if (val) {
11860 int trig_gi_ltf;
11861
11862 trig_gi_ltf = atoi(val);
11863 if (trig_gi_ltf == 0) {
11864 he_ltf(dut, conn, ifname, "3.2");
11865 he_shortgi(dut, conn, ifname, "1.6");
11866 } else if (trig_gi_ltf == 1) {
11867 he_ltf(dut, conn, ifname, "6.4");
11868 he_shortgi(dut, conn, ifname, "1.6");
11869 } else if (trig_gi_ltf == 2) {
11870 he_ltf(dut, conn, ifname, "12.8");
11871 he_shortgi(dut, conn, ifname, "3.2");
11872 } else {
11873 send_resp(dut, conn, SIGMA_ERROR,
11874 "errorCode,Unsupported Trig_ComInfo_GI-LTF");
11875 return STATUS_SENT_ERROR;
11876 }
11877 }
11878
11879 val = get_param(cmd, "Trig_ComInfo_BW");
11880 if (val) {
11881 int chwidth;
11882
11883 chwidth = atoi(val);
11884 /* Set the channel width */
11885 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
11886 }
11887
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070011888 val = get_param(cmd, "NumSS");
11889 if (val) {
11890 int i = 0;
11891 char *numss_val;
11892 char *saveptr;
11893
11894 num_ss = strdup(val);
11895 if (!num_ss)
11896 return ERROR_SEND_STATUS;
11897
11898 numss_val = strtok_r(num_ss, " ", &saveptr);
11899 for (i = 0; numss_val && i < 4; i++) {
11900 nss[i] = numss_val;
11901 numss_val = strtok_r(NULL, " ", &saveptr);
11902 }
11903 }
11904
11905 val = get_param(cmd, "NumSS_MAC");
11906 if (val) {
11907 char *sta_mac_str;
11908 char *saveptr;
11909 char *sta_mac_list_str;
11910
11911 sta_mac_list_str = strdup(val);
11912 if (!sta_mac_list_str) {
11913 free(num_ss);
11914 return ERROR_SEND_STATUS;
11915 }
11916
11917 sta_mac_str = strtok_r(sta_mac_list_str, " ", &saveptr);
11918 if (sta_mac_str && nss[0]) {
11919 run_system_wrapper(dut,
11920 "wifitool %s chmask_persta %s %s",
11921 ifname, sta_mac_str, nss[0]);
11922 }
11923
11924 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11925 if (sta_mac_str && nss[1]) {
11926 run_system_wrapper(dut,
11927 "wifitool %s chmask_persta %s %s",
11928 ifname, sta_mac_str, nss[1]);
11929 }
11930
11931 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11932 if (sta_mac_str && nss[2]) {
11933 run_system_wrapper(dut,
11934 "wifitool %s chmask_persta %s %s",
11935 ifname, sta_mac_str, nss[2]);
11936 }
11937
11938 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11939 if (sta_mac_str && nss[3]) {
11940 run_system_wrapper(dut,
11941 "wifitool %s chmask_persta %s %s",
11942 ifname, sta_mac_str, nss[3]);
11943 }
11944
11945 free(sta_mac_list_str);
11946 }
11947
11948 free(num_ss);
11949 num_ss = NULL;
11950
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070011951 val = get_param(cmd, "AID");
11952 if (val) {
11953 int i = 0;
11954 char *aid_val;
11955 char *saveptr;
11956
11957 aid_ss = strdup(val);
11958 if (!aid_ss)
11959 return ERROR_SEND_STATUS;
11960
11961 aid_val = strtok_r(aid_ss, " ", &saveptr);
11962 for (i = 0; aid_val && i < 4; i++) {
11963 aid[i] = aid_val;
11964 aid_val = strtok_r(NULL, " ", &saveptr);
11965 }
11966 }
11967
11968 val = get_param(cmd, "AddbaReq");
11969 if (val) {
11970 if (strcasecmp(val, "enable") == 0) {
11971 run_iwpriv(dut, ifname, "setaddbaoper 1");
11972 run_system_wrapper(dut,
11973 "wifitool %s sendaddba %s 0 64",
11974 ifname, aid[0]);
11975 } else {
11976 send_resp(dut, conn, SIGMA_ERROR,
11977 "errorCode,Unsupported AddbaReq value");
11978 free(aid_ss);
11979 return STATUS_SENT_ERROR;
11980 }
11981 }
11982
11983 val = get_param(cmd, "AddbaResp");
11984 if (val) {
11985 if (aid_ss && strcasecmp(val, "accepted") == 0) {
11986 int aid_1 = atoi(aid_ss);
11987
11988 if (aid_1 == 1)
11989 aid_1 = 2;
11990 else
11991 aid_1 = aid_1 - 1;
11992
11993 /* There is no mechanism in place to reject Add BA Req
11994 * from all STAs and selectively accept Add BA Req from
11995 * a specified STA. Instead, it can accept Add BA Req
11996 * from all STAs and selectively reject from specified
11997 * STAs. Make changes for the same using the below
11998 * commands. */
11999 run_system_wrapper(dut, ifname, "setaddbaoper 1");
12000 run_system_wrapper(dut, "wifitool %s refusealladdbas 0",
12001 ifname);
12002 run_system_wrapper(dut,
12003 "wifitool %s setaddbaresp %d 0 37",
12004 ifname, aid_1);
12005 } else {
12006 send_resp(dut, conn, SIGMA_ERROR,
12007 "errorCode,Unsupported Addbaresp value");
12008 free(aid_ss);
12009 return STATUS_SENT_ERROR;
12010 }
12011 }
12012
12013 val = get_param(cmd, "Trig_UsrInfo_SSAlloc_RA-RU");
12014 if (val) {
12015 char *ssalloc_str;
12016 char *saveptr;
12017 char *ssalloc_list_str;
12018
12019 ssalloc_list_str = strdup(val);
12020 if (!ssalloc_list_str) {
12021 free(aid_ss);
12022 return ERROR_SEND_STATUS;
12023 }
12024
12025 ssalloc_str = strtok_r(ssalloc_list_str, ":", &saveptr);
12026 if (ssalloc_str && aid[0]) {
12027 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12028 ifname, aid[0], ssalloc_str);
12029 }
12030
12031 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12032 if (ssalloc_str && aid[1]) {
12033 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12034 ifname, aid[1], ssalloc_str);
12035 }
12036
12037 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12038 if (ssalloc_str && aid[2]) {
12039 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12040 ifname, aid[2], ssalloc_str);
12041 }
12042
12043 ssalloc_str = strtok_r(NULL, " ", &saveptr);
12044 if (ssalloc_str && aid[3]) {
12045 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
12046 ifname, aid[3], ssalloc_str);
12047 }
12048
12049 free(ssalloc_list_str);
12050 }
12051
12052 free(aid_ss);
12053 aid_ss = NULL;
12054
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070012055 val = get_param(cmd, "OMCtrl_RxNSS");
12056 if (val)
12057 omctrl_rxnss = atoi(val);
12058
12059 val = get_param(cmd, "OMCtrl_ChnlWidth");
12060 if (val)
12061 omctrl_chwidth = atoi(val);
12062
12063 val = get_param(cmd, "Client_mac");
12064 if (val) {
12065 if (parse_mac_address(dut, val, mac_addr) < 0) {
12066 send_resp(dut, conn, SIGMA_ERROR,
12067 "errorCode,MAC Address not in proper format");
12068 return STATUS_SENT_ERROR;
12069 }
12070
12071 /* setUnitTestCmd 13 7 1 mac3mac2mac1mac0 mac5mac4 <rx_nss>
12072 * <bw> <ulmu> <tx_nss> */
12073 run_system_wrapper(dut,
12074 "wifitool %s setUnitTestCmd 13 7 1 0x%02x%02x%02x%02x 0x%02x%02x %d %d 1 %d",
12075 ifname, mac_addr[3], mac_addr[2],
12076 mac_addr[1], mac_addr[0], mac_addr[5],
12077 mac_addr[4], omctrl_rxnss,
12078 omctrl_chwidth, omctrl_rxnss);
12079 }
12080
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070012081 val = get_param(cmd, "TriggerType");
12082 if (val) {
12083 trigtype = atoi(val);
12084 switch (trigtype) {
12085 case 0:
12086 ath_set_trigger_type_0(dut, ifname);
12087 break;
12088 case 1:
12089 ath_set_trigger_type_1(dut, ifname);
12090 break;
12091 case 2:
12092 ath_set_trigger_type_2(dut, ifname);
12093 break;
12094 case 3:
12095 ath_set_trigger_type_3(dut, ifname);
12096 break;
12097 case 4:
12098 ath_set_trigger_type_4(dut, ifname, basedev);
12099 break;
12100 default:
12101 send_resp(dut, conn, SIGMA_ERROR,
12102 "errorCode,TriggerType not supported");
12103 return STATUS_SENT_ERROR;
12104 }
12105 }
12106
Priyadharshini Gowthamanc352d822019-08-09 12:05:16 -070012107 val = get_param(cmd, "HE_TXOPDurRTSThr");
12108 if (val)
12109 run_iwpriv(dut, ifname, "he_rtsthrshld %d", atoi(val));
12110
12111 val = get_param(cmd, "NAV_Update");
12112 if (val) {
12113 if (strcasecmp(val, "disable") == 0) {
12114 run_iwpriv(dut, basedev, "nav_config 1 0");
12115 } else if (strcasecmp(val, "enable") == 0) {
12116 /* Do nothing */
12117 } else {
12118 send_resp(dut, conn, SIGMA_ERROR,
12119 "errorCode,Unsupported NAV update");
12120 return STATUS_SENT_ERROR;
12121 }
12122 }
12123
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070012124 /* Configure WMM Parameter Elements */
12125 val = get_param(cmd, "STA_WMMPE_ECWmin_BE");
12126 if (val) {
12127 param = atoi(val);
12128 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BE, param);
12129 }
12130
12131 val = get_param(cmd, "STA_WMMPE_ECWmin_BK");
12132 if (val) {
12133 param = atoi(val);
12134 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BK, param);
12135 }
12136
12137 val = get_param(cmd, "STA_WMMPE_ECWmin_VI");
12138 if (val) {
12139 param = atoi(val);
12140 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VI, param);
12141 }
12142
12143 val = get_param(cmd, "STA_WMMPE_ECWmin_VO");
12144 if (val) {
12145 param = atoi(val);
12146 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VO, param);
12147 }
12148
12149 val = get_param(cmd, "STA_WMMPE_ECWmax_BE");
12150 if (val) {
12151 param = atoi(val);
12152 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BE, param);
12153 }
12154
12155 val = get_param(cmd, "STA_WMMPE_ECWmax_BK");
12156 if (val) {
12157 param = atoi(val);
12158 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BK, param);
12159 }
12160
12161 val = get_param(cmd, "STA_WMMPE_ECWmax_VI");
12162 if (val) {
12163 param = atoi(val);
12164 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VI, param);
12165 }
12166
12167 val = get_param(cmd, "STA_WMMPE_ECWmax_VO");
12168 if (val) {
12169 param = atoi(val);
12170 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VO, param);
12171 }
12172
12173 val = get_param(cmd, "STA_WMMPE_AIFSN_BE");
12174 if (val) {
12175 param = atoi(val);
12176 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BE, param);
12177 }
12178
12179 val = get_param(cmd, "STA_WMMPE_AIFSN_BK");
12180 if (val) {
12181 param = atoi(val);
12182 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BK, param);
12183 }
12184
12185 val = get_param(cmd, "STA_WMMPE_AIFSN_VI");
12186 if (val) {
12187 param = atoi(val);
12188 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VI, param);
12189 }
12190
12191 val = get_param(cmd, "STA_WMMPE_AIFSN_VO");
12192 if (val) {
12193 param = atoi(val);
12194 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VO, param);
12195 }
12196
12197
12198 val = get_param(cmd, "STA_WMMPE_TXOP_BE");
12199 if (val) {
12200 param = atoi(val);
12201 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BE, param);
12202 }
12203
12204 val = get_param(cmd, "STA_WMMPE_TOXP_BK");
12205 if (val) {
12206 param = atoi(val);
12207 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BK, param);
12208 }
12209
12210 val = get_param(cmd, "STA_WMMPE_TXOP_VI");
12211 if (val) {
12212 param = atoi(val);
12213 run_iwpriv(dut, ifname, "txoplimit %d %d", AP_AC_VI, param);
12214 }
12215
12216 val = get_param(cmd, "STA_WMMPE_TXOP_VO");
12217 if (val) {
12218 param = atoi(val);
12219 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_VO, param);
12220 }
12221
Priyadharshini Gowthamanc46b7e42019-08-09 12:05:37 -070012222 /* Configure MU EDCA */
12223 val = get_param(cmd, "STA_MUEDCA_ECWmin_BE");
12224 if (val) {
12225 param = atoi(val);
12226 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BE, param);
12227 }
12228
12229 val = get_param(cmd, "STA_MUEDCA_ECWmin_BK");
12230 if (val) {
12231 param = atoi(val);
12232 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BK, param);
12233 }
12234
12235 val = get_param(cmd, "STA_MUEDCA_ECWmin_VI");
12236 if (val) {
12237 param = atoi(val);
12238 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VI, param);
12239 }
12240
12241 val = get_param(cmd, "STA_MUEDCA_ECWmin_VO");
12242 if (val) {
12243 param = atoi(val);
12244 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VO, param);
12245 }
12246
12247 val = get_param(cmd, "STA_MUEDCA_ECWmax_BE");
12248 if (val) {
12249 param = atoi(val);
12250 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BE, param);
12251 }
12252
12253 val = get_param(cmd, "STA_MUEDCA_ECWmax_BK");
12254 if (val) {
12255 param = atoi(val);
12256 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BK, param);
12257 }
12258
12259 val = get_param(cmd, "STA_MUEDCA_ECWmax_VI");
12260 if (val) {
12261 param = atoi(val);
12262 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VI, param);
12263 }
12264
12265 val = get_param(cmd, "STA_MUEDCA_ECWmax_VO");
12266 if (val) {
12267 param = atoi(val);
12268 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VO, param);
12269 }
12270
12271 val = get_param(cmd, "STA_MUEDCA_AIFSN_BE");
12272 if (val) {
12273 param = atoi(val);
12274 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BE, param);
12275 }
12276
12277 val = get_param(cmd, "STA_MUEDCA_AIFSN_BK");
12278 if (val) {
12279 param = atoi(val);
12280 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BK, param);
12281 }
12282
12283 val = get_param(cmd, "STA_MUEDCA_AIFSN_VI");
12284 if (val) {
12285 param = atoi(val);
12286 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VI, param);
12287 }
12288
12289 val = get_param(cmd, "STA_MUEDCA_AIFSN_VO");
12290 if (val) {
12291 param = atoi(val);
12292 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VO, param);
12293 }
12294
12295 val = get_param(cmd, "STA_MUEDCA_Timer_BE");
12296 if (val) {
12297 param = atoi(val);
12298 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BE, param);
12299 }
12300
12301 val = get_param(cmd, "STA_MUEDCA_Timer_BK");
12302 if (val) {
12303 param = atoi(val);
12304 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BK, param);
12305 }
12306
12307 val = get_param(cmd, "STA_MUEDCA_Timer_VI");
12308 if (val) {
12309 param = atoi(val);
12310 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VI, param);
12311 }
12312
12313 val = get_param(cmd, "STA_MUEDCA_Timer_VO");
12314 if (val) {
12315 param = atoi(val);
12316 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VO, param);
12317 }
12318
Jouni Malinen6076ffc2019-08-08 18:18:02 +030012319 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012320}
12321
12322
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012323static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12324 const char *val)
12325{
12326 char *token, *result;
12327 int channel = 36;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012328 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012329
12330 /* Extract the channel info */
12331 token = strdup(val);
12332 if (!token)
12333 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053012334 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012335 if (result)
12336 channel = atoi(result);
12337
12338 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070012339 run_iwpriv(dut, ifname, "setChanChange %d", channel);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012340
12341 free(token);
12342 return 0;
12343}
12344
12345
12346static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
12347 struct sigma_cmd *cmd)
12348{
12349 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012350 const char *ifname;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012351
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012352 ifname = get_main_ifname(dut);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012353
12354 val = get_param(cmd, "chnum_band");
12355 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
12356 return -1;
12357
12358 return 1;
12359}
12360
12361
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012362static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
12363 const char *val)
12364{
12365 char *token, *result;
12366 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
12367 channel_freq;
12368 char buf[100];
12369 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012370 int res;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012371
12372 /* Extract the channel info */
12373 token = strdup(val);
12374 if (!token)
12375 return -1;
12376 result = strtok_r(token, ";", &saveptr);
12377 if (result)
12378 channel = atoi(result);
12379
12380 /* Extract the channel width info */
12381 result = strtok_r(NULL, ";", &saveptr);
12382 if (result)
12383 chwidth = atoi(result);
12384
12385 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
12386 if (center_freq_idx < 0) {
12387 free(token);
12388 return -1;
12389 }
12390
12391 center_freq = get_5g_channel_freq(center_freq_idx);
12392 channel_freq = get_5g_channel_freq(channel);
12393
12394 /* Issue the channel switch command */
Jouni Malinen3aa72862019-05-29 23:14:51 +030012395 res = snprintf(buf, sizeof(buf),
12396 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
12397 ifname, channel_freq, center_freq, chwidth);
12398 if (res < 0 || res >= sizeof(buf) || run_hostapd_cli(dut, buf) != 0) {
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012399 sigma_dut_print(dut, DUT_MSG_ERROR,
12400 "hostapd_cli chan_switch failed");
12401 }
12402
12403 free(token);
12404 return 0;
12405}
12406
12407
12408static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
12409 struct sigma_conn *conn,
12410 struct sigma_cmd *cmd)
12411{
12412 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012413 const char *ifname;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012414
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012415 ifname = get_main_ifname(dut);
Tamizh chelvam638fb472019-08-15 14:00:31 +053012416
12417 val = get_param(cmd, "RTS_FORCE");
12418 if (val)
12419 mac80211_config_rts_force(dut, ifname, val);
12420
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012421 val = get_param(cmd, "chnum_band");
12422 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
12423 return -1;
12424
12425 return 1;
12426}
12427
12428
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012429#ifdef __linux__
12430static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
12431 struct sigma_conn *conn,
12432 struct sigma_cmd *cmd)
12433{
12434 const char *val;
12435
12436 val = get_param(cmd, "ExtSchIE");
12437 if (val && !strcasecmp(val, "Enable")) {
12438 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12439 int count = MAX_ESE_ALLOCS;
12440
12441 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12442 return -1;
12443 if (wil6210_set_ese(dut, count, allocs))
12444 return -1;
12445 return 1;
12446 }
12447
12448 send_resp(dut, conn, SIGMA_ERROR,
12449 "errorCode,Invalid ap_set_rfeature(60G)");
12450 return 0;
12451}
12452#endif /* __linux__ */
12453
12454
Jouni Malinenf7222712019-06-13 01:50:21 +030012455static enum sigma_cmd_result cmd_ap_set_rfeature(struct sigma_dut *dut,
12456 struct sigma_conn *conn,
12457 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012458{
12459 /* const char *name = get_param(cmd, "NAME"); */
12460 /* const char *type = get_param(cmd, "Type"); */
12461
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012462 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012463 case DRIVER_ATHEROS:
12464 return ath_ap_set_rfeature(dut, conn, cmd);
12465 case DRIVER_OPENWRT:
12466 switch (get_openwrt_driver_type()) {
12467 case OPENWRT_DRIVER_ATHEROS:
12468 return ath_ap_set_rfeature(dut, conn, cmd);
12469 default:
12470 send_resp(dut, conn, SIGMA_ERROR,
12471 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
12472 return 0;
12473 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053012474 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053012475 case DRIVER_WCN:
12476 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053012477 case DRIVER_MAC80211:
12478 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012479#ifdef __linux__
12480 case DRIVER_WIL6210:
12481 return wil6210_ap_set_rfeature(dut, conn, cmd);
12482#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012483 default:
12484 send_resp(dut, conn, SIGMA_ERROR,
12485 "errorCode,Unsupported ap_set_rfeature with the current driver");
12486 return 0;
12487 }
12488}
12489
12490
Jouni Malinenf7222712019-06-13 01:50:21 +030012491static enum sigma_cmd_result cmd_accesspoint(struct sigma_dut *dut,
12492 struct sigma_conn *conn,
12493 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012494{
12495 /* const char *name = get_param(cmd, "NAME"); */
12496 return 1;
12497}
12498
12499
Jouni Malinenf7222712019-06-13 01:50:21 +030012500static enum sigma_cmd_result
12501cmd_ap_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
12502 struct sigma_cmd *cmd)
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012503{
12504 const char *val;
12505
12506 val = get_param(cmd, "Oper_Chn");
12507 if (val) {
12508 dut->ap_oper_chn = 1;
12509 dut->ap_channel = atoi(val);
12510 }
12511
Jouni Malinenba4f2d42019-10-04 16:13:41 +030012512 val = get_param(cmd, "DPPConfiguratorAddress");
12513 if (val) {
12514 free(dut->ap_dpp_conf_addr);
12515 dut->ap_dpp_conf_addr = strdup(val);
12516 }
12517
12518 val = get_param(cmd, "DPPConfiguratorPKHash");
12519 if (val) {
12520 free(dut->ap_dpp_conf_pkhash);
12521 dut->ap_dpp_conf_pkhash = strdup(val);
12522 }
12523
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012524 return 1;
12525}
12526
12527
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012528void ap_register_cmds(void)
12529{
12530 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
12531 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
12532 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
12533 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
12534 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
12535 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053012536 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012537 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
12538 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
12539 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
12540 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
12541 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
12542 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
12543 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
12544 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
12545 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
12546 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
12547 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
12548 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
12549 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
12550 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
12551 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
12552 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020012553 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
12554 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020012555 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012556 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080012557 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
12558 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012559}