blob: 196bbff5e035ddbdc67a9fb7c4bb110790770ecf [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinen13701222019-02-19 12:10:53 +02005 * Copyright (c) 2018-2019, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/stat.h>
12#include <sys/wait.h>
13#include <sys/utsname.h>
14#include <sys/ioctl.h>
15#ifdef __linux__
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070016#include <limits.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020017#include <dirent.h>
18#include <string.h>
19#include <sys/types.h>
20#include <unistd.h>
21#endif /* __linux__ */
22#ifdef __QNXNTO__
23#include <ifaddrs.h>
24#include <net/if_dl.h>
25#endif /* __QNXNTO__ */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +020026#include "wpa_ctrl.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020027#include "wpa_helpers.h"
28#ifdef ANDROID
29#include <hardware_legacy/wifi.h>
Veerendranath Jakkamd7e00082018-04-25 19:46:01 +053030#include <grp.h>
31#include <pwd.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020032#endif /* ANDROID */
33
34/* Temporary files for ap_send_addba_req */
35#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
36#define VI_QOS_FILE "/tmp/vi-qos.txt"
37#define VI_QOS_REFFILE "/etc/vi-qos.txt"
38
39/* Configuration file name on Android */
40#ifndef ANDROID_CONFIG_FILE
41#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
42#endif /* ANDROID_CONFIG_FILE */
43/* Maximum length of the line in the configuration file */
44#define MAX_CONF_LINE_LEN (156)
45
Jouni Malinend6bf1b42017-06-23 17:51:01 +030046#ifndef SIGMA_DUT_HOSTAPD_PID_FILE
47#define SIGMA_DUT_HOSTAPD_PID_FILE "/tmp/sigma_dut-ap-hostapd.pid"
48#endif /* SIGMA_DUT_HOSTAPD_PID_FILE */
49
Jouni Malinencd4e3c32015-10-29 12:39:56 +020050/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
51#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
52#define ANQP_VENUE_NAME_1_CHI "P\"\x63\x68\x69\x3a\x57\x69\x2d\x46\x69\xe8\x81\x94\xe7\x9b\x9f\xe5\xae\x9e\xe9\xaa\x8c\xe5\xae\xa4\\n\xe4\xba\x8c\xe4\xb9\x9d\xe5\x85\xab\xe4\xb9\x9d\xe5\xb9\xb4\xe5\xba\x93\xe6\x9f\x8f\xe8\xb7\xaf\\n\xe5\x9c\xa3\xe5\x85\x8b\xe6\x8b\x89\xe6\x8b\x89\x2c\x20\xe5\x8a\xa0\xe5\x88\xa9\xe7\xa6\x8f\xe5\xb0\xbc\xe4\xba\x9a\x39\x35\x30\x35\x31\x2c\x20\xe7\xbe\x8e\xe5\x9b\xbd\""
53#define ANQP_IP_ADDR_TYPE_1 "060101000c"
54#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
55#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
56#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
57#define QOS_MAP_SET_1 "53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255"
58#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
59
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030060#define ADV_OF_CHARGE_1 \
Jouni Malinen3001b432018-05-03 18:18:15 +030061"bc01000000d200454e475553443c3f786d6c2076657273696f6e3d22312e30222065" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030062"6e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f77" \
63"77772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f" \
64"74302f76312e302f616f637069223e3c4465736372697074696f6e3e57692d46692061636365" \
65"737320666f72203120686f75722c207768696c6520796f752077616974206174207468652067" \
Jouni Malinen3001b432018-05-03 18:18:15 +030066"6174652c2024302e39393c2f4465736372697074696f6e3e3c2f506c616e3ee3004652414341" \
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030067"443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d225554462d38223f" \
68"3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f72672f737065" \
69"63696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f637069223e3c" \
Jouni Malinen3001b432018-05-03 18:18:15 +030070"4465736372697074696f6e3e416363c3a8732057692d46692070656e64616e74203120686575" \
71"72652c2070656e64616e742071756520766f757320617474656e64657a20c3a0206c6120706f" \
72"7274652c20302c393920243c2f4465736372697074696f6e3e3c2f506c616e3ea101010000c7" \
73"00454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64696e673d2255" \
74"54462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77692d66692e6f" \
75"72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76312e302f616f" \
76"637069223e3c4465736372697074696f6e3e446f776e6c6f616420766964656f7320666f7220" \
77"796f757220666c696768742c2024322e393920666f7220313047423c2f446573637269707469" \
78"6f6e3e3c2f506c616e3ed3004652414341443c3f786d6c2076657273696f6e3d22312e302220" \
79"656e636f64696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f" \
80"7777772e77692d66692e6f72672f73706563696669636174696f6e732f686f7473706f743264" \
81"6f74302f76312e302f616f637069223e3c4465736372697074696f6e3e54c3a96cc3a9636861" \
82"7267657a2064657320766964c3a96f7320706f757220766f74726520766f6c2c20322c393920" \
83"2420706f757220313020476f3c2f4465736372697074696f6e3e3c2f506c616e3ee40003002b" \
84"736572766963652d70726f76696465722e636f6d3b66656465726174696f6e2e6578616d706c" \
85"652e636f6db400454e475553443c3f786d6c2076657273696f6e3d22312e302220656e636f64" \
86"696e673d225554462d38223f3e3c506c616e20786d6c6e733d22687474703a2f2f7777772e77" \
87"692d66692e6f72672f73706563696669636174696f6e732f686f7473706f7432646f74302f76" \
88"312e302f616f637069223e3c4465736372697074696f6e3e46726565207769746820796f7572" \
89"20737562736372697074696f6e213c2f4465736372697074696f6e3e3c2f506c616e3e"
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030090
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +020091/*
92 * MTU for Ethernet need to take into account 8-byte SNAP header
93 * to be added when encapsulating Ethernet frame into 802.11.
94 */
95#ifndef IEEE80211_MAX_DATA_LEN_DMG
96#define IEEE80211_MAX_DATA_LEN_DMG 7920
97#endif /* IEEE80211_MAX_DATA_LEN_DMG */
98#ifndef IEEE80211_SNAP_LEN_DMG
99#define IEEE80211_SNAP_LEN_DMG 8
100#endif /* IEEE80211_SNAP_LEN_DMG */
101
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200102extern char *sigma_main_ifname;
103extern char *sigma_wpas_ctrl;
104extern char *sigma_hapd_ctrl;
105extern char *ap_inet_addr;
106extern char *ap_inet_mask;
107extern char *sigma_radio_ifname[];
108
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200109static int ath_ap_start_hostapd(struct sigma_dut *dut);
110static void ath_ap_set_params(struct sigma_dut *dut);
111static int kill_process(struct sigma_dut *dut, char *proc_name,
112 unsigned char is_proc_instance_one, int sig);
113
114
Jouni Malinen6be21c82018-08-01 18:47:24 +0300115static int ap_ft_enabled(struct sigma_dut *dut)
116{
117 return dut->ap_ft_oa == 1 ||
Jouni Malinen9f943312019-08-19 23:49:16 +0300118 dut->ap_ft_ds == VALUE_ENABLED ||
Jouni Malinen6be21c82018-08-01 18:47:24 +0300119 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
120 dut->ap_key_mgmt == AP_WPA2_FT_PSK ||
Jouni Malinenda5f35b2019-03-26 00:25:53 +0200121 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP ||
122 (dut->ap_akm_values &
123 ((1 << AKM_FT_EAP) |
124 (1 << AKM_FT_PSK) |
125 (1 << AKM_FT_SAE) |
126 (1 << AKM_FT_SUITE_B) |
127 (1 << AKM_FT_FILS_SHA256) |
128 (1 << AKM_FT_FILS_SHA384)));
Jouni Malinen6be21c82018-08-01 18:47:24 +0300129}
130
131
Jouni Malinenf7222712019-06-13 01:50:21 +0300132static enum sigma_cmd_result cmd_ap_ca_version(struct sigma_dut *dut,
133 struct sigma_conn *conn,
134 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200135{
136 /* const char *name = get_param(cmd, "NAME"); */
137 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
138 return 0;
139}
140
141
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300142static void kill_hostapd_process_pid(struct sigma_dut *dut)
143{
144 FILE *f;
145 int pid, res;
146 char path[100];
147 int count;
148
149 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
150 if (!f)
151 return;
152 res = fscanf(f, "%d", &pid);
153 fclose(f);
154 if (res != 1)
155 return;
156 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
157 kill(pid, SIGTERM);
158 snprintf(path, sizeof(path), "/proc/%d", pid);
159 for (count = 0; count < 20 && file_exists(path); count++)
160 usleep(100000);
161}
162
163
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300164int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200165{
166#ifndef __QNXNTO__
167 struct ifreq ifr;
168 int s;
169
170 s = socket(AF_INET, SOCK_DGRAM, 0);
171 if (s < 0)
172 return -1;
173 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700174 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200175 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
176 perror("ioctl");
177 close(s);
178 return -1;
179 }
180 close(s);
181 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
182#else /* __QNXNTO__ */
183 struct ifaddrs *ifaddrshead = NULL;
184 int found = 0;
185 struct ifaddrs *temp_ifap = NULL;
186 struct sockaddr_dl *sdl = NULL;
187
188 if (getifaddrs(&ifaddrshead) != 0) {
189 perror("getifaddrs failed");
190 return -1;
191 }
192
193 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
194 ifaddrshead = ifaddrshead->ifa_next) {
195 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
196 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
197 found = 1;
198 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
199 if (sdl)
200 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
201 }
202 }
203
204 if (temp_ifap)
205 freeifaddrs(temp_ifap);
206
207 if (!found) {
208 perror("Failed to get the interface");
209 return -1;
210 }
211#endif /* __QNXNTO__ */
212 return 0;
213}
214
215
216static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
217 const char *val)
218{
219 char buf[60];
220
221 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
222 ifname, atoi(val));
223 if (system(buf) != 0) {
224 sigma_dut_print(dut, DUT_MSG_ERROR,
225 "wifitool ap_group_id failed");
226 }
227}
228
229
230void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
231 const char *val)
232{
233 char buf[60];
234
235 /* TODO: Enable support for other values */
236 if (strcasecmp(val, "40") == 0) {
237 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
238 ifname);
239 if (system(buf) != 0) {
240 sigma_dut_print(dut, DUT_MSG_ERROR,
241 "wifitool cts_width failed");
242 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800243 snprintf(buf, sizeof(buf),
244 "athdiag --set --address=0x10024 --val=0xd90b8a14");
245 if (system(buf) != 0) {
246 sigma_dut_print(dut, DUT_MSG_ERROR,
247 "disabling phy restart failed");
248 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200249 } else {
250 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
251 }
252}
253
254
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800255void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
256 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200257{
258 char buf[60];
259
260 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200261 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700262 run_iwpriv(dut, ifname, "cwmenable 1");
263
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800264 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
265 ifname);
266 if (system(buf) != 0) {
267 sigma_dut_print(dut, DUT_MSG_ERROR,
268 "disabling RTS from rate control logic failed");
269 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200270 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200271 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700272 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200273 } else {
274 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
275 }
276}
277
278
279static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
280 const char *val)
281{
282 char buf[60];
283
284 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200285 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200286 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
287 if (system(buf) != 0) {
288 sigma_dut_print(dut, DUT_MSG_ERROR,
289 "iwconfig rts 64 failed");
290 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800291 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
292 ifname);
293 if (system(buf) != 0) {
294 sigma_dut_print(dut, DUT_MSG_ERROR,
295 "wifitool beeliner_fw_test 100 1 failed");
296 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200297 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200298 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
300 if (system(buf) != 0) {
301 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700302 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200303 }
304 } else {
305 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
306 }
307}
308
309
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800310static void ath_radio(struct sigma_dut *dut, const char *val)
311{
312 if (strcasecmp(val, "on") == 0) {
313 if (dut->ap_interface_5g == 1) {
314 run_system(dut, "uci set wireless.wifi0.disabled=0");
315 } else if (dut->ap_interface_2g == 1) {
316 run_system(dut, "uci set wireless.wifi1.disabled=0");
317 } else {
318 run_system(dut, "uci set wireless.wifi0.disabled=0");
319 run_system(dut, "uci set wireless.wifi1.disabled=0");
320 }
321 run_system(dut, "uci commit");
322 run_system(dut, "wifi down");
323 run_system(dut, "wifi up");
324 } else if (strcasecmp(val, "off") == 0) {
325 if (dut->ap_interface_5g == 1) {
326 run_system(dut, "uci set wireless.wifi0.disabled=1");
327 } else if (dut->ap_interface_2g == 1) {
328 run_system(dut, "uci set wireless.wifi1.disabled=1");
329 } else {
330 run_system(dut, "uci set wireless.wifi0.disabled=1");
331 run_system(dut, "uci set wireless.wifi1.disabled=1");
332 }
333 run_system(dut, "uci commit");
334 run_system(dut, "wifi down");
335 run_system(dut, "wifi up");
336 }
337}
338
339
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800340static void deauth_disassoc(struct sigma_dut *dut, const char *ifname,
341 const char *val)
342{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -0700343 if (strcasecmp(val, "disable") == 0)
344 run_iwpriv(dut, ifname, "stealthdown 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -0800345}
346
347
priyadharshini gowthamancb22e432017-12-28 15:23:31 -0800348static void ath_set_txpower(struct sigma_dut *dut, const char *ifname,
349 const char *val)
350{
351 char buf[60];
352
353 if (strcasecmp(val, "high") == 0)
354 snprintf(buf, sizeof(buf), "iwconfig %s txpower 29", ifname);
355 else if (strcasecmp(val, "low") == 0)
356 snprintf(buf, sizeof(buf), "iwconfig %s txpower 1", ifname);
357 else
358 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported txpower");
359
360 if (system(buf) != 0)
361 sigma_dut_print(dut, DUT_MSG_ERROR, "setting txpower failed");
362}
363
364
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200365static enum ap_mode get_mode(const char *str)
366{
367 if (strcasecmp(str, "11a") == 0)
368 return AP_11a;
369 else if (strcasecmp(str, "11g") == 0)
370 return AP_11g;
371 else if (strcasecmp(str, "11b") == 0)
372 return AP_11b;
373 else if (strcasecmp(str, "11na") == 0)
374 return AP_11na;
375 else if (strcasecmp(str, "11ng") == 0)
376 return AP_11ng;
377 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
378 return AP_11ac;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200379 else if (strcasecmp(str, "11ad") == 0)
380 return AP_11ad;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200381 else
382 return AP_inval;
383}
384
385
386static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
387{
388 char command[1000];
389 const char *bin;
390 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700391 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200392
393 if (file_exists("hostapd_cli"))
394 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300395 else if (file_exists("../../hostapd/hostapd_cli"))
396 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200397 else
398 bin = "hostapd_cli";
399
400 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700401 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200402
403 if (sigma_radio_ifname[0] &&
404 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700405 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200406 else if (sigma_radio_ifname[0] &&
407 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700408 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200409 }
410
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700411 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200412 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700413 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200414 else
415 snprintf(command, sizeof(command), "%s %s", bin, buf);
416 return run_system(dut, command);
417}
418
419
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700420static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
421 struct sigma_cmd *cmd)
422{
423 FILE *f;
424 int i;
425
426 f = fopen("/tmp/lci_cfg.txt", "w");
427 if (!f) {
428 sigma_dut_print(dut, DUT_MSG_ERROR,
429 "Failed to open /tmp/lci_cfg.txt");
430 return -1;
431 }
432
433 for (i = 2; i < cmd->count; i++)
434 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
435 fprintf(f, "\n");
436 fclose(f);
437
438 return 0;
439}
440
441
hangtian00606622019-04-19 11:15:48 +0800442static void set_ap_country_code(struct sigma_dut *dut)
443{
444#if defined(ANDROID) || defined(LINUX_EMBEDDED)
445 char buf[256];
446
447 if (dut->ap_countrycode[0]) {
448 snprintf(buf, sizeof(buf), "DRIVER COUNTRY %s",
449 dut->ap_countrycode);
450 if (wpa_command(get_station_ifname(), buf) < 0)
451 sigma_dut_print(dut, DUT_MSG_ERROR,
452 "Failed to set country code");
453 else
454 sigma_dut_print(dut, DUT_MSG_INFO,
455 "Successfully set country code to %s",
456 dut->ap_countrycode);
457 }
458#endif
459}
460
461
Jouni Malinenf7222712019-06-13 01:50:21 +0300462static enum sigma_cmd_result cmd_ap_set_wireless(struct sigma_dut *dut,
463 struct sigma_conn *conn,
464 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200465{
466 /* const char *name = get_param(cmd, "NAME"); */
467 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200468 const char *val;
469 unsigned int wlan_tag = 1;
470 char *ifname = get_main_ifname();
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +0200471 char buf[128];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200472
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200473 /* Allow program to be overridden if specified in the ap_set_wireless
474 * to support some 60 GHz test scripts where the program may be 60 GHz
475 * or WPS. */
476 val = get_param(cmd, "PROGRAM");
477 if (val)
478 dut->program = sigma_program_to_enum(val);
479
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200480 val = get_param(cmd, "WLAN_TAG");
481 if (val) {
482 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700483 if (wlan_tag < 1 || wlan_tag > 3) {
484 /*
485 * The only valid WLAN Tags as of now as per the latest
486 * WFA scripts are 1, 2, and 3.
487 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200488 send_resp(dut, conn, SIGMA_INVALID,
489 "errorCode,Invalid WLAN_TAG");
490 return 0;
491 }
492 }
493
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800494 val = get_param(cmd, "Interface");
495 if (val) {
496 if (strcasecmp(val, "5G") == 0)
497 dut->ap_interface_5g = 1;
498 else
499 dut->ap_interface_2g = 1;
500
501 if (dut->ap_interface_5g && dut->ap_interface_2g)
502 dut->ap_is_dual = 1;
503 }
504
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200505 val = get_param(cmd, "CountryCode");
506 if (val) {
507 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
508 return -1;
509 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
510 "%s", val);
hangtian00606622019-04-19 11:15:48 +0800511
512 /*
513 * Regdomain self-managed driver does not accept hostapd country
514 * code setting in all cases. Try to use wpa_supplicant DRIVER
515 * command first to set the driver to a specific country code
516 * before starting AP functionality. This is targeting cases
517 * where wpa_supplicant is running on the device as well for
518 * non-AP mode functionality.
519 */
520 if (get_driver_type() == DRIVER_LINUX_WCN)
521 set_ap_country_code(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200522 }
523
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530524 val = get_param(cmd, "regulatory_mode");
525 if (val) {
526 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
527 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
528 }
529
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200530 val = get_param(cmd, "SSID");
531 if (val) {
532 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
533 return -1;
534
535 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700536 /*
537 * If tag is not specified, it is deemed to be 1.
538 * Hence tag of 1 is a special case and the values
539 * corresponding to wlan-tag=1 are stored separately
540 * from the values corresponding tags 2 and 3.
541 * This approach minimises the changes to existing code
542 * since most of the sigma_dut code does not deal with
543 * WLAN-TAG CAPI variable.
544 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200545 snprintf(dut->ap_ssid,
546 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700547 } else {
548 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
549 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
550 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200551 }
552 }
553
554 val = get_param(cmd, "CHANNEL");
555 if (val) {
556 const char *pos;
557 dut->ap_channel = atoi(val);
558 pos = strchr(val, ';');
559 if (pos) {
560 pos++;
561 dut->ap_channel_1 = atoi(pos);
562 }
563 }
564
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530565 /* Overwrite the AP channel with DFS channel if configured */
566 val = get_param(cmd, "dfs_chan");
567 if (val) {
568 dut->ap_channel = atoi(val);
569 }
570
571 val = get_param(cmd, "dfs_mode");
572 if (val) {
573 if (strcasecmp(val, "Enable") == 0)
574 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
575 else if (strcasecmp(val, "Disable") == 0)
576 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
577 else
578 sigma_dut_print(dut, DUT_MSG_ERROR,
579 "Unsupported dfs_mode value: %s", val);
580 }
581
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200582 val = get_param(cmd, "MODE");
583 if (val) {
584 char *str, *pos;
585
586 str = strdup(val);
587 if (str == NULL)
588 return -1;
589 pos = strchr(str, ';');
590 if (pos)
591 *pos++ = '\0';
592
593 dut->ap_is_dual = 0;
594 dut->ap_mode = get_mode(str);
595 if (dut->ap_mode == AP_inval) {
596 send_resp(dut, conn, SIGMA_INVALID,
597 "errorCode,Unsupported MODE");
598 free(str);
599 return 0;
600 }
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800601 if (dut->ap_mode == AP_11ac && dut->ap_80plus80 != 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200602 dut->ap_chwidth = AP_80;
603
604 if (pos) {
605 dut->ap_mode_1 = get_mode(pos);
606 if (dut->ap_mode_1 == AP_inval) {
607 send_resp(dut, conn, SIGMA_INVALID,
608 "errorCode,Unsupported MODE");
609 free(str);
610 return 0;
611 }
612 if (dut->ap_mode_1 == AP_11ac)
613 dut->ap_chwidth_1 = AP_80;
614 dut->ap_is_dual = 1;
615 }
616
617 free(str);
618 } else if (dut->ap_mode == AP_inval) {
619 if (dut->ap_channel <= 11)
620 dut->ap_mode = AP_11ng;
621 else if (dut->program == PROGRAM_VHT)
622 dut->ap_mode = AP_11ac;
623 else
624 dut->ap_mode = AP_11na;
625 }
626
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +0200627 /* Override the AP mode in case of 60 GHz */
628 if (dut->program == PROGRAM_60GHZ) {
629 dut->ap_mode = AP_11ad;
630 /* Workaround to force channel 2 if not specified */
631 if (!dut->ap_channel)
632 dut->ap_channel = 2;
633 }
634
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530635 val = get_param(cmd, "WME");
636 if (val) {
637 if (strcasecmp(val, "on") == 0)
638 dut->ap_wme = AP_WME_ON;
639 else if (strcasecmp(val, "off") == 0)
640 dut->ap_wme = AP_WME_OFF;
641 else
642 sigma_dut_print(dut, DUT_MSG_ERROR,
643 "Unsupported WME value: %s", val);
644 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200645
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530646 val = get_param(cmd, "WMMPS");
647 if (val) {
648 if (strcasecmp(val, "on") == 0)
649 dut->ap_wmmps = AP_WMMPS_ON;
650 else if (strcasecmp(val, "off") == 0)
651 dut->ap_wmmps = AP_WMMPS_OFF;
652 else
653 sigma_dut_print(dut, DUT_MSG_ERROR,
654 "Unsupported WMMPS value: %s", val);
655 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200656
657 val = get_param(cmd, "RTS");
658 if (val)
659 dut->ap_rts = atoi(val);
660
661 val = get_param(cmd, "FRGMNT");
662 if (val)
663 dut->ap_frgmnt = atoi(val);
664
665 /* TODO: PWRSAVE */
666
667 val = get_param(cmd, "BCNINT");
668 if (val)
669 dut->ap_bcnint = atoi(val);
670
671 val = get_param(cmd, "RADIO");
672 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530673 enum driver_type drv = get_driver_type();
674
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200675 if (strcasecmp(val, "on") == 0) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800676 if (drv == DRIVER_OPENWRT)
677 ath_radio(dut, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200678 if (drv == DRIVER_ATHEROS)
679 ath_ap_start_hostapd(dut);
680 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
681 return 0;
682 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530683 if (drv == DRIVER_OPENWRT) {
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -0800684 ath_radio(dut, val);
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300685 } else if (dut->use_hostapd_pid_file) {
686 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530687 } else if (kill_process(dut, "(hostapd)", 1,
688 SIGTERM) == 0 ||
689 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200690 sigma_dut_print(dut, DUT_MSG_INFO,
691 "Killed hostapd on radio,off");
692 }
693 } else {
694 send_resp(dut, conn, SIGMA_INVALID,
695 "errorCode,Unsupported RADIO value");
696 return 0;
697 }
698 }
699
700 val = get_param(cmd, "P2PMgmtBit");
701 if (val)
702 dut->ap_p2p_mgmt = atoi(val);
703
704 /* TODO: ChannelUsage */
705
706 /* TODO: 40_INTOLERANT */
707
708 val = get_param(cmd, "ADDBA_REJECT");
709 if (val) {
710 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200711 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200712 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200713 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200714 }
715
716 val = get_param(cmd, "AMPDU");
717 if (val) {
718 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200719 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200720 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200721 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200722 }
723
724 val = get_param(cmd, "AMPDU_EXP");
725 if (val)
726 dut->ap_ampdu_exp = atoi(val);
727
728 val = get_param(cmd, "AMSDU");
729 if (val) {
730 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200731 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200732 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200733 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200734 }
735
736 val = get_param(cmd, "NoAck");
737 if (val) {
738 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200739 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200740 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200741 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200742 }
743
744 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200745 /* TODO: MCS_32 */
746
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530747 val = get_param(cmd, "OFFSET");
748 if (val) {
749 if (strcasecmp(val, "Above") == 0)
750 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
751 else if (strcasecmp(val, "Below") == 0)
752 dut->ap_chwidth_offset = SEC_CH_40BELOW;
753 }
754
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200755 val = get_param(cmd, "MCS_FIXEDRATE");
756 if (val) {
757 dut->ap_fixed_rate = 1;
758 dut->ap_mcs = atoi(val);
759 }
760
761 val = get_param(cmd, "SPATIAL_RX_STREAM");
762 if (val) {
763 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
764 dut->ap_rx_streams = 1;
765 if (dut->device_type == AP_testbed)
766 dut->ap_vhtmcs_map = 0xfffc;
767 } else if (strcasecmp(val, "2SS") == 0 ||
768 strcasecmp(val, "2") == 0) {
769 dut->ap_rx_streams = 2;
770 if (dut->device_type == AP_testbed)
771 dut->ap_vhtmcs_map = 0xfff0;
772 } else if (strcasecmp(val, "3SS") == 0 ||
773 strcasecmp(val, "3") == 0) {
774 dut->ap_rx_streams = 3;
775 if (dut->device_type == AP_testbed)
776 dut->ap_vhtmcs_map = 0xffc0;
777 } else if (strcasecmp(val, "4SS") == 0 ||
778 strcasecmp(val, "4") == 0) {
779 dut->ap_rx_streams = 4;
780 }
781 }
782
783 val = get_param(cmd, "SPATIAL_TX_STREAM");
784 if (val) {
785 if (strcasecmp(val, "1SS") == 0 ||
786 strcasecmp(val, "1") == 0) {
787 dut->ap_tx_streams = 1;
788 if (dut->device_type == AP_testbed)
789 dut->ap_vhtmcs_map = 0xfffc;
790 } else if (strcasecmp(val, "2SS") == 0 ||
791 strcasecmp(val, "2") == 0) {
792 dut->ap_tx_streams = 2;
793 if (dut->device_type == AP_testbed)
794 dut->ap_vhtmcs_map = 0xfff0;
795 } else if (strcasecmp(val, "3SS") == 0 ||
796 strcasecmp(val, "3") == 0) {
797 dut->ap_tx_streams = 3;
798 if (dut->device_type == AP_testbed)
799 dut->ap_vhtmcs_map = 0xffc0;
800 } else if (strcasecmp(val, "4SS") == 0 ||
801 strcasecmp(val, "4") == 0) {
802 dut->ap_tx_streams = 4;
803 }
804 }
805
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700806 val = get_param(cmd, "BSS_max_idle");
807 if (val) {
808 if (strncasecmp(val, "Enable", 7) == 0) {
809 dut->wnm_bss_max_feature = VALUE_ENABLED;
810 } else if (strncasecmp(val, "Disable", 8) == 0) {
811 dut->wnm_bss_max_feature = VALUE_DISABLED;
812 } else {
813 send_resp(dut, conn, SIGMA_ERROR,
814 "errorCode,Invalid value for BSS_max_Feature");
815 return 0;
816 }
817 }
818
819 val = get_param(cmd, "BSS_Idle_Protection_options");
820 if (val) {
821 int protection = (int) strtol(val, (char **) NULL, 10);
822
823 if (protection != 1 && protection != 0) {
824 send_resp(dut, conn, SIGMA_ERROR,
825 "errorCode,Invalid value for BSS_Idle_Protection_options");
826 return 0;
827 }
828 dut->wnm_bss_max_protection = protection ?
829 VALUE_ENABLED : VALUE_DISABLED;
830 }
831
832 val = get_param(cmd, "BSS_max_Idle_period");
833 if (val) {
Jouni Malinen544edf02019-02-25 19:02:33 +0200834 long int idle_time = strtol(val, (char **) NULL, 10);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700835
836 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
837 send_resp(dut, conn, SIGMA_ERROR,
838 "errorCode,Invalid value for BSS_max_Idle_period");
839 return 0;
840 }
Jouni Malinen544edf02019-02-25 19:02:33 +0200841 dut->wnm_bss_max_idle_time = (int) idle_time;
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700842 }
843
844 val = get_param(cmd, "PROXY_ARP");
845 if (val)
846 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
847
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200848 val = get_param(cmd, "nss_mcs_cap");
849 if (val) {
850 int nss, mcs;
851 char token[20];
852 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530853 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200854
855 if (strlen(val) >= sizeof(token))
856 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300857 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530858 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530859 if (!result) {
860 sigma_dut_print(dut, DUT_MSG_ERROR,
861 "VHT NSS not specified");
862 return 0;
863 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200864 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530865 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200866 if (result == NULL) {
867 sigma_dut_print(dut, DUT_MSG_ERROR,
868 "VHTMCS NOT SPECIFIED!");
869 return 0;
870 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530871 result = strtok_r(result, "-", &saveptr);
872 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530873 if (!result) {
874 sigma_dut_print(dut, DUT_MSG_ERROR,
875 "VHT MCS not specified");
876 return 0;
877 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200878 mcs = atoi(result);
879 switch (nss) {
880 case 1:
881 switch (mcs) {
882 case 7:
883 dut->ap_vhtmcs_map = 0xfffc;
884 break;
885 case 8:
886 dut->ap_vhtmcs_map = 0xfffd;
887 break;
888 case 9:
889 dut->ap_vhtmcs_map = 0xfffe;
890 break;
891 default:
892 dut->ap_vhtmcs_map = 0xfffe;
893 break;
894 }
895 break;
896 case 2:
897 switch (mcs) {
898 case 7:
899 dut->ap_vhtmcs_map = 0xfff0;
900 break;
901 case 8:
902 dut->ap_vhtmcs_map = 0xfff5;
903 break;
904 case 9:
905 dut->ap_vhtmcs_map = 0xfffa;
906 break;
907 default:
908 dut->ap_vhtmcs_map = 0xfffa;
909 break;
910 }
911 break;
912 case 3:
913 switch (mcs) {
914 case 7:
915 dut->ap_vhtmcs_map = 0xffc0;
916 break;
917 case 8:
918 dut->ap_vhtmcs_map = 0xffd5;
919 break;
920 case 9:
921 dut->ap_vhtmcs_map = 0xffea;
922 break;
923 default:
924 dut->ap_vhtmcs_map = 0xffea;
925 break;
926 }
927 break;
928 default:
929 dut->ap_vhtmcs_map = 0xffea;
930 break;
931 }
932 }
933
934 /* TODO: MPDU_MIN_START_SPACING */
935 /* TODO: RIFS_TEST */
936 /* TODO: SGI20 */
937
938 val = get_param(cmd, "STBC_TX");
939 if (val)
940 dut->ap_tx_stbc = atoi(val);
941
942 val = get_param(cmd, "WIDTH");
943 if (val) {
944 if (strcasecmp(val, "20") == 0)
945 dut->ap_chwidth = AP_20;
946 else if (strcasecmp(val, "40") == 0)
947 dut->ap_chwidth = AP_40;
948 else if (strcasecmp(val, "80") == 0)
949 dut->ap_chwidth = AP_80;
950 else if (strcasecmp(val, "160") == 0)
951 dut->ap_chwidth = AP_160;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -0800952 else if (strcasecmp(val, "80plus80") == 0) {
953 dut->ap_80plus80 = 1;
954 dut->ap_chwidth = AP_80_80;
955 } else if (strcasecmp(val, "Auto") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200956 dut->ap_chwidth = AP_AUTO;
957 else {
958 send_resp(dut, conn, SIGMA_INVALID,
959 "errorCode,Unsupported WIDTH");
960 return 0;
961 }
962 }
963
964 /* TODO: WIDTH_SCAN */
965
966 val = get_param(cmd, "TDLSProhibit");
967 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
968 val = get_param(cmd, "TDLSChswitchProhibit");
969 dut->ap_tdls_prohibit_chswitch =
970 val && strcasecmp(val, "Enabled") == 0;
971 val = get_param(cmd, "HS2");
972 if (val && wlan_tag == 1)
973 dut->ap_hs2 = atoi(val);
974 val = get_param(cmd, "P2P_CROSS_CONNECT");
975 if (val)
976 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
977
978 val = get_param(cmd, "FakePubKey");
979 dut->ap_fake_pkhash = val && atoi(val);
980
981 val = get_param(cmd, "vht_tkip");
982 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
983 val = get_param(cmd, "vht_wep");
984 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
985
986 val = get_param(cmd, "Protect_mode");
987 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
988
989 val = get_param(cmd, "DYN_BW_SGNL");
990 if (val) {
991 switch (get_driver_type()) {
992 case DRIVER_OPENWRT:
993 switch (get_openwrt_driver_type()) {
994 case OPENWRT_DRIVER_ATHEROS:
995 ath_config_dyn_bw_sig(dut, ifname, val);
996 break;
997 default:
998 send_resp(dut, conn, SIGMA_ERROR,
999 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
1000 return 0;
1001 }
1002 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +05301003 case DRIVER_WCN:
1004 case DRIVER_LINUX_WCN:
1005 ath_config_dyn_bw_sig(dut, ifname, val);
1006 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001007 default:
1008 sigma_dut_print(dut, DUT_MSG_ERROR,
1009 "Unsupported DYN_BW_SGL with the current driver");
1010 break;
1011 }
1012 }
1013
1014 val = get_param(cmd, "SGI80");
1015 if (val) {
1016 if (strcasecmp(val, "enable") == 0)
1017 dut->ap_sgi80 = 1;
1018 else if (strcasecmp(val, "disable") == 0)
1019 dut->ap_sgi80 = 0;
1020 else {
1021 send_resp(dut, conn, SIGMA_INVALID,
1022 "errorCode,Unsupported SGI80");
1023 return 0;
1024 }
1025 }
1026
1027 val = get_param(cmd, "LDPC");
1028 if (val) {
1029 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001030 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001031 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001032 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001033 else {
1034 send_resp(dut, conn, SIGMA_INVALID,
1035 "errorCode,Unsupported LDPC");
1036 return 0;
1037 }
1038 }
1039
1040 val = get_param(cmd, "BW_SGNL");
1041 if (val) {
1042 /*
1043 * With dynamic bandwidth signaling enabled we should see
1044 * RTS if the threshold is met.
1045 */
1046 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001047 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02001049 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001050 } else {
1051 send_resp(dut, conn, SIGMA_INVALID,
1052 "errorCode,Unsupported BW_SGNL");
1053 return 0;
1054 }
1055 }
1056
1057 val = get_param(cmd, "RTS_FORCE");
1058 if (val) {
1059 switch (get_driver_type()) {
1060 case DRIVER_OPENWRT:
1061 switch (get_openwrt_driver_type()) {
1062 case OPENWRT_DRIVER_ATHEROS:
1063 ath_config_rts_force(dut, ifname, val);
1064 break;
1065 default:
1066 send_resp(dut, conn, SIGMA_ERROR,
1067 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
1068 return 0;
1069 }
1070 break;
1071 default:
1072 sigma_dut_print(dut, DUT_MSG_ERROR,
1073 "Unsupported RTS_FORCE with the current driver");
1074 break;
1075 }
1076 }
1077
1078 val = get_param(cmd, "Zero_crc");
1079 if (val) {
1080 switch (get_driver_type()) {
1081 case DRIVER_ATHEROS:
1082 ath_set_zero_crc(dut, val);
1083 break;
1084 case DRIVER_OPENWRT:
1085 switch (get_openwrt_driver_type()) {
1086 case OPENWRT_DRIVER_ATHEROS:
1087 ath_set_zero_crc(dut, val);
1088 break;
1089 default:
1090 send_resp(dut, conn, SIGMA_ERROR,
1091 "errorCode,Unsupported zero_crc with the current driver");
1092 return 0;
1093 }
1094 break;
1095 default:
1096 send_resp(dut, conn, SIGMA_ERROR,
1097 "errorCode,Unsupported zero_crc with the current driver");
1098 return 0;
1099 }
1100 }
1101
1102 val = get_param(cmd, "TxBF");
1103 if (val)
1104 dut->ap_txBF = strcasecmp(val, "enable") == 0;
1105
1106 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +05301107 if (val) {
1108 if (strcasecmp(val, "enable") == 0) {
1109 dut->ap_txBF = 1;
1110 dut->ap_mu_txBF = 1;
1111 } else if (strcasecmp(val, "disable") == 0) {
1112 dut->ap_txBF = 0;
1113 dut->ap_mu_txBF = 0;
1114 } else {
1115 sigma_dut_print(dut, DUT_MSG_ERROR,
1116 "Unsupported MU_TxBF");
1117 }
1118 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001119
1120 /* UNSUPPORTED: tx_lgi_rate */
1121
1122 val = get_param(cmd, "wpsnfc");
1123 if (val)
1124 dut->ap_wpsnfc = atoi(val);
1125
1126 val = get_param(cmd, "GROUP_ID");
1127 if (val) {
1128 switch (get_driver_type()) {
1129 case DRIVER_OPENWRT:
1130 switch (get_openwrt_driver_type()) {
1131 case OPENWRT_DRIVER_ATHEROS:
1132 ath_ap_set_group_id(dut, ifname, val);
1133 break;
1134 default:
1135 send_resp(dut, conn, SIGMA_ERROR,
1136 "errorCode,Unsupported group_id with the current driver");
1137 return 0;
1138 }
1139 break;
1140 default:
1141 send_resp(dut, conn, SIGMA_ERROR,
1142 "errorCode,Unsupported group_id with the current driver");
1143 return 0;
1144 }
1145 }
1146
1147 val = get_param(cmd, "CTS_WIDTH");
1148 if (val) {
1149 switch (get_driver_type()) {
1150 case DRIVER_OPENWRT:
1151 switch (get_openwrt_driver_type()) {
1152 case OPENWRT_DRIVER_ATHEROS:
1153 ath_set_cts_width(dut, ifname, val);
1154 break;
1155 default:
1156 send_resp(dut, conn, SIGMA_ERROR,
1157 "errorCode,Unsupported cts_width with the current driver");
1158 return 0;
1159 }
1160 break;
1161 default:
1162 send_resp(dut, conn, SIGMA_ERROR,
1163 "errorCode,Unsupported cts_width with the current driver");
1164 return 0;
1165 }
1166 }
1167
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08001168 val = get_param(cmd, "MU_NDPA_FrameFormat");
1169 if (val)
1170 dut->ap_ndpa_frame = atoi(val);
1171
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07001172 val = get_param(cmd, "interworking");
1173 if (val && strcmp(val, "1") == 0)
1174 dut->ap_interworking = 1;
1175
1176 val = get_param(cmd, "GAS_CB_DELAY");
1177 if (val)
1178 dut->ap_gas_cb_delay = atoi(val);
1179
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001180 val = get_param(cmd, "LCI");
1181 if (val) {
1182 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1183 return -1;
1184 dut->ap_lci = 1;
1185 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1186 ath_set_lci_config(dut, val, cmd);
1187 }
1188
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001189 val = get_param(cmd, "InfoZ");
1190 if (val) {
1191 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1192 return -1;
1193 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1194 }
1195
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001196 val = get_param(cmd, "LocCivicAddr");
1197 if (val) {
1198 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1199 return -1;
1200 dut->ap_lcr = 1;
1201 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1202 if (dut->ap_lci == 0)
1203 ath_set_lci_config(dut, val, cmd);
1204 }
1205
1206 val = get_param(cmd, "NeighAPBSSID");
1207 if (val) {
1208 if (dut->ap_neighap < 3) {
1209 if (parse_mac_address(
1210 dut, val,
1211 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1212 send_resp(dut, conn, SIGMA_INVALID,
1213 "Failed to parse MAC address");
1214 return 0;
1215 }
1216 dut->ap_neighap++;
1217 if (dut->ap_lci == 1)
1218 dut->ap_scan = 1;
1219 }
1220 }
1221
1222 val = get_param(cmd, "OpChannel");
1223 if (val) {
1224 if (dut->ap_opchannel < 3) {
1225 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1226 dut->ap_opchannel++;
1227 }
1228 }
1229
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001230 val = get_param(cmd, "URI-FQDNdescriptor");
1231 if (val) {
1232 if (strcasecmp(val, "HELD") == 0) {
1233 dut->ap_fqdn_held = 1;
1234 } else if (strcasecmp(val, "SUPL") == 0) {
1235 dut->ap_fqdn_supl = 1;
1236 } else {
1237 send_resp(dut, conn, SIGMA_INVALID,
1238 "errorCode,Unsupported URI-FQDNdescriptor");
1239 return 0;
1240 }
1241 }
1242
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001243 val = get_param(cmd, "Reg_Domain");
1244 if (val) {
1245 if (strcasecmp(val, "Local") == 0) {
1246 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1247 } else if (strcasecmp(val, "Global") == 0) {
1248 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1249 } else {
1250 send_resp(dut, conn, SIGMA_ERROR,
1251 "errorCode,Wrong value for Reg_Domain");
1252 return 0;
1253 }
1254 }
1255
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001256 val = get_param(cmd, "NAME");
1257 if (val) {
1258 if (strcasecmp(val, "ap1mbo") == 0)
1259 dut->ap_name = 1;
1260 else if (strcasecmp(val, "ap2mbo") == 0)
1261 dut->ap_name = 2;
1262 else
1263 dut->ap_name = 0;
1264 }
1265
1266 val = get_param(cmd, "FT_OA");
1267 if (val) {
1268 if (strcasecmp(val, "Enable") == 0) {
1269 dut->ap_ft_oa = 1;
1270 } else if (strcasecmp(val, "Disable") == 0) {
1271 dut->ap_ft_oa = 0;
1272 } else {
1273 send_resp(dut, conn, SIGMA_ERROR,
1274 "errorCode,Wrong value for FT_OA");
1275 return 0;
1276 }
1277 }
1278
Jouni Malinen9f943312019-08-19 23:49:16 +03001279 val = get_param(cmd, "FT_DS");
1280 if (val) {
1281 if (strcasecmp(val, "Enable") == 0) {
1282 dut->ap_ft_ds = VALUE_ENABLED;
1283 } else if (strcasecmp(val, "Disable") == 0) {
1284 dut->ap_ft_ds = VALUE_DISABLED;
1285 } else {
1286 send_resp(dut, conn, SIGMA_ERROR,
1287 "errorCode,Unsupported value for FT_DS");
1288 return STATUS_SENT_ERROR;
1289 }
1290 }
1291
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001292 val = get_param(cmd, "Cellular_Cap_Pref");
1293 if (val)
1294 dut->ap_cell_cap_pref = atoi(val);
1295
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001296 val = get_param(cmd, "DOMAIN");
1297 if (val) {
1298 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1299 send_resp(dut, conn, SIGMA_ERROR,
1300 "errorCode,Too long DOMAIN");
1301 return 0;
1302 }
1303 snprintf(dut->ap_mobility_domain,
1304 sizeof(dut->ap_mobility_domain), "%s", val);
1305 }
1306
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001307 val = get_param(cmd, "ft_bss_list");
1308 if (val) {
1309 char *mac_str;
1310 int i;
1311 char *saveptr;
1312 char *mac_list_str;
1313
1314 mac_list_str = strdup(val);
1315 if (!mac_list_str)
1316 return -1;
1317 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1318 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1319 if (parse_mac_address(dut, mac_str,
1320 dut->ft_bss_mac_list[i]) < 0) {
1321 sigma_dut_print(dut, DUT_MSG_ERROR,
1322 "MAC Address not in proper format");
1323 break;
1324 }
1325 dut->ft_bss_mac_cnt++;
1326 mac_str = strtok_r(NULL, " ", &saveptr);
1327 }
1328 sigma_dut_print(dut, DUT_MSG_DEBUG,
1329 "Storing the following FT BSS MAC List");
1330 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1331 sigma_dut_print(dut, DUT_MSG_DEBUG,
1332 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1333 i,
1334 dut->ft_bss_mac_list[i][0],
1335 dut->ft_bss_mac_list[i][1],
1336 dut->ft_bss_mac_list[i][2],
1337 dut->ft_bss_mac_list[i][3],
1338 dut->ft_bss_mac_list[i][4],
1339 dut->ft_bss_mac_list[i][5]);
1340 }
1341 free(mac_list_str);
1342 }
1343
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08001344 val = get_param(cmd, "OCESupport");
1345 if (val) {
1346 if (strcasecmp(val, "enable") == 0) {
1347 dut->ap_oce = VALUE_ENABLED;
1348 } else if (strcasecmp(val, "disable") == 0) {
1349 dut->ap_oce = VALUE_DISABLED;
1350 dut->ap_filsdscv = VALUE_DISABLED;
1351 } else {
1352 send_resp(dut, conn, SIGMA_INVALID,
1353 "errorCode,Unsupported OCE");
1354 return 0;
1355 }
1356 }
1357
1358 val = get_param(cmd, "FILSDscvInterval");
1359 if (val)
1360 dut->ap_fils_dscv_int = atoi(val);
1361
1362 val = get_param(cmd, "BroadcastSSID");
1363 if (val) {
1364 if (strcasecmp(val, "enable") == 0) {
1365 dut->ap_broadcast_ssid = VALUE_ENABLED;
1366 } else if (strcasecmp(val, "disable") == 0) {
1367 dut->ap_broadcast_ssid = VALUE_DISABLED;
1368 } else {
1369 send_resp(dut, conn, SIGMA_INVALID,
1370 "errorCode,Unsupported hidden SSID");
1371 return 0;
1372 }
1373 }
1374
1375 val = get_param(cmd, "FILSDscv");
1376 if (val) {
1377 if (strcasecmp(val, "enable") == 0) {
1378 dut->ap_filsdscv = VALUE_ENABLED;
1379 } else if (strcasecmp(val, "disable") == 0) {
1380 dut->ap_filsdscv = VALUE_DISABLED;
1381 } else {
1382 send_resp(dut, conn, SIGMA_INVALID,
1383 "errorCode,Unsupported FILSDscv");
1384 return 0;
1385 }
1386 }
1387
1388 val = get_param(cmd, "FILSHLP");
1389 if (val) {
1390 if (strcasecmp(val, "enable") == 0) {
1391 dut->ap_filshlp = VALUE_ENABLED;
1392 } else if (strcasecmp(val, "disable") == 0) {
1393 dut->ap_filshlp = VALUE_DISABLED;
1394 } else {
1395 send_resp(dut, conn, SIGMA_INVALID,
1396 "errorCode,Unsupported FILSHLP");
1397 return 0;
1398 }
1399 }
1400
1401 val = get_param(cmd, "NAIRealm");
1402 if (val) {
1403 dut->ap_nairealm_int = 1;
1404 if (strlen(val) > sizeof(dut->ap_nairealm) - 1)
1405 return -1;
1406 snprintf(dut->ap_nairealm, sizeof(dut->ap_nairealm), "%s", val);
1407 }
1408
1409 val = get_param(cmd, "DeauthDisassocTx");
1410 if (val) {
1411 if (strcasecmp(val, "disable") == 0) {
1412 deauth_disassoc(dut, ifname, val);
1413 } else {
1414 send_resp(dut, conn, SIGMA_INVALID,
1415 "errorCode,Unsupported DeauthDisassocTx");
1416 return 0;
1417 }
1418 }
1419
1420 val = get_param(cmd, "RNR");
1421 if (val) {
1422 if (strcasecmp(val, "enable") == 0) {
1423 dut->ap_rnr = VALUE_ENABLED;
1424 } else if (strcasecmp(val, "disable") == 0) {
1425 dut->ap_rnr = VALUE_DISABLED;
1426 } else {
1427 send_resp(dut, conn, SIGMA_INVALID,
1428 "errorCode,Unsupported RNR");
1429 return 0;
1430 }
1431 }
1432
1433 val = get_param(cmd, "BLEChannelUtil");
1434 if (val)
1435 dut->ap_blechanutil = atoi(val);
1436
1437 val = get_param(cmd, "BLEAvailAdminCap");
1438 if (val)
1439 dut->ap_ble_admit_cap = atoi(val);
1440
1441 val = get_param(cmd, "DataPPDUDuration");
1442 if (val)
1443 dut->ap_datappdudura = atoi(val);
1444
1445 val = get_param(cmd, "AirTimeFract");
1446 if (val)
1447 dut->ap_airtimefract = atoi(val);
1448
1449 val = get_param(cmd, "dhcpServIPADDR");
1450 if (val) {
1451 if (strlen(val) > sizeof(dut->ap_dhcpserv_ipaddr) - 1)
1452 return -1;
1453 snprintf(dut->ap_dhcpserv_ipaddr,
1454 sizeof(dut->ap_dhcpserv_ipaddr), "%s", val);
1455 dut->ap_dhcp_stop = 1;
1456 }
1457
1458 val = get_param(cmd, "ESP_IE");
1459 if (val) {
1460 if (strcasecmp(val, "enable") == 0) {
1461 dut->ap_esp = VALUE_ENABLED;
1462 } else if (strcasecmp(val, "disable") == 0) {
1463 dut->ap_esp = VALUE_DISABLED;
1464 } else {
1465 send_resp(dut, conn, SIGMA_INVALID,
1466 "errorCode,Unsupported ESP_IE");
1467 return 0;
1468 }
1469 }
1470
1471 val = get_param(cmd, "BAWinSize");
1472 if (val)
1473 dut->ap_bawinsize = atoi(val);
1474
1475 val = get_param(cmd, "BLEStaCount");
1476 if (val)
1477 dut->ap_blestacnt = atoi(val);
1478
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001479 val = get_param(cmd, "PPDUTxType");
1480 if (val) {
1481 if (strcasecmp(val, "MU") == 0) {
1482 dut->ap_he_ppdu = PPDU_MU;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001483 } else if (strcasecmp(val, "HE-SU") == 0) {
1484 /* Do nothing */
1485 } else if (strcasecmp(val, "SU") == 0) {
1486 /* Do nothing */
1487 } else if (strcasecmp(val, "legacy") == 0) {
1488 /* Do nothing */
1489 } else if (strcasecmp(val, "ER") == 0) {
1490 /* Do nothing */
1491 } else if (strcasecmp(val, "TB") == 0) {
1492 /* Do nothing */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001493 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001494 send_resp(dut, conn, SIGMA_ERROR,
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001495 "errorCode,Unsupported PPDUTxType");
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001496 return STATUS_SENT_ERROR;
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07001497 }
1498 }
1499
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02001500 val = get_param(cmd, "WscIEFragment");
1501 if (val && strcasecmp(val, "enable") == 0) {
1502 sigma_dut_print(dut, DUT_MSG_DEBUG,
1503 "Enable WSC IE fragmentation");
1504 dut->wsc_fragment = 1;
1505 }
1506
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02001507 val = get_param(cmd, "WpsVersion");
1508 if (val)
1509 dut->wps_forced_version = get_wps_forced_version(dut, val);
1510
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02001511 val = get_param(cmd, "WscEAPFragment");
1512 if (val && strcasecmp(val, "enable") == 0)
1513 dut->eap_fragment = 1;
1514
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001515 val = get_param(cmd, "MSDUSize");
1516 if (val) {
1517 int mtu;
1518
1519 dut->amsdu_size = atoi(val);
1520 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
1521 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
1522 sigma_dut_print(dut, DUT_MSG_ERROR,
1523 "MSDUSize %d is above max %d or below min %d",
1524 dut->amsdu_size,
1525 IEEE80211_MAX_DATA_LEN_DMG,
1526 IEEE80211_SNAP_LEN_DMG);
1527 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001528 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001529 }
1530
1531 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
1532 sigma_dut_print(dut, DUT_MSG_DEBUG,
1533 "Setting amsdu_size to %d", mtu);
1534 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
1535 get_station_ifname(), mtu);
1536
1537 if (system(buf) != 0) {
1538 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
1539 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001540 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar79f57272018-12-23 17:22:47 +02001541 }
1542 }
1543
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001544 val = get_param(cmd, "BAckRcvBuf");
1545 if (val) {
1546 dut->back_rcv_buf = atoi(val);
1547 if (dut->back_rcv_buf == 0) {
1548 sigma_dut_print(dut, DUT_MSG_ERROR,
1549 "Failed to convert %s or value is 0",
1550 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02001551 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar0e239a92018-12-23 17:27:50 +02001552 }
1553
1554 sigma_dut_print(dut, DUT_MSG_DEBUG,
1555 "Setting BAckRcvBuf to %s", val);
1556 }
1557
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02001558 val = get_param(cmd, "ExtSchIE");
1559 if (val && !strcasecmp(val, "Enable")) {
1560 int num_allocs = MAX_ESE_ALLOCS;
1561
1562 if (sta_extract_60g_ese(dut, cmd, dut->ap_ese_allocs,
1563 &num_allocs)) {
1564 send_resp(dut, conn, SIGMA_INVALID,
1565 "errorCode,Invalid ExtSchIE");
1566 return 0;
1567 }
1568 dut->ap_num_ese_allocs = num_allocs;
1569 }
1570
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02001571 if (is_60g_sigma_dut(dut)) {
1572 unsigned int abft_len = 1; /* default is one slot */
1573
1574 val = get_param(cmd, "ABFTLRang");
1575 if (val) {
1576 sigma_dut_print(dut, DUT_MSG_DEBUG,
1577 "ABFTLRang parameter %s", val);
1578 if (strcasecmp(val, "Gt1") == 0)
1579 abft_len = 2; /* 2 slots in this case */
1580 }
1581
1582 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
1583 send_resp(dut, conn, SIGMA_ERROR,
1584 "ErrorCode,Can't set ABFT length");
1585 return STATUS_SENT;
1586 }
1587 }
1588
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001589 val = get_param(cmd, "OFDMA");
1590 if (val) {
1591 if (strcasecmp(val, "UL") == 0) {
1592 dut->ap_he_ulofdma = VALUE_ENABLED;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07001593 } else if (strcasecmp(val, "DL") == 0) {
1594 dut->ap_he_dlofdma = VALUE_ENABLED;
1595 } else if (strcasecmp(val, "DL-20and80") == 0) {
1596 dut->ap_he_dlofdma = VALUE_ENABLED;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -07001597 } else {
1598 send_resp(dut, conn, SIGMA_ERROR,
1599 "errorCode,Unsupported OFDMA value");
1600 return STATUS_SENT_ERROR;
1601 }
1602 }
1603
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07001604 val = get_param(cmd, "NumSoundDim");
1605 if (val)
1606 dut->ap_numsounddim = atoi(val);
1607
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07001608 val = get_param(cmd, "BCC");
1609 if (val) {
1610 if (strcasecmp(val, "enable") == 0) {
1611 dut->ap_bcc = VALUE_ENABLED;
1612 dut->ap_ldpc = VALUE_DISABLED;
1613 } else if (strcasecmp(val, "disable") == 0) {
1614 dut->ap_ldpc = VALUE_ENABLED;
1615 dut->ap_bcc = VALUE_DISABLED;
1616 } else {
1617 send_resp(dut, conn, SIGMA_ERROR,
1618 "errorCode,Unsupported BCC value");
1619 return STATUS_SENT_ERROR;
1620 }
1621 }
1622
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07001623 val = get_param(cmd, "FrgmntSupport");
1624 if (val) {
1625 if (strcasecmp(val, "enable") == 0) {
1626 dut->ap_he_frag = VALUE_ENABLED;
1627 } else if (strcasecmp(val, "disable") == 0) {
1628 dut->ap_he_frag = VALUE_DISABLED;
1629 } else {
1630 send_resp(dut, conn, SIGMA_ERROR,
1631 "errorCode,Unsupported FrgmntSupport value");
1632 return STATUS_SENT_ERROR;
1633 }
1634 }
1635
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001636 return 1;
1637}
1638
1639
1640static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1641{
1642 char buf[256];
1643 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1644
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301645 if (tid < 0 ||
1646 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1647 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1648 return;
1649 }
1650
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001651 snprintf(buf, sizeof(buf),
1652 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1653 ifname, VI_QOS_TMP_FILE);
1654 if (system(buf) != 0)
1655 return;
1656
1657 snprintf(buf, sizeof(buf),
1658 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1659 ifname, VI_QOS_TMP_FILE);
1660 if (system(buf) != 0)
1661 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1662
1663 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1664 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1665 if (system(buf) != 0) {
1666 sigma_dut_print(dut, DUT_MSG_ERROR,
1667 "Output redirection to VI_QOS_TMP_FILE failed");
1668 }
1669
1670 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1671 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1672 if (system(buf) != 0) {
1673 sigma_dut_print(dut, DUT_MSG_ERROR,
1674 "Append TID to VI_QOS_FILE failed ");
1675 }
1676
1677 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1678 if (system(buf) != 0)
1679 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1680}
1681
1682
1683static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1684 struct sigma_cmd *cmd)
1685{
1686 const char *val;
1687 char *ifname;
1688 char buf[256];
1689 int tid = 0;
1690
1691 ifname = get_main_ifname();
1692 val = get_param(cmd, "TID");
1693 if (val) {
1694 tid = atoi(val);
1695 if (tid)
1696 ath_inject_frame(dut, ifname, tid);
1697 }
1698
1699 /* NOTE: This is the command sequence on Peregrine for ADDBA */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07001700 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001701
1702 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1703 ifname, tid);
1704 if (system(buf) != 0) {
1705 sigma_dut_print(dut, DUT_MSG_ERROR,
1706 "wifitool senddelba failed");
1707 }
1708
1709 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1710 ifname, tid);
1711 if (system(buf) != 0) {
1712 sigma_dut_print(dut, DUT_MSG_ERROR,
1713 "wifitool sendaddba failed");
1714 }
1715
1716 return 1;
1717}
1718
1719
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301720static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1721 const char *sta_mac,
1722 const char *dir_path)
1723{
1724 DIR *dir;
1725 struct dirent *entry;
1726 char buf[128], path[128];
Jouni Malinen3aa72862019-05-29 23:14:51 +03001727 int ret = 0, res;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301728
1729 dir = opendir(dir_path);
1730 if (!dir)
1731 return 0;
1732
1733 while ((entry = readdir(dir))) {
1734 ret = 1;
1735
1736 if (strcmp(entry->d_name, ".") == 0 ||
1737 strcmp(entry->d_name, "..") == 0)
1738 continue;
1739
Jouni Malinen3aa72862019-05-29 23:14:51 +03001740 res = snprintf(path, sizeof(path) - 1, "%s/%s",
1741 dir_path, entry->d_name);
1742 if (res < 0 || res >= sizeof(path))
1743 continue;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301744
1745 if (strcmp(entry->d_name, sta_mac) == 0) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03001746 res = snprintf(buf, sizeof(buf),
1747 "echo 1 > %s/aggr_mode", path);
1748 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301749 sigma_dut_print(dut, DUT_MSG_ERROR,
1750 "Failed to set aggr mode for ath10k");
1751 }
1752
Jouni Malinen3aa72862019-05-29 23:14:51 +03001753 res = snprintf(buf, sizeof(buf),
1754 "echo %d 32 > %s/addba", tid, path);
1755 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301756 sigma_dut_print(dut, DUT_MSG_ERROR,
1757 "Failed to set addbareq for ath10k");
1758 }
1759
1760 break;
1761 }
1762
1763 /* Recursively search subdirectories */
1764 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1765 }
1766
1767 closedir(dir);
1768
1769 return ret;
1770}
1771
1772
1773static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1774 struct sigma_cmd *cmd)
1775{
1776 const char *val;
1777 int tid = 0;
1778
1779 val = get_param(cmd, "TID");
1780 if (val)
1781 tid = atoi(val);
1782
1783 val = get_param(cmd, "sta_mac_address");
1784 if (!val) {
1785 sigma_dut_print(dut, DUT_MSG_ERROR,
1786 "Failed to parse station MAC address");
1787 return 0;
1788 }
1789
1790 return ath10k_debug_enable_addba_req(dut, tid, val,
1791 "/sys/kernel/debug/ieee80211");
1792}
1793
1794
Jouni Malinenf7222712019-06-13 01:50:21 +03001795static enum sigma_cmd_result cmd_ap_send_addba_req(struct sigma_dut *dut,
1796 struct sigma_conn *conn,
1797 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001798{
1799 /* const char *name = get_param(cmd, "NAME"); */
1800 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301801 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001802
1803 switch (get_driver_type()) {
1804 case DRIVER_ATHEROS:
1805 return ath_ap_send_addba_req(dut, conn, cmd);
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02001806#ifdef __linux__
1807 case DRIVER_WIL6210:
1808 return send_addba_60g(dut, conn, cmd, "sta_mac_address");
1809#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001810 case DRIVER_OPENWRT:
1811 switch (get_openwrt_driver_type()) {
1812 case OPENWRT_DRIVER_ATHEROS:
1813 return ath_ap_send_addba_req(dut, conn, cmd);
1814 default:
1815 send_resp(dut, conn, SIGMA_ERROR,
1816 "errorCode,ap_send_addba_req not supported with this driver");
1817 return 0;
1818 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301819 case DRIVER_WCN:
1820 case DRIVER_LINUX_WCN:
1821 /* AP automatically sends ADDBA request after association. */
1822 sigma_dut_print(dut, DUT_MSG_INFO,
1823 "ap_send_addba_req command ignored");
1824 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301825 case DRIVER_MAC80211:
1826 if (stat("/sys/module/ath10k_core", &s) == 0)
1827 return ath10k_ap_send_addba_req(dut, cmd);
1828 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001829 default:
1830 send_resp(dut, conn, SIGMA_ERROR,
1831 "errorCode,ap_send_addba_req not supported with this driver");
1832 return 0;
1833 }
1834}
1835
1836
Jouni Malinenf7222712019-06-13 01:50:21 +03001837static enum sigma_cmd_result cmd_ap_set_security(struct sigma_dut *dut,
1838 struct sigma_conn *conn,
1839 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001840{
1841 /* const char *name = get_param(cmd, "NAME"); */
1842 const char *val;
1843 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301844 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001845
1846 val = get_param(cmd, "WLAN_TAG");
1847 if (val)
1848 wlan_tag = atoi(val);
1849
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301850 security = get_param(cmd, "Security");
1851
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001852 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001853 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301854 if (!val)
1855 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001856 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001857 if (strcasecmp(val, "NONE") == 0) {
1858 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1859 } else if (strcasecmp(val, "OSEN") == 0 &&
1860 wlan_tag == 2) {
1861 /*
1862 * OSEN only supported on WLAN_TAG = 2 for now
1863 */
1864 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301865 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1866 (security &&
1867 strcasecmp(security, "PSK") == 0 &&
1868 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001869 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1870 AP2_WPA2_PSK;
Jouni Malinen353ba8b2018-01-10 17:04:12 +02001871 } else if (strcasecmp(val, "OWE") == 0 &&
1872 wlan_tag == 2) {
1873 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1874 AP2_WPA2_OWE;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001875 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001876 send_resp(dut, conn, SIGMA_INVALID,
1877 "errorCode,Unsupported KEYMGNT");
1878 return 0;
1879 }
1880 return 1;
1881 }
1882 }
1883
1884 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301885 if (!val)
1886 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001887 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301888 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1889 (security && strcasecmp(security, "PSK") == 0 &&
1890 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001891 dut->ap_key_mgmt = AP_WPA2_PSK;
1892 dut->ap_cipher = AP_CCMP;
1893 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1894 strcasecmp(val, "WPA2-Ent") == 0) {
1895 dut->ap_key_mgmt = AP_WPA2_EAP;
1896 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001897 } else if (strcasecmp(val, "SuiteB") == 0) {
1898 dut->ap_key_mgmt = AP_SUITEB;
1899 dut->ap_cipher = AP_GCMP_256;
Jouni Malinend75e4d82018-01-11 20:21:15 +02001900 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001901 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1902 dut->ap_key_mgmt = AP_WPA_PSK;
1903 dut->ap_cipher = AP_TKIP;
1904 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1905 strcasecmp(val, "WPA-Ent") == 0) {
1906 dut->ap_key_mgmt = AP_WPA_EAP;
1907 dut->ap_cipher = AP_TKIP;
1908 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1909 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1910 dut->ap_cipher = AP_CCMP_TKIP;
1911 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1912 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1913 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen794a7a32018-01-10 16:39:34 +02001914 } else if (strcasecmp(val, "WPA2-SAE") == 0 ||
1915 strcasecmp(val, "SAE") == 0) {
Jouni Malinen30824df2017-08-22 21:21:38 +03001916 dut->ap_key_mgmt = AP_WPA2_SAE;
1917 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001918 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen30824df2017-08-22 21:21:38 +03001919 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1920 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1921 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001922 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001923 } else if (strcasecmp(val, "OWE") == 0) {
1924 dut->ap_key_mgmt = AP_WPA2_OWE;
1925 dut->ap_cipher = AP_CCMP;
Jouni Malinen1287cd72018-01-04 17:08:01 +02001926 dut->ap_pmf = AP_PMF_REQUIRED;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03001927 } else if (strcasecmp(val, "WPA2-ENT-OSEN") == 0) {
1928 dut->ap_key_mgmt = AP_WPA2_EAP_OSEN;
1929 dut->ap_cipher = AP_CCMP;
1930 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinenc2b91212018-09-12 02:26:39 +03001931 } else if (strcasecmp(val, "OSEN") == 0) {
1932 dut->ap_key_mgmt = AP_OSEN;
1933 dut->ap_cipher = AP_CCMP;
Jouni Malinen6be21c82018-08-01 18:47:24 +03001934 } else if (strcasecmp(val, "FT-EAP") == 0) {
1935 dut->ap_key_mgmt = AP_WPA2_FT_EAP;
1936 dut->ap_cipher = AP_CCMP;
1937 dut->ap_pmf = AP_PMF_OPTIONAL;
1938 } else if (strcasecmp(val, "FT-PSK") == 0) {
1939 dut->ap_key_mgmt = AP_WPA2_FT_PSK;
1940 dut->ap_cipher = AP_CCMP;
1941 dut->ap_pmf = AP_PMF_OPTIONAL;
1942 } else if (strcasecmp(val, "WPA2-ENT-256") == 0) {
1943 dut->ap_key_mgmt = AP_WPA2_EAP_SHA256;
1944 dut->ap_cipher = AP_CCMP;
1945 dut->ap_pmf = AP_PMF_OPTIONAL;
1946 } else if (strcasecmp(val, "WPA2-PSK-256") == 0) {
1947 dut->ap_key_mgmt = AP_WPA2_PSK_SHA256;
1948 dut->ap_cipher = AP_CCMP;
1949 dut->ap_pmf = AP_PMF_OPTIONAL;
1950 } else if (strcasecmp(val, "WPA2-ENT-FT-EAP") == 0) {
1951 dut->ap_key_mgmt = AP_WPA2_ENT_FT_EAP;
1952 dut->ap_cipher = AP_CCMP;
1953 dut->ap_pmf = AP_PMF_OPTIONAL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001954 } else if (strcasecmp(val, "NONE") == 0) {
1955 dut->ap_key_mgmt = AP_OPEN;
1956 dut->ap_cipher = AP_PLAIN;
1957 } else {
1958 send_resp(dut, conn, SIGMA_INVALID,
1959 "errorCode,Unsupported KEYMGNT");
1960 return 0;
1961 }
1962 }
1963
Jouni Malinen30824df2017-08-22 21:21:38 +03001964 val = get_param(cmd, "ECGroupID");
1965 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001966 free(dut->ap_sae_groups);
1967 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001968 }
1969
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001970 val = get_param(cmd, "AntiCloggingThreshold");
1971 if (val)
1972 dut->sae_anti_clogging_threshold = atoi(val);
1973
Jouni Malinenb347db02017-09-02 01:36:03 +03001974 val = get_param(cmd, "Reflection");
1975 if (val)
1976 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1977
Jouni Malinen68143132017-09-02 02:34:08 +03001978 val = get_param(cmd, "InvalidSAEElement");
1979 if (val) {
1980 free(dut->sae_commit_override);
1981 dut->sae_commit_override = strdup(val);
1982 }
1983
Jouni Malinen09550de2019-03-26 00:24:11 +02001984 val = get_param(cmd, "SAEPasswords");
1985 if (val) {
1986 free(dut->ap_sae_passwords);
1987 dut->ap_sae_passwords = strdup(val);
1988 }
1989
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001990 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301991 if (!val)
1992 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001993 if (val) {
1994 if (strcasecmp(val, "WEP") == 0) {
1995 dut->ap_cipher = AP_WEP;
1996 } else if (strcasecmp(val, "TKIP") == 0) {
1997 dut->ap_cipher = AP_TKIP;
1998 } else if (strcasecmp(val, "AES") == 0 ||
1999 strcasecmp(val, "AES-CCMP") == 0) {
2000 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002001 } else if (strcasecmp(val, "AES-GCMP") == 0) {
2002 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002003 } else {
2004 send_resp(dut, conn, SIGMA_INVALID,
2005 "errorCode,Unsupported ENCRYPT");
2006 return 0;
2007 }
2008 }
2009
Jouni Malinen3d633da2017-09-14 22:19:21 +03002010 val = get_param(cmd, "PairwiseCipher");
2011 if (val) {
2012 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2013 dut->ap_cipher = AP_GCMP_256;
2014 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2015 dut->ap_cipher = AP_CCMP_256;
2016 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2017 dut->ap_cipher = AP_GCMP_128;
2018 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2019 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02002020 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
2021 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
2022 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03002023 } else {
2024 send_resp(dut, conn, SIGMA_INVALID,
2025 "errorCode,Unsupported PairwiseCipher");
2026 return 0;
2027 }
2028 }
2029
Jouni Malinen2ba24492017-11-17 12:43:59 +02002030 val = get_param(cmd, "GroupCipher");
2031 if (val) {
2032 if (strcasecmp(val, "AES-GCMP-256") == 0) {
2033 dut->ap_group_cipher = AP_GCMP_256;
2034 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
2035 dut->ap_group_cipher = AP_CCMP_256;
2036 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
2037 dut->ap_group_cipher = AP_GCMP_128;
2038 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
2039 dut->ap_group_cipher = AP_CCMP;
2040 } else {
2041 send_resp(dut, conn, SIGMA_INVALID,
2042 "errorCode,Unsupported GroupCipher");
2043 return 0;
2044 }
2045 }
2046
Jouni Malinen3d633da2017-09-14 22:19:21 +03002047 val = get_param(cmd, "GroupMgntCipher");
2048 if (val) {
2049 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
2050 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
2051 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
2052 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
2053 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2054 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
2055 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2056 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
2057 } else {
2058 send_resp(dut, conn, SIGMA_INVALID,
2059 "errorCode,Unsupported GroupMgntCipher");
2060 return 0;
2061 }
2062 }
2063
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002064 val = get_param(cmd, "WEPKEY");
2065 if (val) {
2066 size_t len;
2067 if (dut->ap_cipher != AP_WEP) {
2068 send_resp(dut, conn, SIGMA_INVALID,
2069 "errorCode,Unexpected WEPKEY without WEP "
2070 "configuration");
2071 return 0;
2072 }
2073 len = strlen(val);
2074 if (len != 10 && len != 26) {
2075 send_resp(dut, conn, SIGMA_INVALID,
2076 "errorCode,Unexpected WEPKEY length");
2077 return 0;
2078 }
2079 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
2080 }
2081
2082 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302083 if (!val)
2084 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002085 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002086 if (dut->ap_key_mgmt != AP_WPA2_SAE &&
2087 (dut->ap_akm_values & (AKM_WPA_PSK | AKM_SAE)) !=
2088 AKM_SAE &&
2089 strlen(val) > 64) {
2090 sigma_dut_print(dut, DUT_MSG_ERROR,
2091 "Too long PSK/passphtase");
Jouni Malinen2126f422017-10-11 23:24:33 +03002092 return -1;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002093 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002094 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
2095 return -1;
2096 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
2097 "%s", val);
2098 }
2099
Jouni Malinen63370622017-11-18 17:47:13 +02002100 val = get_param(cmd, "PSKHEX");
2101 if (val) {
2102 if (strlen(val) != 64)
2103 return -1;
2104 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
2105 }
2106
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302107 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
2108 dut->ap_pmf = AP_PMF_OPTIONAL;
2109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110 val = get_param(cmd, "PMF");
2111 if (val) {
2112 if (strcasecmp(val, "Disabled") == 0) {
2113 dut->ap_pmf = AP_PMF_DISABLED;
2114 } else if (strcasecmp(val, "Optional") == 0) {
2115 dut->ap_pmf = AP_PMF_OPTIONAL;
2116 } else if (strcasecmp(val, "Required") == 0) {
2117 dut->ap_pmf = AP_PMF_REQUIRED;
2118 } else {
2119 send_resp(dut, conn, SIGMA_INVALID,
2120 "errorCode,Unsupported PMF");
2121 return 0;
2122 }
2123 }
2124
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002125 dut->ap_add_sha256 = 0;
2126 val = get_param(cmd, "SHA256AD");
2127 if (val == NULL)
2128 val = get_param(cmd, "SHA256");
2129 if (val) {
2130 if (strcasecmp(val, "Disabled") == 0) {
2131 } else if (strcasecmp(val, "Enabled") == 0) {
2132 dut->ap_add_sha256 = 1;
2133 } else {
2134 send_resp(dut, conn, SIGMA_INVALID,
Jouni Malinena7fa6202019-03-26 00:22:10 +02002135 "errorCode,Unsupported SHA256");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002136 return 0;
2137 }
2138 }
2139
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302140 val = get_param(cmd, "PreAuthentication");
2141 if (val) {
2142 if (strcasecmp(val, "disabled") == 0) {
2143 dut->ap_rsn_preauth = 0;
2144 } else if (strcasecmp(val, "enabled") == 0) {
2145 dut->ap_rsn_preauth = 1;
2146 } else {
2147 send_resp(dut, conn, SIGMA_INVALID,
2148 "errorCode,Unsupported PreAuthentication value");
2149 return 0;
2150 }
2151 }
2152
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002153 val = get_param(cmd, "AKMSuiteType");
2154 if (val) {
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002155 const char *in_pos = val;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002156
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002157 dut->ap_akm_values = 0;
2158 while (*in_pos) {
2159 int akm = atoi(in_pos);
2160
2161 if (akm < 0 || akm >= 32) {
2162 send_resp(dut, conn, SIGMA_ERROR,
2163 "errorCode,Unsupported AKMSuiteType value");
2164 return STATUS_SENT;
2165 }
2166
2167 dut->ap_akm_values |= 1 << akm;
2168
2169 in_pos = strchr(in_pos, ';');
2170 if (!in_pos)
2171 break;
2172 while (*in_pos == ';')
2173 in_pos++;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002174 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02002175 dut->ap_akm = 1;
2176 if (dut->ap_akm_values & (1 << 14))
2177 dut->ap_add_sha384 = 1;
2178 if (dut->ap_akm_values & (1 << 15))
2179 dut->ap_add_sha384 = 1;
2180 }
2181
2182 if (dut->ap_key_mgmt == AP_OPEN && !dut->ap_akm_values) {
2183 dut->ap_hs2 = 0;
2184 dut->ap_pmf = AP_PMF_DISABLED;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08002185 }
2186
2187 val = get_param(cmd, "PMKSACaching");
2188 if (val) {
2189 dut->ap_pmksa = 1;
2190 if (strcasecmp(val, "disabled") == 0) {
2191 dut->ap_pmksa_caching = 1;
2192 } else if (strcasecmp(val, "enabled") == 0) {
2193 dut->ap_pmksa_caching = 0;
2194 } else {
2195 send_resp(dut, conn, SIGMA_INVALID,
2196 "errorCode,Unsupported PMKSACaching value");
2197 return 0;
2198 }
2199 }
2200
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002201 return 1;
2202}
2203
2204
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302205int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
2206 struct sigma_cmd *cmd)
2207{
2208 int status;
2209
2210 status = cmd_ap_set_wireless(dut, conn, cmd);
2211 if (status != 1)
2212 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05302213 status = cmd_ap_set_security(dut, conn, cmd);
2214 if (status != 1)
2215 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05302216 return cmd_ap_config_commit(dut, conn, cmd);
2217}
2218
2219
Jouni Malinenf7222712019-06-13 01:50:21 +03002220static enum sigma_cmd_result cmd_ap_set_radius(struct sigma_dut *dut,
2221 struct sigma_conn *conn,
2222 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002223{
2224 /* const char *name = get_param(cmd, "NAME"); */
2225 const char *val;
2226 unsigned int wlan_tag = 1, radius_port = 0;
2227 char *radius_ipaddr = NULL, *radius_password = NULL;
2228
2229 val = get_param(cmd, "WLAN_TAG");
2230 if (val) {
2231 wlan_tag = atoi(val);
2232 if (wlan_tag != 1 && wlan_tag != 2) {
2233 send_resp(dut, conn, SIGMA_INVALID,
2234 "errorCode,Invalid WLAN_TAG");
2235 return 0;
2236 }
2237 }
2238
2239 val = get_param(cmd, "PORT");
2240 if (val)
2241 radius_port = atoi(val);
2242
2243 if (wlan_tag == 1) {
2244 if (radius_port)
2245 dut->ap_radius_port = radius_port;
2246 radius_ipaddr = dut->ap_radius_ipaddr;
2247 radius_password = dut->ap_radius_password;
2248 } else if (wlan_tag == 2) {
2249 if (radius_port)
2250 dut->ap2_radius_port = radius_port;
2251 radius_ipaddr = dut->ap2_radius_ipaddr;
2252 radius_password = dut->ap2_radius_password;
2253 }
2254
2255 val = get_param(cmd, "IPADDR");
2256 if (val) {
2257 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
2258 return -1;
2259 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
2260 "%s", val);
2261 }
2262
2263 val = get_param(cmd, "PASSWORD");
2264 if (val) {
2265 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
2266 return -1;
2267 snprintf(radius_password,
2268 sizeof(dut->ap_radius_password), "%s", val);
2269 }
2270
2271 return 1;
2272}
2273
2274
2275static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
2276 const char *key, const char *val)
2277{
2278 char buf[100];
2279
2280 if (val == NULL) {
2281 snprintf(buf, sizeof(buf),
2282 "uci delete wireless.wifi%d.%s", id, key);
2283 run_system(dut, buf);
2284 return;
2285 }
2286
2287 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
2288 id, key, val);
2289 run_system(dut, buf);
2290}
2291
2292
2293static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
2294 const char *key, const char *val)
2295{
2296 char buf[256];
2297
2298 if (val == NULL) {
2299 snprintf(buf, sizeof(buf),
2300 "uci del_list wireless.wifi%d.%s", id, key);
2301 run_system(dut, buf);
2302 return;
2303 }
2304
2305 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
2306 id, key, val);
2307 run_system(dut, buf);
2308}
2309
2310
2311static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
2312 const char *val)
2313{
2314 char buf[256];
2315
2316 if (val == NULL) {
2317 snprintf(buf, sizeof(buf),
2318 "uci delete wireless.@wifi-iface[%d].%s", id, key);
2319 run_system(dut, buf);
2320 return;
2321 }
2322
2323 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2324 id, key, val);
2325 run_system(dut, buf);
2326}
2327
2328
2329static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
2330 const char *key, const char *val)
2331{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002332 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002333
2334 if (val == NULL) {
2335 snprintf(buf, sizeof(buf),
2336 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
2337 run_system(dut, buf);
2338 return;
2339 }
2340
2341 snprintf(buf, sizeof(buf),
2342 "uci add_list wireless.@wifi-iface[%d].%s=%s",
2343 id, key, val);
2344 run_system(dut, buf);
2345}
2346
2347
2348static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
2349 const char *val)
2350{
2351 char buf[256];
Jouni Malinen3aa72862019-05-29 23:14:51 +03002352 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002353
2354 if (val == NULL) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002355 res = snprintf(buf, sizeof(buf),
2356 "uci delete wireless.@wifi-iface[%d].%s",
2357 id, key);
2358 if (res >= 0 && res < sizeof(buf))
2359 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002360 return;
2361 }
2362
Jouni Malinen3aa72862019-05-29 23:14:51 +03002363 run_system(dut, "uci add wireless wifi-iface");
2364 res = snprintf(buf, sizeof(buf),
2365 "uci set wireless.@wifi-iface[%d].%s=%s",
2366 id, key, val);
2367 if (res >= 0 && res < sizeof(buf))
2368 run_system(dut, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002369 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2370 id, "network", "lan");
2371 run_system(dut, buf);
2372 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2373 id, "mode", "ap");
2374 run_system(dut, buf);
2375 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
2376 id, "encryption", "none");
2377 run_system(dut, buf);
2378}
2379
2380
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002381#define OPENWRT_MAX_NUM_RADIOS (MAX_RADIO + 1)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002382static void owrt_ap_config_radio(struct sigma_dut *dut)
2383{
Alejandro Vasquez363f5582018-07-17 11:25:05 -07002384 int radio_id[MAX_RADIO] = { 0, 1, 2 };
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002385 int radio_count, radio_no;
2386 char buf[64];
2387
2388 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
2389 radio_count++) {
2390 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
2391 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
2392 if (!sigma_radio_ifname[radio_no] ||
2393 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
2394 continue;
2395 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
2396 owrt_ap_set_vap(dut, radio_count, "device", buf);
2397 radio_id[radio_no] = radio_count;
2398 }
2399 }
2400
2401 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2402 switch (dut->ap_mode) {
2403 case AP_11g:
2404 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
2405 break;
2406 case AP_11b:
2407 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
2408 break;
2409 case AP_11ng:
2410 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2411 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2412 break;
2413 case AP_11a:
2414 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
2415 break;
2416 case AP_11na:
2417 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
2418 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2419 break;
2420 case AP_11ac:
2421 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
2422 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2423 break;
2424 case AP_inval:
2425 sigma_dut_print(dut, DUT_MSG_ERROR,
2426 "MODE NOT SPECIFIED!");
2427 return;
2428 default:
2429 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
2430 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2431 break;
2432 }
2433
2434 if (dut->ap_is_dual) {
2435 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
2436 switch (dut->ap_mode_1) {
2437 case AP_11g:
2438 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
2439 break;
2440 case AP_11b:
2441 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
2442 break;
2443 case AP_11ng:
2444 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2445 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2446 break;
2447 case AP_11a:
2448 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
2449 break;
2450 case AP_11na:
2451 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
2452 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2453 break;
2454 case AP_11ac:
2455 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
2456 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
2457 break;
2458 case AP_inval:
2459 sigma_dut_print(dut, DUT_MSG_ERROR,
2460 "MODE NOT SPECIFIED!");
2461 return;
2462 default:
2463 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
2464 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
2465 break;
2466 }
2467
2468 }
2469
2470 /* Channel */
2471 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
2472 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
2473
2474 switch (dut->ap_chwidth) {
2475 case AP_20:
2476 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
2477 break;
2478 case AP_40:
2479 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
2480 break;
2481 case AP_80:
2482 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
2483 break;
2484 case AP_160:
2485 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
2486 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08002487 case AP_80_80:
2488 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80_80");
2489 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002490 case AP_AUTO:
2491 default:
2492 break;
2493 }
2494
2495 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
2496 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2497 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
2498 }
2499
2500 if (dut->ap_is_dual) {
2501 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
2502 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
2503 }
2504
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002505 /* Country Code */
2506 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
2507 const char *country;
2508
2509 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
2510 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002511 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
priyadharshini gowthaman27406b02017-12-28 15:35:45 -08002512 if (dut->ap_is_dual)
2513 owrt_ap_set_radio(dut, radio_id[1], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07002514 } else if (dut->ap_countrycode[0]) {
2515 owrt_ap_set_radio(dut, radio_id[0], "country",
2516 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002517 }
2518
2519 if (dut->ap_disable_protection == 1) {
2520 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
2521 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
2522 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
2523 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
2524 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08002525
2526 if (dut->ap_oce == VALUE_ENABLED &&
2527 get_driver_type() == DRIVER_OPENWRT)
2528 owrt_ap_set_radio(dut, radio_id[0], "bcnburst", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002529}
2530
2531
2532static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
2533{
2534 char buf[256];
2535
2536 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
2537 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
2538 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
2539 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
2540
2541 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2542 "'eng:Wi-Fi Alliance'");
2543
2544 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
2545 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
2546
2547 if (dut->ap_wan_metrics == 1)
2548 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2549 "'01:2500:384:0:0:10'");
2550 else if (dut->ap_wan_metrics == 1)
2551 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2552 "'01:1500:384:20:20:10'");
2553 else if (dut->ap_wan_metrics == 2)
2554 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2555 "'01:1500:384:20:20:10'");
2556 else if (dut->ap_wan_metrics == 3)
2557 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2558 "'01:2000:1000:20:20:10'");
2559 else if (dut->ap_wan_metrics == 4)
2560 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2561 "'01:8000:1000:20:20:10'");
2562 else if (dut->ap_wan_metrics == 5)
2563 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
2564 "'01:9000:5000:20:20:10'");
2565
2566 if (dut->ap_conn_capab == 1) {
2567 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
2568 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2569 "'6:20:1'");
2570 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2571 "'6:22:0'");
2572 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2573 "'6:80:1'");
2574 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2575 "'6:443:1'");
2576 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2577 "'6:1723:0'");
2578 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2579 "'6:5060:0'");
2580 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2581 "'17:500:1'");
2582 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2583 "'17:5060:0'");
2584 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2585 "'17:4500:1'");
2586 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2587 "'50:0:1'");
2588 } else if (dut->ap_conn_capab == 2) {
2589 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2590 "'6:80:1'");
2591 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2592 "'6:443:1'");
2593 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2594 "'17:5060:1'");
2595 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2596 "'6:5060:1'");
2597 } else if (dut->ap_conn_capab == 3) {
2598 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2599 "'6:80:1'");
2600 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2601 "'6:443:1'");
2602 }
2603
2604 if (dut->ap_oper_class == 1)
2605 snprintf(buf, sizeof(buf), "%s", "51");
2606 else if (dut->ap_oper_class == 2)
2607 snprintf(buf, sizeof(buf), "%s", "73");
2608 else if (dut->ap_oper_class == 3)
2609 snprintf(buf, sizeof(buf), "%s", "5173");
2610
2611 if (dut->ap_oper_class)
2612 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2613
2614 if (dut->ap_osu_provider_list) {
2615 char *osu_friendly_name = NULL;
2616 char *osu_icon = NULL;
2617 char *osu_ssid = NULL;
2618 char *osu_nai = NULL;
2619 char *osu_service_desc = NULL;
2620 char *hs20_icon_filename = NULL;
2621 char hs20_icon[150];
2622 int osu_method;
2623
2624 hs20_icon_filename = "icon_red_zxx.png";
2625 if (dut->ap_osu_icon_tag == 2)
2626 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2627 snprintf(hs20_icon, sizeof(hs20_icon),
2628 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2629 hs20_icon_filename);
2630 osu_icon = "icon_red_zxx.png";
2631 osu_ssid = "OSU";
2632 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2633 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2634 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2635 dut->ap_osu_method[0];
2636
2637 if (strlen(dut->ap_osu_server_uri[0]))
2638 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2639 dut->ap_osu_server_uri[0]);
2640 else
2641 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2642 "'https://osu-server.r2-testbed.wi-fi.org/'");
2643 switch (dut->ap_osu_provider_list) {
2644 case 1:
2645 case 101:
2646 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2647 "'eng:SP Red Test Only'");
2648 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2649 "'eng:Free service for test purpose'");
2650 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2651 hs20_icon);
2652
2653 hs20_icon_filename = "icon_red_eng.png";
2654 if (dut->ap_osu_icon_tag == 2)
2655 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2656
2657 snprintf(hs20_icon, sizeof(hs20_icon),
2658 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2659 hs20_icon_filename);
2660 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2661 "icon_red_eng.png");
2662 break;
2663 case 2:
2664 case 102:
2665 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2666 "'eng:Wireless Broadband Alliance'");
2667 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2668 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002669 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002670 if (dut->ap_osu_icon_tag == 2)
2671 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2672
2673 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002674 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002675 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002676 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002677 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2678 break;
2679 case 3:
2680 case 103:
Jouni Malinen02502de2018-10-15 17:19:33 +03002681 osu_friendly_name = "'spa:SP Red Test Only'";
2682 osu_service_desc = "'spa:Free service for test purpose'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002683 break;
2684 case 4:
2685 case 104:
2686 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002687 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002688 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2689 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002690 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002691 if (dut->ap_osu_icon_tag == 2)
2692 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2693
2694 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002695 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002696 hs20_icon_filename);
2697 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2698 hs20_icon);
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002699 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002700
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002701 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002702 if (dut->ap_osu_icon_tag == 2)
2703 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2704
2705 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002706 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002707 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002708 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002709 break;
2710 case 5:
2711 case 105:
2712 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002713 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002714 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2715 "'eng:Free service for test purpose'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002716 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002717
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002718 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002719 if (dut->ap_osu_icon_tag == 2)
2720 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2721
2722 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002723 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002724 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002725 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 break;
2727 case 6:
2728 case 106:
2729 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2730 "'eng:SP Green Test Only'");
2731 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2732 "'kor:SP 초록 테스트 전용'");
2733
2734 hs20_icon_filename = "icon_green_zxx.png";
2735 if (dut->ap_osu_icon_tag == 2)
2736 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2737
2738 snprintf(hs20_icon, sizeof(hs20_icon),
2739 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2740 hs20_icon_filename);
2741 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2742 hs20_icon);
2743
2744 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2745 "'icon_green_zxx.png'");
2746 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2747 dut->ap_osu_method[0];
2748
2749 snprintf(buf, sizeof(buf), "%d", osu_method);
2750 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2751
2752 if (strlen(dut->ap_osu_server_uri[1]))
2753 owrt_ap_set_list_vap(dut, vap_id,
2754 "osu_server_uri",
2755 dut->ap_osu_server_uri[1]);
2756 else
2757 owrt_ap_set_list_vap(dut, vap_id,
2758 "osu_server_uri",
2759 "'https://osu-server.r2-testbed.wi-fi.org/'");
2760
2761 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2762 "'eng:SP Orange Test Only'");
2763
2764 hs20_icon_filename = "icon_orange_zxx.png";
2765 if (dut->ap_osu_icon_tag == 2)
2766 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2767
2768 snprintf(hs20_icon, sizeof(hs20_icon),
2769 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2770 hs20_icon_filename);
2771
2772 osu_icon = "icon_orange_zxx.png";
2773 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2774 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2775 dut->ap_osu_method[1];
2776 osu_service_desc = NULL;
2777 break;
2778 case 7:
2779 case 107:
2780 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002781 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2783 "'eng:Free service for test purpose'");
2784
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002785 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002786 if (dut->ap_osu_icon_tag == 2)
2787 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2788
2789 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002790 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002791 hs20_icon_filename);
2792 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2793 hs20_icon);
2794
2795 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002796 "'icon_green_eng.png'");
Jouni Malinenfd45ad52018-10-15 17:06:18 +03002797 osu_friendly_name = "'kor:SP 초록 테스트 전용'";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002798
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002799 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002800 if (dut->ap_osu_icon_tag == 2)
2801 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2802
2803 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002804 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002805 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002806 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002807 break;
2808 case 8:
2809 case 108:
2810 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2811 "'eng:SP Red Test Only'");
2812 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2813 "'eng:Free service for test purpose'");
2814 osu_ssid = "OSU-Encrypted";
2815 osu_nai = "'anonymous@hotspot.net'";
2816 break;
2817 case 9:
2818 case 109:
2819 osu_ssid = "OSU-OSEN";
2820 osu_nai = "'test-anonymous@wi-fi.org'";
2821 osu_friendly_name = "'eng:SP Orange Test Only'";
2822 hs20_icon_filename = "icon_orange_zxx.png";
2823 if (dut->ap_osu_icon_tag == 2)
2824 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2825
2826 snprintf(hs20_icon, sizeof(hs20_icon),
2827 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2828 hs20_icon_filename);
2829 osu_icon = "icon_orange_zxx.png";
2830 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2831 dut->ap_osu_method[0];
2832 osu_service_desc = NULL;
2833 break;
2834 default:
2835 break;
2836 }
2837
2838 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03002839 if (dut->ap_tag_ssid[0][0] &&
2840 strcmp(dut->ap_tag_ssid[0],
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002841 dut->ap_osu_ssid) != 0 &&
2842 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002843 sigma_dut_print(dut, DUT_MSG_ERROR,
2844 "OSU_SSID and WLAN_TAG2 SSID differ");
2845 return -2;
2846 }
2847
2848 snprintf(buf, sizeof(buf), "'\"%s\"'",
2849 dut->ap_osu_ssid);
2850 } else {
2851 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2852 }
2853
2854 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2855
2856
2857 if (osu_friendly_name)
2858 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2859 osu_friendly_name);
2860 if (osu_service_desc)
2861 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2862 osu_service_desc);
2863 if (osu_nai)
2864 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2865
2866 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2867
2868 if (osu_icon)
2869 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2870 osu_icon);
2871
2872 if (dut->ap_osu_provider_list > 100) {
2873 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2874 "0");
2875 } else {
2876 snprintf(buf, sizeof(buf), "%d", osu_method);
2877 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2878 buf);
2879 }
2880 }
2881
2882 return 0;
2883}
2884
2885
Jouni Malinen13701222019-02-19 12:10:53 +02002886static int set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2887 char *anqp_string, size_t str_size)
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002888{
2889 unsigned char bssid[ETH_ALEN];
2890 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2891 int preference = 0xff;
2892
Jouni Malinen13701222019-02-19 12:10:53 +02002893 if (get_hwaddr(ifname, bssid) < 0)
2894 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002895 snprintf(anqp_string, str_size,
2896 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2897 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2898 preference,
2899 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2900 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2901 preference - 1);
Jouni Malinen13701222019-02-19 12:10:53 +02002902 return 0;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002903}
2904
2905
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002906static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2907 size_t str_size, int wlan_tag)
2908{
Jouni Malinenf8984642017-10-12 00:02:37 +03002909 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002910 enum driver_type drv;
2911
2912 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002913 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2914 ifname = dut->hostapd_ifname;
2915 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002916 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2917 dut->ap_mode == AP_11ac) &&
2918 if_nametoindex("ath1") > 0)
2919 ifname = "ath1";
2920 else
2921 ifname = "ath0";
2922 } else if (drv == DRIVER_OPENWRT) {
2923 if (sigma_radio_ifname[0] &&
2924 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2925 ifname = "ath2";
2926 else if (sigma_radio_ifname[0] &&
2927 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2928 ifname = "ath1";
2929 else
2930 ifname = "ath0";
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02002931 } else if (drv == DRIVER_WIL6210) {
2932 ifname = get_main_ifname();
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002933 } else {
2934 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2935 dut->ap_mode == AP_11ac) &&
2936 if_nametoindex("wlan1") > 0)
2937 ifname = "wlan1";
2938 else
2939 ifname = "wlan0";
2940 }
2941
2942 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2943 /* Handle tagged-ifname only on OPENWRT for now */
2944 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Liangwei Dong83572892019-01-10 13:51:48 +08002945 } else if ((drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN) &&
2946 wlan_tag == 2) {
Jouni Malinenf8984642017-10-12 00:02:37 +03002947 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002948 } else {
2949 snprintf(ifname_str, str_size, "%s", ifname);
2950 }
2951}
2952
2953
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002954static int owrt_ap_config_vap(struct sigma_dut *dut)
2955{
2956 char buf[256], *temp;
Jouni Malinen3aa72862019-05-29 23:14:51 +03002957 int vap_id = 0, vap_count, i, j, res;
priyadharshini gowthaman04547062018-01-15 11:59:55 -08002958 const char *ifname;
2959 char ifname2[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002960
priyadharshini gowthaman73561262018-02-20 13:24:59 -08002961 if (sigma_radio_ifname[0] &&
2962 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2963 ifname = "ath2";
2964 else if (sigma_radio_ifname[0] &&
2965 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2966 ifname = "ath1";
2967 else
2968 ifname = "ath0";
2969
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002970 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002971 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002972
2973 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2974 if (sigma_radio_ifname[vap_id] &&
2975 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2976 break;
2977 }
2978 if (vap_id == MAX_RADIO)
2979 continue;
2980
2981 /* Single VAP configuration */
2982 if (!dut->ap_is_dual)
2983 vap_id = vap_count;
2984
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002985 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2986 /*
2987 * We keep a separate array of ap_tag_ssid and
2988 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2989 * So j=0 => WLAN_TAG = 2
2990 */
2991 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002992
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08002993 if (wlan_tag == 2 && dut->program == PROGRAM_WPA3 &&
2994 (dut->ap_interface_5g || dut->ap_interface_2g)) {
Jouni Malinen3aa72862019-05-29 23:14:51 +03002995 res = snprintf(
2996 dut->ap_tag_ssid[wlan_tag - 2],
2997 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
2998 "%s-owe", dut->ap_ssid);
2999 if (res < 0 ||
3000 res >= sizeof(dut->ap_tag_ssid[wlan_tag -
3001 2]))
3002 dut->ap_tag_ssid[wlan_tag - 2][0] =
3003 '\0';
priyadharshini gowthaman0e209fc2018-01-26 15:15:37 -08003004 }
3005
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003006 if (dut->ap_tag_ssid[j][0] == '\0')
3007 continue;
3008
3009 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
3010 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
3011 "device", buf);
3012 /* SSID */
3013 snprintf(buf, sizeof(buf), "\"%s\"",
3014 dut->ap_tag_ssid[j]);
3015 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3016 "ssid", buf);
3017
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003018 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3019 dut->ap_tag_ssid[0][0] &&
3020 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3021 /* OWE transition mode */
3022 snprintf(buf, sizeof(buf), "%s", ifname);
3023 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3024 "owe_transition_ifname", buf);
3025 }
3026
3027 if (dut->ap_key_mgmt == AP_OPEN &&
3028 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3029 /* OWE transition mode */
3030 snprintf(buf, sizeof(buf), "%s", ifname);
3031 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3032 "owe_transition_ifname", buf);
3033 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3034 "hidden", "1");
3035 }
3036
Jouni Malinen6be21c82018-08-01 18:47:24 +03003037 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003038 unsigned char self_mac[ETH_ALEN];
3039 char mac_str[20];
3040
3041 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3042 "mobility_domain",
3043 dut->ap_mobility_domain);
3044 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Jouni Malinen9f943312019-08-19 23:49:16 +03003045 "ft_over_ds",
3046 dut->ap_ft_ds == VALUE_ENABLED ?
3047 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003048 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3049 "ieee80211r", "1");
3050 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3051 "nasid", "nas1.example.com");
Jouni Malinen13701222019-02-19 12:10:53 +02003052 if (get_hwaddr(sigma_radio_ifname[0],
3053 self_mac) < 0)
3054 return -1;
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003055 snprintf(mac_str, sizeof(mac_str),
3056 "%02x:%02x:%02x:%02x:%02x:%02x",
3057 self_mac[0], self_mac[1], self_mac[2],
3058 self_mac[3], self_mac[4], self_mac[5]);
3059 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3060 "ap_macaddr", mac_str);
3061 snprintf(mac_str, sizeof(mac_str),
3062 "%02x%02x%02x%02x%02x%02x",
3063 self_mac[0], self_mac[1], self_mac[2],
3064 self_mac[3], self_mac[4], self_mac[5]);
3065 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3066 "r1_key_holder", mac_str);
3067 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3068 "ft_psk_generate_local", "1");
3069 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3070 "kh_key_hex",
3071 "000102030405060708090a0b0c0d0e0f");
3072 snprintf(mac_str, sizeof(mac_str),
3073 "%02x:%02x:%02x:%02x:%02x:%02x",
3074 dut->ft_bss_mac_list[0][0],
3075 dut->ft_bss_mac_list[0][1],
3076 dut->ft_bss_mac_list[0][2],
3077 dut->ft_bss_mac_list[0][3],
3078 dut->ft_bss_mac_list[0][4],
3079 dut->ft_bss_mac_list[0][5]);
3080 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3081 "ap2_macaddr", mac_str);
3082 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3083 "ap2_r1_key_holder", mac_str);
3084 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3085 "nasid2", "nas2.example.com");
3086 }
3087
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003088 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
3089 wlan_tag == 2) {
3090 /* Only supported for WLAN_TAG=2 */
3091 owrt_ap_set_vap(dut, vap_count + 1, "osen",
3092 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003093 snprintf(buf, sizeof(buf), "wpa2");
3094 owrt_ap_set_vap(dut, vap_count + 1,
3095 "encryption", buf);
3096 snprintf(buf, sizeof(buf), "%s",
3097 dut->ap2_radius_ipaddr);
3098 owrt_ap_set_vap(dut, vap_count + 1,
3099 "auth_server", buf);
3100 snprintf(buf, sizeof(buf), "%d",
3101 dut->ap2_radius_port);
3102 owrt_ap_set_vap(dut, vap_count + 1,
3103 "auth_port", buf);
3104 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003105 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003106 owrt_ap_set_vap(dut, vap_count + 1,
3107 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003108 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
3109 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3110 "encryption", "psk2+ccmp");
3111 snprintf(buf, sizeof(buf), "\"%s\"",
3112 dut->ap_passphrase);
3113 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3114 "key", buf);
3115 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003116 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003117 "ieee80211w", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003118 } else if (dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3119 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3120 "owe", "1");
3121 snprintf(buf, sizeof(buf), "ccmp");
3122 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3123 "encryption", buf);
3124 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
3125 "ieee80211w", "2");
3126 if (dut->ap_sae_groups) {
3127 snprintf(buf, sizeof(buf), "\'%s\'",
3128 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003129 owrt_ap_set_list_vap(dut, vap_count +
3130 (wlan_tag - 1),
3131 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003132 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003133 }
3134 }
3135
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003136 /* Now set anqp_elem and ft_oa for wlan_tag = 1 */
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003137 if (dut->program == PROGRAM_MBO &&
3138 get_driver_type() == DRIVER_OPENWRT) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003139 unsigned char self_mac[ETH_ALEN];
3140 char mac_str[20];
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003141 char anqp_string[200];
3142
Jouni Malinen13701222019-02-19 12:10:53 +02003143 if (set_anqp_elem_value(dut, sigma_radio_ifname[0],
3144 anqp_string,
3145 sizeof(anqp_string)) < 0)
3146 return -1;
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003147 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
3148 anqp_string);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003149
Jouni Malinen6be21c82018-08-01 18:47:24 +03003150 if (ap_ft_enabled(dut)) {
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003151 owrt_ap_set_vap(dut, vap_count,
3152 "mobility_domain",
3153 dut->ap_mobility_domain);
3154 owrt_ap_set_vap(dut, vap_count,
Jouni Malinen9f943312019-08-19 23:49:16 +03003155 "ft_over_ds",
3156 dut->ap_ft_ds == VALUE_ENABLED ?
3157 "1" : "0");
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003158 owrt_ap_set_vap(dut, vap_count,
3159 "ieee80211r", "1");
3160 owrt_ap_set_vap(dut, vap_count,
3161 "nasid", "nas1.example.com");
3162 get_hwaddr(sigma_radio_ifname[0], self_mac);
3163 snprintf(mac_str, sizeof(mac_str),
3164 "%02x:%02x:%02x:%02x:%02x:%02x",
3165 self_mac[0], self_mac[1], self_mac[2],
3166 self_mac[3], self_mac[4], self_mac[5]);
3167 owrt_ap_set_vap(dut, vap_count,
3168 "ap_macaddr", mac_str);
3169 snprintf(mac_str, sizeof(mac_str),
3170 "%02x%02x%02x%02x%02x%02x",
3171 self_mac[0], self_mac[1], self_mac[2],
3172 self_mac[3], self_mac[4], self_mac[5]);
3173 owrt_ap_set_vap(dut, vap_count,
3174 "r1_key_holder", mac_str);
3175 owrt_ap_set_vap(dut, vap_count,
3176 "ft_psk_generate_local", "1");
3177 owrt_ap_set_vap(dut, vap_count,
3178 "kh_key_hex",
3179 "000102030405060708090a0b0c0d0e0f");
3180 snprintf(mac_str, sizeof(mac_str),
3181 "%02x:%02x:%02x:%02x:%02x:%02x",
3182 dut->ft_bss_mac_list[0][0],
3183 dut->ft_bss_mac_list[0][1],
3184 dut->ft_bss_mac_list[0][2],
3185 dut->ft_bss_mac_list[0][3],
3186 dut->ft_bss_mac_list[0][4],
3187 dut->ft_bss_mac_list[0][5]);
3188 owrt_ap_set_vap(dut, vap_count,
3189 "ap2_macaddr", mac_str);
3190 owrt_ap_set_vap(dut, vap_count,
3191 "ap2_r1_key_holder", mac_str);
3192 owrt_ap_set_vap(dut, vap_count,
3193 "nasid2", "nas2.example.com");
3194 }
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003195 }
3196
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003197 if (dut->ap_oce == VALUE_ENABLED &&
3198 get_driver_type() == DRIVER_OPENWRT) {
3199 owrt_ap_set_vap(dut, vap_id, "oce", "1");
3200 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
3201 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "1");
3202
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08003203 if (dut->ap_80plus80 == 1)
3204 owrt_ap_set_vap(dut, vap_id, "cfreq2", "5775");
3205
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003206 if (dut->ap_akm == 1) {
3207 owrt_ap_set_vap(dut, vap_id, "wpa_group_rekey",
3208 "3600");
3209 owrt_ap_set_vap(dut, vap_id, "key", "12345678");
3210 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3211 "1");
3212 owrt_ap_set_vap(dut, vap_id, "fils_cache_id",
3213 "1234");
3214 owrt_ap_set_vap(dut, vap_id,
3215 "erp_send_reauth_start", "1");
3216 }
3217
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003218 if (dut->ap_filshlp == VALUE_ENABLED) {
3219 struct ifreq ifr;
3220 char *ifname;
3221 int s;
3222 struct sockaddr_in *ipaddr;
3223
3224 s = socket(AF_INET, SOCK_DGRAM, 0);
3225 if (s < 0) {
3226 sigma_dut_print(dut, DUT_MSG_ERROR,
3227 "Failed to open socket");
3228 return -1;
3229 }
3230 ifr.ifr_addr.sa_family = AF_INET;
3231
3232 memset(&ifr, 0, sizeof(ifr));
3233 ifname = "br-lan";
3234 strlcpy(ifr.ifr_name, ifname,
3235 sizeof(ifr.ifr_name));
3236 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
3237 perror("ioctl");
3238 close(s);
3239 return -1;
3240 }
3241
3242 ipaddr = (struct sockaddr_in*)&ifr.ifr_addr;
3243 snprintf(buf, sizeof(buf), "%s",
3244 inet_ntoa(ipaddr->sin_addr));
3245 owrt_ap_set_vap(dut, vap_id, "own_ip_addr",
3246 buf);
3247 snprintf(buf, sizeof(buf), "%s",
3248 dut->ap_dhcpserv_ipaddr);
3249 owrt_ap_set_vap(dut, vap_id, "dhcp_server",
3250 buf);
3251 owrt_ap_set_vap(dut, vap_id,
3252 "dhcp_rapid_commit_proxy", "1");
3253 owrt_ap_set_vap(dut, vap_id,
3254 "fils_hlp_wait_time", "300");
3255 }
3256
3257 if (dut->ap_filsdscv == VALUE_ENABLED) {
3258 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3259 "1");
3260 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3261 "20");
3262 }
3263 }
3264
3265 if (dut->ap_filsdscv == VALUE_DISABLED) {
3266 owrt_ap_set_vap(dut, vap_id, "ieee80211ai", "0");
3267 owrt_ap_set_vap(dut, vap_id, "fils_fd_period", "0");
3268 }
3269
3270 if (dut->ap_oce == VALUE_DISABLED &&
3271 get_driver_type() == DRIVER_OPENWRT) {
3272 owrt_ap_set_vap(dut, vap_id, "oce", "0");
3273 owrt_ap_set_vap(dut, vap_id, "qbssload", "0");
3274 owrt_ap_set_vap(dut, vap_id, "bpr_enable", "0");
3275
3276 if (dut->ap_filsdscv == VALUE_DISABLED) {
3277 owrt_ap_set_vap(dut, vap_id, "ieee80211ai",
3278 "0");
3279 owrt_ap_set_vap(dut, vap_id, "fils_fd_period",
3280 "0");
3281 }
3282
3283 if (dut->device_type == AP_testbed)
3284 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3285 }
3286
3287 /* NAIRealm */
3288 if (dut->ap_nairealm_int == 1) {
3289 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_nairealm);
3290 owrt_ap_set_vap(dut, vap_id, "fils_realm", buf);
3291 owrt_ap_set_vap(dut, vap_id, "erp_domain", buf);
3292 }
3293
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003294 /* SSID */
3295 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
3296 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
3297
3298 /* Encryption */
3299 switch (dut->ap_key_mgmt) {
3300 case AP_OPEN:
3301 if (dut->ap_cipher == AP_WEP) {
3302 owrt_ap_set_vap(dut, vap_count, "encryption",
3303 "wep-mixed");
3304 owrt_ap_set_vap(dut, vap_count, "key",
3305 dut->ap_wepkey);
3306 } else {
3307 owrt_ap_set_vap(dut, vap_count, "encryption",
3308 "none");
3309 }
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003310 if (dut->ap_key_mgmt == AP_OPEN &&
3311 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
3312 /* OWE transition mode */
3313 snprintf(ifname2, sizeof(ifname2), "%s1",
3314 ifname);
3315 owrt_ap_set_vap(dut, vap_count,
3316 "owe_transition_ifname",
3317 ifname2);
3318 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003319 break;
3320 case AP_WPA2_PSK:
3321 case AP_WPA2_PSK_MIXED:
3322 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03003323 case AP_WPA2_SAE:
3324 case AP_WPA2_PSK_SAE:
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003325 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
3326 dut->ap_key_mgmt == AP_WPA2_PSK_SAE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003327 snprintf(buf, sizeof(buf), "psk2");
3328 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
3329 snprintf(buf, sizeof(buf), "psk-mixed");
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003330 } else if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3331 snprintf(buf, sizeof(buf), "ccmp");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003332 } else {
3333 snprintf(buf, sizeof(buf), "psk");
3334 }
3335
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003336 if (dut->ap_key_mgmt != AP_WPA2_SAE) {
3337 if (dut->ap_cipher == AP_CCMP_TKIP)
3338 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3339 else if (dut->ap_cipher == AP_TKIP)
3340 strlcat(buf, "+tkip", sizeof(buf));
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02003341 else if (dut->ap_cipher == AP_GCMP_128)
3342 strlcat(buf, "+gcmp", sizeof(buf));
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003343 else
3344 strlcat(buf, "+ccmp", sizeof(buf));
3345 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003346
3347 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003348
3349 if (!dut->ap_passphrase[0] && dut->ap_psk[0]) {
3350 snprintf(buf, sizeof(buf), "\"%s\"",
3351 dut->ap_psk);
3352 owrt_ap_set_vap(dut, vap_count, "key", buf);
3353 } else {
3354 snprintf(buf, sizeof(buf), "\"%s\"",
3355 dut->ap_passphrase);
3356 owrt_ap_set_vap(dut, vap_count, "key", buf);
3357 }
3358
3359 if (dut->ap_key_mgmt == AP_WPA2_SAE ||
3360 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
3361 owrt_ap_set_vap(dut, vap_count, "sae", "1");
3362 else
3363 owrt_ap_set_vap(dut, vap_count, "sae", "0");
3364
3365 if (dut->ap_key_mgmt == AP_WPA2_SAE) {
3366 snprintf(buf, sizeof(buf), "%s",
3367 dut->ap_passphrase);
3368 owrt_ap_set_vap(dut, vap_count, "sae_password",
3369 buf);
3370 } else {
3371 snprintf(buf, sizeof(buf), "%s",
3372 dut->ap_passphrase);
3373 owrt_ap_set_vap(dut, vap_count,
3374 "wpa_passphrase", buf);
3375 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003376 break;
3377 case AP_WPA2_EAP:
3378 case AP_WPA2_EAP_MIXED:
3379 case AP_WPA_EAP:
3380 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
3381 snprintf(buf, sizeof(buf), "wpa2");
3382 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
3383 snprintf(buf, sizeof(buf), "wpa-mixed");
3384 } else {
3385 snprintf(buf, sizeof(buf), "wpa");
3386 }
3387
Peng Xu591be452017-05-10 17:27:28 -07003388 if (dut->ap_cipher == AP_CCMP_TKIP)
3389 strlcat(buf, "+ccmp+tkip", sizeof(buf));
3390 else if (dut->ap_cipher == AP_TKIP)
3391 strlcat(buf, "+tkip", sizeof(buf));
3392 else
3393 strlcat(buf, "+ccmp", sizeof(buf));
3394
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003395 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3396 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3397 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3398 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3399 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3400 snprintf(buf, sizeof(buf), "%s",
3401 dut->ap_radius_password);
3402 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3403 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003404 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03003405 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03003406 case AP_WPA2_FT_EAP:
3407 case AP_WPA2_FT_PSK:
3408 case AP_WPA2_EAP_SHA256:
3409 case AP_WPA2_PSK_SHA256:
3410 case AP_WPA2_ENT_FT_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03003411 /* TODO */
3412 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03003413 case AP_SUITEB:
priyadharshini gowthaman2136bd52018-01-15 11:28:55 -08003414 owrt_ap_set_vap(dut, vap_count, "suite_b", "192");
3415 snprintf(buf, sizeof(buf), "gcmp");
3416 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3417 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
3418 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
3419 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
3420 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
3421 snprintf(buf, sizeof(buf), "%s",
3422 dut->ap_radius_password);
3423 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
3424 snprintf(buf, sizeof(buf), "%d",
3425 dut->ap_group_mgmt_cipher);
3426 owrt_ap_set_vap(dut, vap_count, "group_mgmt_cipher",
3427 buf);
Jouni Malinenad395a22017-09-01 21:13:46 +03003428 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03003429 case AP_WPA2_OWE:
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003430 owrt_ap_set_vap(dut, vap_count, "owe", "1");
3431 snprintf(buf, sizeof(buf), "ccmp");
3432 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
3433 if (dut->ap_sae_groups) {
3434 snprintf(buf, sizeof(buf), "\'%s\'",
3435 dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003436 owrt_ap_set_list_vap(dut, vap_count,
3437 "owe_groups", buf);
priyadharshini gowthaman04547062018-01-15 11:59:55 -08003438 }
3439
3440 if (dut->ap_key_mgmt == AP_WPA2_OWE &&
3441 dut->ap_tag_ssid[0][0] &&
3442 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
3443 /* OWE transition mode */
3444 snprintf(ifname2, sizeof(ifname2), "%s1",
3445 ifname);
3446 owrt_ap_set_vap(dut, vap_count,
3447 "owe_transition_ifname",
3448 ifname2);
3449 owrt_ap_set_vap(dut, vap_count, "hidden", "1");
3450 }
Jouni Malinen147b3c32017-10-09 16:51:54 +03003451 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003452 }
3453
3454 if (!dut->ap_is_dual)
3455 break;
3456 }
3457
3458 if (dut->ap_is_dual)
3459 return 1;
3460
3461 /* PMF */
3462 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
3463 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
3464
3465 /* Add SHA256 */
3466 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
3467 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
3468
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003469 /* Add SHA384 for akmsuitetype 15 */
3470 if (dut->ap_akm == 1) {
3471 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha384);
3472 owrt_ap_set_vap(dut, vap_id, "add_sha384", buf);
3473 }
3474
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05303475 /* Enable RSN preauthentication, if asked to */
3476 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
3477 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
3478
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003479 /* Hotspot 2.0 */
3480 if (dut->ap_hs2) {
3481 int ret;
3482
3483 ret = owrt_ap_config_vap_hs2(dut, vap_id);
3484 if (ret)
3485 return ret;
3486 }
3487
3488 /* Interworking */
3489 if (dut->ap_interworking) {
3490 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
3491 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
3492 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
3493 owrt_ap_set_vap(dut, vap_id, "internet", buf);
3494 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
3495 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
3496 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
3497 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
3498 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3499 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3500
3501 if (dut->ap_gas_cb_delay > 0) {
3502 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3503 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
3504 }
3505
3506 if (dut->ap_roaming_cons[0]) {
3507 char *rcons, *temp_ptr;
3508
3509 rcons = strdup(dut->ap_roaming_cons);
3510 if (rcons == NULL)
Jouni Malinen13701222019-02-19 12:10:53 +02003511 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003512
3513 temp_ptr = strchr(rcons, ';');
3514
3515 if (temp_ptr)
3516 *temp_ptr++ = '\0';
3517
3518 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
3519 rcons);
3520
3521 if (temp_ptr)
3522 owrt_ap_set_list_vap(dut, vap_id,
3523 "roaming_consortium",
3524 temp_ptr);
3525
3526 free(rcons);
3527 }
3528 }
3529
3530 if (dut->ap_venue_name) {
3531 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3532 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
3533 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
3534 "\'"ANQP_VENUE_NAME_1_CHI"\'");
3535 }
3536
3537 if (dut->ap_net_auth_type == 1) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003538 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type",
3539 "'00https://tandc-server.wi-fi.org'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003540 } else if (dut->ap_net_auth_type == 2) {
priyadharshini gowthaman9b8a8c32018-08-31 10:49:24 -07003541 owrt_ap_set_list_vap(dut, vap_id, "network_auth_type", "'01'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003542 }
3543
3544 if (dut->ap_nai_realm_list == 1) {
3545 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3546 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
3547 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3548 "'0,wi-fi.org;example.com,13[5:6]'");
3549
3550 } else if (dut->ap_nai_realm_list == 2) {
3551 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3552 "'0,wi-fi.org,21[2:4][5:7]'");
3553 } else if (dut->ap_nai_realm_list == 3) {
3554 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3555 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
3556 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3557 "'0,wi-fi.org;example.com,13[5:6]'");
3558 } else if (dut->ap_nai_realm_list == 4) {
3559 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3560 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
3561 } else if (dut->ap_nai_realm_list == 5) {
3562 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3563 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
3564 } else if (dut->ap_nai_realm_list == 6) {
3565 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3566 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
3567 } else if (dut->ap_nai_realm_list == 7) {
3568 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3569 "'0,wi-fi.org,13[5:6]'");
3570 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
3571 "'0,wi-fi.org,21[2:4][5:7]'");
3572 }
3573
3574 if (dut->ap_domain_name_list[0])
3575 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
3576 dut->ap_domain_name_list);
3577
3578 if (dut->ap_ip_addr_type_avail)
3579 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
3580 "'0c'");
3581
3582 temp = buf;
3583
3584 *temp++ = '\'';
3585
3586 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3587 if (i)
3588 *temp++ = ';';
3589
3590 snprintf(temp,
3591 sizeof(dut->ap_plmn_mcc[i]) +
3592 sizeof(dut->ap_plmn_mnc[i]) + 1,
3593 "%s,%s",
3594 dut->ap_plmn_mcc[i],
3595 dut->ap_plmn_mnc[i]);
3596
3597 temp += strlen(dut->ap_plmn_mcc[i]) +
3598 strlen(dut->ap_plmn_mnc[i]) + 1;
3599 }
3600
3601 *temp++ = '\'';
3602 *temp++ = '\0';
3603
3604 if (i)
3605 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
3606
3607 if (dut->ap_qos_map_set == 1)
3608 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
3609 else if (dut->ap_qos_map_set == 2)
3610 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
3611
3612 /* Proxy-ARP */
3613 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
3614 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
3615
3616 /* DGAF */
3617 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
3618 /* parse to hostapd */
3619 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
3620 /* parse to wifi driver */
3621 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
3622
3623 /* HCBSSLoad */
3624 if (dut->ap_bss_load) {
3625 unsigned int bssload = 0;
3626
3627 if (dut->ap_bss_load == 1) {
3628 /* STA count: 1, CU: 50, AAC: 65535 */
3629 bssload = 0x0132ffff;
3630 } else if (dut->ap_bss_load == 2) {
3631 /* STA count: 1, CU: 200, AAC: 65535 */
3632 bssload = 0x01c8ffff;
3633 } else if (dut->ap_bss_load == 3) {
3634 /* STA count: 1, CU: 75, AAC: 65535 */
3635 bssload = 0x014bffff;
3636 }
3637
3638 snprintf(buf, sizeof(buf), "%d", bssload);
3639 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
3640 }
3641
3642 /* L2TIF */
3643 if (dut->ap_l2tif)
3644 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
3645
3646 if (dut->ap_disable_protection == 1)
3647 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
3648
Sunil Dutt77b213d2017-09-14 18:24:40 +03003649 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003650 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
3651 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
3652 }
3653
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05303654 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003655 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003656
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05303657 if (dut->ap_tx_stbc) {
3658 /* STBC and beamforming are mutually exclusive features */
3659 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
3660 }
3661
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05303662 /* enable dfsmode */
3663 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
3664 owrt_ap_set_vap(dut, vap_id, "doth", buf);
3665
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003666 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
3667 char anqpval[1024];
3668
3669 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3670
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003671 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303672 snprintf(anqpval, sizeof(anqpval),
3673 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003674 dut->ap_val_lci, dut->ap_infoz);
3675 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3676 }
3677
3678 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05303679 snprintf(anqpval, sizeof(anqpval),
3680 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07003681 dut->ap_val_lcr);
3682 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3683 }
3684
3685 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
3686 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3687 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
3688 }
3689
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003690 if (dut->program == PROGRAM_MBO) {
3691 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
3692 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
3693 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07003694 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003695
3696 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
3697 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07003698 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
3699 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07003700 }
3701
Jouni Malinen6be21c82018-08-01 18:47:24 +03003702 if (ap_ft_enabled(dut)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003703 unsigned char self_mac[ETH_ALEN];
3704 char mac_str[20];
3705
Jouni Malinen9f943312019-08-19 23:49:16 +03003706 owrt_ap_set_vap(dut, vap_id, "ft_over_ds",
3707 dut->ap_ft_ds == VALUE_ENABLED ? "1" : "0");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003708 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
Jouni Malinen13701222019-02-19 12:10:53 +02003709 if (get_hwaddr(sigma_radio_ifname[0], self_mac) < 0)
3710 return -1;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003711 snprintf(mac_str, sizeof(mac_str),
3712 "%02x:%02x:%02x:%02x:%02x:%02x",
3713 self_mac[0], self_mac[1], self_mac[2],
3714 self_mac[3], self_mac[4], self_mac[5]);
3715 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003716 snprintf(mac_str, sizeof(mac_str),
3717 "%02x:%02x:%02x:%02x:%02x:%02x",
3718 self_mac[0], self_mac[1], self_mac[2],
3719 self_mac[3], self_mac[4], self_mac[5]);
3720 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003721 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
3722 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
3723 "000102030405060708090a0b0c0d0e0f");
3724 snprintf(mac_str, sizeof(mac_str),
3725 "%02x:%02x:%02x:%02x:%02x:%02x",
3726 dut->ft_bss_mac_list[0][0],
3727 dut->ft_bss_mac_list[0][1],
3728 dut->ft_bss_mac_list[0][2],
3729 dut->ft_bss_mac_list[0][3],
3730 dut->ft_bss_mac_list[0][4],
3731 dut->ft_bss_mac_list[0][5]);
3732 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
priyadharshini gowthaman47189f52017-12-28 12:37:46 -08003733 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
3734 dut->ap_mobility_domain);
3735 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder", mac_str);
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003736 }
3737
Jouni Malinen6be21c82018-08-01 18:47:24 +03003738 if ((ap_ft_enabled(dut) && dut->ap_name == 0) ||
3739 (ap_ft_enabled(dut) && dut->ap_name == 2)) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003740 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
3741 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003742 }
3743
Jouni Malinen6be21c82018-08-01 18:47:24 +03003744 if (ap_ft_enabled(dut) && dut->ap_name == 1) {
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003745 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
3746 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07003747 }
3748
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08003749 if (dut->ap_broadcast_ssid == VALUE_DISABLED)
3750 owrt_ap_set_vap(dut, vap_id, "hidden", "1");
3751
priyadharshini gowthamande81f392017-12-28 15:28:49 -08003752 /* Enable/disable PMKSA caching, if asked to */
3753 if (dut->ap_pmksa == 1) {
3754 snprintf(buf, sizeof(buf), "%d", dut->ap_pmksa_caching);
3755 owrt_ap_set_vap(dut, vap_id, "disable_pmksa_caching", buf);
3756 }
3757
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003758 if (dut->rsne_override) {
3759 snprintf(buf, sizeof(buf), "%s", dut->rsne_override);
3760 owrt_ap_set_vap(dut, vap_count, "own_ie_override", buf);
3761 }
3762
3763 if (dut->sae_commit_override) {
3764 snprintf(buf, sizeof(buf), "%s", dut->sae_commit_override);
3765 owrt_ap_set_vap(dut, vap_count, "sae_commit_override", buf);
3766 }
3767
3768 if (dut->ap_sae_groups) {
3769 snprintf(buf, sizeof(buf), "\'%s\'", dut->ap_sae_groups);
priyadharshini gowthamanb59bfe42018-08-30 15:14:08 -07003770 owrt_ap_set_list_vap(dut, vap_count, "sae_groups", buf);
priyadharshini gowthamancce6ca02018-01-15 11:12:45 -08003771 }
3772
3773 if (dut->sae_anti_clogging_threshold >= 0) {
3774 snprintf(buf, sizeof(buf), "%d",
3775 dut->sae_anti_clogging_threshold);
3776 owrt_ap_set_vap(dut, vap_count, "sae_anti_clogging_threshold",
3777 buf);
3778 }
3779
3780 if (dut->sae_reflection)
3781 owrt_ap_set_vap(dut, vap_count, "sae_reflection_attack", "1");
3782
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07003783 if (dut->program == PROGRAM_HE &&
3784 (dut->ap_txBF || dut->ap_he_ulofdma == VALUE_ENABLED)) {
3785 switch (dut->ap_chwidth) {
3786 case AP_20:
3787 owrt_ap_set_vap(dut, vap_id, "chwidth", "0");
3788 break;
3789 case AP_40:
3790 owrt_ap_set_vap(dut, vap_id, "chwidth", "1");
3791 break;
3792 case AP_80:
3793 owrt_ap_set_vap(dut, vap_id, "chwidth", "2");
3794 break;
3795 case AP_160:
3796 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
3797 break;
3798 case AP_80_80:
3799 owrt_ap_set_vap(dut, vap_id, "chwidth", "3");
3800 break;
3801 case AP_AUTO:
3802 break;
3803 }
3804 }
3805
3806 if (dut->ap_he_dlofdma == VALUE_ENABLED && dut->ap_he_ppdu == PPDU_MU) {
3807 dut->ap_txBF = 0;
3808 dut->ap_mu_txBF = 0;
3809 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "0");
3810 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "0");
3811 owrt_ap_set_vap(dut, vap_id, "he_subfer", "0");
3812 }
3813
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003814 return 1;
3815}
3816
3817
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003818static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
3819{
3820 char anqpval[1024];
3821 unsigned char addr[6];
3822 unsigned char addr2[6];
3823 struct ifreq ifr;
3824 char *ifname;
3825 int s;
3826 int vap_id = 0;
3827
3828 s = socket(AF_INET, SOCK_DGRAM, 0);
3829 if (s < 0) {
3830 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
3831 return -1;
3832 }
3833
3834 memset(&ifr, 0, sizeof(ifr));
3835 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003836 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003837 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3838 perror("ioctl");
3839 close(s);
3840 return -1;
3841 }
3842 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
3843
3844 memset(&ifr, 0, sizeof(ifr));
3845 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07003846 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003847 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
3848 perror("ioctl");
3849 close(s);
3850 return -1;
3851 }
3852 close(s);
3853 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
3854
3855 snprintf(anqpval, sizeof(anqpval),
3856 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
3857 dut->ap_val_lci, dut->ap_infoz,
3858 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
3859 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
3860
3861 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
3862 return 0;
3863}
3864
3865
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003866static int owrt_ap_post_config_commit(struct sigma_dut *dut,
3867 struct sigma_conn *conn,
3868 struct sigma_cmd *cmd)
3869{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003870 int ap_security = 0;
3871 int i;
3872
3873 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
3874 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
3875 ap_security = 1;
3876 }
3877 if (dut->ap_key_mgmt != AP_OPEN)
3878 ap_security = 1;
3879 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003880 /* allow some time for hostapd to start before returning
3881 * success */
3882 usleep(500000);
3883
3884 if (run_hostapd_cli(dut, "ping") != 0) {
3885 send_resp(dut, conn, SIGMA_ERROR,
3886 "errorCode,Failed to talk to hostapd");
3887 return 0;
3888 }
3889 }
3890
3891 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
3892 ath_ap_set_params(dut);
3893
3894 /* Send response */
3895 return 1;
3896}
3897
3898
3899static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
3900 struct sigma_conn *conn,
3901 struct sigma_cmd *cmd)
3902{
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08003903 if (dut->program == PROGRAM_DPP &&
3904 get_driver_type() == DRIVER_OPENWRT) {
3905 wpa_command(dut->hostapd_ifname, "DPP_BOOTSTRAP_REMOVE *");
3906 wpa_command(dut->hostapd_ifname, "DPP_PKEX_REMOVE *");
3907 }
3908
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003909 /* Stop the AP */
3910 run_system(dut, "wifi down");
3911
3912 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05303913 run_system(dut, "rm -rf /etc/config/wireless");
3914 switch (get_openwrt_driver_type()) {
3915 case OPENWRT_DRIVER_ATHEROS:
3916 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
3917 break;
3918 default:
3919 run_system(dut, "wifi detect > /etc/config/wireless");
3920 break;
3921 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003922
3923 /* Configure Radio & VAP, commit the config */
3924 owrt_ap_config_radio(dut);
Jouni Malinen13701222019-02-19 12:10:53 +02003925 if (owrt_ap_config_vap(dut) < 0)
3926 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003927 run_system(dut, "uci commit");
3928
3929 /* Start AP */
3930 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003931 if (dut->program != PROGRAM_MBO &&
3932 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003933 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07003934 /*
3935 * MBO has a different ANQP element value which is set in
3936 * owrt_ap_config_vap().
3937 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07003938 owrt_ap_config_vap_anqp(dut);
3939 run_system(dut, "uci commit");
3940 run_system(dut, "wifi");
3941 }
3942
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003943 return owrt_ap_post_config_commit(dut, conn, cmd);
3944}
3945
3946
3947static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
3948{
3949 unsigned char bssid[6];
3950 char buf[100];
3951 char *ifname, *radio_name;
3952 int vap_id = 0;
3953
3954 if (sigma_radio_ifname[0] &&
3955 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3956 ifname = "ath2";
3957 radio_name = "wifi2";
3958 vap_id = 2;
3959 } else if (sigma_radio_ifname[0] &&
3960 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3961 ifname = "ath1";
3962 radio_name = "wifi1";
3963 vap_id = 1;
3964 } else {
3965 ifname = "ath0";
3966 radio_name = "wifi0";
3967 vap_id = 0;
3968 }
3969
3970 if (!get_hwaddr(ifname, bssid)) {
3971 snprintf(buf, sizeof(buf), "%s", bssid);
3972 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3973 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3974 "%02x:%02x:%02x:%02x:%02x:%02x",
3975 bssid[0], bssid[1], bssid[2], bssid[3],
3976 bssid[4], bssid[5]);
3977 } else {
3978 if (!get_hwaddr(radio_name, bssid)) {
3979 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
3980 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3981 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3982 "%02x:%02x:%02x:%02x:%02x:%02x",
3983 bssid[0], bssid[1], bssid[2], bssid[3],
3984 bssid[4], bssid[5]);
3985 } else {
3986 /* Select & enable/disable radios */
3987 if (sigma_radio_ifname[0] &&
3988 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
3989 /* We want to use wifi2 */
3990 owrt_ap_set_radio(dut, 0, "disabled", "1");
3991 owrt_ap_set_radio(dut, 1, "disabled", "1");
3992 owrt_ap_set_radio(dut, 2, "disabled", "0");
3993 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
3994 } else if (sigma_radio_ifname[0] &&
3995 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
3996 /* We want to use wifi1 */
3997 owrt_ap_set_radio(dut, 0, "disabled", "1");
3998 owrt_ap_set_radio(dut, 1, "disabled", "0");
3999 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
4000 } else {
4001 /* We want to use wifi0 */
4002 owrt_ap_set_radio(dut, 0, "disabled", "0");
4003 owrt_ap_set_radio(dut, 1, "disabled", "1");
4004 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
4005 }
4006
4007 run_system(dut, "uci commit");
4008 run_system(dut, "wifi up");
4009
4010 if (!get_hwaddr(radio_name, bssid)) {
4011 snprintf(buf, sizeof(buf), "%s",
4012 dut->ap_hessid);
4013 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
4014 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
4015 "%02x:%02x:%02x:%02x:%02x:%02x",
4016 bssid[0], bssid[1], bssid[2], bssid[3],
4017 bssid[4], bssid[5]);
4018 }
4019 }
4020 }
4021}
4022
4023
Jouni Malinenf7222712019-06-13 01:50:21 +03004024static enum sigma_cmd_result cmd_ap_reboot(struct sigma_dut *dut,
4025 struct sigma_conn *conn,
4026 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004027{
4028 switch (get_driver_type()) {
4029 case DRIVER_ATHEROS:
4030 run_system(dut, "apdown");
4031 sleep(1);
4032 run_system(dut, "reboot");
4033 break;
4034 case DRIVER_OPENWRT:
4035 run_system(dut, "wifi down");
4036 sleep(1);
4037 run_system(dut, "reboot");
4038 break;
4039 default:
4040 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
4041 break;
4042 }
4043
4044 return 1;
4045}
4046
4047
4048int ascii2hexstr(const char *str, char *hex)
4049{
4050 int i, length;
4051
4052 length = strlen(str);
4053
4054 for (i = 0; i < length; i++)
4055 snprintf(hex + i * 2, 3, "%X", str[i]);
4056
4057 hex[length * 2] = '\0';
4058 return 1;
4059}
4060
4061
4062static int kill_process(struct sigma_dut *dut, char *proc_name,
4063 unsigned char is_proc_instance_one, int sig)
4064{
4065#ifdef __linux__
4066 struct dirent *dp, *dp_in;
4067 const char *direc = "/proc/";
4068 char buf[100];
4069 DIR *dir = opendir(direc);
4070 DIR *dir_in;
4071 FILE *fp;
4072 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304073 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004074 int ret = -1, res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004075
4076 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304077 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004078
4079 while ((dp = readdir(dir)) != NULL) {
4080 if (dp->d_type != DT_DIR)
4081 continue;
4082
Jouni Malinen3aa72862019-05-29 23:14:51 +03004083 res = snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
4084 if (res < 0 || res >= sizeof(buf))
4085 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004086 dir_in = opendir(buf);
4087 if (dir_in == NULL)
4088 continue;
4089 dp_in = readdir(dir_in);
4090 closedir(dir_in);
4091 if (dp_in == NULL)
4092 continue;
Jouni Malinen3aa72862019-05-29 23:14:51 +03004093 res = snprintf(buf, sizeof(buf), "%s%s/stat",
4094 direc, dp->d_name);
4095 if (res < 0 || res >= sizeof(buf))
4096 continue;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004097 fp = fopen(buf, "r");
4098 if (fp == NULL)
4099 continue;
4100 if (fgets(buf, 100, fp) == NULL)
4101 buf[0] = '\0';
4102 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304103 pid = strtok_r(buf, " ", &saveptr);
4104 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004105 if (pid && temp &&
4106 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
4107 sigma_dut_print(dut, DUT_MSG_INFO,
4108 "killing %s process with PID %s",
4109 proc_name, pid);
4110 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
4111 atoi(pid));
4112 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304113 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004114 if (is_proc_instance_one)
4115 break;
4116 }
4117 }
4118
4119 closedir(dir);
4120
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304121 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004122#else /* __linux__ */
4123 return -1;
4124#endif /* __linux__ */
4125}
4126
4127
4128static int run_ndc(struct sigma_dut *dut, char *buf)
4129{
4130 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
4131 sleep(2);
4132 return run_system(dut, buf);
4133}
4134
4135
4136static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
4137 const char *field, const char *value)
4138{
4139 FILE *fcfg, *ftmp;
4140 char buf[MAX_CONF_LINE_LEN + 1];
4141 int len, found = 0, res;
4142
4143 /* Open the configuration file */
4144 fcfg = fopen(pfile, "r");
4145 if (!fcfg) {
4146 sigma_dut_print(dut, DUT_MSG_ERROR,
4147 "Failed to open hostapd conf file");
4148 return -1;
4149 }
4150
4151 snprintf(buf, sizeof(buf), "%s~", pfile);
4152 /* Open a temporary file */
4153 ftmp = fopen(buf, "w+");
4154 if (!ftmp) {
4155 fclose(fcfg);
4156 sigma_dut_print(dut, DUT_MSG_ERROR,
4157 "Failed to open temp buf");
4158 return -1;
4159 }
4160
4161 /* Read the values from the configuration file */
4162 len = strlen(field);
4163 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
4164 char *pline = buf;
4165
4166 /* commented line */
4167 if (buf[0] == '#')
4168 pline++;
4169
4170 /* Identify the configuration parameter to be updated */
4171 if (!found && strncmp(pline, field, len) == 0 &&
4172 pline[len] == '=') {
4173 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
4174 found = 1;
4175 sigma_dut_print(dut, DUT_MSG_INFO,
4176 "Updated hostapd conf file");
4177 }
4178
4179 fprintf(ftmp, "%s", buf);
4180 }
4181
4182 if (!found) {
4183 /* Configuration line not found */
4184 /* Add the new line at the end of file */
4185 fprintf(ftmp, "%s=%s\n", field, value);
4186 sigma_dut_print(dut, DUT_MSG_INFO,
4187 "Adding a new line in hostapd conf file");
4188 }
4189
4190 fclose(fcfg);
4191 fclose(ftmp);
4192
4193 snprintf(buf, sizeof(buf), "%s~", pfile);
4194
4195 /* Restore the updated configuration file */
4196 res = rename(buf, pfile);
4197
4198 /* Remove the temporary file. Ignore the return value */
4199 unlink(buf);
4200
4201 /* chmod is needed because open() may not set permissions properly
4202 * depending on the current umask */
4203 if (chmod(pfile, 0660) < 0) {
4204 unlink(pfile);
4205 sigma_dut_print(dut, DUT_MSG_ERROR,
4206 "Error changing permissions");
4207 return -1;
4208 }
4209
4210 if (res < 0) {
4211 sigma_dut_print(dut, DUT_MSG_ERROR,
4212 "Error restoring conf file");
4213 return -1;
4214 }
4215
4216 return 0;
4217}
4218
4219
4220static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
4221 struct sigma_conn *conn,
4222 struct sigma_cmd *cmd)
4223{
4224 char buf[100];
4225 struct stat s;
4226 int num_tries = 0, ret;
4227
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05304228 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
4229 system("killall netd") == 0) {
4230 /* Avoid Error: Error connecting (Connection refused)
4231 * Wait some time to allow netd to reinitialize.
4232 */
4233 usleep(1500000);
4234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004235
4236 while (num_tries < 10) {
4237 ret = run_ndc(dut, "ndc softap stopap");
4238 num_tries++;
4239 if (WIFEXITED(ret))
4240 ret = WEXITSTATUS(ret);
4241 /* On success, NDC exits with 0 */
4242 if (ret == 0)
4243 break;
4244 sigma_dut_print(dut, DUT_MSG_INFO,
4245 "Try No. %d: ndc softap stopap failed, exit code %d",
4246 num_tries, ret);
4247 }
4248
4249 if (ret != 0)
4250 sigma_dut_print(dut, DUT_MSG_ERROR,
4251 "ndc softap stopap command failed for 10 times - giving up");
4252
4253#ifdef ANDROID
4254 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05304255 system("rmmod -f wlan");
4256 usleep(500000);
4257 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258#else /* ANDROID */
4259 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
4260 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
4261#endif /* ANDROID */
4262
4263 switch (dut->ap_mode) {
4264 case AP_11g:
4265 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
4266 break;
4267 case AP_11b:
4268 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
4269 break;
4270 case AP_11ng:
4271 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4272 break;
4273 case AP_11a:
4274 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
4275 break;
4276 case AP_11na:
4277 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
4278 break;
4279 case AP_11ac:
4280 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
4281 break;
4282 default:
4283 break;
4284 }
4285
4286 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
4287 dut->ap_channel);
4288 run_ndc(dut, buf);
4289
4290 /*
4291 * ndc doesn't support double quotes as SSID string, so re-write
4292 * hostapd configuration file to update SSID.
4293 */
4294 if (dut->ap_ssid[0] != '\0')
4295 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
4296
4297 switch (dut->ap_key_mgmt) {
4298 case AP_OPEN:
4299 if (dut->ap_cipher == AP_WEP) {
4300 run_ndc(dut, "ndc softap qccmd set security_mode=1");
4301 snprintf(buf, sizeof(buf),
4302 "ndc softap qccmd set wep_key0=%s",
4303 dut->ap_wepkey);
4304 run_ndc(dut, buf);
4305 } else {
4306 run_ndc(dut, "ndc softap qccmd set security_mode=0");
4307 }
4308 break;
4309 case AP_WPA2_PSK:
4310 case AP_WPA2_PSK_MIXED:
4311 case AP_WPA_PSK:
4312 if (dut->ap_key_mgmt == AP_WPA2_PSK)
4313 run_ndc(dut, "ndc softap qccmd set security_mode=3");
4314 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4315 run_ndc(dut, "ndc softap qccmd set security_mode=4");
4316 else
4317 run_ndc(dut, "ndc softap qccmd set security_mode=2");
4318
4319 /*
4320 * ndc doesn't support some special characters as passphrase,
4321 * so re-write hostapd configuration file to update Passphrase.
4322 */
4323 if (dut->ap_passphrase[0] != '\0')
4324 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
4325 "wpa_passphrase", dut->ap_passphrase);
4326
4327 if (dut->ap_cipher == AP_CCMP_TKIP)
4328 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4329 "TKIP CCMP");
4330 else if (dut->ap_cipher == AP_TKIP)
4331 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4332 "TKIP");
4333 else
4334 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
4335 "CCMP &");
4336 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03004337 case AP_WPA2_SAE:
4338 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339 case AP_WPA2_EAP:
4340 case AP_WPA2_EAP_MIXED:
4341 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03004342 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03004343 case AP_WPA2_OWE:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03004344 case AP_WPA2_EAP_OSEN:
Jouni Malinenc2b91212018-09-12 02:26:39 +03004345 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03004346 case AP_WPA2_FT_EAP:
4347 case AP_WPA2_FT_PSK:
4348 case AP_WPA2_EAP_SHA256:
4349 case AP_WPA2_PSK_SHA256:
4350 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004351 /* Not supported */
4352 break;
4353 }
4354
4355 switch (dut->ap_pmf) {
4356 case AP_PMF_DISABLED:
4357 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
4358 break;
4359 case AP_PMF_OPTIONAL:
4360 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
4361 if (dut->ap_add_sha256)
4362 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
4363 else
4364 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
4365 break;
4366 case AP_PMF_REQUIRED:
4367 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
4368 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
4369 break;
4370 }
4371
4372 if (dut->ap_countrycode[0]) {
4373 snprintf(buf, sizeof(buf),
4374 "ndc softap qccmd set country_code=%s",
4375 dut->ap_countrycode);
4376 run_ndc(dut, buf);
4377 }
4378
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05304379 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
4380 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
4381
4382 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
4383 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
4384
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004385 run_ndc(dut, "ndc softap startap");
4386
4387 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
4388 num_tries = 0;
4389 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
4390 run_ndc(dut, "ndc softap stopap");
4391 run_ndc(dut, "ndc softap startap");
4392 num_tries++;
4393 }
4394
4395 if (num_tries == 10) {
4396 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
4397 "iface %s :: reboot the APDUT", buf);
4398 return ret;
4399 }
4400
4401 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
4402 ap_inet_addr, ap_inet_mask);
4403 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
4404 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
4405 if (system(buf) != 0) {
4406 sigma_dut_print(dut, DUT_MSG_ERROR,
4407 "Failed to intialize the interface");
4408 return -1;
4409 }
4410
4411 return 1;
4412}
4413
4414
4415static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
4416{
4417 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
4418 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
4419
4420 if (dut->ap_oper_name) {
4421 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
4422 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
4423 }
4424
4425 if (dut->ap_wan_metrics == 1)
4426 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
4427 else if (dut->ap_wan_metrics == 2)
4428 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
4429 else if (dut->ap_wan_metrics == 3)
4430 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
4431 else if (dut->ap_wan_metrics == 4)
4432 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
4433 else if (dut->ap_wan_metrics == 5)
4434 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
4435
4436 if (dut->ap_conn_capab == 1) {
4437 fprintf(f, "hs20_conn_capab=1:0:0\n");
4438 fprintf(f, "hs20_conn_capab=6:20:1\n");
4439 fprintf(f, "hs20_conn_capab=6:22:0\n");
4440 fprintf(f, "hs20_conn_capab=6:80:1\n");
4441 fprintf(f, "hs20_conn_capab=6:443:1\n");
4442 fprintf(f, "hs20_conn_capab=6:1723:0\n");
4443 fprintf(f, "hs20_conn_capab=6:5060:0\n");
4444 fprintf(f, "hs20_conn_capab=17:500:1\n");
4445 fprintf(f, "hs20_conn_capab=17:5060:0\n");
4446 fprintf(f, "hs20_conn_capab=17:4500:1\n");
4447 fprintf(f, "hs20_conn_capab=50:0:1\n");
4448 } else if (dut->ap_conn_capab == 2) {
4449 fprintf(f, "hs20_conn_capab=6:80:1\n");
4450 fprintf(f, "hs20_conn_capab=6:443:1\n");
4451 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4452 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4453 } else if (dut->ap_conn_capab == 3) {
4454 fprintf(f, "hs20_conn_capab=6:80:1\n");
4455 fprintf(f, "hs20_conn_capab=6:443:1\n");
4456 } else if (dut->ap_conn_capab == 4) {
4457 fprintf(f, "hs20_conn_capab=6:80:1\n");
4458 fprintf(f, "hs20_conn_capab=6:443:1\n");
4459 fprintf(f, "hs20_conn_capab=6:5060:1\n");
4460 fprintf(f, "hs20_conn_capab=17:5060:1\n");
4461 }
4462
4463 if (dut->ap_oper_class == 1)
4464 fprintf(f, "hs20_operating_class=51\n");
4465 else if (dut->ap_oper_class == 2)
4466 fprintf(f, "hs20_operating_class=73\n");
4467 else if (dut->ap_oper_class == 3)
4468 fprintf(f, "hs20_operating_class=5173\n");
4469
4470 if (dut->ap_osu_provider_list) {
4471 char *osu_friendly_name = NULL;
4472 char *osu_icon = NULL;
4473 char *osu_ssid = NULL;
4474 char *osu_nai = NULL;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004475 char *osu_nai2 = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004476 char *osu_service_desc = NULL;
4477 char *hs20_icon_filename = NULL;
4478 char hs20_icon[150];
4479 int osu_method;
4480
4481 hs20_icon_filename = "icon_red_zxx.png";
4482 if (dut->ap_osu_icon_tag == 2)
4483 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4484 snprintf(hs20_icon, sizeof(hs20_icon),
4485 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
4486 hs20_icon_filename);
4487 osu_icon = "icon_red_zxx.png";
4488 osu_ssid = "OSU";
4489 osu_friendly_name = "kor:SP 빨강 테스트 전용";
4490 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
4491 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4492
4493 if (strlen(dut->ap_osu_server_uri[0]))
4494 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
4495 else
4496 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4497
4498 switch (dut->ap_osu_provider_list) {
4499 case 1:
4500 case 101:
4501 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4502 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4503 hs20_icon_filename = "icon_red_eng.png";
4504 if (dut->ap_osu_icon_tag == 2)
4505 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4506 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
4507 hs20_icon_filename);
4508 fprintf(f, "osu_icon=icon_red_eng.png\n");
4509 break;
4510 case 2:
4511 case 102:
4512 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
4513 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4514 hs20_icon_filename = "icon_orange_zxx.png";
4515 if (dut->ap_osu_icon_tag == 2)
4516 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4517 snprintf(hs20_icon, sizeof(hs20_icon),
4518 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4519 hs20_icon_filename);
4520 osu_icon = "icon_orange_zxx.png";
4521 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
4522 break;
4523 case 3:
4524 case 103:
4525 osu_friendly_name = "spa:SP Red Test Only";
4526 osu_service_desc = "spa:Free service for test purpose";
4527 break;
4528 case 4:
4529 case 104:
4530 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4531 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4532 hs20_icon_filename = "icon_orange_eng.png";
4533 if (dut->ap_osu_icon_tag == 2)
4534 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4535 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
4536 hs20_icon_filename);
4537 fprintf(f, "osu_icon=icon_orange_eng.png\n");
4538 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4539
4540 hs20_icon_filename = "icon_orange_zxx.png";
4541 if (dut->ap_osu_icon_tag == 2)
4542 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4543 snprintf(hs20_icon, sizeof(hs20_icon),
4544 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4545 hs20_icon_filename);
4546 osu_icon = "icon_orange_zxx.png";
4547 break;
4548 case 5:
4549 case 105:
4550 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4551 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4552 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4553 hs20_icon_filename = "icon_orange_zxx.png";
4554 if (dut->ap_osu_icon_tag == 2)
4555 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4556 snprintf(hs20_icon, sizeof(hs20_icon),
4557 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4558 hs20_icon_filename);
4559 osu_icon = "icon_orange_zxx.png";
4560 break;
4561 case 6:
4562 case 106:
4563 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4564 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
4565 hs20_icon_filename = "icon_green_zxx.png";
4566 if (dut->ap_osu_icon_tag == 2)
4567 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4568 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
4569 hs20_icon_filename);
4570 fprintf(f, "osu_icon=icon_green_zxx.png\n");
4571 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
4572 fprintf(f, "osu_method_list=%d\n", osu_method);
4573
4574 if (strlen(dut->ap_osu_server_uri[1]))
4575 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4576 else
4577 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4578 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4579 hs20_icon_filename = "icon_orange_zxx.png";
4580 if (dut->ap_osu_icon_tag == 2)
4581 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4582 snprintf(hs20_icon, sizeof(hs20_icon),
4583 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4584 hs20_icon_filename);
4585 osu_icon = "icon_orange_zxx.png";
4586 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
4587 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
4588 osu_service_desc = NULL;
4589 break;
4590 case 7:
4591 case 107:
4592 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
4593 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4594 hs20_icon_filename = "icon_green_eng.png";
4595 if (dut->ap_osu_icon_tag == 2)
4596 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4597 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
4598 hs20_icon_filename);
4599 fprintf(f, "osu_icon=icon_green_eng.png\n");
4600 osu_friendly_name = "kor:SP 초록 테스트 전용";
4601
4602 hs20_icon_filename = "icon_green_zxx.png";
4603 if (dut->ap_osu_icon_tag == 2)
4604 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4605 snprintf(hs20_icon, sizeof(hs20_icon),
4606 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
4607 hs20_icon_filename);
4608 osu_icon = "icon_green_zxx.png";
4609 break;
4610 case 8:
4611 case 108:
4612 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4613 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
4614 osu_ssid = "OSU-Encrypted";
4615 osu_nai = "anonymous@hotspot.net";
4616 break;
4617 case 9:
4618 case 109:
4619 osu_ssid = "OSU-OSEN";
4620 osu_nai = "test-anonymous@wi-fi.org";
4621 osu_friendly_name = "eng:SP Orange Test Only";
4622 hs20_icon_filename = "icon_orange_zxx.png";
4623 if (dut->ap_osu_icon_tag == 2)
4624 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
4625 snprintf(hs20_icon, sizeof(hs20_icon),
4626 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
4627 hs20_icon_filename);
4628 osu_icon = "icon_orange_zxx.png";
4629 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
4630 osu_service_desc = NULL;
4631 break;
Jouni Malinen93a837f2018-11-01 17:09:22 +02004632 case 10:
4633 case 110:
4634 /* OSU Provider #1 */
4635 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
4636 fprintf(f, "osu_friendly_name=kor:SP 오렌지 테스트 전용\n");
4637 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/icon_orange_zxx.png\n");
4638 fprintf(f, "osu_icon=icon_orange_zxx.png\n");
4639 osu_method = (dut->ap_osu_method[0] == 0xFF) ?
4640 1 : dut->ap_osu_method[0];
4641 fprintf(f, "osu_method_list=%d\n", osu_method);
4642 fprintf(f, "osu_nai=test-anonymous@wi-fi.org\n");
4643 switch (dut->ap_osu_provider_nai_list) {
4644 case 3:
4645 fprintf(f,
4646 "osu_nai2=test-anonymous@wi-fi.org\n");
4647 break;
4648 case 4:
4649 fprintf(f, "osu_nai2=random@hotspot.net\n");
4650 break;
4651 }
4652
4653 /* OSU Provider #2 */
4654 /* SP Red from defaults */
4655 if (strlen(dut->ap_osu_server_uri[1]))
4656 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
4657 else
4658 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
4659 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
4660 snprintf(hs20_icon, sizeof(hs20_icon),
4661 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/icon_red_zxx.png");
4662 osu_method = (dut->ap_osu_method[1] == 0xFF) ?
4663 1 : dut->ap_osu_method[1];
4664 osu_service_desc = NULL;
4665 osu_nai = "anonymous@hotspot.net";
4666 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004667 default:
4668 break;
4669 }
4670
Jouni Malinen93a837f2018-11-01 17:09:22 +02004671 switch (dut->ap_osu_provider_nai_list) {
4672 case 1:
4673 osu_nai2 = "anonymous@hotspot.net";
4674 break;
4675 case 2:
4676 osu_nai2 = "test-anonymous@wi-fi.org";
4677 break;
4678 case 3:
4679 /* OSU Provider NAI #1 written above */
4680 /* OSU Provider NAI #2 */
4681 osu_nai2 = "anonymous@hotspot.net";
4682 break;
4683 case 4:
4684 /* OSU Provider NAI #1 written above */
4685 /* OSU Provider NAI #2 */
4686 osu_nai2 = "anonymous@hotspot.net";
4687 break;
4688 }
4689
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004690 if (strlen(dut->ap_osu_ssid)) {
Jouni Malinene6ac6a02018-09-11 02:40:17 +03004691 if (dut->ap_tag_ssid[0][0] &&
4692 strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004693 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004694 sigma_dut_print(dut, DUT_MSG_ERROR,
4695 "OSU_SSID and "
4696 "WLAN_TAG2 SSID differ");
4697 return -2;
4698 }
4699 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
4700 } else
4701 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
4702
4703
4704 if (osu_friendly_name)
4705 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
4706
4707 if (osu_service_desc)
4708 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
4709
4710 if (osu_nai)
4711 fprintf(f, "osu_nai=%s\n", osu_nai);
Jouni Malinen93a837f2018-11-01 17:09:22 +02004712 if (osu_nai2)
4713 fprintf(f, "osu_nai2=%s\n", osu_nai2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004714
4715 fprintf(f, "hs20_icon=%s\n", hs20_icon);
4716
4717 if (osu_icon)
4718 fprintf(f, "osu_icon=%s\n", osu_icon);
4719
4720 if (dut->ap_osu_provider_list > 100)
4721 fprintf(f, "osu_method_list=0\n");
4722 else
4723 fprintf(f, "osu_method_list=%d\n", osu_method);
4724 }
4725
Jouni Malinen54a89b02018-05-01 00:16:26 +03004726 switch (dut->ap_venue_url) {
4727 case 1:
4728 fprintf(f,
4729 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4730 "venue_url=1:https://venue-server.r2m-testbed.wi-fi.org/directory/index.html\n");
4731 break;
4732 case 2:
4733 fprintf(f,
4734 "venue_url=1:https://the-great-mall.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4735 "venue_url=2:https://abercrombie.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4736 "venue_url=3:https://adidas.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4737 "venue_url=4:https://aeropostale.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4738 "venue_url=5:https://agaci.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4739 "venue_url=6:https://aldo-shoes.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4740 "venue_url=7:https://american-eagle-outfitters.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4741 "venue_url=8:https://anderson-bakery.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4742 "venue_url=9:https://banana-republic-factory-store.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4743 "venue_url=10:https://bed-bath-and-beyond.r2m-testbed.wi-fi.org/floorplans/index.html\n"
4744 );
4745 break;
4746 }
4747
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03004748 switch (dut->ap_advice_of_charge) {
4749 case 1:
4750 fprintf(f, "anqp_elem=278:" ADV_OF_CHARGE_1 "\n");
4751 break;
4752 }
4753
Jouni Malinenac104532018-05-01 00:27:37 +03004754 switch (dut->ap_oper_icon_metadata) {
4755 case 1:
4756 fprintf(f,
4757 "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/icon_red_eng.png\n"
4758 "operator_icon=icon_red_eng.png\n");
4759 break;
4760 }
4761
Jouni Malinenac367142018-05-01 00:32:24 +03004762 switch (dut->ap_tnc_file_name) {
4763 case 1:
4764 fprintf(f, "hs20_t_c_filename=tandc-id1-content.txt\n");
4765 break;
4766 }
4767
4768 if (dut->ap_tnc_time_stamp)
4769 fprintf(f, "hs20_t_c_timestamp=%u\n", dut->ap_tnc_time_stamp);
4770
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004771 return 0;
4772}
4773
4774
4775static void write_ap_roaming_cons(FILE *f, const char *list)
4776{
4777 char *buf, *pos, *end;
4778
4779 if (list == NULL || list[0] == '\0')
4780 return;
4781
4782 buf = strdup(list);
4783 if (buf == NULL)
4784 return;
4785
4786 pos = buf;
4787 while (pos && *pos) {
4788 end = strchr(pos, ';');
4789 if (end)
4790 *end++ = '\0';
4791 fprintf(f, "roaming_consortium=%s\n", pos);
4792 pos = end;
4793 }
4794
4795 free(buf);
4796}
4797
4798
4799static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
4800{
4801 int i;
4802 char buf[100], *temp;
4803
4804 if (dut->ap_gas_cb_delay > 0)
4805 fprintf(f, "gas_comeback_delay=%d\n",
4806 dut->ap_gas_cb_delay);
4807
4808 fprintf(f, "interworking=1\n"
4809 "access_network_type=%d\n"
4810 "internet=%d\n"
4811 "asra=0\n"
4812 "esr=0\n"
4813 "uesa=0\n"
4814 "venue_group=%d\n"
4815 "venue_type=%d\n",
4816 dut->ap_access_net_type,
4817 dut->ap_internet,
4818 dut->ap_venue_group,
4819 dut->ap_venue_type);
4820 if (dut->ap_hessid[0])
4821 fprintf(f, "hessid=%s\n", dut->ap_hessid);
4822
4823 write_ap_roaming_cons(f, dut->ap_roaming_cons);
4824
4825 if (dut->ap_venue_name) {
4826 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
4827 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
4828 }
4829
4830 if (dut->ap_net_auth_type == 1)
4831 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
4832 else if (dut->ap_net_auth_type == 2)
4833 fprintf(f, "network_auth_type=01\n");
4834
4835 if (dut->ap_nai_realm_list == 1) {
4836 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
4837 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4838 } else if (dut->ap_nai_realm_list == 2) {
4839 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4840 } else if (dut->ap_nai_realm_list == 3) {
4841 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
4842 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
4843 } else if (dut->ap_nai_realm_list == 4) {
4844 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
4845 } else if (dut->ap_nai_realm_list == 5) {
4846 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
4847 } else if (dut->ap_nai_realm_list == 6) {
4848 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
4849 } else if (dut->ap_nai_realm_list == 7) {
4850 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
4851 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
4852 }
4853
4854 if (dut->ap_domain_name_list[0]) {
4855 fprintf(f, "domain_name=%s\n",
4856 dut->ap_domain_name_list);
4857 }
4858
4859 if (dut->ap_ip_addr_type_avail == 1) {
4860 fprintf(f, "ipaddr_type_availability=0c\n");
4861 }
4862
4863 temp = buf;
4864 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
4865 i++) {
4866 if (i)
4867 *temp++ = ';';
4868
4869 snprintf(temp,
4870 sizeof(dut->ap_plmn_mcc[i]) +
4871 sizeof(dut->ap_plmn_mnc[i]) + 1,
4872 "%s,%s",
4873 dut->ap_plmn_mcc[i],
4874 dut->ap_plmn_mnc[i]);
4875
4876 temp += strlen(dut->ap_plmn_mcc[i]) +
4877 strlen(dut->ap_plmn_mnc[i]) + 1;
4878 }
4879 if (i)
4880 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
4881
4882 if (dut->ap_qos_map_set == 1)
4883 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
4884 else if (dut->ap_qos_map_set == 2)
4885 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
4886
4887 return 0;
4888}
4889
4890
4891static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
4892{
4893 FILE *f;
4894
4895 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
4896 system("killall hostapd") == 0) {
4897 int i;
4898
4899 /* Wait some time to allow hostapd to complete cleanup before
4900 * starting a new process */
4901 for (i = 0; i < 10; i++) {
4902 usleep(500000);
4903 if (system("pidof hostapd") != 0)
4904 break;
4905 }
4906 }
4907
4908 f = fopen("/tmp/secath0", "a");
4909 if (f == NULL)
4910 return -2;
4911
4912 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
4913 fclose(f);
4914 return -2;
4915 }
4916
4917 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
4918 fclose(f);
4919 return -2;
4920 }
4921
4922 fflush(f);
4923 fclose(f);
4924 return ath_ap_start_hostapd(dut);
4925}
4926
4927
4928static int ath_ap_start_hostapd(struct sigma_dut *dut)
4929{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07004930 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004931 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
4932 else
4933 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
4934
4935 return 0;
4936}
4937
4938
4939#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
4940
4941static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
4942{
4943 FILE *f;
4944 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
4945 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
4946 char buf[100];
4947 int i;
4948
4949 f = fopen("/root/anqpserver.conf", "w");
4950 if (f == NULL)
4951 return -1;
4952
4953 if (dut->ap_nai_realm_list == 1) {
4954 nai_realm = 1;
4955 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");
4956 } else if (dut->ap_nai_realm_list == 2) {
4957 nai_realm = 1;
4958 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
4959 } else if (dut->ap_nai_realm_list == 3) {
4960 nai_realm = 1;
4961 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");
4962 } else if (dut->ap_nai_realm_list == 4) {
4963 nai_realm = 1;
4964 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");
4965 } else
4966 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
4967
4968 if (dut->ap_domain_name_list[0]) {
4969 char *next, *start, *dnbuf, *dn1, *anqp_dn;
4970 int len, dn_len_max;
4971 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304972 if (dnbuf == NULL) {
4973 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004974 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304975 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004976
4977 len = strlen(dnbuf);
4978 dn_len_max = 50 + len*2;
4979 anqp_dn = malloc(dn_len_max);
4980 if (anqp_dn == NULL) {
4981 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304982 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004983 return -1;
4984 }
4985 start = dnbuf;
4986 dn1 = anqp_dn;
4987 while (start && *start) {
4988 char *hexstr;
4989
4990 next = strchr(start, ',');
4991 if (next)
4992 *next++ = '\0';
4993
4994 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05304995 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004996 if (hexstr == NULL) {
4997 free(dnbuf);
4998 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05304999 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005000 return -1;
5001 }
5002 ascii2hexstr(start, hexstr);
5003 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
5004 free(hexstr);
5005 dn1 += 2 + len * 2;
5006 dn_len_max -= 2 + len * 2;
5007 start = next;
5008 }
5009 free(dnbuf);
5010 if (dut->ap_gas_cb_delay) {
5011 fprintf(f, "dyn_domain_name=0c01%04x%s",
5012 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5013 domain_name = 1;
5014 } else
5015 fprintf(f, "domain_name=0c01%04x%s",
5016 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
5017 free(anqp_dn);
5018 } else
5019 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
5020
5021 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
5022
5023 if (dut->ap_oper_name) {
5024 if (dut->ap_gas_cb_delay) {
5025 fprintf(f, "dyn_oper_friendly_name="
5026 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5027 oper_name = 1;
5028 } else
5029 fprintf(f, "oper_friendly_name="
5030 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
5031 } else
5032 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
5033
5034 if (dut->ap_venue_name) {
5035 if (dut->ap_gas_cb_delay) {
5036 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
5037 venue_name = 1;
5038 } else
5039 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
5040 } else
5041 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
5042
5043 if (dut->ap_wan_metrics) {
5044 if (dut->ap_gas_cb_delay) {
5045 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
5046 wan_metrics = 1;
5047 } else
5048 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
5049 "\n");
5050 } else
5051 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
5052
5053 if (dut->ap_conn_capab) {
5054 if (dut->ap_gas_cb_delay) {
5055 fprintf(f, "dyn_conn_capability="
5056 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5057 conn_cap = 1;
5058 } else
5059 fprintf(f, "conn_capability="
5060 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
5061 } else
5062 sigma_dut_print(dut, DUT_MSG_ERROR,
5063 "not setting conn_capability");
5064
5065 if (dut->ap_ip_addr_type_avail) {
5066 if (dut->ap_gas_cb_delay) {
5067 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
5068 "\n");
5069 ipaddr_avail = 1;
5070 } else
5071 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
5072 } else
5073 sigma_dut_print(dut, DUT_MSG_ERROR,
5074 "not setting ipaddr_type_avail");
5075
5076 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
5077 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
5078 dut->ap_plmn_mcc[i][1],
5079 dut->ap_plmn_mcc[i][0],
5080 dut->ap_plmn_mnc[i][2] == '\0' ?
5081 'f' : dut->ap_plmn_mnc[i][2],
5082 dut->ap_plmn_mcc[i][2],
5083 dut->ap_plmn_mnc[i][1],
5084 dut->ap_plmn_mnc[i][0]);
5085 }
5086 if (i) {
5087 uint16_t ie_len = (i * 3) + 5;
5088 if (dut->ap_gas_cb_delay) {
5089 fprintf(f, "dyn_cell_net=0801");
5090 cell_net = 1;
5091 } else
5092 fprintf(f, "cell_net=0801");
5093 fprintf(f, "%04x", LE16(ie_len));
5094 fprintf(f, "00"); /* version */
5095 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
5096 fprintf(f, "00"); /* plmn list */
5097 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
5098 fprintf(f, "%02x", i); /* number of plmns */
5099 fprintf(f, "%s\n", buf); /* plmns */
5100 } else
5101 sigma_dut_print(dut, DUT_MSG_ERROR,
5102 "not setting 3gpp_cellular_network");
5103
5104 if (nai_realm || domain_name || oper_name || venue_name ||
5105 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
5106 fprintf(f, "anqp_attach=");
5107 if (venue_name)
5108 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
5109 if (nai_realm)
5110 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
5111 if (cell_net)
5112 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
5113 if (domain_name)
5114 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
5115 if (oper_name)
5116 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
5117 if (wan_metrics)
5118 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
5119 if (conn_cap)
5120 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
5121 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
5122 fprintf(f, "\n");
5123 }
5124
5125 fclose(f);
5126
5127 run_system(dut, "anqpserver -i ath0 &");
5128 if (!dut->ap_anqpserver_on)
5129 run_system(dut, "killall anqpserver");
5130
5131 return 1;
5132}
5133
5134
5135static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
5136{
5137 char buf[100];
5138
5139 run_system(dut, "cfg -a AP_STARTMODE=standard");
5140
5141 if (sigma_radio_ifname[0] &&
5142 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
5143 run_system(dut, "cfg -a AP_RADIO_ID=1");
5144 switch (dut->ap_mode) {
5145 case AP_11g:
5146 run_system(dut, "cfg -a AP_CHMODE_2=11G");
5147 break;
5148 case AP_11b:
5149 run_system(dut, "cfg -a AP_CHMODE_2=11B");
5150 break;
5151 case AP_11ng:
5152 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
5153 break;
5154 case AP_11a:
5155 run_system(dut, "cfg -a AP_CHMODE_2=11A");
5156 break;
5157 case AP_11na:
5158 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
5159 break;
5160 case AP_11ac:
5161 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5162 break;
5163 default:
5164 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5165 break;
5166 }
5167
5168 switch (dut->ap_rx_streams) {
5169 case 1:
5170 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
5171 break;
5172 case 2:
5173 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
5174 break;
5175 case 3:
5176 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
5177 break;
5178 }
5179
5180 switch (dut->ap_tx_streams) {
5181 case 1:
5182 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
5183 break;
5184 case 2:
5185 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
5186 break;
5187 case 3:
5188 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
5189 break;
5190 }
5191
5192 switch (dut->ap_chwidth) {
5193 case AP_20:
5194 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
5195 break;
5196 case AP_40:
5197 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
5198 break;
5199 case AP_80:
5200 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5201 break;
5202 case AP_160:
5203 case AP_AUTO:
5204 default:
5205 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
5206 break;
5207 }
5208
5209 if (dut->ap_tx_stbc) {
5210 run_system(dut, "cfg -a TX_STBC_2=1");
5211 }
5212
5213 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
5214 dut->ap_channel);
5215
5216 if (dut->ap_is_dual) {
5217 switch (dut->ap_mode_1) {
5218 case AP_11g:
5219 run_system(dut, "cfg -a AP_CHMODE=11G");
5220 break;
5221 case AP_11b:
5222 run_system(dut, "cfg -a AP_CHMODE=11B");
5223 break;
5224 case AP_11ng:
5225 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5226 break;
5227 case AP_11a:
5228 run_system(dut, "cfg -a AP_CHMODE=11A");
5229 break;
5230 case AP_11na:
5231 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5232 break;
5233 case AP_11ac:
5234 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5235 break;
5236 default:
5237 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5238 break;
5239 }
5240 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5241 dut->ap_channel_1);
5242 }
5243 run_system(dut, buf);
5244 } else {
5245 run_system(dut, "cfg -a AP_RADIO_ID=0");
5246 switch (dut->ap_mode) {
5247 case AP_11g:
5248 run_system(dut, "cfg -a AP_CHMODE=11G");
5249 break;
5250 case AP_11b:
5251 run_system(dut, "cfg -a AP_CHMODE=11B");
5252 break;
5253 case AP_11ng:
5254 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5255 break;
5256 case AP_11a:
5257 run_system(dut, "cfg -a AP_CHMODE=11A");
5258 break;
5259 case AP_11na:
5260 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
5261 break;
5262 case AP_11ac:
5263 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
5264 break;
5265 default:
5266 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
5267 break;
5268 }
5269 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
5270 dut->ap_channel);
5271 run_system(dut, buf);
5272 }
5273
5274 if (dut->ap_sgi80 == 1) {
5275 run_system(dut, "cfg -a SHORTGI=1");
5276 run_system(dut, "cfg -a SHORTGI_2=1");
5277 } else if (dut->ap_sgi80 == 0) {
5278 run_system(dut, "cfg -a SHORTGI=0");
5279 run_system(dut, "cfg -a SHORTGI_2=0");
5280 }
5281
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005282 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005283 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005284 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005285 run_system(dut, "cfg -a LDPC=0");
5286}
5287
5288
5289void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
5290{
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005291 run_iwpriv(dut, intf, "vhtsubfee 0");
5292 run_iwpriv(dut, intf, "vhtsubfer 0");
5293 run_iwpriv(dut, intf, "vhtmubfee 0");
5294 run_iwpriv(dut, intf, "vhtmubfer 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005295}
5296
5297
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005298static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
5299 const char *val)
5300{
5301 if (strcasecmp(val, "enable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005302 run_iwpriv(dut, ifname, "mbo_asoc_dis 1");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005303 } else if (strcasecmp(val, "disable") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005304 run_iwpriv(dut, ifname, "mbo_asoc_dis 0");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005305 } else {
5306 sigma_dut_print(dut, DUT_MSG_ERROR,
5307 "Unsupported assoc_disallow");
5308 }
5309}
5310
5311
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005312static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
5313{
5314 int i;
5315 int least_pref = 1 << 8;
5316 char ifname[20];
5317 uint8_t self_mac[ETH_ALEN];
5318 char buf[200];
5319 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
5320
5321 get_if_name(dut, ifname, sizeof(ifname), 1);
5322 get_hwaddr(ifname, self_mac);
5323
5324 /* Clear off */
5325 snprintf(buf, sizeof(buf),
5326 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
5327 ifname);
5328 run_system(dut, buf);
5329
5330 /* Find the least preference number */
5331 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
5332 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
5333
5334 ap_ne_class = 1;
5335 ap_ne_pref = 255;
5336 ap_ne_op_ch = 1;
5337 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
5338 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
5339 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
5340 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
5341 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
5342 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
5343
5344 if (ap_ne_pref < least_pref)
5345 least_pref = ap_ne_pref;
5346 snprintf(buf, sizeof(buf),
5347 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5348 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
5349 mac_addr[3], mac_addr[4], mac_addr[5],
5350 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
5351 run_system(dut, buf);
5352 }
5353
5354 /* Now add the self AP Address */
5355 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
5356 if (dut->ap_channel <= 11)
5357 ap_ne_class = 81;
5358 else
5359 ap_ne_class = 115;
5360 } else {
5361 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
5362 }
5363
5364 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
5365 ap_ne_op_ch = dut->ap_channel;
5366 else
5367 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
5368
5369 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
5370 ap_ne_pref = least_pref - 1;
5371 else
5372 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
5373
5374 snprintf(buf, sizeof(buf),
5375 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
5376 ifname, self_mac[0], self_mac[1], self_mac[2],
5377 self_mac[3], self_mac[4], self_mac[5],
5378 ap_ne_pref,
5379 ap_ne_class,
5380 ap_ne_op_ch);
5381 run_system(dut, buf);
5382}
5383
5384
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -07005385static void mubrp_commands(struct sigma_dut *dut, const char *ifname)
5386{
5387 run_iwpriv(dut, ifname, "he_subfer 1");
5388 run_iwpriv(dut, ifname, "he_mubfer 1");
5389 /* To enable MU_AX with MU_BRP trigger */
5390 run_iwpriv(dut, ifname, "he_sounding_mode 13");
5391 /* Sets g_force_1x1_peer to 1 which should be reset to zero for non MU
5392 * test cases */
5393 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 118 1",
5394 ifname);
5395 /* Disable DL OFDMA */
5396 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 11 0",
5397 ifname);
5398}
5399
5400
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005401static void ath_ap_set_params(struct sigma_dut *dut)
5402{
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005403 const char *basedev = "wifi0";
5404 const char *basedev_radio = "wifi1";
5405 char *ifname = get_main_ifname();
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005406 char *ifname_dual = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005407 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005408 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005409
priyadharshini gowthamane1617462017-04-25 12:03:59 -07005410 if (sigma_radio_ifname[0])
5411 basedev = sigma_radio_ifname[0];
5412
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005413 if (dut->ap_is_dual == 1) {
5414 basedev = sigma_radio_ifname[0];
5415 basedev_radio = sigma_radio_ifname[1];
5416 if (sigma_radio_ifname[0] &&
5417 strcmp(sigma_radio_ifname[0], "wifi0") == 0) {
5418 ifname = "ath0";
5419 ifname_dual = "ath1";
5420 } else {
5421 ifname = "ath1";
5422 ifname_dual = "ath0";
5423 }
5424 }
5425
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005426 if (dut->ap_countrycode[0]) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005427 run_iwpriv(dut, basedev, "setCountry %s", dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005428 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
5429 }
5430
5431 for (i = 0; i < NUM_AP_AC; i++) {
5432 if (dut->ap_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005433 run_iwpriv(dut, ifname, "cwmin %d 0 %d", i,
5434 dut->ap_qos[i].cwmin);
5435 run_iwpriv(dut, ifname, "cwmax %d 0 %d", i,
5436 dut->ap_qos[i].cwmax);
5437 run_iwpriv(dut, ifname, "aifs %d 0 %d", i,
5438 dut->ap_qos[i].aifs);
5439 run_iwpriv(dut, ifname, "txoplimit %d 0 %d", i,
5440 dut->ap_qos[i].txop);
5441 run_iwpriv(dut, ifname, "acm %d 0 %d", i,
5442 dut->ap_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005443 }
5444 }
5445
5446 for (i = 0; i < NUM_AP_AC; i++) {
5447 if (dut->ap_sta_qos[i].ac) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005448 run_iwpriv(dut, ifname, "cwmin %d 1 %d", i,
5449 dut->ap_sta_qos[i].cwmin);
5450 run_iwpriv(dut, ifname, "cwmax %d 1 %d", i,
5451 dut->ap_sta_qos[i].cwmax);
5452 run_iwpriv(dut, ifname, "aifs %d 1 %d", i,
5453 dut->ap_sta_qos[i].aifs);
5454 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", i,
5455 dut->ap_sta_qos[i].txop);
5456 run_iwpriv(dut, ifname, "acm %d 1 %d", i,
5457 dut->ap_sta_qos[i].acm);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005458 }
5459 }
5460
5461 if (dut->ap_disable_protection == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005462 run_iwpriv(dut, ifname, "enablertscts 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005463 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
5464 }
5465
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005466 if (dut->ap_ldpc == VALUE_ENABLED)
5467 run_iwpriv(dut, ifname, "ldpc 3");
5468 else if (dut->ap_ldpc == VALUE_DISABLED)
5469 run_iwpriv(dut, ifname, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005470
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005471 if (dut->ap_ampdu == VALUE_ENABLED)
5472 run_iwpriv(dut, ifname, "ampdu 1");
5473 else if (dut->ap_ampdu == VALUE_DISABLED)
5474 run_iwpriv(dut, ifname, "ampdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005475
5476 if (dut->ap_ampdu_exp) {
5477 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005478 run_iwpriv(dut, ifname, "vhtmaxampdu %d",
5479 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005480 } else {
5481 /* 11N */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005482 run_iwpriv(dut, ifname, "maxampdu %d",
5483 dut->ap_ampdu_exp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005484 }
5485 }
5486
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005487 if (dut->ap_noack == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005488 run_iwpriv(dut, ifname, "noackpolicy 0 0 1");
5489 run_iwpriv(dut, ifname, "noackpolicy 1 0 1");
5490 run_iwpriv(dut, ifname, "noackpolicy 2 0 1");
5491 run_iwpriv(dut, ifname, "noackpolicy 3 0 1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005492 } else if (dut->ap_noack == VALUE_DISABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005493 run_iwpriv(dut, ifname, "noackpolicy 0 0 0");
5494 run_iwpriv(dut, ifname, "noackpolicy 1 0 0");
5495 run_iwpriv(dut, ifname, "noackpolicy 2 0 0");
5496 run_iwpriv(dut, ifname, "noackpolicy 3 0 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005497 }
5498
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005499 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map)
5500 run_iwpriv(dut, ifname, "vht_mcsmap 0x%04x",
5501 dut->ap_vhtmcs_map);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005502
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005503 if (dut->ap_amsdu == VALUE_ENABLED)
5504 run_iwpriv(dut, ifname, "amsdu 2");
5505 else if (dut->ap_amsdu == VALUE_DISABLED)
5506 run_iwpriv(dut, ifname, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005507
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005508 if (dut->ap_rx_amsdu == VALUE_ENABLED)
5509 run_iwpriv(dut, basedev_radio, "rx_amsdu 1");
5510 else if (dut->ap_rx_amsdu == VALUE_DISABLED)
5511 run_iwpriv(dut, basedev_radio, "rx_amsdu 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005512
5513 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005514 if (dut->ap_addba_reject != VALUE_NOT_SET &&
5515 dut->ap_ampdu == VALUE_DISABLED &&
5516 dut->ap_amsdu == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005517 run_iwpriv(dut, ifname, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005518
5519 snprintf(buf, sizeof(buf),
5520 "wifitool %s senddelba 1 0 1 4", ifname);
5521 if (system(buf) != 0) {
5522 sigma_dut_print(dut, DUT_MSG_ERROR,
5523 "wifitool senddelba failed");
5524 }
5525
5526 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
5527 ifname);
5528 if (system(buf) != 0) {
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "wifitool sendsingleamsdu failed");
5531 }
5532
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005533 run_iwpriv(dut, ifname, "amsdu 10");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005534 }
5535
5536 if (dut->ap_mode == AP_11ac) {
5537 int chwidth, nss;
5538
5539 switch (dut->ap_chwidth) {
5540 case AP_20:
5541 chwidth = 0;
5542 break;
5543 case AP_40:
5544 chwidth = 1;
5545 break;
5546 case AP_80:
5547 chwidth = 2;
5548 break;
5549 case AP_160:
5550 chwidth = 3;
5551 break;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08005552 case AP_80_80:
5553 chwidth = 3;
5554 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005555 default:
5556 chwidth = 0;
5557 break;
5558 }
5559
5560 switch (dut->ap_tx_streams) {
5561 case 1:
5562 nss = 1;
5563 break;
5564 case 2:
5565 nss = 2;
5566 break;
5567 case 3:
5568 nss = 3;
5569 break;
5570 case 4:
5571 nss = 4;
5572 break;
5573 default:
5574 nss = 3;
5575 break;
5576 }
5577
5578 if (dut->ap_fixed_rate) {
5579 if (nss == 4)
5580 ath_disable_txbf(dut, ifname);
5581
5582 /* Set the nss */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005583 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584
5585 /* Set the channel width */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005586 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005587
5588 /* Set the VHT MCS */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005589 run_iwpriv(dut, ifname, "vhtmcs %d", dut->ap_mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005590 }
5591 }
5592
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005593 if (dut->ap_dyn_bw_sig == VALUE_ENABLED)
5594 run_iwpriv(dut, ifname, "cwmenable 1");
5595 else if (dut->ap_dyn_bw_sig == VALUE_DISABLED)
5596 run_iwpriv(dut, ifname, "cwmenable 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005597
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005598 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005599 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
5600 if (system(buf) != 0) {
5601 sigma_dut_print(dut, DUT_MSG_ERROR,
5602 "iwconfig rts 64 failed");
5603 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02005604 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005605 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
5606 if (system(buf) != 0) {
5607 sigma_dut_print(dut, DUT_MSG_ERROR,
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005608 "iwconfig rts 2347 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005609 }
5610 }
5611
5612 if (dut->ap_hs2) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005613 run_iwpriv(dut, ifname, "qbssload 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005614 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
5615 }
5616
5617 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
5618 unsigned int bssload = 0;
5619
5620 if (dut->ap_bss_load == 1) {
5621 /* STA count: 1, CU: 50, AAC: 65535 */
5622 bssload = 0x0132ffff;
5623 } else if (dut->ap_bss_load == 2) {
5624 /* STA count: 1, CU: 200, AAC: 65535 */
5625 bssload = 0x01c8ffff;
5626 } else if (dut->ap_bss_load == 3) {
5627 /* STA count: 1, CU: 75, AAC: 65535 */
5628 bssload = 0x014bffff;
5629 }
5630
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005631 run_iwpriv(dut, ifname, "hcbssload %u", bssload);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005632 } else if (dut->ap_bss_load == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005633 run_iwpriv(dut, ifname, "qbssload 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
5635 }
5636
5637 if (dut->ap_dgaf_disable) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005638 run_iwpriv(dut, ifname, "dgaf_disable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005639 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
5640 }
5641
5642 if (dut->ap_l2tif) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005643 run_iwpriv(dut, ifname, "l2tif 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005644 snprintf(buf, sizeof(buf),
5645 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
5646 if (system(buf) != 0)
5647 sigma_dut_print(dut, DUT_MSG_ERROR,
5648 "l2tif br failed");
5649
5650 snprintf(buf, sizeof(buf),
5651 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
5652 if (system(buf) != 0)
5653 sigma_dut_print(dut, DUT_MSG_ERROR,
5654 "l2tif brif failed");
5655 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
5656 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08005657
5658 if (dut->ap_ndpa_frame == 0) {
5659 snprintf(buf, sizeof(buf),
5660 "wifitool %s beeliner_fw_test 117 192", ifname);
5661 if (system(buf) != 0) {
5662 sigma_dut_print(dut, DUT_MSG_ERROR,
5663 "wifitool beeliner_fw_test 117 192 failed");
5664 }
5665 snprintf(buf, sizeof(buf),
5666 "wifitool %s beeliner_fw_test 118 192", ifname);
5667 if (system(buf) != 0) {
5668 sigma_dut_print(dut, DUT_MSG_ERROR,
5669 "wifitool beeliner_fw_test 117 192 failed");
5670 }
5671 } else if (dut->ap_ndpa_frame == 1) {
5672 /* Driver default - no changes needed */
5673 } else if (dut->ap_ndpa_frame == 2) {
5674 snprintf(buf, sizeof(buf),
5675 "wifitool %s beeliner_fw_test 115 1", ifname);
5676 if (system(buf) != 0) {
5677 sigma_dut_print(dut, DUT_MSG_ERROR,
5678 "wifitool beeliner_fw_test 117 192 failed");
5679 }
5680 snprintf(buf, sizeof(buf),
5681 "wifitool %s beeliner_fw_test 116 1", ifname);
5682 if (system(buf) != 0) {
5683 sigma_dut_print(dut, DUT_MSG_ERROR,
5684 "wifitool beeliner_fw_test 117 192 failed");
5685 }
5686 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005687
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005688 if (dut->ap_rtt == 1)
5689 run_iwpriv(dut, ifname, "enable_rtt 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005690
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005691 if (dut->ap_lci == 1)
5692 run_iwpriv(dut, ifname, "enable_lci 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005693
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005694 if (dut->ap_lcr == 1)
5695 run_iwpriv(dut, ifname, "enable_lcr 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005696
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005697 if (dut->ap_rrm == 1)
5698 run_iwpriv(dut, ifname, "enable_rmm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005699
5700 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
5701 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
5702 }
5703
5704 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
5705 FILE *f;
5706
5707 f = fopen("/tmp/nbr_report.txt", "w");
5708 if (!f) {
5709 sigma_dut_print(dut, DUT_MSG_ERROR,
5710 "Failed to open /tmp/nbr_report.txt");
5711 return;
5712 }
5713
5714 fprintf(f,
5715 "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",
5716 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5717 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5718 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5719 dut->ap_val_opchannel[0]);
5720 fclose(f);
5721
5722 f = fopen("/tmp/ftmrr.txt", "w");
5723 if (!f) {
5724 sigma_dut_print(dut, DUT_MSG_ERROR,
5725 "Failed to open /tmp/ftmrr.txt");
5726 return;
5727 }
5728
5729 fprintf(f,
5730 "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",
5731 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
5732 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
5733 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
5734 dut->ap_val_opchannel[0]);
5735 fclose(f);
5736 }
5737
5738 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
5739 FILE *f;
5740
5741 f = fopen("/tmp/nbr_report.txt", "a");
5742 if (!f) {
5743 sigma_dut_print(dut, DUT_MSG_ERROR,
5744 "Failed to open /tmp/nbr_report.txt");
5745 return;
5746 }
5747 fprintf(f,
5748 "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",
5749 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5750 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5751 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5752 dut->ap_val_opchannel[1]);
5753 fclose(f);
5754
5755 f = fopen("/tmp/ftmrr.txt", "a");
5756 if (!f) {
5757 sigma_dut_print(dut, DUT_MSG_ERROR,
5758 "Failed to open /tmp/ftmrr.txt");
5759 return;
5760 }
5761 fprintf(f,
5762 "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",
5763 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
5764 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
5765 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
5766 dut->ap_val_opchannel[1]);
5767 fclose(f);
5768 }
5769
5770 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
5771 FILE *f;
5772
5773 f = fopen("/tmp/nbr_report.txt", "a");
5774 if (!f) {
5775 sigma_dut_print(dut, DUT_MSG_ERROR,
5776 "Failed to open /tmp/nbr_report.txt");
5777 return;
5778 }
5779
5780 fprintf(f,
5781 "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",
5782 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5783 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5784 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5785 dut->ap_val_opchannel[2]);
5786 fclose(f);
5787
5788 f = fopen("/tmp/ftmrr.txt", "a");
5789 if (!f) {
5790 sigma_dut_print(dut, DUT_MSG_ERROR,
5791 "Failed to open /tmp/ftmrr.txt");
5792 return;
5793 }
5794
5795 fprintf(f,
5796 "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",
5797 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
5798 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
5799 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
5800 dut->ap_val_opchannel[2]);
5801 fclose(f);
5802 }
5803
5804 if (dut->ap_neighap) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005805 run_iwpriv(dut, ifname, "enable_rtt 1");
5806 run_iwpriv(dut, ifname, "enable_lci 1");
5807 run_iwpriv(dut, ifname, "enable_lcr 1");
5808 run_iwpriv(dut, ifname, "enable_rrm 1");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005809 }
5810
5811 if (dut->ap_scan == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005812 run_iwpriv(dut, ifname, "scanentryage 600");
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07005813 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
5814 run_system(dut, buf);
5815 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07005816
5817 if (dut->ap_set_bssidpref) {
5818 snprintf(buf, sizeof(buf),
5819 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
5820 ifname);
5821 if (system(buf) != 0) {
5822 sigma_dut_print(dut, DUT_MSG_ERROR,
5823 "wifitool clear bssidpref failed");
5824 }
5825 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005826
5827 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
5828 int feature_enable;
5829
5830 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005831 run_iwpriv(dut, ifname, "wnm %d", feature_enable);
5832 run_iwpriv(dut, ifname, "wnm_bss %d", feature_enable);
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07005833 if (feature_enable) {
5834 const char *extra = "";
5835
5836 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
5837 if (dut->wnm_bss_max_protection ==
5838 VALUE_ENABLED)
5839 extra = " 1";
5840 else
5841 extra = " 0";
5842 }
5843 snprintf(buf, sizeof(buf),
5844 "wlanconfig %s wnm setbssmax %d%s",
5845 ifname, dut->wnm_bss_max_idle_time, extra);
5846 run_system(dut, buf);
5847 }
5848 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005849
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005850 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07005851 apply_mbo_pref_ap_list(dut);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005852 run_iwpriv(dut, ifname, "mbo_cel_pref %d",
5853 dut->ap_cell_cap_pref);
5854 run_iwpriv(dut, ifname, "mbocap 0x40");
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07005855 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07005856 }
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005857
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005858 if (dut->ap_oce == VALUE_ENABLED)
5859 run_iwpriv(dut, ifname, "set_bpr_enable 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005860
5861 if (dut->ap_oce == VALUE_ENABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005862 run_iwpriv(dut, ifname, "prb_rate 5500");
5863 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005864 }
5865
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005866 if (dut->ap_oce == VALUE_DISABLED)
5867 run_iwpriv(dut, ifname, "set_bpr_enable 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005868
5869 if (dut->ap_oce == VALUE_DISABLED && dut->ap_channel <= 11) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005870 run_iwpriv(dut, ifname, "mgmt_rate 1000");
5871 run_iwpriv(dut, ifname, "set_bcn_rate 1000");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005872 }
5873
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005874 if (dut->ap_bcnint)
5875 run_iwpriv(dut, ifname, "bintval %d", dut->ap_bcnint);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005876
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005877 if (dut->ap_filsdscv == VALUE_DISABLED)
5878 run_iwpriv(dut, ifname, "enable_fils 0 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005879
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005880 if (dut->ap_filshlp == VALUE_ENABLED)
5881 run_iwpriv(dut, ifname, "oce_hlp 1");
5882 else if (dut->ap_filshlp == VALUE_DISABLED)
5883 run_iwpriv(dut, ifname, "oce_hlp 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005884
5885 /* When RNR is enabled, also enable apchannelreport, background scan */
5886 if (dut->ap_rnr == VALUE_ENABLED) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005887 run_iwpriv(dut, ifname, "rnr 1");
5888 run_iwpriv(dut, ifname, "rnr_tbtt 1");
5889 run_iwpriv(dut, ifname, "apchanrpt 1");
5890 run_iwpriv(dut, basedev, "acs_ctrlflags 0x4");
5891 run_iwpriv(dut, basedev, "acs_scanintvl 60");
5892 run_iwpriv(dut, basedev, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005893 if (dut->ap_is_dual == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005894 run_iwpriv(dut, ifname_dual, "rnr 1");
5895 run_iwpriv(dut, ifname_dual, "rnr_tbtt 1");
5896 run_iwpriv(dut, ifname_dual, "apchanrpt 1");
5897 run_iwpriv(dut, basedev_radio, "acs_ctrlflags 0x4");
5898 run_iwpriv(dut, basedev_radio, "acs_scanintvl 60");
5899 run_iwpriv(dut, basedev_radio, "acs_bkscanen 1");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005900 }
5901 }
5902
5903 if (dut->ap_blechanutil || dut->ap_ble_admit_cap || dut->ap_blestacnt) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005904 run_iwpriv(dut, ifname, "qbssload 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005905 snprintf(buf, sizeof(buf),
5906 "wlanconfig %s addie ftype 0 len 7 data 0b05%02x%02x%02x%02x%02x ",
5907 ifname, dut->ap_blestacnt & 0xFF,
5908 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5909 dut->ap_ble_admit_cap & 0xFF,
5910 dut->ap_ble_admit_cap >> 8);
5911 run_system(dut, buf);
5912 snprintf(buf, sizeof(buf),
5913 "wlanconfig %s addie ftype 2 len 7 data 0b05%02x%02x%02x%02x%02x ",
5914 ifname, dut->ap_blestacnt & 0xFF,
5915 dut->ap_blestacnt >> 8, dut->ap_blechanutil,
5916 dut->ap_ble_admit_cap & 0xFF,
5917 dut->ap_ble_admit_cap >> 8);
5918 run_system(dut, buf);
5919 }
5920
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005921 if (dut->ap_esp == VALUE_ENABLED)
5922 run_iwpriv(dut, basedev, "esp_period 5");
5923 else if (dut->ap_esp == VALUE_DISABLED)
5924 run_iwpriv(dut, basedev, "esp_period 0");
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005925
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005926 if (dut->ap_datappdudura)
5927 run_iwpriv(dut, basedev, "esp_ppdu_dur %d",
5928 dut->ap_datappdudura);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005929
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005930 if (dut->ap_airtimefract)
5931 run_iwpriv(dut, basedev, "esp_airtime %d",
5932 dut->ap_airtimefract);
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08005933
5934 if (dut->ap_dhcp_stop) {
5935 snprintf(buf, sizeof(buf), "/etc/init.d/dnsmasq stop");
5936 run_system(dut, buf);
5937 }
5938
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005939 if (dut->ap_bawinsize)
5940 run_iwpriv(dut, basedev, "esp_ba_window %d", dut->ap_bawinsize);
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005941
5942 if (dut->program == PROGRAM_DPP) {
5943 if (dut->ap_interface_2g == 1) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005944 run_iwpriv(dut, ifname, "set_bcn_rate 5500");
5945 run_iwpriv(dut, ifname, "prb_rate 5500");
5946 run_iwpriv(dut, ifname, "mgmt_rate 5500");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005947 }
5948
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07005949 run_iwpriv(dut, basedev, "set_rxfilter 0xffffffff");
priyadharshini gowthamanb4de1962018-01-15 12:21:04 -08005950 dut->hostapd_running = 1;
5951 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07005952
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07005953 if (dut->ap_he_ulofdma == VALUE_ENABLED) {
5954 run_iwpriv(dut, ifname, "he_ul_ofdma 1");
5955 run_iwpriv(dut, ifname, "he_mu_edca 1");
5956
5957 /* Disable sounding for UL OFDMA */
5958 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 0",
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07005959 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07005960
5961 if ((dut->ap_rx_streams || dut->ap_tx_streams) &&
5962 dut->device_type == AP_testbed) {
5963 unsigned int txchainmask = 0x00;
5964
5965 switch (dut->ap_rx_streams) {
5966 case 1:
5967 txchainmask = 0x01;
5968 break;
5969 case 2:
5970 txchainmask = 0x03;
5971 break;
5972 case 3:
5973 txchainmask = 0x07;
5974 break;
5975 case 4:
5976 txchainmask = 0x0f;
5977 break;
5978 case 5:
5979 txchainmask = 0x1f;
5980 break;
5981 case 6:
5982 txchainmask = 0x3f;
5983 break;
5984 case 7:
5985 txchainmask = 0x7f;
5986 break;
5987 case 8:
5988 txchainmask = 0xff;
5989 break;
5990 }
5991
5992 run_iwpriv(dut, ifname, "he_ul_nss %d",
5993 dut->ap_rx_streams);
5994 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
5995 run_iwpriv(dut, basedev, "rxchainmask %d", txchainmask);
5996 }
5997
5998 if (dut->ap_channel == 100 && dut->device_type == AP_testbed)
5999 run_system_wrapper(dut, "iwpriv %s inact 1000", ifname);
6000
6001 run_iwpriv(dut, ifname, "he_ul_ltf 3");
6002 run_iwpriv(dut, ifname, "he_ul_shortgi 3");
6003 run_iwpriv(dut, basedev, "he_ul_trig_int 2");
6004
6005 /* Set random RU allocation */
6006 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 9 1",
6007 ifname);
6008 /* To set TBTT PPDU duration (us) */
6009 run_system_wrapper(dut,
6010 "wifitool %s setUnitTestCmd 0x48 2 63 1908",
6011 ifname);
6012 }
6013
6014 if (dut->program == PROGRAM_HE && dut->device_type == AP_testbed &&
6015 dut->ap_he_dlofdma == VALUE_DISABLED)
6016 run_iwpriv(dut, ifname, "he_dl_ofdma 0");
6017
6018 if (dut->ap_he_dlofdma == VALUE_ENABLED) {
6019 run_iwpriv(dut, ifname, "he_dl_ofdma 1", ifname);
6020
6021 /* For fixed MCS */
6022 novap_reset(dut, ifname, 0);
6023 run_iwpriv(dut, ifname,
6024 "cfg80211tool %s setratemask 3 0x80f80f80 0x0f80f80f 0xf80f80f8");
6025 }
6026
6027 if (dut->ap_he_ppdu == PPDU_MU && dut->ap_he_dlofdma == VALUE_ENABLED) {
6028 /* Increase the min TX time limit for MU MIMO to disable MU MIMO
6029 * scheduling */
6030 run_system_wrapper(dut,
6031 "wifitool %s setUnitTestCmd 0x47 2 11 1000000",
6032 ifname);
6033 /* Increase the max TX time limit for DL OFDMA to enable OFDMA
6034 * scheduling */
6035 run_system_wrapper(dut,
6036 "wifitool %s setUnitTestCmd 0x47 2 17 1000000",
6037 ifname);
6038 /* Disable 'force SU schedule' to enable MU sch */
6039 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 8 0",
6040 ifname);
6041 /* Enable MU 11ax support in sch algo */
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006042 run_system_wrapper(dut,
6043 "wifitool %s setUnitTestCmd 0x47 2 29 0",
6044 ifname);
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07006045 /* Enable to sort RU allocation */
6046 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x4b 2 2 1",
6047 ifname);
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07006048 }
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07006049
6050 if (dut->ap_numsounddim) {
6051 unsigned int txchainmask = 0;
6052
6053 switch (dut->ap_numsounddim) {
6054 case 1:
6055 txchainmask = 0x01;
6056 break;
6057 case 2:
6058 txchainmask = 0x03;
6059 break;
6060 case 3:
6061 txchainmask = 0x07;
6062 break;
6063 case 4:
6064 txchainmask = 0x0f;
6065 break;
6066 case 5:
6067 txchainmask = 0x1f;
6068 break;
6069 case 6:
6070 txchainmask = 0x3f;
6071 break;
6072 case 7:
6073 txchainmask = 0x7f;
6074 break;
6075 case 8:
6076 txchainmask = 0xff;
6077 break;
6078 }
6079 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
6080 }
6081
6082 if (dut->ap_numsounddim && dut->device_type == AP_testbed) {
6083 /* Sets g_force_1x1_peer to 1 which should be reset to zero
6084 * for non-MU test cases */
6085 run_system_wrapper(dut,
6086 "wifitool %s setUnitTestCmd 0x48 2 118 1",
6087 ifname);
6088 if (dut->ap_mu_txBF) {
6089 /* Disable DL OFDMA */
6090 run_system_wrapper(dut,
6091 "wifitool %s setUnitTestCmd 0x47 2 11 0",
6092 ifname);
6093 }
6094 }
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07006095
6096 if (dut->ap_channel <= 11 && dut->program == PROGRAM_HE &&
6097 dut->device_type == AP_testbed) {
6098 dut->ap_bcc = VALUE_ENABLED;
6099 run_iwpriv(dut, ifname, "vht_11ng 0");
6100 }
6101
6102 if (dut->ap_bcc == VALUE_ENABLED) {
6103 run_iwpriv(dut, ifname, "mode 11AHE20");
6104 run_iwpriv(dut, ifname, "nss 2");
6105 run_iwpriv(dut, ifname, "he_txmcsmap 0x0");
6106 run_iwpriv(dut, ifname, "he_rxmcsmap 0x0");
6107 }
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07006108
6109 if (dut->ap_he_frag == VALUE_ENABLED)
6110 run_iwpriv(dut, ifname, "he_frag 1");
6111 else if (dut->ap_he_frag == VALUE_DISABLED)
6112 run_iwpriv(dut, ifname, "he_frag 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006113}
6114
6115
6116static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
6117 struct sigma_conn *conn,
6118 struct sigma_cmd *cmd)
6119{
6120 /* const char *name = get_param(cmd, "NAME"); */
6121 char buf[100];
6122 struct stat s;
6123 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
Jouni Malinen3aa72862019-05-29 23:14:51 +03006124 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006125
6126 if (stat("/proc/athversion", &s) == 0) {
6127 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
6128 run_system(dut, "apdown");
6129 }
6130
6131 cmd_ath_ap_radio_config(dut);
6132
6133 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
6134 run_system(dut, buf);
6135
6136 switch (dut->ap_key_mgmt) {
6137 case AP_OPEN:
6138 if (dut->ap_cipher == AP_WEP) {
6139 run_system(dut, "cfg -a AP_SECMODE=WEP");
6140 run_system(dut, "cfg -a AP_SECFILE=NONE");
6141 /* shared auth mode not supported */
6142 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6143 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6144 snprintf(buf, sizeof(buf),
6145 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6146 dut->ap_wepkey);
6147 run_system(dut, buf);
6148 snprintf(buf, sizeof(buf),
6149 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6150 dut->ap_wepkey);
6151 run_system(dut, buf);
6152 } else {
6153 run_system(dut, "cfg -a AP_SECMODE=None");
6154 }
6155 break;
6156 case AP_WPA2_PSK:
6157 case AP_WPA2_PSK_MIXED:
6158 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006159 case AP_WPA2_SAE:
6160 case AP_WPA2_PSK_SAE:
6161 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6162 dut->ap_key_mgmt == AP_WPA2_SAE ||
6163 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006164 run_system(dut, "cfg -a AP_WPA=2");
6165 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6166 run_system(dut, "cfg -a AP_WPA=3");
6167 else
6168 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03006169 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006170 run_system(dut, "cfg -a AP_SECMODE=WPA");
6171 run_system(dut, "cfg -a AP_SECFILE=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006172 res = snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
6173 dut->ap_passphrase);
6174 if (res < 0 || res >= sizeof(buf))
6175 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006176 run_system(dut, buf);
6177 if (dut->ap_cipher == AP_CCMP_TKIP)
6178 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6179 else if (dut->ap_cipher == AP_TKIP)
6180 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6181 else
6182 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6183 break;
6184 case AP_WPA2_EAP:
6185 case AP_WPA2_EAP_MIXED:
6186 case AP_WPA_EAP:
6187 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6188 run_system(dut, "cfg -a AP_WPA=2");
6189 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6190 run_system(dut, "cfg -a AP_WPA=3");
6191 else
6192 run_system(dut, "cfg -a AP_WPA=1");
6193 run_system(dut, "cfg -a AP_SECMODE=WPA");
6194 run_system(dut, "cfg -a AP_SECFILE=EAP");
6195 if (dut->ap_cipher == AP_CCMP_TKIP)
6196 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
6197 else if (dut->ap_cipher == AP_TKIP)
6198 run_system(dut, "cfg -a AP_CYPHER=TKIP");
6199 else
6200 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6201 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
6202 dut->ap_radius_ipaddr);
6203 run_system(dut, buf);
6204 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
6205 dut->ap_radius_port);
6206 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006207 res = snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
6208 dut->ap_radius_password);
6209 if (res < 0 || res >= sizeof(buf))
6210 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211 run_system(dut, buf);
6212 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006213 case AP_WPA2_EAP_OSEN:
6214 /* TODO */
6215 sigma_dut_print(dut, DUT_MSG_ERROR, "EAP+OSEN not supported");
6216 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006217 case AP_SUITEB:
6218 /* TODO */
6219 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
6220 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006221 case AP_WPA2_OWE:
6222 /* TODO */
6223 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
6224 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006225 case AP_WPA2_FT_EAP:
6226 case AP_WPA2_FT_PSK:
6227 case AP_WPA2_EAP_SHA256:
6228 case AP_WPA2_PSK_SHA256:
6229 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006230 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006231 /* TODO */
6232 send_resp(dut, conn, SIGMA_ERROR,
6233 "errorCode,Unsupported KeyMgnt value");
6234 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006235 }
6236
6237 if (dut->ap_is_dual) {
6238 /* ath1 settings in case of dual */
6239 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
6240 dut->ap_ssid);
6241 run_system(dut, buf);
6242
6243 switch (dut->ap_key_mgmt) {
6244 case AP_OPEN:
6245 if (dut->ap_cipher == AP_WEP) {
6246 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
6247 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
6248 /* shared auth mode not supported */
6249 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
6250 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
6251 snprintf(buf, sizeof(buf),
6252 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
6253 dut->ap_wepkey);
6254 run_system(dut, buf);
6255 snprintf(buf, sizeof(buf),
6256 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
6257 dut->ap_wepkey);
6258 run_system(dut, buf);
6259 } else {
6260 run_system(dut, "cfg -a AP_SECMODE_2=None");
6261 }
6262 break;
6263 case AP_WPA2_PSK:
6264 case AP_WPA2_PSK_MIXED:
6265 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03006266 case AP_WPA2_SAE:
6267 case AP_WPA2_PSK_SAE:
6268 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
6269 dut->ap_key_mgmt == AP_WPA2_SAE ||
6270 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006271 run_system(dut, "cfg -a AP_WPA_2=2");
6272 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
6273 run_system(dut, "cfg -a AP_WPA_2=3");
6274 else
6275 run_system(dut, "cfg -a AP_WPA_2=1");
6276 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03006277 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6279 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
Jouni Malinen3aa72862019-05-29 23:14:51 +03006280 res = snprintf(buf, sizeof(buf),
6281 "cfg -a 'PSK_KEY_2=%s'",
6282 dut->ap_passphrase);
6283 if (res < 0 || res >= sizeof(buf))
6284 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006285 run_system(dut, buf);
6286 if (dut->ap_cipher == AP_CCMP_TKIP)
6287 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6288 else if (dut->ap_cipher == AP_TKIP)
6289 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6290 else
6291 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6292 break;
6293 case AP_WPA2_EAP:
6294 case AP_WPA2_EAP_MIXED:
6295 case AP_WPA_EAP:
6296 if (dut->ap_key_mgmt == AP_WPA2_EAP)
6297 run_system(dut, "cfg -a AP_WPA_2=2");
6298 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
6299 run_system(dut, "cfg -a AP_WPA_2=3");
6300 else
6301 run_system(dut, "cfg -a AP_WPA_2=1");
6302 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6303 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
6304 if (dut->ap_cipher == AP_CCMP_TKIP)
6305 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
6306 else if (dut->ap_cipher == AP_TKIP)
6307 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
6308 else
6309 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
6310
6311 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
6312 dut->ap_radius_ipaddr);
6313 run_system(dut, buf);
6314 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
6315 dut->ap_radius_port);
6316 run_system(dut, buf);
Jouni Malinen3aa72862019-05-29 23:14:51 +03006317 res = snprintf(buf, sizeof(buf),
6318 "cfg -a AP_AUTH_SECRET_2=%s",
6319 dut->ap_radius_password);
6320 if (res < 0 || res >= sizeof(buf))
6321 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006322 run_system(dut, buf);
6323 break;
Jouni Malinen4cf699f2018-06-19 00:46:27 +03006324 case AP_WPA2_EAP_OSEN:
6325 /* TODO */
6326 sigma_dut_print(dut, DUT_MSG_ERROR,
6327 "EAP+OSEN not supported");
6328 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03006329 case AP_SUITEB:
6330 /* TODO */
6331 sigma_dut_print(dut, DUT_MSG_ERROR,
6332 "SuiteB not supported");
6333 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03006334 case AP_WPA2_OWE:
6335 /* TODO */
6336 sigma_dut_print(dut, DUT_MSG_ERROR,
6337 "OWE not supported");
6338 break;
Jouni Malinen6be21c82018-08-01 18:47:24 +03006339 case AP_WPA2_FT_EAP:
6340 case AP_WPA2_FT_PSK:
6341 case AP_WPA2_EAP_SHA256:
6342 case AP_WPA2_PSK_SHA256:
6343 case AP_WPA2_ENT_FT_EAP:
Jouni Malinenc2b91212018-09-12 02:26:39 +03006344 case AP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03006345 /* TODO */
6346 send_resp(dut, conn, SIGMA_ERROR,
6347 "errorCode,Unsupported KeyMgnt value");
6348 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006349 }
6350
6351 /* wifi0 settings in case of dual */
6352 run_system(dut, "cfg -a AP_RADIO_ID=0");
6353 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
6354 run_system(dut, "cfg -a AP_STARTMODE=dual");
6355 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
6356 run_system(dut, "cfg -a TX_CHAINMASK=7");
6357 run_system(dut, "cfg -a RX_CHAINMASK=7");
6358 }
6359
6360 switch (dut->ap_pmf) {
6361 case AP_PMF_DISABLED:
6362 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
6363 run_system(dut, buf);
6364 break;
6365 case AP_PMF_OPTIONAL:
6366 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
6367 run_system(dut, buf);
6368 break;
6369 case AP_PMF_REQUIRED:
6370 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
6371 run_system(dut, buf);
6372 break;
6373 }
6374 if (dut->ap_add_sha256) {
6375 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
6376 run_system(dut, buf);
6377 } else {
6378 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
6379 run_system(dut, buf);
6380 }
6381
6382 if (dut->ap_hs2)
6383 run_system(dut, "cfg -a AP_HOTSPOT=1");
6384 else
6385 run_system(dut, "cfg -r AP_HOTSPOT");
6386
6387 if (dut->ap_interworking) {
6388 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
6389 dut->ap_access_net_type);
6390 run_system(dut, buf);
6391 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
6392 dut->ap_internet);
6393 run_system(dut, buf);
6394 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
6395 dut->ap_venue_group);
6396 run_system(dut, buf);
6397 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
6398 dut->ap_venue_type);
6399 run_system(dut, buf);
6400 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
6401 dut->ap_hessid);
6402 run_system(dut, buf);
6403
6404 if (dut->ap_roaming_cons[0]) {
6405 char *second, *rc;
6406 rc = strdup(dut->ap_roaming_cons);
6407 if (rc == NULL)
6408 return 0;
6409
6410 second = strchr(rc, ';');
6411 if (second)
6412 *second++ = '\0';
6413
6414 snprintf(buf, sizeof(buf),
6415 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
6416 run_system(dut, buf);
6417
6418 if (second) {
6419 snprintf(buf, sizeof(buf),
6420 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
6421 "=%s", second);
6422 run_system(dut, buf);
6423 }
6424 free(rc);
6425 } else {
6426 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6427 run_system(dut,
6428 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6429 }
6430 } else {
6431 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
6432 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
6433 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
6434 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
6435 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
6436 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
6437 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
6438 }
6439
6440 if (dut->ap_proxy_arp)
6441 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
6442 else
6443 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
6444 if (dut->ap_dgaf_disable)
6445 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
6446 else
6447 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
6448
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006449 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006450 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006451 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006452 run_system(dut, buf);
6453
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006454 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006455 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
6456 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
6457
Jouni Malinen3aa72862019-05-29 23:14:51 +03006458 res = snprintf(buf, sizeof(buf),
6459 "cfg -a AP_AUTH_SERVER_2=%s",
6460 dut->ap2_radius_ipaddr);
6461 if (res < 0 || res >= sizeof(buf))
6462 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006463 run_system(dut, buf);
6464
Jouni Malinen3aa72862019-05-29 23:14:51 +03006465 res = snprintf(buf, sizeof(buf),
6466 "cfg -a AP_AUTH_PORT_2=%d",
6467 dut->ap2_radius_port);
6468 if (res < 0 || res >= sizeof(buf))
6469 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006470 run_system(dut, buf);
6471
Jouni Malinen3aa72862019-05-29 23:14:51 +03006472 res = snprintf(buf, sizeof(buf),
6473 "cfg -a AP_AUTH_SECRET_2=%s",
6474 dut->ap2_radius_password);
6475 if (res < 0 || res >= sizeof(buf))
6476 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006477 run_system(dut, buf);
6478 } else {
6479 run_system(dut, "cfg -a AP_SECMODE_2=None");
6480 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
6481 run_system(dut, "cfg -r AP_AUTH_PORT_2");
6482 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
6483 }
6484
6485 run_system(dut, "cfg -a AP_STARTMODE=multi");
6486 }
6487
6488 run_system(dut, "cfg -c");
6489
6490 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
6491 if (system("apup") != 0) {
6492 /* to be debugged why apup returns error
6493 send_resp(dut, conn, SIGMA_ERROR,
6494 "errorCode,apup failed");
6495 return 0;
6496 */
6497 }
6498 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
6499
6500 if (dut->ap_key_mgmt != AP_OPEN) {
6501 int res;
6502 /* allow some time for hostapd to start before returning
6503 * success */
6504 usleep(500000);
6505 if (run_hostapd_cli(dut, "ping") != 0) {
6506 send_resp(dut, conn, SIGMA_ERROR,
6507 "errorCode,Failed to talk to hostapd");
6508 return 0;
6509 }
6510
6511 if (dut->ap_hs2 && !dut->ap_anqpserver) {
6512 /* the cfg app doesn't like ";" in the variables */
6513 res = ath_ap_append_hostapd_conf(dut);
6514 if (res < 0)
6515 return res;
6516
6517 /* wait for hostapd to be ready */
6518 usleep(500000);
6519 if (run_hostapd_cli(dut, "ping") != 0) {
6520 send_resp(dut, conn, SIGMA_ERROR,
6521 "errorCode,Failed to talk to "
6522 "hostapd");
6523 return 0;
6524 }
6525 }
6526 }
6527
6528 ath_ap_set_params(dut);
6529
6530 if (dut->ap_anqpserver)
6531 return cmd_ath_ap_anqpserver_start(dut);
6532
6533 if (dut->ap2_proxy_arp)
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006534 run_iwpriv(dut, ifname, "proxy_arp 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006535
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07006536 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip)
6537 run_iwpriv(dut, ifname, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538
6539 return 1;
6540}
6541
6542
6543static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
6544 const char *ifname)
6545{
6546 char buf[200];
6547
6548 if (!chain || !ifname)
6549 return -2;
6550
6551 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6552 if (system(buf) != 0) {
6553 sigma_dut_print(dut, DUT_MSG_ERROR,
6554 "Failed to set ebtables rules, RULE-1, %s",
6555 chain);
6556 return -2;
6557 }
6558
6559 snprintf(buf, sizeof(buf),
6560 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6561 chain, ifname);
6562 if (system(buf) != 0) {
6563 sigma_dut_print(dut, DUT_MSG_ERROR,
6564 "Failed to set ebtables rules, RULE-2, %s",
6565 chain);
6566 return -2;
6567 }
6568
6569 snprintf(buf, sizeof(buf),
6570 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
6571 chain, ifname);
6572 if (system(buf) != 0) {
6573 sigma_dut_print(dut, DUT_MSG_ERROR,
6574 "Failed to set ebtables rules, RULE-3, %s",
6575 chain);
6576 return -2;
6577 }
6578
6579 snprintf(buf, sizeof(buf),
6580 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
6581 chain, ifname);
6582 if (system(buf) != 0) {
6583 sigma_dut_print(dut, DUT_MSG_ERROR,
6584 "Failed to set ebtables rules, RULE-4, %s",
6585 chain);
6586 return -2;
6587 }
6588
6589 return 0;
6590}
6591
6592
6593static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
6594 const char *chain,
6595 const char *ifname)
6596{
6597 char buf[200];
6598
6599 if (!chain || !ifname)
6600 return -2;
6601
6602 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
6603 if (system(buf) != 0) {
6604 sigma_dut_print(dut, DUT_MSG_ERROR,
6605 "Failed to set ebtables rules, RULE-5, %s",
6606 chain);
6607 return -2;
6608 }
6609
6610 snprintf(buf, sizeof(buf),
6611 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
6612 chain, ifname);
6613 if (system(buf) != 0) {
6614 sigma_dut_print(dut, DUT_MSG_ERROR,
6615 "Failed to set ebtables rules, RULE-6, %s",
6616 chain);
6617 return -2;
6618 }
6619
6620 snprintf(buf, sizeof(buf),
6621 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
6622 chain, ifname);
6623 if (system(buf) != 0) {
6624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "Failed to set ebtables rules, RULE-7, %s",
6626 chain);
6627 return -2;
6628 }
6629
6630 snprintf(buf, sizeof(buf),
6631 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
6632 chain, ifname);
6633 if (system(buf) != 0) {
6634 sigma_dut_print(dut, DUT_MSG_ERROR,
6635 "Failed to set ebtables rules, RULE-8, %s",
6636 chain);
6637 return -2;
6638 }
6639
6640 return 0;
6641}
6642
6643
Jouni Malinendbbc2c42018-11-14 23:55:41 +02006644static void set_ebtables_forward_drop(struct sigma_dut *dut,
6645 const char *ifname, const char *ifname2)
6646{
6647 char buf[128];
6648
6649 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6650 ifname, ifname2);
6651 if (system(buf) != 0)
6652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "Failed to set ebtables rule");
6654
6655 snprintf(buf, sizeof(buf), "ebtables -A FORWARD -i %s -o %s -j DROP",
6656 ifname2, ifname);
6657 if (system(buf) != 0)
6658 sigma_dut_print(dut, DUT_MSG_ERROR,
6659 "Failed to set ebtables rule");
6660}
6661
6662
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006663static int check_channel(int channel)
6664{
6665 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
6666 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
6667 161, 165 };
6668 int num_chan = sizeof(channel_list) / sizeof(int);
6669 int i;
6670
6671 for (i = 0; i < num_chan; i++) {
6672 if (channel == channel_list[i])
6673 return i;
6674 }
6675
6676 return -1;
6677}
6678
6679
6680static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
6681{
6682 int ch_base;
6683 int period;
6684
6685 if (check_channel(channel) < 0)
6686 return -1;
6687
6688 if (channel >= 36 && channel <= 64)
6689 ch_base = 36;
6690 else if (channel >= 100 && channel <= 144)
6691 ch_base = 100;
6692 else
6693 ch_base = 149;
6694
6695 period = channel % ch_base * 5 / chwidth;
6696 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
6697}
6698
6699
6700static int is_ht40plus_chan(int chan)
6701{
6702 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
6703 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
6704 chan == 132 || chan == 149 || chan == 157;
6705}
6706
6707
6708static int is_ht40minus_chan(int chan)
6709{
6710 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
6711 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
6712 chan == 136 || chan == 153 || chan == 161;
6713}
6714
6715
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05306716static int get_5g_channel_freq(int chan)
6717{
6718 return 5000 + chan * 5;
6719}
6720
6721
Jouni Malinen3d633da2017-09-14 22:19:21 +03006722static const char * hostapd_cipher_name(enum ap_cipher cipher)
6723{
6724 switch (cipher) {
6725 case AP_CCMP:
6726 return "CCMP";
6727 case AP_TKIP:
6728 return "TKIP";
6729 case AP_CCMP_TKIP:
6730 return "CCMP TKIP";
6731 case AP_GCMP_256:
6732 return "GCMP-256";
6733 case AP_GCMP_128:
6734 return "GCMP";
6735 case AP_CCMP_256:
6736 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02006737 case AP_CCMP_128_GCMP_256:
6738 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006739 default:
6740 return "UNKNOWN";
6741 }
6742}
6743
6744
6745static const char *
6746hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
6747{
6748 switch (cipher) {
6749 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03006750 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03006751 case AP_BIP_CMAC_256:
6752 return "BIP-CMAC-256";
6753 case AP_BIP_GMAC_128:
6754 return "BIP-GMAC-128";
6755 case AP_BIP_CMAC_128:
6756 return "AES-128-CMAC";
6757 default:
6758 return "UNKNOWN";
6759 }
6760}
6761
6762
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02006763static int ap_set_60g_ese(struct sigma_dut *dut, int count,
6764 struct sigma_ese_alloc *allocs)
6765{
6766 switch (get_driver_type()) {
6767#ifdef __linux__
6768 case DRIVER_WIL6210:
6769 return wil6210_set_ese(dut, count, allocs);
6770#endif /* __linux__ */
6771 default:
6772 sigma_dut_print(dut, DUT_MSG_ERROR,
6773 "Unsupported ap_set_60g_ese with the current driver");
6774 return -1;
6775 }
6776}
6777
6778
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006779static int ap_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
6780{
6781 switch (get_driver_type()) {
6782#ifdef __linux__
6783 case DRIVER_WIL6210:
6784 return wil6210_set_force_mcs(dut, force, mcs);
6785#endif /* __linux__ */
6786 default:
6787 sigma_dut_print(dut, DUT_MSG_ERROR,
6788 "Unsupported ap_set_force_mcs with the current driver");
6789 return -1;
6790 }
6791}
6792
6793
Jouni Malinenf7222712019-06-13 01:50:21 +03006794enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
6795 struct sigma_conn *conn,
6796 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006797{
6798 /* const char *name = get_param(cmd, "NAME"); */
6799 FILE *f;
6800 const char *ifname;
6801 char buf[500];
6802 char path[100];
6803 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03006804 const char *key_mgmt;
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05306805#ifdef ANDROID
6806 struct group *gr;
6807#endif /* ANDROID */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006808
6809 drv = get_driver_type();
6810
6811 if (dut->mode == SIGMA_MODE_STATION) {
6812 stop_sta_mode(dut);
6813 sleep(1);
6814 }
6815
6816 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
6817 snprintf(buf, sizeof(buf), "ifconfig %s down",
6818 dut->sniffer_ifname);
6819 if (system(buf) != 0) {
6820 sigma_dut_print(dut, DUT_MSG_INFO,
6821 "Failed to run '%s'", buf);
6822 }
6823 snprintf(buf, sizeof(buf), "iw dev %s set type station",
6824 dut->sniffer_ifname);
6825 if (system(buf) != 0) {
6826 sigma_dut_print(dut, DUT_MSG_INFO,
6827 "Failed to run '%s'", buf);
6828 }
6829 }
6830
6831 dut->mode = SIGMA_MODE_AP;
6832
6833 if (drv == DRIVER_ATHEROS)
6834 return cmd_ath_ap_config_commit(dut, conn, cmd);
6835 if (drv == DRIVER_WCN)
6836 return cmd_wcn_ap_config_commit(dut, conn, cmd);
6837 if (drv == DRIVER_OPENWRT)
6838 return cmd_owrt_ap_config_commit(dut, conn, cmd);
6839
6840 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
6841 if (f == NULL) {
6842 sigma_dut_print(dut, DUT_MSG_ERROR,
6843 "%s: Failed to open sigma_dut-ap.conf",
6844 __func__);
6845 return -2;
6846 }
6847 switch (dut->ap_mode) {
6848 case AP_11g:
6849 case AP_11b:
6850 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306851 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
6852 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
6853 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006854 ifname = sigma_main_ifname;
6855 fprintf(f, "hw_mode=g\n");
6856 break;
6857 case AP_11a:
6858 case AP_11na:
6859 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306860 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006861 if (sigma_main_ifname)
6862 ifname = sigma_main_ifname;
6863 else
6864 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05306865 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006866 if (if_nametoindex("wlan1") > 0)
6867 ifname = "wlan1";
6868 else
6869 ifname = "wlan0";
6870 } else {
6871 ifname = get_main_ifname();
6872 }
6873 fprintf(f, "hw_mode=a\n");
6874 break;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02006875 case AP_11ad:
6876 ifname = get_main_ifname();
6877 fprintf(f, "hw_mode=ad\n");
6878 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006879 default:
6880 fclose(f);
6881 return -1;
6882 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006883 if (dut->hostapd_ifname)
6884 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006885
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306886 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006887 fprintf(f, "driver=nl80211\n");
6888
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306889 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6890 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006891 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05306892 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
6893
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006894 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306895 if (dut->ap_mode == AP_11ng &&
6896 (dut->ap_chwidth == AP_40 ||
6897 (dut->ap_chwidth == AP_AUTO &&
6898 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006899 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306900 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006901 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306902 ht40minus = 1;
6903 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006904 }
6905
6906 /* configure ht_capab based on channel width */
6907 if (dut->ap_mode == AP_11na &&
6908 (dut->ap_chwidth == AP_40 ||
6909 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05306910 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006911 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306912 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006913 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05306914 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006915 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306916
6917 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05306918 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05306919
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306920 /* Overwrite the ht_capab with offset value if configured */
6921 if (dut->ap_chwidth == AP_40 &&
6922 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
6923 ht40plus = 1;
6924 ht40minus = 0;
6925 } else if (dut->ap_chwidth == AP_40 &&
6926 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
6927 ht40minus = 1;
6928 ht40plus = 0;
6929 }
6930
Tamizh chelvam431c6002017-03-07 17:07:16 +05306931 fprintf(f, "ht_capab=%s%s%s\n",
6932 ht40plus ? "[HT40+]" : "",
6933 ht40minus ? "[HT40-]" : "",
6934 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006935 }
6936
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306937 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6938 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006939 dut->ap_mode == AP_11ac) {
Hu Wang29392102019-07-03 15:41:12 +08006940 int ht40plus = 0, ht40minus = 0;
6941
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006942 fprintf(f, "ieee80211ac=1\n"
Hu Wang29392102019-07-03 15:41:12 +08006943 "ieee80211n=1\n");
6944
6945 /* configure ht_capab based on channel width */
6946 if (dut->ap_chwidth != AP_20) {
6947 if (is_ht40plus_chan(dut->ap_channel))
6948 ht40plus = 1;
6949 else if (is_ht40minus_chan(dut->ap_channel))
6950 ht40minus = 1;
6951
6952 fprintf(f, "ht_capab=%s%s\n",
6953 ht40plus ? "[HT40+]" : "",
6954 ht40minus ? "[HT40-]" : "");
6955 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006956 }
6957
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306958 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
6959 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006960 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
6961 if (dut->ap_countrycode[0]) {
6962 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
6963 fprintf(f, "ieee80211d=1\n");
6964 fprintf(f, "ieee80211h=1\n");
6965 }
6966 }
6967
6968 fprintf(f, "interface=%s\n", ifname);
6969 if (dut->bridge)
6970 fprintf(f, "bridge=%s\n", dut->bridge);
6971 fprintf(f, "channel=%d\n", dut->ap_channel);
6972
6973 if (sigma_hapd_ctrl)
6974 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
6975 else
6976 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
6977
6978 if (dut->ap_ssid[0])
6979 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6980 else
6981 fprintf(f, "ssid=QCA AP OOB\n");
6982 if (dut->ap_bcnint)
6983 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
6984
Jouni Malinenda5f35b2019-03-26 00:25:53 +02006985 if (dut->ap_akm_values) {
6986 struct {
6987 int akm;
6988 const char *str;
6989 } akms[] = {
6990 { AKM_WPA_EAP, "WPA-EAP" },
6991 { AKM_WPA_PSK, "WPA-PSK" },
6992 { AKM_FT_EAP, "FT-EAP" },
6993 { AKM_FT_PSK, "FT-PSK" },
6994 { AKM_EAP_SHA256, "WPA-EAP-SHA256" },
6995 { AKM_PSK_SHA256, "WPA-PSK-SHA256" },
6996 { AKM_SAE, "SAE" },
6997 { AKM_FT_SAE, "FT-SAE" },
6998 { AKM_SUITE_B, "WPA-EAP-SUITE-B-192" },
6999 { AKM_FT_SUITE_B, "FT-EAP-SHA384" },
7000 { AKM_FILS_SHA256, "FILS-SHA256" },
7001 { AKM_FILS_SHA384, "FILS-SHA384" },
7002 { AKM_FT_FILS_SHA256, "FT-FILS-SHA256" },
7003 { AKM_FT_FILS_SHA384, "FT-FILS-SHA384" },
7004 };
Jouni Malinen8400c082019-04-26 13:26:07 +03007005 int first = 1;
7006 unsigned int i;
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007007
7008 fprintf(f, "wpa_key_mgmt=");
7009 for (i = 0; i < ARRAY_SIZE(akms); i++) {
7010 if (dut->ap_akm_values & (1 << akms[i].akm)) {
7011 fprintf(f, "%s%s", first ? "" : " ",
7012 akms[i].str);
7013 first = 0;
7014 }
7015 }
7016 fprintf(f, "\n");
7017 /* TODO: mixed mode and WPAv1 only */
7018 fprintf(f, "wpa=2\n");
7019 fprintf(f, "wpa_pairwise=%s\n",
7020 hostapd_cipher_name(dut->ap_cipher));
7021 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7022 fprintf(f, "group_cipher=%s\n",
7023 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3e255412019-03-28 22:04:08 +02007024 if ((dut->ap_akm_values &
7025 ((1 << AKM_SAE) | (1 << AKM_FT_SAE))) &&
7026 !(dut->ap_akm_values &
7027 ((1 << AKM_WPA_PSK) | (1 << AKM_FT_PSK))) &&
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007028 dut->ap_passphrase[0])
7029 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
7030 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7031 fprintf(f, "wpa_psk=%s", dut->ap_psk);
7032 else if (dut->ap_passphrase[0])
7033 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007034 if (dut->ap_akm_values & ((1 << AKM_WPA_EAP) |
Jouni Malinene5393c32019-06-20 01:34:34 +03007035 (1 << AKM_FT_EAP) |
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007036 (1 << AKM_EAP_SHA256) |
7037 (1 << AKM_SUITE_B) |
7038 (1 << AKM_FT_SUITE_B) |
7039 (1 << AKM_FILS_SHA256) |
7040 (1 << AKM_FILS_SHA384) |
7041 (1 << AKM_FT_FILS_SHA256) |
7042 (1 << AKM_FT_FILS_SHA384))) {
7043 fprintf(f, "ieee8021x=1\n");
7044 fprintf(f, "auth_server_addr=%s\n",
7045 dut->ap_radius_ipaddr);
7046 if (dut->ap_radius_port)
7047 fprintf(f, "auth_server_port=%d\n",
7048 dut->ap_radius_port);
7049 fprintf(f, "auth_server_shared_secret=%s\n",
7050 dut->ap_radius_password);
7051 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007052 goto skip_key_mgmt;
7053 }
7054
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007055 switch (dut->ap_key_mgmt) {
7056 case AP_OPEN:
7057 if (dut->ap_cipher == AP_WEP)
7058 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
7059 break;
7060 case AP_WPA2_PSK:
7061 case AP_WPA2_PSK_MIXED:
7062 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007063 case AP_WPA2_SAE:
7064 case AP_WPA2_PSK_SAE:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007065 case AP_WPA2_PSK_SHA256:
7066 case AP_WPA2_FT_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03007067 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
7068 dut->ap_key_mgmt == AP_WPA2_SAE ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007069 dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7070 dut->ap_key_mgmt == AP_WPA2_PSK_SHA256 ||
7071 dut->ap_key_mgmt == AP_WPA2_FT_PSK)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072 fprintf(f, "wpa=2\n");
7073 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
7074 fprintf(f, "wpa=3\n");
7075 else
7076 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03007077 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7078 key_mgmt = "SAE";
7079 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7080 key_mgmt = "WPA-PSK SAE";
7081 else
7082 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007083 switch (dut->ap_pmf) {
7084 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007085 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007086 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7087 break;
7088 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03007089 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007090 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
7091 break;
7092 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03007093 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7094 key_mgmt = "SAE";
7095 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
7096 key_mgmt = "WPA-PSK-SHA256 SAE";
7097 else
7098 key_mgmt = "WPA-PSK-SHA256";
7099 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007100 break;
7101 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007102 if (dut->ap_key_mgmt == AP_WPA2_PSK_SHA256)
7103 fprintf(f, "wpa_key_mgmt=WPA-PSK-SHA256\n");
7104 else if (dut->ap_key_mgmt == AP_WPA2_FT_PSK)
7105 fprintf(f, "wpa_key_mgmt=FT-PSK\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007106 fprintf(f, "wpa_pairwise=%s\n",
7107 hostapd_cipher_name(dut->ap_cipher));
7108 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7109 fprintf(f, "group_cipher=%s\n",
7110 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03007111 if (dut->ap_key_mgmt == AP_WPA2_SAE)
7112 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02007113 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
7114 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03007115 else
7116 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007117 break;
7118 case AP_WPA2_EAP:
7119 case AP_WPA2_EAP_MIXED:
7120 case AP_WPA_EAP:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007121 case AP_WPA2_EAP_OSEN:
Jouni Malinen6be21c82018-08-01 18:47:24 +03007122 case AP_WPA2_EAP_SHA256:
7123 case AP_WPA2_FT_EAP:
7124 case AP_WPA2_ENT_FT_EAP:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007125 fprintf(f, "ieee8021x=1\n");
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007126 if (dut->ap_key_mgmt == AP_WPA2_EAP ||
Jouni Malinen6be21c82018-08-01 18:47:24 +03007127 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ||
7128 dut->ap_key_mgmt == AP_WPA2_EAP_SHA256 ||
7129 dut->ap_key_mgmt == AP_WPA2_FT_EAP ||
7130 dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007131 fprintf(f, "wpa=2\n");
7132 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
7133 fprintf(f, "wpa=3\n");
7134 else
7135 fprintf(f, "wpa=1\n");
7136 switch (dut->ap_pmf) {
7137 case AP_PMF_DISABLED:
7138 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
7139 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
7140 break;
7141 case AP_PMF_OPTIONAL:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007142 fprintf(f, "wpa_key_mgmt=WPA-EAP%s%s\n",
7143 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "",
7144 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7145 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007146 break;
7147 case AP_PMF_REQUIRED:
Jouni Malinen4cf699f2018-06-19 00:46:27 +03007148 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256%s\n",
7149 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN ? " OSEN" :
7150 "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151 break;
7152 }
Jouni Malinen6be21c82018-08-01 18:47:24 +03007153 if (dut->ap_key_mgmt == AP_WPA2_EAP_SHA256)
7154 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
7155 else if (dut->ap_key_mgmt == AP_WPA2_FT_EAP)
7156 fprintf(f, "wpa_key_mgmt=FT-EAP\n");
7157 else if (dut->ap_key_mgmt == AP_WPA2_ENT_FT_EAP)
7158 fprintf(f, "wpa_key_mgmt=FT-EAP WPA-EAP\n");
Jouni Malinen2ba24492017-11-17 12:43:59 +02007159 fprintf(f, "wpa_pairwise=%s\n",
7160 hostapd_cipher_name(dut->ap_cipher));
7161 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7162 fprintf(f, "group_cipher=%s\n",
7163 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007164 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7165 if (dut->ap_radius_port)
7166 fprintf(f, "auth_server_port=%d\n",
7167 dut->ap_radius_port);
7168 fprintf(f, "auth_server_shared_secret=%s\n",
7169 dut->ap_radius_password);
Jouni Malinen1a2bc992018-06-22 11:50:59 +03007170 if (dut->program == PROGRAM_HS2_R3) {
7171 fprintf(f, "radius_das_port=3799\n");
7172 fprintf(f, "radius_das_client=0.0.0.0 %s\n",
7173 dut->ap_radius_password);
7174 fprintf(f, "radius_das_require_event_timestamp=1\n");
7175 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007176 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03007177 case AP_SUITEB:
7178 fprintf(f, "ieee8021x=1\n");
7179 fprintf(f, "wpa=2\n");
7180 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03007181 fprintf(f, "wpa_pairwise=%s\n",
7182 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02007183 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7184 fprintf(f, "group_cipher=%s\n",
7185 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03007186 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7187 fprintf(f, "group_mgmt_cipher=%s\n",
7188 hostapd_group_mgmt_cipher_name(
7189 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03007190 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7191 if (dut->ap_radius_port)
7192 fprintf(f, "auth_server_port=%d\n",
7193 dut->ap_radius_port);
7194 fprintf(f, "auth_server_shared_secret=%s\n",
7195 dut->ap_radius_password);
7196 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03007197 case AP_WPA2_OWE:
7198 fprintf(f, "wpa=2\n");
7199 fprintf(f, "wpa_key_mgmt=OWE\n");
7200 fprintf(f, "rsn_pairwise=%s\n",
7201 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03007202 if (dut->ap_sae_groups)
7203 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03007204 break;
Jouni Malinenc2b91212018-09-12 02:26:39 +03007205 case AP_OSEN:
7206 fprintf(f, "osen=1\n");
7207 fprintf(f, "disable_dgaf=1\n");
7208 fprintf(f, "wpa_pairwise=%s\n",
7209 hostapd_cipher_name(dut->ap_cipher));
7210 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
7211 fprintf(f, "group_cipher=%s\n",
7212 hostapd_cipher_name(dut->ap_group_cipher));
7213 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
7214 if (dut->ap_radius_port)
7215 fprintf(f, "auth_server_port=%d\n",
7216 dut->ap_radius_port);
7217 fprintf(f, "auth_server_shared_secret=%s\n",
7218 dut->ap_radius_password);
7219 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007220 }
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007221skip_key_mgmt:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007222
Jouni Malinen09550de2019-03-26 00:24:11 +02007223 if (dut->ap_sae_passwords) {
7224 char *tmp, *pos, *end, *id;
7225
7226 tmp = strdup(dut->ap_sae_passwords);
7227 if (!tmp) {
7228 fclose(f);
7229 return ERROR_SEND_STATUS;
7230 }
7231
7232 pos = tmp;
7233 while (*pos) {
7234 end = strchr(pos, ';');
7235 if (end)
7236 *end = '\0';
7237 id = strchr(pos, ':');
7238 if (id)
7239 *id++ = '\0';
7240
7241 fprintf(f, "sae_password=%s%s%s\n",
7242 pos, id ? "|id=" : "", id ? id : "");
7243 if (!end)
7244 break;
7245 pos = end + 1;
7246 }
7247
7248 free(tmp);
7249 }
7250
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05307251 if (dut->ap_rsn_preauth)
7252 fprintf(f, "rsn_preauth=1\n");
7253
Jouni Malinenb75c5322019-06-14 01:47:43 +03007254 if (dut->ap_pmksa && dut->ap_pmksa_caching)
7255 fprintf(f, "disable_pmksa_caching=1\n");
7256
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007257 switch (dut->ap_pmf) {
7258 case AP_PMF_DISABLED:
7259 break;
7260 case AP_PMF_OPTIONAL:
7261 fprintf(f, "ieee80211w=1\n");
Jouni Malinenda5f35b2019-03-26 00:25:53 +02007262 if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE ||
7263 (dut->ap_akm_values & (AKM_SAE | AKM_WPA_PSK)) ==
7264 (AKM_SAE | AKM_WPA_PSK))
Jouni Malinen1287cd72018-01-04 17:08:01 +02007265 fprintf(f, "sae_require_mfp=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007266 break;
7267 case AP_PMF_REQUIRED:
7268 fprintf(f, "ieee80211w=2\n");
7269 break;
7270 }
7271
Jouni Malinen10ed9e72019-03-28 03:00:11 +02007272 if (dut->ap_pmf != AP_PMF_DISABLED &&
7273 dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
7274 fprintf(f, "group_mgmt_cipher=%s\n",
7275 hostapd_group_mgmt_cipher_name(
7276 dut->ap_group_mgmt_cipher));
7277
Jouni Malinen6be21c82018-08-01 18:47:24 +03007278 if (ap_ft_enabled(dut)) {
7279 unsigned char own_addr[ETH_ALEN];
7280
7281 fprintf(f, "mobility_domain=%s\n", dut->ap_mobility_domain);
Jouni Malinen9f943312019-08-19 23:49:16 +03007282 fprintf(f, "ft_over_ds=%d\n", dut->ap_ft_ds == VALUE_ENABLED);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007283 if (get_hwaddr(ifname, own_addr) < 0) {
7284 memset(own_addr, 0, ETH_ALEN);
7285 own_addr[0] = 0x02;
7286 }
Jouni Malinenc9674462019-03-26 02:40:19 +02007287 fprintf(f,
7288 "nas_identifier=%02x%02x%02x%02x%02x%02x.nas.example.com\n",
7289 own_addr[0], own_addr[1], own_addr[2],
7290 own_addr[3], own_addr[4], own_addr[5]);
Jouni Malinen6be21c82018-08-01 18:47:24 +03007291 fprintf(f, "r1_key_holder=%02x%02x%02x%02x%02x%02x\n",
7292 own_addr[0], own_addr[1], own_addr[2],
7293 own_addr[3], own_addr[4], own_addr[5]);
7294 fprintf(f, "ft_psk_generate_local=1\n");
7295 fprintf(f, "pmk_r1_push=0\n");
7296 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007297 "r0kh=ff:ff:ff:ff:ff:ff * 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007298 fprintf(f,
Jouni Malinen69222a62019-03-26 01:56:20 +02007299 "r1kh=00:00:00:00:00:00 00:00:00:00:00:00 00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff\n");
Jouni Malinen6be21c82018-08-01 18:47:24 +03007300 }
7301
Jouni Malinen3c367e82017-06-23 17:01:47 +03007302 if (dut->rsne_override)
7303 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
7304
Jouni Malinen68143132017-09-02 02:34:08 +03007305 if (dut->sae_commit_override)
7306 fprintf(f, "sae_commit_override=%s\n",
7307 dut->sae_commit_override);
7308
Jouni Malinened670f42017-08-31 01:39:28 +03007309 if (dut->ap_sae_groups)
7310 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03007311
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007312 if (dut->sae_anti_clogging_threshold >= 0)
7313 fprintf(f, "sae_anti_clogging_threshold=%d\n",
7314 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03007315 if (dut->sae_reflection)
7316 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03007317
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007318 if (dut->ap_p2p_mgmt)
7319 fprintf(f, "manage_p2p=1\n");
7320
7321 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
7322 fprintf(f, "tdls_prohibit=1\n");
7323 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
7324 fprintf(f, "tdls_prohibit_chan_switch=1\n");
7325 if (dut->ap_p2p_cross_connect >= 0) {
7326 fprintf(f, "manage_p2p=1\n"
7327 "allow_cross_connection=%d\n",
7328 dut->ap_p2p_cross_connect);
7329 }
7330
Jouni Malinen4d479c92018-11-06 00:43:36 +02007331 if (dut->ap_l2tif || dut->ap_proxy_arp ||
7332 dut->ap_key_mgmt == AP_WPA2_EAP_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007333 if (!dut->bridge) {
7334 sigma_dut_print(dut, DUT_MSG_ERROR,
7335 "Bridge must be configured. Run with -b <brname>.");
7336 fclose(f);
7337 return -2;
7338 }
7339 fprintf(f, "ap_isolate=1\n");
7340 }
7341
7342 if (dut->ap_proxy_arp)
7343 fprintf(f, "proxy_arp=1\n");
7344
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05307345 if (dut->ap_wme)
7346 fprintf(f, "wmm_enabled=1\n");
7347
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05307348 if (dut->ap_wmmps == AP_WMMPS_ON)
7349 fprintf(f, "uapsd_advertisement_enabled=1\n");
7350
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007351 if (dut->ap_hs2) {
7352 if (dut->ap_bss_load) {
7353 char *bss_load;
7354
7355 switch (dut->ap_bss_load) {
7356 case -1:
7357 bss_load = "bss_load_update_period=10";
7358 break;
7359 case 1:
7360 /* STA count: 1, CU: 50, AAC: 65535 */
7361 bss_load = "bss_load_test=1:50:65535";
7362 break;
7363 case 2:
7364 /* STA count: 1, CU: 200, AAC: 65535 */
7365 bss_load = "bss_load_test=1:200:65535";
7366 break;
7367 case 3:
7368 /* STA count: 1, CU: 75, AAC: 65535 */
7369 bss_load = "bss_load_test=1:75:65535";
7370 break;
7371 default:
7372 bss_load = NULL;
7373 break;
7374 }
7375
7376 if (!bss_load) {
7377 fclose(f);
7378 return -2;
7379 }
7380 fprintf(f, "%s\n", bss_load);
7381 }
7382
7383 if (append_hostapd_conf_hs2(dut, f)) {
7384 fclose(f);
7385 return -2;
7386 }
7387 }
7388
7389 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
7390 fclose(f);
7391 return -2;
7392 }
7393
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007394 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007395 unsigned char bssid[6];
7396 char ifname2[50];
7397
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307398 if (get_hwaddr(ifname, bssid)) {
7399 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007400 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307401 }
Jouni Malinenb37f0bc2018-05-03 18:29:55 +03007402 if (bssid[0] & 0x02)
7403 bssid[5] ^= 0x01;
7404 else
7405 bssid[0] |= 0x02;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007406
7407 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
Jouni Malinen10b47b22018-06-07 23:28:07 +03007408 fprintf(f, "bss=%s\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007409 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007410 if (dut->bridge)
7411 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007412
7413 if (drv == DRIVER_LINUX_WCN)
7414 fprintf(f, "use_driver_iface_addr=1\n");
7415 else
7416 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7417 bssid[0], bssid[1], bssid[2], bssid[3],
7418 bssid[4], bssid[5]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007419
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007420 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007421 fprintf(f, "osen=1\n");
Sriram R61f5d952018-06-07 17:47:07 +05307422 /* Disable DGAF for OSEN BSS */
7423 fprintf(f, "disable_dgaf=1\n");
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007424 fprintf(f, "ap_isolate=1\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007425 if (strlen(dut->ap2_radius_ipaddr))
7426 fprintf(f, "auth_server_addr=%s\n",
7427 dut->ap2_radius_ipaddr);
7428 if (dut->ap2_radius_port)
7429 fprintf(f, "auth_server_port=%d\n",
7430 dut->ap2_radius_port);
7431 if (strlen(dut->ap2_radius_password))
7432 fprintf(f, "auth_server_shared_secret=%s\n",
7433 dut->ap2_radius_password);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02007434
7435 set_ebtables_forward_drop(dut, ifname, ifname2);
7436 } else if (dut->ap2_osu) {
7437 fprintf(f, "ap_isolate=1\n");
7438 set_ebtables_forward_drop(dut, ifname, ifname2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 }
7440
7441 if (dut->ap2_proxy_arp) {
7442 if (!dut->bridge) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "Bridge must be configured. Run with -b <brname>.");
7445 fclose(f);
7446 return -2;
7447 }
7448 fprintf(f, "ap_isolate=1\n");
7449 fprintf(f, "proxy_arp=1\n");
7450
7451 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
7452 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
7453 fclose(f);
7454 return -2;
7455 }
7456
7457 }
7458 }
7459
7460 if (dut->program == PROGRAM_WPS) {
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007461 /* 60G WPS tests requires wps_state of 2 (configured) */
7462 int wps_state = is_60g_sigma_dut(dut) ? 2 : 1;
7463
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007464 fprintf(f, "eap_server=1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007465 "wps_state=%d\n"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007466 "device_name=QCA AP\n"
7467 "manufacturer=QCA\n"
7468 "device_type=6-0050F204-1\n"
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007469 "config_methods=label virtual_display %s"
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007470 "virtual_push_button keypad%s\n"
7471 "ap_pin=12345670\n"
7472 "friendly_name=QCA Access Point\n"
7473 "upnp_iface=%s\n",
Alexei Avshalom Lazard303e472018-12-23 16:49:49 +02007474 wps_state,
7475 is_60g_sigma_dut(dut) ? "physical_display " : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007476 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
7477 dut->bridge ? dut->bridge : ifname);
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007478 if (dut->wsc_fragment) {
7479 fprintf(f, "device_name=%s\n"
7480 "manufacturer=%s\n"
7481 "model_name=%s\n"
7482 "model_number=%s\n"
7483 "serial_number=%s\n",
7484 WPS_LONG_DEVICE_NAME,
7485 WPS_LONG_MANUFACTURER,
7486 WPS_LONG_MODEL_NAME,
7487 WPS_LONG_MODEL_NUMBER,
7488 WPS_LONG_SERIAL_NUMBER);
7489 } else {
7490 fprintf(f, "device_name=QCA AP\n"
7491 "manufacturer=QCA\n");
7492 }
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02007493 if (dut->eap_fragment)
7494 fprintf(f, "fragment_size=128\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007495 }
7496
7497 if (dut->program == PROGRAM_VHT) {
7498 int vht_oper_centr_freq_idx;
7499
7500 if (check_channel(dut->ap_channel) < 0) {
7501 send_resp(dut, conn, SIGMA_INVALID,
7502 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307503 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007504 return 0;
7505 }
7506
7507 switch (dut->ap_chwidth) {
7508 case AP_20:
7509 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7510 vht_oper_centr_freq_idx =
7511 get_oper_centr_freq_seq_idx(20,
7512 dut->ap_channel);
7513 break;
7514 case AP_40:
7515 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
7516 vht_oper_centr_freq_idx =
7517 get_oper_centr_freq_seq_idx(40,
7518 dut->ap_channel);
7519 break;
7520 case AP_80:
7521 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
7522 vht_oper_centr_freq_idx =
7523 get_oper_centr_freq_seq_idx(80,
7524 dut->ap_channel);
7525 break;
7526 case AP_160:
7527 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
7528 vht_oper_centr_freq_idx =
7529 get_oper_centr_freq_seq_idx(160,
7530 dut->ap_channel);
7531 break;
7532 default:
7533 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
7534 vht_oper_centr_freq_idx =
7535 get_oper_centr_freq_seq_idx(80,
7536 dut->ap_channel);
7537 break;
7538 }
7539 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
7540 vht_oper_centr_freq_idx);
7541 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
7542
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007543 if (dut->ap_sgi80 || dut->ap_txBF ||
7544 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307545 dut->ap_tx_stbc || dut->ap_mu_txBF) {
7546 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007547 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05307548 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05307549 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02007550 (dut->ap_ldpc == VALUE_ENABLED) ?
7551 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05307552 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
7553 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007554 }
7555 }
7556
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007557 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
7558 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
7559 /* OWE transition mode */
7560 unsigned char bssid[6];
7561 char ifname2[50];
7562 unsigned long val;
7563 FILE *f2;
7564
7565 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7566
7567 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7568 val = 0x12345678; /* default to something */
7569 f2 = fopen("/dev/urandom", "r");
7570 if (f2) {
7571 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7572 sigma_dut_print(dut, DUT_MSG_ERROR,
7573 "Could not read /dev/urandom");
7574 }
7575 fclose(f2);
7576 }
7577 fprintf(f, "ssid=owe-%lx\n", val);
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007578 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007579
7580 if (get_hwaddr(ifname, bssid)) {
7581 fclose(f);
7582 return -2;
7583 }
7584 if (bssid[0] & 0x02)
7585 bssid[5] ^= 0x01;
7586 else
7587 bssid[0] |= 0x02;
7588
7589 fprintf(f, "bss=%s\n", ifname2);
7590 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7591 if (dut->bridge)
7592 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007593 if (drv == DRIVER_LINUX_WCN)
7594 fprintf(f, "use_driver_iface_addr=1\n");
7595 else
7596 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7597 bssid[0], bssid[1], bssid[2], bssid[3],
7598 bssid[4], bssid[5]);
Jouni Malinen6d1d7392017-10-10 20:35:29 +03007599 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7600 }
7601
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007602 if (dut->ap_key_mgmt == AP_OPEN &&
7603 dut->ap_tag_key_mgmt[0] == AP2_WPA2_OWE) {
7604 /* OWE transition mode */
7605 unsigned char bssid[6];
7606 char ifname2[50];
7607 unsigned long val;
7608 FILE *f2;
7609
7610 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
7611
7612 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
7613 fprintf(f, "ssid=%s\n", dut->ap_ssid);
7614
7615 if (get_hwaddr(ifname, bssid)) {
7616 fclose(f);
7617 return -2;
7618 }
7619 if (bssid[0] & 0x02)
7620 bssid[5] ^= 0x01;
7621 else
7622 bssid[0] |= 0x02;
7623
7624 fprintf(f, "bss=%s\n", ifname2);
7625 val = 0x12345678; /* default to something */
7626 f2 = fopen("/dev/urandom", "r");
7627 if (f2) {
7628 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "Could not read /dev/urandom");
7631 }
7632 fclose(f2);
7633 }
7634 fprintf(f, "ssid=owe-%lx\n", val);
7635 if (dut->bridge)
7636 fprintf(f, "bridge=%s\n", dut->bridge);
Liangwei Dong911cb142019-01-10 14:35:55 +08007637 if (drv == DRIVER_LINUX_WCN)
7638 fprintf(f, "use_driver_iface_addr=1\n");
7639 else
7640 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
7641 bssid[0], bssid[1], bssid[2], bssid[3],
7642 bssid[4], bssid[5]);
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007643 fprintf(f, "owe_transition_ifname=%s\n", ifname);
7644 fprintf(f, "wpa=2\n");
7645 fprintf(f, "wpa_key_mgmt=OWE\n");
7646 fprintf(f, "rsn_pairwise=CCMP\n");
7647 fprintf(f, "ieee80211w=2\n");
Liangwei Dongd3b87da2019-01-09 20:10:20 +08007648 fprintf(f, "ignore_broadcast_ssid=1\n");
Jouni Malinen353ba8b2018-01-10 17:04:12 +02007649 if (dut->ap_sae_groups)
7650 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
7651 }
7652
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307653 if (dut->program == PROGRAM_OCE) {
7654 fprintf(f, "oce=%d\n",
7655 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
7656 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007657 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007658 if (dut->use_hostapd_pid_file)
7659 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007660#ifdef __QNXNTO__
7661 if (system("slay hostapd") == 0)
7662#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007663 if (!dut->use_hostapd_pid_file &&
7664 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
7665 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007666#endif /* __QNXNTO__ */
7667 {
7668 int i;
7669 /* Wait some time to allow hostapd to complete cleanup before
7670 * starting a new process */
7671 for (i = 0; i < 10; i++) {
7672 usleep(500000);
7673#ifdef __QNXNTO__
7674 if (system("pidin | grep hostapd") != 0)
7675 break;
7676#else /* __QNXNTO__ */
7677 if (system("pidof hostapd") != 0)
7678 break;
7679#endif /* __QNXNTO__ */
7680 }
7681 }
Jouni Malinend86e5822017-08-29 03:55:32 +03007682 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007683
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307684#ifdef ANDROID
7685 /* Set proper conf file permissions so that hostapd process
7686 * can access it.
7687 */
7688 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
7689 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
7690 sigma_dut_print(dut, DUT_MSG_ERROR,
7691 "Error changing permissions");
7692
Srinivas Dasaria1deeaa2018-06-18 22:54:04 +05307693 gr = getgrnam("wifi");
7694 if (!gr ||
7695 chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, gr->gr_gid) < 0)
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05307696 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
7697#endif /* ANDROID */
7698
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007699 if (drv == DRIVER_QNXNTO) {
7700 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05307701 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007702 "/sigma_dut-ap.conf",
7703 dut->hostapd_debug_log ? "-ddKt -f " : "",
7704 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007705 dut->hostapd_entropy_log ? " -e" : "",
7706 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
7707 "");
7708 } else {
7709 /*
7710 * It looks like a monitor interface can cause some issues for
7711 * beaconing, so remove it (if injection was used) before
7712 * starting hostapd.
7713 */
7714 if (if_nametoindex("sigmadut") > 0 &&
7715 system("iw dev sigmadut del") != 0)
7716 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
7717 "monitor interface");
7718
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007719 snprintf(path, sizeof(path), "%shostapd",
7720 file_exists("hostapd") ? "./" : "");
7721 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007722 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007723 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007724 dut->hostapd_debug_log ? " -ddKt -f" : "",
7725 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
7726 dut->hostapd_entropy_log ? " -e" : "",
7727 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007728 "",
7729 dut->use_hostapd_pid_file ?
7730 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731 }
7732
Jouni Malinend6bf1b42017-06-23 17:51:01 +03007733 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007734 if (system(buf) != 0) {
7735 send_resp(dut, conn, SIGMA_ERROR,
7736 "errorCode,Failed to start hostapd");
7737 return 0;
7738 }
7739
7740 /* allow some time for hostapd to start before returning success */
7741 usleep(500000);
7742 if (run_hostapd_cli(dut, "ping") != 0) {
7743 send_resp(dut, conn, SIGMA_ERROR,
7744 "errorCode,Failed to talk to hostapd");
7745 return 0;
7746 }
7747
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05307748 if (drv == DRIVER_LINUX_WCN) {
7749 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
7750 ap_inet_addr, ap_inet_mask);
7751 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
7752 ifname, ap_inet_addr, ap_inet_mask);
7753 if (system(buf) != 0) {
7754 sigma_dut_print(dut, DUT_MSG_ERROR,
7755 "Failed to initialize the interface");
7756 return -1;
7757 }
7758 }
7759
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760 if (dut->ap_l2tif) {
7761 snprintf(path, sizeof(path),
7762 "/sys/class/net/%s/brport/hairpin_mode",
7763 ifname);
7764 if (!file_exists(path)) {
7765 sigma_dut_print(dut, DUT_MSG_ERROR,
7766 "%s must be binded to the bridge for L2TIF",
7767 ifname);
7768 return -2;
7769 }
7770
7771 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
7772 if (system(buf) != 0) {
7773 sigma_dut_print(dut, DUT_MSG_ERROR,
7774 "Failed to enable hairpin_mode for L2TIF");
7775 return -2;
7776 }
7777
7778 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
7779 if (system(buf) != 0) {
7780 sigma_dut_print(dut, DUT_MSG_ERROR,
7781 "Failed to set ebtables rules, RULE-9");
7782 return -2;
7783 }
7784
7785 snprintf(buf, sizeof(buf),
7786 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
7787 ifname);
7788 if (system(buf) != 0) {
7789 sigma_dut_print(dut, DUT_MSG_ERROR,
7790 "Failed to set ebtables rules, RULE-11");
7791 return -2;
7792 }
7793 }
7794
7795 if (dut->ap_proxy_arp) {
7796 if (dut->ap_dgaf_disable) {
7797 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
7798 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
7799 return -2;
7800 } else {
7801 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
7802 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
7803 return -2;
7804 }
7805
7806 /* For 4.5-(c) */
7807 snprintf(buf, sizeof(buf),
7808 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
7809 ifname);
7810 if (system(buf) != 0) {
7811 sigma_dut_print(dut, DUT_MSG_ERROR,
7812 "Failed to set ebtables rules, RULE-10");
7813 return -2;
7814 }
7815 }
7816
7817 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
7818 /* Drop TDLS frames */
7819 snprintf(buf, sizeof(buf),
7820 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
7821 if (system(buf) != 0) {
7822 sigma_dut_print(dut, DUT_MSG_ERROR,
7823 "Failed to set ebtables rules, RULE-13");
7824 return -2;
7825 }
7826 }
7827
7828 if (dut->ap_fake_pkhash &&
7829 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
7830 send_resp(dut, conn, SIGMA_ERROR,
7831 "errorCode,Could not enable FakePubKey");
7832 return 0;
7833 }
7834
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007835 if (dut->program == PROGRAM_60GHZ && dut->ap_num_ese_allocs > 0) {
7836 /* wait extra time for AP to start */
7837 sleep(2);
7838 if (ap_set_60g_ese(dut, dut->ap_num_ese_allocs,
7839 dut->ap_ese_allocs)) {
7840 send_resp(dut, conn, SIGMA_ERROR,
7841 "errorCode,Could not set ExtSch");
7842 return 0;
7843 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007844 if (dut->ap_fixed_rate) {
7845 sigma_dut_print(dut, DUT_MSG_DEBUG,
7846 "forcing TX MCS index %d",
7847 dut->ap_mcs);
7848 if (ap_set_force_mcs(dut, 1, dut->ap_mcs)) {
7849 send_resp(dut, conn, SIGMA_ERROR,
7850 "errorCode,Could not force MCS");
7851 return -2;
7852 }
7853 }
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02007854 }
7855
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007856 if (dut->wps_forced_version) {
7857 snprintf(buf, sizeof(buf), "SET wps_version_number %d",
7858 dut->wps_forced_version);
7859 if (hapd_command(ifname, buf) < 0) {
7860 send_resp(dut, conn, SIGMA_ERROR,
7861 "errorCode,Fail to set wps_version_number");
7862 return STATUS_SENT;
7863 }
7864 }
7865
Jouni Malinend86e5822017-08-29 03:55:32 +03007866 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867 return 1;
7868}
7869
7870
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307871static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
7872 struct qos_params *qos, const char *cwmin,
7873 const char *cwmax, const char *aifs,
7874 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007875{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307876 int val;
7877
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007878 if (cwmin) {
7879 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307880 val = atoi(cwmin);
7881 if (val < 0 || val > 15) {
7882 send_resp(dut, conn, SIGMA_INVALID,
7883 "errorCode,Invalid cwMin");
7884 return 0;
7885 }
7886 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007887 }
7888
7889 if (cwmax) {
7890 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307891 val = atoi(cwmax);
7892 if (val < 0 || val > 15) {
7893 send_resp(dut, conn, SIGMA_INVALID,
7894 "errorCode,Invalid cwMax");
7895 return 0;
7896 }
7897 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007898 }
7899
7900 if (aifs) {
7901 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307902 val = atoi(aifs);
7903 if (val < 1 || val > 255) {
7904 send_resp(dut, conn, SIGMA_INVALID,
7905 "errorCode,Invalid AIFS");
7906 return 0;
7907 }
7908 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007909 }
7910
7911 if (txop) {
7912 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307913 val = atoi(txop);
7914 if (val < 0 || val > 0xffff) {
7915 send_resp(dut, conn, SIGMA_INVALID,
7916 "errorCode,Invalid txop");
7917 return 0;
7918 }
7919 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007920 }
7921
7922 if (acm) {
7923 qos->ac = 1;
7924 qos->acm = strcasecmp(acm, "on") == 0;
7925 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307926
7927 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007928}
7929
7930
Jouni Malinenf7222712019-06-13 01:50:21 +03007931static enum sigma_cmd_result cmd_ap_set_apqos(struct sigma_dut *dut,
7932 struct sigma_conn *conn,
7933 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007934{
7935 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307936 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
7937 get_param(cmd, "cwmin_VO"),
7938 get_param(cmd, "cwmax_VO"),
7939 get_param(cmd, "AIFS_VO"),
7940 get_param(cmd, "TXOP_VO"),
7941 get_param(cmd, "ACM_VO")) ||
7942 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
7943 get_param(cmd, "cwmin_VI"),
7944 get_param(cmd, "cwmax_VI"),
7945 get_param(cmd, "AIFS_VI"),
7946 get_param(cmd, "TXOP_VI"),
7947 get_param(cmd, "ACM_VI")) ||
7948 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
7949 get_param(cmd, "cwmin_BE"),
7950 get_param(cmd, "cwmax_BE"),
7951 get_param(cmd, "AIFS_BE"),
7952 get_param(cmd, "TXOP_BE"),
7953 get_param(cmd, "ACM_BE")) ||
7954 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
7955 get_param(cmd, "cwmin_BK"),
7956 get_param(cmd, "cwmax_BK"),
7957 get_param(cmd, "AIFS_BK"),
7958 get_param(cmd, "TXOP_BK"),
7959 get_param(cmd, "ACM_BK")))
7960 return 0;
7961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007962 return 1;
7963}
7964
7965
Jouni Malinenf7222712019-06-13 01:50:21 +03007966static enum sigma_cmd_result cmd_ap_set_staqos(struct sigma_dut *dut,
7967 struct sigma_conn *conn,
7968 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007969{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05307970 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
7971 get_param(cmd, "cwmin_VO"),
7972 get_param(cmd, "cwmax_VO"),
7973 get_param(cmd, "AIFS_VO"),
7974 get_param(cmd, "TXOP_VO"),
7975 get_param(cmd, "ACM_VO")) ||
7976 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
7977 get_param(cmd, "cwmin_VI"),
7978 get_param(cmd, "cwmax_VI"),
7979 get_param(cmd, "AIFS_VI"),
7980 get_param(cmd, "TXOP_VI"),
7981 get_param(cmd, "ACM_VI")) ||
7982 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
7983 get_param(cmd, "cwmin_BE"),
7984 get_param(cmd, "cwmax_BE"),
7985 get_param(cmd, "AIFS_BE"),
7986 get_param(cmd, "TXOP_BE"),
7987 get_param(cmd, "ACM_BE")) ||
7988 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
7989 get_param(cmd, "cwmin_BK"),
7990 get_param(cmd, "cwmax_BK"),
7991 get_param(cmd, "AIFS_BK"),
7992 get_param(cmd, "TXOP_BK"),
7993 get_param(cmd, "ACM_BK")))
7994 return 0;
7995
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007996 return 1;
7997}
7998
7999
8000static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
8001{
8002 unsigned char bssid[6];
8003 char buf[100];
8004 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
8005 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
8006 run_system(dut, "cfg -a AP_SECMODE=WPA");
8007 run_system(dut, "cfg -a AP_SECFILE=EAP");
8008 run_system(dut, "cfg -a AP_WPA=2");
8009 run_system(dut, "cfg -a AP_CYPHER=CCMP");
8010 run_system(dut, "cfg -a AP_HOTSPOT=1");
8011 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
8012 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
8013 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
8014 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
8015 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
8016 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
8017 if (!get_hwaddr("ath0", bssid)) {
8018 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8019 "%02x:%02x:%02x:%02x:%02x:%02x",
8020 bssid[0], bssid[1], bssid[2], bssid[3],
8021 bssid[4], bssid[5]);
8022 run_system(dut, buf);
8023 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8024 "%02x:%02x:%02x:%02x:%02x:%02x",
8025 bssid[0], bssid[1], bssid[2], bssid[3],
8026 bssid[4], bssid[5]);
8027 } else {
8028 if (!get_hwaddr("wifi0", bssid)) {
8029 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
8030 "%02x:%02x:%02x:%02x:%02x:%02x",
8031 bssid[0], bssid[1], bssid[2], bssid[3],
8032 bssid[4], bssid[5]);
8033 run_system(dut, buf);
8034 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
8035 "%02x:%02x:%02x:%02x:%02x:%02x",
8036 bssid[0], bssid[1], bssid[2], bssid[3],
8037 bssid[4], bssid[5]);
8038 } else {
8039 /* load the driver and try again */
8040 run_system(dut, "/etc/rc.d/rc.wlan up");
8041
8042 if (!get_hwaddr("wifi0", bssid)) {
8043 snprintf(buf, sizeof(buf),
8044 "cfg -a AP_HOTSPOT_HESSID="
8045 "%02x:%02x:%02x:%02x:%02x:%02x",
8046 bssid[0], bssid[1], bssid[2],
8047 bssid[3], bssid[4], bssid[5]);
8048 run_system(dut, buf);
8049 snprintf(dut->ap_hessid,
8050 sizeof(dut->ap_hessid),
8051 "%02x:%02x:%02x:%02x:%02x:%02x",
8052 bssid[0], bssid[1], bssid[2],
8053 bssid[3], bssid[4], bssid[5]);
8054 }
8055 }
8056 }
8057
8058 run_system(dut, "cfg -r AP_SSID_2");
8059 run_system(dut, "cfg -c");
8060 /* run_system(dut, "cfg -s"); */
8061}
8062
8063
8064static void ath_reset_vht_defaults(struct sigma_dut *dut)
8065{
8066 run_system(dut, "cfg -x");
8067 run_system(dut, "cfg -a AP_RADIO_ID=1");
8068 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
8069 run_system(dut, "cfg -a AP_STARTMODE=standard");
8070 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
8071 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
8072 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
8073 run_system(dut, "cfg -a ATH_countrycode=0x348");
8074 /* NOTE: For Beeliner we have to turn off MU-MIMO */
8075 if (system("rm /tmp/secath*") != 0) {
8076 sigma_dut_print(dut, DUT_MSG_ERROR,
8077 "Failed to remove secath file");
8078 }
8079}
8080
8081
Jouni Malinenf7222712019-06-13 01:50:21 +03008082static enum sigma_cmd_result cmd_ap_reset_default(struct sigma_dut *dut,
8083 struct sigma_conn *conn,
8084 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008085{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308086 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308087 enum driver_type drv;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008088 char buf[128];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008089 int i;
8090
8091 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
8092 /*
8093 * Reset all tagged SSIDs to NULL-string and all key management
8094 * to open.
8095 */
8096 dut->ap_tag_ssid[i][0] = '\0';
8097 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
8098 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008099
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308100 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308101
8102 program = get_param(cmd, "program");
8103 if (!program)
8104 program = get_param(cmd, "prog");
8105 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008106 dut->device_type = AP_unknown;
8107 type = get_param(cmd, "type");
8108 if (type && strcasecmp(type, "Testbed") == 0)
8109 dut->device_type = AP_testbed;
8110 if (type && strcasecmp(type, "DUT") == 0)
8111 dut->device_type = AP_dut;
8112
8113 dut->ap_rts = 0;
8114 dut->ap_frgmnt = 0;
8115 dut->ap_bcnint = 0;
8116 dut->ap_key_mgmt = AP_OPEN;
8117 dut->ap_ssid[0] = '\0';
8118 dut->ap_fake_pkhash = 0;
8119 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
8120 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008121 dut->ap_addba_reject = VALUE_NOT_SET;
8122 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008123 dut->ap_is_dual = 0;
8124 dut->ap_mode = AP_inval;
8125 dut->ap_mode_1 = AP_inval;
8126
8127 dut->ap_allow_vht_wep = 0;
8128 dut->ap_allow_vht_tkip = 0;
8129 dut->ap_disable_protection = 0;
8130 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008131 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
8132 dut->ap_ldpc = VALUE_NOT_SET;
8133 dut->ap_sig_rts = VALUE_NOT_SET;
8134 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008135 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05308136 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008137 dut->ap_chwidth = AP_AUTO;
8138
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05308139 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008140 dut->ap_wpsnfc = 0;
8141 dut->ap_bss_load = -1;
8142 dut->ap_p2p_cross_connect = -1;
8143
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308144 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
8145 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05308146 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308147
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008148 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008149 dut->ft_bss_mac_cnt = 0;
priyadharshini gowthaman09d613e2017-12-20 11:43:44 -08008150 dut->ap_interface_5g = 0;
8151 dut->ap_interface_2g = 0;
priyadharshini gowthamana3fe8c62018-01-26 15:19:41 -08008152 dut->ap_pmf = AP_PMF_DISABLED;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008153
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008154 dut->wsc_fragment = 0;
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02008155 dut->eap_fragment = 0;
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02008156 dut->wps_forced_version = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02008157
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308158 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308159 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308160 dut->ap_wmmps = AP_WMMPS_ON;
8161 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308162 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05308163 dut->ap_wmmps = AP_WMMPS_OFF;
8164 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05308165
Jouni Malinen54a89b02018-05-01 00:16:26 +03008166 dut->ap_venue_url = 0;
Jouni Malinenf7ff42b2018-05-01 00:21:56 +03008167 dut->ap_advice_of_charge = 0;
Jouni Malinenac104532018-05-01 00:27:37 +03008168 dut->ap_oper_icon_metadata = 0;
Jouni Malinenac367142018-05-01 00:32:24 +03008169 dut->ap_tnc_file_name = 0;
8170 dut->ap_tnc_time_stamp = 0;
Jouni Malinen54a89b02018-05-01 00:16:26 +03008171
Jouni Malinenda5f35b2019-03-26 00:25:53 +02008172 dut->ap_akm_values = 0;
Jouni Malinen09550de2019-03-26 00:24:11 +02008173 free(dut->ap_sae_passwords);
8174 dut->ap_sae_passwords = NULL;
8175
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008176 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03008177 dut->program == PROGRAM_HS2_R3 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008178 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008179 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008180
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008181 if (drv == DRIVER_ATHEROS)
8182 cmd_ath_ap_hs2_reset(dut);
8183 else if (drv == DRIVER_OPENWRT)
8184 cmd_owrt_ap_hs2_reset(dut);
8185
8186 dut->ap_interworking = 1;
8187 dut->ap_access_net_type = 2;
8188 dut->ap_internet = 0;
8189 dut->ap_venue_group = 2;
8190 dut->ap_venue_type = 8;
8191 dut->ap_domain_name_list[0] = '\0';
8192 dut->ap_hs2 = 1;
8193 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
8194 "506f9a;001bc504bd");
8195 dut->ap_l2tif = 0;
8196 dut->ap_proxy_arp = 0;
8197 if (dut->bridge) {
8198 char buf[50];
8199
8200 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
8201 dut->bridge);
8202 if (system(buf) != 0) {
8203 sigma_dut_print(dut, DUT_MSG_DEBUG,
8204 "%s ip neigh table flushing failed",
8205 dut->bridge);
8206 }
8207
8208 snprintf(buf, sizeof(buf), "ebtables -F");
8209 if (system(buf) != 0) {
8210 sigma_dut_print(dut, DUT_MSG_DEBUG,
8211 "%s ebtables flushing failed",
8212 dut->bridge);
8213 }
8214 }
8215 dut->ap_dgaf_disable = 0;
8216 dut->ap_p2p_cross_connect = 0;
8217 dut->ap_gas_cb_delay = 0;
8218 dut->ap_nai_realm_list = 0;
8219 dut->ap_oper_name = 0;
8220 dut->ap_venue_name = 0;
8221 for (i = 0; i < 10; i++) {
8222 dut->ap_plmn_mcc[i][0] = '\0';
8223 dut->ap_plmn_mnc[i][0] = '\0';
8224 }
8225 dut->ap_wan_metrics = 0;
8226 dut->ap_conn_capab = 0;
8227 dut->ap_ip_addr_type_avail = 0;
8228 dut->ap_net_auth_type = 0;
8229 dut->ap_oper_class = 0;
8230 dut->ap_pmf = 0;
8231 dut->ap_add_sha256 = 0;
8232 }
8233
Jouni Malinenba630452018-06-22 11:49:59 +03008234 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3 ||
8235 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008236 int i;
8237 const char hessid[] = "50:6f:9a:00:11:22";
8238
8239 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
8240 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008241 dut->ap_pmf = 1;
8242 dut->ap_osu_provider_list = 0;
Jouni Malinen93a837f2018-11-01 17:09:22 +02008243 dut->ap_osu_provider_nai_list = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008244 for (i = 0; i < 10; i++) {
8245 dut->ap_osu_server_uri[i][0] = '\0';
8246 dut->ap_osu_method[i] = 0xFF;
8247 }
8248 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07008249 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008250 dut->ap2_proxy_arp = 0;
Jouni Malinendbbc2c42018-11-14 23:55:41 +02008251 dut->ap2_osu = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008252 dut->ap_osu_icon_tag = 0;
8253 }
8254
8255 if (dut->program == PROGRAM_VHT) {
8256 /* Set up the defaults */
8257 dut->ap_mode = AP_11ac;
8258 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008259 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08008260 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008261 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008262 dut->ap_amsdu = VALUE_DISABLED;
8263 dut->ap_ldpc = VALUE_DISABLED;
8264 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008265 dut->ap_sgi80 = 0;
8266 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008267 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05308268 /*
8269 * As LDPC is optional, don't enable this by default
8270 * for LINUX-WCN driver. The ap_set_wireless command
8271 * can be used to enable LDPC, when needed.
8272 */
8273 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008274 dut->ap_ldpc = VALUE_ENABLED;
8275 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008276 dut->ap_sgi80 = 1;
8277 }
8278 dut->ap_fixed_rate = 0;
8279 dut->ap_rx_streams = 3;
8280 dut->ap_tx_streams = 3;
8281 dut->ap_vhtmcs_map = 0;
8282 dut->ap_chwidth = AP_80;
8283 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02008284 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05308285 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8286 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008287 if (get_driver_type() == DRIVER_ATHEROS)
8288 ath_reset_vht_defaults(dut);
8289 }
8290
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07008291 if (dut->program == PROGRAM_IOTLP) {
8292 dut->wnm_bss_max_feature = VALUE_DISABLED;
8293 dut->wnm_bss_max_idle_time = 0;
8294 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8295 dut->ap_proxy_arp = 1;
8296 } else {
8297 /*
8298 * Do not touch the BSS-MAX Idle time feature
8299 * if the program is not IOTLP.
8300 */
8301 dut->wnm_bss_max_feature = VALUE_NOT_SET;
8302 dut->wnm_bss_max_idle_time = 0;
8303 dut->wnm_bss_max_protection = VALUE_NOT_SET;
8304 }
8305
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008306 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008307 dut->ap_rrm = 1;
8308 dut->ap_rtt = 1;
8309 dut->ap_lci = 0;
8310 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008311 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07008312 dut->ap_lcr = 0;
8313 dut->ap_val_lcr[0] = '\0';
8314 dut->ap_neighap = 0;
8315 dut->ap_opchannel = 0;
8316 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07008317 dut->ap_fqdn_held = 0;
8318 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07008319 dut->ap_interworking = 0;
8320 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008321 dut->ap_msnt_type = 0;
8322 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07008323 dut->ap_ft_oa = 0;
Jouni Malinen9f943312019-08-19 23:49:16 +03008324 dut->ap_ft_ds = VALUE_NOT_SET;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07008325 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07008326 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008327
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008328 if (dut->program == PROGRAM_MBO) {
8329 dut->ap_mbo = 1;
8330 dut->ap_interworking = 1;
8331 dut->ap_ne_class = 0;
8332 dut->ap_ne_op_ch = 0;
8333 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008334 dut->ap_btmreq_disassoc_imnt = 0;
8335 dut->ap_btmreq_term_bit = 0;
8336 dut->ap_disassoc_timer = 0;
8337 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07008338 dut->ap_channel = 36;
8339 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07008340 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07008341 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008342 dut->mbo_self_ap_tuple.ap_ne_class = -1;
8343 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
8344 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08008345 dut->ap_btmreq_bss_term_tsf = 0;
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08008346 dut->ap_assoc_delay = 0;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008347 }
8348
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008349 if (dut->program == PROGRAM_OCE) {
8350 if (dut->ap_dhcp_stop)
8351 run_system(dut, "/etc/init.d/dnsmasq start");
8352
8353 dut->ap_dhcp_stop = 0;
8354 dut->ap_oce = VALUE_ENABLED;
8355 dut->ap_broadcast_ssid = VALUE_ENABLED;
8356 dut->ap_fils_dscv_int = 20;
8357 dut->ap_filsdscv = VALUE_ENABLED;
8358 dut->ap_filshlp = VALUE_DISABLED;
8359 dut->ap_rnr = VALUE_DISABLED;
8360 dut->ap_nairealm[0] = '\0';
8361 dut->ap_nairealm_int = 0;
8362 dut->ap_blechanutil = 0;
8363 dut->ap_ble_admit_cap = 0;
8364 dut->ap_esp = VALUE_ENABLED;
8365 dut->ap_datappdudura = 0;
8366 dut->ap_airtimefract = 0;
8367 dut->ap_blestacnt = 0;
priyadharshini gowthamancb22e432017-12-28 15:23:31 -08008368 dut->ap_ul_availcap = 0;
8369 dut->ap_dl_availcap = 0;
priyadharshini gowthamande81f392017-12-28 15:28:49 -08008370 dut->ap_akm = 0;
8371 dut->ap_add_sha256 = 0;
8372 dut->ap_add_sha384 = 0;
priyadharshini gowthaman63ab8482017-12-28 15:32:55 -08008373 dut->ap_80plus80 = 0;
priyadharshini gowthaman00798a22017-12-28 15:15:00 -08008374 }
8375
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008376 dut->ap_he_ppdu = PPDU_NOT_SET;
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008377 dut->ap_he_ulofdma = VALUE_NOT_SET;
Priyadharshini Gowthamanbc948892019-09-10 14:22:49 -07008378 dut->ap_numsounddim = 0;
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008379 dut->ap_bcc = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008380 if (dut->device_type == AP_testbed) {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008381 dut->ap_he_dlofdma = VALUE_DISABLED;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008382 dut->ap_he_frag = VALUE_DISABLED;
8383 } else {
Priyadharshini Gowthamanfe60c502019-08-14 13:00:34 -07008384 dut->ap_he_dlofdma = VALUE_NOT_SET;
Priyadharshini Gowthaman6bc4c1e2019-09-10 16:24:51 -07008385 dut->ap_he_frag = VALUE_NOT_SET;
8386 }
priyadharshini gowthaman350f1912018-06-04 13:09:12 -07008387
Priyadharshini Gowthaman670b3232019-09-10 16:09:19 -07008388 if (dut->program == PROGRAM_HE) {
8389 if (dut->device_type == AP_testbed)
8390 dut->ap_ldpc = VALUE_DISABLED;
8391 }
8392
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -08008393 dut->ap_oper_chn = 0;
8394
Jouni Malinenb75c5322019-06-14 01:47:43 +03008395 dut->ap_pmksa = 0;
8396 dut->ap_pmksa_caching = 0;
8397
Jouni Malinen3c367e82017-06-23 17:01:47 +03008398 free(dut->rsne_override);
8399 dut->rsne_override = NULL;
8400
Jouni Malinen68143132017-09-02 02:34:08 +03008401 free(dut->sae_commit_override);
8402 dut->sae_commit_override = NULL;
8403
Jouni Malinened670f42017-08-31 01:39:28 +03008404 free(dut->ap_sae_groups);
8405 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03008406
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008407 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03008408 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03008409
Jouni Malinen3d633da2017-09-14 22:19:21 +03008410 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02008411 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03008412 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02008413 dut->ap_passphrase[0] = '\0';
8414 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03008415
Jouni Malinend86e5822017-08-29 03:55:32 +03008416 dut->dpp_conf_id = -1;
8417
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008418 if (is_60g_sigma_dut(dut)) {
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008419 dut->ap_mode = AP_11ad;
8420 dut->ap_channel = 2;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02008421 dut->wps_disable = 0; /* WPS is enabled */
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008422 dut->ap_pmf = 0;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +02008423 dut->ap_num_ese_allocs = 0;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008424 dut->ap_fixed_rate = 0;
8425
8426 dut->dev_role = DEVROLE_AP;
8427
8428 sigma_dut_print(dut, DUT_MSG_DEBUG,
8429 "Setting msdu_size to MAX: 7912");
8430 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
8431 get_main_ifname());
8432
8433 if (system(buf) != 0) {
8434 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
8435 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008436 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008437 }
8438
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008439 if (ap_set_force_mcs(dut, 0, 1)) {
8440 sigma_dut_print(dut, DUT_MSG_ERROR,
8441 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008442 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02008443 }
8444
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008445 if (set_ps(get_main_ifname(), dut, 1)) {
8446 sigma_dut_print(dut, DUT_MSG_ERROR,
8447 "Failed to enable power save");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008448 return ERROR_SEND_STATUS;
Alexei Avshalom Lazar2712cc82018-12-23 16:29:14 +02008449 }
8450 }
8451
Alexei Avshalom Lazarb6d25d52019-02-04 14:08:44 +02008452 if (dut->program == PROGRAM_WPS &&
8453 get_driver_type() == DRIVER_WIL6210) {
8454 /*
8455 * In 60 GHz WPS tests, we configure the AP OOB to
8456 * secure connection with a random passphrase.
8457 */
8458 char r[16], passphrase[65];
8459
8460 if (random_get_bytes(r, sizeof(r))) {
8461 sigma_dut_print(dut, DUT_MSG_ERROR,
8462 "Failed to get random bytes");
8463 return ERROR_SEND_STATUS;
8464 }
8465 if (base64_encode(r, sizeof(r),
8466 passphrase, sizeof(passphrase))) {
8467 sigma_dut_print(dut, DUT_MSG_ERROR,
8468 "Failed to generate random passphrase");
8469 return ERROR_SEND_STATUS;
8470 }
8471
8472 dut->ap_key_mgmt = AP_WPA2_PSK;
8473 dut->ap_cipher = AP_GCMP_128;
8474 strlcpy(dut->ap_passphrase, passphrase,
8475 sizeof(dut->ap_passphrase));
8476 sigma_dut_print(dut, DUT_MSG_DEBUG,
8477 "60G WPS: configure secure AP with random passphrase");
8478 }
8479
Jouni Malinend86e5822017-08-29 03:55:32 +03008480 dut->hostapd_running = 0;
priyadharshini gowthaman9947fd32018-01-26 15:19:41 -08008481
8482 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
8483 return 1;
8484
Jouni Malinend6bf1b42017-06-23 17:51:01 +03008485 if (dut->use_hostapd_pid_file) {
8486 kill_hostapd_process_pid(dut);
8487 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
8488 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008489 int i;
8490 /* Wait some time to allow hostapd to complete cleanup before
8491 * starting a new process */
8492 for (i = 0; i < 10; i++) {
8493 usleep(500000);
8494 if (system("pidof hostapd") != 0)
8495 break;
8496 }
8497 }
8498
8499 if (if_nametoindex("sigmadut") > 0 &&
8500 system("iw dev sigmadut del") != 0)
8501 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
8502 "monitor interface");
8503
8504 return 1;
8505}
8506
8507
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308508int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
8509 struct sigma_cmd *cmd)
8510{
8511 return cmd_ap_reset_default(dut, conn, cmd);
8512}
8513
8514
Jouni Malinenf7222712019-06-13 01:50:21 +03008515static enum sigma_cmd_result cmd_ap_get_info(struct sigma_dut *dut,
8516 struct sigma_conn *conn,
8517 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008518{
8519 /* const char *name = get_param(cmd, "NAME"); */
8520 struct stat s;
8521 char resp[200];
8522 FILE *f;
8523 enum driver_type drv = get_driver_type();
Jouni Malinen3aa72862019-05-29 23:14:51 +03008524 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008525
8526 switch (drv) {
8527 case DRIVER_ATHEROS: {
8528 /* Atheros AP */
8529 struct utsname uts;
8530 char *version, athver[100];
8531
8532 if (stat("/proc/athversion", &s) != 0) {
8533 if (system("/etc/rc.d/rc.wlan up") != 0) {
8534 }
8535 }
8536
8537 athver[0] = '\0';
8538 f = fopen("/proc/athversion", "r");
8539 if (f) {
8540 if (fgets(athver, sizeof(athver), f)) {
8541 char *pos = strchr(athver, '\n');
8542 if (pos)
8543 *pos = '\0';
8544 }
8545 fclose(f);
8546 }
8547
8548 if (uname(&uts) == 0)
8549 version = uts.release;
8550 else
8551 version = "Unknown";
8552
8553 if (if_nametoindex("ath1") > 0)
Jouni Malinen3aa72862019-05-29 23:14:51 +03008554 res = snprintf(resp, sizeof(resp),
8555 "interface,ath0_24G ath1_5G,agent,1.0,version,%s/drv:%s",
8556 version, athver);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008557 else
Jouni Malinen3aa72862019-05-29 23:14:51 +03008558 res = snprintf(resp, sizeof(resp),
8559 "interface,ath0_24G,agent,1.0,version,%s/drv:%s",
8560 version, athver);
8561 if (res < 0 || res >= sizeof(resp))
8562 send_resp(dut, conn, SIGMA_ERROR, NULL);
8563 else
8564 send_resp(dut, conn, SIGMA_COMPLETE, resp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008565 return 0;
8566 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05308567 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008568 case DRIVER_MAC80211: {
8569 struct utsname uts;
8570 char *version;
8571
8572 if (uname(&uts) == 0)
8573 version = uts.release;
8574 else
8575 version = "Unknown";
8576
8577 if (if_nametoindex("wlan1") > 0)
8578 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
8579 "wlan1_5G,agent,1.0,version,%s", version);
8580 else
8581 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
8582 "agent,1.0,version,%s", version);
8583
8584 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8585 return 0;
8586 }
8587 case DRIVER_QNXNTO: {
8588 struct utsname uts;
8589 char *version;
8590
8591 if (uname(&uts) == 0)
8592 version = uts.release;
8593 else
8594 version = "Unknown";
8595 snprintf(resp, sizeof(resp),
8596 "interface,%s_any,agent,1.0,version,%s",
8597 sigma_main_ifname ? sigma_main_ifname : "NA",
8598 version);
8599 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8600 return 0;
8601 }
8602 case DRIVER_OPENWRT: {
8603 switch (get_openwrt_driver_type()) {
8604 case OPENWRT_DRIVER_ATHEROS: {
8605 struct utsname uts;
8606 char *version;
8607
8608 if (uname(&uts) == 0)
8609 version = uts.release;
8610 else
8611 version = "Unknown";
8612
8613 if (if_nametoindex("ath1") > 0)
8614 snprintf(resp, sizeof(resp),
8615 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
8616 version);
8617 else
8618 snprintf(resp, sizeof(resp),
8619 "interface,ath0_any,agent,1.0,version,%s",
8620 version);
8621
8622 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8623 return 0;
8624 }
8625 default:
8626 send_resp(dut, conn, SIGMA_ERROR,
8627 "errorCode,Unsupported openwrt driver");
8628 return 0;
8629 }
8630 }
8631 default:
8632 send_resp(dut, conn, SIGMA_ERROR,
8633 "errorCode,Unsupported driver");
8634 return 0;
8635 }
8636}
8637
8638
Jouni Malinenf7222712019-06-13 01:50:21 +03008639static enum sigma_cmd_result cmd_ap_deauth_sta(struct sigma_dut *dut,
8640 struct sigma_conn *conn,
8641 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008642{
8643 /* const char *name = get_param(cmd, "NAME"); */
8644 /* const char *ifname = get_param(cmd, "INTERFACE"); */
8645 const char *val;
8646 char buf[100];
8647
8648 val = get_param(cmd, "MinorCode");
8649 if (val) {
8650 /* TODO: add support for P2P minor code */
8651 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
8652 "yet supported");
8653 return 0;
8654 }
8655
8656 val = get_param(cmd, "STA_MAC_ADDRESS");
8657 if (val == NULL)
8658 return -1;
8659 snprintf(buf, sizeof(buf), "deauth %s", val);
8660 if (run_hostapd_cli(dut, buf) != 0)
8661 return -2;
8662
8663 return 1;
8664}
8665
8666
8667#ifdef __linux__
8668int inject_frame(int s, const void *data, size_t len, int encrypt);
8669int open_monitor(const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008670#endif /* __linux__ */
8671
8672enum send_frame_type {
8673 DISASSOC, DEAUTH, SAQUERY
8674};
8675enum send_frame_protection {
8676 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8677};
8678
8679
8680static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8681 enum send_frame_type frame,
8682 enum send_frame_protection protected,
8683 const char *sta_addr)
8684{
8685#ifdef __linux__
8686 unsigned char buf[1000], *pos;
8687 int s, res;
8688 unsigned char addr_sta[6], addr_own[6];
8689 char *ifname;
8690 char cbuf[100];
8691 struct ifreq ifr;
8692
8693 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
8694 dut->ap_mode == AP_11ac) &&
8695 if_nametoindex("wlan1") > 0)
8696 ifname = "wlan1";
8697 else
8698 ifname = "wlan0";
8699
8700 if (hwaddr_aton(sta_addr, addr_sta) < 0)
8701 return -1;
8702
8703 s = socket(AF_INET, SOCK_DGRAM, 0);
8704 if (s < 0)
8705 return -1;
8706 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07008707 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008708 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
8709 perror("ioctl");
8710 close(s);
8711 return -1;
8712 }
8713 close(s);
8714 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
8715
8716 if (if_nametoindex("sigmadut") == 0) {
8717 snprintf(cbuf, sizeof(cbuf),
8718 "iw dev %s interface add sigmadut type monitor",
8719 ifname);
8720 if (system(cbuf) != 0 ||
8721 if_nametoindex("sigmadut") == 0) {
8722 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8723 "monitor interface with '%s'", cbuf);
8724 return -2;
8725 }
8726 }
8727
8728 if (system("ifconfig sigmadut up") != 0) {
8729 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8730 "monitor interface up");
8731 return -2;
8732 }
8733
8734 pos = buf;
8735
8736 /* Frame Control */
8737 switch (frame) {
8738 case DISASSOC:
8739 *pos++ = 0xa0;
8740 break;
8741 case DEAUTH:
8742 *pos++ = 0xc0;
8743 break;
8744 case SAQUERY:
8745 *pos++ = 0xd0;
8746 break;
8747 }
8748
8749 if (protected == INCORRECT_KEY)
8750 *pos++ = 0x40; /* Set Protected field to 1 */
8751 else
8752 *pos++ = 0x00;
8753
8754 /* Duration */
8755 *pos++ = 0x00;
8756 *pos++ = 0x00;
8757
8758 /* addr1 = DA (station) */
8759 memcpy(pos, addr_sta, 6);
8760 pos += 6;
8761 /* addr2 = SA (own address) */
8762 memcpy(pos, addr_own, 6);
8763 pos += 6;
8764 /* addr3 = BSSID (own address) */
8765 memcpy(pos, addr_own, 6);
8766 pos += 6;
8767
8768 /* Seq# (to be filled by driver/mac80211) */
8769 *pos++ = 0x00;
8770 *pos++ = 0x00;
8771
8772 if (protected == INCORRECT_KEY) {
8773 /* CCMP parameters */
8774 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8775 pos += 8;
8776 }
8777
8778 if (protected == INCORRECT_KEY) {
8779 switch (frame) {
8780 case DEAUTH:
8781 /* Reason code (encrypted) */
8782 memcpy(pos, "\xa7\x39", 2);
8783 pos += 2;
8784 break;
8785 case DISASSOC:
8786 /* Reason code (encrypted) */
8787 memcpy(pos, "\xa7\x39", 2);
8788 pos += 2;
8789 break;
8790 case SAQUERY:
8791 /* Category|Action|TransID (encrypted) */
8792 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8793 pos += 4;
8794 break;
8795 default:
8796 return -1;
8797 }
8798
8799 /* CCMP MIC */
8800 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8801 pos += 8;
8802 } else {
8803 switch (frame) {
8804 case DEAUTH:
8805 /* reason code = 8 */
8806 *pos++ = 0x08;
8807 *pos++ = 0x00;
8808 break;
8809 case DISASSOC:
8810 /* reason code = 8 */
8811 *pos++ = 0x08;
8812 *pos++ = 0x00;
8813 break;
8814 case SAQUERY:
8815 /* Category - SA Query */
8816 *pos++ = 0x08;
8817 /* SA query Action - Request */
8818 *pos++ = 0x00;
8819 /* Transaction ID */
8820 *pos++ = 0x12;
8821 *pos++ = 0x34;
8822 break;
8823 }
8824 }
8825
8826 s = open_monitor("sigmadut");
8827 if (s < 0) {
8828 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8829 "monitor socket");
8830 return 0;
8831 }
8832
8833 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8834 if (res < 0) {
8835 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8836 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308837 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008838 return 0;
8839 }
8840 if (res < pos - buf) {
8841 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8842 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308843 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008844 return 0;
8845 }
8846
8847 close(s);
8848
8849 return 1;
8850#else /* __linux__ */
8851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
8852 "yet supported");
8853 return 0;
8854#endif /* __linux__ */
8855}
8856
8857
8858int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
8859 struct sigma_cmd *cmd)
8860{
8861 const char *val, *dest;
8862 char buf[100];
8863
8864 val = get_param(cmd, "FrameName");
8865 if (val == NULL)
8866 return -1;
8867
8868 if (strcasecmp(val, "QoSMapConfigure") == 0) {
8869 dest = get_param(cmd, "Dest");
8870 if (!dest)
8871 return -1;
8872
8873 val = get_param(cmd, "QoS_MAP_SET");
8874 if (val) {
8875 dut->ap_qos_map_set = atoi(val);
8876 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8877 dut->ap_qos_map_set);
8878 }
8879
8880 if (dut->ap_qos_map_set == 1)
8881 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
8882 else if (dut->ap_qos_map_set == 2)
8883 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
8884
8885 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
8886 if (run_hostapd_cli(dut, buf) != 0)
8887 return -1;
8888 }
8889
8890 return 1;
8891}
8892
8893
8894static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
8895 struct sigma_cmd *cmd)
8896{
8897 const char *val;
8898 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008899 int chwidth, nss;
8900
8901 val = get_param(cmd, "FrameName");
8902 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
8903 send_resp(dut, conn, SIGMA_ERROR,
8904 "errorCode,Unsupported FrameName");
8905 return 0;
8906 }
8907
8908 /*
8909 * Sequence of commands for Opmode notification on
8910 * Peregrine based products
8911 */
8912 ifname = get_main_ifname();
8913
8914 /* Disable STBC */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008915 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008916
8917 /* Check whether optional arg channel width was passed */
8918 val = get_param(cmd, "Channel_width");
8919 if (val) {
8920 switch (atoi(val)) {
8921 case 20:
8922 chwidth = 0;
8923 break;
8924 case 40:
8925 chwidth = 1;
8926 break;
8927 case 80:
8928 chwidth = 2;
8929 break;
8930 case 160:
8931 chwidth = 3;
8932 break;
8933 default:
8934 chwidth = 2;
8935 break;
8936 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008937 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008938 }
8939
8940 /* Check whether optional arg NSS was passed */
8941 val = get_param(cmd, "NSS");
8942 if (val) {
8943 /* Convert nss to chainmask */
8944 switch (atoi(val)) {
8945 case 1:
8946 nss = 1;
8947 break;
8948 case 2:
8949 nss = 3;
8950 break;
8951 case 3:
8952 nss = 7;
8953 break;
8954 default:
8955 /* We do not support NSS > 3 */
8956 nss = 3;
8957 break;
8958 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008959 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008960 }
8961
8962 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07008963 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008964
8965 return 1;
8966}
8967
8968
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008969static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
8970 struct sigma_cmd *cmd)
8971{
8972 const char *val;
8973 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008974 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008975
8976 val = get_param(cmd, "MsntType");
8977 if (val) {
8978 if (dut->ap_msnt_type == 0)
8979 dut->ap_msnt_type = atoi(val);
8980
8981 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
8982 dut->ap_msnt_type = atoi(val);
8983 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008984 val = get_param(cmd, "RandInterval");
8985 if (val)
8986 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008987 f = fopen("/tmp/ftmrr.txt", "a");
8988 if (!f) {
8989 sigma_dut_print(dut, DUT_MSG_ERROR,
8990 "Failed to open /tmp/ftmrr.txt");
8991 return -1;
8992 }
8993
8994 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07008995 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",
8996 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07008997 fclose(f);
8998 dut->ap_msnt_type = 5;
8999 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9000 }
9001 } else if (dut->ap_msnt_type == 5) {
9002 run_system(dut, "wpc -f /tmp/ftmrr.txt");
9003 } else if (dut->ap_msnt_type == 2) {
9004 f = fopen("/tmp/wru.txt", "w");
9005 if (!f) {
9006 sigma_dut_print(dut, DUT_MSG_ERROR,
9007 "Failed to open /tmp/wru.txt");
9008 return -1;
9009 }
9010
9011 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
9012 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
9013 fclose(f);
9014 run_system(dut, "wpc -w /tmp/wru.txt");
9015 }
9016 }
9017 return 1;
9018}
9019
9020
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009021/*
9022 * The following functions parse_send_frame_params_int(),
9023 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
9024 * are used by ath_ap_send_frame_bcn_rpt_req().
9025 * Beacon Report Request is a frame used as part of the MBO program.
9026 * The command for sending beacon report has a lot of
9027 * arguments and having these functions reduces code size.
9028 *
9029 */
9030static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
9031 struct sigma_dut *dut,
9032 char *buf, size_t buf_size)
9033{
9034 const char *str_val;
9035 int int_val;
9036 char temp[100];
9037
9038 str_val = get_param(cmd, param);
9039 if (!str_val) {
9040 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9041 return -1;
9042 }
9043 int_val = atoi(str_val);
9044 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07009045 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009046 return 0;
9047}
9048
9049
9050static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
9051 struct sigma_dut *dut,
9052 char *buf, size_t buf_size)
9053{
9054 const char *str_val;
9055 char temp[100];
9056
9057 str_val = get_param(cmd, param);
9058 if (!str_val) {
9059 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9060 return -1;
9061 }
9062 snprintf(temp, sizeof(temp), " %s", str_val);
9063 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07009064 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009065 return 0;
9066}
9067
9068
9069static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
9070 struct sigma_dut *dut,
9071 char *buf, size_t buf_size)
9072{
9073 const char *str_val;
9074 unsigned char mac[6];
9075 char temp[100];
9076
9077 str_val = get_param(cmd, param);
9078 if (!str_val) {
9079 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
9080 return -1;
9081 }
9082
9083 if (parse_mac_address(dut, str_val, mac) < 0) {
9084 sigma_dut_print(dut, DUT_MSG_ERROR,
9085 "MAC Address not in proper format");
9086 return -1;
9087 }
9088 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
9089 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07009090 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009091 return 0;
9092}
9093
9094
9095static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
9096 char *buf, size_t buf_size)
9097{
9098 const char *str_val;
9099 char *value = " 1";
9100
9101 str_val = get_param(cmd, param);
9102 if (!str_val || str_val[0] == '\0')
9103 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07009104 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009105
9106}
9107
9108
9109/*
9110 * wifitool athN sendbcnrpt
9111 * <STA MAC - Plugs in from Dest_MAC>
9112 * <regclass - Plugs in from RegClass - int>
9113 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
9114 * <rand_ivl - Plugs in from RandInt - string>
9115 * <duration - Plugs in from MeaDur - integer>
9116 * <mode - Plugs in from MeaMode - string>
9117 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
9118 * <rep_cond - Plugs in from RptCond - integer>
9119 * <rpt_detail - Plugs in from RptDet - integer>
9120 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
9121 * <chanrpt_mode - Plugs in from APChanRpt - integer>
9122 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
9123 * [AP channel numbers]
9124 */
9125static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
9126 struct sigma_cmd *cmd,
9127 const char *ifname)
9128{
9129 char buf[100];
9130 int rpt_det;
9131 const char *str_val;
9132 const char *mea_mode;
9133
9134 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
9135
9136 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
9137 return -1;
9138 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
9139 return -1;
9140 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
9141 return -1;
9142 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
9143 return -1;
9144 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
9145 return -1;
9146
9147 str_val = get_param(cmd, "MeaMode");
9148 if (!str_val) {
9149 sigma_dut_print(dut, DUT_MSG_ERROR,
9150 "MeaMode parameter not present in send bcn-rpt-req");
9151 return -1;
9152 }
9153 if (strcasecmp(str_val, "passive") == 0) {
9154 mea_mode = " 0";
9155 } else if (strcasecmp(str_val, "active") == 0) {
9156 mea_mode = " 1";
9157 } else if (strcasecmp(str_val, "table") == 0) {
9158 mea_mode = " 2";
9159 } else {
9160 sigma_dut_print(dut, DUT_MSG_ERROR,
9161 "MEA-MODE Value not correctly given");
9162 return -1;
9163 }
Peng Xu591be452017-05-10 17:27:28 -07009164 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009165
9166 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
9167
9168 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
9169 return -1;
9170
9171 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
9172 return -1;
9173 str_val = get_param(cmd, "RptDet");
9174 rpt_det = str_val ? atoi(str_val) : 0;
9175
9176 if (rpt_det)
9177 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
9178 else
Peng Xu591be452017-05-10 17:27:28 -07009179 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009180
9181 if (rpt_det)
9182 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
9183 sizeof(buf));
9184 else
Peng Xu591be452017-05-10 17:27:28 -07009185 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009186
9187 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
9188 return -1;
9189
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009190 str_val = get_param(cmd, "APChanRpt");
9191 if (str_val) {
9192 const char *pos;
9193 int ap_chanrpt;
9194 int ap_chanrpt_2 = 0;
9195 char chanrpt[100];
9196
9197 ap_chanrpt = atoi(str_val);
9198 pos = strchr(str_val, '_');
9199 if (pos) {
9200 pos++;
9201 ap_chanrpt_2 = atoi(pos);
9202 }
9203 if (ap_chanrpt) {
9204 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt);
9205 strlcat(buf, chanrpt, sizeof(buf));
9206 }
9207 if (ap_chanrpt_2) {
9208 snprintf(chanrpt, sizeof(chanrpt), " %d", ap_chanrpt_2);
9209 strlcat(buf, chanrpt, sizeof(buf));
9210 }
9211 }
9212
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009213 run_system(dut, buf);
9214 return 0;
9215}
9216
9217
9218static void inform_and_sleep(struct sigma_dut *dut, int seconds)
9219{
9220 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
9221 sleep(seconds);
9222 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
9223 seconds);
9224}
9225
9226
9227static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
9228 struct sigma_cmd *cmd, const char *ifname)
9229{
9230 unsigned char mac_addr[ETH_ALEN];
9231 int disassoc_timer;
9232 char buf[100];
9233 const char *val;
9234 int cand_list = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009235
9236 val = get_param(cmd, "Dest_MAC");
9237 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9238 sigma_dut_print(dut, DUT_MSG_ERROR,
9239 "MAC Address not in proper format");
9240 return -1;
9241 }
9242
9243 val = get_param(cmd, "Disassoc_Timer");
9244 if (val)
9245 disassoc_timer = atoi(val);
9246 else
9247 disassoc_timer = dut->ap_disassoc_timer;
Jouni Malinen032aeab2018-01-04 12:30:46 +02009248 if (disassoc_timer < 0) {
9249 sigma_dut_print(dut, DUT_MSG_ERROR,
9250 "Invalid Disassoc_Timer value %d",
9251 disassoc_timer);
9252 return -1;
9253 }
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009254
9255 val = get_param(cmd, "Cand_List");
9256 if (val && val[0])
9257 cand_list = atoi(val);
9258
9259 val = get_param(cmd, "BTMQuery_Reason_Code");
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009260 if (val)
9261 run_iwpriv(dut, ifname, "mbo_trans_rs %s", val);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009262
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009263 if (dut->ap_btmreq_disassoc_imnt && !dut->ap_assoc_delay)
9264 run_iwpriv(dut, ifname, "mbo_asoc_ret 1");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009265
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009266 snprintf(buf, sizeof(buf),
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009267 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 15 %d %d %d %d",
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009268 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
9269 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
9270 dut->ap_btmreq_disassoc_imnt,
9271 dut->ap_btmreq_term_bit,
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009272 dut->ap_btmreq_bss_term_tsf,
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009273 dut->ap_btmreq_bss_term_dur);
9274 run_system(dut, buf);
9275
9276 if (dut->ap_btmreq_term_bit) {
priyadharshini gowthaman94062b52017-12-20 12:33:34 -08009277 if (dut->ap_btmreq_bss_term_tsf >= 2)
9278 inform_and_sleep(dut, dut->ap_btmreq_bss_term_tsf - 2);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009279 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9280 mac_addr[0], mac_addr[1], mac_addr[2],
9281 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009282 inform_and_sleep(dut, 2);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009283 run_system_wrapper(dut, "ifconfig %s down", ifname);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -08009284 inform_and_sleep(dut, 5);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009285 run_system_wrapper(dut, "ifconfig %s up", ifname);
9286 } else if (dut->ap_btmreq_disassoc_imnt) {
9287 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009288 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9289 mac_addr[0], mac_addr[1], mac_addr[2],
9290 mac_addr[3], mac_addr[4], mac_addr[5]);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009291 }
9292 return 0;
9293}
9294
9295
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009296static int ath_ap_send_frame_disassoc(struct sigma_dut *dut,
9297 struct sigma_cmd *cmd, const char *ifname)
9298{
9299 unsigned char mac_addr[ETH_ALEN];
9300 const char *val;
9301
9302 val = get_param(cmd, "Dest_MAC");
9303 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
9304 sigma_dut_print(dut, DUT_MSG_ERROR,
9305 "MAC Address not in proper format");
9306 return -1;
9307 }
9308
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -07009309 run_iwpriv(dut, ifname, "kickmac %02x:%02x:%02x:%02x:%02x:%02x",
9310 mac_addr[0], mac_addr[1], mac_addr[2],
9311 mac_addr[3], mac_addr[4], mac_addr[5]);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009312 return 0;
9313}
9314
9315
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009316static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9317 struct sigma_cmd *cmd)
9318{
9319 const char *val;
9320 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009321
9322 ifname = get_main_ifname();
9323
9324 val = get_param(cmd, "FrameName");
9325 if (!val)
9326 return -1;
9327
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009328 if (strcasecmp(val, "BTMReq") == 0)
9329 ath_ap_send_frame_btm_req(dut, cmd, ifname);
9330 else if (strcasecmp(val, "BcnRptReq") == 0)
9331 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
priyadharshini gowthaman2a4d20e2017-12-28 13:01:34 -08009332 else if (strcasecmp(val, "disassoc") == 0)
9333 ath_ap_send_frame_disassoc(dut, cmd, ifname);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07009334 else
9335 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009336
9337 return 1;
9338}
9339
9340
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009341static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
9342 struct sigma_cmd *cmd)
9343{
9344 switch (get_driver_type()) {
9345 case DRIVER_ATHEROS:
9346 return ath_ap_send_frame_vht(dut, conn, cmd);
9347 break;
9348 case DRIVER_OPENWRT:
9349 switch (get_openwrt_driver_type()) {
9350 case OPENWRT_DRIVER_ATHEROS:
9351 return ath_ap_send_frame_vht(dut, conn, cmd);
9352 default:
9353 send_resp(dut, conn, SIGMA_ERROR,
9354 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9355 return 0;
9356 }
9357 default:
9358 send_resp(dut, conn, SIGMA_ERROR,
9359 "errorCode,Unsupported ap_send_frame with the current driver");
9360 return 0;
9361 }
9362}
9363
9364
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009365static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
9366 struct sigma_cmd *cmd)
9367{
9368 switch (get_driver_type()) {
9369 case DRIVER_ATHEROS:
9370 return ath_ap_send_frame_loc(dut, conn, cmd);
9371 case DRIVER_OPENWRT:
9372 switch (get_openwrt_driver_type()) {
9373 case OPENWRT_DRIVER_ATHEROS:
9374 return ath_ap_send_frame_loc(dut, conn, cmd);
9375 default:
9376 send_resp(dut, conn, SIGMA_ERROR,
9377 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
9378 return 0;
9379 }
9380 default:
9381 send_resp(dut, conn, SIGMA_ERROR,
9382 "errorCode,Unsupported ap_send_frame_loc with the current driver");
9383 return 0;
9384 }
9385}
9386
9387
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009388static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
9389 struct sigma_cmd *cmd)
9390{
9391 switch (get_driver_type()) {
9392 case DRIVER_ATHEROS:
9393 return ath_ap_send_frame_mbo(dut, conn, cmd);
9394 case DRIVER_OPENWRT:
9395 switch (get_openwrt_driver_type()) {
9396 case OPENWRT_DRIVER_ATHEROS:
9397 return ath_ap_send_frame_mbo(dut, conn, cmd);
9398 default:
9399 send_resp(dut, conn, SIGMA_ERROR,
9400 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
9401 return 0;
9402 }
9403 default:
9404 send_resp(dut, conn, SIGMA_ERROR,
9405 "errorCode,Unsupported ap_send_frame with the current driver");
9406 return 0;
9407 }
9408}
9409
9410
Lior David0fe101e2017-03-09 16:09:50 +02009411static int ap_send_frame_60g(struct sigma_dut *dut,
9412 struct sigma_conn *conn,
9413 struct sigma_cmd *cmd)
9414{
9415 switch (get_driver_type()) {
9416#ifdef __linux__
9417 case DRIVER_WIL6210:
9418 return wil6210_send_frame_60g(dut, conn, cmd);
9419#endif /* __linux__ */
9420 default:
9421 send_resp(dut, conn, SIGMA_ERROR,
9422 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9423 return 0;
9424 }
9425}
9426
9427
Jouni Malinenf7222712019-06-13 01:50:21 +03009428enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
9429 struct sigma_conn *conn,
9430 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009431{
9432 /* const char *name = get_param(cmd, "NAME"); */
9433 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9434 const char *val;
9435 enum send_frame_type frame;
9436 enum send_frame_protection protected;
9437 char buf[100];
9438
9439 val = get_param(cmd, "Program");
9440 if (val) {
9441 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07009442 strcasecmp(val, "HS2-R2") == 0 ||
9443 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009444 return ap_send_frame_hs2(dut, conn, cmd);
9445 if (strcasecmp(val, "VHT") == 0)
9446 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07009447 if (strcasecmp(val, "LOC") == 0)
9448 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07009449 if (strcasecmp(val, "MBO") == 0)
9450 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009451 if (strcasecmp(val, "60GHz") == 0)
9452 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009453 }
9454
9455 val = get_param(cmd, "PMFFrameType");
9456 if (val == NULL)
9457 val = get_param(cmd, "FrameName");
9458 if (val == NULL)
9459 val = get_param(cmd, "Type");
9460 if (val == NULL)
9461 return -1;
9462 if (strcasecmp(val, "disassoc") == 0)
9463 frame = DISASSOC;
9464 else if (strcasecmp(val, "deauth") == 0)
9465 frame = DEAUTH;
9466 else if (strcasecmp(val, "saquery") == 0)
9467 frame = SAQUERY;
9468 else {
9469 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9470 "PMFFrameType");
9471 return 0;
9472 }
9473
9474 val = get_param(cmd, "PMFProtected");
9475 if (val == NULL)
9476 val = get_param(cmd, "Protected");
9477 if (val == NULL)
9478 return -1;
9479 if (strcasecmp(val, "Correct-key") == 0 ||
9480 strcasecmp(val, "CorrectKey") == 0)
9481 protected = CORRECT_KEY;
9482 else if (strcasecmp(val, "IncorrectKey") == 0)
9483 protected = INCORRECT_KEY;
9484 else if (strcasecmp(val, "Unprotected") == 0)
9485 protected = UNPROTECTED;
9486 else {
9487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9488 "PMFProtected");
9489 return 0;
9490 }
9491
9492 val = get_param(cmd, "stationID");
9493 if (val == NULL)
9494 return -1;
9495
9496 if (protected == INCORRECT_KEY ||
9497 (protected == UNPROTECTED && frame == SAQUERY))
9498 return ap_inject_frame(dut, conn, frame, protected, val);
9499
9500 switch (frame) {
9501 case DISASSOC:
9502 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
9503 val, protected == CORRECT_KEY);
9504 break;
9505 case DEAUTH:
9506 snprintf(buf, sizeof(buf), "deauth %s test=%d",
9507 val, protected == CORRECT_KEY);
9508 break;
9509 case SAQUERY:
9510 snprintf(buf, sizeof(buf), "sa_query %s", val);
9511 break;
9512 }
9513
9514 if (run_hostapd_cli(dut, buf) != 0)
9515 return -2;
9516
9517 return 1;
9518}
9519
9520
Jouni Malinenf7222712019-06-13 01:50:21 +03009521static enum sigma_cmd_result cmd_ap_get_mac_address(struct sigma_dut *dut,
9522 struct sigma_conn *conn,
9523 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009524{
9525#if defined( __linux__)
9526 /* const char *name = get_param(cmd, "NAME"); */
9527 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03009528 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009529 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009530 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009531 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009532 int s, wlan_tag = 1;
9533 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009534
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009535 val = get_param(cmd, "WLAN_TAG");
9536 if (val) {
9537 wlan_tag = atoi(val);
9538 if (wlan_tag < 1 || wlan_tag > 3) {
9539 /*
9540 * The only valid WLAN Tags as of now as per the latest
9541 * WFA scripts are 1, 2, and 3.
9542 */
Jouni Malinenf8984642017-10-12 00:02:37 +03009543 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009544 "errorCode,Unsupported WLAN_TAG");
9545 return 0;
9546 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009547 }
9548
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07009549 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
9550
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009551 s = socket(AF_INET, SOCK_DGRAM, 0);
9552 if (s < 0)
9553 return -1;
9554 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07009555 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009556 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
9557 perror("ioctl");
9558 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03009559 snprintf(resp, sizeof(resp),
9560 "errorCode,Could not find interface %s", ifname);
9561 send_resp(dut, conn, SIGMA_ERROR, resp);
9562 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009563 }
9564 close(s);
9565 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
9566
9567 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9568 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9569 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9570 return 0;
9571#elif defined( __QNXNTO__)
9572 char resp[50];
9573 unsigned char addr[6];
9574
9575 if (!sigma_main_ifname) {
9576 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
9577 return 0;
9578 }
9579
9580 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
9581 send_resp(dut, conn, SIGMA_ERROR,
9582 "errorCode,Failed to get address");
9583 return 0;
9584 }
9585 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
9586 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
9587 send_resp(dut, conn, SIGMA_COMPLETE, resp);
9588 return 0;
9589#else /* __linux__ */
9590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
9591 "yet supported");
9592 return 0;
9593#endif /* __linux__ */
9594}
9595
9596
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309597int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
9598 struct sigma_cmd *cmd)
9599{
9600 return cmd_ap_get_mac_address(dut, conn, cmd);
9601}
9602
9603
Jouni Malinenf7222712019-06-13 01:50:21 +03009604static enum sigma_cmd_result cmd_ap_set_pmf(struct sigma_dut *dut,
9605 struct sigma_conn *conn,
9606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009607{
9608 /*
9609 * Ignore the command since the parameters are already handled through
9610 * ap_set_security.
9611 */
9612
9613 return 1;
9614}
9615
9616
Jouni Malinenf7222712019-06-13 01:50:21 +03009617static enum sigma_cmd_result cmd_ap_set_hs2(struct sigma_dut *dut,
9618 struct sigma_conn *conn,
9619 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009620{
9621 /* const char *name = get_param(cmd, "NAME"); */
9622 /* const char *ifname = get_param(cmd, "INTERFACE"); */
9623 const char *val, *dest;
9624 char *pos, buf[100];
9625 int i, wlan_tag = 1;
9626
9627 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
9628 "following parameters");
9629 for (i = 0; i < cmd->count; i++) {
9630 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
9631 (cmd->values[i] ? cmd->values[i] : "NULL"));
9632 }
9633
9634 val = get_param(cmd, "ICMPv4_ECHO");
9635 if (val && atoi(val)) {
9636 snprintf(buf, sizeof(buf), "ebtables -F");
9637 if (system(buf) != 0) {
9638 sigma_dut_print(dut, DUT_MSG_ERROR,
9639 "Failed to set ebtables rules, RULE-12");
9640 }
9641 return 1;
9642 }
9643
9644 val = get_param(cmd, "WLAN_TAG");
9645 if (val) {
9646 wlan_tag = atoi(val);
9647 if (wlan_tag != 1 && wlan_tag != 2) {
9648 send_resp(dut, conn, SIGMA_INVALID,
9649 "errorCode,Invalid WLAN_TAG");
9650 return 0;
9651 }
9652 }
9653
9654 if (wlan_tag == 2) {
9655 val = get_param(cmd, "PROXY_ARP");
9656 if (val)
9657 dut->ap2_proxy_arp = atoi(val);
Jouni Malinendbbc2c42018-11-14 23:55:41 +02009658
9659 val = get_param(cmd, "OSU");
9660 if (val)
9661 dut->ap2_osu = atoi(val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009662 return 1;
9663 }
9664
9665 dest = get_param(cmd, "STA_MAC");
9666 if (dest) {
9667 /* This is a special/ugly way of using this command.
9668 * If "Dest" MAC is included, assume that this command
9669 * is being issued after ap_config_commit for dynamically
9670 * setting the QoS Map Set.
9671 */
9672 val = get_param(cmd, "QoS_MAP_SET");
9673 if (val) {
9674 dut->ap_qos_map_set = atoi(val);
9675 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
9676 dut->ap_qos_map_set);
9677 }
9678
9679 if (dut->ap_qos_map_set == 1)
9680 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
9681 else if (dut->ap_qos_map_set == 2)
9682 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
9683
9684 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
9685 if (run_hostapd_cli(dut, buf) != 0)
9686 return -1;
9687 }
9688
9689 val = get_param(cmd, "DGAF_DISABLE");
9690 if (val)
9691 dut->ap_dgaf_disable = atoi(val);
9692
9693 dut->ap_interworking = 1;
9694
9695 val = get_param(cmd, "INTERWORKING");
9696 if (val == NULL)
9697 val = get_param(cmd, "INTERNETWORKING");
9698 if (val != NULL && atoi(val) == 0) {
9699 dut->ap_interworking = 0;
9700 dut->ap_hs2 = 0;
9701 return 1;
9702 }
9703
9704 val = get_param(cmd, "ACCS_NET_TYPE");
9705 if (val) {
9706 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
9707 strcasecmp(val, "Chargable_Public_Network") == 0 ||
9708 strcasecmp(val, "Chargable Public Network") == 0)
9709 dut->ap_access_net_type = 2;
9710 else
9711 dut->ap_access_net_type = atoi(val);
9712 }
9713
9714 val = get_param(cmd, "INTERNET");
9715 if (val)
9716 dut->ap_internet = atoi(val);
9717
9718 val = get_param(cmd, "VENUE_GRP");
9719 if (val) {
9720 if (strcasecmp(val, "Business") == 0)
9721 dut->ap_venue_group = 2;
9722 else
9723 dut->ap_venue_group = atoi(val);
9724 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9725 dut->ap_venue_name);
9726 }
9727
9728 val = get_param(cmd, "VENUE_TYPE");
9729 if (val) {
9730 if (strcasecmp(val, "R&D") == 0)
9731 dut->ap_venue_type = 8;
9732 else
9733 dut->ap_venue_type = atoi(val);
9734 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
9735 dut->ap_venue_type);
9736 }
9737
9738 val = get_param(cmd, "HESSID");
9739 if (val) {
9740 if (strlen(val) >= sizeof(dut->ap_hessid)) {
9741 send_resp(dut, conn, SIGMA_ERROR,
9742 "errorCode,Invalid HESSID");
9743 return 0;
9744 }
9745 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
9746 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
9747 dut->ap_hessid);
9748 }
9749
9750 val = get_param(cmd, "ROAMING_CONS");
9751 if (val) {
9752 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
9753 send_resp(dut, conn, SIGMA_ERROR,
9754 "errorCode,Invalid ROAMING_CONS");
9755 return 0;
9756 }
9757 if (strcasecmp(val, "Disabled") == 0) {
9758 dut->ap_roaming_cons[0] = '\0';
9759 } else {
9760 snprintf(dut->ap_roaming_cons,
9761 sizeof(dut->ap_roaming_cons), "%s", val);
9762 }
9763 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
9764 dut->ap_roaming_cons);
9765 }
9766
9767 val = get_param(cmd, "ANQP");
9768 if (val)
9769 dut->ap_anqpserver_on = atoi(val);
9770
9771 val = get_param(cmd, "NAI_REALM_LIST");
9772 if (val) {
9773 dut->ap_nai_realm_list = atoi(val);
9774 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
9775 dut->ap_nai_realm_list);
9776 }
9777
9778 val = get_param(cmd, "3GPP_INFO");
9779 if (val) {
9780 /* What kind of encoding format is used?! */
9781 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
9782 "not yet supported (contents not fully defined)");
9783 return 0;
9784 }
9785
9786 val = get_param(cmd, "DOMAIN_LIST");
9787 if (val) {
9788 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
9789 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
9790 "DOMAIN_LIST");
9791 return 0;
9792 }
9793 snprintf(dut->ap_domain_name_list,
9794 sizeof(dut->ap_domain_name_list), "%s", val);
9795 pos = dut->ap_domain_name_list;
9796 while (*pos) {
9797 if (*pos == ';')
9798 *pos = ',';
9799 pos++;
9800 }
9801 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
9802 dut->ap_domain_name_list);
9803 }
9804
9805 val = get_param(cmd, "OPER_NAME");
9806 if (val) {
9807 dut->ap_oper_name = atoi(val);
9808 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
9809 dut->ap_oper_name);
9810 }
9811
9812 val = get_param(cmd, "VENUE_NAME");
9813 if (val) {
9814 dut->ap_venue_name = atoi(val);
9815 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
9816 dut->ap_venue_name);
9817 }
9818
9819 val = get_param(cmd, "GAS_CB_DELAY");
9820 if (val) {
9821 dut->ap_gas_cb_delay = atoi(val);
9822 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
9823 dut->ap_gas_cb_delay);
9824 }
9825
9826 val = get_param(cmd, "MIH");
9827 if (val && atoi(val) > 0) {
9828 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
9829 "supported");
9830 return 0;
9831 }
9832
9833 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
9834 if (val) {
9835 dut->ap_l2tif = atoi(val);
9836 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
9837 dut->ap_l2tif);
9838 }
9839
9840 val = get_param(cmd, "BCST_UNCST");
9841 if (val) {
9842 send_resp(dut, conn, SIGMA_ERROR,
9843 "errorCode,BCST_UNCST not yet supported");
9844 return 0;
9845 }
9846
9847 val = get_param(cmd, "PLMN_MCC");
9848 if (val) {
9849 char mcc[100], *start, *end;
9850 int i = 0;
9851 if (strlen(val) >= sizeof(mcc)) {
9852 send_resp(dut, conn, SIGMA_ERROR,
9853 "errorCode,PLMN_MCC too long");
9854 return 0;
9855 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009856 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009857 start = mcc;
9858 while ((end = strchr(start, ';'))) {
9859 /* process all except the last */
9860 *end = '\0';
9861 if (strlen(start) != 3) {
9862 send_resp(dut, conn, SIGMA_ERROR,
9863 "errorCode,Invalid PLMN_MCC");
9864 return 0;
9865 }
9866 snprintf(dut->ap_plmn_mcc[i],
9867 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9868 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9869 dut->ap_plmn_mcc[i]);
9870 i++;
9871 start = end + 1;
9872 *end = ';';
9873 }
9874 if (strlen(start) != 3) {
9875 send_resp(dut, conn, SIGMA_ERROR,
9876 "errorCode,Invalid PLMN_MCC");
9877 return 0;
9878 }
9879 /* process last or only one */
9880 snprintf(dut->ap_plmn_mcc[i],
9881 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
9882 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
9883 dut->ap_plmn_mcc[i]);
9884 }
9885
9886 val = get_param(cmd, "PLMN_MNC");
9887 if (val) {
9888 char mnc[100], *start, *end;
9889 int i = 0;
9890 if (strlen(val) >= sizeof(mnc)) {
9891 send_resp(dut, conn, SIGMA_ERROR,
9892 "errorCode,PLMN_MNC too long");
9893 return 0;
9894 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07009895 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009896 start = mnc;
9897 while ((end = strchr(start, ';'))) {
9898 *end = '\0';
9899 if (strlen(start) != 2 && strlen(start) != 3) {
9900 send_resp(dut, conn, SIGMA_ERROR,
9901 "errorCode,Invalid PLMN_MNC");
9902 return 0;
9903 }
9904 snprintf(dut->ap_plmn_mnc[i],
9905 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9906 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9907 dut->ap_plmn_mnc[i]);
9908 i++;
9909 start = end + 1;
9910 *end = ';';
9911 }
9912 if (strlen(start) != 2 && strlen(start) != 3) {
9913 send_resp(dut, conn, SIGMA_ERROR,
9914 "errorCode,Invalid PLMN_MNC");
9915 return 0;
9916 }
9917 snprintf(dut->ap_plmn_mnc[i],
9918 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
9919 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
9920 dut->ap_plmn_mnc[i]);
9921 }
9922
9923 val = get_param(cmd, "PROXY_ARP");
9924 if (val) {
9925 dut->ap_proxy_arp = atoi(val);
9926 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
9927 dut->ap_proxy_arp);
9928 }
9929
9930 val = get_param(cmd, "WAN_METRICS");
9931 if (val) {
9932 dut->ap_wan_metrics = atoi(val);
9933 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
9934 dut->ap_wan_metrics);
9935 }
9936
9937 val = get_param(cmd, "CONN_CAP");
9938 if (val) {
9939 dut->ap_conn_capab = atoi(val);
9940 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
9941 dut->ap_conn_capab);
9942 }
9943
9944 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
9945 if (val) {
9946 dut->ap_ip_addr_type_avail = atoi(val);
9947 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
9948 dut->ap_ip_addr_type_avail);
9949 }
9950
9951 val = get_param(cmd, "NET_AUTH_TYPE");
9952 if (val) {
9953 dut->ap_net_auth_type = atoi(val);
9954 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
9955 dut->ap_net_auth_type);
9956 }
9957
9958 val = get_param(cmd, "OP_CLASS");
9959 if (val == NULL)
9960 val = get_param(cmd, "OPER_CLASS");
9961 if (val) {
9962 dut->ap_oper_class = atoi(val);
9963 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
9964 dut->ap_oper_class);
9965 }
9966
9967 val = get_param(cmd, "OSU_PROVIDER_LIST");
9968 if (val) {
9969 dut->ap_osu_provider_list = atoi(val);
9970 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
9971 dut->ap_osu_provider_list);
9972 }
9973
Jouni Malinen93a837f2018-11-01 17:09:22 +02009974 val = get_param(cmd, "OSU_PROVIDER_NAI_LIST");
9975 if (val) {
9976 dut->ap_osu_provider_nai_list = atoi(val);
9977 sigma_dut_print(dut, DUT_MSG_INFO,
9978 "ap_osu_provider_nai_list %d",
9979 dut->ap_osu_provider_nai_list);
9980 }
9981
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009982 val = get_param(cmd, "OSU_SERVER_URI");
9983 if (val) {
9984 i = 0;
9985 do {
9986 int len;
9987 const char *uri = val;
9988 val = strchr(val, ' ');
9989 len = val ? (val++ - uri) : (int) strlen(uri);
9990 if (len > 0 && len < 256) {
9991 memcpy(dut->ap_osu_server_uri[i], uri, len);
9992 dut->ap_osu_server_uri[i][len] = '\0';
9993 sigma_dut_print(dut, DUT_MSG_INFO,
9994 "ap_osu_server_uri[%d] %s", i,
9995 dut->ap_osu_server_uri[i]);
9996 }
9997 } while (val && ++i < 10);
9998 }
9999
10000 val = get_param(cmd, "OSU_METHOD");
10001 if (val) {
10002 i = 0;
10003 do {
10004 int len;
10005 const char *method = val;
10006 val = strchr(val, ' ');
10007 len = val ? (val++ - method) : (int) strlen(method);
10008 if (len > 0) {
10009 if (strncasecmp(method, "SOAP", len) == 0)
10010 dut->ap_osu_method[i] = 1;
10011 else if (strncasecmp(method, "OMADM", len) == 0)
10012 dut->ap_osu_method[i] = 0;
10013 else
10014 return -2;
10015 }
10016 } while (val && ++i < 10);
10017 }
10018
10019 val = get_param(cmd, "OSU_SSID");
10020 if (val) {
10021 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -070010022 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010023 sizeof(dut->ap_osu_ssid));
10024 sigma_dut_print(dut, DUT_MSG_INFO,
10025 "ap_osu_ssid %s",
10026 dut->ap_osu_ssid);
10027 }
10028 }
10029
10030 val = get_param(cmd, "OSU_ICON_TAG");
10031 if (val)
10032 dut->ap_osu_icon_tag = atoi(val);
10033
10034 val = get_param(cmd, "QoS_MAP_SET");
10035 if (val) {
10036 dut->ap_qos_map_set = atoi(val);
10037 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
10038 dut->ap_qos_map_set);
10039 }
10040
10041 val = get_param(cmd, "BSS_LOAD");
10042 if (val) {
10043 dut->ap_bss_load = atoi(val);
10044 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
10045 dut->ap_bss_load);
10046 }
10047
Jouni Malinen54a89b02018-05-01 00:16:26 +030010048 val = get_param(cmd, "Venue_URL");
10049 if (val)
10050 dut->ap_venue_url = atoi(val);
10051
Jouni Malinenf7ff42b2018-05-01 00:21:56 +030010052 val = get_param(cmd, "Advice_of_Charge");
10053 if (val)
10054 dut->ap_advice_of_charge = atoi(val);
10055
Jouni Malinenac104532018-05-01 00:27:37 +030010056 val = get_param(cmd, "Operator_Icon_Metadata");
10057 if (val)
10058 dut->ap_oper_icon_metadata = atoi(val);
10059
Jouni Malinenac367142018-05-01 00:32:24 +030010060 val = get_param(cmd, "TnC_File_Name");
10061 if (val)
10062 dut->ap_tnc_file_name = atoi(val);
10063
10064 val = get_param(cmd, "TnC_File_Time_Stamp");
10065 if (val)
10066 dut->ap_tnc_time_stamp = strtol(val, NULL, 10);
10067
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010068 return 1;
10069}
10070
10071
10072void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
10073{
10074 char buf[100];
10075
10076 if (!file_exists("nfc-status"))
10077 return;
10078
10079 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
10080 run_system(dut, buf);
10081}
10082
10083
10084static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
10085 const char *info)
10086{
10087 int res;
10088
10089 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
10090 printf("%s\n\n", info);
10091
10092 nfc_status(dut, "START", info);
10093 res = run_system(dut, cmd);
10094 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
10095 if (res) {
10096 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
10097 cmd, res);
10098 return res;
10099 }
10100
10101 return 0;
10102}
10103
10104
10105static int ap_nfc_write_config_token(struct sigma_dut *dut,
10106 struct sigma_conn *conn,
10107 struct sigma_cmd *cmd)
10108{
10109 int res;
10110 char buf[300];
10111
10112 run_system(dut, "killall wps-ap-nfc.py");
10113 unlink("nfc-success");
10114 snprintf(buf, sizeof(buf),
10115 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
10116 dut->summary_log ? "--summary " : "",
10117 dut->summary_log ? dut->summary_log : "");
10118 res = run_nfc_command(dut, buf,
10119 "Touch NFC Tag to write WPS configuration token");
10120 if (res || !file_exists("nfc-success")) {
10121 send_resp(dut, conn, SIGMA_ERROR,
10122 "ErrorCode,Failed to write tag");
10123 return 0;
10124 }
10125
10126 return 1;
10127}
10128
10129
10130static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
10131 struct sigma_conn *conn,
10132 struct sigma_cmd *cmd)
10133{
10134 int res;
10135 char buf[300];
10136
10137 run_system(dut, "killall wps-ap-nfc.py");
10138
10139 unlink("nfc-success");
10140 snprintf(buf, sizeof(buf),
10141 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10142 dut->summary_log ? "--summary " : "",
10143 dut->summary_log ? dut->summary_log : "");
10144 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
10145 if (res || !file_exists("nfc-success")) {
10146 send_resp(dut, conn, SIGMA_ERROR,
10147 "ErrorCode,Failed to read tag");
10148 return 0;
10149 }
10150
10151 return 1;
10152}
10153
10154
10155static int ap_nfc_write_password_token(struct sigma_dut *dut,
10156 struct sigma_conn *conn,
10157 struct sigma_cmd *cmd)
10158{
10159 int res;
10160 char buf[300];
10161
10162 run_system(dut, "killall wps-ap-nfc.py");
10163 unlink("nfc-success");
10164 snprintf(buf, sizeof(buf),
10165 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
10166 dut->summary_log ? "--summary " : "",
10167 dut->summary_log ? dut->summary_log : "");
10168 res = run_nfc_command(dut, buf,
10169 "Touch NFC Tag to write WPS password token");
10170 if (res || !file_exists("nfc-success")) {
10171 send_resp(dut, conn, SIGMA_ERROR,
10172 "ErrorCode,Failed to write tag");
10173 return 0;
10174 }
10175
10176 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
10177 send_resp(dut, conn, SIGMA_ERROR,
10178 "ErrorCode,Failed to enable NFC password token");
10179 return 0;
10180 }
10181
10182 return 1;
10183}
10184
10185
10186static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
10187 struct sigma_conn *conn,
10188 struct sigma_cmd *cmd)
10189{
10190 int res;
10191 char buf[300];
10192
10193 run_system(dut, "killall wps-ap-nfc.py");
10194 unlink("nfc-success");
10195 snprintf(buf, sizeof(buf),
10196 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
10197 dut->summary_log ? "--summary " : "",
10198 dut->summary_log ? dut->summary_log : "");
10199 res = run_nfc_command(dut, buf,
10200 "Touch NFC Device to respond to WPS connection handover");
10201 if (res) {
10202 send_resp(dut, conn, SIGMA_ERROR,
10203 "ErrorCode,Failed to enable NFC for connection "
10204 "handover");
10205 return 0;
10206 }
10207 if (!file_exists("nfc-success")) {
10208 send_resp(dut, conn, SIGMA_ERROR,
10209 "ErrorCode,Failed to complete NFC connection handover");
10210 return 0;
10211 }
10212
10213 return 1;
10214}
10215
10216
Jouni Malinenf7222712019-06-13 01:50:21 +030010217static enum sigma_cmd_result cmd_ap_nfc_action(struct sigma_dut *dut,
10218 struct sigma_conn *conn,
10219 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010220{
10221 /* const char *name = get_param(cmd, "Name"); */
10222 /* const char *intf = get_param(cmd, "Interface"); */
10223 const char *oper = get_param(cmd, "Operation");
10224
10225 if (oper == NULL)
10226 return -1;
10227
10228 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
10229 return ap_nfc_write_config_token(dut, conn, cmd);
10230 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
10231 return ap_nfc_write_password_token(dut, conn, cmd);
10232 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
10233 return ap_nfc_wps_read_passwd(dut, conn, cmd);
10234 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
10235 return ap_nfc_wps_connection_handover(dut, conn, cmd);
10236
10237 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
10238 return 0;
10239}
10240
10241
Jouni Malinenf7222712019-06-13 01:50:21 +030010242static enum sigma_cmd_result cmd_ap_wps_read_pin(struct sigma_dut *dut,
10243 struct sigma_conn *conn,
10244 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010245{
10246 char *pin = "12345670"; /* TODO: use random PIN */
10247 char resp[100];
10248
10249 snprintf(resp, sizeof(resp), "PIN,%s", pin);
10250 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10251
10252 return 0;
10253}
10254
10255
Jouni Malinenf7222712019-06-13 01:50:21 +030010256static enum sigma_cmd_result cmd_ap_wps_enter_pin(struct sigma_dut *dut,
10257 struct sigma_conn *conn,
10258 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010259{
10260 const char *pin = get_param(cmd, "PIN");
10261 char wps_pin[11];
10262
10263 if (!pin)
10264 return -1;
10265
10266 sigma_dut_print(dut, DUT_MSG_DEBUG,
10267 "Authorize a client to join with WPS PIN %s", pin);
10268
10269 strlcpy(wps_pin, pin, sizeof(wps_pin));
10270 /* we need to tolerate extra '-' characters entered */
10271 str_remove_chars(wps_pin, '-');
10272 strlcpy(dut->wps_pin, wps_pin, sizeof(dut->wps_pin));
10273 dut->wps_method = WFA_CS_WPS_PIN_KEYPAD;
10274
10275 return 1;
10276}
10277
10278
Jouni Malinenf7222712019-06-13 01:50:21 +030010279static enum sigma_cmd_result cmd_ap_wps_set_pbc(struct sigma_dut *dut,
10280 struct sigma_conn *conn,
10281 struct sigma_cmd *cmd)
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020010282{
10283 sigma_dut_print(dut, DUT_MSG_DEBUG,
10284 "Selecting the push button configuration method");
10285
10286 dut->wps_method = WFA_CS_WPS_PBC;
10287
10288 return 1;
10289}
10290
10291
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020010292int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
10293 struct sigma_cmd *cmd)
10294{
10295 char buf[100], resp[256];
10296 const char *intf = get_param(cmd, "interface");
10297 const char *config_method = get_param(cmd, "WPSConfigMethod");
10298
10299 if (config_method && strcasecmp(config_method, "PBC") == 0)
10300 dut->wps_method = WFA_CS_WPS_PBC;
10301
10302 if (!intf)
10303 intf = get_main_ifname();
10304
10305 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
10306 send_resp(dut, conn, SIGMA_ERROR,
10307 "ErrorCode,WPS parameters not yet set");
10308 return STATUS_SENT;
10309 }
10310
10311 if (dut->wps_method == WFA_CS_WPS_PBC)
10312 snprintf(buf, sizeof(buf), "WPS_PBC");
10313 else /* WFA_CS_WPS_PIN_KEYPAD */
10314 snprintf(buf, sizeof(buf), "WPS_PIN any %s", dut->wps_pin);
10315
10316 /* Run WPS command */
10317 if (hapd_command(intf, buf) < 0) {
10318 /* command fails immediately if overlapped session detected */
10319 snprintf(resp, sizeof(resp), "WpsState,OverlapSession");
10320 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10321 return STATUS_SENT;
10322 }
10323
10324 /* In AP mode return immediately and do not wait for WPS registration */
10325 return SUCCESS_SEND_STATUS;
10326}
10327
10328
Jouni Malinenf7222712019-06-13 01:50:21 +030010329static enum sigma_cmd_result cmd_ap_get_parameter(struct sigma_dut *dut,
10330 struct sigma_conn *conn,
10331 struct sigma_cmd *cmd)
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020010332{
10333 char value[256], resp[512];
10334 const char *param = get_param(cmd, "parameter");
10335 const char *ifname = get_param(cmd, "Interface");
10336
10337 if (!ifname)
10338 ifname = get_main_ifname();
10339
10340 if (!param) {
10341 send_resp(dut, conn, SIGMA_ERROR,
10342 "ErrorCode,Parameter not specified");
10343 return 0;
10344 }
10345
10346 if (strcasecmp(param, "SSID") == 0) {
10347 if (get_hapd_config(ifname, "ssid", value, sizeof(value))) {
10348 sigma_dut_print(dut, DUT_MSG_ERROR,
10349 "Failed to get SSID");
10350 return -2;
10351 }
10352 snprintf(resp, sizeof(resp), "SSID,%s", value);
10353 } else if (strcasecmp(param, "PSK") == 0) {
10354 if (get_hapd_config(ifname, "passphrase", value,
10355 sizeof(value))) {
10356 sigma_dut_print(dut, DUT_MSG_ERROR,
10357 "Failed to get PSK");
10358 return -2;
10359 }
10360 snprintf(resp, sizeof(resp), "PSK,%s", value);
10361 } else {
10362 send_resp(dut, conn, SIGMA_ERROR,
10363 "ErrorCode,Unsupported parameter");
10364 return 0;
10365 }
10366
10367 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10368 return 0;
10369}
10370
10371
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010372static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
10373 const char *val)
10374{
10375 char *token, *result;
10376 int nss = 0, chwidth = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010377 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010378
10379 /*
10380 * The following commands should be invoked to generate
10381 * VHT op mode notification
10382 */
10383
10384 /* Extract the NSS info */
10385 token = strdup(val);
10386 if (!token)
10387 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010388 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010389 if (result) {
10390 int count = atoi(result);
10391
10392 /* We do not support NSS > 3 */
10393 if (count < 0 || count > 3) {
10394 free(token);
10395 return -1;
10396 }
10397
10398 /* Convert nss to chainmask */
10399 while (count--)
10400 nss = (nss << 1) | 1;
10401
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010402 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010403 }
10404
10405 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010406 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010407 if (result) {
10408 switch (atoi(result)) {
10409 case 20:
10410 chwidth = 0;
10411 break;
10412 case 40:
10413 chwidth = 1;
10414 break;
10415 case 80:
10416 chwidth = 2;
10417 break;
10418 case 160:
10419 chwidth = 3;
10420 break;
10421 default:
10422 chwidth = 2;
10423 break;
10424 }
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010425 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010426 }
10427
10428 /* Send the opmode notification */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010429 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010430 free(token);
10431
10432 return 0;
10433}
10434
10435
10436static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
10437 const char *val)
10438{
10439 /* String (nss_operating_mode; mcs_operating_mode) */
10440 int nss, mcs;
10441 char *token, *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010442 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010443
10444 token = strdup(val);
10445 if (!token)
10446 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010447 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010448 if (!result) {
10449 sigma_dut_print(dut, DUT_MSG_ERROR,
10450 "VHT NSS not specified");
10451 goto end;
10452 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010453 if (strcasecmp(result, "def") != 0) {
10454 nss = atoi(result);
10455
10456 if (nss == 4)
10457 ath_disable_txbf(dut, ifname);
10458
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010459 run_iwpriv(dut, ifname, "nss %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010460 } else {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010461 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
10462 run_iwpriv(dut, ifname, "nss 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010463 }
10464
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010465 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010466 if (!result) {
10467 sigma_dut_print(dut, DUT_MSG_ERROR,
10468 "VHT MCS not specified");
10469 goto end;
10470 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010471 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010472 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1)
10473 run_iwpriv(dut, ifname, "vhtmcs 7");
10474 else
10475 run_iwpriv(dut, ifname, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010476 } else {
10477 mcs = atoi(result);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010478 run_iwpriv(dut, ifname, "vhtmcs %d", mcs);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010479 }
10480
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010481end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010482 free(token);
10483 return 0;
10484}
10485
10486
10487static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
10488 const char *val)
10489{
10490 char *token, *result;
10491 int channel = 36;
10492 int chwidth = 80;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010493 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010494
10495 /* Extract the channel info */
10496 token = strdup(val);
10497 if (!token)
10498 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010499 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010500 if (result)
10501 channel = atoi(result);
10502
10503 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010504 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010505 if (result)
10506 chwidth = atoi(result);
10507
10508 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010509 run_iwpriv(dut, ifname, "doth_ch_chwidth %d 10 %d", channel, chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010510
10511 free(token);
10512 return 0;
10513}
10514
10515
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010516static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
10517 const char *val)
10518{
10519 char buf[80];
10520 unsigned char mac_addr[6];
10521
10522 if (parse_mac_address(dut, val, mac_addr) < 0)
10523 return -1;
10524
10525 snprintf(buf, sizeof(buf),
10526 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
10527 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
10528 run_system(dut, buf);
10529
10530 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
10531 ifname, mac_addr[4], mac_addr[5]);
10532 run_system(dut, buf);
10533
10534 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
10535 run_system(dut, buf);
10536
10537 return 0;
10538}
10539
10540
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010541void novap_reset(struct sigma_dut *dut, const char *ifname, int reset)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010542{
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010543 run_iwpriv(dut, ifname, "novap_reset %d", reset);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010544}
10545
10546
Jouni Malinenb4335432019-06-13 02:23:57 +030010547static struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
10548 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010549{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010550 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010551
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010552 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
10553 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
10554 ETH_ALEN) == 0)
10555 return &dut->mbo_pref_aps[i];
10556 }
10557 return NULL;
10558}
10559
10560
10561static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
10562 int ap_ne_class, int ap_ne_op_ch,
10563 int ap_ne_pref)
10564{
10565 struct mbo_pref_ap *entry;
10566 uint8_t self_mac[ETH_ALEN];
10567 char ifname[50];
10568
10569 get_if_name(dut, ifname, sizeof(ifname), 1);
10570 get_hwaddr(ifname, self_mac);
10571
10572 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
10573 entry = &dut->mbo_self_ap_tuple;
10574 else
10575 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
10576
10577 if (!entry) {
10578 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
10579 sigma_dut_print(dut, DUT_MSG_ERROR,
10580 "Nebor AP List is full. Not adding");
10581 return;
10582 }
10583 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
10584 dut->mbo_pref_ap_cnt++;
10585 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
10586 entry->ap_ne_class = -1;
10587 entry->ap_ne_op_ch = -1;
10588 entry->ap_ne_pref = -1;
10589 }
10590 if (ap_ne_class != -1)
10591 entry->ap_ne_class = ap_ne_class;
10592 if (ap_ne_op_ch != -1)
10593 entry->ap_ne_op_ch = ap_ne_op_ch;
10594 if (ap_ne_pref != -1)
10595 entry->ap_ne_pref = ap_ne_pref;
10596}
10597
10598
10599static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
10600 struct sigma_cmd *cmd)
10601{
10602 unsigned char mac_addr[ETH_ALEN];
10603 const char *val;
10604 /*
10605 * -1 is invalid value for the following
10606 * to differentiate between unset and set values
10607 * -1 => implies not set by CAPI
10608 */
10609 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
10610 int list_offset = dut->mbo_pref_ap_cnt;
10611
10612 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
10613 sigma_dut_print(dut, DUT_MSG_ERROR,
10614 "AP Pref Entry list is full");
10615 return -1;
10616 }
10617
10618 val = get_param(cmd, "Nebor_Op_Class");
10619 if (val)
10620 ap_ne_class = atoi(val);
10621
10622 val = get_param(cmd, "Nebor_Op_Ch");
10623 if (val)
10624 ap_ne_op_ch = atoi(val);
10625
10626 val = get_param(cmd, "Nebor_Pref");
10627 if (val)
10628 ap_ne_pref = atoi(val);
10629
10630 val = get_param(cmd, "Nebor_BSSID");
10631 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010632 return -1;
10633
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010634 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
10635 ap_ne_pref);
10636 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010637 return 0;
10638}
10639
10640
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010641static enum sigma_cmd_result he_ltf(struct sigma_dut *dut,
10642 struct sigma_conn *conn,
10643 const char *ifname, const char *val)
10644{
10645 const char *var;
10646
10647 if (dut->ap_he_ulofdma == VALUE_ENABLED)
10648 var = "he_ul_ltf";
10649 else
10650 var = "he_ltf";
10651
10652 if (strcmp(val, "6.4") == 0) {
10653 run_iwpriv(dut, ifname, "%s 2", var);
10654 } else if (strcmp(val, "12.8") == 0) {
10655 run_iwpriv(dut, ifname, "%s 3", var);
10656 } else if (strcmp(val, "3.2") == 0) {
10657 run_iwpriv(dut, ifname, "%s 1", var);
10658 } else {
10659 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported LTF");
10660 return STATUS_SENT_ERROR;
10661 }
10662
10663 return SUCCESS_SEND_STATUS;
10664}
10665
10666
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070010667static enum sigma_cmd_result he_shortgi(struct sigma_dut *dut,
10668 struct sigma_conn *conn,
10669 const char *ifname,
10670 const char *val)
10671{
10672 const char *var;
10673
10674 if (dut->ap_he_ulofdma == VALUE_ENABLED)
10675 var = "he_ul_shortgi";
10676 else
10677 var = "shortgi";
10678
10679 if (strcmp(val, "0.8") == 0) {
10680 run_iwpriv(dut, ifname, "%s 0", var);
10681 } else if (strcmp(val, "1.6") == 0) {
10682 run_iwpriv(dut, ifname, "%s 2", var);
10683 } else if (strcmp(val, "3.2") == 0) {
10684 run_iwpriv(dut, ifname, "%s 3", var);
10685 } else {
10686 send_resp(dut, conn, SIGMA_ERROR,
10687 "errorCode,Unsupported shortGI");
10688 return STATUS_SENT_ERROR;
10689 }
10690
10691 return SUCCESS_SEND_STATUS;
10692}
10693
10694
10695static enum sigma_cmd_result he_ar_gi_ltf_mask(struct sigma_dut *dut,
10696 struct sigma_conn *conn,
10697 const char *ifname,
10698 const char *val)
10699{
10700
10701 uint32_t he_ar_gi_ltf;
10702 uint16_t he_ar_gi, he_ar_ltf;
10703
10704 if (strcmp(val, "0.4") == 0) {
10705 he_ar_gi = 0x01;
10706 } else if (strcmp(val, "0.8") == 0) {
10707 he_ar_gi = 0x02;
10708 } else if (strcmp(val, "1.6") == 0) {
10709 he_ar_gi = 0x04;
10710 } else if (strcmp(val, "3.2") == 0) {
10711 he_ar_gi = 0x08;
10712 } else {
10713 send_resp(dut, conn, SIGMA_ERROR,
10714 "errorCode,Unsupported shortGI");
10715 return STATUS_SENT_ERROR;
10716 }
10717
10718 if (dut->ar_ltf && strcmp(dut->ar_ltf, "6.4") == 0) {
10719 he_ar_ltf = 0x02;
10720 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "12.8") == 0) {
10721 he_ar_ltf = 0x04;
10722 } else if (dut->ar_ltf && strcmp(dut->ar_ltf, "3.2") == 0) {
10723 he_ar_ltf = 0x01;
10724 } else {
10725 send_resp(dut, conn, SIGMA_ERROR,
10726 "errorCode,Unsupported LTF");
10727 return STATUS_SENT_ERROR;
10728 }
10729
10730 he_ar_gi_ltf = (he_ar_gi << 8) | he_ar_ltf;
10731 run_iwpriv(dut, ifname, "he_ar_gi_ltf %lu", he_ar_gi_ltf);
10732
10733 return SUCCESS_SEND_STATUS;
10734}
10735
10736
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070010737static enum sigma_cmd_result he_rualloctones(struct sigma_dut *dut,
10738 struct sigma_conn *conn,
10739 const char *ifname,
10740 const char *val)
10741{
10742 char *token, *result;
10743 int value;
10744 char *saveptr;
10745 int rualloc_type;
10746 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
10747
10748 token = strdup(val);
10749 if (!token)
10750 return -1;
10751 result = strtok_r(token, ":", &saveptr);
10752 if (!result) {
10753 free(token);
10754 send_resp(dut, conn, SIGMA_ERROR,
10755 "errorCode,RUAllocTones not specified");
10756 return STATUS_SENT_ERROR;
10757 }
10758
10759 /*
10760 * ru_allocation_type can take the values of:
10761 * 1 - DL OFDMA data RU allocation
10762 * 3 - UL OFDMA data RU allocation
10763 */
10764 rualloc_type = dut->ap_he_ulofdma == VALUE_ENABLED ? 3 : 1;
10765
10766
10767 value = atoi(result);
10768 if (value == 106) {
10769 enum value_not_set_enabled_disabled ap_he_rualloc_106_80 =
10770 VALUE_NOT_SET;
10771
10772 result = strtok_r(NULL, ":", &saveptr);
10773 if (result) {
10774 result = strtok_r(NULL, ":", &saveptr);
10775 if (result)
10776 ap_he_rualloc_106_80 = VALUE_ENABLED;
10777 else
10778 ap_he_rualloc_106_80 = VALUE_DISABLED;
10779 }
10780 if (ap_he_rualloc_106_80 == VALUE_ENABLED) {
10781 run_system_wrapper(dut,
10782 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 2 1 2 2 2 3 2",
10783 ifname, rualloc_type);
10784 } else {
10785 run_system_wrapper(dut,
10786 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 2 1 2",
10787 ifname, rualloc_type);
10788 }
10789 } else if (value == 242) {
10790 run_system_wrapper(
10791 dut,
10792 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 3 1 3 2 3 3 3",
10793 ifname, rualloc_type);
10794 } else if (value == 26) {
10795 run_system_wrapper(
10796 dut,
10797 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 0 2 0 5 0 7 0",
10798 ifname, rualloc_type);
10799 } else if (value == 52) {
10800 run_system_wrapper(
10801 dut,
10802 "wifitool %s setUnitTestCmd 0x4b 9 %d 0 1 1 1 2 1 3 1",
10803 ifname, rualloc_type);
10804 } else if (value == 484) {
10805 run_system_wrapper(
10806 dut,
10807 "wifitool %s setUnitTestCmd 0x4b 5 %d 0 4 1 4",
10808 ifname, rualloc_type);
10809 } else if (value == 996) {
10810 run_system_wrapper(dut,
10811 "wifitool %s setUnitTestCmd 0x4b 3 %d 0 5",
10812 ifname, rualloc_type);
10813 } else {
10814 send_resp(dut, conn, SIGMA_ERROR,
10815 "errorCode,Unsupported RUAllocTones");
10816 ret = STATUS_SENT_ERROR;
10817 }
10818
10819 free(token);
10820 return ret;
10821}
10822
10823
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070010824static void ath_set_trigger_type_0(struct sigma_dut *dut, const char *ifname)
10825{
10826 /* TriggerType "0" for Basic trigger */
10827 if (dut->ap_channel >= 36) {
10828 /* 1 and 2 here is interpreted to 5g and 2g (bitmasks) */
10829 run_system_wrapper(dut,
10830 "wifitool %s setUnitTestCmd 0x47 2 42 1",
10831 ifname);
10832 } else {
10833 run_system_wrapper(dut,
10834 "wifitool %s setUnitTestCmd 0x47 2 42 2",
10835 ifname);
10836 }
10837 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 6",
10838 ifname);
10839}
10840
10841
10842static void ath_set_trigger_type_1(struct sigma_dut *dut, const char *ifname)
10843{
10844 /* TriggerType "1" for MU BRP */
10845 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 7 1",
10846 ifname);
10847 mubrp_commands(dut, ifname);
10848}
10849
10850
10851static void ath_set_trigger_type_2(struct sigma_dut *dut, const char *ifname)
10852{
10853 /* TriggerType "2" for MU BAR */
10854 if (dut->ap_channel >= 36) {
10855 /* RU allocation RU 242 - DL OFDMA data */
10856 run_system_wrapper(dut,
10857 "wifitool %s setUnitTestCmd 0x4b 5 9 0 3 1 3 2 3 3 3",
10858 ifname);
10859 /* RU allocation RU 52 - UL BA */
10860 run_system_wrapper(dut,
10861 "wifitool %s setUnitTestCmd 0x4b 5 9 0 2 1 2 2 2 3 2",
10862 ifname);
10863 } else {
10864 /* RU allocation RU 52 - DL ofdma data */
10865 run_system_wrapper(dut,
10866 "wifitool %s setUnitTestCmd 0x4b 5 9 0 1 1 1 2 1 3 1",
10867 ifname);
10868 }
10869 /* Force TBPPDU duration to 400 us */
10870 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 400",
10871 ifname);
10872 /* 0 to enable MU BAR, 1 to enable SU BAR */
10873 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 49 0",
10874 ifname);
10875 /* MU BAR */
10876 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 64 0",
10877 ifname);
10878}
10879
10880
10881static void ath_set_trigger_type_3(struct sigma_dut *dut, const char *ifname)
10882{
10883 /* TriggerType "3" for MU RTS */
10884 /* Send MU RTS Trigger - '1' is to enable MU RTS */
10885 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 101 1",
10886 ifname);
10887}
10888
10889
10890static void ath_set_trigger_type_4(struct sigma_dut *dut, const char *ifname,
10891 const char *basedev)
10892{
10893 /* TriggerType "4" for BSRP */
10894 run_system_wrapper(dut, "cfg80211tool %s he_ul_trig_int 200", basedev);
10895 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x48 2 63 1000",
10896 ifname);
10897 if (dut->ap_channel >= 36) {
10898 run_system_wrapper(dut,
10899 "wifitool %s setUnitTestCmd 0x47 2 42 1",
10900 ifname);
10901 } else {
10902 run_system_wrapper(dut,
10903 "wifitool %s setUnitTestCmd 0x47 2 42 2",
10904 ifname);
10905 }
10906 /* Send BSRP command */
10907 run_system_wrapper(dut, "wifitool %s setUnitTestCmd 0x47 2 43 7",
10908 ifname);
10909}
10910
10911
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010912static enum sigma_cmd_result ath_ap_set_rfeature(struct sigma_dut *dut,
10913 struct sigma_conn *conn,
10914 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010915{
10916 const char *val;
10917 char *ifname;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070010918 enum sigma_cmd_result res;
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070010919 const char *basedev = "wifi0";
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070010920 int trigtype;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070010921 int he_ackpolicymac = 0;
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070010922 char *num_ss = NULL;
10923 char *nss[4] = { NULL, NULL, NULL, NULL };
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070010924 char *aid[4] = { NULL, NULL, NULL, NULL };
10925 char *aid_ss = NULL;
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070010926 int omctrl_rxnss = 0, omctrl_chwidth = 0;
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070010927 int param;
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070010928 unsigned char mac_addr[ETH_ALEN];
10929
10930 memset(mac_addr, 0x00, ETH_ALEN);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010931
10932 ifname = get_main_ifname();
10933
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070010934 if (sigma_radio_ifname[0])
10935 basedev = sigma_radio_ifname[0];
10936
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010937 /* Disable vap reset between the commands */
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070010938 novap_reset(dut, ifname, 1);
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -080010939
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010940 val = get_param(cmd, "Opt_md_notif_ie");
10941 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010942 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010943
10944 /* TODO: Optional arguments */
10945
10946 val = get_param(cmd, "nss_mcs_opt");
10947 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010948 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010949
10950 val = get_param(cmd, "chnum_band");
10951 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010952 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010953
10954 val = get_param(cmd, "RTS_FORCE");
10955 if (val)
10956 ath_config_rts_force(dut, ifname, val);
10957
10958 val = get_param(cmd, "DYN_BW_SGNL");
10959 if (val)
10960 ath_config_dyn_bw_sig(dut, ifname, val);
10961
10962 val = get_param(cmd, "CTS_WIDTH");
10963 if (val)
10964 ath_set_cts_width(dut, ifname, val);
10965
10966 val = get_param(cmd, "Ndpa_stainfo_mac");
10967 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010968 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010969
10970 val = get_param(cmd, "txBandwidth");
10971 if (val && ath_set_width(dut, conn, ifname, val) < 0)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030010972 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010973
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010974 val = get_param(cmd, "Assoc_Disallow");
10975 if (val)
10976 ath_set_assoc_disallow(dut, ifname, val);
10977
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010978
Adil Saeed Musthafa69063722017-04-10 23:13:40 -070010979 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010980 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010981 if (val) {
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010982 dut->ap_btmreq_disassoc_imnt = atoi(val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010983 dut->ap_disassoc_timer = 1000;
10984 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -070010985
10986 val = get_param(cmd, "BTMReq_Term_Bit");
10987 if (val)
10988 dut->ap_btmreq_term_bit = atoi(val);
10989
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010990 val = get_param(cmd, "Assoc_Delay");
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010991 if (val) {
10992 dut->ap_assoc_delay = 1;
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070010993 run_iwpriv(dut, ifname, "mbo_asoc_ret %s", val);
priyadharshini gowthaman776562e2017-12-20 12:33:34 -080010994 }
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -070010995
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -070010996 val = get_param(cmd, "Disassoc_Timer");
10997 if (val)
10998 dut->ap_disassoc_timer = atoi(val);
10999
11000 val = get_param(cmd, "BSS_Term_Duration");
11001 if (val)
11002 dut->ap_btmreq_bss_term_dur = atoi(val);
11003
priyadharshini gowthaman94062b52017-12-20 12:33:34 -080011004 val = get_param(cmd, "BSS_Term_TSF");
11005 if (val)
11006 dut->ap_btmreq_bss_term_tsf = atoi(val);
11007
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011008 val = get_param(cmd, "TxPower");
11009 if (val)
11010 ath_set_txpower(dut, ifname, val);
11011
11012 val = get_param(cmd, "DownlinkAvailCap");
11013 if (val)
11014 dut->ap_dl_availcap = atoi(val);
11015
11016 val = get_param(cmd, "UplinkAvailCap");
11017 if (val) {
11018 dut->ap_ul_availcap = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011019 run_iwpriv(dut, ifname, "oce_wan_mtr %d %d",
11020 dut->ap_dl_availcap, dut->ap_ul_availcap);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011021 }
11022
11023 val = get_param(cmd, "RSSIthreshold");
11024 if (val) {
11025 int rssithreshold;
11026
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011027 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011028 rssithreshold = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011029 run_iwpriv(dut, ifname, "oce_asoc_rssi %d", rssithreshold);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011030 }
11031
11032 val = get_param(cmd, "RetryDelay");
11033 if (val) {
11034 int retrydelay;
11035
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011036 run_iwpriv(dut, ifname, "oce_asoc_rej 1");
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011037 retrydelay = atoi(val);
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011038 run_iwpriv(dut, ifname, "oce_asoc_dly %d", retrydelay);
priyadharshini gowthamancb22e432017-12-28 15:23:31 -080011039 }
11040
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011041 val = get_param(cmd, "LTF");
11042 if (val) {
11043 if (dut->ap_fixed_rate) {
11044 res = he_ltf(dut, conn, ifname, val);
11045 if (res != SUCCESS_SEND_STATUS)
11046 return res;
11047 } else {
11048 free(dut->ar_ltf);
11049 dut->ar_ltf = strdup(val);
11050 if (!dut->ar_ltf)
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011051 return ERROR_SEND_STATUS;
Priyadharshini Gowthamanc067edf2019-06-20 11:23:27 -070011052 }
11053 }
11054
Priyadharshini Gowthamancc6ff5a2019-06-20 11:23:52 -070011055 val = get_param(cmd, "GI");
11056 if (val) {
11057 if (dut->ap_fixed_rate)
11058 res = he_shortgi(dut, conn, ifname, val);
11059 else
11060 res = he_ar_gi_ltf_mask(dut, conn, ifname, val);
11061 if (res != SUCCESS_SEND_STATUS)
11062 return res;
11063 }
11064
Priyadharshini Gowthaman9e7d8312019-06-20 11:24:03 -070011065 val = get_param(cmd, "RUAllocTones");
11066 if (val) {
11067 res = he_rualloctones(dut, conn, ifname, val);
11068 if (res != SUCCESS_SEND_STATUS)
11069 return res;
11070 }
11071
Priyadharshini Gowthaman803fd662019-07-31 14:37:49 -070011072 val = get_param(cmd, "MPDU_MU_SpacingFactor");
11073 if (val)
11074 run_system_wrapper(dut,
11075 "wifitool %s setUnitTestCmd 0x48 2 119, %s",
11076 ifname, val);
11077
11078 val = get_param(cmd, "PPDUTxType");
11079 if (val) {
11080 if (strcasecmp(val, "HE-SU") == 0) {
11081 /* Change PPDU format type to HE-SU MCS 1 */
11082 run_system_wrapper(dut,
11083 "wifitool %s setUnitTestCmd 0x48 2 89 0x401",
11084 ifname);
11085 } else if (strcasecmp(val, "legacy") == 0) {
11086 /* Change PPDU format type to non-HT */
11087 run_system_wrapper(dut,
11088 "wifitool %s setUnitTestCmd 0x48 2 89 3",
11089 ifname);
11090 } else {
11091 send_resp(dut, conn, SIGMA_ERROR,
11092 "errorCode,Unsupported PPDUTxType");
11093 return STATUS_SENT_ERROR;
11094 }
11095 }
11096
11097 val = get_param(cmd, "TXOPDuration");
11098 if (val) {
11099 if (strcasecmp(val, "UNSPECIFIED") == 0) {
11100 /* The hardware is hardcoded with 0x7f; do nothing */
11101 } else {
11102 send_resp(dut, conn, SIGMA_ERROR,
11103 "errorCode,Unsupported TXOPDuration");
11104 return STATUS_SENT_ERROR;
11105 }
11106 }
11107
Priyadharshini Gowthamanf8c032d2019-07-31 14:38:02 -070011108 val = get_param(cmd, "Trig_Usrinfo_UL-MCS");
11109 if (val)
11110 run_iwpriv(dut, ifname, "he_ul_mcs %d", atoi(val));
11111
11112 val = get_param(cmd, "Trig_Usrinfo_UL-Target-RSSI");
11113 if (val) {
11114 /* Set target RSSI to -55 dBm */
11115 run_system_wrapper(dut,
11116 "wifitool %s setUnitTestCmd 0x4b 2 7 %d",
11117 ifname, atoi(val) - 110);
11118 }
11119
11120 val = get_param(cmd, "Trig_Interval");
11121 if (val)
11122 run_iwpriv(dut, basedev, "he_ul_trig_int %d", atoi(val));
11123
11124 val = get_param(cmd, "Trig_ComInfo_ULLength");
11125 if (val)
11126 run_system_wrapper(dut,
11127 "wifitool %s setUnitTestCmd 0x48 2 141 %d",
11128 ifname, atoi(val));
11129
Priyadharshini Gowthaman2f8c3172019-07-31 14:38:12 -070011130 val = get_param(cmd, "DisableTriggerType");
11131 if (val) {
11132 trigtype = atoi(val);
11133 switch (trigtype) {
11134 case 0:
11135 /* DisableTriggerType "0" for basic trigger */
11136 run_system_wrapper(dut,
11137 "wifitool %s setUnitTestCmd 0x47 2 42 0",
11138 ifname);
11139 break;
11140 default:
11141 /* Nothing to be done for now */
11142 break;
11143 }
11144 }
11145
11146 val = get_param(cmd, "Trigger_TxBF");
11147 if (val) {
11148 if (strcasecmp(val, "enable") == 0) {
11149 run_iwpriv(dut, ifname, "he_sounding_mode 0x9");
11150 } else if (strcasecmp(val, "disable") == 0) {
11151 run_iwpriv(dut, ifname, "he_sounding_mode 0x1");
11152 } else {
11153 send_resp(dut, conn, SIGMA_ERROR,
11154 "errorCode,Unsupported trigger_txbf");
11155 return STATUS_SENT_ERROR;
11156 }
11157 }
11158
Priyadharshini Gowthaman7b94f082019-07-31 14:38:25 -070011159 val = get_param(cmd, "Trig_UsrInfo_RUAlloc");
11160 if (val) {
11161 res = he_rualloctones(dut, conn, ifname, val);
11162 if (res != SUCCESS_SEND_STATUS)
11163 return res;
11164 }
11165
Priyadharshini Gowthaman8701fac2019-07-31 14:38:48 -070011166 val = get_param(cmd, "TriggerCoding");
11167 if (val) {
11168 if (strcasecmp(val, "BCC") == 0) {
11169 /* In case of LDPC enable this command can force BCC if
11170 * RU size <= 242 */
11171 run_iwpriv(dut, ifname, "he_ul_ldpc 0");
11172 } else if (strcasecmp(val, "LDPC") == 0) {
11173 novap_reset(dut, ifname, 0);
11174 run_iwpriv(dut, ifname, "he_ul_ldpc 1");
11175 novap_reset(dut, ifname, 1);
11176 } else {
11177 send_resp(dut, conn, SIGMA_ERROR,
11178 "errorCode,Unsupported TriggerCoding");
11179 return STATUS_SENT_ERROR;
11180 }
11181 }
11182
Priyadharshini Gowthaman51c0fec2019-08-09 12:04:05 -070011183 val = get_param(cmd, "AckPolicy_MAC");
11184 if (val) {
11185 if (parse_mac_address(dut, val, mac_addr) < 0) {
11186 send_resp(dut, conn, SIGMA_ERROR,
11187 "errorCode,MAC Address not in proper format");
11188 return STATUS_SENT_ERROR;
11189 }
11190 he_ackpolicymac = 1;
11191 }
11192
11193 val = get_param(cmd, "AckPolicy");
11194 if (val) {
11195 int ap_he_ackpolicy;
11196
11197 ap_he_ackpolicy = atoi(val);
11198 if (ap_he_ackpolicy == 0 && he_ackpolicymac) {
11199 /* Disable all-BAR ackpolicy for MU-MIMO */
11200 run_system_wrapper(dut,
11201 "wifitool %s setUnitTestCmd 0x48 2 62 0",
11202 ifname);
11203 /* Disable all-BAR ackpolicy first */
11204 run_system_wrapper(dut,
11205 "wifitool %s setUnitTestCmd 0x48 2 64 0",
11206 ifname);
11207 /* Set normal ack policy for the STA with the specified
11208 * MAC address in DL-TX case */
11209 run_system_wrapper(dut,
11210 "wifitool %s setUnitTestCmd 0x4b 8 8 1 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
11211 ifname, mac_addr[0], mac_addr[1],
11212 mac_addr[2], mac_addr[3],
11213 mac_addr[4], mac_addr[5]);
11214 } else if (ap_he_ackpolicy == 3) {
11215 /* Enable all-BAR ackpolicy for MU-MIMO DL */
11216 run_system_wrapper(dut,
11217 "wifitool %s setUnitTestCmd 0x48 2 62 1",
11218 ifname);
11219 /* Enable all-BAR ackpolicy */
11220 run_system_wrapper(dut,
11221 "wifitool %s setUnitTestCmd 0x48 2 64 1",
11222 ifname);
11223 } else if (ap_he_ackpolicy == 4) {
11224 /* Enable htp-ack ackpolicy */
11225 run_system_wrapper(dut,
11226 "wifitool %s setUnitTestCmd 0x47 2 99 1",
11227 ifname);
11228 } else {
11229 send_resp(dut, conn, SIGMA_ERROR,
11230 "errorCode,Invalid AckPolicy setting");
11231 return STATUS_SENT_ERROR;
11232 }
11233 }
11234
Priyadharshini Gowthamanc9a88c72019-08-09 12:04:17 -070011235 val = get_param(cmd, "Trig_ComInfo_GI-LTF");
11236 if (val) {
11237 int trig_gi_ltf;
11238
11239 trig_gi_ltf = atoi(val);
11240 if (trig_gi_ltf == 0) {
11241 he_ltf(dut, conn, ifname, "3.2");
11242 he_shortgi(dut, conn, ifname, "1.6");
11243 } else if (trig_gi_ltf == 1) {
11244 he_ltf(dut, conn, ifname, "6.4");
11245 he_shortgi(dut, conn, ifname, "1.6");
11246 } else if (trig_gi_ltf == 2) {
11247 he_ltf(dut, conn, ifname, "12.8");
11248 he_shortgi(dut, conn, ifname, "3.2");
11249 } else {
11250 send_resp(dut, conn, SIGMA_ERROR,
11251 "errorCode,Unsupported Trig_ComInfo_GI-LTF");
11252 return STATUS_SENT_ERROR;
11253 }
11254 }
11255
11256 val = get_param(cmd, "Trig_ComInfo_BW");
11257 if (val) {
11258 int chwidth;
11259
11260 chwidth = atoi(val);
11261 /* Set the channel width */
11262 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
11263 }
11264
Priyadharshini Gowthamane87e2c92019-08-09 12:04:31 -070011265 val = get_param(cmd, "NumSS");
11266 if (val) {
11267 int i = 0;
11268 char *numss_val;
11269 char *saveptr;
11270
11271 num_ss = strdup(val);
11272 if (!num_ss)
11273 return ERROR_SEND_STATUS;
11274
11275 numss_val = strtok_r(num_ss, " ", &saveptr);
11276 for (i = 0; numss_val && i < 4; i++) {
11277 nss[i] = numss_val;
11278 numss_val = strtok_r(NULL, " ", &saveptr);
11279 }
11280 }
11281
11282 val = get_param(cmd, "NumSS_MAC");
11283 if (val) {
11284 char *sta_mac_str;
11285 char *saveptr;
11286 char *sta_mac_list_str;
11287
11288 sta_mac_list_str = strdup(val);
11289 if (!sta_mac_list_str) {
11290 free(num_ss);
11291 return ERROR_SEND_STATUS;
11292 }
11293
11294 sta_mac_str = strtok_r(sta_mac_list_str, " ", &saveptr);
11295 if (sta_mac_str && nss[0]) {
11296 run_system_wrapper(dut,
11297 "wifitool %s chmask_persta %s %s",
11298 ifname, sta_mac_str, nss[0]);
11299 }
11300
11301 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11302 if (sta_mac_str && nss[1]) {
11303 run_system_wrapper(dut,
11304 "wifitool %s chmask_persta %s %s",
11305 ifname, sta_mac_str, nss[1]);
11306 }
11307
11308 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11309 if (sta_mac_str && nss[2]) {
11310 run_system_wrapper(dut,
11311 "wifitool %s chmask_persta %s %s",
11312 ifname, sta_mac_str, nss[2]);
11313 }
11314
11315 sta_mac_str = strtok_r(NULL, " ", &saveptr);
11316 if (sta_mac_str && nss[3]) {
11317 run_system_wrapper(dut,
11318 "wifitool %s chmask_persta %s %s",
11319 ifname, sta_mac_str, nss[3]);
11320 }
11321
11322 free(sta_mac_list_str);
11323 }
11324
11325 free(num_ss);
11326 num_ss = NULL;
11327
Priyadharshini Gowthamandca0c542019-08-09 12:04:42 -070011328 val = get_param(cmd, "AID");
11329 if (val) {
11330 int i = 0;
11331 char *aid_val;
11332 char *saveptr;
11333
11334 aid_ss = strdup(val);
11335 if (!aid_ss)
11336 return ERROR_SEND_STATUS;
11337
11338 aid_val = strtok_r(aid_ss, " ", &saveptr);
11339 for (i = 0; aid_val && i < 4; i++) {
11340 aid[i] = aid_val;
11341 aid_val = strtok_r(NULL, " ", &saveptr);
11342 }
11343 }
11344
11345 val = get_param(cmd, "AddbaReq");
11346 if (val) {
11347 if (strcasecmp(val, "enable") == 0) {
11348 run_iwpriv(dut, ifname, "setaddbaoper 1");
11349 run_system_wrapper(dut,
11350 "wifitool %s sendaddba %s 0 64",
11351 ifname, aid[0]);
11352 } else {
11353 send_resp(dut, conn, SIGMA_ERROR,
11354 "errorCode,Unsupported AddbaReq value");
11355 free(aid_ss);
11356 return STATUS_SENT_ERROR;
11357 }
11358 }
11359
11360 val = get_param(cmd, "AddbaResp");
11361 if (val) {
11362 if (aid_ss && strcasecmp(val, "accepted") == 0) {
11363 int aid_1 = atoi(aid_ss);
11364
11365 if (aid_1 == 1)
11366 aid_1 = 2;
11367 else
11368 aid_1 = aid_1 - 1;
11369
11370 /* There is no mechanism in place to reject Add BA Req
11371 * from all STAs and selectively accept Add BA Req from
11372 * a specified STA. Instead, it can accept Add BA Req
11373 * from all STAs and selectively reject from specified
11374 * STAs. Make changes for the same using the below
11375 * commands. */
11376 run_system_wrapper(dut, ifname, "setaddbaoper 1");
11377 run_system_wrapper(dut, "wifitool %s refusealladdbas 0",
11378 ifname);
11379 run_system_wrapper(dut,
11380 "wifitool %s setaddbaresp %d 0 37",
11381 ifname, aid_1);
11382 } else {
11383 send_resp(dut, conn, SIGMA_ERROR,
11384 "errorCode,Unsupported Addbaresp value");
11385 free(aid_ss);
11386 return STATUS_SENT_ERROR;
11387 }
11388 }
11389
11390 val = get_param(cmd, "Trig_UsrInfo_SSAlloc_RA-RU");
11391 if (val) {
11392 char *ssalloc_str;
11393 char *saveptr;
11394 char *ssalloc_list_str;
11395
11396 ssalloc_list_str = strdup(val);
11397 if (!ssalloc_list_str) {
11398 free(aid_ss);
11399 return ERROR_SEND_STATUS;
11400 }
11401
11402 ssalloc_str = strtok_r(ssalloc_list_str, ":", &saveptr);
11403 if (ssalloc_str && aid[0]) {
11404 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
11405 ifname, aid[0], ssalloc_str);
11406 }
11407
11408 ssalloc_str = strtok_r(NULL, " ", &saveptr);
11409 if (ssalloc_str && aid[1]) {
11410 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
11411 ifname, aid[1], ssalloc_str);
11412 }
11413
11414 ssalloc_str = strtok_r(NULL, " ", &saveptr);
11415 if (ssalloc_str && aid[2]) {
11416 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
11417 ifname, aid[2], ssalloc_str);
11418 }
11419
11420 ssalloc_str = strtok_r(NULL, " ", &saveptr);
11421 if (ssalloc_str && aid[3]) {
11422 run_system_wrapper(dut, "wifitool %s peer_nss %s %s",
11423 ifname, aid[3], ssalloc_str);
11424 }
11425
11426 free(ssalloc_list_str);
11427 }
11428
11429 free(aid_ss);
11430 aid_ss = NULL;
11431
Priyadharshini Gowthaman2da1ecc2019-08-09 12:04:54 -070011432 val = get_param(cmd, "OMCtrl_RxNSS");
11433 if (val)
11434 omctrl_rxnss = atoi(val);
11435
11436 val = get_param(cmd, "OMCtrl_ChnlWidth");
11437 if (val)
11438 omctrl_chwidth = atoi(val);
11439
11440 val = get_param(cmd, "Client_mac");
11441 if (val) {
11442 if (parse_mac_address(dut, val, mac_addr) < 0) {
11443 send_resp(dut, conn, SIGMA_ERROR,
11444 "errorCode,MAC Address not in proper format");
11445 return STATUS_SENT_ERROR;
11446 }
11447
11448 /* setUnitTestCmd 13 7 1 mac3mac2mac1mac0 mac5mac4 <rx_nss>
11449 * <bw> <ulmu> <tx_nss> */
11450 run_system_wrapper(dut,
11451 "wifitool %s setUnitTestCmd 13 7 1 0x%02x%02x%02x%02x 0x%02x%02x %d %d 1 %d",
11452 ifname, mac_addr[3], mac_addr[2],
11453 mac_addr[1], mac_addr[0], mac_addr[5],
11454 mac_addr[4], omctrl_rxnss,
11455 omctrl_chwidth, omctrl_rxnss);
11456 }
11457
Priyadharshini Gowthaman7e438702019-08-09 12:05:05 -070011458 val = get_param(cmd, "TriggerType");
11459 if (val) {
11460 trigtype = atoi(val);
11461 switch (trigtype) {
11462 case 0:
11463 ath_set_trigger_type_0(dut, ifname);
11464 break;
11465 case 1:
11466 ath_set_trigger_type_1(dut, ifname);
11467 break;
11468 case 2:
11469 ath_set_trigger_type_2(dut, ifname);
11470 break;
11471 case 3:
11472 ath_set_trigger_type_3(dut, ifname);
11473 break;
11474 case 4:
11475 ath_set_trigger_type_4(dut, ifname, basedev);
11476 break;
11477 default:
11478 send_resp(dut, conn, SIGMA_ERROR,
11479 "errorCode,TriggerType not supported");
11480 return STATUS_SENT_ERROR;
11481 }
11482 }
11483
Priyadharshini Gowthamanc352d822019-08-09 12:05:16 -070011484 val = get_param(cmd, "HE_TXOPDurRTSThr");
11485 if (val)
11486 run_iwpriv(dut, ifname, "he_rtsthrshld %d", atoi(val));
11487
11488 val = get_param(cmd, "NAV_Update");
11489 if (val) {
11490 if (strcasecmp(val, "disable") == 0) {
11491 run_iwpriv(dut, basedev, "nav_config 1 0");
11492 } else if (strcasecmp(val, "enable") == 0) {
11493 /* Do nothing */
11494 } else {
11495 send_resp(dut, conn, SIGMA_ERROR,
11496 "errorCode,Unsupported NAV update");
11497 return STATUS_SENT_ERROR;
11498 }
11499 }
11500
Priyadharshini Gowthaman872fb292019-08-09 12:05:27 -070011501 /* Configure WMM Parameter Elements */
11502 val = get_param(cmd, "STA_WMMPE_ECWmin_BE");
11503 if (val) {
11504 param = atoi(val);
11505 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BE, param);
11506 }
11507
11508 val = get_param(cmd, "STA_WMMPE_ECWmin_BK");
11509 if (val) {
11510 param = atoi(val);
11511 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_BK, param);
11512 }
11513
11514 val = get_param(cmd, "STA_WMMPE_ECWmin_VI");
11515 if (val) {
11516 param = atoi(val);
11517 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VI, param);
11518 }
11519
11520 val = get_param(cmd, "STA_WMMPE_ECWmin_VO");
11521 if (val) {
11522 param = atoi(val);
11523 run_iwpriv(dut, ifname, "cwmin %d 1 %d", AP_AC_VO, param);
11524 }
11525
11526 val = get_param(cmd, "STA_WMMPE_ECWmax_BE");
11527 if (val) {
11528 param = atoi(val);
11529 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BE, param);
11530 }
11531
11532 val = get_param(cmd, "STA_WMMPE_ECWmax_BK");
11533 if (val) {
11534 param = atoi(val);
11535 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_BK, param);
11536 }
11537
11538 val = get_param(cmd, "STA_WMMPE_ECWmax_VI");
11539 if (val) {
11540 param = atoi(val);
11541 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VI, param);
11542 }
11543
11544 val = get_param(cmd, "STA_WMMPE_ECWmax_VO");
11545 if (val) {
11546 param = atoi(val);
11547 run_iwpriv(dut, ifname, "cwmax %d 1 %d", AP_AC_VO, param);
11548 }
11549
11550 val = get_param(cmd, "STA_WMMPE_AIFSN_BE");
11551 if (val) {
11552 param = atoi(val);
11553 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BE, param);
11554 }
11555
11556 val = get_param(cmd, "STA_WMMPE_AIFSN_BK");
11557 if (val) {
11558 param = atoi(val);
11559 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_BK, param);
11560 }
11561
11562 val = get_param(cmd, "STA_WMMPE_AIFSN_VI");
11563 if (val) {
11564 param = atoi(val);
11565 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VI, param);
11566 }
11567
11568 val = get_param(cmd, "STA_WMMPE_AIFSN_VO");
11569 if (val) {
11570 param = atoi(val);
11571 run_iwpriv(dut, ifname, "aifs %d 1 %d", AP_AC_VO, param);
11572 }
11573
11574
11575 val = get_param(cmd, "STA_WMMPE_TXOP_BE");
11576 if (val) {
11577 param = atoi(val);
11578 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BE, param);
11579 }
11580
11581 val = get_param(cmd, "STA_WMMPE_TOXP_BK");
11582 if (val) {
11583 param = atoi(val);
11584 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_BK, param);
11585 }
11586
11587 val = get_param(cmd, "STA_WMMPE_TXOP_VI");
11588 if (val) {
11589 param = atoi(val);
11590 run_iwpriv(dut, ifname, "txoplimit %d %d", AP_AC_VI, param);
11591 }
11592
11593 val = get_param(cmd, "STA_WMMPE_TXOP_VO");
11594 if (val) {
11595 param = atoi(val);
11596 run_iwpriv(dut, ifname, "txoplimit %d 1 %d", AP_AC_VO, param);
11597 }
11598
Priyadharshini Gowthamanc46b7e42019-08-09 12:05:37 -070011599 /* Configure MU EDCA */
11600 val = get_param(cmd, "STA_MUEDCA_ECWmin_BE");
11601 if (val) {
11602 param = atoi(val);
11603 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BE, param);
11604 }
11605
11606 val = get_param(cmd, "STA_MUEDCA_ECWmin_BK");
11607 if (val) {
11608 param = atoi(val);
11609 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_BK, param);
11610 }
11611
11612 val = get_param(cmd, "STA_MUEDCA_ECWmin_VI");
11613 if (val) {
11614 param = atoi(val);
11615 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VI, param);
11616 }
11617
11618 val = get_param(cmd, "STA_MUEDCA_ECWmin_VO");
11619 if (val) {
11620 param = atoi(val);
11621 run_iwpriv(dut, ifname, "muedca_ecwmin %d %d", AP_AC_VO, param);
11622 }
11623
11624 val = get_param(cmd, "STA_MUEDCA_ECWmax_BE");
11625 if (val) {
11626 param = atoi(val);
11627 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BE, param);
11628 }
11629
11630 val = get_param(cmd, "STA_MUEDCA_ECWmax_BK");
11631 if (val) {
11632 param = atoi(val);
11633 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_BK, param);
11634 }
11635
11636 val = get_param(cmd, "STA_MUEDCA_ECWmax_VI");
11637 if (val) {
11638 param = atoi(val);
11639 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VI, param);
11640 }
11641
11642 val = get_param(cmd, "STA_MUEDCA_ECWmax_VO");
11643 if (val) {
11644 param = atoi(val);
11645 run_iwpriv(dut, ifname, "muedca_ecwmax %d %d", AP_AC_VO, param);
11646 }
11647
11648 val = get_param(cmd, "STA_MUEDCA_AIFSN_BE");
11649 if (val) {
11650 param = atoi(val);
11651 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BE, param);
11652 }
11653
11654 val = get_param(cmd, "STA_MUEDCA_AIFSN_BK");
11655 if (val) {
11656 param = atoi(val);
11657 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_BK, param);
11658 }
11659
11660 val = get_param(cmd, "STA_MUEDCA_AIFSN_VI");
11661 if (val) {
11662 param = atoi(val);
11663 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VI, param);
11664 }
11665
11666 val = get_param(cmd, "STA_MUEDCA_AIFSN_VO");
11667 if (val) {
11668 param = atoi(val);
11669 run_iwpriv(dut, ifname, "muedca_aifsn %d %d", AP_AC_VO, param);
11670 }
11671
11672 val = get_param(cmd, "STA_MUEDCA_Timer_BE");
11673 if (val) {
11674 param = atoi(val);
11675 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BE, param);
11676 }
11677
11678 val = get_param(cmd, "STA_MUEDCA_Timer_BK");
11679 if (val) {
11680 param = atoi(val);
11681 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_BK, param);
11682 }
11683
11684 val = get_param(cmd, "STA_MUEDCA_Timer_VI");
11685 if (val) {
11686 param = atoi(val);
11687 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VI, param);
11688 }
11689
11690 val = get_param(cmd, "STA_MUEDCA_Timer_VO");
11691 if (val) {
11692 param = atoi(val);
11693 run_iwpriv(dut, ifname, "muedca_timer %d %d", AP_AC_VO, param);
11694 }
11695
Jouni Malinen6076ffc2019-08-08 18:18:02 +030011696 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011697}
11698
11699
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011700static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
11701 const char *val)
11702{
11703 char *token, *result;
11704 int channel = 36;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011705 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011706
11707 /* Extract the channel info */
11708 token = strdup(val);
11709 if (!token)
11710 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011711 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011712 if (result)
11713 channel = atoi(result);
11714
11715 /* Issue the channel switch command */
Priyadharshini Gowthamand06f1002019-04-22 15:45:41 -070011716 run_iwpriv(dut, ifname, "setChanChange %d", channel);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011717
11718 free(token);
11719 return 0;
11720}
11721
11722
11723static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
11724 struct sigma_cmd *cmd)
11725{
11726 const char *val;
11727 char *ifname;
11728
11729 ifname = get_main_ifname();
11730
11731 val = get_param(cmd, "chnum_band");
11732 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
11733 return -1;
11734
11735 return 1;
11736}
11737
11738
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053011739static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
11740 const char *val)
11741{
11742 char *token, *result;
11743 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
11744 channel_freq;
11745 char buf[100];
11746 char *saveptr;
Jouni Malinen3aa72862019-05-29 23:14:51 +030011747 int res;
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053011748
11749 /* Extract the channel info */
11750 token = strdup(val);
11751 if (!token)
11752 return -1;
11753 result = strtok_r(token, ";", &saveptr);
11754 if (result)
11755 channel = atoi(result);
11756
11757 /* Extract the channel width info */
11758 result = strtok_r(NULL, ";", &saveptr);
11759 if (result)
11760 chwidth = atoi(result);
11761
11762 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
11763 if (center_freq_idx < 0) {
11764 free(token);
11765 return -1;
11766 }
11767
11768 center_freq = get_5g_channel_freq(center_freq_idx);
11769 channel_freq = get_5g_channel_freq(channel);
11770
11771 /* Issue the channel switch command */
Jouni Malinen3aa72862019-05-29 23:14:51 +030011772 res = snprintf(buf, sizeof(buf),
11773 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
11774 ifname, channel_freq, center_freq, chwidth);
11775 if (res < 0 || res >= sizeof(buf) || run_hostapd_cli(dut, buf) != 0) {
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053011776 sigma_dut_print(dut, DUT_MSG_ERROR,
11777 "hostapd_cli chan_switch failed");
11778 }
11779
11780 free(token);
11781 return 0;
11782}
11783
11784
11785static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
11786 struct sigma_conn *conn,
11787 struct sigma_cmd *cmd)
11788{
11789 const char *val;
11790 char *ifname;
11791
11792 ifname = get_main_ifname();
11793 val = get_param(cmd, "chnum_band");
11794 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
11795 return -1;
11796
11797 return 1;
11798}
11799
11800
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011801#ifdef __linux__
11802static int wil6210_ap_set_rfeature(struct sigma_dut *dut,
11803 struct sigma_conn *conn,
11804 struct sigma_cmd *cmd)
11805{
11806 const char *val;
11807
11808 val = get_param(cmd, "ExtSchIE");
11809 if (val && !strcasecmp(val, "Enable")) {
11810 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11811 int count = MAX_ESE_ALLOCS;
11812
11813 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11814 return -1;
11815 if (wil6210_set_ese(dut, count, allocs))
11816 return -1;
11817 return 1;
11818 }
11819
11820 send_resp(dut, conn, SIGMA_ERROR,
11821 "errorCode,Invalid ap_set_rfeature(60G)");
11822 return 0;
11823}
11824#endif /* __linux__ */
11825
11826
Jouni Malinenf7222712019-06-13 01:50:21 +030011827static enum sigma_cmd_result cmd_ap_set_rfeature(struct sigma_dut *dut,
11828 struct sigma_conn *conn,
11829 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011830{
11831 /* const char *name = get_param(cmd, "NAME"); */
11832 /* const char *type = get_param(cmd, "Type"); */
11833
11834 switch (get_driver_type()) {
11835 case DRIVER_ATHEROS:
11836 return ath_ap_set_rfeature(dut, conn, cmd);
11837 case DRIVER_OPENWRT:
11838 switch (get_openwrt_driver_type()) {
11839 case OPENWRT_DRIVER_ATHEROS:
11840 return ath_ap_set_rfeature(dut, conn, cmd);
11841 default:
11842 send_resp(dut, conn, SIGMA_ERROR,
11843 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
11844 return 0;
11845 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +053011846 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +053011847 case DRIVER_WCN:
11848 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +053011849 case DRIVER_MAC80211:
11850 return mac80211_ap_set_rfeature(dut, conn, cmd);
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011851#ifdef __linux__
11852 case DRIVER_WIL6210:
11853 return wil6210_ap_set_rfeature(dut, conn, cmd);
11854#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011855 default:
11856 send_resp(dut, conn, SIGMA_ERROR,
11857 "errorCode,Unsupported ap_set_rfeature with the current driver");
11858 return 0;
11859 }
11860}
11861
11862
Jouni Malinenf7222712019-06-13 01:50:21 +030011863static enum sigma_cmd_result cmd_accesspoint(struct sigma_dut *dut,
11864 struct sigma_conn *conn,
11865 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011866{
11867 /* const char *name = get_param(cmd, "NAME"); */
11868 return 1;
11869}
11870
11871
Jouni Malinenf7222712019-06-13 01:50:21 +030011872static enum sigma_cmd_result
11873cmd_ap_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
11874 struct sigma_cmd *cmd)
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080011875{
11876 const char *val;
11877
11878 val = get_param(cmd, "Oper_Chn");
11879 if (val) {
11880 dut->ap_oper_chn = 1;
11881 dut->ap_channel = atoi(val);
11882 }
11883
11884 return 1;
11885}
11886
11887
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011888void ap_register_cmds(void)
11889{
11890 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
11891 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
11892 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
11893 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
11894 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
11895 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +053011896 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011897 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
11898 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
11899 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
11900 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
11901 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
11902 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
11903 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
11904 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
11905 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
11906 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
11907 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
11908 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
11909 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
11910 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
11911 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
11912 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
Alexei Avshalom Lazar64279692018-12-23 16:49:49 +020011913 sigma_dut_reg_cmd("ap_wps_enter_pin", NULL, cmd_ap_wps_enter_pin);
11914 sigma_dut_reg_cmd("ap_wps_set_pbc", NULL, cmd_ap_wps_set_pbc);
Alexei Avshalom Lazar0c1d82d2018-12-23 17:02:42 +020011915 sigma_dut_reg_cmd("ap_get_parameter", NULL, cmd_ap_get_parameter);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011916 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
priyadharshini gowthaman9149afc2018-01-15 13:40:18 -080011917 sigma_dut_reg_cmd("ap_preset_testparameters", NULL,
11918 cmd_ap_preset_testparameters);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011919}