blob: 3d4b3e18ebbaacb01305e93fa53f66e4d8b65ef8 [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.
4 * Copyright (c) 2011-2015, Qualcomm Atheros, Inc.
5 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
10#include <sys/stat.h>
11#include <sys/wait.h>
12#include <sys/utsname.h>
13#include <sys/ioctl.h>
14#ifdef __linux__
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -070015#include <limits.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020016#include <dirent.h>
17#include <string.h>
18#include <sys/types.h>
19#include <unistd.h>
20#endif /* __linux__ */
21#ifdef __QNXNTO__
22#include <ifaddrs.h>
23#include <net/if_dl.h>
24#endif /* __QNXNTO__ */
25#include "wpa_helpers.h"
26#ifdef ANDROID
27#include <hardware_legacy/wifi.h>
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +053028#include <private/android_filesystem_config.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020029#endif /* ANDROID */
30
31/* Temporary files for ap_send_addba_req */
32#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
33#define VI_QOS_FILE "/tmp/vi-qos.txt"
34#define VI_QOS_REFFILE "/etc/vi-qos.txt"
35
36/* Configuration file name on Android */
37#ifndef ANDROID_CONFIG_FILE
38#define ANDROID_CONFIG_FILE "/data/misc/wifi/hostapd.conf"
39#endif /* ANDROID_CONFIG_FILE */
40/* Maximum length of the line in the configuration file */
41#define MAX_CONF_LINE_LEN (156)
42
Jouni Malinend6bf1b42017-06-23 17:51:01 +030043#ifndef SIGMA_DUT_HOSTAPD_PID_FILE
44#define SIGMA_DUT_HOSTAPD_PID_FILE "/tmp/sigma_dut-ap-hostapd.pid"
45#endif /* SIGMA_DUT_HOSTAPD_PID_FILE */
46
Jouni Malinencd4e3c32015-10-29 12:39:56 +020047/* The following is taken from Hotspot 2.0 testplan Appendix B.1 */
48#define ANQP_VENUE_NAME_1 "02019c0002083d656e6757692d466920416c6c69616e63650a3239383920436f7070657220526f61640a53616e746120436c6172612c2043412039353035312c205553415b63686957692d4669e88194e79b9fe5ae9ee9aa8ce5aea40ae4ba8ce4b99de585abe4b99de5b9b4e5ba93e69f8fe8b7af0ae59ca3e5858be68b89e68b892c20e58aa0e588a9e7a68fe5b0bce4ba9a39353035312c20e7be8ee59bbd"
49#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\""
50#define ANQP_IP_ADDR_TYPE_1 "060101000c"
51#define ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "dddd2700506f9a11030011656e6757692d466920416c6c69616e63650e63686957692d4669e88194e79b9f"
52#define ANQP_HS20_WAN_METRICS_1 "dddd1300506f9a11040001c40900008001000000000000"
53#define ANQP_HS20_CONNECTION_CAPABILITY_1 "dddd3200506f9a1105000100000006140001061600000650000106bb010106bb060006c4130011f4010111c413001194110132000001"
54#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"
55#define QOS_MAP_SET_2 "8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,63"
56
57extern char *sigma_main_ifname;
58extern char *sigma_wpas_ctrl;
59extern char *sigma_hapd_ctrl;
60extern char *ap_inet_addr;
61extern char *ap_inet_mask;
62extern char *sigma_radio_ifname[];
63
Jouni Malinencd4e3c32015-10-29 12:39:56 +020064static int ath_ap_start_hostapd(struct sigma_dut *dut);
65static void ath_ap_set_params(struct sigma_dut *dut);
66static int kill_process(struct sigma_dut *dut, char *proc_name,
67 unsigned char is_proc_instance_one, int sig);
68
69
70static int cmd_ap_ca_version(struct sigma_dut *dut, struct sigma_conn *conn,
71 struct sigma_cmd *cmd)
72{
73 /* const char *name = get_param(cmd, "NAME"); */
74 send_resp(dut, conn, SIGMA_COMPLETE, "version,1.0");
75 return 0;
76}
77
78
Jouni Malinend6bf1b42017-06-23 17:51:01 +030079static void kill_hostapd_process_pid(struct sigma_dut *dut)
80{
81 FILE *f;
82 int pid, res;
83 char path[100];
84 int count;
85
86 f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
87 if (!f)
88 return;
89 res = fscanf(f, "%d", &pid);
90 fclose(f);
91 if (res != 1)
92 return;
93 sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
94 kill(pid, SIGTERM);
95 snprintf(path, sizeof(path), "/proc/%d", pid);
96 for (count = 0; count < 20 && file_exists(path); count++)
97 usleep(100000);
98}
99
100
Jouni Malinen2e6ccc22017-09-04 13:43:16 +0300101int get_hwaddr(const char *ifname, unsigned char *hwaddr)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200102{
103#ifndef __QNXNTO__
104 struct ifreq ifr;
105 int s;
106
107 s = socket(AF_INET, SOCK_DGRAM, 0);
108 if (s < 0)
109 return -1;
110 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700111 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200112 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
113 perror("ioctl");
114 close(s);
115 return -1;
116 }
117 close(s);
118 memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6);
119#else /* __QNXNTO__ */
120 struct ifaddrs *ifaddrshead = NULL;
121 int found = 0;
122 struct ifaddrs *temp_ifap = NULL;
123 struct sockaddr_dl *sdl = NULL;
124
125 if (getifaddrs(&ifaddrshead) != 0) {
126 perror("getifaddrs failed");
127 return -1;
128 }
129
130 for (temp_ifap = ifaddrshead; ifaddrshead && !found;
131 ifaddrshead = ifaddrshead->ifa_next) {
132 if (ifaddrshead->ifa_addr->sa_family == AF_LINK &&
133 strcmp(ifaddrshead->ifa_name, ifname) == 0) {
134 found = 1;
135 sdl = (struct sockaddr_dl *) ifaddrshead->ifa_addr;
136 if (sdl)
137 memcpy(hwaddr, LLADDR(sdl), sdl->sdl_alen);
138 }
139 }
140
141 if (temp_ifap)
142 freeifaddrs(temp_ifap);
143
144 if (!found) {
145 perror("Failed to get the interface");
146 return -1;
147 }
148#endif /* __QNXNTO__ */
149 return 0;
150}
151
152
153static void ath_ap_set_group_id(struct sigma_dut *dut, const char *ifname,
154 const char *val)
155{
156 char buf[60];
157
158 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 55 %d",
159 ifname, atoi(val));
160 if (system(buf) != 0) {
161 sigma_dut_print(dut, DUT_MSG_ERROR,
162 "wifitool ap_group_id failed");
163 }
164}
165
166
167void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
168 const char *val)
169{
170 char buf[60];
171
172 /* TODO: Enable support for other values */
173 if (strcasecmp(val, "40") == 0) {
174 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 1",
175 ifname);
176 if (system(buf) != 0) {
177 sigma_dut_print(dut, DUT_MSG_ERROR,
178 "wifitool cts_width failed");
179 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800180 snprintf(buf, sizeof(buf),
181 "athdiag --set --address=0x10024 --val=0xd90b8a14");
182 if (system(buf) != 0) {
183 sigma_dut_print(dut, DUT_MSG_ERROR,
184 "disabling phy restart failed");
185 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200186 } else {
187 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported CTS_WIDTH");
188 }
189}
190
191
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800192void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
193 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200194{
195 char buf[60];
196
197 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200198 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200199 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
200 if (system(buf) != 0) {
201 sigma_dut_print(dut, DUT_MSG_ERROR,
202 "iwpriv cwmenable 1 failed");
203 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800204 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 96 1",
205 ifname);
206 if (system(buf) != 0) {
207 sigma_dut_print(dut, DUT_MSG_ERROR,
208 "disabling RTS from rate control logic failed");
209 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200210 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200211 dut->ap_dyn_bw_sig = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200212 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
213 if (system(buf) != 0) {
214 sigma_dut_print(dut, DUT_MSG_ERROR,
215 "iwpriv cwmenable 0 failed");
216 }
217 } else {
218 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported DYN_BW_SGL");
219 }
220}
221
222
223static void ath_config_rts_force(struct sigma_dut *dut, const char *ifname,
224 const char *val)
225{
226 char buf[60];
227
228 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200229 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
231 if (system(buf) != 0) {
232 sigma_dut_print(dut, DUT_MSG_ERROR,
233 "iwconfig rts 64 failed");
234 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -0800235 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 100 1",
236 ifname);
237 if (system(buf) != 0) {
238 sigma_dut_print(dut, DUT_MSG_ERROR,
239 "wifitool beeliner_fw_test 100 1 failed");
240 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200241 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200242 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200243 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
244 if (system(buf) != 0) {
245 sigma_dut_print(dut, DUT_MSG_ERROR,
246 "iwpriv rts 2347 failed");
247 }
248 } else {
249 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported RTS_FORCE");
250 }
251}
252
253
254static enum ap_mode get_mode(const char *str)
255{
256 if (strcasecmp(str, "11a") == 0)
257 return AP_11a;
258 else if (strcasecmp(str, "11g") == 0)
259 return AP_11g;
260 else if (strcasecmp(str, "11b") == 0)
261 return AP_11b;
262 else if (strcasecmp(str, "11na") == 0)
263 return AP_11na;
264 else if (strcasecmp(str, "11ng") == 0)
265 return AP_11ng;
266 else if (strcasecmp(str, "11ac") == 0 || strcasecmp(str, "ac") == 0)
267 return AP_11ac;
268 else
269 return AP_inval;
270}
271
272
273static int run_hostapd_cli(struct sigma_dut *dut, char *buf)
274{
275 char command[1000];
276 const char *bin;
277 enum driver_type drv = get_driver_type();
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700278 char *sigma_hapd_file = sigma_hapd_ctrl;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200279
280 if (file_exists("hostapd_cli"))
281 bin = "./hostapd_cli";
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300282 else if (file_exists("../../hostapd/hostapd_cli"))
283 bin = "../../hostapd/hostapd_cli";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200284 else
285 bin = "hostapd_cli";
286
287 if (drv == DRIVER_OPENWRT && sigma_hapd_ctrl == NULL) {
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700288 sigma_hapd_file = "/var/run/hostapd-wifi0";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200289
290 if (sigma_radio_ifname[0] &&
291 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700292 sigma_hapd_file = "/var/run/hostapd-wifi1";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200293 else if (sigma_radio_ifname[0] &&
294 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700295 sigma_hapd_file = "/var/run/hostapd-wifi2";
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200296 }
297
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700298 if (sigma_hapd_file)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200299 snprintf(command, sizeof(command), "%s -p %s %s",
Adil Saeed Musthafa3dd6ca72017-05-15 12:45:18 -0700300 bin, sigma_hapd_file, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200301 else
302 snprintf(command, sizeof(command), "%s %s", bin, buf);
303 return run_system(dut, command);
304}
305
306
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -0700307static int ath_set_lci_config(struct sigma_dut *dut, const char *val,
308 struct sigma_cmd *cmd)
309{
310 FILE *f;
311 int i;
312
313 f = fopen("/tmp/lci_cfg.txt", "w");
314 if (!f) {
315 sigma_dut_print(dut, DUT_MSG_ERROR,
316 "Failed to open /tmp/lci_cfg.txt");
317 return -1;
318 }
319
320 for (i = 2; i < cmd->count; i++)
321 fprintf(f, "%s = %s \n", cmd->params[i], cmd->values[i]);
322 fprintf(f, "\n");
323 fclose(f);
324
325 return 0;
326}
327
328
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329static int cmd_ap_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
330 struct sigma_cmd *cmd)
331{
332 /* const char *name = get_param(cmd, "NAME"); */
333 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200334 const char *val;
335 unsigned int wlan_tag = 1;
336 char *ifname = get_main_ifname();
337
338 val = get_param(cmd, "WLAN_TAG");
339 if (val) {
340 wlan_tag = atoi(val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700341 if (wlan_tag < 1 || wlan_tag > 3) {
342 /*
343 * The only valid WLAN Tags as of now as per the latest
344 * WFA scripts are 1, 2, and 3.
345 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200346 send_resp(dut, conn, SIGMA_INVALID,
347 "errorCode,Invalid WLAN_TAG");
348 return 0;
349 }
350 }
351
352 val = get_param(cmd, "CountryCode");
353 if (val) {
354 if (strlen(val) > sizeof(dut->ap_countrycode) - 1)
355 return -1;
356 snprintf(dut->ap_countrycode, sizeof(dut->ap_countrycode),
357 "%s", val);
358 }
359
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530360 val = get_param(cmd, "regulatory_mode");
361 if (val) {
362 if (strcasecmp(val, "11d") == 0 || strcasecmp(val, "11h") == 0)
363 dut->ap_regulatory_mode = AP_80211D_MODE_ENABLED;
364 }
365
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200366 val = get_param(cmd, "SSID");
367 if (val) {
368 if (strlen(val) > sizeof(dut->ap_ssid) - 1)
369 return -1;
370
371 if (wlan_tag == 1) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700372 /*
373 * If tag is not specified, it is deemed to be 1.
374 * Hence tag of 1 is a special case and the values
375 * corresponding to wlan-tag=1 are stored separately
376 * from the values corresponding tags 2 and 3.
377 * This approach minimises the changes to existing code
378 * since most of the sigma_dut code does not deal with
379 * WLAN-TAG CAPI variable.
380 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200381 snprintf(dut->ap_ssid,
382 sizeof(dut->ap_ssid), "%s", val);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -0700383 } else {
384 snprintf(dut->ap_tag_ssid[wlan_tag - 2],
385 sizeof(dut->ap_tag_ssid[wlan_tag - 2]),
386 "%s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200387 }
388 }
389
390 val = get_param(cmd, "CHANNEL");
391 if (val) {
392 const char *pos;
393 dut->ap_channel = atoi(val);
394 pos = strchr(val, ';');
395 if (pos) {
396 pos++;
397 dut->ap_channel_1 = atoi(pos);
398 }
399 }
400
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530401 /* Overwrite the AP channel with DFS channel if configured */
402 val = get_param(cmd, "dfs_chan");
403 if (val) {
404 dut->ap_channel = atoi(val);
405 }
406
407 val = get_param(cmd, "dfs_mode");
408 if (val) {
409 if (strcasecmp(val, "Enable") == 0)
410 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
411 else if (strcasecmp(val, "Disable") == 0)
412 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
413 else
414 sigma_dut_print(dut, DUT_MSG_ERROR,
415 "Unsupported dfs_mode value: %s", val);
416 }
417
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200418 val = get_param(cmd, "MODE");
419 if (val) {
420 char *str, *pos;
421
422 str = strdup(val);
423 if (str == NULL)
424 return -1;
425 pos = strchr(str, ';');
426 if (pos)
427 *pos++ = '\0';
428
429 dut->ap_is_dual = 0;
430 dut->ap_mode = get_mode(str);
431 if (dut->ap_mode == AP_inval) {
432 send_resp(dut, conn, SIGMA_INVALID,
433 "errorCode,Unsupported MODE");
434 free(str);
435 return 0;
436 }
437 if (dut->ap_mode == AP_11ac)
438 dut->ap_chwidth = AP_80;
439
440 if (pos) {
441 dut->ap_mode_1 = get_mode(pos);
442 if (dut->ap_mode_1 == AP_inval) {
443 send_resp(dut, conn, SIGMA_INVALID,
444 "errorCode,Unsupported MODE");
445 free(str);
446 return 0;
447 }
448 if (dut->ap_mode_1 == AP_11ac)
449 dut->ap_chwidth_1 = AP_80;
450 dut->ap_is_dual = 1;
451 }
452
453 free(str);
454 } else if (dut->ap_mode == AP_inval) {
455 if (dut->ap_channel <= 11)
456 dut->ap_mode = AP_11ng;
457 else if (dut->program == PROGRAM_VHT)
458 dut->ap_mode = AP_11ac;
459 else
460 dut->ap_mode = AP_11na;
461 }
462
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530463 val = get_param(cmd, "WME");
464 if (val) {
465 if (strcasecmp(val, "on") == 0)
466 dut->ap_wme = AP_WME_ON;
467 else if (strcasecmp(val, "off") == 0)
468 dut->ap_wme = AP_WME_OFF;
469 else
470 sigma_dut_print(dut, DUT_MSG_ERROR,
471 "Unsupported WME value: %s", val);
472 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200473
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +0530474 val = get_param(cmd, "WMMPS");
475 if (val) {
476 if (strcasecmp(val, "on") == 0)
477 dut->ap_wmmps = AP_WMMPS_ON;
478 else if (strcasecmp(val, "off") == 0)
479 dut->ap_wmmps = AP_WMMPS_OFF;
480 else
481 sigma_dut_print(dut, DUT_MSG_ERROR,
482 "Unsupported WMMPS value: %s", val);
483 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200484
485 val = get_param(cmd, "RTS");
486 if (val)
487 dut->ap_rts = atoi(val);
488
489 val = get_param(cmd, "FRGMNT");
490 if (val)
491 dut->ap_frgmnt = atoi(val);
492
493 /* TODO: PWRSAVE */
494
495 val = get_param(cmd, "BCNINT");
496 if (val)
497 dut->ap_bcnint = atoi(val);
498
499 val = get_param(cmd, "RADIO");
500 if (val) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530501 enum driver_type drv = get_driver_type();
502
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200503 if (strcasecmp(val, "on") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200504 if (drv == DRIVER_ATHEROS)
505 ath_ap_start_hostapd(dut);
506 else if (cmd_ap_config_commit(dut, conn, cmd) <= 0)
507 return 0;
508 } else if (strcasecmp(val, "off") == 0) {
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530509 if (drv == DRIVER_OPENWRT) {
510 run_system(dut, "wifi down");
511 sigma_dut_print(dut, DUT_MSG_INFO,
512 "wifi down on radio,off");
Jouni Malinend6bf1b42017-06-23 17:51:01 +0300513 } else if (dut->use_hostapd_pid_file) {
514 kill_hostapd_process_pid(dut);
Mohammed Shafi Shajakhan94997f92017-01-09 21:31:09 +0530515 } else if (kill_process(dut, "(hostapd)", 1,
516 SIGTERM) == 0 ||
517 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200518 sigma_dut_print(dut, DUT_MSG_INFO,
519 "Killed hostapd on radio,off");
520 }
521 } else {
522 send_resp(dut, conn, SIGMA_INVALID,
523 "errorCode,Unsupported RADIO value");
524 return 0;
525 }
526 }
527
528 val = get_param(cmd, "P2PMgmtBit");
529 if (val)
530 dut->ap_p2p_mgmt = atoi(val);
531
532 /* TODO: ChannelUsage */
533
534 /* TODO: 40_INTOLERANT */
535
536 val = get_param(cmd, "ADDBA_REJECT");
537 if (val) {
538 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200539 dut->ap_addba_reject = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200540 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200541 dut->ap_addba_reject = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200542 }
543
544 val = get_param(cmd, "AMPDU");
545 if (val) {
546 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200547 dut->ap_ampdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200548 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200549 dut->ap_ampdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200550 }
551
552 val = get_param(cmd, "AMPDU_EXP");
553 if (val)
554 dut->ap_ampdu_exp = atoi(val);
555
556 val = get_param(cmd, "AMSDU");
557 if (val) {
558 if (strcasecmp(val, "Enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200559 dut->ap_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200560 else if (strcasecmp(val, "Disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200561 dut->ap_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200562 }
563
564 val = get_param(cmd, "NoAck");
565 if (val) {
566 if (strcasecmp(val, "on") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200567 dut->ap_noack = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200568 else if (strcasecmp(val, "off") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200569 dut->ap_noack = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200570 }
571
572 /* TODO: GREENFIELD */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200573 /* TODO: MCS_32 */
574
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +0530575 val = get_param(cmd, "OFFSET");
576 if (val) {
577 if (strcasecmp(val, "Above") == 0)
578 dut->ap_chwidth_offset = SEC_CH_40ABOVE;
579 else if (strcasecmp(val, "Below") == 0)
580 dut->ap_chwidth_offset = SEC_CH_40BELOW;
581 }
582
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200583 val = get_param(cmd, "MCS_FIXEDRATE");
584 if (val) {
585 dut->ap_fixed_rate = 1;
586 dut->ap_mcs = atoi(val);
587 }
588
589 val = get_param(cmd, "SPATIAL_RX_STREAM");
590 if (val) {
591 if (strcasecmp(val, "1SS") == 0 || strcasecmp(val, "1") == 0) {
592 dut->ap_rx_streams = 1;
593 if (dut->device_type == AP_testbed)
594 dut->ap_vhtmcs_map = 0xfffc;
595 } else if (strcasecmp(val, "2SS") == 0 ||
596 strcasecmp(val, "2") == 0) {
597 dut->ap_rx_streams = 2;
598 if (dut->device_type == AP_testbed)
599 dut->ap_vhtmcs_map = 0xfff0;
600 } else if (strcasecmp(val, "3SS") == 0 ||
601 strcasecmp(val, "3") == 0) {
602 dut->ap_rx_streams = 3;
603 if (dut->device_type == AP_testbed)
604 dut->ap_vhtmcs_map = 0xffc0;
605 } else if (strcasecmp(val, "4SS") == 0 ||
606 strcasecmp(val, "4") == 0) {
607 dut->ap_rx_streams = 4;
608 }
609 }
610
611 val = get_param(cmd, "SPATIAL_TX_STREAM");
612 if (val) {
613 if (strcasecmp(val, "1SS") == 0 ||
614 strcasecmp(val, "1") == 0) {
615 dut->ap_tx_streams = 1;
616 if (dut->device_type == AP_testbed)
617 dut->ap_vhtmcs_map = 0xfffc;
618 } else if (strcasecmp(val, "2SS") == 0 ||
619 strcasecmp(val, "2") == 0) {
620 dut->ap_tx_streams = 2;
621 if (dut->device_type == AP_testbed)
622 dut->ap_vhtmcs_map = 0xfff0;
623 } else if (strcasecmp(val, "3SS") == 0 ||
624 strcasecmp(val, "3") == 0) {
625 dut->ap_tx_streams = 3;
626 if (dut->device_type == AP_testbed)
627 dut->ap_vhtmcs_map = 0xffc0;
628 } else if (strcasecmp(val, "4SS") == 0 ||
629 strcasecmp(val, "4") == 0) {
630 dut->ap_tx_streams = 4;
631 }
632 }
633
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -0700634 val = get_param(cmd, "BSS_max_idle");
635 if (val) {
636 if (strncasecmp(val, "Enable", 7) == 0) {
637 dut->wnm_bss_max_feature = VALUE_ENABLED;
638 } else if (strncasecmp(val, "Disable", 8) == 0) {
639 dut->wnm_bss_max_feature = VALUE_DISABLED;
640 } else {
641 send_resp(dut, conn, SIGMA_ERROR,
642 "errorCode,Invalid value for BSS_max_Feature");
643 return 0;
644 }
645 }
646
647 val = get_param(cmd, "BSS_Idle_Protection_options");
648 if (val) {
649 int protection = (int) strtol(val, (char **) NULL, 10);
650
651 if (protection != 1 && protection != 0) {
652 send_resp(dut, conn, SIGMA_ERROR,
653 "errorCode,Invalid value for BSS_Idle_Protection_options");
654 return 0;
655 }
656 dut->wnm_bss_max_protection = protection ?
657 VALUE_ENABLED : VALUE_DISABLED;
658 }
659
660 val = get_param(cmd, "BSS_max_Idle_period");
661 if (val) {
662 int idle_time = (int) strtol(val, (char **) NULL, 10);
663
664 if (idle_time == LONG_MIN || idle_time == LONG_MAX) {
665 send_resp(dut, conn, SIGMA_ERROR,
666 "errorCode,Invalid value for BSS_max_Idle_period");
667 return 0;
668 }
669 dut->wnm_bss_max_idle_time = idle_time;
670 }
671
672 val = get_param(cmd, "PROXY_ARP");
673 if (val)
674 dut->ap_proxy_arp = (int) strtol(val, (char **) NULL, 10);
675
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200676 val = get_param(cmd, "nss_mcs_cap");
677 if (val) {
678 int nss, mcs;
679 char token[20];
680 char *result = NULL;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530681 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200682
683 if (strlen(val) >= sizeof(token))
684 return -1;
Jouni Malinen947fdf62017-05-14 22:29:32 +0300685 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530686 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530687 if (!result) {
688 sigma_dut_print(dut, DUT_MSG_ERROR,
689 "VHT NSS not specified");
690 return 0;
691 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200692 nss = atoi(result);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530693 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200694 if (result == NULL) {
695 sigma_dut_print(dut, DUT_MSG_ERROR,
696 "VHTMCS NOT SPECIFIED!");
697 return 0;
698 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +0530699 result = strtok_r(result, "-", &saveptr);
700 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +0530701 if (!result) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "VHT MCS not specified");
704 return 0;
705 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200706 mcs = atoi(result);
707 switch (nss) {
708 case 1:
709 switch (mcs) {
710 case 7:
711 dut->ap_vhtmcs_map = 0xfffc;
712 break;
713 case 8:
714 dut->ap_vhtmcs_map = 0xfffd;
715 break;
716 case 9:
717 dut->ap_vhtmcs_map = 0xfffe;
718 break;
719 default:
720 dut->ap_vhtmcs_map = 0xfffe;
721 break;
722 }
723 break;
724 case 2:
725 switch (mcs) {
726 case 7:
727 dut->ap_vhtmcs_map = 0xfff0;
728 break;
729 case 8:
730 dut->ap_vhtmcs_map = 0xfff5;
731 break;
732 case 9:
733 dut->ap_vhtmcs_map = 0xfffa;
734 break;
735 default:
736 dut->ap_vhtmcs_map = 0xfffa;
737 break;
738 }
739 break;
740 case 3:
741 switch (mcs) {
742 case 7:
743 dut->ap_vhtmcs_map = 0xffc0;
744 break;
745 case 8:
746 dut->ap_vhtmcs_map = 0xffd5;
747 break;
748 case 9:
749 dut->ap_vhtmcs_map = 0xffea;
750 break;
751 default:
752 dut->ap_vhtmcs_map = 0xffea;
753 break;
754 }
755 break;
756 default:
757 dut->ap_vhtmcs_map = 0xffea;
758 break;
759 }
760 }
761
762 /* TODO: MPDU_MIN_START_SPACING */
763 /* TODO: RIFS_TEST */
764 /* TODO: SGI20 */
765
766 val = get_param(cmd, "STBC_TX");
767 if (val)
768 dut->ap_tx_stbc = atoi(val);
769
770 val = get_param(cmd, "WIDTH");
771 if (val) {
772 if (strcasecmp(val, "20") == 0)
773 dut->ap_chwidth = AP_20;
774 else if (strcasecmp(val, "40") == 0)
775 dut->ap_chwidth = AP_40;
776 else if (strcasecmp(val, "80") == 0)
777 dut->ap_chwidth = AP_80;
778 else if (strcasecmp(val, "160") == 0)
779 dut->ap_chwidth = AP_160;
780 else if (strcasecmp(val, "Auto") == 0)
781 dut->ap_chwidth = AP_AUTO;
782 else {
783 send_resp(dut, conn, SIGMA_INVALID,
784 "errorCode,Unsupported WIDTH");
785 return 0;
786 }
787 }
788
789 /* TODO: WIDTH_SCAN */
790
791 val = get_param(cmd, "TDLSProhibit");
792 dut->ap_tdls_prohibit = val && strcasecmp(val, "Enabled") == 0;
793 val = get_param(cmd, "TDLSChswitchProhibit");
794 dut->ap_tdls_prohibit_chswitch =
795 val && strcasecmp(val, "Enabled") == 0;
796 val = get_param(cmd, "HS2");
797 if (val && wlan_tag == 1)
798 dut->ap_hs2 = atoi(val);
799 val = get_param(cmd, "P2P_CROSS_CONNECT");
800 if (val)
801 dut->ap_p2p_cross_connect = strcasecmp(val, "Enabled") == 0;
802
803 val = get_param(cmd, "FakePubKey");
804 dut->ap_fake_pkhash = val && atoi(val);
805
806 val = get_param(cmd, "vht_tkip");
807 dut->ap_allow_vht_tkip = val && strcasecmp(val, "Enable") == 0;
808 val = get_param(cmd, "vht_wep");
809 dut->ap_allow_vht_wep = val && strcasecmp(val, "Enable") == 0;
810
811 val = get_param(cmd, "Protect_mode");
812 dut->ap_disable_protection = val && strcasecmp(val, "Disable") == 0;
813
814 val = get_param(cmd, "DYN_BW_SGNL");
815 if (val) {
816 switch (get_driver_type()) {
817 case DRIVER_OPENWRT:
818 switch (get_openwrt_driver_type()) {
819 case OPENWRT_DRIVER_ATHEROS:
820 ath_config_dyn_bw_sig(dut, ifname, val);
821 break;
822 default:
823 send_resp(dut, conn, SIGMA_ERROR,
824 "errorCode,Unsupported DYN_BW_SGNL with OpenWrt driver");
825 return 0;
826 }
827 break;
Nirav Shah8ad8d742017-10-17 10:49:11 +0530828 case DRIVER_WCN:
829 case DRIVER_LINUX_WCN:
830 ath_config_dyn_bw_sig(dut, ifname, val);
831 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200832 default:
833 sigma_dut_print(dut, DUT_MSG_ERROR,
834 "Unsupported DYN_BW_SGL with the current driver");
835 break;
836 }
837 }
838
839 val = get_param(cmd, "SGI80");
840 if (val) {
841 if (strcasecmp(val, "enable") == 0)
842 dut->ap_sgi80 = 1;
843 else if (strcasecmp(val, "disable") == 0)
844 dut->ap_sgi80 = 0;
845 else {
846 send_resp(dut, conn, SIGMA_INVALID,
847 "errorCode,Unsupported SGI80");
848 return 0;
849 }
850 }
851
852 val = get_param(cmd, "LDPC");
853 if (val) {
854 if (strcasecmp(val, "enable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200855 dut->ap_ldpc = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200856 else if (strcasecmp(val, "disable") == 0)
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200857 dut->ap_ldpc = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200858 else {
859 send_resp(dut, conn, SIGMA_INVALID,
860 "errorCode,Unsupported LDPC");
861 return 0;
862 }
863 }
864
865 val = get_param(cmd, "BW_SGNL");
866 if (val) {
867 /*
868 * With dynamic bandwidth signaling enabled we should see
869 * RTS if the threshold is met.
870 */
871 if (strcasecmp(val, "enable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200872 dut->ap_sig_rts = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200873 } else if (strcasecmp(val, "disable") == 0) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +0200874 dut->ap_sig_rts = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200875 } else {
876 send_resp(dut, conn, SIGMA_INVALID,
877 "errorCode,Unsupported BW_SGNL");
878 return 0;
879 }
880 }
881
882 val = get_param(cmd, "RTS_FORCE");
883 if (val) {
884 switch (get_driver_type()) {
885 case DRIVER_OPENWRT:
886 switch (get_openwrt_driver_type()) {
887 case OPENWRT_DRIVER_ATHEROS:
888 ath_config_rts_force(dut, ifname, val);
889 break;
890 default:
891 send_resp(dut, conn, SIGMA_ERROR,
892 "errorCode,Unsupported RTS_FORCE with OpenWrt driver");
893 return 0;
894 }
895 break;
896 default:
897 sigma_dut_print(dut, DUT_MSG_ERROR,
898 "Unsupported RTS_FORCE with the current driver");
899 break;
900 }
901 }
902
903 val = get_param(cmd, "Zero_crc");
904 if (val) {
905 switch (get_driver_type()) {
906 case DRIVER_ATHEROS:
907 ath_set_zero_crc(dut, val);
908 break;
909 case DRIVER_OPENWRT:
910 switch (get_openwrt_driver_type()) {
911 case OPENWRT_DRIVER_ATHEROS:
912 ath_set_zero_crc(dut, val);
913 break;
914 default:
915 send_resp(dut, conn, SIGMA_ERROR,
916 "errorCode,Unsupported zero_crc with the current driver");
917 return 0;
918 }
919 break;
920 default:
921 send_resp(dut, conn, SIGMA_ERROR,
922 "errorCode,Unsupported zero_crc with the current driver");
923 return 0;
924 }
925 }
926
927 val = get_param(cmd, "TxBF");
928 if (val)
929 dut->ap_txBF = strcasecmp(val, "enable") == 0;
930
931 val = get_param(cmd, "MU_TxBF");
Manikanta Pubbisetty210f7c82017-02-14 12:33:54 +0530932 if (val) {
933 if (strcasecmp(val, "enable") == 0) {
934 dut->ap_txBF = 1;
935 dut->ap_mu_txBF = 1;
936 } else if (strcasecmp(val, "disable") == 0) {
937 dut->ap_txBF = 0;
938 dut->ap_mu_txBF = 0;
939 } else {
940 sigma_dut_print(dut, DUT_MSG_ERROR,
941 "Unsupported MU_TxBF");
942 }
943 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200944
945 /* UNSUPPORTED: tx_lgi_rate */
946
947 val = get_param(cmd, "wpsnfc");
948 if (val)
949 dut->ap_wpsnfc = atoi(val);
950
951 val = get_param(cmd, "GROUP_ID");
952 if (val) {
953 switch (get_driver_type()) {
954 case DRIVER_OPENWRT:
955 switch (get_openwrt_driver_type()) {
956 case OPENWRT_DRIVER_ATHEROS:
957 ath_ap_set_group_id(dut, ifname, val);
958 break;
959 default:
960 send_resp(dut, conn, SIGMA_ERROR,
961 "errorCode,Unsupported group_id with the current driver");
962 return 0;
963 }
964 break;
965 default:
966 send_resp(dut, conn, SIGMA_ERROR,
967 "errorCode,Unsupported group_id with the current driver");
968 return 0;
969 }
970 }
971
972 val = get_param(cmd, "CTS_WIDTH");
973 if (val) {
974 switch (get_driver_type()) {
975 case DRIVER_OPENWRT:
976 switch (get_openwrt_driver_type()) {
977 case OPENWRT_DRIVER_ATHEROS:
978 ath_set_cts_width(dut, ifname, val);
979 break;
980 default:
981 send_resp(dut, conn, SIGMA_ERROR,
982 "errorCode,Unsupported cts_width with the current driver");
983 return 0;
984 }
985 break;
986 default:
987 send_resp(dut, conn, SIGMA_ERROR,
988 "errorCode,Unsupported cts_width with the current driver");
989 return 0;
990 }
991 }
992
priyadharshini gowthaman264d5442016-02-25 15:52:22 -0800993 val = get_param(cmd, "MU_NDPA_FrameFormat");
994 if (val)
995 dut->ap_ndpa_frame = atoi(val);
996
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -0700997 val = get_param(cmd, "interworking");
998 if (val && strcmp(val, "1") == 0)
999 dut->ap_interworking = 1;
1000
1001 val = get_param(cmd, "GAS_CB_DELAY");
1002 if (val)
1003 dut->ap_gas_cb_delay = atoi(val);
1004
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001005 val = get_param(cmd, "LCI");
1006 if (val) {
1007 if (strlen(val) > sizeof(dut->ap_val_lci) - 1)
1008 return -1;
1009 dut->ap_lci = 1;
1010 snprintf(dut->ap_val_lci, sizeof(dut->ap_val_lci), "%s", val);
1011 ath_set_lci_config(dut, val, cmd);
1012 }
1013
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001014 val = get_param(cmd, "InfoZ");
1015 if (val) {
1016 if (strlen(val) > sizeof(dut->ap_infoz) - 1)
1017 return -1;
1018 snprintf(dut->ap_infoz, sizeof(dut->ap_infoz), "%s", val);
1019 }
1020
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07001021 val = get_param(cmd, "LocCivicAddr");
1022 if (val) {
1023 if (strlen(val) > sizeof(dut->ap_val_lcr) - 1)
1024 return -1;
1025 dut->ap_lcr = 1;
1026 snprintf(dut->ap_val_lcr, sizeof(dut->ap_val_lcr), "%s", val);
1027 if (dut->ap_lci == 0)
1028 ath_set_lci_config(dut, val, cmd);
1029 }
1030
1031 val = get_param(cmd, "NeighAPBSSID");
1032 if (val) {
1033 if (dut->ap_neighap < 3) {
1034 if (parse_mac_address(
1035 dut, val,
1036 dut->ap_val_neighap[dut->ap_neighap]) < 0) {
1037 send_resp(dut, conn, SIGMA_INVALID,
1038 "Failed to parse MAC address");
1039 return 0;
1040 }
1041 dut->ap_neighap++;
1042 if (dut->ap_lci == 1)
1043 dut->ap_scan = 1;
1044 }
1045 }
1046
1047 val = get_param(cmd, "OpChannel");
1048 if (val) {
1049 if (dut->ap_opchannel < 3) {
1050 dut->ap_val_opchannel[dut->ap_opchannel] = atoi(val);
1051 dut->ap_opchannel++;
1052 }
1053 }
1054
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07001055 val = get_param(cmd, "URI-FQDNdescriptor");
1056 if (val) {
1057 if (strcasecmp(val, "HELD") == 0) {
1058 dut->ap_fqdn_held = 1;
1059 } else if (strcasecmp(val, "SUPL") == 0) {
1060 dut->ap_fqdn_supl = 1;
1061 } else {
1062 send_resp(dut, conn, SIGMA_INVALID,
1063 "errorCode,Unsupported URI-FQDNdescriptor");
1064 return 0;
1065 }
1066 }
1067
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001068 val = get_param(cmd, "Reg_Domain");
1069 if (val) {
1070 if (strcasecmp(val, "Local") == 0) {
1071 dut->ap_reg_domain = REG_DOMAIN_LOCAL;
1072 } else if (strcasecmp(val, "Global") == 0) {
1073 dut->ap_reg_domain = REG_DOMAIN_GLOBAL;
1074 } else {
1075 send_resp(dut, conn, SIGMA_ERROR,
1076 "errorCode,Wrong value for Reg_Domain");
1077 return 0;
1078 }
1079 }
1080
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001081 val = get_param(cmd, "NAME");
1082 if (val) {
1083 if (strcasecmp(val, "ap1mbo") == 0)
1084 dut->ap_name = 1;
1085 else if (strcasecmp(val, "ap2mbo") == 0)
1086 dut->ap_name = 2;
1087 else
1088 dut->ap_name = 0;
1089 }
1090
1091 val = get_param(cmd, "FT_OA");
1092 if (val) {
1093 if (strcasecmp(val, "Enable") == 0) {
1094 dut->ap_ft_oa = 1;
1095 } else if (strcasecmp(val, "Disable") == 0) {
1096 dut->ap_ft_oa = 0;
1097 } else {
1098 send_resp(dut, conn, SIGMA_ERROR,
1099 "errorCode,Wrong value for FT_OA");
1100 return 0;
1101 }
1102 }
1103
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07001104 val = get_param(cmd, "Cellular_Cap_Pref");
1105 if (val)
1106 dut->ap_cell_cap_pref = atoi(val);
1107
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07001108 val = get_param(cmd, "DOMAIN");
1109 if (val) {
1110 if (strlen(val) >= sizeof(dut->ap_mobility_domain)) {
1111 send_resp(dut, conn, SIGMA_ERROR,
1112 "errorCode,Too long DOMAIN");
1113 return 0;
1114 }
1115 snprintf(dut->ap_mobility_domain,
1116 sizeof(dut->ap_mobility_domain), "%s", val);
1117 }
1118
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07001119 val = get_param(cmd, "ft_bss_list");
1120 if (val) {
1121 char *mac_str;
1122 int i;
1123 char *saveptr;
1124 char *mac_list_str;
1125
1126 mac_list_str = strdup(val);
1127 if (!mac_list_str)
1128 return -1;
1129 mac_str = strtok_r(mac_list_str, " ", &saveptr);
1130 for (i = 0; mac_str && i < MAX_FT_BSS_LIST; i++) {
1131 if (parse_mac_address(dut, mac_str,
1132 dut->ft_bss_mac_list[i]) < 0) {
1133 sigma_dut_print(dut, DUT_MSG_ERROR,
1134 "MAC Address not in proper format");
1135 break;
1136 }
1137 dut->ft_bss_mac_cnt++;
1138 mac_str = strtok_r(NULL, " ", &saveptr);
1139 }
1140 sigma_dut_print(dut, DUT_MSG_DEBUG,
1141 "Storing the following FT BSS MAC List");
1142 for (i = 0; i < dut->ft_bss_mac_cnt; i++) {
1143 sigma_dut_print(dut, DUT_MSG_DEBUG,
1144 "MAC[%d] %02x:%02x:%02x:%02x:%02x:%02x",
1145 i,
1146 dut->ft_bss_mac_list[i][0],
1147 dut->ft_bss_mac_list[i][1],
1148 dut->ft_bss_mac_list[i][2],
1149 dut->ft_bss_mac_list[i][3],
1150 dut->ft_bss_mac_list[i][4],
1151 dut->ft_bss_mac_list[i][5]);
1152 }
1153 free(mac_list_str);
1154 }
1155
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001156 return 1;
1157}
1158
1159
1160static void ath_inject_frame(struct sigma_dut *dut, const char *ifname, int tid)
1161{
1162 char buf[256];
1163 int tid_to_dscp[] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
1164
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05301165 if (tid < 0 ||
1166 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
1167 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
1168 return;
1169 }
1170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001171 snprintf(buf, sizeof(buf),
1172 "wlanconfig %s list sta | grep : | cut -b 1-17 > %s",
1173 ifname, VI_QOS_TMP_FILE);
1174 if (system(buf) != 0)
1175 return;
1176
1177 snprintf(buf, sizeof(buf),
1178 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
1179 ifname, VI_QOS_TMP_FILE);
1180 if (system(buf) != 0)
1181 sigma_dut_print(dut, DUT_MSG_ERROR, "Retrieve HWaddr failed");
1182
1183 snprintf(buf, sizeof(buf), "sed -n '3,$p' %s >> %s",
1184 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
1185 if (system(buf) != 0) {
1186 sigma_dut_print(dut, DUT_MSG_ERROR,
1187 "Output redirection to VI_QOS_TMP_FILE failed");
1188 }
1189
1190 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
1191 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
1192 if (system(buf) != 0) {
1193 sigma_dut_print(dut, DUT_MSG_ERROR,
1194 "Append TID to VI_QOS_FILE failed ");
1195 }
1196
1197 snprintf(buf, sizeof(buf), "ethinject %s %s", ifname, VI_QOS_FILE);
1198 if (system(buf) != 0)
1199 sigma_dut_print(dut, DUT_MSG_ERROR, "Ethinject frame failed");
1200}
1201
1202
1203static int ath_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1204 struct sigma_cmd *cmd)
1205{
1206 const char *val;
1207 char *ifname;
1208 char buf[256];
1209 int tid = 0;
1210
1211 ifname = get_main_ifname();
1212 val = get_param(cmd, "TID");
1213 if (val) {
1214 tid = atoi(val);
1215 if (tid)
1216 ath_inject_frame(dut, ifname, tid);
1217 }
1218
1219 /* NOTE: This is the command sequence on Peregrine for ADDBA */
1220 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
1221 if (system(buf) != 0) {
1222 sigma_dut_print(dut, DUT_MSG_ERROR,
1223 "iwpriv setaddbaoper failed");
1224 }
1225
1226 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4",
1227 ifname, tid);
1228 if (system(buf) != 0) {
1229 sigma_dut_print(dut, DUT_MSG_ERROR,
1230 "wifitool senddelba failed");
1231 }
1232
1233 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64",
1234 ifname, tid);
1235 if (system(buf) != 0) {
1236 sigma_dut_print(dut, DUT_MSG_ERROR,
1237 "wifitool sendaddba failed");
1238 }
1239
1240 return 1;
1241}
1242
1243
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301244static int ath10k_debug_enable_addba_req(struct sigma_dut *dut, int tid,
1245 const char *sta_mac,
1246 const char *dir_path)
1247{
1248 DIR *dir;
1249 struct dirent *entry;
1250 char buf[128], path[128];
1251 int ret = 0;
1252
1253 dir = opendir(dir_path);
1254 if (!dir)
1255 return 0;
1256
1257 while ((entry = readdir(dir))) {
1258 ret = 1;
1259
1260 if (strcmp(entry->d_name, ".") == 0 ||
1261 strcmp(entry->d_name, "..") == 0)
1262 continue;
1263
1264 snprintf(path, sizeof(path) - 1, "%s/%s",
1265 dir_path, entry->d_name);
1266 path[sizeof(path) - 1] = 0;
1267
1268 if (strcmp(entry->d_name, sta_mac) == 0) {
1269 snprintf(buf, sizeof(buf), "echo 1 > %s/aggr_mode",
1270 path);
1271 if (system(buf) != 0) {
1272 sigma_dut_print(dut, DUT_MSG_ERROR,
1273 "Failed to set aggr mode for ath10k");
1274 }
1275
1276 snprintf(buf, sizeof(buf), "echo %d 32 > %s/addba",
1277 tid, path);
1278 if (system(buf) != 0) {
1279 sigma_dut_print(dut, DUT_MSG_ERROR,
1280 "Failed to set addbareq for ath10k");
1281 }
1282
1283 break;
1284 }
1285
1286 /* Recursively search subdirectories */
1287 ath10k_debug_enable_addba_req(dut, tid, sta_mac, path);
1288 }
1289
1290 closedir(dir);
1291
1292 return ret;
1293}
1294
1295
1296static int ath10k_ap_send_addba_req(struct sigma_dut *dut,
1297 struct sigma_cmd *cmd)
1298{
1299 const char *val;
1300 int tid = 0;
1301
1302 val = get_param(cmd, "TID");
1303 if (val)
1304 tid = atoi(val);
1305
1306 val = get_param(cmd, "sta_mac_address");
1307 if (!val) {
1308 sigma_dut_print(dut, DUT_MSG_ERROR,
1309 "Failed to parse station MAC address");
1310 return 0;
1311 }
1312
1313 return ath10k_debug_enable_addba_req(dut, tid, val,
1314 "/sys/kernel/debug/ieee80211");
1315}
1316
1317
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001318static int cmd_ap_send_addba_req(struct sigma_dut *dut, struct sigma_conn *conn,
1319 struct sigma_cmd *cmd)
1320{
1321 /* const char *name = get_param(cmd, "NAME"); */
1322 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301323 struct stat s;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001324
1325 switch (get_driver_type()) {
1326 case DRIVER_ATHEROS:
1327 return ath_ap_send_addba_req(dut, conn, cmd);
1328 case DRIVER_OPENWRT:
1329 switch (get_openwrt_driver_type()) {
1330 case OPENWRT_DRIVER_ATHEROS:
1331 return ath_ap_send_addba_req(dut, conn, cmd);
1332 default:
1333 send_resp(dut, conn, SIGMA_ERROR,
1334 "errorCode,ap_send_addba_req not supported with this driver");
1335 return 0;
1336 }
Pradeep Reddy POTTETIfdb04912016-08-02 14:16:24 +05301337 case DRIVER_WCN:
1338 case DRIVER_LINUX_WCN:
1339 /* AP automatically sends ADDBA request after association. */
1340 sigma_dut_print(dut, DUT_MSG_INFO,
1341 "ap_send_addba_req command ignored");
1342 return 1;
Mohammed Shafi Shajakhana0535d42016-06-17 11:55:00 +05301343 case DRIVER_MAC80211:
1344 if (stat("/sys/module/ath10k_core", &s) == 0)
1345 return ath10k_ap_send_addba_req(dut, cmd);
1346 /* fall through */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001347 default:
1348 send_resp(dut, conn, SIGMA_ERROR,
1349 "errorCode,ap_send_addba_req not supported with this driver");
1350 return 0;
1351 }
1352}
1353
1354
1355static int cmd_ap_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1356 struct sigma_cmd *cmd)
1357{
1358 /* const char *name = get_param(cmd, "NAME"); */
1359 const char *val;
1360 unsigned int wlan_tag = 1;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301361 const char *security;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001362
1363 val = get_param(cmd, "WLAN_TAG");
1364 if (val)
1365 wlan_tag = atoi(val);
1366
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301367 security = get_param(cmd, "Security");
1368
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001369 if (wlan_tag > 1) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001370 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301371 if (!val)
1372 val = get_param(cmd, "KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373 if (val) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001374 if (strcasecmp(val, "NONE") == 0) {
1375 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OPEN;
1376 } else if (strcasecmp(val, "OSEN") == 0 &&
1377 wlan_tag == 2) {
1378 /*
1379 * OSEN only supported on WLAN_TAG = 2 for now
1380 */
1381 dut->ap_tag_key_mgmt[wlan_tag - 2] = AP2_OSEN;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301382 } else if (strcasecmp(val, "WPA2-PSK") == 0 ||
1383 (security &&
1384 strcasecmp(security, "PSK") == 0 &&
1385 strcasecmp(val, "WPA2") == 0)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07001386 dut->ap_tag_key_mgmt[wlan_tag - 2] =
1387 AP2_WPA2_PSK;
1388 } else {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001389 send_resp(dut, conn, SIGMA_INVALID,
1390 "errorCode,Unsupported KEYMGNT");
1391 return 0;
1392 }
1393 return 1;
1394 }
1395 }
1396
1397 val = get_param(cmd, "KEYMGNT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301398 if (!val)
1399 val = get_param(cmd,"KeyMgmtType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001400 if (val) {
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301401 if (strcasecmp(val, "WPA2-PSK") == 0 ||
1402 (security && strcasecmp(security, "PSK") == 0 &&
1403 strcasecmp(val, "WPA2") == 0)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001404 dut->ap_key_mgmt = AP_WPA2_PSK;
1405 dut->ap_cipher = AP_CCMP;
1406 } else if (strcasecmp(val, "WPA2-EAP") == 0 ||
1407 strcasecmp(val, "WPA2-Ent") == 0) {
1408 dut->ap_key_mgmt = AP_WPA2_EAP;
1409 dut->ap_cipher = AP_CCMP;
Jouni Malinenad395a22017-09-01 21:13:46 +03001410 } else if (strcasecmp(val, "SuiteB") == 0) {
1411 dut->ap_key_mgmt = AP_SUITEB;
1412 dut->ap_cipher = AP_GCMP_256;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001413 } else if (strcasecmp(val, "WPA-PSK") == 0) {
1414 dut->ap_key_mgmt = AP_WPA_PSK;
1415 dut->ap_cipher = AP_TKIP;
1416 } else if (strcasecmp(val, "WPA-EAP") == 0 ||
1417 strcasecmp(val, "WPA-Ent") == 0) {
1418 dut->ap_key_mgmt = AP_WPA_EAP;
1419 dut->ap_cipher = AP_TKIP;
1420 } else if (strcasecmp(val, "WPA2-Mixed") == 0) {
1421 dut->ap_key_mgmt = AP_WPA2_EAP_MIXED;
1422 dut->ap_cipher = AP_CCMP_TKIP;
1423 } else if (strcasecmp(val, "WPA2-PSK-Mixed") == 0) {
1424 dut->ap_key_mgmt = AP_WPA2_PSK_MIXED;
1425 dut->ap_cipher = AP_CCMP_TKIP;
Jouni Malinen30824df2017-08-22 21:21:38 +03001426 } else if (strcasecmp(val, "WPA2-SAE") == 0) {
1427 dut->ap_key_mgmt = AP_WPA2_SAE;
1428 dut->ap_cipher = AP_CCMP;
1429 } else if (strcasecmp(val, "WPA2-PSK-SAE") == 0) {
1430 dut->ap_key_mgmt = AP_WPA2_PSK_SAE;
1431 dut->ap_cipher = AP_CCMP;
Jouni Malinen147b3c32017-10-09 16:51:54 +03001432 } else if (strcasecmp(val, "OWE") == 0) {
1433 dut->ap_key_mgmt = AP_WPA2_OWE;
1434 dut->ap_cipher = AP_CCMP;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435 } else if (strcasecmp(val, "NONE") == 0) {
1436 dut->ap_key_mgmt = AP_OPEN;
1437 dut->ap_cipher = AP_PLAIN;
1438 } else {
1439 send_resp(dut, conn, SIGMA_INVALID,
1440 "errorCode,Unsupported KEYMGNT");
1441 return 0;
1442 }
1443 }
1444
Jouni Malinen30824df2017-08-22 21:21:38 +03001445 val = get_param(cmd, "ECGroupID");
1446 if (val) {
Jouni Malinened670f42017-08-31 01:39:28 +03001447 free(dut->ap_sae_groups);
1448 dut->ap_sae_groups = strdup(val);
Jouni Malinen30824df2017-08-22 21:21:38 +03001449 }
1450
Jouni Malinen2f524ce2017-08-31 01:43:29 +03001451 val = get_param(cmd, "AntiCloggingThreshold");
1452 if (val)
1453 dut->sae_anti_clogging_threshold = atoi(val);
1454
Jouni Malinenb347db02017-09-02 01:36:03 +03001455 val = get_param(cmd, "Reflection");
1456 if (val)
1457 dut->sae_reflection = strcasecmp(val, "SAE") == 0;
1458
Jouni Malinen68143132017-09-02 02:34:08 +03001459 val = get_param(cmd, "InvalidSAEElement");
1460 if (val) {
1461 free(dut->sae_commit_override);
1462 dut->sae_commit_override = strdup(val);
1463 }
1464
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001465 val = get_param(cmd, "ENCRYPT");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301466 if (!val)
1467 val = get_param(cmd, "EncpType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001468 if (val) {
1469 if (strcasecmp(val, "WEP") == 0) {
1470 dut->ap_cipher = AP_WEP;
1471 } else if (strcasecmp(val, "TKIP") == 0) {
1472 dut->ap_cipher = AP_TKIP;
1473 } else if (strcasecmp(val, "AES") == 0 ||
1474 strcasecmp(val, "AES-CCMP") == 0) {
1475 dut->ap_cipher = AP_CCMP;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001476 } else if (strcasecmp(val, "AES-GCMP") == 0) {
1477 dut->ap_cipher = AP_GCMP_128;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001478 } else {
1479 send_resp(dut, conn, SIGMA_INVALID,
1480 "errorCode,Unsupported ENCRYPT");
1481 return 0;
1482 }
1483 }
1484
Jouni Malinen3d633da2017-09-14 22:19:21 +03001485 val = get_param(cmd, "PairwiseCipher");
1486 if (val) {
1487 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1488 dut->ap_cipher = AP_GCMP_256;
1489 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1490 dut->ap_cipher = AP_CCMP_256;
1491 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1492 dut->ap_cipher = AP_GCMP_128;
1493 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1494 dut->ap_cipher = AP_CCMP;
Jouni Malinend538c782017-11-17 12:13:04 +02001495 } else if (strcasecmp(val, "AES-CCMP-128 AES-GCMP-256") == 0 ||
1496 strcasecmp(val, "AES-GCMP-256 AES-CCMP-128") == 0) {
1497 dut->ap_cipher = AP_CCMP_128_GCMP_256;
Jouni Malinen3d633da2017-09-14 22:19:21 +03001498 } else {
1499 send_resp(dut, conn, SIGMA_INVALID,
1500 "errorCode,Unsupported PairwiseCipher");
1501 return 0;
1502 }
1503 }
1504
Jouni Malinen2ba24492017-11-17 12:43:59 +02001505 val = get_param(cmd, "GroupCipher");
1506 if (val) {
1507 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1508 dut->ap_group_cipher = AP_GCMP_256;
1509 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1510 dut->ap_group_cipher = AP_CCMP_256;
1511 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1512 dut->ap_group_cipher = AP_GCMP_128;
1513 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1514 dut->ap_group_cipher = AP_CCMP;
1515 } else {
1516 send_resp(dut, conn, SIGMA_INVALID,
1517 "errorCode,Unsupported GroupCipher");
1518 return 0;
1519 }
1520 }
1521
Jouni Malinen3d633da2017-09-14 22:19:21 +03001522 val = get_param(cmd, "GroupMgntCipher");
1523 if (val) {
1524 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1525 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_256;
1526 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1527 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_256;
1528 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1529 dut->ap_group_mgmt_cipher = AP_BIP_GMAC_128;
1530 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1531 dut->ap_group_mgmt_cipher = AP_BIP_CMAC_128;
1532 } else {
1533 send_resp(dut, conn, SIGMA_INVALID,
1534 "errorCode,Unsupported GroupMgntCipher");
1535 return 0;
1536 }
1537 }
1538
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001539 val = get_param(cmd, "WEPKEY");
1540 if (val) {
1541 size_t len;
1542 if (dut->ap_cipher != AP_WEP) {
1543 send_resp(dut, conn, SIGMA_INVALID,
1544 "errorCode,Unexpected WEPKEY without WEP "
1545 "configuration");
1546 return 0;
1547 }
1548 len = strlen(val);
1549 if (len != 10 && len != 26) {
1550 send_resp(dut, conn, SIGMA_INVALID,
1551 "errorCode,Unexpected WEPKEY length");
1552 return 0;
1553 }
1554 snprintf(dut->ap_wepkey, sizeof(dut->ap_wepkey), "%s", val);
1555 }
1556
1557 val = get_param(cmd, "PSK");
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301558 if (!val)
1559 val = get_param(cmd, "passphrase");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001560 if (val) {
Jouni Malinen2126f422017-10-11 23:24:33 +03001561 if (dut->ap_key_mgmt != AP_WPA2_SAE && strlen(val) > 64)
1562 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001563 if (strlen(val) > sizeof(dut->ap_passphrase) - 1)
1564 return -1;
1565 snprintf(dut->ap_passphrase, sizeof(dut->ap_passphrase),
1566 "%s", val);
1567 }
1568
Jouni Malinen63370622017-11-18 17:47:13 +02001569 val = get_param(cmd, "PSKHEX");
1570 if (val) {
1571 if (strlen(val) != 64)
1572 return -1;
1573 strlcpy(dut->ap_psk, val, sizeof(dut->ap_psk));
1574 }
1575
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301576 if (dut->program == PROGRAM_OCE && dut->dev_role == DEVROLE_STA_CFON)
1577 dut->ap_pmf = AP_PMF_OPTIONAL;
1578
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001579 val = get_param(cmd, "PMF");
1580 if (val) {
1581 if (strcasecmp(val, "Disabled") == 0) {
1582 dut->ap_pmf = AP_PMF_DISABLED;
1583 } else if (strcasecmp(val, "Optional") == 0) {
1584 dut->ap_pmf = AP_PMF_OPTIONAL;
1585 } else if (strcasecmp(val, "Required") == 0) {
1586 dut->ap_pmf = AP_PMF_REQUIRED;
1587 } else {
1588 send_resp(dut, conn, SIGMA_INVALID,
1589 "errorCode,Unsupported PMF");
1590 return 0;
1591 }
1592 }
1593
1594 if (dut->ap_key_mgmt == AP_OPEN) {
1595 dut->ap_hs2 = 0;
1596 dut->ap_pmf = AP_PMF_DISABLED;
1597 }
1598
1599 dut->ap_add_sha256 = 0;
1600 val = get_param(cmd, "SHA256AD");
1601 if (val == NULL)
1602 val = get_param(cmd, "SHA256");
1603 if (val) {
1604 if (strcasecmp(val, "Disabled") == 0) {
1605 } else if (strcasecmp(val, "Enabled") == 0) {
1606 dut->ap_add_sha256 = 1;
1607 } else {
1608 send_resp(dut, conn, SIGMA_INVALID,
1609 "errorCode,Unsupported PMF");
1610 return 0;
1611 }
1612 }
1613
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05301614 val = get_param(cmd, "PreAuthentication");
1615 if (val) {
1616 if (strcasecmp(val, "disabled") == 0) {
1617 dut->ap_rsn_preauth = 0;
1618 } else if (strcasecmp(val, "enabled") == 0) {
1619 dut->ap_rsn_preauth = 1;
1620 } else {
1621 send_resp(dut, conn, SIGMA_INVALID,
1622 "errorCode,Unsupported PreAuthentication value");
1623 return 0;
1624 }
1625 }
1626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001627 return 1;
1628}
1629
1630
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301631int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
1632 struct sigma_cmd *cmd)
1633{
1634 int status;
1635
1636 status = cmd_ap_set_wireless(dut, conn, cmd);
1637 if (status != 1)
1638 return status;
Ankita Bajaj0d212e82017-11-27 15:54:57 +05301639 status = cmd_ap_set_security(dut, conn, cmd);
1640 if (status != 1)
1641 return status;
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301642 return cmd_ap_config_commit(dut, conn, cmd);
1643}
1644
1645
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001646static int cmd_ap_set_radius(struct sigma_dut *dut, struct sigma_conn *conn,
1647 struct sigma_cmd *cmd)
1648{
1649 /* const char *name = get_param(cmd, "NAME"); */
1650 const char *val;
1651 unsigned int wlan_tag = 1, radius_port = 0;
1652 char *radius_ipaddr = NULL, *radius_password = NULL;
1653
1654 val = get_param(cmd, "WLAN_TAG");
1655 if (val) {
1656 wlan_tag = atoi(val);
1657 if (wlan_tag != 1 && wlan_tag != 2) {
1658 send_resp(dut, conn, SIGMA_INVALID,
1659 "errorCode,Invalid WLAN_TAG");
1660 return 0;
1661 }
1662 }
1663
1664 val = get_param(cmd, "PORT");
1665 if (val)
1666 radius_port = atoi(val);
1667
1668 if (wlan_tag == 1) {
1669 if (radius_port)
1670 dut->ap_radius_port = radius_port;
1671 radius_ipaddr = dut->ap_radius_ipaddr;
1672 radius_password = dut->ap_radius_password;
1673 } else if (wlan_tag == 2) {
1674 if (radius_port)
1675 dut->ap2_radius_port = radius_port;
1676 radius_ipaddr = dut->ap2_radius_ipaddr;
1677 radius_password = dut->ap2_radius_password;
1678 }
1679
1680 val = get_param(cmd, "IPADDR");
1681 if (val) {
1682 if (strlen(val) > sizeof(dut->ap_radius_ipaddr) - 1)
1683 return -1;
1684 snprintf(radius_ipaddr, sizeof(dut->ap_radius_ipaddr),
1685 "%s", val);
1686 }
1687
1688 val = get_param(cmd, "PASSWORD");
1689 if (val) {
1690 if (strlen(val) > sizeof(dut->ap_radius_password) - 1)
1691 return -1;
1692 snprintf(radius_password,
1693 sizeof(dut->ap_radius_password), "%s", val);
1694 }
1695
1696 return 1;
1697}
1698
1699
1700static void owrt_ap_set_radio(struct sigma_dut *dut, int id,
1701 const char *key, const char *val)
1702{
1703 char buf[100];
1704
1705 if (val == NULL) {
1706 snprintf(buf, sizeof(buf),
1707 "uci delete wireless.wifi%d.%s", id, key);
1708 run_system(dut, buf);
1709 return;
1710 }
1711
1712 snprintf(buf, sizeof(buf), "uci set wireless.wifi%d.%s=%s",
1713 id, key, val);
1714 run_system(dut, buf);
1715}
1716
1717
1718static void owrt_ap_set_list_radio(struct sigma_dut *dut, int id,
1719 const char *key, const char *val)
1720{
1721 char buf[256];
1722
1723 if (val == NULL) {
1724 snprintf(buf, sizeof(buf),
1725 "uci del_list wireless.wifi%d.%s", id, key);
1726 run_system(dut, buf);
1727 return;
1728 }
1729
1730 snprintf(buf, sizeof(buf), "uci add_list wireless.wifi%d.%s=%s",
1731 id, key, val);
1732 run_system(dut, buf);
1733}
1734
1735
1736static void owrt_ap_set_vap(struct sigma_dut *dut, int id, const char *key,
1737 const char *val)
1738{
1739 char buf[256];
1740
1741 if (val == NULL) {
1742 snprintf(buf, sizeof(buf),
1743 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1744 run_system(dut, buf);
1745 return;
1746 }
1747
1748 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1749 id, key, val);
1750 run_system(dut, buf);
1751}
1752
1753
1754static void owrt_ap_set_list_vap(struct sigma_dut *dut, int id,
1755 const char *key, const char *val)
1756{
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07001757 char buf[1024];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001758
1759 if (val == NULL) {
1760 snprintf(buf, sizeof(buf),
1761 "uci del_list wireless.@wifi-iface[%d].%s", id, key);
1762 run_system(dut, buf);
1763 return;
1764 }
1765
1766 snprintf(buf, sizeof(buf),
1767 "uci add_list wireless.@wifi-iface[%d].%s=%s",
1768 id, key, val);
1769 run_system(dut, buf);
1770}
1771
1772
1773static void owrt_ap_add_vap(struct sigma_dut *dut, int id, const char *key,
1774 const char *val)
1775{
1776 char buf[256];
1777
1778 if (val == NULL) {
1779 snprintf(buf, sizeof(buf),
1780 "uci delete wireless.@wifi-iface[%d].%s", id, key);
1781 run_system(dut, buf);
1782 return;
1783 }
1784
1785 snprintf(buf, sizeof(buf), "uci add wireless wifi-iface");
1786 run_system(dut, buf);
1787 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1788 id, key, val);
1789 run_system(dut, buf);
1790 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1791 id, "network", "lan");
1792 run_system(dut, buf);
1793 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1794 id, "mode", "ap");
1795 run_system(dut, buf);
1796 snprintf(buf, sizeof(buf), "uci set wireless.@wifi-iface[%d].%s=%s",
1797 id, "encryption", "none");
1798 run_system(dut, buf);
1799}
1800
1801
1802#define OPENWRT_MAX_NUM_RADIOS 3
1803static void owrt_ap_config_radio(struct sigma_dut *dut)
1804{
1805 int radio_id[MAX_RADIO] = { 0, 1 };
1806 int radio_count, radio_no;
1807 char buf[64];
1808
1809 for (radio_count = 0; radio_count < OPENWRT_MAX_NUM_RADIOS;
1810 radio_count++) {
1811 snprintf(buf, sizeof(buf), "%s%d", "wifi", radio_count);
1812 for (radio_no = 0; radio_no < MAX_RADIO; radio_no++) {
1813 if (!sigma_radio_ifname[radio_no] ||
1814 strcmp(sigma_radio_ifname[radio_no], buf) != 0)
1815 continue;
1816 owrt_ap_set_radio(dut, radio_count, "disabled", "0");
1817 owrt_ap_set_vap(dut, radio_count, "device", buf);
1818 radio_id[radio_no] = radio_count;
1819 }
1820 }
1821
1822 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1823 switch (dut->ap_mode) {
1824 case AP_11g:
1825 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11g");
1826 break;
1827 case AP_11b:
1828 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11b");
1829 break;
1830 case AP_11ng:
1831 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1832 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1833 break;
1834 case AP_11a:
1835 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11a");
1836 break;
1837 case AP_11na:
1838 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11na");
1839 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1840 break;
1841 case AP_11ac:
1842 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ac");
1843 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1844 break;
1845 case AP_inval:
1846 sigma_dut_print(dut, DUT_MSG_ERROR,
1847 "MODE NOT SPECIFIED!");
1848 return;
1849 default:
1850 owrt_ap_set_radio(dut, radio_id[0], "hwmode", "11ng");
1851 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1852 break;
1853 }
1854
1855 if (dut->ap_is_dual) {
1856 /* Hardware mode (11a/b/g/n/ac) & HT mode selection */
1857 switch (dut->ap_mode_1) {
1858 case AP_11g:
1859 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11g");
1860 break;
1861 case AP_11b:
1862 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11b");
1863 break;
1864 case AP_11ng:
1865 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1866 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1867 break;
1868 case AP_11a:
1869 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11a");
1870 break;
1871 case AP_11na:
1872 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11na");
1873 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1874 break;
1875 case AP_11ac:
1876 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ac");
1877 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT80");
1878 break;
1879 case AP_inval:
1880 sigma_dut_print(dut, DUT_MSG_ERROR,
1881 "MODE NOT SPECIFIED!");
1882 return;
1883 default:
1884 owrt_ap_set_radio(dut, radio_id[1], "hwmode", "11ng");
1885 owrt_ap_set_radio(dut, radio_id[1], "htmode", "HT20");
1886 break;
1887 }
1888
1889 }
1890
1891 /* Channel */
1892 snprintf(buf, sizeof(buf), "%d", dut->ap_channel);
1893 owrt_ap_set_radio(dut, radio_id[0], "channel", buf);
1894
1895 switch (dut->ap_chwidth) {
1896 case AP_20:
1897 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT20");
1898 break;
1899 case AP_40:
1900 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT40");
1901 break;
1902 case AP_80:
1903 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT80");
1904 break;
1905 case AP_160:
1906 owrt_ap_set_radio(dut, radio_id[0], "htmode", "HT160");
1907 break;
1908 case AP_AUTO:
1909 default:
1910 break;
1911 }
1912
1913 if (dut->ap_channel == 140 || dut->ap_channel == 144) {
1914 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
1915 owrt_ap_set_radio(dut, radio_id[0], "set_ch_144", "3");
1916 }
1917
1918 if (dut->ap_is_dual) {
1919 snprintf(buf, sizeof(buf), "%d", dut->ap_channel_1);
1920 owrt_ap_set_radio(dut, radio_id[1], "channel", buf);
1921 }
1922
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001923 /* Country Code */
1924 if (dut->ap_reg_domain == REG_DOMAIN_GLOBAL) {
1925 const char *country;
1926
1927 country = dut->ap_countrycode[0] ? dut->ap_countrycode : "US";
1928 snprintf(buf, sizeof(buf), "%s4", country);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001929 owrt_ap_set_radio(dut, radio_id[0], "country", buf);
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07001930 } else if (dut->ap_countrycode[0]) {
1931 owrt_ap_set_radio(dut, radio_id[0], "country",
1932 dut->ap_countrycode);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001933 }
1934
1935 if (dut->ap_disable_protection == 1) {
1936 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'0 0'");
1937 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'1 0'");
1938 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'2 0'");
1939 owrt_ap_set_list_radio(dut, radio_id[0], "aggr_burst", "'3 0'");
1940 }
1941}
1942
1943
1944static int owrt_ap_config_vap_hs2(struct sigma_dut *dut, int vap_id)
1945{
1946 char buf[256];
1947
1948 snprintf(buf, sizeof(buf), "%d", dut->ap_hs2);
1949 owrt_ap_set_vap(dut, vap_id, "hs20", buf);
1950 owrt_ap_set_vap(dut, vap_id, "qbssload", "1");
1951 owrt_ap_set_vap(dut, vap_id, "hs20_deauth_req_timeout","3");
1952
1953 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1954 "'eng:Wi-Fi Alliance'");
1955
1956 owrt_ap_set_list_vap(dut, vap_id, "hs20_oper_friendly_name",
1957 "'chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f'");
1958
1959 if (dut->ap_wan_metrics == 1)
1960 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1961 "'01:2500:384:0:0:10'");
1962 else if (dut->ap_wan_metrics == 1)
1963 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1964 "'01:1500:384:20:20:10'");
1965 else if (dut->ap_wan_metrics == 2)
1966 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1967 "'01:1500:384:20:20:10'");
1968 else if (dut->ap_wan_metrics == 3)
1969 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1970 "'01:2000:1000:20:20:10'");
1971 else if (dut->ap_wan_metrics == 4)
1972 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1973 "'01:8000:1000:20:20:10'");
1974 else if (dut->ap_wan_metrics == 5)
1975 owrt_ap_set_vap(dut, vap_id, "hs20_wan_metrics",
1976 "'01:9000:5000:20:20:10'");
1977
1978 if (dut->ap_conn_capab == 1) {
1979 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab", "'1:0:0'");
1980 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1981 "'6:20:1'");
1982 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1983 "'6:22:0'");
1984 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1985 "'6:80:1'");
1986 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1987 "'6:443:1'");
1988 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1989 "'6:1723:0'");
1990 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1991 "'6:5060:0'");
1992 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1993 "'17:500:1'");
1994 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1995 "'17:5060:0'");
1996 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1997 "'17:4500:1'");
1998 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
1999 "'50:0:1'");
2000 } else if (dut->ap_conn_capab == 2) {
2001 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2002 "'6:80:1'");
2003 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2004 "'6:443:1'");
2005 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2006 "'17:5060:1'");
2007 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2008 "'6:5060:1'");
2009 } else if (dut->ap_conn_capab == 3) {
2010 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2011 "'6:80:1'");
2012 owrt_ap_set_list_vap(dut, vap_id, "hs20_conn_capab",
2013 "'6:443:1'");
2014 }
2015
2016 if (dut->ap_oper_class == 1)
2017 snprintf(buf, sizeof(buf), "%s", "51");
2018 else if (dut->ap_oper_class == 2)
2019 snprintf(buf, sizeof(buf), "%s", "73");
2020 else if (dut->ap_oper_class == 3)
2021 snprintf(buf, sizeof(buf), "%s", "5173");
2022
2023 if (dut->ap_oper_class)
2024 owrt_ap_set_vap(dut, vap_id, "hs20_operating_class", buf);
2025
2026 if (dut->ap_osu_provider_list) {
2027 char *osu_friendly_name = NULL;
2028 char *osu_icon = NULL;
2029 char *osu_ssid = NULL;
2030 char *osu_nai = NULL;
2031 char *osu_service_desc = NULL;
2032 char *hs20_icon_filename = NULL;
2033 char hs20_icon[150];
2034 int osu_method;
2035
2036 hs20_icon_filename = "icon_red_zxx.png";
2037 if (dut->ap_osu_icon_tag == 2)
2038 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2039 snprintf(hs20_icon, sizeof(hs20_icon),
2040 "'128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s'",
2041 hs20_icon_filename);
2042 osu_icon = "icon_red_zxx.png";
2043 osu_ssid = "OSU";
2044 osu_friendly_name = "'kor:SP 빨강 테스트 전용'";
2045 osu_service_desc = "'kor:테스트 목적으로 무료 서비스'";
2046 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2047 dut->ap_osu_method[0];
2048
2049 if (strlen(dut->ap_osu_server_uri[0]))
2050 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2051 dut->ap_osu_server_uri[0]);
2052 else
2053 owrt_ap_set_list_vap(dut, vap_id, "osu_server_uri",
2054 "'https://osu-server.r2-testbed.wi-fi.org/'");
2055 switch (dut->ap_osu_provider_list) {
2056 case 1:
2057 case 101:
2058 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2059 "'eng:SP Red Test Only'");
2060 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2061 "'eng:Free service for test purpose'");
2062 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2063 hs20_icon);
2064
2065 hs20_icon_filename = "icon_red_eng.png";
2066 if (dut->ap_osu_icon_tag == 2)
2067 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2068
2069 snprintf(hs20_icon, sizeof(hs20_icon),
2070 "'160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s'",
2071 hs20_icon_filename);
2072 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2073 "icon_red_eng.png");
2074 break;
2075 case 2:
2076 case 102:
2077 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2078 "'eng:Wireless Broadband Alliance'");
2079 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2080 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002081 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002082 if (dut->ap_osu_icon_tag == 2)
2083 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2084
2085 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002086 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002087 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002088 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002089 osu_friendly_name = "'kor:와이어리스 브로드밴드 얼라이언스'";
2090 break;
2091 case 3:
2092 case 103:
2093 osu_friendly_name = "spa:SP Red Test Only";
2094 osu_service_desc = "spa:Free service for test purpose";
2095 break;
2096 case 4:
2097 case 104:
2098 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002099 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002100 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2101 "'eng:Free service for test purpose'");
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002102 hs20_icon_filename = "icon_orange_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002103 if (dut->ap_osu_icon_tag == 2)
2104 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2105
2106 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002107 "'160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002108 hs20_icon_filename);
2109 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2110 hs20_icon);
2111 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
2112
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002113 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002114 if (dut->ap_osu_icon_tag == 2)
2115 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2116
2117 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002118 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002119 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002120 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002121 break;
2122 case 5:
2123 case 105:
2124 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002125 "'eng:SP Orange Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002126 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2127 "'eng:Free service for test purpose'");
2128 osu_friendly_name = "'kor:SP 파랑 테스트 전용'";
2129
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002130 hs20_icon_filename = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002131 if (dut->ap_osu_icon_tag == 2)
2132 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2133
2134 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002135 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002136 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002137 osu_icon = "icon_orange_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002138 break;
2139 case 6:
2140 case 106:
2141 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2142 "'eng:SP Green Test Only'");
2143 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2144 "'kor:SP 초록 테스트 전용'");
2145
2146 hs20_icon_filename = "icon_green_zxx.png";
2147 if (dut->ap_osu_icon_tag == 2)
2148 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2149
2150 snprintf(hs20_icon, sizeof(hs20_icon),
2151 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
2152 hs20_icon_filename);
2153 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2154 hs20_icon);
2155
2156 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2157 "'icon_green_zxx.png'");
2158 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 :
2159 dut->ap_osu_method[0];
2160
2161 snprintf(buf, sizeof(buf), "%d", osu_method);
2162 owrt_ap_set_vap(dut, vap_id, "osu_method_list", buf);
2163
2164 if (strlen(dut->ap_osu_server_uri[1]))
2165 owrt_ap_set_list_vap(dut, vap_id,
2166 "osu_server_uri",
2167 dut->ap_osu_server_uri[1]);
2168 else
2169 owrt_ap_set_list_vap(dut, vap_id,
2170 "osu_server_uri",
2171 "'https://osu-server.r2-testbed.wi-fi.org/'");
2172
2173 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2174 "'eng:SP Orange Test Only'");
2175
2176 hs20_icon_filename = "icon_orange_zxx.png";
2177 if (dut->ap_osu_icon_tag == 2)
2178 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2179
2180 snprintf(hs20_icon, sizeof(hs20_icon),
2181 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2182 hs20_icon_filename);
2183
2184 osu_icon = "icon_orange_zxx.png";
2185 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2186 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 :
2187 dut->ap_osu_method[1];
2188 osu_service_desc = NULL;
2189 break;
2190 case 7:
2191 case 107:
2192 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002193 "'eng:SP Green Test Only'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002194 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2195 "'eng:Free service for test purpose'");
2196
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002197 hs20_icon_filename = "icon_green_eng.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002198 if (dut->ap_osu_icon_tag == 2)
2199 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2200
2201 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002202 "'160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002203 hs20_icon_filename);
2204 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon",
2205 hs20_icon);
2206
2207 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002208 "'icon_green_eng.png'");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002209 osu_friendly_name = "'kor:SP 오렌지 테스트 전용'";
2210
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002211 hs20_icon_filename = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002212 if (dut->ap_osu_icon_tag == 2)
2213 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2214
2215 snprintf(hs20_icon, sizeof(hs20_icon),
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002216 "'128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s'",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217 hs20_icon_filename);
priyadharshini gowthamancc0e29c2016-10-17 11:48:59 +03002218 osu_icon = "icon_green_zxx.png";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002219 break;
2220 case 8:
2221 case 108:
2222 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2223 "'eng:SP Red Test Only'");
2224 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2225 "'eng:Free service for test purpose'");
2226 osu_ssid = "OSU-Encrypted";
2227 osu_nai = "'anonymous@hotspot.net'";
2228 break;
2229 case 9:
2230 case 109:
2231 osu_ssid = "OSU-OSEN";
2232 osu_nai = "'test-anonymous@wi-fi.org'";
2233 osu_friendly_name = "'eng:SP Orange Test Only'";
2234 hs20_icon_filename = "icon_orange_zxx.png";
2235 if (dut->ap_osu_icon_tag == 2)
2236 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
2237
2238 snprintf(hs20_icon, sizeof(hs20_icon),
2239 "'128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s'",
2240 hs20_icon_filename);
2241 osu_icon = "icon_orange_zxx.png";
2242 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 :
2243 dut->ap_osu_method[0];
2244 osu_service_desc = NULL;
2245 break;
2246 default:
2247 break;
2248 }
2249
2250 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002251 if (strcmp(dut->ap_tag_ssid[0],
2252 dut->ap_osu_ssid) != 0 &&
2253 strcmp(dut->ap_tag_ssid[0], osu_ssid) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002254 sigma_dut_print(dut, DUT_MSG_ERROR,
2255 "OSU_SSID and WLAN_TAG2 SSID differ");
2256 return -2;
2257 }
2258
2259 snprintf(buf, sizeof(buf), "'\"%s\"'",
2260 dut->ap_osu_ssid);
2261 } else {
2262 snprintf(buf, sizeof(buf), "'\"%s\"'", osu_ssid);
2263 }
2264
2265 owrt_ap_set_vap(dut, vap_id, "osu_ssid", buf);
2266
2267
2268 if (osu_friendly_name)
2269 owrt_ap_set_list_vap(dut, vap_id, "osu_friendly_name",
2270 osu_friendly_name);
2271 if (osu_service_desc)
2272 owrt_ap_set_list_vap(dut, vap_id, "osu_service_desc",
2273 osu_service_desc);
2274 if (osu_nai)
2275 owrt_ap_set_vap(dut, vap_id, "osu_nai", osu_nai);
2276
2277 owrt_ap_set_list_vap(dut, vap_id, "hs20_icon", hs20_icon);
2278
2279 if (osu_icon)
2280 owrt_ap_set_list_vap(dut, vap_id, "osu_icon",
2281 osu_icon);
2282
2283 if (dut->ap_osu_provider_list > 100) {
2284 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2285 "0");
2286 } else {
2287 snprintf(buf, sizeof(buf), "%d", osu_method);
2288 owrt_ap_set_list_vap(dut, vap_id, "osu_method_list",
2289 buf);
2290 }
2291 }
2292
2293 return 0;
2294}
2295
2296
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002297static void set_anqp_elem_value(struct sigma_dut *dut, const char *ifname,
2298 char *anqp_string, size_t str_size)
2299{
2300 unsigned char bssid[ETH_ALEN];
2301 unsigned char dummy_mac[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50 };
2302 int preference = 0xff;
2303
2304 get_hwaddr(ifname, bssid);
2305 snprintf(anqp_string, str_size,
2306 "272:3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x3410%02x%02x%02x%02x%02x%02xf70000007330000301%02x",
2307 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5],
2308 preference,
2309 dummy_mac[0], dummy_mac[1], dummy_mac[2],
2310 dummy_mac[3], dummy_mac[4], dummy_mac[5],
2311 preference - 1);
2312}
2313
2314
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002315static void get_if_name(struct sigma_dut *dut, char *ifname_str,
2316 size_t str_size, int wlan_tag)
2317{
Jouni Malinenf8984642017-10-12 00:02:37 +03002318 const char *ifname;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002319 enum driver_type drv;
2320
2321 drv = get_driver_type();
Jouni Malinenf8984642017-10-12 00:02:37 +03002322 if (dut->hostapd_ifname && if_nametoindex(dut->hostapd_ifname) > 0) {
2323 ifname = dut->hostapd_ifname;
2324 } else if (drv == DRIVER_ATHEROS) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002325 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2326 dut->ap_mode == AP_11ac) &&
2327 if_nametoindex("ath1") > 0)
2328 ifname = "ath1";
2329 else
2330 ifname = "ath0";
2331 } else if (drv == DRIVER_OPENWRT) {
2332 if (sigma_radio_ifname[0] &&
2333 strcmp(sigma_radio_ifname[0], "wifi2") == 0)
2334 ifname = "ath2";
2335 else if (sigma_radio_ifname[0] &&
2336 strcmp(sigma_radio_ifname[0], "wifi1") == 0)
2337 ifname = "ath1";
2338 else
2339 ifname = "ath0";
2340 } else {
2341 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
2342 dut->ap_mode == AP_11ac) &&
2343 if_nametoindex("wlan1") > 0)
2344 ifname = "wlan1";
2345 else
2346 ifname = "wlan0";
2347 }
2348
2349 if (drv == DRIVER_OPENWRT && wlan_tag > 1) {
2350 /* Handle tagged-ifname only on OPENWRT for now */
2351 snprintf(ifname_str, str_size, "%s%d", ifname, wlan_tag - 1);
Jouni Malinenf8984642017-10-12 00:02:37 +03002352 } else if (drv == DRIVER_MAC80211 && wlan_tag == 2) {
2353 snprintf(ifname_str, str_size, "%s_1", ifname);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002354 } else {
2355 snprintf(ifname_str, str_size, "%s", ifname);
2356 }
2357}
2358
2359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002360static int owrt_ap_config_vap(struct sigma_dut *dut)
2361{
2362 char buf[256], *temp;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002363 int vap_id = 0, vap_count, i, j;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002364
2365 for (vap_count = 0; vap_count < OPENWRT_MAX_NUM_RADIOS; vap_count++) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002366 snprintf(buf, sizeof(buf), "wifi%d", vap_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002367
2368 for (vap_id = 0; vap_id < MAX_RADIO; vap_id++) {
2369 if (sigma_radio_ifname[vap_id] &&
2370 strcmp(sigma_radio_ifname[vap_id], buf) == 0)
2371 break;
2372 }
2373 if (vap_id == MAX_RADIO)
2374 continue;
2375
2376 /* Single VAP configuration */
2377 if (!dut->ap_is_dual)
2378 vap_id = vap_count;
2379
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002380 for (j = 0; j < MAX_WLAN_TAGS - 1; j++) {
2381 /*
2382 * We keep a separate array of ap_tag_ssid and
2383 * ap_tag_key_mgmt for tags starting from WLAN_TAG=2.
2384 * So j=0 => WLAN_TAG = 2
2385 */
2386 int wlan_tag = j + 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002387
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002388 if (dut->ap_tag_ssid[j][0] == '\0')
2389 continue;
2390
2391 snprintf(buf, sizeof(buf), "%s%d", "wifi", vap_count);
2392 owrt_ap_add_vap(dut, vap_count + (wlan_tag - 1),
2393 "device", buf);
2394 /* SSID */
2395 snprintf(buf, sizeof(buf), "\"%s\"",
2396 dut->ap_tag_ssid[j]);
2397 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2398 "ssid", buf);
2399
2400 if (dut->ap_tag_key_mgmt[j] == AP2_OSEN &&
2401 wlan_tag == 2) {
2402 /* Only supported for WLAN_TAG=2 */
2403 owrt_ap_set_vap(dut, vap_count + 1, "osen",
2404 "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002405 snprintf(buf, sizeof(buf), "wpa2");
2406 owrt_ap_set_vap(dut, vap_count + 1,
2407 "encryption", buf);
2408 snprintf(buf, sizeof(buf), "%s",
2409 dut->ap2_radius_ipaddr);
2410 owrt_ap_set_vap(dut, vap_count + 1,
2411 "auth_server", buf);
2412 snprintf(buf, sizeof(buf), "%d",
2413 dut->ap2_radius_port);
2414 owrt_ap_set_vap(dut, vap_count + 1,
2415 "auth_port", buf);
2416 snprintf(buf, sizeof(buf), "%s",
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002417 dut->ap2_radius_password);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002418 owrt_ap_set_vap(dut, vap_count + 1,
2419 "auth_secret", buf);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002420 } else if (dut->ap_tag_key_mgmt[j] == AP2_WPA2_PSK) {
2421 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2422 "encryption", "psk2+ccmp");
2423 snprintf(buf, sizeof(buf), "\"%s\"",
2424 dut->ap_passphrase);
2425 owrt_ap_set_vap(dut, vap_count + (wlan_tag - 1),
2426 "key", buf);
2427 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
2428 owrt_ap_set_vap(dut, vap_count + 1,
2429 "ieee80211w", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002430 }
2431 }
2432
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002433 /* Now set anqp_elem for wlan_tag = 1 */
2434 if (dut->program == PROGRAM_MBO &&
2435 get_driver_type() == DRIVER_OPENWRT) {
2436 char anqp_string[200];
2437
2438 set_anqp_elem_value(dut, sigma_radio_ifname[0],
2439 anqp_string, sizeof(anqp_string));
2440 owrt_ap_set_list_vap(dut, vap_count, "anqp_elem",
2441 anqp_string);
2442 }
2443
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002444 /* SSID */
2445 snprintf(buf, sizeof(buf), "\"%s\"", dut->ap_ssid);
2446 owrt_ap_set_vap(dut, vap_count, "ssid", buf);
2447
2448 /* Encryption */
2449 switch (dut->ap_key_mgmt) {
2450 case AP_OPEN:
2451 if (dut->ap_cipher == AP_WEP) {
2452 owrt_ap_set_vap(dut, vap_count, "encryption",
2453 "wep-mixed");
2454 owrt_ap_set_vap(dut, vap_count, "key",
2455 dut->ap_wepkey);
2456 } else {
2457 owrt_ap_set_vap(dut, vap_count, "encryption",
2458 "none");
2459 }
2460 break;
2461 case AP_WPA2_PSK:
2462 case AP_WPA2_PSK_MIXED:
2463 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03002464 case AP_WPA2_SAE:
2465 case AP_WPA2_PSK_SAE:
2466 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002467 if (dut->ap_key_mgmt == AP_WPA2_PSK) {
2468 snprintf(buf, sizeof(buf), "psk2");
2469 } else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED) {
2470 snprintf(buf, sizeof(buf), "psk-mixed");
2471 } else {
2472 snprintf(buf, sizeof(buf), "psk");
2473 }
2474
Peng Xu591be452017-05-10 17:27:28 -07002475 if (dut->ap_cipher == AP_CCMP_TKIP)
2476 strlcat(buf, "+ccmp+tkip", sizeof(buf));
2477 else if (dut->ap_cipher == AP_TKIP)
2478 strlcat(buf, "+tkip", sizeof(buf));
2479 else
2480 strlcat(buf, "+ccmp", sizeof(buf));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002481
2482 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
2483 snprintf(buf, sizeof(buf), "\"%s\"",
2484 dut->ap_passphrase);
2485 owrt_ap_set_vap(dut, vap_count, "key", buf);
2486 break;
2487 case AP_WPA2_EAP:
2488 case AP_WPA2_EAP_MIXED:
2489 case AP_WPA_EAP:
2490 if (dut->ap_key_mgmt == AP_WPA2_EAP) {
2491 snprintf(buf, sizeof(buf), "wpa2");
2492 } else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED) {
2493 snprintf(buf, sizeof(buf), "wpa-mixed");
2494 } else {
2495 snprintf(buf, sizeof(buf), "wpa");
2496 }
2497
Peng Xu591be452017-05-10 17:27:28 -07002498 if (dut->ap_cipher == AP_CCMP_TKIP)
2499 strlcat(buf, "+ccmp+tkip", sizeof(buf));
2500 else if (dut->ap_cipher == AP_TKIP)
2501 strlcat(buf, "+tkip", sizeof(buf));
2502 else
2503 strlcat(buf, "+ccmp", sizeof(buf));
2504
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002505 owrt_ap_set_vap(dut, vap_count, "encryption", buf);
2506 snprintf(buf, sizeof(buf), "%s", dut->ap_radius_ipaddr);
2507 owrt_ap_set_vap(dut, vap_count, "auth_server", buf);
2508 snprintf(buf, sizeof(buf), "%d", dut->ap_radius_port);
2509 owrt_ap_set_vap(dut, vap_count, "auth_port", buf);
2510 snprintf(buf, sizeof(buf), "%s",
2511 dut->ap_radius_password);
2512 owrt_ap_set_vap(dut, vap_count, "auth_secret", buf);
2513 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03002514 case AP_SUITEB:
2515 /* TODO */
2516 sigma_dut_print(dut, DUT_MSG_ERROR,
2517 "SuiteB not supported");
2518 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03002519 case AP_WPA2_OWE:
2520 /* TODO */
2521 sigma_dut_print(dut, DUT_MSG_ERROR,
2522 "OWE not supported");
2523 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002524 }
2525
2526 if (!dut->ap_is_dual)
2527 break;
2528 }
2529
2530 if (dut->ap_is_dual)
2531 return 1;
2532
2533 /* PMF */
2534 snprintf(buf, sizeof(buf), "%d", dut->ap_pmf);
2535 owrt_ap_set_vap(dut, vap_id, "ieee80211w", buf);
2536
2537 /* Add SHA256 */
2538 snprintf(buf, sizeof(buf), "%d", dut->ap_add_sha256);
2539 owrt_ap_set_vap(dut, vap_id, "add_sha256", buf);
2540
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05302541 /* Enable RSN preauthentication, if asked to */
2542 snprintf(buf, sizeof(buf), "%d", dut->ap_rsn_preauth);
2543 owrt_ap_set_vap(dut, vap_id, "rsn_preauth", buf);
2544
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 /* Hotspot 2.0 */
2546 if (dut->ap_hs2) {
2547 int ret;
2548
2549 ret = owrt_ap_config_vap_hs2(dut, vap_id);
2550 if (ret)
2551 return ret;
2552 }
2553
2554 /* Interworking */
2555 if (dut->ap_interworking) {
2556 snprintf(buf, sizeof(buf), "%d", dut->ap_access_net_type);
2557 owrt_ap_set_vap(dut, vap_id, "access_network_type", buf);
2558 snprintf(buf, sizeof(buf), "%d", dut->ap_internet);
2559 owrt_ap_set_vap(dut, vap_id, "internet", buf);
2560 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_group);
2561 owrt_ap_set_vap(dut, vap_id, "venue_group", buf);
2562 snprintf(buf, sizeof(buf), "%d", dut->ap_venue_type);
2563 owrt_ap_set_vap(dut, vap_id, "venue_type", buf);
2564 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
2565 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2566
2567 if (dut->ap_gas_cb_delay > 0) {
2568 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
2569 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
2570 }
2571
2572 if (dut->ap_roaming_cons[0]) {
2573 char *rcons, *temp_ptr;
2574
2575 rcons = strdup(dut->ap_roaming_cons);
2576 if (rcons == NULL)
2577 return 0;
2578
2579 temp_ptr = strchr(rcons, ';');
2580
2581 if (temp_ptr)
2582 *temp_ptr++ = '\0';
2583
2584 owrt_ap_set_list_vap(dut, vap_id, "roaming_consortium",
2585 rcons);
2586
2587 if (temp_ptr)
2588 owrt_ap_set_list_vap(dut, vap_id,
2589 "roaming_consortium",
2590 temp_ptr);
2591
2592 free(rcons);
2593 }
2594 }
2595
2596 if (dut->ap_venue_name) {
2597 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
2598 "'P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"'");
2599 owrt_ap_set_list_vap(dut, vap_id, "venue_name",
2600 "\'"ANQP_VENUE_NAME_1_CHI"\'");
2601 }
2602
2603 if (dut->ap_net_auth_type == 1) {
2604 owrt_ap_set_vap(dut, vap_id, "network_auth_type",
2605 "'00https://tandc-server.wi-fi.org'");
2606 } else if (dut->ap_net_auth_type == 2) {
2607 owrt_ap_set_vap(dut, vap_id, "network_auth_type", "'01'");
2608 }
2609
2610 if (dut->ap_nai_realm_list == 1) {
2611 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2612 "'0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]'");
2613 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2614 "'0,wi-fi.org;example.com,13[5:6]'");
2615
2616 } else if (dut->ap_nai_realm_list == 2) {
2617 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2618 "'0,wi-fi.org,21[2:4][5:7]'");
2619 } else if (dut->ap_nai_realm_list == 3) {
2620 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2621 "'0,cisco.com;wi-fi.org,21[2:4][5:7]'");
2622 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2623 "'0,wi-fi.org;example.com,13[5:6]'");
2624 } else if (dut->ap_nai_realm_list == 4) {
2625 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2626 "'0,mail.example.com,21[2:4][5:7],13[5:6]'");
2627 } else if (dut->ap_nai_realm_list == 5) {
2628 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2629 "'0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]'");
2630 } else if (dut->ap_nai_realm_list == 6) {
2631 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2632 "'0,wi-fi.org;mail.example.com,21[2:4][5:7]'");
2633 } else if (dut->ap_nai_realm_list == 7) {
2634 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2635 "'0,wi-fi.org,13[5:6]'");
2636 owrt_ap_set_list_vap(dut, vap_id, "nai_realm",
2637 "'0,wi-fi.org,21[2:4][5:7]'");
2638 }
2639
2640 if (dut->ap_domain_name_list[0])
2641 owrt_ap_set_list_vap(dut, vap_id, "domain_name",
2642 dut->ap_domain_name_list);
2643
2644 if (dut->ap_ip_addr_type_avail)
2645 owrt_ap_set_vap(dut, vap_id, "ipaddr_type_availability",
2646 "'0c'");
2647
2648 temp = buf;
2649
2650 *temp++ = '\'';
2651
2652 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
2653 if (i)
2654 *temp++ = ';';
2655
2656 snprintf(temp,
2657 sizeof(dut->ap_plmn_mcc[i]) +
2658 sizeof(dut->ap_plmn_mnc[i]) + 1,
2659 "%s,%s",
2660 dut->ap_plmn_mcc[i],
2661 dut->ap_plmn_mnc[i]);
2662
2663 temp += strlen(dut->ap_plmn_mcc[i]) +
2664 strlen(dut->ap_plmn_mnc[i]) + 1;
2665 }
2666
2667 *temp++ = '\'';
2668 *temp++ = '\0';
2669
2670 if (i)
2671 owrt_ap_set_vap(dut, vap_id, "anqp_3gpp_cell_net", buf);
2672
2673 if (dut->ap_qos_map_set == 1)
2674 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_1);
2675 else if (dut->ap_qos_map_set == 2)
2676 owrt_ap_set_vap(dut, vap_id, "qos_map_set", QOS_MAP_SET_2);
2677
2678 /* Proxy-ARP */
2679 snprintf(buf, sizeof(buf), "%d", dut->ap_proxy_arp);
2680 owrt_ap_set_vap(dut, vap_id, "proxyarp", buf);
2681
2682 /* DGAF */
2683 snprintf(buf, sizeof(buf), "%d", dut->ap_dgaf_disable);
2684 /* parse to hostapd */
2685 owrt_ap_set_vap(dut, vap_id, "disable_dgaf", buf);
2686 /* parse to wifi driver */
2687 owrt_ap_set_vap(dut, vap_id, "dgaf_disable", buf);
2688
2689 /* HCBSSLoad */
2690 if (dut->ap_bss_load) {
2691 unsigned int bssload = 0;
2692
2693 if (dut->ap_bss_load == 1) {
2694 /* STA count: 1, CU: 50, AAC: 65535 */
2695 bssload = 0x0132ffff;
2696 } else if (dut->ap_bss_load == 2) {
2697 /* STA count: 1, CU: 200, AAC: 65535 */
2698 bssload = 0x01c8ffff;
2699 } else if (dut->ap_bss_load == 3) {
2700 /* STA count: 1, CU: 75, AAC: 65535 */
2701 bssload = 0x014bffff;
2702 }
2703
2704 snprintf(buf, sizeof(buf), "%d", bssload);
2705 owrt_ap_set_vap(dut, vap_id, "hcbssload", buf);
2706 }
2707
2708 /* L2TIF */
2709 if (dut->ap_l2tif)
2710 owrt_ap_set_vap(dut, vap_id, "l2tif", "1");
2711
2712 if (dut->ap_disable_protection == 1)
2713 owrt_ap_set_vap(dut, vap_id, "enablertscts", "0");
2714
Sunil Dutt77b213d2017-09-14 18:24:40 +03002715 if (dut->ap_txBF) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002716 owrt_ap_set_vap(dut, vap_id, "vhtsubfee", "1");
2717 owrt_ap_set_vap(dut, vap_id, "vhtsubfer", "1");
2718 }
2719
Mohammed Shafi Shajakhan061af002016-06-02 20:10:54 +05302720 if (dut->ap_mu_txBF)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002721 owrt_ap_set_vap(dut, vap_id, "vhtmubfer", "1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722
Vasanthakumar Pandurangan2b5431d2016-01-12 15:52:48 +05302723 if (dut->ap_tx_stbc) {
2724 /* STBC and beamforming are mutually exclusive features */
2725 owrt_ap_set_vap(dut, vap_id, "implicitbf", "0");
2726 }
2727
Priyadharshini Gowthaman8fb15042015-11-25 18:27:41 +05302728 /* enable dfsmode */
2729 snprintf(buf, sizeof(buf), "%d", dut->ap_dfs_mode);
2730 owrt_ap_set_vap(dut, vap_id, "doth", buf);
2731
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002732 if (dut->program == PROGRAM_LOC && dut->ap_interworking) {
2733 char anqpval[1024];
2734
2735 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
2736
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002737 if (dut->ap_lci == 1 && strlen(dut->ap_tag_ssid[0]) == 0) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05302738 snprintf(anqpval, sizeof(anqpval),
2739 "'265:0010%s%s060101'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002740 dut->ap_val_lci, dut->ap_infoz);
2741 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2742 }
2743
2744 if (dut->ap_lcr == 1) {
Pradeep Reddy Pottetib48012a2016-11-28 16:58:54 +05302745 snprintf(anqpval, sizeof(anqpval),
2746 "'266:0000b2555302ae%s'",
priyadharshini gowthaman2323d0a2016-09-02 15:48:02 -07002747 dut->ap_val_lcr);
2748 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2749 }
2750
2751 if (dut->ap_fqdn_held == 1 && dut->ap_fqdn_supl == 1)
2752 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
2753 "'267:00110168656c642e6578616d706c652e636f6d0011027375706c2e6578616d706c652e636f6d'");
2754 }
2755
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002756 if (dut->program == PROGRAM_MBO) {
2757 owrt_ap_set_vap(dut, vap_id, "interworking", "1");
2758 owrt_ap_set_vap(dut, vap_id, "mbo", "1");
2759 owrt_ap_set_vap(dut, vap_id, "rrm", "1");
Adil Saeed Musthafa65160c02017-04-10 23:13:38 -07002760 owrt_ap_set_vap(dut, vap_id, "mbo_cell_conn_pref", "1");
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002761
2762 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem",
2763 "'272:34108cfdf0020df1f7000000733000030101'");
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07002764 snprintf(buf, sizeof(buf), "%d", dut->ap_gas_cb_delay);
2765 owrt_ap_set_vap(dut, vap_id, "gas_comeback_delay", buf);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07002766 }
2767
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07002768 if (dut->ap_ft_oa == 1) {
2769 unsigned char self_mac[ETH_ALEN];
2770 char mac_str[20];
2771
2772 owrt_ap_set_vap(dut, vap_id, "ft_over_ds", "0");
2773 owrt_ap_set_vap(dut, vap_id, "ieee80211r", "1");
2774 get_hwaddr(sigma_radio_ifname[0], self_mac);
2775 snprintf(mac_str, sizeof(mac_str),
2776 "%02x:%02x:%02x:%02x:%02x:%02x",
2777 self_mac[0], self_mac[1], self_mac[2],
2778 self_mac[3], self_mac[4], self_mac[5]);
2779 owrt_ap_set_vap(dut, vap_id, "ap_macaddr", mac_str);
2780 owrt_ap_set_vap(dut, vap_id, "ft_psk_generate_local", "1");
2781 owrt_ap_set_vap(dut, vap_id, "kh_key_hex",
2782 "000102030405060708090a0b0c0d0e0f");
2783 snprintf(mac_str, sizeof(mac_str),
2784 "%02x:%02x:%02x:%02x:%02x:%02x",
2785 dut->ft_bss_mac_list[0][0],
2786 dut->ft_bss_mac_list[0][1],
2787 dut->ft_bss_mac_list[0][2],
2788 dut->ft_bss_mac_list[0][3],
2789 dut->ft_bss_mac_list[0][4],
2790 dut->ft_bss_mac_list[0][5]);
2791 owrt_ap_set_vap(dut, vap_id, "ap2_macaddr", mac_str);
2792 }
2793
2794 if ((dut->ap_ft_oa == 1 && dut->ap_name == 0) ||
2795 (dut->ap_ft_oa == 1 && dut->ap_name == 2)) {
2796 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder",
2797 "00:01:02:03:04:06");
2798 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas2.example.com");
2799 owrt_ap_set_vap(dut, vap_id, "nasid", "nas1.example.com");
2800 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", "000102030405");
2801 }
2802
2803 if (dut->ap_ft_oa == 1 && dut->ap_name == 1) {
2804 owrt_ap_set_vap(dut, vap_id, "ap2_r1_key_holder",
2805 "00:01:02:03:04:05");
2806 owrt_ap_set_vap(dut, vap_id, "nasid2", "nas1.example.com");
2807 owrt_ap_set_vap(dut, vap_id, "nasid", "nas2.example.com");
2808 owrt_ap_set_vap(dut, vap_id, "r1_key_holder", "000102030406");
2809 }
2810
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07002811 if (dut->ap_mobility_domain[0])
2812 owrt_ap_set_vap(dut, vap_id, "mobility_domain",
2813 dut->ap_mobility_domain);
2814
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002815 return 1;
2816}
2817
2818
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002819static int owrt_ap_config_vap_anqp(struct sigma_dut *dut)
2820{
2821 char anqpval[1024];
2822 unsigned char addr[6];
2823 unsigned char addr2[6];
2824 struct ifreq ifr;
2825 char *ifname;
2826 int s;
2827 int vap_id = 0;
2828
2829 s = socket(AF_INET, SOCK_DGRAM, 0);
2830 if (s < 0) {
2831 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open socket");
2832 return -1;
2833 }
2834
2835 memset(&ifr, 0, sizeof(ifr));
2836 ifname = "ath0";
Peng Xub8fc5cc2017-05-10 17:27:28 -07002837 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002838 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2839 perror("ioctl");
2840 close(s);
2841 return -1;
2842 }
2843 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
2844
2845 memset(&ifr, 0, sizeof(ifr));
2846 ifname = "ath01";
Peng Xub8fc5cc2017-05-10 17:27:28 -07002847 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002848 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
2849 perror("ioctl");
2850 close(s);
2851 return -1;
2852 }
2853 close(s);
2854 memcpy(addr2, ifr.ifr_hwaddr.sa_data, 6);
2855
2856 snprintf(anqpval, sizeof(anqpval),
2857 "'265:0010%s%s060101070d00%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x'",
2858 dut->ap_val_lci, dut->ap_infoz,
2859 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
2860 addr2[0], addr2[1], addr2[2], addr2[3], addr2[4], addr2[5]);
2861
2862 owrt_ap_set_list_vap(dut, vap_id, "anqp_elem", anqpval);
2863 return 0;
2864}
2865
2866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002867static int owrt_ap_post_config_commit(struct sigma_dut *dut,
2868 struct sigma_conn *conn,
2869 struct sigma_cmd *cmd)
2870{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002871 int ap_security = 0;
2872 int i;
2873
2874 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
2875 if (dut->ap_tag_key_mgmt[i] != AP2_OPEN)
2876 ap_security = 1;
2877 }
2878 if (dut->ap_key_mgmt != AP_OPEN)
2879 ap_security = 1;
2880 if (ap_security) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002881 /* allow some time for hostapd to start before returning
2882 * success */
2883 usleep(500000);
2884
2885 if (run_hostapd_cli(dut, "ping") != 0) {
2886 send_resp(dut, conn, SIGMA_ERROR,
2887 "errorCode,Failed to talk to hostapd");
2888 return 0;
2889 }
2890 }
2891
2892 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
2893 ath_ap_set_params(dut);
2894
2895 /* Send response */
2896 return 1;
2897}
2898
2899
2900static int cmd_owrt_ap_config_commit(struct sigma_dut *dut,
2901 struct sigma_conn *conn,
2902 struct sigma_cmd *cmd)
2903{
2904 /* Stop the AP */
2905 run_system(dut, "wifi down");
2906
2907 /* Reset the wireless configuration */
Mohammed Shafi Shajakhanf789f822016-04-07 18:53:16 +05302908 run_system(dut, "rm -rf /etc/config/wireless");
2909 switch (get_openwrt_driver_type()) {
2910 case OPENWRT_DRIVER_ATHEROS:
2911 run_system(dut, "wifi detect qcawifi > /etc/config/wireless");
2912 break;
2913 default:
2914 run_system(dut, "wifi detect > /etc/config/wireless");
2915 break;
2916 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002917
2918 /* Configure Radio & VAP, commit the config */
2919 owrt_ap_config_radio(dut);
2920 owrt_ap_config_vap(dut);
2921 run_system(dut, "uci commit");
2922
2923 /* Start AP */
2924 run_system(dut, "wifi up");
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002925 if (dut->program != PROGRAM_MBO &&
2926 dut->ap_lci == 1 && dut->ap_interworking &&
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07002927 strlen(dut->ap_tag_ssid[0]) > 0) {
Adil Saeed Musthafaa8d74842017-04-10 23:13:39 -07002928 /*
2929 * MBO has a different ANQP element value which is set in
2930 * owrt_ap_config_vap().
2931 */
priyadharshini gowthaman2500f202016-10-13 17:13:55 -07002932 owrt_ap_config_vap_anqp(dut);
2933 run_system(dut, "uci commit");
2934 run_system(dut, "wifi");
2935 }
2936
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002937 return owrt_ap_post_config_commit(dut, conn, cmd);
2938}
2939
2940
2941static void cmd_owrt_ap_hs2_reset(struct sigma_dut *dut)
2942{
2943 unsigned char bssid[6];
2944 char buf[100];
2945 char *ifname, *radio_name;
2946 int vap_id = 0;
2947
2948 if (sigma_radio_ifname[0] &&
2949 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2950 ifname = "ath2";
2951 radio_name = "wifi2";
2952 vap_id = 2;
2953 } else if (sigma_radio_ifname[0] &&
2954 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2955 ifname = "ath1";
2956 radio_name = "wifi1";
2957 vap_id = 1;
2958 } else {
2959 ifname = "ath0";
2960 radio_name = "wifi0";
2961 vap_id = 0;
2962 }
2963
2964 if (!get_hwaddr(ifname, bssid)) {
2965 snprintf(buf, sizeof(buf), "%s", bssid);
2966 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2967 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2968 "%02x:%02x:%02x:%02x:%02x:%02x",
2969 bssid[0], bssid[1], bssid[2], bssid[3],
2970 bssid[4], bssid[5]);
2971 } else {
2972 if (!get_hwaddr(radio_name, bssid)) {
2973 snprintf(buf, sizeof(buf), "%s", dut->ap_hessid);
2974 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
2975 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
2976 "%02x:%02x:%02x:%02x:%02x:%02x",
2977 bssid[0], bssid[1], bssid[2], bssid[3],
2978 bssid[4], bssid[5]);
2979 } else {
2980 /* Select & enable/disable radios */
2981 if (sigma_radio_ifname[0] &&
2982 strcmp(sigma_radio_ifname[0], "wifi2") == 0) {
2983 /* We want to use wifi2 */
2984 owrt_ap_set_radio(dut, 0, "disabled", "1");
2985 owrt_ap_set_radio(dut, 1, "disabled", "1");
2986 owrt_ap_set_radio(dut, 2, "disabled", "0");
2987 owrt_ap_set_vap(dut, vap_id, "device", "wifi2");
2988 } else if (sigma_radio_ifname[0] &&
2989 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
2990 /* We want to use wifi1 */
2991 owrt_ap_set_radio(dut, 0, "disabled", "1");
2992 owrt_ap_set_radio(dut, 1, "disabled", "0");
2993 owrt_ap_set_vap(dut, vap_id, "device", "wifi1");
2994 } else {
2995 /* We want to use wifi0 */
2996 owrt_ap_set_radio(dut, 0, "disabled", "0");
2997 owrt_ap_set_radio(dut, 1, "disabled", "1");
2998 owrt_ap_set_vap(dut, vap_id, "device", "wifi0");
2999 }
3000
3001 run_system(dut, "uci commit");
3002 run_system(dut, "wifi up");
3003
3004 if (!get_hwaddr(radio_name, bssid)) {
3005 snprintf(buf, sizeof(buf), "%s",
3006 dut->ap_hessid);
3007 owrt_ap_set_vap(dut, vap_id, "hessid", buf);
3008 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
3009 "%02x:%02x:%02x:%02x:%02x:%02x",
3010 bssid[0], bssid[1], bssid[2], bssid[3],
3011 bssid[4], bssid[5]);
3012 }
3013 }
3014 }
3015}
3016
3017
3018static int cmd_ap_reboot(struct sigma_dut *dut, struct sigma_conn *conn,
3019 struct sigma_cmd *cmd)
3020{
3021 switch (get_driver_type()) {
3022 case DRIVER_ATHEROS:
3023 run_system(dut, "apdown");
3024 sleep(1);
3025 run_system(dut, "reboot");
3026 break;
3027 case DRIVER_OPENWRT:
3028 run_system(dut, "wifi down");
3029 sleep(1);
3030 run_system(dut, "reboot");
3031 break;
3032 default:
3033 sigma_dut_print(dut, DUT_MSG_INFO, "Ignore ap_reboot command");
3034 break;
3035 }
3036
3037 return 1;
3038}
3039
3040
3041int ascii2hexstr(const char *str, char *hex)
3042{
3043 int i, length;
3044
3045 length = strlen(str);
3046
3047 for (i = 0; i < length; i++)
3048 snprintf(hex + i * 2, 3, "%X", str[i]);
3049
3050 hex[length * 2] = '\0';
3051 return 1;
3052}
3053
3054
3055static int kill_process(struct sigma_dut *dut, char *proc_name,
3056 unsigned char is_proc_instance_one, int sig)
3057{
3058#ifdef __linux__
3059 struct dirent *dp, *dp_in;
3060 const char *direc = "/proc/";
3061 char buf[100];
3062 DIR *dir = opendir(direc);
3063 DIR *dir_in;
3064 FILE *fp;
3065 char *pid, *temp;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303066 char *saveptr;
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303067 int ret = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003068
3069 if (dir == NULL)
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303070 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003071
3072 while ((dp = readdir(dir)) != NULL) {
3073 if (dp->d_type != DT_DIR)
3074 continue;
3075
3076 snprintf(buf, sizeof(buf), "%s%s", direc, dp->d_name);
3077 dir_in = opendir(buf);
3078 if (dir_in == NULL)
3079 continue;
3080 dp_in = readdir(dir_in);
3081 closedir(dir_in);
3082 if (dp_in == NULL)
3083 continue;
3084 snprintf(buf, sizeof(buf), "%s%s/stat", direc, dp->d_name);
3085 fp = fopen(buf, "r");
3086 if (fp == NULL)
3087 continue;
3088 if (fgets(buf, 100, fp) == NULL)
3089 buf[0] = '\0';
3090 fclose(fp);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303091 pid = strtok_r(buf, " ", &saveptr);
3092 temp = strtok_r(NULL, " ", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003093 if (pid && temp &&
3094 strncmp(temp, proc_name, strlen(proc_name)) == 0) {
3095 sigma_dut_print(dut, DUT_MSG_INFO,
3096 "killing %s process with PID %s",
3097 proc_name, pid);
3098 snprintf(buf, sizeof(buf), "kill -%d %d", sig,
3099 atoi(pid));
3100 run_system(dut, buf);
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303101 ret = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003102 if (is_proc_instance_one)
3103 break;
3104 }
3105 }
3106
3107 closedir(dir);
3108
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303109 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003110#else /* __linux__ */
3111 return -1;
3112#endif /* __linux__ */
3113}
3114
3115
3116static int run_ndc(struct sigma_dut *dut, char *buf)
3117{
3118 sigma_dut_print(dut, DUT_MSG_INFO, "CMD NDC:: %s", buf);
3119 sleep(2);
3120 return run_system(dut, buf);
3121}
3122
3123
3124static int sigma_write_cfg(struct sigma_dut *dut, const char *pfile,
3125 const char *field, const char *value)
3126{
3127 FILE *fcfg, *ftmp;
3128 char buf[MAX_CONF_LINE_LEN + 1];
3129 int len, found = 0, res;
3130
3131 /* Open the configuration file */
3132 fcfg = fopen(pfile, "r");
3133 if (!fcfg) {
3134 sigma_dut_print(dut, DUT_MSG_ERROR,
3135 "Failed to open hostapd conf file");
3136 return -1;
3137 }
3138
3139 snprintf(buf, sizeof(buf), "%s~", pfile);
3140 /* Open a temporary file */
3141 ftmp = fopen(buf, "w+");
3142 if (!ftmp) {
3143 fclose(fcfg);
3144 sigma_dut_print(dut, DUT_MSG_ERROR,
3145 "Failed to open temp buf");
3146 return -1;
3147 }
3148
3149 /* Read the values from the configuration file */
3150 len = strlen(field);
3151 while (fgets(buf, MAX_CONF_LINE_LEN, fcfg)) {
3152 char *pline = buf;
3153
3154 /* commented line */
3155 if (buf[0] == '#')
3156 pline++;
3157
3158 /* Identify the configuration parameter to be updated */
3159 if (!found && strncmp(pline, field, len) == 0 &&
3160 pline[len] == '=') {
3161 snprintf(buf, sizeof(buf), "%s=%s\n", field, value);
3162 found = 1;
3163 sigma_dut_print(dut, DUT_MSG_INFO,
3164 "Updated hostapd conf file");
3165 }
3166
3167 fprintf(ftmp, "%s", buf);
3168 }
3169
3170 if (!found) {
3171 /* Configuration line not found */
3172 /* Add the new line at the end of file */
3173 fprintf(ftmp, "%s=%s\n", field, value);
3174 sigma_dut_print(dut, DUT_MSG_INFO,
3175 "Adding a new line in hostapd conf file");
3176 }
3177
3178 fclose(fcfg);
3179 fclose(ftmp);
3180
3181 snprintf(buf, sizeof(buf), "%s~", pfile);
3182
3183 /* Restore the updated configuration file */
3184 res = rename(buf, pfile);
3185
3186 /* Remove the temporary file. Ignore the return value */
3187 unlink(buf);
3188
3189 /* chmod is needed because open() may not set permissions properly
3190 * depending on the current umask */
3191 if (chmod(pfile, 0660) < 0) {
3192 unlink(pfile);
3193 sigma_dut_print(dut, DUT_MSG_ERROR,
3194 "Error changing permissions");
3195 return -1;
3196 }
3197
3198 if (res < 0) {
3199 sigma_dut_print(dut, DUT_MSG_ERROR,
3200 "Error restoring conf file");
3201 return -1;
3202 }
3203
3204 return 0;
3205}
3206
3207
3208static int cmd_wcn_ap_config_commit(struct sigma_dut *dut,
3209 struct sigma_conn *conn,
3210 struct sigma_cmd *cmd)
3211{
3212 char buf[100];
3213 struct stat s;
3214 int num_tries = 0, ret;
3215
Pradeep Reddy Pottetid068e642017-02-17 20:03:12 +05303216 if (kill_process(dut, "(netd)", 1, SIGKILL) == 0 ||
3217 system("killall netd") == 0) {
3218 /* Avoid Error: Error connecting (Connection refused)
3219 * Wait some time to allow netd to reinitialize.
3220 */
3221 usleep(1500000);
3222 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003223
3224 while (num_tries < 10) {
3225 ret = run_ndc(dut, "ndc softap stopap");
3226 num_tries++;
3227 if (WIFEXITED(ret))
3228 ret = WEXITSTATUS(ret);
3229 /* On success, NDC exits with 0 */
3230 if (ret == 0)
3231 break;
3232 sigma_dut_print(dut, DUT_MSG_INFO,
3233 "Try No. %d: ndc softap stopap failed, exit code %d",
3234 num_tries, ret);
3235 }
3236
3237 if (ret != 0)
3238 sigma_dut_print(dut, DUT_MSG_ERROR,
3239 "ndc softap stopap command failed for 10 times - giving up");
3240
3241#ifdef ANDROID
3242 /* Unload/Load driver to cleanup the state of the driver */
Ajit Vaishya14d1f9a2017-09-04 23:24:25 +05303243 system("rmmod -f wlan");
3244 usleep(500000);
3245 system("insmod /system/lib/modules/wlan.ko");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003246#else /* ANDROID */
3247 run_ndc(dut, "ndc softap qccmd set enable_softap=0");
3248 run_ndc(dut, "ndc softap qccmd set enable_softap=1");
3249#endif /* ANDROID */
3250
3251 switch (dut->ap_mode) {
3252 case AP_11g:
3253 run_ndc(dut, "ndc softap qccmd set hw_mode=g-only");
3254 break;
3255 case AP_11b:
3256 run_ndc(dut, "ndc softap qccmd set hw_mode=b-only");
3257 break;
3258 case AP_11ng:
3259 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3260 break;
3261 case AP_11a:
3262 run_ndc(dut, "ndc softap qccmd set hw_mode=a-only");
3263 break;
3264 case AP_11na:
3265 run_ndc(dut, "ndc softap qccmd set hw_mode=n");
3266 break;
3267 case AP_11ac:
3268 run_ndc(dut, "ndc softap qccmd set hw_mode=ac");
3269 break;
3270 default:
3271 break;
3272 }
3273
3274 snprintf(buf, sizeof(buf), "ndc softap qccmd set channel=%d",
3275 dut->ap_channel);
3276 run_ndc(dut, buf);
3277
3278 /*
3279 * ndc doesn't support double quotes as SSID string, so re-write
3280 * hostapd configuration file to update SSID.
3281 */
3282 if (dut->ap_ssid[0] != '\0')
3283 sigma_write_cfg(dut, ANDROID_CONFIG_FILE, "ssid", dut->ap_ssid);
3284
3285 switch (dut->ap_key_mgmt) {
3286 case AP_OPEN:
3287 if (dut->ap_cipher == AP_WEP) {
3288 run_ndc(dut, "ndc softap qccmd set security_mode=1");
3289 snprintf(buf, sizeof(buf),
3290 "ndc softap qccmd set wep_key0=%s",
3291 dut->ap_wepkey);
3292 run_ndc(dut, buf);
3293 } else {
3294 run_ndc(dut, "ndc softap qccmd set security_mode=0");
3295 }
3296 break;
3297 case AP_WPA2_PSK:
3298 case AP_WPA2_PSK_MIXED:
3299 case AP_WPA_PSK:
3300 if (dut->ap_key_mgmt == AP_WPA2_PSK)
3301 run_ndc(dut, "ndc softap qccmd set security_mode=3");
3302 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
3303 run_ndc(dut, "ndc softap qccmd set security_mode=4");
3304 else
3305 run_ndc(dut, "ndc softap qccmd set security_mode=2");
3306
3307 /*
3308 * ndc doesn't support some special characters as passphrase,
3309 * so re-write hostapd configuration file to update Passphrase.
3310 */
3311 if (dut->ap_passphrase[0] != '\0')
3312 sigma_write_cfg(dut, ANDROID_CONFIG_FILE,
3313 "wpa_passphrase", dut->ap_passphrase);
3314
3315 if (dut->ap_cipher == AP_CCMP_TKIP)
3316 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3317 "TKIP CCMP");
3318 else if (dut->ap_cipher == AP_TKIP)
3319 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3320 "TKIP");
3321 else
3322 run_ndc(dut, "ndc softap qccmd set wpa_pairwise="
3323 "CCMP &");
3324 break;
Jouni Malinen30824df2017-08-22 21:21:38 +03003325 case AP_WPA2_SAE:
3326 case AP_WPA2_PSK_SAE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003327 case AP_WPA2_EAP:
3328 case AP_WPA2_EAP_MIXED:
3329 case AP_WPA_EAP:
Jouni Malinenad395a22017-09-01 21:13:46 +03003330 case AP_SUITEB:
Jouni Malinen147b3c32017-10-09 16:51:54 +03003331 case AP_WPA2_OWE:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003332 /* Not supported */
3333 break;
3334 }
3335
3336 switch (dut->ap_pmf) {
3337 case AP_PMF_DISABLED:
3338 run_ndc(dut, "ndc softap qccmd set ieee80211w=0");
3339 break;
3340 case AP_PMF_OPTIONAL:
3341 run_ndc(dut, "ndc softap qccmd set ieee80211w=1");
3342 if (dut->ap_add_sha256)
3343 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK WPA-PSK-SHA256");
3344 else
3345 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK");
3346 break;
3347 case AP_PMF_REQUIRED:
3348 run_ndc(dut, "ndc softap qccmd set ieee80211w=2");
3349 run_ndc(dut, "ndc softap qccmd set wpa_key_mgmt=WPA-PSK-SHA256");
3350 break;
3351 }
3352
3353 if (dut->ap_countrycode[0]) {
3354 snprintf(buf, sizeof(buf),
3355 "ndc softap qccmd set country_code=%s",
3356 dut->ap_countrycode);
3357 run_ndc(dut, buf);
3358 }
3359
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05303360 if (dut->ap_regulatory_mode == AP_80211D_MODE_ENABLED)
3361 run_ndc(dut, "ndc softap qccmd set ieee80211d=1");
3362
3363 if (dut->ap_dfs_mode == AP_DFS_MODE_ENABLED)
3364 run_ndc(dut, "ndc softap qccmd set ieee80211h=1");
3365
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003366 run_ndc(dut, "ndc softap startap");
3367
3368 snprintf(buf, sizeof(buf), "%s%s", sigma_wpas_ctrl, sigma_main_ifname);
3369 num_tries = 0;
3370 while (num_tries < 10 && (ret = stat(buf, &s) != 0)) {
3371 run_ndc(dut, "ndc softap stopap");
3372 run_ndc(dut, "ndc softap startap");
3373 num_tries++;
3374 }
3375
3376 if (num_tries == 10) {
3377 sigma_dut_print(dut, DUT_MSG_INFO, "Tried 10 times with ctrl "
3378 "iface %s :: reboot the APDUT", buf);
3379 return ret;
3380 }
3381
3382 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
3383 ap_inet_addr, ap_inet_mask);
3384 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
3385 sigma_main_ifname, ap_inet_addr, ap_inet_mask);
3386 if (system(buf) != 0) {
3387 sigma_dut_print(dut, DUT_MSG_ERROR,
3388 "Failed to intialize the interface");
3389 return -1;
3390 }
3391
3392 return 1;
3393}
3394
3395
3396static int append_hostapd_conf_hs2(struct sigma_dut *dut, FILE *f)
3397{
3398 fprintf(f, "hs20=1\nhs20_deauth_req_timeout=3\n"
3399 "disable_dgaf=%d\n", dut->ap_dgaf_disable);
3400
3401 if (dut->ap_oper_name) {
3402 fprintf(f, "hs20_oper_friendly_name=eng:Wi-Fi Alliance\n");
3403 fprintf(f, "hs20_oper_friendly_name=chi:Wi-Fi\xe8\x81\x94\xe7\x9b\x9f\n");
3404 }
3405
3406 if (dut->ap_wan_metrics == 1)
3407 fprintf(f, "hs20_wan_metrics=01:2500:384:0:0:10\n");
3408 else if (dut->ap_wan_metrics == 2)
3409 fprintf(f, "hs20_wan_metrics=01:1500:384:20:20:10\n");
3410 else if (dut->ap_wan_metrics == 3)
3411 fprintf(f, "hs20_wan_metrics=01:2000:1000:20:20:10\n");
3412 else if (dut->ap_wan_metrics == 4)
3413 fprintf(f, "hs20_wan_metrics=01:8000:1000:20:20:10\n");
3414 else if (dut->ap_wan_metrics == 5)
3415 fprintf(f, "hs20_wan_metrics=01:9000:5000:20:20:10\n");
3416
3417 if (dut->ap_conn_capab == 1) {
3418 fprintf(f, "hs20_conn_capab=1:0:0\n");
3419 fprintf(f, "hs20_conn_capab=6:20:1\n");
3420 fprintf(f, "hs20_conn_capab=6:22:0\n");
3421 fprintf(f, "hs20_conn_capab=6:80:1\n");
3422 fprintf(f, "hs20_conn_capab=6:443:1\n");
3423 fprintf(f, "hs20_conn_capab=6:1723:0\n");
3424 fprintf(f, "hs20_conn_capab=6:5060:0\n");
3425 fprintf(f, "hs20_conn_capab=17:500:1\n");
3426 fprintf(f, "hs20_conn_capab=17:5060:0\n");
3427 fprintf(f, "hs20_conn_capab=17:4500:1\n");
3428 fprintf(f, "hs20_conn_capab=50:0:1\n");
3429 } else if (dut->ap_conn_capab == 2) {
3430 fprintf(f, "hs20_conn_capab=6:80:1\n");
3431 fprintf(f, "hs20_conn_capab=6:443:1\n");
3432 fprintf(f, "hs20_conn_capab=17:5060:1\n");
3433 fprintf(f, "hs20_conn_capab=6:5060:1\n");
3434 } else if (dut->ap_conn_capab == 3) {
3435 fprintf(f, "hs20_conn_capab=6:80:1\n");
3436 fprintf(f, "hs20_conn_capab=6:443:1\n");
3437 } else if (dut->ap_conn_capab == 4) {
3438 fprintf(f, "hs20_conn_capab=6:80:1\n");
3439 fprintf(f, "hs20_conn_capab=6:443:1\n");
3440 fprintf(f, "hs20_conn_capab=6:5060:1\n");
3441 fprintf(f, "hs20_conn_capab=17:5060:1\n");
3442 }
3443
3444 if (dut->ap_oper_class == 1)
3445 fprintf(f, "hs20_operating_class=51\n");
3446 else if (dut->ap_oper_class == 2)
3447 fprintf(f, "hs20_operating_class=73\n");
3448 else if (dut->ap_oper_class == 3)
3449 fprintf(f, "hs20_operating_class=5173\n");
3450
3451 if (dut->ap_osu_provider_list) {
3452 char *osu_friendly_name = NULL;
3453 char *osu_icon = NULL;
3454 char *osu_ssid = NULL;
3455 char *osu_nai = NULL;
3456 char *osu_service_desc = NULL;
3457 char *hs20_icon_filename = NULL;
3458 char hs20_icon[150];
3459 int osu_method;
3460
3461 hs20_icon_filename = "icon_red_zxx.png";
3462 if (dut->ap_osu_icon_tag == 2)
3463 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3464 snprintf(hs20_icon, sizeof(hs20_icon),
3465 "128:61:zxx:image/png:icon_red_zxx.png:/etc/ath/%s",
3466 hs20_icon_filename);
3467 osu_icon = "icon_red_zxx.png";
3468 osu_ssid = "OSU";
3469 osu_friendly_name = "kor:SP 빨강 테스트 전용";
3470 osu_service_desc = "kor:테스트 목적으로 무료 서비스";
3471 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
3472
3473 if (strlen(dut->ap_osu_server_uri[0]))
3474 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[0]);
3475 else
3476 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
3477
3478 switch (dut->ap_osu_provider_list) {
3479 case 1:
3480 case 101:
3481 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
3482 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3483 hs20_icon_filename = "icon_red_eng.png";
3484 if (dut->ap_osu_icon_tag == 2)
3485 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3486 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_red_eng.png:/etc/ath/%s\n",
3487 hs20_icon_filename);
3488 fprintf(f, "osu_icon=icon_red_eng.png\n");
3489 break;
3490 case 2:
3491 case 102:
3492 fprintf(f, "osu_friendly_name=eng:Wireless Broadband Alliance\n");
3493 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3494 hs20_icon_filename = "icon_orange_zxx.png";
3495 if (dut->ap_osu_icon_tag == 2)
3496 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3497 snprintf(hs20_icon, sizeof(hs20_icon),
3498 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3499 hs20_icon_filename);
3500 osu_icon = "icon_orange_zxx.png";
3501 osu_friendly_name = "kor:와이어리스 브로드밴드 얼라이언스";
3502 break;
3503 case 3:
3504 case 103:
3505 osu_friendly_name = "spa:SP Red Test Only";
3506 osu_service_desc = "spa:Free service for test purpose";
3507 break;
3508 case 4:
3509 case 104:
3510 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3511 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3512 hs20_icon_filename = "icon_orange_eng.png";
3513 if (dut->ap_osu_icon_tag == 2)
3514 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3515 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_orange_eng.png:/etc/ath/%s\n",
3516 hs20_icon_filename);
3517 fprintf(f, "osu_icon=icon_orange_eng.png\n");
3518 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3519
3520 hs20_icon_filename = "icon_orange_zxx.png";
3521 if (dut->ap_osu_icon_tag == 2)
3522 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3523 snprintf(hs20_icon, sizeof(hs20_icon),
3524 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3525 hs20_icon_filename);
3526 osu_icon = "icon_orange_zxx.png";
3527 break;
3528 case 5:
3529 case 105:
3530 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3531 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3532 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3533 hs20_icon_filename = "icon_orange_zxx.png";
3534 if (dut->ap_osu_icon_tag == 2)
3535 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3536 snprintf(hs20_icon, sizeof(hs20_icon),
3537 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3538 hs20_icon_filename);
3539 osu_icon = "icon_orange_zxx.png";
3540 break;
3541 case 6:
3542 case 106:
3543 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
3544 fprintf(f, "osu_friendly_name=kor:SP 초록 테스트 전용\n");
3545 hs20_icon_filename = "icon_green_zxx.png";
3546 if (dut->ap_osu_icon_tag == 2)
3547 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3548 fprintf(f, "hs20_icon=128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s\n",
3549 hs20_icon_filename);
3550 fprintf(f, "osu_icon=icon_green_zxx.png\n");
3551 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 0 : dut->ap_osu_method[0];
3552 fprintf(f, "osu_method_list=%d\n", osu_method);
3553
3554 if (strlen(dut->ap_osu_server_uri[1]))
3555 fprintf(f, "osu_server_uri=%s\n", dut->ap_osu_server_uri[1]);
3556 else
3557 fprintf(f, "osu_server_uri=https://osu-server.r2-testbed.wi-fi.org/\n");
3558 fprintf(f, "osu_friendly_name=eng:SP Orange Test Only\n");
3559 hs20_icon_filename = "icon_orange_zxx.png";
3560 if (dut->ap_osu_icon_tag == 2)
3561 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3562 snprintf(hs20_icon, sizeof(hs20_icon),
3563 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3564 hs20_icon_filename);
3565 osu_icon = "icon_orange_zxx.png";
3566 osu_friendly_name = "kor:SP 오렌지 테스트 전용";
3567 osu_method = (dut->ap_osu_method[1] == 0xFF) ? 0 : dut->ap_osu_method[1];
3568 osu_service_desc = NULL;
3569 break;
3570 case 7:
3571 case 107:
3572 fprintf(f, "osu_friendly_name=eng:SP Green Test Only\n");
3573 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3574 hs20_icon_filename = "icon_green_eng.png";
3575 if (dut->ap_osu_icon_tag == 2)
3576 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3577 fprintf(f, "hs20_icon=160:76:eng:image/png:icon_green_eng.png:/etc/ath/%s\n",
3578 hs20_icon_filename);
3579 fprintf(f, "osu_icon=icon_green_eng.png\n");
3580 osu_friendly_name = "kor:SP 초록 테스트 전용";
3581
3582 hs20_icon_filename = "icon_green_zxx.png";
3583 if (dut->ap_osu_icon_tag == 2)
3584 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3585 snprintf(hs20_icon, sizeof(hs20_icon),
3586 "128:61:zxx:image/png:icon_green_zxx.png:/etc/ath/%s",
3587 hs20_icon_filename);
3588 osu_icon = "icon_green_zxx.png";
3589 break;
3590 case 8:
3591 case 108:
3592 fprintf(f, "osu_friendly_name=eng:SP Red Test Only\n");
3593 fprintf(f, "osu_service_desc=eng:Free service for test purpose\n");
3594 osu_ssid = "OSU-Encrypted";
3595 osu_nai = "anonymous@hotspot.net";
3596 break;
3597 case 9:
3598 case 109:
3599 osu_ssid = "OSU-OSEN";
3600 osu_nai = "test-anonymous@wi-fi.org";
3601 osu_friendly_name = "eng:SP Orange Test Only";
3602 hs20_icon_filename = "icon_orange_zxx.png";
3603 if (dut->ap_osu_icon_tag == 2)
3604 hs20_icon_filename = "wifi-abgn-logo_270x73.png";
3605 snprintf(hs20_icon, sizeof(hs20_icon),
3606 "128:61:zxx:image/png:icon_orange_zxx.png:/etc/ath/%s",
3607 hs20_icon_filename);
3608 osu_icon = "icon_orange_zxx.png";
3609 osu_method = (dut->ap_osu_method[0] == 0xFF) ? 1 : dut->ap_osu_method[0];
3610 osu_service_desc = NULL;
3611 break;
3612 default:
3613 break;
3614 }
3615
3616 if (strlen(dut->ap_osu_ssid)) {
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003617 if (strcmp(dut->ap_tag_ssid[0], dut->ap_osu_ssid) &&
3618 strcmp(dut->ap_tag_ssid[0], osu_ssid)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003619 sigma_dut_print(dut, DUT_MSG_ERROR,
3620 "OSU_SSID and "
3621 "WLAN_TAG2 SSID differ");
3622 return -2;
3623 }
3624 fprintf(f, "osu_ssid=\"%s\"\n", dut->ap_osu_ssid);
3625 } else
3626 fprintf(f, "osu_ssid=\"%s\"\n", osu_ssid);
3627
3628
3629 if (osu_friendly_name)
3630 fprintf(f, "osu_friendly_name=%s\n", osu_friendly_name);
3631
3632 if (osu_service_desc)
3633 fprintf(f, "osu_service_desc=%s\n", osu_service_desc);
3634
3635 if (osu_nai)
3636 fprintf(f, "osu_nai=%s\n", osu_nai);
3637
3638 fprintf(f, "hs20_icon=%s\n", hs20_icon);
3639
3640 if (osu_icon)
3641 fprintf(f, "osu_icon=%s\n", osu_icon);
3642
3643 if (dut->ap_osu_provider_list > 100)
3644 fprintf(f, "osu_method_list=0\n");
3645 else
3646 fprintf(f, "osu_method_list=%d\n", osu_method);
3647 }
3648
3649 return 0;
3650}
3651
3652
3653static void write_ap_roaming_cons(FILE *f, const char *list)
3654{
3655 char *buf, *pos, *end;
3656
3657 if (list == NULL || list[0] == '\0')
3658 return;
3659
3660 buf = strdup(list);
3661 if (buf == NULL)
3662 return;
3663
3664 pos = buf;
3665 while (pos && *pos) {
3666 end = strchr(pos, ';');
3667 if (end)
3668 *end++ = '\0';
3669 fprintf(f, "roaming_consortium=%s\n", pos);
3670 pos = end;
3671 }
3672
3673 free(buf);
3674}
3675
3676
3677static int append_hostapd_conf_interworking(struct sigma_dut *dut, FILE *f)
3678{
3679 int i;
3680 char buf[100], *temp;
3681
3682 if (dut->ap_gas_cb_delay > 0)
3683 fprintf(f, "gas_comeback_delay=%d\n",
3684 dut->ap_gas_cb_delay);
3685
3686 fprintf(f, "interworking=1\n"
3687 "access_network_type=%d\n"
3688 "internet=%d\n"
3689 "asra=0\n"
3690 "esr=0\n"
3691 "uesa=0\n"
3692 "venue_group=%d\n"
3693 "venue_type=%d\n",
3694 dut->ap_access_net_type,
3695 dut->ap_internet,
3696 dut->ap_venue_group,
3697 dut->ap_venue_type);
3698 if (dut->ap_hessid[0])
3699 fprintf(f, "hessid=%s\n", dut->ap_hessid);
3700
3701 write_ap_roaming_cons(f, dut->ap_roaming_cons);
3702
3703 if (dut->ap_venue_name) {
3704 fprintf(f, "venue_name=P\"eng:Wi-Fi Alliance\\n2989 Copper Road\\nSanta Clara, CA 95051, USA\"\n");
3705 fprintf(f, "venue_name=%s\n", ANQP_VENUE_NAME_1_CHI);
3706 }
3707
3708 if (dut->ap_net_auth_type == 1)
3709 fprintf(f, "network_auth_type=00https://tandc-server.wi-fi.org\n");
3710 else if (dut->ap_net_auth_type == 2)
3711 fprintf(f, "network_auth_type=01\n");
3712
3713 if (dut->ap_nai_realm_list == 1) {
3714 fprintf(f, "nai_realm=0,mail.example.com;cisco.com;wi-fi.org,21[2:4][5:7]\n");
3715 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
3716 } else if (dut->ap_nai_realm_list == 2) {
3717 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
3718 } else if (dut->ap_nai_realm_list == 3) {
3719 fprintf(f, "nai_realm=0,cisco.com;wi-fi.org,21[2:4][5:7]\n");
3720 fprintf(f, "nai_realm=0,wi-fi.org;example.com,13[5:6]\n");
3721 } else if (dut->ap_nai_realm_list == 4) {
3722 fprintf(f, "nai_realm=0,mail.example.com,21[2:4][5:7],13[5:6]\n");
3723 } else if (dut->ap_nai_realm_list == 5) {
3724 fprintf(f, "nai_realm=0,wi-fi.org;ruckuswireless.com,21[2:4][5:7]\n");
3725 } else if (dut->ap_nai_realm_list == 6) {
3726 fprintf(f, "nai_realm=0,wi-fi.org;mail.example.com,21[2:4][5:7]\n");
3727 } else if (dut->ap_nai_realm_list == 7) {
3728 fprintf(f, "nai_realm=0,wi-fi.org,13[5:6]\n");
3729 fprintf(f, "nai_realm=0,wi-fi.org,21[2:4][5:7]\n");
3730 }
3731
3732 if (dut->ap_domain_name_list[0]) {
3733 fprintf(f, "domain_name=%s\n",
3734 dut->ap_domain_name_list);
3735 }
3736
3737 if (dut->ap_ip_addr_type_avail == 1) {
3738 fprintf(f, "ipaddr_type_availability=0c\n");
3739 }
3740
3741 temp = buf;
3742 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0];
3743 i++) {
3744 if (i)
3745 *temp++ = ';';
3746
3747 snprintf(temp,
3748 sizeof(dut->ap_plmn_mcc[i]) +
3749 sizeof(dut->ap_plmn_mnc[i]) + 1,
3750 "%s,%s",
3751 dut->ap_plmn_mcc[i],
3752 dut->ap_plmn_mnc[i]);
3753
3754 temp += strlen(dut->ap_plmn_mcc[i]) +
3755 strlen(dut->ap_plmn_mnc[i]) + 1;
3756 }
3757 if (i)
3758 fprintf(f, "anqp_3gpp_cell_net=%s\n", buf);
3759
3760 if (dut->ap_qos_map_set == 1)
3761 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_1);
3762 else if (dut->ap_qos_map_set == 2)
3763 fprintf(f, "qos_map_set=%s\n", QOS_MAP_SET_2);
3764
3765 return 0;
3766}
3767
3768
3769static int ath_ap_append_hostapd_conf(struct sigma_dut *dut)
3770{
3771 FILE *f;
3772
3773 if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
3774 system("killall hostapd") == 0) {
3775 int i;
3776
3777 /* Wait some time to allow hostapd to complete cleanup before
3778 * starting a new process */
3779 for (i = 0; i < 10; i++) {
3780 usleep(500000);
3781 if (system("pidof hostapd") != 0)
3782 break;
3783 }
3784 }
3785
3786 f = fopen("/tmp/secath0", "a");
3787 if (f == NULL)
3788 return -2;
3789
3790 if (dut->ap_hs2 && append_hostapd_conf_hs2(dut, f)) {
3791 fclose(f);
3792 return -2;
3793 }
3794
3795 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
3796 fclose(f);
3797 return -2;
3798 }
3799
3800 fflush(f);
3801 fclose(f);
3802 return ath_ap_start_hostapd(dut);
3803}
3804
3805
3806static int ath_ap_start_hostapd(struct sigma_dut *dut)
3807{
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07003808 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003809 run_system(dut, "hostapd -B /tmp/secath0 /tmp/secath1 -e /etc/wpa2/entropy");
3810 else
3811 run_system(dut, "hostapd -B /tmp/secath0 -e /etc/wpa2/entropy");
3812
3813 return 0;
3814}
3815
3816
3817#define LE16(a) ((((a) & 0xff) << 8) | (((a) >> 8) & 0xff))
3818
3819static int cmd_ath_ap_anqpserver_start(struct sigma_dut *dut)
3820{
3821 FILE *f;
3822 int nai_realm = 0, domain_name = 0, oper_name = 0, venue_name = 0,
3823 wan_metrics = 0, conn_cap = 0, ipaddr_avail = 0, cell_net = 0;
3824 char buf[100];
3825 int i;
3826
3827 f = fopen("/root/anqpserver.conf", "w");
3828 if (f == NULL)
3829 return -1;
3830
3831 if (dut->ap_nai_realm_list == 1) {
3832 nai_realm = 1;
3833 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");
3834 } else if (dut->ap_nai_realm_list == 2) {
3835 nai_realm = 1;
3836 fprintf(f, "dyn_nai_home_realm=encoding=00realm=wi-fi.org;eap_method=0Dauth_id=05auth_val=06\n");
3837 } else if (dut->ap_nai_realm_list == 3) {
3838 nai_realm = 1;
3839 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");
3840 } else if (dut->ap_nai_realm_list == 4) {
3841 nai_realm = 1;
3842 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");
3843 } else
3844 sigma_dut_print(dut, DUT_MSG_INFO, "not setting nai_realm");
3845
3846 if (dut->ap_domain_name_list[0]) {
3847 char *next, *start, *dnbuf, *dn1, *anqp_dn;
3848 int len, dn_len_max;
3849 dnbuf = strdup(dut->ap_domain_name_list);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303850 if (dnbuf == NULL) {
3851 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003852 return 0;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303853 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003854
3855 len = strlen(dnbuf);
3856 dn_len_max = 50 + len*2;
3857 anqp_dn = malloc(dn_len_max);
3858 if (anqp_dn == NULL) {
3859 free(dnbuf);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303860 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003861 return -1;
3862 }
3863 start = dnbuf;
3864 dn1 = anqp_dn;
3865 while (start && *start) {
3866 char *hexstr;
3867
3868 next = strchr(start, ',');
3869 if (next)
3870 *next++ = '\0';
3871
3872 len = strlen(start);
vamsi krishna2e881302016-05-25 15:02:39 +05303873 hexstr = malloc(len * 2 + 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003874 if (hexstr == NULL) {
3875 free(dnbuf);
3876 free(anqp_dn);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05303877 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003878 return -1;
3879 }
3880 ascii2hexstr(start, hexstr);
3881 snprintf(dn1, dn_len_max, "%02x%s", len, hexstr);
3882 free(hexstr);
3883 dn1 += 2 + len * 2;
3884 dn_len_max -= 2 + len * 2;
3885 start = next;
3886 }
3887 free(dnbuf);
3888 if (dut->ap_gas_cb_delay) {
3889 fprintf(f, "dyn_domain_name=0c01%04x%s",
3890 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3891 domain_name = 1;
3892 } else
3893 fprintf(f, "domain_name=0c01%04x%s",
3894 LE16((unsigned int) strlen(anqp_dn)), anqp_dn);
3895 free(anqp_dn);
3896 } else
3897 sigma_dut_print(dut, DUT_MSG_INFO, "not setting domain_name");
3898
3899 sigma_dut_print(dut, DUT_MSG_INFO, "not setting roaming_consortium");
3900
3901 if (dut->ap_oper_name) {
3902 if (dut->ap_gas_cb_delay) {
3903 fprintf(f, "dyn_oper_friendly_name="
3904 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3905 oper_name = 1;
3906 } else
3907 fprintf(f, "oper_friendly_name="
3908 ANQP_HS20_OPERATOR_FRIENDLY_NAME_1 "\n");
3909 } else
3910 sigma_dut_print(dut, DUT_MSG_INFO, "not setting oper_name");
3911
3912 if (dut->ap_venue_name) {
3913 if (dut->ap_gas_cb_delay) {
3914 fprintf(f, "dyn_venue_name=" ANQP_VENUE_NAME_1 "\n");
3915 venue_name = 1;
3916 } else
3917 fprintf(f, "venue_name=" ANQP_VENUE_NAME_1 "\n");
3918 } else
3919 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting venue_name");
3920
3921 if (dut->ap_wan_metrics) {
3922 if (dut->ap_gas_cb_delay) {
3923 fprintf(f, "dyn_wan_metrics=" ANQP_HS20_WAN_METRICS_1 "\n");
3924 wan_metrics = 1;
3925 } else
3926 fprintf(f, "wan_metrics=" ANQP_HS20_WAN_METRICS_1
3927 "\n");
3928 } else
3929 sigma_dut_print(dut, DUT_MSG_ERROR, "not setting wan_metrics");
3930
3931 if (dut->ap_conn_capab) {
3932 if (dut->ap_gas_cb_delay) {
3933 fprintf(f, "dyn_conn_capability="
3934 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3935 conn_cap = 1;
3936 } else
3937 fprintf(f, "conn_capability="
3938 ANQP_HS20_CONNECTION_CAPABILITY_1 "\n");
3939 } else
3940 sigma_dut_print(dut, DUT_MSG_ERROR,
3941 "not setting conn_capability");
3942
3943 if (dut->ap_ip_addr_type_avail) {
3944 if (dut->ap_gas_cb_delay) {
3945 fprintf(f, "dyn_ipaddr_type=" ANQP_IP_ADDR_TYPE_1
3946 "\n");
3947 ipaddr_avail = 1;
3948 } else
3949 fprintf(f, "ipaddr_type=" ANQP_IP_ADDR_TYPE_1 "\n");
3950 } else
3951 sigma_dut_print(dut, DUT_MSG_ERROR,
3952 "not setting ipaddr_type_avail");
3953
3954 for (i = 0; dut->ap_plmn_mcc[i][0] && dut->ap_plmn_mnc[i][0]; i++) {
3955 snprintf(buf + i * 6, sizeof(buf) - i * 6, "%c%c%c%c%c%c",
3956 dut->ap_plmn_mcc[i][1],
3957 dut->ap_plmn_mcc[i][0],
3958 dut->ap_plmn_mnc[i][2] == '\0' ?
3959 'f' : dut->ap_plmn_mnc[i][2],
3960 dut->ap_plmn_mcc[i][2],
3961 dut->ap_plmn_mnc[i][1],
3962 dut->ap_plmn_mnc[i][0]);
3963 }
3964 if (i) {
3965 uint16_t ie_len = (i * 3) + 5;
3966 if (dut->ap_gas_cb_delay) {
3967 fprintf(f, "dyn_cell_net=0801");
3968 cell_net = 1;
3969 } else
3970 fprintf(f, "cell_net=0801");
3971 fprintf(f, "%04x", LE16(ie_len));
3972 fprintf(f, "00"); /* version */
3973 fprintf(f, "%02x", (i * 3) + 3); /* user data hdr length */
3974 fprintf(f, "00"); /* plmn list */
3975 fprintf(f, "%02x", (i * 3) + 1); /* length of plmn list */
3976 fprintf(f, "%02x", i); /* number of plmns */
3977 fprintf(f, "%s\n", buf); /* plmns */
3978 } else
3979 sigma_dut_print(dut, DUT_MSG_ERROR,
3980 "not setting 3gpp_cellular_network");
3981
3982 if (nai_realm || domain_name || oper_name || venue_name ||
3983 wan_metrics || conn_cap || ipaddr_avail || cell_net) {
3984 fprintf(f, "anqp_attach=");
3985 if (venue_name)
3986 fprintf(f, "00000104%4.4x", dut->ap_gas_cb_delay);
3987 if (nai_realm)
3988 fprintf(f, "00000107%4.4x", dut->ap_gas_cb_delay);
3989 if (cell_net)
3990 fprintf(f, "00000108%4.4x", dut->ap_gas_cb_delay);
3991 if (domain_name)
3992 fprintf(f, "0000010c%4.4x", dut->ap_gas_cb_delay);
3993 if (oper_name)
3994 fprintf(f, "00010003%4.4x", dut->ap_gas_cb_delay);
3995 if (wan_metrics)
3996 fprintf(f, "00010004%4.4x", dut->ap_gas_cb_delay);
3997 if (conn_cap)
3998 fprintf(f, "00010005%4.4x", dut->ap_gas_cb_delay);
3999 fprintf(f, "00010006%4.4x", dut->ap_gas_cb_delay);
4000 fprintf(f, "\n");
4001 }
4002
4003 fclose(f);
4004
4005 run_system(dut, "anqpserver -i ath0 &");
4006 if (!dut->ap_anqpserver_on)
4007 run_system(dut, "killall anqpserver");
4008
4009 return 1;
4010}
4011
4012
4013static void cmd_ath_ap_radio_config(struct sigma_dut *dut)
4014{
4015 char buf[100];
4016
4017 run_system(dut, "cfg -a AP_STARTMODE=standard");
4018
4019 if (sigma_radio_ifname[0] &&
4020 strcmp(sigma_radio_ifname[0], "wifi1") == 0) {
4021 run_system(dut, "cfg -a AP_RADIO_ID=1");
4022 switch (dut->ap_mode) {
4023 case AP_11g:
4024 run_system(dut, "cfg -a AP_CHMODE_2=11G");
4025 break;
4026 case AP_11b:
4027 run_system(dut, "cfg -a AP_CHMODE_2=11B");
4028 break;
4029 case AP_11ng:
4030 run_system(dut, "cfg -a AP_CHMODE_2=11NGHT20");
4031 break;
4032 case AP_11a:
4033 run_system(dut, "cfg -a AP_CHMODE_2=11A");
4034 break;
4035 case AP_11na:
4036 run_system(dut, "cfg -a AP_CHMODE_2=11NAHT20");
4037 break;
4038 case AP_11ac:
4039 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4040 break;
4041 default:
4042 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4043 break;
4044 }
4045
4046 switch (dut->ap_rx_streams) {
4047 case 1:
4048 run_system(dut, "cfg -a RX_CHAINMASK_2=1");
4049 break;
4050 case 2:
4051 run_system(dut, "cfg -a RX_CHAINMASK_2=3");
4052 break;
4053 case 3:
4054 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
4055 break;
4056 }
4057
4058 switch (dut->ap_tx_streams) {
4059 case 1:
4060 run_system(dut, "cfg -a TX_CHAINMASK_2=1");
4061 break;
4062 case 2:
4063 run_system(dut, "cfg -a TX_CHAINMASK_2=3");
4064 break;
4065 case 3:
4066 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
4067 break;
4068 }
4069
4070 switch (dut->ap_chwidth) {
4071 case AP_20:
4072 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT20");
4073 break;
4074 case AP_40:
4075 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT40");
4076 break;
4077 case AP_80:
4078 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4079 break;
4080 case AP_160:
4081 case AP_AUTO:
4082 default:
4083 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
4084 break;
4085 }
4086
4087 if (dut->ap_tx_stbc) {
4088 run_system(dut, "cfg -a TX_STBC_2=1");
4089 }
4090
4091 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH_2=%d",
4092 dut->ap_channel);
4093
4094 if (dut->ap_is_dual) {
4095 switch (dut->ap_mode_1) {
4096 case AP_11g:
4097 run_system(dut, "cfg -a AP_CHMODE=11G");
4098 break;
4099 case AP_11b:
4100 run_system(dut, "cfg -a AP_CHMODE=11B");
4101 break;
4102 case AP_11ng:
4103 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4104 break;
4105 case AP_11a:
4106 run_system(dut, "cfg -a AP_CHMODE=11A");
4107 break;
4108 case AP_11na:
4109 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4110 break;
4111 case AP_11ac:
4112 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4113 break;
4114 default:
4115 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4116 break;
4117 }
4118 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4119 dut->ap_channel_1);
4120 }
4121 run_system(dut, buf);
4122 } else {
4123 run_system(dut, "cfg -a AP_RADIO_ID=0");
4124 switch (dut->ap_mode) {
4125 case AP_11g:
4126 run_system(dut, "cfg -a AP_CHMODE=11G");
4127 break;
4128 case AP_11b:
4129 run_system(dut, "cfg -a AP_CHMODE=11B");
4130 break;
4131 case AP_11ng:
4132 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4133 break;
4134 case AP_11a:
4135 run_system(dut, "cfg -a AP_CHMODE=11A");
4136 break;
4137 case AP_11na:
4138 run_system(dut, "cfg -a AP_CHMODE=11NAHT20");
4139 break;
4140 case AP_11ac:
4141 run_system(dut, "cfg -a AP_CHMODE=11ACVHT80");
4142 break;
4143 default:
4144 run_system(dut, "cfg -a AP_CHMODE=11NGHT20");
4145 break;
4146 }
4147 snprintf(buf, sizeof(buf), "cfg -a AP_PRIMARY_CH=%d",
4148 dut->ap_channel);
4149 run_system(dut, buf);
4150 }
4151
4152 if (dut->ap_sgi80 == 1) {
4153 run_system(dut, "cfg -a SHORTGI=1");
4154 run_system(dut, "cfg -a SHORTGI_2=1");
4155 } else if (dut->ap_sgi80 == 0) {
4156 run_system(dut, "cfg -a SHORTGI=0");
4157 run_system(dut, "cfg -a SHORTGI_2=0");
4158 }
4159
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004160 if (dut->ap_ldpc == VALUE_ENABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004161 run_system(dut, "cfg -a LDPC=1");
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004162 else if (dut->ap_ldpc == VALUE_DISABLED)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004163 run_system(dut, "cfg -a LDPC=0");
4164}
4165
4166
4167void ath_disable_txbf(struct sigma_dut *dut, const char *intf)
4168{
4169 char buf[50];
4170
4171 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 0", intf);
4172 if (system(buf) != 0)
4173 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfee failed");
4174
4175 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 0", intf);
4176 if (system(buf) != 0)
4177 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtsubfer failed");
4178
4179 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 0", intf);
4180 if (system(buf) != 0)
4181 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfee failed");
4182
4183 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 0", intf);
4184 if (system(buf) != 0)
4185 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv vhtmubfer failed");
4186}
4187
4188
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004189static void ath_set_assoc_disallow(struct sigma_dut *dut, const char *ifname,
4190 const char *val)
4191{
4192 if (strcasecmp(val, "enable") == 0) {
4193 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 1", ifname);
4194 } else if (strcasecmp(val, "disable") == 0) {
4195 run_system_wrapper(dut, "iwpriv %s mbo_asoc_dis 0", ifname);
4196 } else {
4197 sigma_dut_print(dut, DUT_MSG_ERROR,
4198 "Unsupported assoc_disallow");
4199 }
4200}
4201
4202
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07004203static void apply_mbo_pref_ap_list(struct sigma_dut *dut)
4204{
4205 int i;
4206 int least_pref = 1 << 8;
4207 char ifname[20];
4208 uint8_t self_mac[ETH_ALEN];
4209 char buf[200];
4210 int ap_ne_class, ap_ne_pref, ap_ne_op_ch;
4211
4212 get_if_name(dut, ifname, sizeof(ifname), 1);
4213 get_hwaddr(ifname, self_mac);
4214
4215 /* Clear off */
4216 snprintf(buf, sizeof(buf),
4217 "wifitool %s setbssidpref 00:00:00:00:00:00 0 0 0",
4218 ifname);
4219 run_system(dut, buf);
4220
4221 /* Find the least preference number */
4222 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
4223 unsigned char *mac_addr = dut->mbo_pref_aps[i].mac_addr;
4224
4225 ap_ne_class = 1;
4226 ap_ne_pref = 255;
4227 ap_ne_op_ch = 1;
4228 if (dut->mbo_pref_aps[i].ap_ne_pref != -1)
4229 ap_ne_pref = dut->mbo_pref_aps[i].ap_ne_pref;
4230 if (dut->mbo_pref_aps[i].ap_ne_class != -1)
4231 ap_ne_class = dut->mbo_pref_aps[i].ap_ne_class;
4232 if (dut->mbo_pref_aps[i].ap_ne_op_ch != -1)
4233 ap_ne_op_ch = dut->mbo_pref_aps[i].ap_ne_op_ch;
4234
4235 if (ap_ne_pref < least_pref)
4236 least_pref = ap_ne_pref;
4237 snprintf(buf, sizeof(buf),
4238 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4239 ifname, mac_addr[0], mac_addr[1], mac_addr[2],
4240 mac_addr[3], mac_addr[4], mac_addr[5],
4241 ap_ne_pref, ap_ne_class, ap_ne_op_ch);
4242 run_system(dut, buf);
4243 }
4244
4245 /* Now add the self AP Address */
4246 if (dut->mbo_self_ap_tuple.ap_ne_class == -1) {
4247 if (dut->ap_channel <= 11)
4248 ap_ne_class = 81;
4249 else
4250 ap_ne_class = 115;
4251 } else {
4252 ap_ne_class = dut->mbo_self_ap_tuple.ap_ne_class;
4253 }
4254
4255 if (dut->mbo_self_ap_tuple.ap_ne_op_ch == -1)
4256 ap_ne_op_ch = dut->ap_channel;
4257 else
4258 ap_ne_op_ch = dut->mbo_self_ap_tuple.ap_ne_op_ch;
4259
4260 if (dut->mbo_self_ap_tuple.ap_ne_pref == -1)
4261 ap_ne_pref = least_pref - 1;
4262 else
4263 ap_ne_pref = dut->mbo_self_ap_tuple.ap_ne_pref;
4264
4265 snprintf(buf, sizeof(buf),
4266 "wifitool %s setbssidpref %02x:%02x:%02x:%02x:%02x:%02x %d %d %d",
4267 ifname, self_mac[0], self_mac[1], self_mac[2],
4268 self_mac[3], self_mac[4], self_mac[5],
4269 ap_ne_pref,
4270 ap_ne_class,
4271 ap_ne_op_ch);
4272 run_system(dut, buf);
4273}
4274
4275
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004276static void ath_ap_set_params(struct sigma_dut *dut)
4277{
4278 const char *basedev = "wifi1";
priyadharshini gowthamane1617462017-04-25 12:03:59 -07004279 const char *ifname = get_main_ifname();
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004280 int i;
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07004281 char buf[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004282
priyadharshini gowthamane1617462017-04-25 12:03:59 -07004283 if (sigma_radio_ifname[0])
4284 basedev = sigma_radio_ifname[0];
4285
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004286 if (dut->ap_countrycode[0]) {
4287 snprintf(buf, sizeof(buf), "iwpriv %s setCountry %s",
4288 basedev, dut->ap_countrycode);
4289 if (system(buf) != 0) {
4290 sigma_dut_print(dut, DUT_MSG_ERROR,
4291 "iwpriv setCountry failed");
4292 }
4293 sigma_dut_print(dut, DUT_MSG_INFO, "Set countrycode");
4294 }
4295
4296 for (i = 0; i < NUM_AP_AC; i++) {
4297 if (dut->ap_qos[i].ac) {
4298 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 0 %d",
4299 ifname, i, dut->ap_qos[i].cwmin);
4300 if (system(buf) != 0) {
4301 sigma_dut_print(dut, DUT_MSG_ERROR,
4302 "iwpriv cwmin failed");
4303 }
4304
4305 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 0 %d",
4306 ifname, i, dut->ap_qos[i].cwmax);
4307 if (system(buf) != 0) {
4308 sigma_dut_print(dut, DUT_MSG_ERROR,
4309 "iwpriv cwmax failed");
4310 }
4311
4312 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 0 %d",
4313 ifname, i, dut->ap_qos[i].aifs);
4314 if (system(buf) != 0) {
4315 sigma_dut_print(dut, DUT_MSG_ERROR,
4316 "iwpriv aifs failed");
4317 }
4318
4319 snprintf(buf, sizeof(buf),
4320 "iwpriv %s txoplimit %d 0 %d",
4321 ifname, i, dut->ap_qos[i].txop);
4322 if (system(buf) != 0) {
4323 sigma_dut_print(dut, DUT_MSG_ERROR,
4324 "iwpriv txoplimit failed");
4325 }
4326
4327 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 0 %d",
4328 ifname, i, dut->ap_qos[i].acm);
4329 if (system(buf) != 0) {
4330 sigma_dut_print(dut, DUT_MSG_ERROR,
4331 "iwpriv acm failed");
4332 }
4333 }
4334 }
4335
4336 for (i = 0; i < NUM_AP_AC; i++) {
4337 if (dut->ap_sta_qos[i].ac) {
4338 snprintf(buf, sizeof(buf), "iwpriv %s cwmin %d 1 %d",
4339 ifname, i, dut->ap_sta_qos[i].cwmin);
4340 if (system(buf) != 0) {
4341 sigma_dut_print(dut, DUT_MSG_ERROR,
4342 "iwpriv cwmin failed");
4343 }
4344
4345 snprintf(buf, sizeof(buf), "iwpriv %s cwmax %d 1 %d",
4346 ifname, i, dut->ap_sta_qos[i].cwmax);
4347 if (system(buf) != 0) {
4348 sigma_dut_print(dut, DUT_MSG_ERROR,
4349 "iwpriv cwmax failed");
4350 }
4351
4352 snprintf(buf, sizeof(buf), "iwpriv %s aifs %d 1 %d",
4353 ifname, i, dut->ap_sta_qos[i].aifs);
4354 if (system(buf) != 0) {
4355 sigma_dut_print(dut, DUT_MSG_ERROR,
4356 "iwpriv aifs failed");
4357 }
4358
4359 snprintf(buf, sizeof(buf),
4360 "iwpriv %s txoplimit %d 1 %d",
4361 ifname, i, dut->ap_sta_qos[i].txop);
4362 if (system(buf) != 0) {
4363 sigma_dut_print(dut, DUT_MSG_ERROR,
4364 "iwpriv txoplimit failed");
4365 }
4366
4367 snprintf(buf, sizeof(buf), "iwpriv %s acm %d 1 %d",
4368 ifname, i, dut->ap_sta_qos[i].acm);
4369 if (system(buf) != 0) {
4370 sigma_dut_print(dut, DUT_MSG_ERROR,
4371 "iwpriv acm failed");
4372 }
4373 }
4374 }
4375
4376 if (dut->ap_disable_protection == 1) {
4377 snprintf(buf, sizeof(buf), "iwpriv %s enablertscts 0", ifname);
4378 if (system(buf) != 0) {
4379 sigma_dut_print(dut, DUT_MSG_ERROR,
4380 "iwpriv enablertscts failed");
4381 }
4382 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled rtscts");
4383 }
4384
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004385 if (dut->ap_ldpc == VALUE_ENABLED) {
Sarvepalli, Rajesh Babu580572a2016-11-29 22:07:14 +05304386 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 3", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004387 if (system(buf) != 0) {
4388 sigma_dut_print(dut, DUT_MSG_ERROR,
priyadharshini gowthaman15b299d2017-04-20 12:10:45 -07004389 "iwpriv ldpc 3 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004390 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004391 } else if (dut->ap_ldpc == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004392 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", ifname);
4393 if (system(buf) != 0) {
4394 sigma_dut_print(dut, DUT_MSG_ERROR,
4395 "iwpriv ldpc 0 failed");
4396 }
4397 }
4398
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004399 if (dut->ap_ampdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004400 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 1", ifname);
4401 if (system(buf) != 0) {
4402 sigma_dut_print(dut, DUT_MSG_ERROR,
4403 "iwpriv ampdu 1 failed");
4404 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004405 } else if (dut->ap_ampdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004406 snprintf(buf, sizeof(buf), "iwpriv %s ampdu 0", ifname);
4407 if (system(buf) != 0) {
4408 sigma_dut_print(dut, DUT_MSG_ERROR,
4409 "iwpriv ampdu 0 failed");
4410 }
4411 }
4412
4413 if (dut->ap_ampdu_exp) {
4414 if (dut->program == PROGRAM_VHT) {
4415 snprintf(buf, sizeof(buf), "iwpriv %s vhtmaxampdu %d",
4416 ifname, dut->ap_ampdu_exp);
4417 if (system(buf) != 0) {
4418 sigma_dut_print(dut, DUT_MSG_ERROR,
4419 "iwpriv vhtmaxampdu failed");
4420 }
4421 } else {
4422 /* 11N */
4423 snprintf(buf, sizeof(buf), "iwpriv %s maxampdu %d",
4424 ifname, dut->ap_ampdu_exp);
4425 if (system(buf) != 0) {
4426 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv maxampdu failed");
4427 }
4428 }
4429 }
4430
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004431 if (dut->ap_noack == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004432 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 1", ifname);
4433 if (system(buf) != 0) {
4434 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 1 failed");
4435 }
4436 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 1", ifname);
4437 if (system(buf) != 0) {
4438 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 1 failed");
4439 }
4440 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 1", ifname);
4441 if (system(buf) != 0) {
4442 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 1 failed");
4443 }
4444 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 1", ifname);
4445 if (system(buf) != 0) {
4446 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 1 failed");
4447 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004448 } else if (dut->ap_noack == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004449 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 0 0 0", ifname);
4450 if (system(buf) != 0) {
4451 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 0 0 0 failed");
4452 }
4453 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 1 0 0", ifname);
4454 if (system(buf) != 0) {
4455 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 1 0 0 failed");
4456 }
4457 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 2 0 0", ifname);
4458 if (system(buf) != 0) {
4459 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 2 0 0 failed");
4460 }
4461 snprintf(buf, sizeof(buf), "iwpriv %s noackpolicy 3 0 0", ifname);
4462 if (system(buf) != 0) {
4463 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv noackpolicy 3 0 0 failed");
4464 }
4465 }
4466
4467 if (dut->device_type == AP_testbed && dut->ap_vhtmcs_map) {
4468 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4469 ifname, dut->ap_vhtmcs_map);
4470 if (system(buf) != 0) {
4471 sigma_dut_print(dut, DUT_MSG_ERROR,
4472 "iwpriv vht_mcsmap failed");
4473 }
4474 }
4475
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004476 if (dut->ap_amsdu == VALUE_ENABLED) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03004477 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004478 if (system(buf) != 0) {
Sunil Dutt27ec7f62017-09-14 18:22:59 +03004479 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 2 failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004480 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004481 } else if (dut->ap_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004482 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", ifname);
4483 if (system(buf) != 0) {
4484 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu 1 failed");
4485 }
4486 }
4487
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004488 if (dut->ap_rx_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004489 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 1");
4490 if (system(buf) != 0) {
4491 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 1 failed");
4492 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004493 } else if (dut->ap_rx_amsdu == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004494 snprintf(buf, sizeof(buf), "iwpriv wifi1 rx_amsdu 0");
4495 if (system(buf) != 0) {
4496 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_amsdu 0 failed");
4497 }
4498 }
4499
4500 /* Command sequence to generate single VHT AMSDU and MPDU */
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004501 if (dut->ap_addba_reject != VALUE_NOT_SET &&
4502 dut->ap_ampdu == VALUE_DISABLED &&
4503 dut->ap_amsdu == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004504 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", ifname);
4505 if (system(buf) != 0) {
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "iwpriv setaddbaoper 1 failed");
4508 }
4509
4510 snprintf(buf, sizeof(buf),
4511 "wifitool %s senddelba 1 0 1 4", ifname);
4512 if (system(buf) != 0) {
4513 sigma_dut_print(dut, DUT_MSG_ERROR,
4514 "wifitool senddelba failed");
4515 }
4516
4517 snprintf(buf, sizeof(buf), "wifitool %s sendsingleamsdu 1 0",
4518 ifname);
4519 if (system(buf) != 0) {
4520 sigma_dut_print(dut, DUT_MSG_ERROR,
4521 "wifitool sendsingleamsdu failed");
4522 }
4523
4524 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 10", ifname);
4525 if (system(buf) != 0) {
4526 sigma_dut_print(dut, DUT_MSG_ERROR,
4527 "iwpriv amsdu failed");
4528 }
4529 }
4530
4531 if (dut->ap_mode == AP_11ac) {
4532 int chwidth, nss;
4533
4534 switch (dut->ap_chwidth) {
4535 case AP_20:
4536 chwidth = 0;
4537 break;
4538 case AP_40:
4539 chwidth = 1;
4540 break;
4541 case AP_80:
4542 chwidth = 2;
4543 break;
4544 case AP_160:
4545 chwidth = 3;
4546 break;
4547 default:
4548 chwidth = 0;
4549 break;
4550 }
4551
4552 switch (dut->ap_tx_streams) {
4553 case 1:
4554 nss = 1;
4555 break;
4556 case 2:
4557 nss = 2;
4558 break;
4559 case 3:
4560 nss = 3;
4561 break;
4562 case 4:
4563 nss = 4;
4564 break;
4565 default:
4566 nss = 3;
4567 break;
4568 }
4569
4570 if (dut->ap_fixed_rate) {
4571 if (nss == 4)
4572 ath_disable_txbf(dut, ifname);
4573
4574 /* Set the nss */
4575 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
4576 ifname, nss);
4577 if (system(buf) != 0) {
4578 sigma_dut_print(dut, DUT_MSG_ERROR,
4579 "iwpriv nss failed");
4580 }
4581
4582 /* Set the channel width */
4583 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
4584 ifname, chwidth);
4585 if (system(buf) != 0) {
4586 sigma_dut_print(dut, DUT_MSG_ERROR,
4587 "iwpriv chwidth failed");
4588 }
4589
4590 /* Set the VHT MCS */
4591 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
4592 ifname, dut->ap_mcs);
4593 if (system(buf) != 0) {
4594 sigma_dut_print(dut, DUT_MSG_ERROR,
4595 "iwpriv vhtmcs failed");
4596 }
4597 }
4598 }
4599
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004600 if (dut->ap_dyn_bw_sig == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004601 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", ifname);
4602 if (system(buf) != 0) {
4603 sigma_dut_print(dut, DUT_MSG_ERROR,
4604 "iwpriv cwmenable 1 failed");
4605 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004606 } else if (dut->ap_dyn_bw_sig == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004607 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 0", ifname);
4608 if (system(buf) != 0) {
4609 sigma_dut_print(dut, DUT_MSG_ERROR,
4610 "iwpriv cwmenable 0 failed");
4611 }
4612 }
4613
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004614 if (dut->ap_sig_rts == VALUE_ENABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004615 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", ifname);
4616 if (system(buf) != 0) {
4617 sigma_dut_print(dut, DUT_MSG_ERROR,
4618 "iwconfig rts 64 failed");
4619 }
Jouni Malinen57fa3d82016-11-30 12:51:43 +02004620 } else if (dut->ap_sig_rts == VALUE_DISABLED) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004621 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", ifname);
4622 if (system(buf) != 0) {
4623 sigma_dut_print(dut, DUT_MSG_ERROR,
4624 "iwpriv rts 2347 failed");
4625 }
4626 }
4627
4628 if (dut->ap_hs2) {
4629 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 1", ifname);
4630 if (system(buf) != 0) {
4631 sigma_dut_print(dut, DUT_MSG_ERROR,
4632 "iwpriv qbssload failed");
4633 }
4634 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled qbssload");
4635 }
4636
4637 if (dut->ap_bss_load && dut->ap_bss_load != -1) {
4638 unsigned int bssload = 0;
4639
4640 if (dut->ap_bss_load == 1) {
4641 /* STA count: 1, CU: 50, AAC: 65535 */
4642 bssload = 0x0132ffff;
4643 } else if (dut->ap_bss_load == 2) {
4644 /* STA count: 1, CU: 200, AAC: 65535 */
4645 bssload = 0x01c8ffff;
4646 } else if (dut->ap_bss_load == 3) {
4647 /* STA count: 1, CU: 75, AAC: 65535 */
4648 bssload = 0x014bffff;
4649 }
4650
4651 snprintf(buf, sizeof(buf), "iwpriv %s hcbssload %u",
4652 ifname, bssload);
4653 if (system(buf) != 0) {
4654 sigma_dut_print(dut, DUT_MSG_ERROR,
4655 "iwpriv hcbssload failed");
4656 }
4657 } else if (dut->ap_bss_load == 0) {
4658 snprintf(buf, sizeof(buf), "iwpriv %s qbssload 0", ifname);
4659 if (system(buf) != 0) {
4660 sigma_dut_print(dut, DUT_MSG_ERROR,
4661 "iwpriv qbssload failed");
4662 }
4663 sigma_dut_print(dut, DUT_MSG_INFO, "Disabled qbssload");
4664 }
4665
4666 if (dut->ap_dgaf_disable) {
4667 snprintf(buf, sizeof(buf), "iwpriv %s dgaf_disable 1", ifname);
4668 if (system(buf) != 0) {
4669 sigma_dut_print(dut, DUT_MSG_ERROR,
4670 "iwpriv dgaf_disable failed");
4671 }
4672 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled dgaf_disable");
4673 }
4674
4675 if (dut->ap_l2tif) {
4676 snprintf(buf, sizeof(buf), "iwpriv %s l2tif 1", ifname);
4677 if (system(buf) != 0) {
4678 sigma_dut_print(dut, DUT_MSG_ERROR,
4679 "iwpriv l2tif failed");
4680 }
4681 snprintf(buf, sizeof(buf),
4682 "echo 1 > /sys/class/net/br0/brif/ath0/hotspot_l2tif");
4683 if (system(buf) != 0)
4684 sigma_dut_print(dut, DUT_MSG_ERROR,
4685 "l2tif br failed");
4686
4687 snprintf(buf, sizeof(buf),
4688 "echo 1 > /sys/class/net/br0/brif/eth0/hotspot_wan");
4689 if (system(buf) != 0)
4690 sigma_dut_print(dut, DUT_MSG_ERROR,
4691 "l2tif brif failed");
4692 sigma_dut_print(dut, DUT_MSG_INFO, "Enabled l2tif");
4693 }
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08004694
4695 if (dut->ap_ndpa_frame == 0) {
4696 snprintf(buf, sizeof(buf),
4697 "wifitool %s beeliner_fw_test 117 192", ifname);
4698 if (system(buf) != 0) {
4699 sigma_dut_print(dut, DUT_MSG_ERROR,
4700 "wifitool beeliner_fw_test 117 192 failed");
4701 }
4702 snprintf(buf, sizeof(buf),
4703 "wifitool %s beeliner_fw_test 118 192", ifname);
4704 if (system(buf) != 0) {
4705 sigma_dut_print(dut, DUT_MSG_ERROR,
4706 "wifitool beeliner_fw_test 117 192 failed");
4707 }
4708 } else if (dut->ap_ndpa_frame == 1) {
4709 /* Driver default - no changes needed */
4710 } else if (dut->ap_ndpa_frame == 2) {
4711 snprintf(buf, sizeof(buf),
4712 "wifitool %s beeliner_fw_test 115 1", ifname);
4713 if (system(buf) != 0) {
4714 sigma_dut_print(dut, DUT_MSG_ERROR,
4715 "wifitool beeliner_fw_test 117 192 failed");
4716 }
4717 snprintf(buf, sizeof(buf),
4718 "wifitool %s beeliner_fw_test 116 1", ifname);
4719 if (system(buf) != 0) {
4720 sigma_dut_print(dut, DUT_MSG_ERROR,
4721 "wifitool beeliner_fw_test 117 192 failed");
4722 }
4723 }
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07004724
4725 if (dut->ap_rtt == 1) {
4726 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
4727 run_system(dut, buf);
4728 }
4729
4730 if (dut->ap_lci == 1) {
4731 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
4732 run_system(dut, buf);
4733 }
4734
4735 if (dut->ap_lcr == 1) {
4736 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
4737 run_system(dut, buf);
4738 }
4739
4740 if (dut->ap_rrm == 1) {
4741 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
4742 run_system(dut, buf);
4743 }
4744
4745 if (dut->ap_lci == 1 || dut->ap_lcr == 1) {
4746 run_system(dut, "wpc -l /tmp/lci_cfg.txt");
4747 }
4748
4749 if (dut->ap_neighap >= 1 && dut->ap_lci == 0) {
4750 FILE *f;
4751
4752 f = fopen("/tmp/nbr_report.txt", "w");
4753 if (!f) {
4754 sigma_dut_print(dut, DUT_MSG_ERROR,
4755 "Failed to open /tmp/nbr_report.txt");
4756 return;
4757 }
4758
4759 fprintf(f,
4760 "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",
4761 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
4762 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
4763 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
4764 dut->ap_val_opchannel[0]);
4765 fclose(f);
4766
4767 f = fopen("/tmp/ftmrr.txt", "w");
4768 if (!f) {
4769 sigma_dut_print(dut, DUT_MSG_ERROR,
4770 "Failed to open /tmp/ftmrr.txt");
4771 return;
4772 }
4773
4774 fprintf(f,
4775 "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",
4776 dut->ap_val_neighap[0][0], dut->ap_val_neighap[0][1],
4777 dut->ap_val_neighap[0][2], dut->ap_val_neighap[0][3],
4778 dut->ap_val_neighap[0][4], dut->ap_val_neighap[0][5],
4779 dut->ap_val_opchannel[0]);
4780 fclose(f);
4781 }
4782
4783 if (dut->ap_neighap >= 2 && dut->ap_lci == 0) {
4784 FILE *f;
4785
4786 f = fopen("/tmp/nbr_report.txt", "a");
4787 if (!f) {
4788 sigma_dut_print(dut, DUT_MSG_ERROR,
4789 "Failed to open /tmp/nbr_report.txt");
4790 return;
4791 }
4792 fprintf(f,
4793 "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",
4794 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
4795 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
4796 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
4797 dut->ap_val_opchannel[1]);
4798 fclose(f);
4799
4800 f = fopen("/tmp/ftmrr.txt", "a");
4801 if (!f) {
4802 sigma_dut_print(dut, DUT_MSG_ERROR,
4803 "Failed to open /tmp/ftmrr.txt");
4804 return;
4805 }
4806 fprintf(f,
4807 "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",
4808 dut->ap_val_neighap[1][0], dut->ap_val_neighap[1][1],
4809 dut->ap_val_neighap[1][2], dut->ap_val_neighap[1][3],
4810 dut->ap_val_neighap[1][4], dut->ap_val_neighap[1][5],
4811 dut->ap_val_opchannel[1]);
4812 fclose(f);
4813 }
4814
4815 if (dut->ap_neighap >= 3 && dut->ap_lci == 0) {
4816 FILE *f;
4817
4818 f = fopen("/tmp/nbr_report.txt", "a");
4819 if (!f) {
4820 sigma_dut_print(dut, DUT_MSG_ERROR,
4821 "Failed to open /tmp/nbr_report.txt");
4822 return;
4823 }
4824
4825 fprintf(f,
4826 "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",
4827 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
4828 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
4829 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
4830 dut->ap_val_opchannel[2]);
4831 fclose(f);
4832
4833 f = fopen("/tmp/ftmrr.txt", "a");
4834 if (!f) {
4835 sigma_dut_print(dut, DUT_MSG_ERROR,
4836 "Failed to open /tmp/ftmrr.txt");
4837 return;
4838 }
4839
4840 fprintf(f,
4841 "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",
4842 dut->ap_val_neighap[2][0], dut->ap_val_neighap[2][1],
4843 dut->ap_val_neighap[2][2], dut->ap_val_neighap[2][3],
4844 dut->ap_val_neighap[2][4], dut->ap_val_neighap[2][5],
4845 dut->ap_val_opchannel[2]);
4846 fclose(f);
4847 }
4848
4849 if (dut->ap_neighap) {
4850 snprintf(buf, sizeof(buf), "iwpriv %s enable_rtt 1", ifname);
4851 run_system(dut, buf);
4852 snprintf(buf, sizeof(buf), "iwpriv %s enable_lci 1", ifname);
4853 run_system(dut, buf);
4854 snprintf(buf, sizeof(buf), "iwpriv %s enable_lcr 1", ifname);
4855 run_system(dut, buf);
4856 snprintf(buf, sizeof(buf), "iwpriv %s rrm 1", ifname);
4857 run_system(dut, buf);
4858 }
4859
4860 if (dut->ap_scan == 1) {
4861 snprintf(buf, sizeof(buf), "iwpriv %s scanentryage 600",
4862 ifname);
4863 run_system(dut, buf);
4864 snprintf(buf, sizeof(buf), "iwlist %s scan", ifname);
4865 run_system(dut, buf);
4866 }
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07004867
4868 if (dut->ap_set_bssidpref) {
4869 snprintf(buf, sizeof(buf),
4870 "wifitool %s setbssidpref 00:00:00:00:00:00 0 00 00",
4871 ifname);
4872 if (system(buf) != 0) {
4873 sigma_dut_print(dut, DUT_MSG_ERROR,
4874 "wifitool clear bssidpref failed");
4875 }
4876 }
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07004877
4878 if (dut->wnm_bss_max_feature != VALUE_NOT_SET) {
4879 int feature_enable;
4880
4881 feature_enable = dut->wnm_bss_max_feature == VALUE_ENABLED;
4882 snprintf(buf, sizeof(buf), "iwpriv %s wnm %d",
4883 ifname, feature_enable);
4884 run_system(dut, buf);
4885 snprintf(buf, sizeof(buf), "iwpriv %s wnm_bss %d",
4886 ifname, feature_enable);
4887 run_system(dut, buf);
4888 if (feature_enable) {
4889 const char *extra = "";
4890
4891 if (dut->wnm_bss_max_protection != VALUE_NOT_SET) {
4892 if (dut->wnm_bss_max_protection ==
4893 VALUE_ENABLED)
4894 extra = " 1";
4895 else
4896 extra = " 0";
4897 }
4898 snprintf(buf, sizeof(buf),
4899 "wlanconfig %s wnm setbssmax %d%s",
4900 ifname, dut->wnm_bss_max_idle_time, extra);
4901 run_system(dut, buf);
4902 }
4903 }
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004904
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004905 if (dut->program == PROGRAM_MBO) {
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07004906 apply_mbo_pref_ap_list(dut);
4907
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004908 snprintf(buf, sizeof(buf), "iwpriv %s mbo_cel_pref %d",
4909 ifname, dut->ap_cell_cap_pref);
4910 run_system(dut, buf);
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07004911
4912 snprintf(buf, sizeof(buf), "iwpriv %s mbocap 0x40", ifname);
4913 run_system(dut, buf);
4914
Adil Saeed Musthafa05ec7442017-04-10 23:13:35 -07004915 ath_set_assoc_disallow(dut, ifname, "disable");
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07004916 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004917}
4918
4919
4920static int cmd_ath_ap_config_commit(struct sigma_dut *dut,
4921 struct sigma_conn *conn,
4922 struct sigma_cmd *cmd)
4923{
4924 /* const char *name = get_param(cmd, "NAME"); */
4925 char buf[100];
4926 struct stat s;
4927 const char *ifname = dut->ap_is_dual ? "ath1" : "ath0";
4928
4929 if (stat("/proc/athversion", &s) == 0) {
4930 sigma_dut_print(dut, DUT_MSG_INFO, "Run apdown");
4931 run_system(dut, "apdown");
4932 }
4933
4934 cmd_ath_ap_radio_config(dut);
4935
4936 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID=%s'", dut->ap_ssid);
4937 run_system(dut, buf);
4938
4939 switch (dut->ap_key_mgmt) {
4940 case AP_OPEN:
4941 if (dut->ap_cipher == AP_WEP) {
4942 run_system(dut, "cfg -a AP_SECMODE=WEP");
4943 run_system(dut, "cfg -a AP_SECFILE=NONE");
4944 /* shared auth mode not supported */
4945 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
4946 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
4947 snprintf(buf, sizeof(buf),
4948 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
4949 dut->ap_wepkey);
4950 run_system(dut, buf);
4951 snprintf(buf, sizeof(buf),
4952 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
4953 dut->ap_wepkey);
4954 run_system(dut, buf);
4955 } else {
4956 run_system(dut, "cfg -a AP_SECMODE=None");
4957 }
4958 break;
4959 case AP_WPA2_PSK:
4960 case AP_WPA2_PSK_MIXED:
4961 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03004962 case AP_WPA2_SAE:
4963 case AP_WPA2_PSK_SAE:
4964 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
4965 dut->ap_key_mgmt == AP_WPA2_SAE ||
4966 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004967 run_system(dut, "cfg -a AP_WPA=2");
4968 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
4969 run_system(dut, "cfg -a AP_WPA=3");
4970 else
4971 run_system(dut, "cfg -a AP_WPA=1");
Jouni Malinen30824df2017-08-22 21:21:38 +03004972 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004973 run_system(dut, "cfg -a AP_SECMODE=WPA");
4974 run_system(dut, "cfg -a AP_SECFILE=PSK");
4975 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY=%s'",
4976 dut->ap_passphrase);
4977 run_system(dut, buf);
4978 if (dut->ap_cipher == AP_CCMP_TKIP)
4979 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
4980 else if (dut->ap_cipher == AP_TKIP)
4981 run_system(dut, "cfg -a AP_CYPHER=TKIP");
4982 else
4983 run_system(dut, "cfg -a AP_CYPHER=CCMP");
4984 break;
4985 case AP_WPA2_EAP:
4986 case AP_WPA2_EAP_MIXED:
4987 case AP_WPA_EAP:
4988 if (dut->ap_key_mgmt == AP_WPA2_EAP)
4989 run_system(dut, "cfg -a AP_WPA=2");
4990 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
4991 run_system(dut, "cfg -a AP_WPA=3");
4992 else
4993 run_system(dut, "cfg -a AP_WPA=1");
4994 run_system(dut, "cfg -a AP_SECMODE=WPA");
4995 run_system(dut, "cfg -a AP_SECFILE=EAP");
4996 if (dut->ap_cipher == AP_CCMP_TKIP)
4997 run_system(dut, "cfg -a AP_CYPHER=\"CCMP TKIP\"");
4998 else if (dut->ap_cipher == AP_TKIP)
4999 run_system(dut, "cfg -a AP_CYPHER=TKIP");
5000 else
5001 run_system(dut, "cfg -a AP_CYPHER=CCMP");
5002 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER=%s",
5003 dut->ap_radius_ipaddr);
5004 run_system(dut, buf);
5005 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT=%d",
5006 dut->ap_radius_port);
5007 run_system(dut, buf);
5008 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET=%s",
5009 dut->ap_radius_password);
5010 run_system(dut, buf);
5011 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03005012 case AP_SUITEB:
5013 /* TODO */
5014 sigma_dut_print(dut, DUT_MSG_ERROR, "SuiteB not supported");
5015 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03005016 case AP_WPA2_OWE:
5017 /* TODO */
5018 sigma_dut_print(dut, DUT_MSG_ERROR, "OWE not supported");
5019 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005020 }
5021
5022 if (dut->ap_is_dual) {
5023 /* ath1 settings in case of dual */
5024 snprintf(buf, sizeof(buf), "cfg -a 'AP_SSID_2=%s'",
5025 dut->ap_ssid);
5026 run_system(dut, buf);
5027
5028 switch (dut->ap_key_mgmt) {
5029 case AP_OPEN:
5030 if (dut->ap_cipher == AP_WEP) {
5031 run_system(dut, "cfg -a AP_SECMODE_2=WEP");
5032 run_system(dut, "cfg -a AP_SECFILE_2=NONE");
5033 /* shared auth mode not supported */
5034 run_system(dut, "cfg -a AP_WEP_MODE_0=1");
5035 run_system(dut, "cfg -a AP_WEP_MODE_1=1");
5036 snprintf(buf, sizeof(buf),
5037 "cfg -a WEP_RADIO_NUM0_KEY_1=%s",
5038 dut->ap_wepkey);
5039 run_system(dut, buf);
5040 snprintf(buf, sizeof(buf),
5041 "cfg -a WEP_RADIO_NUM1_KEY_1=%s",
5042 dut->ap_wepkey);
5043 run_system(dut, buf);
5044 } else {
5045 run_system(dut, "cfg -a AP_SECMODE_2=None");
5046 }
5047 break;
5048 case AP_WPA2_PSK:
5049 case AP_WPA2_PSK_MIXED:
5050 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005051 case AP_WPA2_SAE:
5052 case AP_WPA2_PSK_SAE:
5053 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5054 dut->ap_key_mgmt == AP_WPA2_SAE ||
5055 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005056 run_system(dut, "cfg -a AP_WPA_2=2");
5057 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5058 run_system(dut, "cfg -a AP_WPA_2=3");
5059 else
5060 run_system(dut, "cfg -a AP_WPA_2=1");
5061 // run_system(dut, "cfg -a AP_WPA_2=2");
Jouni Malinen30824df2017-08-22 21:21:38 +03005062 /* TODO: SAE configuration */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005063 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5064 run_system(dut, "cfg -a AP_SECFILE_2=PSK");
5065 snprintf(buf, sizeof(buf), "cfg -a 'PSK_KEY_2=%s'",
5066 dut->ap_passphrase);
5067 run_system(dut, buf);
5068 if (dut->ap_cipher == AP_CCMP_TKIP)
5069 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
5070 else if (dut->ap_cipher == AP_TKIP)
5071 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
5072 else
5073 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
5074 break;
5075 case AP_WPA2_EAP:
5076 case AP_WPA2_EAP_MIXED:
5077 case AP_WPA_EAP:
5078 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5079 run_system(dut, "cfg -a AP_WPA_2=2");
5080 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5081 run_system(dut, "cfg -a AP_WPA_2=3");
5082 else
5083 run_system(dut, "cfg -a AP_WPA_2=1");
5084 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5085 run_system(dut, "cfg -a AP_SECFILE_2=EAP");
5086 if (dut->ap_cipher == AP_CCMP_TKIP)
5087 run_system(dut, "cfg -a AP_CYPHER_2=\"CCMP TKIP\"");
5088 else if (dut->ap_cipher == AP_TKIP)
5089 run_system(dut, "cfg -a AP_CYPHER_2=TKIP");
5090 else
5091 run_system(dut, "cfg -a AP_CYPHER_2=CCMP");
5092
5093 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
5094 dut->ap_radius_ipaddr);
5095 run_system(dut, buf);
5096 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
5097 dut->ap_radius_port);
5098 run_system(dut, buf);
5099 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
5100 dut->ap_radius_password);
5101 run_system(dut, buf);
5102 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03005103 case AP_SUITEB:
5104 /* TODO */
5105 sigma_dut_print(dut, DUT_MSG_ERROR,
5106 "SuiteB not supported");
5107 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03005108 case AP_WPA2_OWE:
5109 /* TODO */
5110 sigma_dut_print(dut, DUT_MSG_ERROR,
5111 "OWE not supported");
5112 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005113 }
5114
5115 /* wifi0 settings in case of dual */
5116 run_system(dut, "cfg -a AP_RADIO_ID=0");
5117 run_system(dut, "cfg -a AP_PRIMARY_CH=6");
5118 run_system(dut, "cfg -a AP_STARTMODE=dual");
5119 run_system(dut, "cfg -a AP_CHMODE=11NGHT40PLUS");
5120 run_system(dut, "cfg -a TX_CHAINMASK=7");
5121 run_system(dut, "cfg -a RX_CHAINMASK=7");
5122 }
5123
5124 switch (dut->ap_pmf) {
5125 case AP_PMF_DISABLED:
5126 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=0");
5127 run_system(dut, buf);
5128 break;
5129 case AP_PMF_OPTIONAL:
5130 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=1");
5131 run_system(dut, buf);
5132 break;
5133 case AP_PMF_REQUIRED:
5134 snprintf(buf, sizeof(buf), "cfg -a AP_PMF=2");
5135 run_system(dut, buf);
5136 break;
5137 }
5138 if (dut->ap_add_sha256) {
5139 snprintf(buf, sizeof(buf), "cfg -a AP_WPA_SHA256=1");
5140 run_system(dut, buf);
5141 } else {
5142 snprintf(buf, sizeof(buf), "cfg -r AP_WPA_SHA256");
5143 run_system(dut, buf);
5144 }
5145
5146 if (dut->ap_hs2)
5147 run_system(dut, "cfg -a AP_HOTSPOT=1");
5148 else
5149 run_system(dut, "cfg -r AP_HOTSPOT");
5150
5151 if (dut->ap_interworking) {
5152 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_ANT=%d",
5153 dut->ap_access_net_type);
5154 run_system(dut, buf);
5155 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_INTERNET=%d",
5156 dut->ap_internet);
5157 run_system(dut, buf);
5158 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUEGROUP=%d",
5159 dut->ap_venue_group);
5160 run_system(dut, buf);
5161 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_VENUETYPE=%d",
5162 dut->ap_venue_type);
5163 run_system(dut, buf);
5164 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID=%s",
5165 dut->ap_hessid);
5166 run_system(dut, buf);
5167
5168 if (dut->ap_roaming_cons[0]) {
5169 char *second, *rc;
5170 rc = strdup(dut->ap_roaming_cons);
5171 if (rc == NULL)
5172 return 0;
5173
5174 second = strchr(rc, ';');
5175 if (second)
5176 *second++ = '\0';
5177
5178 snprintf(buf, sizeof(buf),
5179 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=%s", rc);
5180 run_system(dut, buf);
5181
5182 if (second) {
5183 snprintf(buf, sizeof(buf),
5184 "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2"
5185 "=%s", second);
5186 run_system(dut, buf);
5187 }
5188 free(rc);
5189 } else {
5190 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
5191 run_system(dut,
5192 "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
5193 }
5194 } else {
5195 run_system(dut, "cfg -r AP_HOTSPOT_ANT");
5196 run_system(dut, "cfg -r AP_HOTSPOT_INTERNET");
5197 run_system(dut, "cfg -r AP_HOTSPOT_VENUEGROUP");
5198 run_system(dut, "cfg -r AP_HOTSPOT_VENUETYPE");
5199 run_system(dut, "cfg -r AP_HOTSPOT_HESSID");
5200 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM");
5201 run_system(dut, "cfg -r AP_HOTSPOT_ROAMINGCONSORTIUM2");
5202 }
5203
5204 if (dut->ap_proxy_arp)
5205 run_system(dut, "cfg -a IEEE80211V_PROXYARP=1");
5206 else
5207 run_system(dut, "cfg -a IEEE80211V_PROXYARP=0");
5208 if (dut->ap_dgaf_disable)
5209 run_system(dut, "cfg -a AP_HOTSPOT_DISABLE_DGAF=1");
5210 else
5211 run_system(dut, "cfg -r AP_HOTSPOT_DISABLE_DGAF");
5212
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005213 if (strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005214 snprintf(buf, sizeof(buf),
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005215 "cfg -a AP_SSID_2=%s", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005216 run_system(dut, buf);
5217
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005218 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005219 run_system(dut, "cfg -a AP_SECMODE_2=WPA");
5220 run_system(dut, "cfg -a AP_SECFILE_2=OSEN");
5221
5222 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SERVER_2=%s",
5223 dut->ap2_radius_ipaddr);
5224 run_system(dut, buf);
5225
5226 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_PORT_2=%d",
5227 dut->ap2_radius_port);
5228 run_system(dut, buf);
5229
5230 snprintf(buf, sizeof(buf), "cfg -a AP_AUTH_SECRET_2=%s",
5231 dut->ap2_radius_password);
5232 run_system(dut, buf);
5233 } else {
5234 run_system(dut, "cfg -a AP_SECMODE_2=None");
5235 run_system(dut, "cfg -r AP_AUTH_SERVER_2");
5236 run_system(dut, "cfg -r AP_AUTH_PORT_2");
5237 run_system(dut, "cfg -r AP_AUTH_SECRET_2");
5238 }
5239
5240 run_system(dut, "cfg -a AP_STARTMODE=multi");
5241 }
5242
5243 run_system(dut, "cfg -c");
5244
5245 sigma_dut_print(dut, DUT_MSG_INFO, "Starting AP");
5246 if (system("apup") != 0) {
5247 /* to be debugged why apup returns error
5248 send_resp(dut, conn, SIGMA_ERROR,
5249 "errorCode,apup failed");
5250 return 0;
5251 */
5252 }
5253 sigma_dut_print(dut, DUT_MSG_INFO, "AP started");
5254
5255 if (dut->ap_key_mgmt != AP_OPEN) {
5256 int res;
5257 /* allow some time for hostapd to start before returning
5258 * success */
5259 usleep(500000);
5260 if (run_hostapd_cli(dut, "ping") != 0) {
5261 send_resp(dut, conn, SIGMA_ERROR,
5262 "errorCode,Failed to talk to hostapd");
5263 return 0;
5264 }
5265
5266 if (dut->ap_hs2 && !dut->ap_anqpserver) {
5267 /* the cfg app doesn't like ";" in the variables */
5268 res = ath_ap_append_hostapd_conf(dut);
5269 if (res < 0)
5270 return res;
5271
5272 /* wait for hostapd to be ready */
5273 usleep(500000);
5274 if (run_hostapd_cli(dut, "ping") != 0) {
5275 send_resp(dut, conn, SIGMA_ERROR,
5276 "errorCode,Failed to talk to "
5277 "hostapd");
5278 return 0;
5279 }
5280 }
5281 }
5282
5283 ath_ap_set_params(dut);
5284
5285 if (dut->ap_anqpserver)
5286 return cmd_ath_ap_anqpserver_start(dut);
5287
5288 if (dut->ap2_proxy_arp)
5289 run_system(dut, "iwpriv ath1 proxy_arp 1");
5290
5291 if (dut->ap_allow_vht_wep || dut->ap_allow_vht_tkip) {
5292 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1", ifname);
5293 if (system(buf) != 0) {
5294 sigma_dut_print(dut, DUT_MSG_ERROR,
5295 "iwpriv htweptkip failed");
5296 }
5297 }
5298
5299 return 1;
5300}
5301
5302
5303static int set_ebtables_proxy_arp(struct sigma_dut *dut, const char *chain,
5304 const char *ifname)
5305{
5306 char buf[200];
5307
5308 if (!chain || !ifname)
5309 return -2;
5310
5311 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
5312 if (system(buf) != 0) {
5313 sigma_dut_print(dut, DUT_MSG_ERROR,
5314 "Failed to set ebtables rules, RULE-1, %s",
5315 chain);
5316 return -2;
5317 }
5318
5319 snprintf(buf, sizeof(buf),
5320 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
5321 chain, ifname);
5322 if (system(buf) != 0) {
5323 sigma_dut_print(dut, DUT_MSG_ERROR,
5324 "Failed to set ebtables rules, RULE-2, %s",
5325 chain);
5326 return -2;
5327 }
5328
5329 snprintf(buf, sizeof(buf),
5330 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-solicitation -o %s -j DROP",
5331 chain, ifname);
5332 if (system(buf) != 0) {
5333 sigma_dut_print(dut, DUT_MSG_ERROR,
5334 "Failed to set ebtables rules, RULE-3, %s",
5335 chain);
5336 return -2;
5337 }
5338
5339 snprintf(buf, sizeof(buf),
5340 "ebtables -A %s -d Multicast -p IPv6 --ip6-protocol ipv6-icmp --ip6-icmp-type neighbor-advertisement -o %s -j DROP",
5341 chain, ifname);
5342 if (system(buf) != 0) {
5343 sigma_dut_print(dut, DUT_MSG_ERROR,
5344 "Failed to set ebtables rules, RULE-4, %s",
5345 chain);
5346 return -2;
5347 }
5348
5349 return 0;
5350}
5351
5352
5353static int set_ebtables_disable_dgaf(struct sigma_dut *dut,
5354 const char *chain,
5355 const char *ifname)
5356{
5357 char buf[200];
5358
5359 if (!chain || !ifname)
5360 return -2;
5361
5362 snprintf(buf, sizeof(buf), "ebtables -P %s ACCEPT", chain);
5363 if (system(buf) != 0) {
5364 sigma_dut_print(dut, DUT_MSG_ERROR,
5365 "Failed to set ebtables rules, RULE-5, %s",
5366 chain);
5367 return -2;
5368 }
5369
5370 snprintf(buf, sizeof(buf),
5371 "ebtables -A %s -p ARP -d Broadcast -o %s -j DROP",
5372 chain, ifname);
5373 if (system(buf) != 0) {
5374 sigma_dut_print(dut, DUT_MSG_ERROR,
5375 "Failed to set ebtables rules, RULE-6, %s",
5376 chain);
5377 return -2;
5378 }
5379
5380 snprintf(buf, sizeof(buf),
5381 "ebtables -A %s -p IPv4 -d Multicast -o %s -j DROP",
5382 chain, ifname);
5383 if (system(buf) != 0) {
5384 sigma_dut_print(dut, DUT_MSG_ERROR,
5385 "Failed to set ebtables rules, RULE-7, %s",
5386 chain);
5387 return -2;
5388 }
5389
5390 snprintf(buf, sizeof(buf),
5391 "ebtables -A %s -p IPv6 -d Multicast -o %s -j DROP",
5392 chain, ifname);
5393 if (system(buf) != 0) {
5394 sigma_dut_print(dut, DUT_MSG_ERROR,
5395 "Failed to set ebtables rules, RULE-8, %s",
5396 chain);
5397 return -2;
5398 }
5399
5400 return 0;
5401}
5402
5403
5404static int check_channel(int channel)
5405{
5406 int channel_list[] = { 36, 40, 44, 48, 52, 60, 64, 100, 104, 108, 112,
5407 116, 120, 124, 128, 132, 140, 144, 149, 153, 157,
5408 161, 165 };
5409 int num_chan = sizeof(channel_list) / sizeof(int);
5410 int i;
5411
5412 for (i = 0; i < num_chan; i++) {
5413 if (channel == channel_list[i])
5414 return i;
5415 }
5416
5417 return -1;
5418}
5419
5420
5421static int get_oper_centr_freq_seq_idx(int chwidth, int channel)
5422{
5423 int ch_base;
5424 int period;
5425
5426 if (check_channel(channel) < 0)
5427 return -1;
5428
5429 if (channel >= 36 && channel <= 64)
5430 ch_base = 36;
5431 else if (channel >= 100 && channel <= 144)
5432 ch_base = 100;
5433 else
5434 ch_base = 149;
5435
5436 period = channel % ch_base * 5 / chwidth;
5437 return ch_base + period * chwidth / 5 + (chwidth - 20) / 10;
5438}
5439
5440
5441static int is_ht40plus_chan(int chan)
5442{
5443 return chan == 36 || chan == 44 || chan == 52 || chan == 60 ||
5444 chan == 100 || chan == 108 || chan == 116 || chan == 124 ||
5445 chan == 132 || chan == 149 || chan == 157;
5446}
5447
5448
5449static int is_ht40minus_chan(int chan)
5450{
5451 return chan == 40 || chan == 48 || chan == 56 || chan == 64 ||
5452 chan == 104 || chan == 112 || chan == 120 || chan == 128 ||
5453 chan == 136 || chan == 153 || chan == 161;
5454}
5455
5456
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05305457static int get_5g_channel_freq(int chan)
5458{
5459 return 5000 + chan * 5;
5460}
5461
5462
Jouni Malinen3d633da2017-09-14 22:19:21 +03005463static const char * hostapd_cipher_name(enum ap_cipher cipher)
5464{
5465 switch (cipher) {
5466 case AP_CCMP:
5467 return "CCMP";
5468 case AP_TKIP:
5469 return "TKIP";
5470 case AP_CCMP_TKIP:
5471 return "CCMP TKIP";
5472 case AP_GCMP_256:
5473 return "GCMP-256";
5474 case AP_GCMP_128:
5475 return "GCMP";
5476 case AP_CCMP_256:
5477 return "CCMP-256";
Jouni Malinend538c782017-11-17 12:13:04 +02005478 case AP_CCMP_128_GCMP_256:
5479 return "CCMP GCMP-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03005480 default:
5481 return "UNKNOWN";
5482 }
5483}
5484
5485
5486static const char *
5487hostapd_group_mgmt_cipher_name(enum ap_group_mgmt_cipher cipher)
5488{
5489 switch (cipher) {
5490 case AP_BIP_GMAC_256:
Jouni Malinen57887a22017-10-10 20:43:25 +03005491 return "BIP-GMAC-256";
Jouni Malinen3d633da2017-09-14 22:19:21 +03005492 case AP_BIP_CMAC_256:
5493 return "BIP-CMAC-256";
5494 case AP_BIP_GMAC_128:
5495 return "BIP-GMAC-128";
5496 case AP_BIP_CMAC_128:
5497 return "AES-128-CMAC";
5498 default:
5499 return "UNKNOWN";
5500 }
5501}
5502
5503
Jouni Malinena326d7b2017-09-04 13:46:02 +03005504int cmd_ap_config_commit(struct sigma_dut *dut, struct sigma_conn *conn,
5505 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005506{
5507 /* const char *name = get_param(cmd, "NAME"); */
5508 FILE *f;
5509 const char *ifname;
5510 char buf[500];
5511 char path[100];
5512 enum driver_type drv;
Jouni Malinen30824df2017-08-22 21:21:38 +03005513 const char *key_mgmt;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005514
5515 drv = get_driver_type();
5516
5517 if (dut->mode == SIGMA_MODE_STATION) {
5518 stop_sta_mode(dut);
5519 sleep(1);
5520 }
5521
5522 if (dut->mode == SIGMA_MODE_SNIFFER && dut->sniffer_ifname) {
5523 snprintf(buf, sizeof(buf), "ifconfig %s down",
5524 dut->sniffer_ifname);
5525 if (system(buf) != 0) {
5526 sigma_dut_print(dut, DUT_MSG_INFO,
5527 "Failed to run '%s'", buf);
5528 }
5529 snprintf(buf, sizeof(buf), "iw dev %s set type station",
5530 dut->sniffer_ifname);
5531 if (system(buf) != 0) {
5532 sigma_dut_print(dut, DUT_MSG_INFO,
5533 "Failed to run '%s'", buf);
5534 }
5535 }
5536
5537 dut->mode = SIGMA_MODE_AP;
5538
5539 if (drv == DRIVER_ATHEROS)
5540 return cmd_ath_ap_config_commit(dut, conn, cmd);
5541 if (drv == DRIVER_WCN)
5542 return cmd_wcn_ap_config_commit(dut, conn, cmd);
5543 if (drv == DRIVER_OPENWRT)
5544 return cmd_owrt_ap_config_commit(dut, conn, cmd);
5545
5546 f = fopen(SIGMA_TMPDIR "/sigma_dut-ap.conf", "w");
5547 if (f == NULL) {
5548 sigma_dut_print(dut, DUT_MSG_ERROR,
5549 "%s: Failed to open sigma_dut-ap.conf",
5550 __func__);
5551 return -2;
5552 }
5553 switch (dut->ap_mode) {
5554 case AP_11g:
5555 case AP_11b:
5556 case AP_11ng:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05305557 ifname = (drv == DRIVER_MAC80211) ? "wlan0" : "ath0";
5558 if ((drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) &&
5559 sigma_main_ifname)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005560 ifname = sigma_main_ifname;
5561 fprintf(f, "hw_mode=g\n");
5562 break;
5563 case AP_11a:
5564 case AP_11na:
5565 case AP_11ac:
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05305566 if (drv == DRIVER_QNXNTO || drv == DRIVER_LINUX_WCN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005567 if (sigma_main_ifname)
5568 ifname = sigma_main_ifname;
5569 else
5570 ifname = "wlan0";
Pradeep Reddy Potteti08eaeba2017-06-14 12:43:19 +05305571 } else if (drv == DRIVER_MAC80211) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005572 if (if_nametoindex("wlan1") > 0)
5573 ifname = "wlan1";
5574 else
5575 ifname = "wlan0";
5576 } else {
5577 ifname = get_main_ifname();
5578 }
5579 fprintf(f, "hw_mode=a\n");
5580 break;
5581 default:
5582 fclose(f);
5583 return -1;
5584 }
Jouni Malinend6bf1b42017-06-23 17:51:01 +03005585 if (dut->hostapd_ifname)
5586 ifname = dut->hostapd_ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005587
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305588 if (drv == DRIVER_MAC80211 || drv == DRIVER_LINUX_WCN)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589 fprintf(f, "driver=nl80211\n");
5590
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305591 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5592 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005593 (dut->ap_mode == AP_11ng || dut->ap_mode == AP_11na)) {
Tamizh chelvam431c6002017-03-07 17:07:16 +05305594 int ht40plus = 0, ht40minus = 0, tx_stbc = 0;
5595
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005596 fprintf(f, "ieee80211n=1\n");
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05305597 if (dut->ap_mode == AP_11ng &&
5598 (dut->ap_chwidth == AP_40 ||
5599 (dut->ap_chwidth == AP_AUTO &&
5600 dut->default_11ng_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005601 if (dut->ap_channel >= 1 && dut->ap_channel <= 7)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305602 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005603 else if (dut->ap_channel >= 8 && dut->ap_channel <= 11)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305604 ht40minus = 1;
5605 fprintf(f, "obss_interval=300\n");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005606 }
5607
5608 /* configure ht_capab based on channel width */
5609 if (dut->ap_mode == AP_11na &&
5610 (dut->ap_chwidth == AP_40 ||
5611 (dut->ap_chwidth == AP_AUTO &&
Pradeep Reddy Pottetibf8af292017-02-15 15:28:39 +05305612 dut->default_11na_ap_chwidth == AP_40))) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005613 if (is_ht40plus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05305614 ht40plus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005615 else if (is_ht40minus_chan(dut->ap_channel))
Tamizh chelvam431c6002017-03-07 17:07:16 +05305616 ht40minus = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005617 }
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05305618
5619 if (dut->ap_tx_stbc)
Tamizh chelvam431c6002017-03-07 17:07:16 +05305620 tx_stbc = 1;
Mohammed Shafi Shajakhan31d8a152016-06-02 20:10:55 +05305621
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05305622 /* Overwrite the ht_capab with offset value if configured */
5623 if (dut->ap_chwidth == AP_40 &&
5624 dut->ap_chwidth_offset == SEC_CH_40ABOVE) {
5625 ht40plus = 1;
5626 ht40minus = 0;
5627 } else if (dut->ap_chwidth == AP_40 &&
5628 dut->ap_chwidth_offset == SEC_CH_40BELOW) {
5629 ht40minus = 1;
5630 ht40plus = 0;
5631 }
5632
Tamizh chelvam431c6002017-03-07 17:07:16 +05305633 fprintf(f, "ht_capab=%s%s%s\n",
5634 ht40plus ? "[HT40+]" : "",
5635 ht40minus ? "[HT40-]" : "",
5636 tx_stbc ? "[TX-STBC]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005637 }
5638
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305639 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5640 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005641 dut->ap_mode == AP_11ac) {
5642 fprintf(f, "ieee80211ac=1\n"
5643 "ieee80211n=1\n"
5644 "ht_capab=[HT40+]\n");
5645 }
5646
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05305647 if ((drv == DRIVER_MAC80211 || drv == DRIVER_QNXNTO ||
5648 drv == DRIVER_LINUX_WCN) &&
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005649 (dut->ap_mode == AP_11ac || dut->ap_mode == AP_11na)) {
5650 if (dut->ap_countrycode[0]) {
5651 fprintf(f, "country_code=%s\n", dut->ap_countrycode);
5652 fprintf(f, "ieee80211d=1\n");
5653 fprintf(f, "ieee80211h=1\n");
5654 }
5655 }
5656
5657 fprintf(f, "interface=%s\n", ifname);
5658 if (dut->bridge)
5659 fprintf(f, "bridge=%s\n", dut->bridge);
5660 fprintf(f, "channel=%d\n", dut->ap_channel);
5661
5662 if (sigma_hapd_ctrl)
5663 fprintf(f, "ctrl_interface=%s\n", sigma_hapd_ctrl);
5664 else
5665 fprintf(f, "ctrl_interface=/var/run/hostapd\n");
5666
5667 if (dut->ap_ssid[0])
5668 fprintf(f, "ssid=%s\n", dut->ap_ssid);
5669 else
5670 fprintf(f, "ssid=QCA AP OOB\n");
5671 if (dut->ap_bcnint)
5672 fprintf(f, "beacon_int=%d\n", dut->ap_bcnint);
5673
5674 switch (dut->ap_key_mgmt) {
5675 case AP_OPEN:
5676 if (dut->ap_cipher == AP_WEP)
5677 fprintf(f, "wep_key0=%s\n", dut->ap_wepkey);
5678 break;
5679 case AP_WPA2_PSK:
5680 case AP_WPA2_PSK_MIXED:
5681 case AP_WPA_PSK:
Jouni Malinen30824df2017-08-22 21:21:38 +03005682 case AP_WPA2_SAE:
5683 case AP_WPA2_PSK_SAE:
5684 if (dut->ap_key_mgmt == AP_WPA2_PSK ||
5685 dut->ap_key_mgmt == AP_WPA2_SAE ||
5686 dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005687 fprintf(f, "wpa=2\n");
5688 else if (dut->ap_key_mgmt == AP_WPA2_PSK_MIXED)
5689 fprintf(f, "wpa=3\n");
5690 else
5691 fprintf(f, "wpa=1\n");
Jouni Malinen30824df2017-08-22 21:21:38 +03005692 if (dut->ap_key_mgmt == AP_WPA2_SAE)
5693 key_mgmt = "SAE";
5694 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
5695 key_mgmt = "WPA-PSK SAE";
5696 else
5697 key_mgmt = "WPA-PSK";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005698 switch (dut->ap_pmf) {
5699 case AP_PMF_DISABLED:
Jouni Malinen30824df2017-08-22 21:21:38 +03005700 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005701 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
5702 break;
5703 case AP_PMF_OPTIONAL:
Jouni Malinen30824df2017-08-22 21:21:38 +03005704 fprintf(f, "wpa_key_mgmt=%s%s\n", key_mgmt,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005705 dut->ap_add_sha256 ? " WPA-PSK-SHA256" : "");
5706 break;
5707 case AP_PMF_REQUIRED:
Jouni Malinen30824df2017-08-22 21:21:38 +03005708 if (dut->ap_key_mgmt == AP_WPA2_SAE)
5709 key_mgmt = "SAE";
5710 else if (dut->ap_key_mgmt == AP_WPA2_PSK_SAE)
5711 key_mgmt = "WPA-PSK-SHA256 SAE";
5712 else
5713 key_mgmt = "WPA-PSK-SHA256";
5714 fprintf(f, "wpa_key_mgmt=%s\n", key_mgmt);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005715 break;
5716 }
Jouni Malinen2ba24492017-11-17 12:43:59 +02005717 fprintf(f, "wpa_pairwise=%s\n",
5718 hostapd_cipher_name(dut->ap_cipher));
5719 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
5720 fprintf(f, "group_cipher=%s\n",
5721 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen2126f422017-10-11 23:24:33 +03005722 if (dut->ap_key_mgmt == AP_WPA2_SAE)
5723 fprintf(f, "sae_password=%s\n", dut->ap_passphrase);
Jouni Malinen63370622017-11-18 17:47:13 +02005724 else if (!dut->ap_passphrase[0] && dut->ap_psk[0])
5725 fprintf(f, "wpa_psk=%s", dut->ap_psk);
Jouni Malinen2126f422017-10-11 23:24:33 +03005726 else
5727 fprintf(f, "wpa_passphrase=%s\n", dut->ap_passphrase);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 break;
5729 case AP_WPA2_EAP:
5730 case AP_WPA2_EAP_MIXED:
5731 case AP_WPA_EAP:
5732 fprintf(f, "ieee8021x=1\n");
5733 if (dut->ap_key_mgmt == AP_WPA2_EAP)
5734 fprintf(f, "wpa=2\n");
5735 else if (dut->ap_key_mgmt == AP_WPA2_EAP_MIXED)
5736 fprintf(f, "wpa=3\n");
5737 else
5738 fprintf(f, "wpa=1\n");
5739 switch (dut->ap_pmf) {
5740 case AP_PMF_DISABLED:
5741 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
5742 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
5743 break;
5744 case AP_PMF_OPTIONAL:
5745 fprintf(f, "wpa_key_mgmt=WPA-EAP%s\n",
5746 dut->ap_add_sha256 ? " WPA-EAP-SHA256" : "");
5747 break;
5748 case AP_PMF_REQUIRED:
5749 fprintf(f, "wpa_key_mgmt=WPA-EAP-SHA256\n");
5750 break;
5751 }
Jouni Malinen2ba24492017-11-17 12:43:59 +02005752 fprintf(f, "wpa_pairwise=%s\n",
5753 hostapd_cipher_name(dut->ap_cipher));
5754 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
5755 fprintf(f, "group_cipher=%s\n",
5756 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005757 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
5758 if (dut->ap_radius_port)
5759 fprintf(f, "auth_server_port=%d\n",
5760 dut->ap_radius_port);
5761 fprintf(f, "auth_server_shared_secret=%s\n",
5762 dut->ap_radius_password);
5763 break;
Jouni Malinenad395a22017-09-01 21:13:46 +03005764 case AP_SUITEB:
5765 fprintf(f, "ieee8021x=1\n");
5766 fprintf(f, "wpa=2\n");
5767 fprintf(f, "wpa_key_mgmt=WPA-EAP-SUITE-B-192\n");
Jouni Malinen3d633da2017-09-14 22:19:21 +03005768 fprintf(f, "wpa_pairwise=%s\n",
5769 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen2ba24492017-11-17 12:43:59 +02005770 if (dut->ap_group_cipher != AP_NO_GROUP_CIPHER_SET)
5771 fprintf(f, "group_cipher=%s\n",
5772 hostapd_cipher_name(dut->ap_group_cipher));
Jouni Malinen3d633da2017-09-14 22:19:21 +03005773 if (dut->ap_group_mgmt_cipher != AP_NO_GROUP_MGMT_CIPHER_SET)
5774 fprintf(f, "group_mgmt_cipher=%s\n",
5775 hostapd_group_mgmt_cipher_name(
5776 dut->ap_group_mgmt_cipher));
Jouni Malinenad395a22017-09-01 21:13:46 +03005777 fprintf(f, "auth_server_addr=%s\n", dut->ap_radius_ipaddr);
5778 if (dut->ap_radius_port)
5779 fprintf(f, "auth_server_port=%d\n",
5780 dut->ap_radius_port);
5781 fprintf(f, "auth_server_shared_secret=%s\n",
5782 dut->ap_radius_password);
5783 break;
Jouni Malinen147b3c32017-10-09 16:51:54 +03005784 case AP_WPA2_OWE:
5785 fprintf(f, "wpa=2\n");
5786 fprintf(f, "wpa_key_mgmt=OWE\n");
5787 fprintf(f, "rsn_pairwise=%s\n",
5788 hostapd_cipher_name(dut->ap_cipher));
Jouni Malinen72461d42017-10-10 19:20:45 +03005789 if (dut->ap_sae_groups)
5790 fprintf(f, "owe_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen147b3c32017-10-09 16:51:54 +03005791 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005792 }
5793
Anilkumar Kollif0fd5992017-02-23 12:54:01 +05305794 if (dut->ap_rsn_preauth)
5795 fprintf(f, "rsn_preauth=1\n");
5796
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005797 switch (dut->ap_pmf) {
5798 case AP_PMF_DISABLED:
5799 break;
5800 case AP_PMF_OPTIONAL:
5801 fprintf(f, "ieee80211w=1\n");
5802 break;
5803 case AP_PMF_REQUIRED:
5804 fprintf(f, "ieee80211w=2\n");
5805 break;
5806 }
5807
Jouni Malinen3c367e82017-06-23 17:01:47 +03005808 if (dut->rsne_override)
5809 fprintf(f, "own_ie_override=%s\n", dut->rsne_override);
5810
Jouni Malinen68143132017-09-02 02:34:08 +03005811 if (dut->sae_commit_override)
5812 fprintf(f, "sae_commit_override=%s\n",
5813 dut->sae_commit_override);
5814
Jouni Malinened670f42017-08-31 01:39:28 +03005815 if (dut->ap_sae_groups)
5816 fprintf(f, "sae_groups=%s\n", dut->ap_sae_groups);
Jouni Malinen30824df2017-08-22 21:21:38 +03005817
Jouni Malinen2f524ce2017-08-31 01:43:29 +03005818 if (dut->sae_anti_clogging_threshold >= 0)
5819 fprintf(f, "sae_anti_clogging_threshold=%d\n",
5820 dut->sae_anti_clogging_threshold);
Jouni Malinenb347db02017-09-02 01:36:03 +03005821 if (dut->sae_reflection)
5822 fprintf(f, "sae_reflection_attack=1\n");
Jouni Malinen2f524ce2017-08-31 01:43:29 +03005823
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005824 if (dut->ap_p2p_mgmt)
5825 fprintf(f, "manage_p2p=1\n");
5826
5827 if (dut->ap_tdls_prohibit || dut->ap_l2tif)
5828 fprintf(f, "tdls_prohibit=1\n");
5829 if (dut->ap_tdls_prohibit_chswitch || dut->ap_l2tif)
5830 fprintf(f, "tdls_prohibit_chan_switch=1\n");
5831 if (dut->ap_p2p_cross_connect >= 0) {
5832 fprintf(f, "manage_p2p=1\n"
5833 "allow_cross_connection=%d\n",
5834 dut->ap_p2p_cross_connect);
5835 }
5836
5837 if (dut->ap_l2tif || dut->ap_proxy_arp) {
5838 if (!dut->bridge) {
5839 sigma_dut_print(dut, DUT_MSG_ERROR,
5840 "Bridge must be configured. Run with -b <brname>.");
5841 fclose(f);
5842 return -2;
5843 }
5844 fprintf(f, "ap_isolate=1\n");
5845 }
5846
5847 if (dut->ap_proxy_arp)
5848 fprintf(f, "proxy_arp=1\n");
5849
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05305850 if (dut->ap_wme)
5851 fprintf(f, "wmm_enabled=1\n");
5852
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05305853 if (dut->ap_wmmps == AP_WMMPS_ON)
5854 fprintf(f, "uapsd_advertisement_enabled=1\n");
5855
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005856 if (dut->ap_hs2) {
5857 if (dut->ap_bss_load) {
5858 char *bss_load;
5859
5860 switch (dut->ap_bss_load) {
5861 case -1:
5862 bss_load = "bss_load_update_period=10";
5863 break;
5864 case 1:
5865 /* STA count: 1, CU: 50, AAC: 65535 */
5866 bss_load = "bss_load_test=1:50:65535";
5867 break;
5868 case 2:
5869 /* STA count: 1, CU: 200, AAC: 65535 */
5870 bss_load = "bss_load_test=1:200:65535";
5871 break;
5872 case 3:
5873 /* STA count: 1, CU: 75, AAC: 65535 */
5874 bss_load = "bss_load_test=1:75:65535";
5875 break;
5876 default:
5877 bss_load = NULL;
5878 break;
5879 }
5880
5881 if (!bss_load) {
5882 fclose(f);
5883 return -2;
5884 }
5885 fprintf(f, "%s\n", bss_load);
5886 }
5887
5888 if (append_hostapd_conf_hs2(dut, f)) {
5889 fclose(f);
5890 return -2;
5891 }
5892 }
5893
5894 if (dut->ap_interworking && append_hostapd_conf_interworking(dut, f)) {
5895 fclose(f);
5896 return -2;
5897 }
5898
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005899 if (dut->ap_hs2 && strlen(dut->ap_tag_ssid[0])) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005900 unsigned char bssid[6];
5901 char ifname2[50];
5902
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305903 if (get_hwaddr(ifname, bssid)) {
5904 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005905 return -2;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305906 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005907 bssid[0] |= 0x02;
5908
5909 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
5910 fprintf(f, "bss=%s_1\n", ifname2);
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005911 fprintf(f, "ssid=%s\n", dut->ap_tag_ssid[0]);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005912 if (dut->bridge)
5913 fprintf(f, "bridge=%s\n", dut->bridge);
5914 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
5915 bssid[0], bssid[1], bssid[2], bssid[3],
5916 bssid[4], bssid[5]);
5917
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07005918 if (dut->ap_tag_key_mgmt[0] == AP2_OSEN) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005919 fprintf(f, "osen=1\n");
5920 if (strlen(dut->ap2_radius_ipaddr))
5921 fprintf(f, "auth_server_addr=%s\n",
5922 dut->ap2_radius_ipaddr);
5923 if (dut->ap2_radius_port)
5924 fprintf(f, "auth_server_port=%d\n",
5925 dut->ap2_radius_port);
5926 if (strlen(dut->ap2_radius_password))
5927 fprintf(f, "auth_server_shared_secret=%s\n",
5928 dut->ap2_radius_password);
5929 }
5930
5931 if (dut->ap2_proxy_arp) {
5932 if (!dut->bridge) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR,
5934 "Bridge must be configured. Run with -b <brname>.");
5935 fclose(f);
5936 return -2;
5937 }
5938 fprintf(f, "ap_isolate=1\n");
5939 fprintf(f, "proxy_arp=1\n");
5940
5941 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname2) ||
5942 set_ebtables_proxy_arp(dut, "OUTPUT", ifname2)) {
5943 fclose(f);
5944 return -2;
5945 }
5946
5947 }
5948 }
5949
5950 if (dut->program == PROGRAM_WPS) {
5951 fprintf(f, "eap_server=1\n"
5952 "wps_state=1\n"
5953 "device_name=QCA AP\n"
5954 "manufacturer=QCA\n"
5955 "device_type=6-0050F204-1\n"
5956 "config_methods=label virtual_display "
5957 "virtual_push_button keypad%s\n"
5958 "ap_pin=12345670\n"
5959 "friendly_name=QCA Access Point\n"
5960 "upnp_iface=%s\n",
5961 dut->ap_wpsnfc ? " nfc_interface ext_nfc_token" : "",
5962 dut->bridge ? dut->bridge : ifname);
5963 }
5964
5965 if (dut->program == PROGRAM_VHT) {
5966 int vht_oper_centr_freq_idx;
5967
5968 if (check_channel(dut->ap_channel) < 0) {
5969 send_resp(dut, conn, SIGMA_INVALID,
5970 "errorCode,Invalid channel");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305971 fclose(f);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005972 return 0;
5973 }
5974
5975 switch (dut->ap_chwidth) {
5976 case AP_20:
5977 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
5978 vht_oper_centr_freq_idx =
5979 get_oper_centr_freq_seq_idx(20,
5980 dut->ap_channel);
5981 break;
5982 case AP_40:
5983 dut->ap_vht_chwidth = AP_20_40_VHT_OPER_CHWIDTH;
5984 vht_oper_centr_freq_idx =
5985 get_oper_centr_freq_seq_idx(40,
5986 dut->ap_channel);
5987 break;
5988 case AP_80:
5989 dut->ap_vht_chwidth = AP_80_VHT_OPER_CHWIDTH;
5990 vht_oper_centr_freq_idx =
5991 get_oper_centr_freq_seq_idx(80,
5992 dut->ap_channel);
5993 break;
5994 case AP_160:
5995 dut->ap_vht_chwidth = AP_160_VHT_OPER_CHWIDTH;
5996 vht_oper_centr_freq_idx =
5997 get_oper_centr_freq_seq_idx(160,
5998 dut->ap_channel);
5999 break;
6000 default:
6001 dut->ap_vht_chwidth = VHT_DEFAULT_OPER_CHWIDTH;
6002 vht_oper_centr_freq_idx =
6003 get_oper_centr_freq_seq_idx(80,
6004 dut->ap_channel);
6005 break;
6006 }
6007 fprintf(f, "vht_oper_centr_freq_seg0_idx=%d\n",
6008 vht_oper_centr_freq_idx);
6009 fprintf(f, "vht_oper_chwidth=%d\n", dut->ap_vht_chwidth);
6010
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006011 if (dut->ap_sgi80 || dut->ap_txBF ||
6012 dut->ap_ldpc != VALUE_NOT_SET ||
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05306013 dut->ap_tx_stbc || dut->ap_mu_txBF) {
6014 fprintf(f, "vht_capab=%s%s%s%s%s\n",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006015 dut->ap_sgi80 ? "[SHORT-GI-80]" : "",
Mohammed Shafi Shajakhanc039ce32016-06-02 20:10:58 +05306016 dut->ap_txBF ?
Tamizh chelvam8312f6d2016-06-02 20:10:59 +05306017 "[SU-BEAMFORMER][SU-BEAMFORMEE][BF-ANTENNA-2][SOUNDING-DIMENSION-2]" : "",
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006018 (dut->ap_ldpc == VALUE_ENABLED) ?
6019 "[RXLDPC]" : "",
Mohammed Shafi Shajakhanf3e68d92016-06-02 20:10:57 +05306020 dut->ap_tx_stbc ? "[TX-STBC-2BY1]" : "",
6021 dut->ap_mu_txBF ? "[MU-BEAMFORMER]" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006022 }
6023 }
6024
Jouni Malinen6d1d7392017-10-10 20:35:29 +03006025 if (dut->ap_key_mgmt == AP_WPA2_OWE && dut->ap_tag_ssid[0][0] &&
6026 dut->ap_tag_key_mgmt[0] == AP2_OPEN) {
6027 /* OWE transition mode */
6028 unsigned char bssid[6];
6029 char ifname2[50];
6030 unsigned long val;
6031 FILE *f2;
6032
6033 snprintf(ifname2, sizeof(ifname2), "%s_1", ifname);
6034
6035 fprintf(f, "owe_transition_ifname=%s\n", ifname2);
6036 val = 0x12345678; /* default to something */
6037 f2 = fopen("/dev/urandom", "r");
6038 if (f2) {
6039 if (fread(&val, 1, sizeof(val), f2) != sizeof(val)) {
6040 sigma_dut_print(dut, DUT_MSG_ERROR,
6041 "Could not read /dev/urandom");
6042 }
6043 fclose(f2);
6044 }
6045 fprintf(f, "ssid=owe-%lx\n", val);
6046
6047 if (get_hwaddr(ifname, bssid)) {
6048 fclose(f);
6049 return -2;
6050 }
6051 if (bssid[0] & 0x02)
6052 bssid[5] ^= 0x01;
6053 else
6054 bssid[0] |= 0x02;
6055
6056 fprintf(f, "bss=%s\n", ifname2);
6057 fprintf(f, "ssid=%s\n", dut->ap_ssid);
6058 if (dut->bridge)
6059 fprintf(f, "bridge=%s\n", dut->bridge);
6060 fprintf(f, "bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
6061 bssid[0], bssid[1], bssid[2], bssid[3],
6062 bssid[4], bssid[5]);
6063 fprintf(f, "owe_transition_ifname=%s\n", ifname);
6064 }
6065
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306066 if (dut->program == PROGRAM_OCE) {
6067 fprintf(f, "oce=%d\n",
6068 dut->dev_role == DEVROLE_STA_CFON ? 2 : 1);
6069 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006070 fclose(f);
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006071 if (dut->use_hostapd_pid_file)
6072 kill_hostapd_process_pid(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073#ifdef __QNXNTO__
6074 if (system("slay hostapd") == 0)
6075#else /* __QNXNTO__ */
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006076 if (!dut->use_hostapd_pid_file &&
6077 (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
6078 system("killall hostapd") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079#endif /* __QNXNTO__ */
6080 {
6081 int i;
6082 /* Wait some time to allow hostapd to complete cleanup before
6083 * starting a new process */
6084 for (i = 0; i < 10; i++) {
6085 usleep(500000);
6086#ifdef __QNXNTO__
6087 if (system("pidin | grep hostapd") != 0)
6088 break;
6089#else /* __QNXNTO__ */
6090 if (system("pidof hostapd") != 0)
6091 break;
6092#endif /* __QNXNTO__ */
6093 }
6094 }
Jouni Malinend86e5822017-08-29 03:55:32 +03006095 dut->hostapd_running = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006096
Pradeep Reddy POTTETIa076c302016-05-16 13:36:07 +05306097#ifdef ANDROID
6098 /* Set proper conf file permissions so that hostapd process
6099 * can access it.
6100 */
6101 if (chmod(SIGMA_TMPDIR "/sigma_dut-ap.conf",
6102 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) < 0)
6103 sigma_dut_print(dut, DUT_MSG_ERROR,
6104 "Error changing permissions");
6105
6106 if (chown(SIGMA_TMPDIR "/sigma_dut-ap.conf", -1, AID_WIFI) < 0)
6107 sigma_dut_print(dut, DUT_MSG_ERROR, "Error changing groupid");
6108#endif /* ANDROID */
6109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006110 if (drv == DRIVER_QNXNTO) {
6111 snprintf(buf, sizeof(buf),
Pradeep Reddy POTTETIbf4a9742016-02-04 12:32:30 +05306112 "hostapd -B %s%s %s%s" SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006113 "/sigma_dut-ap.conf",
6114 dut->hostapd_debug_log ? "-ddKt -f " : "",
6115 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006116 dut->hostapd_entropy_log ? " -e" : "",
6117 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
6118 "");
6119 } else {
6120 /*
6121 * It looks like a monitor interface can cause some issues for
6122 * beaconing, so remove it (if injection was used) before
6123 * starting hostapd.
6124 */
6125 if (if_nametoindex("sigmadut") > 0 &&
6126 system("iw dev sigmadut del") != 0)
6127 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
6128 "monitor interface");
6129
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006130 snprintf(path, sizeof(path), "%shostapd",
6131 file_exists("hostapd") ? "./" : "");
6132 snprintf(buf, sizeof(buf), "%s -B%s%s%s%s%s " SIGMA_TMPDIR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006133 "/sigma_dut-ap.conf",
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006134 dut->hostapd_bin ? dut->hostapd_bin : path,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006135 dut->hostapd_debug_log ? " -ddKt -f" : "",
6136 dut->hostapd_debug_log ? dut->hostapd_debug_log : "",
6137 dut->hostapd_entropy_log ? " -e" : "",
6138 dut->hostapd_entropy_log ? dut->hostapd_entropy_log :
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006139 "",
6140 dut->use_hostapd_pid_file ?
6141 " -P " SIGMA_DUT_HOSTAPD_PID_FILE : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006142 }
6143
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006144 sigma_dut_print(dut, DUT_MSG_DEBUG, "hostapd command: %s", buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006145 if (system(buf) != 0) {
6146 send_resp(dut, conn, SIGMA_ERROR,
6147 "errorCode,Failed to start hostapd");
6148 return 0;
6149 }
6150
6151 /* allow some time for hostapd to start before returning success */
6152 usleep(500000);
6153 if (run_hostapd_cli(dut, "ping") != 0) {
6154 send_resp(dut, conn, SIGMA_ERROR,
6155 "errorCode,Failed to talk to hostapd");
6156 return 0;
6157 }
6158
Pradeep Reddy Potteti923a9b32017-06-14 12:18:59 +05306159 if (drv == DRIVER_LINUX_WCN) {
6160 sigma_dut_print(dut, DUT_MSG_INFO, "setting ip addr %s mask %s",
6161 ap_inet_addr, ap_inet_mask);
6162 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s up",
6163 ifname, ap_inet_addr, ap_inet_mask);
6164 if (system(buf) != 0) {
6165 sigma_dut_print(dut, DUT_MSG_ERROR,
6166 "Failed to initialize the interface");
6167 return -1;
6168 }
6169 }
6170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006171 if (dut->ap_l2tif) {
6172 snprintf(path, sizeof(path),
6173 "/sys/class/net/%s/brport/hairpin_mode",
6174 ifname);
6175 if (!file_exists(path)) {
6176 sigma_dut_print(dut, DUT_MSG_ERROR,
6177 "%s must be binded to the bridge for L2TIF",
6178 ifname);
6179 return -2;
6180 }
6181
6182 snprintf(buf, sizeof(buf), "echo 1 > %s", path);
6183 if (system(buf) != 0) {
6184 sigma_dut_print(dut, DUT_MSG_ERROR,
6185 "Failed to enable hairpin_mode for L2TIF");
6186 return -2;
6187 }
6188
6189 snprintf(buf, sizeof(buf), "ebtables -P FORWARD ACCEPT");
6190 if (system(buf) != 0) {
6191 sigma_dut_print(dut, DUT_MSG_ERROR,
6192 "Failed to set ebtables rules, RULE-9");
6193 return -2;
6194 }
6195
6196 snprintf(buf, sizeof(buf),
6197 "ebtables -A FORWARD -p IPv4 --ip-proto icmp -i %s -j DROP",
6198 ifname);
6199 if (system(buf) != 0) {
6200 sigma_dut_print(dut, DUT_MSG_ERROR,
6201 "Failed to set ebtables rules, RULE-11");
6202 return -2;
6203 }
6204 }
6205
6206 if (dut->ap_proxy_arp) {
6207 if (dut->ap_dgaf_disable) {
6208 if (set_ebtables_disable_dgaf(dut, "FORWARD", ifname) ||
6209 set_ebtables_disable_dgaf(dut, "OUTPUT", ifname))
6210 return -2;
6211 } else {
6212 if (set_ebtables_proxy_arp(dut, "FORWARD", ifname) ||
6213 set_ebtables_proxy_arp(dut, "OUTPUT", ifname))
6214 return -2;
6215 }
6216
6217 /* For 4.5-(c) */
6218 snprintf(buf, sizeof(buf),
6219 "ebtables -A FORWARD -p ARP --arp-opcode 2 -i %s -j DROP",
6220 ifname);
6221 if (system(buf) != 0) {
6222 sigma_dut_print(dut, DUT_MSG_ERROR,
6223 "Failed to set ebtables rules, RULE-10");
6224 return -2;
6225 }
6226 }
6227
6228 if (dut->ap_tdls_prohibit || dut->ap_l2tif) {
6229 /* Drop TDLS frames */
6230 snprintf(buf, sizeof(buf),
6231 "ebtables -A FORWARD -p 0x890d -i %s -j DROP", ifname);
6232 if (system(buf) != 0) {
6233 sigma_dut_print(dut, DUT_MSG_ERROR,
6234 "Failed to set ebtables rules, RULE-13");
6235 return -2;
6236 }
6237 }
6238
6239 if (dut->ap_fake_pkhash &&
6240 run_hostapd_cli(dut, "set wps_corrupt_pkhash 1") != 0) {
6241 send_resp(dut, conn, SIGMA_ERROR,
6242 "errorCode,Could not enable FakePubKey");
6243 return 0;
6244 }
6245
Jouni Malinend86e5822017-08-29 03:55:32 +03006246 dut->hostapd_running = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006247 return 1;
6248}
6249
6250
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306251static int parse_qos_params(struct sigma_dut *dut, struct sigma_conn *conn,
6252 struct qos_params *qos, const char *cwmin,
6253 const char *cwmax, const char *aifs,
6254 const char *txop, const char *acm)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006255{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306256 int val;
6257
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006258 if (cwmin) {
6259 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306260 val = atoi(cwmin);
6261 if (val < 0 || val > 15) {
6262 send_resp(dut, conn, SIGMA_INVALID,
6263 "errorCode,Invalid cwMin");
6264 return 0;
6265 }
6266 qos->cwmin = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006267 }
6268
6269 if (cwmax) {
6270 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306271 val = atoi(cwmax);
6272 if (val < 0 || val > 15) {
6273 send_resp(dut, conn, SIGMA_INVALID,
6274 "errorCode,Invalid cwMax");
6275 return 0;
6276 }
6277 qos->cwmax = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 }
6279
6280 if (aifs) {
6281 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306282 val = atoi(aifs);
6283 if (val < 1 || val > 255) {
6284 send_resp(dut, conn, SIGMA_INVALID,
6285 "errorCode,Invalid AIFS");
6286 return 0;
6287 }
6288 qos->aifs = val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006289 }
6290
6291 if (txop) {
6292 qos->ac = 1;
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306293 val = atoi(txop);
6294 if (val < 0 || val > 0xffff) {
6295 send_resp(dut, conn, SIGMA_INVALID,
6296 "errorCode,Invalid txop");
6297 return 0;
6298 }
6299 qos->txop = val * 32;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006300 }
6301
6302 if (acm) {
6303 qos->ac = 1;
6304 qos->acm = strcasecmp(acm, "on") == 0;
6305 }
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306306
6307 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006308}
6309
6310
6311static int cmd_ap_set_apqos(struct sigma_dut *dut, struct sigma_conn *conn,
6312 struct sigma_cmd *cmd)
6313{
6314 /* TXOP: The values provided here for VHT5G only */
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306315 if (!parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VO],
6316 get_param(cmd, "cwmin_VO"),
6317 get_param(cmd, "cwmax_VO"),
6318 get_param(cmd, "AIFS_VO"),
6319 get_param(cmd, "TXOP_VO"),
6320 get_param(cmd, "ACM_VO")) ||
6321 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_VI],
6322 get_param(cmd, "cwmin_VI"),
6323 get_param(cmd, "cwmax_VI"),
6324 get_param(cmd, "AIFS_VI"),
6325 get_param(cmd, "TXOP_VI"),
6326 get_param(cmd, "ACM_VI")) ||
6327 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BE],
6328 get_param(cmd, "cwmin_BE"),
6329 get_param(cmd, "cwmax_BE"),
6330 get_param(cmd, "AIFS_BE"),
6331 get_param(cmd, "TXOP_BE"),
6332 get_param(cmd, "ACM_BE")) ||
6333 !parse_qos_params(dut, conn, &dut->ap_qos[AP_AC_BK],
6334 get_param(cmd, "cwmin_BK"),
6335 get_param(cmd, "cwmax_BK"),
6336 get_param(cmd, "AIFS_BK"),
6337 get_param(cmd, "TXOP_BK"),
6338 get_param(cmd, "ACM_BK")))
6339 return 0;
6340
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006341 return 1;
6342}
6343
6344
6345static int cmd_ap_set_staqos(struct sigma_dut *dut, struct sigma_conn *conn,
6346 struct sigma_cmd *cmd)
6347{
Pradeep Reddy POTTETIeff46112016-10-13 17:22:03 +05306348 if (!parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VO],
6349 get_param(cmd, "cwmin_VO"),
6350 get_param(cmd, "cwmax_VO"),
6351 get_param(cmd, "AIFS_VO"),
6352 get_param(cmd, "TXOP_VO"),
6353 get_param(cmd, "ACM_VO")) ||
6354 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_VI],
6355 get_param(cmd, "cwmin_VI"),
6356 get_param(cmd, "cwmax_VI"),
6357 get_param(cmd, "AIFS_VI"),
6358 get_param(cmd, "TXOP_VI"),
6359 get_param(cmd, "ACM_VI")) ||
6360 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BE],
6361 get_param(cmd, "cwmin_BE"),
6362 get_param(cmd, "cwmax_BE"),
6363 get_param(cmd, "AIFS_BE"),
6364 get_param(cmd, "TXOP_BE"),
6365 get_param(cmd, "ACM_BE")) ||
6366 !parse_qos_params(dut, conn, &dut->ap_sta_qos[AP_AC_BK],
6367 get_param(cmd, "cwmin_BK"),
6368 get_param(cmd, "cwmax_BK"),
6369 get_param(cmd, "AIFS_BK"),
6370 get_param(cmd, "TXOP_BK"),
6371 get_param(cmd, "ACM_BK")))
6372 return 0;
6373
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006374 return 1;
6375}
6376
6377
6378static void cmd_ath_ap_hs2_reset(struct sigma_dut *dut)
6379{
6380 unsigned char bssid[6];
6381 char buf[100];
6382 run_system(dut, "cfg -a AP_SSID=\"Hotspot 2.0\"");
6383 run_system(dut, "cfg -a AP_PRIMARY_CH=1");
6384 run_system(dut, "cfg -a AP_SECMODE=WPA");
6385 run_system(dut, "cfg -a AP_SECFILE=EAP");
6386 run_system(dut, "cfg -a AP_WPA=2");
6387 run_system(dut, "cfg -a AP_CYPHER=CCMP");
6388 run_system(dut, "cfg -a AP_HOTSPOT=1");
6389 run_system(dut, "cfg -a AP_HOTSPOT_ANT=2");
6390 run_system(dut, "cfg -a AP_HOTSPOT_INTERNET=0");
6391 run_system(dut, "cfg -a AP_HOTSPOT_VENUEGROUP=2");
6392 run_system(dut, "cfg -a AP_HOTSPOT_VENUETYPE=8");
6393 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM=506f9a");
6394 run_system(dut, "cfg -a AP_HOTSPOT_ROAMINGCONSORTIUM2=001bc504bd");
6395 if (!get_hwaddr("ath0", bssid)) {
6396 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
6397 "%02x:%02x:%02x:%02x:%02x:%02x",
6398 bssid[0], bssid[1], bssid[2], bssid[3],
6399 bssid[4], bssid[5]);
6400 run_system(dut, buf);
6401 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
6402 "%02x:%02x:%02x:%02x:%02x:%02x",
6403 bssid[0], bssid[1], bssid[2], bssid[3],
6404 bssid[4], bssid[5]);
6405 } else {
6406 if (!get_hwaddr("wifi0", bssid)) {
6407 snprintf(buf, sizeof(buf), "cfg -a AP_HOTSPOT_HESSID="
6408 "%02x:%02x:%02x:%02x:%02x:%02x",
6409 bssid[0], bssid[1], bssid[2], bssid[3],
6410 bssid[4], bssid[5]);
6411 run_system(dut, buf);
6412 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid),
6413 "%02x:%02x:%02x:%02x:%02x:%02x",
6414 bssid[0], bssid[1], bssid[2], bssid[3],
6415 bssid[4], bssid[5]);
6416 } else {
6417 /* load the driver and try again */
6418 run_system(dut, "/etc/rc.d/rc.wlan up");
6419
6420 if (!get_hwaddr("wifi0", bssid)) {
6421 snprintf(buf, sizeof(buf),
6422 "cfg -a AP_HOTSPOT_HESSID="
6423 "%02x:%02x:%02x:%02x:%02x:%02x",
6424 bssid[0], bssid[1], bssid[2],
6425 bssid[3], bssid[4], bssid[5]);
6426 run_system(dut, buf);
6427 snprintf(dut->ap_hessid,
6428 sizeof(dut->ap_hessid),
6429 "%02x:%02x:%02x:%02x:%02x:%02x",
6430 bssid[0], bssid[1], bssid[2],
6431 bssid[3], bssid[4], bssid[5]);
6432 }
6433 }
6434 }
6435
6436 run_system(dut, "cfg -r AP_SSID_2");
6437 run_system(dut, "cfg -c");
6438 /* run_system(dut, "cfg -s"); */
6439}
6440
6441
6442static void ath_reset_vht_defaults(struct sigma_dut *dut)
6443{
6444 run_system(dut, "cfg -x");
6445 run_system(dut, "cfg -a AP_RADIO_ID=1");
6446 run_system(dut, "cfg -a AP_PRIMARY_CH_2=36");
6447 run_system(dut, "cfg -a AP_STARTMODE=standard");
6448 run_system(dut, "cfg -a AP_CHMODE_2=11ACVHT80");
6449 run_system(dut, "cfg -a TX_CHAINMASK_2=7");
6450 run_system(dut, "cfg -a RX_CHAINMASK_2=7");
6451 run_system(dut, "cfg -a ATH_countrycode=0x348");
6452 /* NOTE: For Beeliner we have to turn off MU-MIMO */
6453 if (system("rm /tmp/secath*") != 0) {
6454 sigma_dut_print(dut, DUT_MSG_ERROR,
6455 "Failed to remove secath file");
6456 }
6457}
6458
6459
6460static int cmd_ap_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
6461 struct sigma_cmd *cmd)
6462{
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306463 const char *type, *program;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306464 enum driver_type drv;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006465 int i;
6466
6467 for (i = 0; i < MAX_WLAN_TAGS - 1; i++) {
6468 /*
6469 * Reset all tagged SSIDs to NULL-string and all key management
6470 * to open.
6471 */
6472 dut->ap_tag_ssid[i][0] = '\0';
6473 dut->ap_tag_key_mgmt[i] = AP2_OPEN;
6474 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006475
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306476 drv = get_driver_type();
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306477
6478 program = get_param(cmd, "program");
6479 if (!program)
6480 program = get_param(cmd, "prog");
6481 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006482 dut->device_type = AP_unknown;
6483 type = get_param(cmd, "type");
6484 if (type && strcasecmp(type, "Testbed") == 0)
6485 dut->device_type = AP_testbed;
6486 if (type && strcasecmp(type, "DUT") == 0)
6487 dut->device_type = AP_dut;
6488
6489 dut->ap_rts = 0;
6490 dut->ap_frgmnt = 0;
6491 dut->ap_bcnint = 0;
6492 dut->ap_key_mgmt = AP_OPEN;
6493 dut->ap_ssid[0] = '\0';
6494 dut->ap_fake_pkhash = 0;
6495 memset(dut->ap_qos, 0, sizeof(dut->ap_qos));
6496 memset(dut->ap_sta_qos, 0, sizeof(dut->ap_sta_qos));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006497 dut->ap_addba_reject = VALUE_NOT_SET;
6498 dut->ap_noack = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006499 dut->ap_is_dual = 0;
6500 dut->ap_mode = AP_inval;
6501 dut->ap_mode_1 = AP_inval;
6502
6503 dut->ap_allow_vht_wep = 0;
6504 dut->ap_allow_vht_tkip = 0;
6505 dut->ap_disable_protection = 0;
6506 memset(dut->ap_countrycode, 0, sizeof(dut->ap_countrycode));
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006507 dut->ap_dyn_bw_sig = VALUE_NOT_SET;
6508 dut->ap_ldpc = VALUE_NOT_SET;
6509 dut->ap_sig_rts = VALUE_NOT_SET;
6510 dut->ap_rx_amsdu = VALUE_NOT_SET;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006511 dut->ap_txBF = 0;
Mohammed Shafi Shajakhan495fdb22016-06-02 20:10:56 +05306512 dut->ap_mu_txBF = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006513 dut->ap_chwidth = AP_AUTO;
6514
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +05306515 dut->ap_rsn_preauth = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006516 dut->ap_wpsnfc = 0;
6517 dut->ap_bss_load = -1;
6518 dut->ap_p2p_cross_connect = -1;
6519
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05306520 dut->ap_regulatory_mode = AP_80211D_MODE_DISABLED;
6521 dut->ap_dfs_mode = AP_DFS_MODE_DISABLED;
Pradeep Reddy Potteti4b0cdee2017-03-15 12:37:33 +05306522 dut->ap_chwidth_offset = SEC_CH_NO;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05306523
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006524 dut->mbo_pref_ap_cnt = 0;
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07006525 dut->ft_bss_mac_cnt = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006526
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306527 if (dut->program == PROGRAM_HT || dut->program == PROGRAM_VHT) {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306528 dut->ap_wme = AP_WME_ON;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306529 dut->ap_wmmps = AP_WMMPS_ON;
6530 } else {
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306531 dut->ap_wme = AP_WME_OFF;
Mohammed Shafi Shajakhan02e3b822017-02-23 04:15:02 +05306532 dut->ap_wmmps = AP_WMMPS_OFF;
6533 }
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +05306534
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006535 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6536 dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006537 int i;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006539 if (drv == DRIVER_ATHEROS)
6540 cmd_ath_ap_hs2_reset(dut);
6541 else if (drv == DRIVER_OPENWRT)
6542 cmd_owrt_ap_hs2_reset(dut);
6543
6544 dut->ap_interworking = 1;
6545 dut->ap_access_net_type = 2;
6546 dut->ap_internet = 0;
6547 dut->ap_venue_group = 2;
6548 dut->ap_venue_type = 8;
6549 dut->ap_domain_name_list[0] = '\0';
6550 dut->ap_hs2 = 1;
6551 snprintf(dut->ap_roaming_cons, sizeof(dut->ap_roaming_cons),
6552 "506f9a;001bc504bd");
6553 dut->ap_l2tif = 0;
6554 dut->ap_proxy_arp = 0;
6555 if (dut->bridge) {
6556 char buf[50];
6557
6558 snprintf(buf, sizeof(buf), "ip neigh flush dev %s",
6559 dut->bridge);
6560 if (system(buf) != 0) {
6561 sigma_dut_print(dut, DUT_MSG_DEBUG,
6562 "%s ip neigh table flushing failed",
6563 dut->bridge);
6564 }
6565
6566 snprintf(buf, sizeof(buf), "ebtables -F");
6567 if (system(buf) != 0) {
6568 sigma_dut_print(dut, DUT_MSG_DEBUG,
6569 "%s ebtables flushing failed",
6570 dut->bridge);
6571 }
6572 }
6573 dut->ap_dgaf_disable = 0;
6574 dut->ap_p2p_cross_connect = 0;
6575 dut->ap_gas_cb_delay = 0;
6576 dut->ap_nai_realm_list = 0;
6577 dut->ap_oper_name = 0;
6578 dut->ap_venue_name = 0;
6579 for (i = 0; i < 10; i++) {
6580 dut->ap_plmn_mcc[i][0] = '\0';
6581 dut->ap_plmn_mnc[i][0] = '\0';
6582 }
6583 dut->ap_wan_metrics = 0;
6584 dut->ap_conn_capab = 0;
6585 dut->ap_ip_addr_type_avail = 0;
6586 dut->ap_net_auth_type = 0;
6587 dut->ap_oper_class = 0;
6588 dut->ap_pmf = 0;
6589 dut->ap_add_sha256 = 0;
6590 }
6591
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006592 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_IOTLP) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 int i;
6594 const char hessid[] = "50:6f:9a:00:11:22";
6595
6596 memcpy(dut->ap_hessid, hessid, strlen(hessid) + 1);
6597 dut->ap_osu_ssid[0] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 dut->ap_pmf = 1;
6599 dut->ap_osu_provider_list = 0;
6600 for (i = 0; i < 10; i++) {
6601 dut->ap_osu_server_uri[i][0] = '\0';
6602 dut->ap_osu_method[i] = 0xFF;
6603 }
6604 dut->ap_qos_map_set = 0;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07006605 dut->ap_tag_key_mgmt[0] = AP2_OPEN;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006606 dut->ap2_proxy_arp = 0;
6607 dut->ap_osu_icon_tag = 0;
6608 }
6609
6610 if (dut->program == PROGRAM_VHT) {
6611 /* Set up the defaults */
6612 dut->ap_mode = AP_11ac;
6613 dut->ap_channel = 36;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006614 dut->ap_ampdu = VALUE_NOT_SET;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -08006615 dut->ap_ndpa_frame = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 if (dut->device_type == AP_testbed) {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006617 dut->ap_amsdu = VALUE_DISABLED;
6618 dut->ap_ldpc = VALUE_DISABLED;
6619 dut->ap_rx_amsdu = VALUE_DISABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006620 dut->ap_sgi80 = 0;
6621 } else {
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006622 dut->ap_amsdu = VALUE_ENABLED;
Pradeep Reddy POTTETI83b80672016-09-02 13:01:44 +05306623 /*
6624 * As LDPC is optional, don't enable this by default
6625 * for LINUX-WCN driver. The ap_set_wireless command
6626 * can be used to enable LDPC, when needed.
6627 */
6628 if (drv != DRIVER_LINUX_WCN)
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006629 dut->ap_ldpc = VALUE_ENABLED;
6630 dut->ap_rx_amsdu = VALUE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006631 dut->ap_sgi80 = 1;
6632 }
6633 dut->ap_fixed_rate = 0;
6634 dut->ap_rx_streams = 3;
6635 dut->ap_tx_streams = 3;
6636 dut->ap_vhtmcs_map = 0;
6637 dut->ap_chwidth = AP_80;
6638 dut->ap_tx_stbc = 1;
Jouni Malinen57fa3d82016-11-30 12:51:43 +02006639 dut->ap_dyn_bw_sig = VALUE_ENABLED;
Mohammed Shafi Shajakhanbae72302016-03-02 11:56:23 +05306640 if (get_openwrt_driver_type() == OPENWRT_DRIVER_ATHEROS)
6641 dut->ap_dfs_mode = AP_DFS_MODE_ENABLED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642 if (get_driver_type() == DRIVER_ATHEROS)
6643 ath_reset_vht_defaults(dut);
6644 }
6645
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07006646 if (dut->program == PROGRAM_IOTLP) {
6647 dut->wnm_bss_max_feature = VALUE_DISABLED;
6648 dut->wnm_bss_max_idle_time = 0;
6649 dut->wnm_bss_max_protection = VALUE_NOT_SET;
6650 dut->ap_proxy_arp = 1;
6651 } else {
6652 /*
6653 * Do not touch the BSS-MAX Idle time feature
6654 * if the program is not IOTLP.
6655 */
6656 dut->wnm_bss_max_feature = VALUE_NOT_SET;
6657 dut->wnm_bss_max_idle_time = 0;
6658 dut->wnm_bss_max_protection = VALUE_NOT_SET;
6659 }
6660
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006661 if (dut->program == PROGRAM_LOC) {
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006662 dut->ap_rrm = 1;
6663 dut->ap_rtt = 1;
6664 dut->ap_lci = 0;
6665 dut->ap_val_lci[0] = '\0';
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07006666 dut->ap_infoz[0] = '\0';
priyadharshini gowthaman8e26ff42016-06-22 22:47:14 -07006667 dut->ap_lcr = 0;
6668 dut->ap_val_lcr[0] = '\0';
6669 dut->ap_neighap = 0;
6670 dut->ap_opchannel = 0;
6671 dut->ap_scan = 0;
priyadharshini gowthamanc2357bd2016-06-22 22:47:14 -07006672 dut->ap_fqdn_held = 0;
6673 dut->ap_fqdn_supl = 0;
priyadharshini gowthamanc52fff82016-06-22 22:47:14 -07006674 dut->ap_interworking = 0;
6675 dut->ap_gas_cb_delay = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006676 dut->ap_msnt_type = 0;
6677 }
Adil Saeed Musthafa4ec61bd2017-04-10 23:13:41 -07006678 dut->ap_ft_oa = 0;
Adil Saeed Musthafa604c8262017-04-10 23:13:31 -07006679 dut->ap_reg_domain = REG_DOMAIN_NOT_SET;
Adil Saeed Musthafacf752fa2017-04-10 23:13:32 -07006680 dut->ap_mobility_domain[0] = '\0';
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07006681
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006682 if (dut->program == PROGRAM_MBO) {
6683 dut->ap_mbo = 1;
6684 dut->ap_interworking = 1;
6685 dut->ap_ne_class = 0;
6686 dut->ap_ne_op_ch = 0;
6687 dut->ap_set_bssidpref = 1;
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07006688 dut->ap_btmreq_disassoc_imnt = 0;
6689 dut->ap_btmreq_term_bit = 0;
6690 dut->ap_disassoc_timer = 0;
6691 dut->ap_btmreq_bss_term_dur = 0;
Adil Saeed Musthafa16d9e632017-04-10 23:13:38 -07006692 dut->ap_channel = 36;
6693 dut->ap_chwidth = AP_20;
Adil Saeed Musthafa023108a2017-04-10 23:13:37 -07006694 dut->ap_cell_cap_pref = 0;
Adil Saeed Musthafaed5faae2017-04-10 23:13:36 -07006695 dut->ap_gas_cb_delay = 0;
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07006696 dut->mbo_self_ap_tuple.ap_ne_class = -1;
6697 dut->mbo_self_ap_tuple.ap_ne_pref = -1; /* Not set */
6698 dut->mbo_self_ap_tuple.ap_ne_op_ch = -1;
6699
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07006700 }
6701
Jouni Malinen3c367e82017-06-23 17:01:47 +03006702 free(dut->rsne_override);
6703 dut->rsne_override = NULL;
6704
Jouni Malinen68143132017-09-02 02:34:08 +03006705 free(dut->sae_commit_override);
6706 dut->sae_commit_override = NULL;
6707
Jouni Malinened670f42017-08-31 01:39:28 +03006708 free(dut->ap_sae_groups);
6709 dut->ap_sae_groups = NULL;
Jouni Malinen30824df2017-08-22 21:21:38 +03006710
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006711 dut->sae_anti_clogging_threshold = -1;
Jouni Malinenb347db02017-09-02 01:36:03 +03006712 dut->sae_reflection = 0;
Jouni Malinen2f524ce2017-08-31 01:43:29 +03006713
Jouni Malinen3d633da2017-09-14 22:19:21 +03006714 dut->ap_cipher = AP_CCMP;
Jouni Malinen2ba24492017-11-17 12:43:59 +02006715 dut->ap_group_cipher = AP_NO_GROUP_CIPHER_SET;
Jouni Malinen3d633da2017-09-14 22:19:21 +03006716 dut->ap_group_mgmt_cipher = AP_NO_GROUP_MGMT_CIPHER_SET;
Jouni Malinen63370622017-11-18 17:47:13 +02006717 dut->ap_passphrase[0] = '\0';
6718 dut->ap_psk[0] = '\0';
Jouni Malinen3d633da2017-09-14 22:19:21 +03006719
Jouni Malinend86e5822017-08-29 03:55:32 +03006720 dut->dpp_conf_id = -1;
6721
6722 dut->hostapd_running = 0;
Jouni Malinend6bf1b42017-06-23 17:51:01 +03006723 if (dut->use_hostapd_pid_file) {
6724 kill_hostapd_process_pid(dut);
6725 } else if (kill_process(dut, "(hostapd)", 1, SIGTERM) == 0 ||
6726 system("killall hostapd") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006727 int i;
6728 /* Wait some time to allow hostapd to complete cleanup before
6729 * starting a new process */
6730 for (i = 0; i < 10; i++) {
6731 usleep(500000);
6732 if (system("pidof hostapd") != 0)
6733 break;
6734 }
6735 }
6736
6737 if (if_nametoindex("sigmadut") > 0 &&
6738 system("iw dev sigmadut del") != 0)
6739 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to remove "
6740 "monitor interface");
6741
6742 return 1;
6743}
6744
6745
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306746int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
6747 struct sigma_cmd *cmd)
6748{
6749 return cmd_ap_reset_default(dut, conn, cmd);
6750}
6751
6752
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006753static int cmd_ap_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
6754 struct sigma_cmd *cmd)
6755{
6756 /* const char *name = get_param(cmd, "NAME"); */
6757 struct stat s;
6758 char resp[200];
6759 FILE *f;
6760 enum driver_type drv = get_driver_type();
6761
6762 switch (drv) {
6763 case DRIVER_ATHEROS: {
6764 /* Atheros AP */
6765 struct utsname uts;
6766 char *version, athver[100];
6767
6768 if (stat("/proc/athversion", &s) != 0) {
6769 if (system("/etc/rc.d/rc.wlan up") != 0) {
6770 }
6771 }
6772
6773 athver[0] = '\0';
6774 f = fopen("/proc/athversion", "r");
6775 if (f) {
6776 if (fgets(athver, sizeof(athver), f)) {
6777 char *pos = strchr(athver, '\n');
6778 if (pos)
6779 *pos = '\0';
6780 }
6781 fclose(f);
6782 }
6783
6784 if (uname(&uts) == 0)
6785 version = uts.release;
6786 else
6787 version = "Unknown";
6788
6789 if (if_nametoindex("ath1") > 0)
6790 snprintf(resp, sizeof(resp), "interface,ath0_24G "
6791 "ath1_5G,agent,1.0,version,%s/drv:%s",
6792 version, athver);
6793 else
6794 snprintf(resp, sizeof(resp), "interface,ath0_24G,"
6795 "agent,1.0,version,%s/drv:%s",
6796 version, athver);
6797
6798 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6799 return 0;
6800 }
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +05306801 case DRIVER_LINUX_WCN:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006802 case DRIVER_MAC80211: {
6803 struct utsname uts;
6804 char *version;
6805
6806 if (uname(&uts) == 0)
6807 version = uts.release;
6808 else
6809 version = "Unknown";
6810
6811 if (if_nametoindex("wlan1") > 0)
6812 snprintf(resp, sizeof(resp), "interface,wlan0_24G "
6813 "wlan1_5G,agent,1.0,version,%s", version);
6814 else
6815 snprintf(resp, sizeof(resp), "interface,wlan0_any,"
6816 "agent,1.0,version,%s", version);
6817
6818 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6819 return 0;
6820 }
6821 case DRIVER_QNXNTO: {
6822 struct utsname uts;
6823 char *version;
6824
6825 if (uname(&uts) == 0)
6826 version = uts.release;
6827 else
6828 version = "Unknown";
6829 snprintf(resp, sizeof(resp),
6830 "interface,%s_any,agent,1.0,version,%s",
6831 sigma_main_ifname ? sigma_main_ifname : "NA",
6832 version);
6833 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6834 return 0;
6835 }
6836 case DRIVER_OPENWRT: {
6837 switch (get_openwrt_driver_type()) {
6838 case OPENWRT_DRIVER_ATHEROS: {
6839 struct utsname uts;
6840 char *version;
6841
6842 if (uname(&uts) == 0)
6843 version = uts.release;
6844 else
6845 version = "Unknown";
6846
6847 if (if_nametoindex("ath1") > 0)
6848 snprintf(resp, sizeof(resp),
6849 "interface,ath0_5G ath1_24G,agent,1.0,version,%s",
6850 version);
6851 else
6852 snprintf(resp, sizeof(resp),
6853 "interface,ath0_any,agent,1.0,version,%s",
6854 version);
6855
6856 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6857 return 0;
6858 }
6859 default:
6860 send_resp(dut, conn, SIGMA_ERROR,
6861 "errorCode,Unsupported openwrt driver");
6862 return 0;
6863 }
6864 }
6865 default:
6866 send_resp(dut, conn, SIGMA_ERROR,
6867 "errorCode,Unsupported driver");
6868 return 0;
6869 }
6870}
6871
6872
6873static int cmd_ap_deauth_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6874 struct sigma_cmd *cmd)
6875{
6876 /* const char *name = get_param(cmd, "NAME"); */
6877 /* const char *ifname = get_param(cmd, "INTERFACE"); */
6878 const char *val;
6879 char buf[100];
6880
6881 val = get_param(cmd, "MinorCode");
6882 if (val) {
6883 /* TODO: add support for P2P minor code */
6884 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MinorCode not "
6885 "yet supported");
6886 return 0;
6887 }
6888
6889 val = get_param(cmd, "STA_MAC_ADDRESS");
6890 if (val == NULL)
6891 return -1;
6892 snprintf(buf, sizeof(buf), "deauth %s", val);
6893 if (run_hostapd_cli(dut, buf) != 0)
6894 return -2;
6895
6896 return 1;
6897}
6898
6899
6900#ifdef __linux__
6901int inject_frame(int s, const void *data, size_t len, int encrypt);
6902int open_monitor(const char *ifname);
6903int hwaddr_aton(const char *txt, unsigned char *addr);
6904#endif /* __linux__ */
6905
6906enum send_frame_type {
6907 DISASSOC, DEAUTH, SAQUERY
6908};
6909enum send_frame_protection {
6910 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
6911};
6912
6913
6914static int ap_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6915 enum send_frame_type frame,
6916 enum send_frame_protection protected,
6917 const char *sta_addr)
6918{
6919#ifdef __linux__
6920 unsigned char buf[1000], *pos;
6921 int s, res;
6922 unsigned char addr_sta[6], addr_own[6];
6923 char *ifname;
6924 char cbuf[100];
6925 struct ifreq ifr;
6926
6927 if ((dut->ap_mode == AP_11a || dut->ap_mode == AP_11na ||
6928 dut->ap_mode == AP_11ac) &&
6929 if_nametoindex("wlan1") > 0)
6930 ifname = "wlan1";
6931 else
6932 ifname = "wlan0";
6933
6934 if (hwaddr_aton(sta_addr, addr_sta) < 0)
6935 return -1;
6936
6937 s = socket(AF_INET, SOCK_DGRAM, 0);
6938 if (s < 0)
6939 return -1;
6940 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07006941 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006942 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
6943 perror("ioctl");
6944 close(s);
6945 return -1;
6946 }
6947 close(s);
6948 memcpy(addr_own, ifr.ifr_hwaddr.sa_data, 6);
6949
6950 if (if_nametoindex("sigmadut") == 0) {
6951 snprintf(cbuf, sizeof(cbuf),
6952 "iw dev %s interface add sigmadut type monitor",
6953 ifname);
6954 if (system(cbuf) != 0 ||
6955 if_nametoindex("sigmadut") == 0) {
6956 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6957 "monitor interface with '%s'", cbuf);
6958 return -2;
6959 }
6960 }
6961
6962 if (system("ifconfig sigmadut up") != 0) {
6963 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6964 "monitor interface up");
6965 return -2;
6966 }
6967
6968 pos = buf;
6969
6970 /* Frame Control */
6971 switch (frame) {
6972 case DISASSOC:
6973 *pos++ = 0xa0;
6974 break;
6975 case DEAUTH:
6976 *pos++ = 0xc0;
6977 break;
6978 case SAQUERY:
6979 *pos++ = 0xd0;
6980 break;
6981 }
6982
6983 if (protected == INCORRECT_KEY)
6984 *pos++ = 0x40; /* Set Protected field to 1 */
6985 else
6986 *pos++ = 0x00;
6987
6988 /* Duration */
6989 *pos++ = 0x00;
6990 *pos++ = 0x00;
6991
6992 /* addr1 = DA (station) */
6993 memcpy(pos, addr_sta, 6);
6994 pos += 6;
6995 /* addr2 = SA (own address) */
6996 memcpy(pos, addr_own, 6);
6997 pos += 6;
6998 /* addr3 = BSSID (own address) */
6999 memcpy(pos, addr_own, 6);
7000 pos += 6;
7001
7002 /* Seq# (to be filled by driver/mac80211) */
7003 *pos++ = 0x00;
7004 *pos++ = 0x00;
7005
7006 if (protected == INCORRECT_KEY) {
7007 /* CCMP parameters */
7008 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
7009 pos += 8;
7010 }
7011
7012 if (protected == INCORRECT_KEY) {
7013 switch (frame) {
7014 case DEAUTH:
7015 /* Reason code (encrypted) */
7016 memcpy(pos, "\xa7\x39", 2);
7017 pos += 2;
7018 break;
7019 case DISASSOC:
7020 /* Reason code (encrypted) */
7021 memcpy(pos, "\xa7\x39", 2);
7022 pos += 2;
7023 break;
7024 case SAQUERY:
7025 /* Category|Action|TransID (encrypted) */
7026 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
7027 pos += 4;
7028 break;
7029 default:
7030 return -1;
7031 }
7032
7033 /* CCMP MIC */
7034 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
7035 pos += 8;
7036 } else {
7037 switch (frame) {
7038 case DEAUTH:
7039 /* reason code = 8 */
7040 *pos++ = 0x08;
7041 *pos++ = 0x00;
7042 break;
7043 case DISASSOC:
7044 /* reason code = 8 */
7045 *pos++ = 0x08;
7046 *pos++ = 0x00;
7047 break;
7048 case SAQUERY:
7049 /* Category - SA Query */
7050 *pos++ = 0x08;
7051 /* SA query Action - Request */
7052 *pos++ = 0x00;
7053 /* Transaction ID */
7054 *pos++ = 0x12;
7055 *pos++ = 0x34;
7056 break;
7057 }
7058 }
7059
7060 s = open_monitor("sigmadut");
7061 if (s < 0) {
7062 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
7063 "monitor socket");
7064 return 0;
7065 }
7066
7067 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
7068 if (res < 0) {
7069 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
7070 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307071 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072 return 0;
7073 }
7074 if (res < pos - buf) {
7075 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
7076 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05307077 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007078 return 0;
7079 }
7080
7081 close(s);
7082
7083 return 1;
7084#else /* __linux__ */
7085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_send_frame not "
7086 "yet supported");
7087 return 0;
7088#endif /* __linux__ */
7089}
7090
7091
7092int ap_send_frame_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
7093 struct sigma_cmd *cmd)
7094{
7095 const char *val, *dest;
7096 char buf[100];
7097
7098 val = get_param(cmd, "FrameName");
7099 if (val == NULL)
7100 return -1;
7101
7102 if (strcasecmp(val, "QoSMapConfigure") == 0) {
7103 dest = get_param(cmd, "Dest");
7104 if (!dest)
7105 return -1;
7106
7107 val = get_param(cmd, "QoS_MAP_SET");
7108 if (val) {
7109 dut->ap_qos_map_set = atoi(val);
7110 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
7111 dut->ap_qos_map_set);
7112 }
7113
7114 if (dut->ap_qos_map_set == 1)
7115 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
7116 else if (dut->ap_qos_map_set == 2)
7117 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
7118
7119 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
7120 if (run_hostapd_cli(dut, buf) != 0)
7121 return -1;
7122 }
7123
7124 return 1;
7125}
7126
7127
7128static int ath_ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
7129 struct sigma_cmd *cmd)
7130{
7131 const char *val;
7132 char *ifname;
7133 char buf[100];
7134 int chwidth, nss;
7135
7136 val = get_param(cmd, "FrameName");
7137 if (!val || strcasecmp(val, "op_md_notif_frm") != 0) {
7138 send_resp(dut, conn, SIGMA_ERROR,
7139 "errorCode,Unsupported FrameName");
7140 return 0;
7141 }
7142
7143 /*
7144 * Sequence of commands for Opmode notification on
7145 * Peregrine based products
7146 */
7147 ifname = get_main_ifname();
7148
7149 /* Disable STBC */
7150 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", ifname);
7151 if (system(buf) != 0) {
7152 sigma_dut_print(dut, DUT_MSG_ERROR,
7153 "iwpriv tx_stbc 0 failed!");
7154 }
7155
7156 /* Check whether optional arg channel width was passed */
7157 val = get_param(cmd, "Channel_width");
7158 if (val) {
7159 switch (atoi(val)) {
7160 case 20:
7161 chwidth = 0;
7162 break;
7163 case 40:
7164 chwidth = 1;
7165 break;
7166 case 80:
7167 chwidth = 2;
7168 break;
7169 case 160:
7170 chwidth = 3;
7171 break;
7172 default:
7173 chwidth = 2;
7174 break;
7175 }
7176 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7177 ifname, chwidth);
7178 if (system(buf) != 0) {
7179 sigma_dut_print(dut, DUT_MSG_ERROR,
7180 "iwpriv chwidth failed!");
7181 }
7182 }
7183
7184 /* Check whether optional arg NSS was passed */
7185 val = get_param(cmd, "NSS");
7186 if (val) {
7187 /* Convert nss to chainmask */
7188 switch (atoi(val)) {
7189 case 1:
7190 nss = 1;
7191 break;
7192 case 2:
7193 nss = 3;
7194 break;
7195 case 3:
7196 nss = 7;
7197 break;
7198 default:
7199 /* We do not support NSS > 3 */
7200 nss = 3;
7201 break;
7202 }
7203 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7204 ifname, nss);
7205 if (system(buf) != 0) {
7206 sigma_dut_print(dut, DUT_MSG_ERROR,
7207 "iwpriv rxchainmask failed!");
7208 }
7209 }
7210
7211 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03007212 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007213 if (system(buf) != 0) {
7214 sigma_dut_print(dut, DUT_MSG_ERROR,
7215 "iwpriv opmode_notify failed!");
7216 }
7217
7218 return 1;
7219}
7220
7221
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007222static int ath_ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
7223 struct sigma_cmd *cmd)
7224{
7225 const char *val;
7226 FILE *f;
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07007227 int rand_int = 0;
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007228
7229 val = get_param(cmd, "MsntType");
7230 if (val) {
7231 if (dut->ap_msnt_type == 0)
7232 dut->ap_msnt_type = atoi(val);
7233
7234 if (dut->ap_msnt_type != 5 && dut->ap_msnt_type != 2) {
7235 dut->ap_msnt_type = atoi(val);
7236 if (dut->ap_msnt_type == 1) {
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07007237 val = get_param(cmd, "RandInterval");
7238 if (val)
7239 rand_int = atoi(val);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007240 f = fopen("/tmp/ftmrr.txt", "a");
7241 if (!f) {
7242 sigma_dut_print(dut, DUT_MSG_ERROR,
7243 "Failed to open /tmp/ftmrr.txt");
7244 return -1;
7245 }
7246
7247 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
priyadharshini gowthamana61badd2016-08-16 13:37:27 -07007248 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",
7249 rand_int, cmd->values[7]);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007250 fclose(f);
7251 dut->ap_msnt_type = 5;
7252 run_system(dut, "wpc -f /tmp/ftmrr.txt");
7253 }
7254 } else if (dut->ap_msnt_type == 5) {
7255 run_system(dut, "wpc -f /tmp/ftmrr.txt");
7256 } else if (dut->ap_msnt_type == 2) {
7257 f = fopen("/tmp/wru.txt", "w");
7258 if (!f) {
7259 sigma_dut_print(dut, DUT_MSG_ERROR,
7260 "Failed to open /tmp/wru.txt");
7261 return -1;
7262 }
7263
7264 fprintf(f, "sta_mac = %s\n", cmd->values[3]);
7265 fprintf(f, "meas_type = 0x08\ndialogtoken = 0x1\nnum_repetitions = 0x0\nmeas_token = 0x1\nmeas_req_mode = 0x00\nloc_subject = 0x01\n");
7266 fclose(f);
7267 run_system(dut, "wpc -w /tmp/wru.txt");
7268 }
7269 }
7270 return 1;
7271}
7272
7273
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007274/*
7275 * The following functions parse_send_frame_params_int(),
7276 * parse_send_frame_params_str(), and parse_send_frame_params_mac()
7277 * are used by ath_ap_send_frame_bcn_rpt_req().
7278 * Beacon Report Request is a frame used as part of the MBO program.
7279 * The command for sending beacon report has a lot of
7280 * arguments and having these functions reduces code size.
7281 *
7282 */
7283static int parse_send_frame_params_int(char *param, struct sigma_cmd *cmd,
7284 struct sigma_dut *dut,
7285 char *buf, size_t buf_size)
7286{
7287 const char *str_val;
7288 int int_val;
7289 char temp[100];
7290
7291 str_val = get_param(cmd, param);
7292 if (!str_val) {
7293 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
7294 return -1;
7295 }
7296 int_val = atoi(str_val);
7297 snprintf(temp, sizeof(temp), " %d", int_val);
Peng Xu591be452017-05-10 17:27:28 -07007298 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007299 return 0;
7300}
7301
7302
7303static int parse_send_frame_params_str(char *param, struct sigma_cmd *cmd,
7304 struct sigma_dut *dut,
7305 char *buf, size_t buf_size)
7306{
7307 const char *str_val;
7308 char temp[100];
7309
7310 str_val = get_param(cmd, param);
7311 if (!str_val) {
7312 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
7313 return -1;
7314 }
7315 snprintf(temp, sizeof(temp), " %s", str_val);
7316 temp[sizeof(temp) - 1] = '\0';
Peng Xu591be452017-05-10 17:27:28 -07007317 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007318 return 0;
7319}
7320
7321
7322static int parse_send_frame_params_mac(char *param, struct sigma_cmd *cmd,
7323 struct sigma_dut *dut,
7324 char *buf, size_t buf_size)
7325{
7326 const char *str_val;
7327 unsigned char mac[6];
7328 char temp[100];
7329
7330 str_val = get_param(cmd, param);
7331 if (!str_val) {
7332 sigma_dut_print(dut, DUT_MSG_ERROR, "%s not given", param);
7333 return -1;
7334 }
7335
7336 if (parse_mac_address(dut, str_val, mac) < 0) {
7337 sigma_dut_print(dut, DUT_MSG_ERROR,
7338 "MAC Address not in proper format");
7339 return -1;
7340 }
7341 snprintf(temp, sizeof(temp), " %02x:%02x:%02x:%02x:%02x:%02x",
7342 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
Peng Xu591be452017-05-10 17:27:28 -07007343 strlcat(buf, temp, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007344 return 0;
7345}
7346
7347
7348static void fill_1_or_0_based_on_presence(struct sigma_cmd *cmd, char *param,
7349 char *buf, size_t buf_size)
7350{
7351 const char *str_val;
7352 char *value = " 1";
7353
7354 str_val = get_param(cmd, param);
7355 if (!str_val || str_val[0] == '\0')
7356 value = " 0";
Peng Xu591be452017-05-10 17:27:28 -07007357 strlcat(buf, value, buf_size);
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007358
7359}
7360
7361
7362/*
7363 * wifitool athN sendbcnrpt
7364 * <STA MAC - Plugs in from Dest_MAC>
7365 * <regclass - Plugs in from RegClass - int>
7366 * <channum - Plugs in from Channel PARAM of dev_send_frame - int>
7367 * <rand_ivl - Plugs in from RandInt - string>
7368 * <duration - Plugs in from MeaDur - integer>
7369 * <mode - Plugs in from MeaMode - string>
7370 * <req_ssid - Plugs in from SSID PARAM of dev_send_frame - string>
7371 * <rep_cond - Plugs in from RptCond - integer>
7372 * <rpt_detail - Plugs in from RptDet - integer>
7373 * <req_ie - Plugs in from ReqInfo PARAM of dev_send_frame - string>
7374 * <chanrpt_mode - Plugs in from APChanRpt - integer>
7375 * <specific_bssid - Plugs in from BSSID PARAM of dev_send_frame>
7376 * [AP channel numbers]
7377 */
7378static int ath_ap_send_frame_bcn_rpt_req(struct sigma_dut *dut,
7379 struct sigma_cmd *cmd,
7380 const char *ifname)
7381{
7382 char buf[100];
7383 int rpt_det;
7384 const char *str_val;
7385 const char *mea_mode;
7386
7387 snprintf(buf, sizeof(buf), "wifitool %s sendbcnrpt", ifname);
7388
7389 if (parse_send_frame_params_mac("Dest_MAC", cmd, dut, buf, sizeof(buf)))
7390 return -1;
7391 if (parse_send_frame_params_int("RegClass", cmd, dut, buf, sizeof(buf)))
7392 return -1;
7393 if (parse_send_frame_params_int("Channel", cmd, dut, buf, sizeof(buf)))
7394 return -1;
7395 if (parse_send_frame_params_str("RandInt", cmd, dut, buf, sizeof(buf)))
7396 return -1;
7397 if (parse_send_frame_params_int("MeaDur", cmd, dut, buf, sizeof(buf)))
7398 return -1;
7399
7400 str_val = get_param(cmd, "MeaMode");
7401 if (!str_val) {
7402 sigma_dut_print(dut, DUT_MSG_ERROR,
7403 "MeaMode parameter not present in send bcn-rpt-req");
7404 return -1;
7405 }
7406 if (strcasecmp(str_val, "passive") == 0) {
7407 mea_mode = " 0";
7408 } else if (strcasecmp(str_val, "active") == 0) {
7409 mea_mode = " 1";
7410 } else if (strcasecmp(str_val, "table") == 0) {
7411 mea_mode = " 2";
7412 } else {
7413 sigma_dut_print(dut, DUT_MSG_ERROR,
7414 "MEA-MODE Value not correctly given");
7415 return -1;
7416 }
Peng Xu591be452017-05-10 17:27:28 -07007417 strlcat(buf, mea_mode, sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007418
7419 fill_1_or_0_based_on_presence(cmd, "SSID", buf, sizeof(buf));
7420
7421 if (parse_send_frame_params_int("RptCond", cmd, dut, buf, sizeof(buf)))
7422 return -1;
7423
7424 if (parse_send_frame_params_int("RptDet", cmd, dut, buf, sizeof(buf)))
7425 return -1;
7426 str_val = get_param(cmd, "RptDet");
7427 rpt_det = str_val ? atoi(str_val) : 0;
7428
7429 if (rpt_det)
7430 fill_1_or_0_based_on_presence(cmd, "ReqInfo", buf, sizeof(buf));
7431 else
Peng Xu591be452017-05-10 17:27:28 -07007432 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007433
7434 if (rpt_det)
7435 fill_1_or_0_based_on_presence(cmd, "APChanRpt", buf,
7436 sizeof(buf));
7437 else
Peng Xu591be452017-05-10 17:27:28 -07007438 strlcat(buf, " 0", sizeof(buf));
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007439
7440 if (parse_send_frame_params_mac("BSSID", cmd, dut, buf, sizeof(buf)))
7441 return -1;
7442
7443 run_system(dut, buf);
7444 return 0;
7445}
7446
7447
7448static void inform_and_sleep(struct sigma_dut *dut, int seconds)
7449{
7450 sigma_dut_print(dut, DUT_MSG_DEBUG, "sleeping for %d seconds", seconds);
7451 sleep(seconds);
7452 sigma_dut_print(dut, DUT_MSG_DEBUG, "woke up after %d seconds",
7453 seconds);
7454}
7455
7456
7457static int ath_ap_send_frame_btm_req(struct sigma_dut *dut,
7458 struct sigma_cmd *cmd, const char *ifname)
7459{
7460 unsigned char mac_addr[ETH_ALEN];
7461 int disassoc_timer;
7462 char buf[100];
7463 const char *val;
7464 int cand_list = 1;
7465 int tsf = 2;
7466
7467 val = get_param(cmd, "Dest_MAC");
7468 if (!val || parse_mac_address(dut, val, mac_addr) < 0) {
7469 sigma_dut_print(dut, DUT_MSG_ERROR,
7470 "MAC Address not in proper format");
7471 return -1;
7472 }
7473
7474 val = get_param(cmd, "Disassoc_Timer");
7475 if (val)
7476 disassoc_timer = atoi(val);
7477 else
7478 disassoc_timer = dut->ap_disassoc_timer;
7479
7480 val = get_param(cmd, "Cand_List");
7481 if (val && val[0])
7482 cand_list = atoi(val);
7483
7484 val = get_param(cmd, "BTMQuery_Reason_Code");
7485 if (val) {
7486 snprintf(buf, sizeof(buf), "iwpriv %s mbo_trans_rs %s",
7487 ifname, val);
7488 run_system(dut, buf);
7489 }
7490
7491 snprintf(buf, sizeof(buf),
7492 "wifitool %s sendbstmreq %02x:%02x:%02x:%02x:%02x:%02x %d %d 3 %d %d %d %d",
7493 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
7494 mac_addr[4], mac_addr[5], cand_list, disassoc_timer,
7495 dut->ap_btmreq_disassoc_imnt,
7496 dut->ap_btmreq_term_bit,
7497 tsf,
7498 dut->ap_btmreq_bss_term_dur);
7499 run_system(dut, buf);
7500
7501 if (dut->ap_btmreq_term_bit) {
7502 inform_and_sleep(dut, 3);
7503 run_system_wrapper(dut, "ifconfig %s down", ifname);
7504 inform_and_sleep(dut, dut->ap_btmreq_bss_term_dur * 60);
7505 run_system_wrapper(dut, "ifconfig %s up", ifname);
7506 } else if (dut->ap_btmreq_disassoc_imnt) {
7507 inform_and_sleep(dut, (disassoc_timer / 1000) + 1);
7508 run_system_wrapper(dut,
7509 "iwpriv %s kickmac %02x:%02x:%02x:%02x:%02x:%02x",
7510 ifname,
7511 mac_addr[0], mac_addr[1], mac_addr[2],
7512 mac_addr[3], mac_addr[4], mac_addr[5]);
7513 }
7514 return 0;
7515}
7516
7517
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007518static int ath_ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
7519 struct sigma_cmd *cmd)
7520{
7521 const char *val;
7522 char *ifname;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007523
7524 ifname = get_main_ifname();
7525
7526 val = get_param(cmd, "FrameName");
7527 if (!val)
7528 return -1;
7529
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07007530 if (strcasecmp(val, "BTMReq") == 0)
7531 ath_ap_send_frame_btm_req(dut, cmd, ifname);
7532 else if (strcasecmp(val, "BcnRptReq") == 0)
7533 ath_ap_send_frame_bcn_rpt_req(dut, cmd, ifname);
7534 else
7535 return -1;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007536
7537 return 1;
7538}
7539
7540
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007541static int ap_send_frame_vht(struct sigma_dut *dut, struct sigma_conn *conn,
7542 struct sigma_cmd *cmd)
7543{
7544 switch (get_driver_type()) {
7545 case DRIVER_ATHEROS:
7546 return ath_ap_send_frame_vht(dut, conn, cmd);
7547 break;
7548 case DRIVER_OPENWRT:
7549 switch (get_openwrt_driver_type()) {
7550 case OPENWRT_DRIVER_ATHEROS:
7551 return ath_ap_send_frame_vht(dut, conn, cmd);
7552 default:
7553 send_resp(dut, conn, SIGMA_ERROR,
7554 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
7555 return 0;
7556 }
7557 default:
7558 send_resp(dut, conn, SIGMA_ERROR,
7559 "errorCode,Unsupported ap_send_frame with the current driver");
7560 return 0;
7561 }
7562}
7563
7564
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007565static int ap_send_frame_loc(struct sigma_dut *dut, struct sigma_conn *conn,
7566 struct sigma_cmd *cmd)
7567{
7568 switch (get_driver_type()) {
7569 case DRIVER_ATHEROS:
7570 return ath_ap_send_frame_loc(dut, conn, cmd);
7571 case DRIVER_OPENWRT:
7572 switch (get_openwrt_driver_type()) {
7573 case OPENWRT_DRIVER_ATHEROS:
7574 return ath_ap_send_frame_loc(dut, conn, cmd);
7575 default:
7576 send_resp(dut, conn, SIGMA_ERROR,
7577 "errorCode,Unsupported ap_send_frame_loc with the current openwrt driver");
7578 return 0;
7579 }
7580 default:
7581 send_resp(dut, conn, SIGMA_ERROR,
7582 "errorCode,Unsupported ap_send_frame_loc with the current driver");
7583 return 0;
7584 }
7585}
7586
7587
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007588static int ap_send_frame_mbo(struct sigma_dut *dut, struct sigma_conn *conn,
7589 struct sigma_cmd *cmd)
7590{
7591 switch (get_driver_type()) {
7592 case DRIVER_ATHEROS:
7593 return ath_ap_send_frame_mbo(dut, conn, cmd);
7594 case DRIVER_OPENWRT:
7595 switch (get_openwrt_driver_type()) {
7596 case OPENWRT_DRIVER_ATHEROS:
7597 return ath_ap_send_frame_mbo(dut, conn, cmd);
7598 default:
7599 send_resp(dut, conn, SIGMA_ERROR,
7600 "errorCode,Unsupported ap_send_frame with the current openwrt driver");
7601 return 0;
7602 }
7603 default:
7604 send_resp(dut, conn, SIGMA_ERROR,
7605 "errorCode,Unsupported ap_send_frame with the current driver");
7606 return 0;
7607 }
7608}
7609
7610
Lior David0fe101e2017-03-09 16:09:50 +02007611static int ap_send_frame_60g(struct sigma_dut *dut,
7612 struct sigma_conn *conn,
7613 struct sigma_cmd *cmd)
7614{
7615 switch (get_driver_type()) {
7616#ifdef __linux__
7617 case DRIVER_WIL6210:
7618 return wil6210_send_frame_60g(dut, conn, cmd);
7619#endif /* __linux__ */
7620 default:
7621 send_resp(dut, conn, SIGMA_ERROR,
7622 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
7623 return 0;
7624 }
7625}
7626
7627
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7629 struct sigma_cmd *cmd)
7630{
7631 /* const char *name = get_param(cmd, "NAME"); */
7632 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7633 const char *val;
7634 enum send_frame_type frame;
7635 enum send_frame_protection protected;
7636 char buf[100];
7637
7638 val = get_param(cmd, "Program");
7639 if (val) {
7640 if (strcasecmp(val, "HS2") == 0 ||
Adil Saeed Musthafa33ea2872017-04-10 23:13:24 -07007641 strcasecmp(val, "HS2-R2") == 0 ||
7642 strcasecmp(val, "IOTLP") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007643 return ap_send_frame_hs2(dut, conn, cmd);
7644 if (strcasecmp(val, "VHT") == 0)
7645 return ap_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamana27b5b62016-06-22 22:47:14 -07007646 if (strcasecmp(val, "LOC") == 0)
7647 return ap_send_frame_loc(dut, conn, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07007648 if (strcasecmp(val, "MBO") == 0)
7649 return ap_send_frame_mbo(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02007650 if (strcasecmp(val, "60GHz") == 0)
7651 return ap_send_frame_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007652 }
7653
7654 val = get_param(cmd, "PMFFrameType");
7655 if (val == NULL)
7656 val = get_param(cmd, "FrameName");
7657 if (val == NULL)
7658 val = get_param(cmd, "Type");
7659 if (val == NULL)
7660 return -1;
7661 if (strcasecmp(val, "disassoc") == 0)
7662 frame = DISASSOC;
7663 else if (strcasecmp(val, "deauth") == 0)
7664 frame = DEAUTH;
7665 else if (strcasecmp(val, "saquery") == 0)
7666 frame = SAQUERY;
7667 else {
7668 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7669 "PMFFrameType");
7670 return 0;
7671 }
7672
7673 val = get_param(cmd, "PMFProtected");
7674 if (val == NULL)
7675 val = get_param(cmd, "Protected");
7676 if (val == NULL)
7677 return -1;
7678 if (strcasecmp(val, "Correct-key") == 0 ||
7679 strcasecmp(val, "CorrectKey") == 0)
7680 protected = CORRECT_KEY;
7681 else if (strcasecmp(val, "IncorrectKey") == 0)
7682 protected = INCORRECT_KEY;
7683 else if (strcasecmp(val, "Unprotected") == 0)
7684 protected = UNPROTECTED;
7685 else {
7686 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7687 "PMFProtected");
7688 return 0;
7689 }
7690
7691 val = get_param(cmd, "stationID");
7692 if (val == NULL)
7693 return -1;
7694
7695 if (protected == INCORRECT_KEY ||
7696 (protected == UNPROTECTED && frame == SAQUERY))
7697 return ap_inject_frame(dut, conn, frame, protected, val);
7698
7699 switch (frame) {
7700 case DISASSOC:
7701 snprintf(buf, sizeof(buf), "disassoc %s test=%d",
7702 val, protected == CORRECT_KEY);
7703 break;
7704 case DEAUTH:
7705 snprintf(buf, sizeof(buf), "deauth %s test=%d",
7706 val, protected == CORRECT_KEY);
7707 break;
7708 case SAQUERY:
7709 snprintf(buf, sizeof(buf), "sa_query %s", val);
7710 break;
7711 }
7712
7713 if (run_hostapd_cli(dut, buf) != 0)
7714 return -2;
7715
7716 return 1;
7717}
7718
7719
7720static int cmd_ap_get_mac_address(struct sigma_dut *dut,
7721 struct sigma_conn *conn,
7722 struct sigma_cmd *cmd)
7723{
7724#if defined( __linux__)
7725 /* const char *name = get_param(cmd, "NAME"); */
7726 /* const char *ifname = get_param(cmd, "INTERFACE"); */
Jouni Malinenf8984642017-10-12 00:02:37 +03007727 char resp[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007728 unsigned char addr[6];
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007729 char ifname[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007730 struct ifreq ifr;
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007731 int s, wlan_tag = 1;
7732 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007733
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007734 val = get_param(cmd, "WLAN_TAG");
7735 if (val) {
7736 wlan_tag = atoi(val);
7737 if (wlan_tag < 1 || wlan_tag > 3) {
7738 /*
7739 * The only valid WLAN Tags as of now as per the latest
7740 * WFA scripts are 1, 2, and 3.
7741 */
Jouni Malinenf8984642017-10-12 00:02:37 +03007742 send_resp(dut, conn, SIGMA_ERROR,
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007743 "errorCode,Unsupported WLAN_TAG");
7744 return 0;
7745 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007746 }
7747
Adil Saeed Musthafab7b297f2017-04-10 23:13:31 -07007748 get_if_name(dut, ifname, sizeof(ifname), wlan_tag);
7749
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007750 s = socket(AF_INET, SOCK_DGRAM, 0);
7751 if (s < 0)
7752 return -1;
7753 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07007754 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007755 if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
7756 perror("ioctl");
7757 close(s);
Jouni Malinenf8984642017-10-12 00:02:37 +03007758 snprintf(resp, sizeof(resp),
7759 "errorCode,Could not find interface %s", ifname);
7760 send_resp(dut, conn, SIGMA_ERROR, resp);
7761 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007762 }
7763 close(s);
7764 memcpy(addr, ifr.ifr_hwaddr.sa_data, 6);
7765
7766 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
7767 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
7768 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7769 return 0;
7770#elif defined( __QNXNTO__)
7771 char resp[50];
7772 unsigned char addr[6];
7773
7774 if (!sigma_main_ifname) {
7775 send_resp(dut, conn, SIGMA_ERROR, "ifname is null");
7776 return 0;
7777 }
7778
7779 if (get_hwaddr(sigma_main_ifname, addr) != 0) {
7780 send_resp(dut, conn, SIGMA_ERROR,
7781 "errorCode,Failed to get address");
7782 return 0;
7783 }
7784 snprintf(resp, sizeof(resp), "mac,%02x:%02x:%02x:%02x:%02x:%02x",
7785 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
7786 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7787 return 0;
7788#else /* __linux__ */
7789 send_resp(dut, conn, SIGMA_ERROR, "errorCode,ap_get_mac_address not "
7790 "yet supported");
7791 return 0;
7792#endif /* __linux__ */
7793}
7794
7795
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307796int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
7797 struct sigma_cmd *cmd)
7798{
7799 return cmd_ap_get_mac_address(dut, conn, cmd);
7800}
7801
7802
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007803static int cmd_ap_set_pmf(struct sigma_dut *dut, struct sigma_conn *conn,
7804 struct sigma_cmd *cmd)
7805{
7806 /*
7807 * Ignore the command since the parameters are already handled through
7808 * ap_set_security.
7809 */
7810
7811 return 1;
7812}
7813
7814
7815static int cmd_ap_set_hs2(struct sigma_dut *dut, struct sigma_conn *conn,
7816 struct sigma_cmd *cmd)
7817{
7818 /* const char *name = get_param(cmd, "NAME"); */
7819 /* const char *ifname = get_param(cmd, "INTERFACE"); */
7820 const char *val, *dest;
7821 char *pos, buf[100];
7822 int i, wlan_tag = 1;
7823
7824 sigma_dut_print(dut, DUT_MSG_INFO, "ap_set_hs2: Processing the "
7825 "following parameters");
7826 for (i = 0; i < cmd->count; i++) {
7827 sigma_dut_print(dut, DUT_MSG_INFO, "%s %s", cmd->params[i],
7828 (cmd->values[i] ? cmd->values[i] : "NULL"));
7829 }
7830
7831 val = get_param(cmd, "ICMPv4_ECHO");
7832 if (val && atoi(val)) {
7833 snprintf(buf, sizeof(buf), "ebtables -F");
7834 if (system(buf) != 0) {
7835 sigma_dut_print(dut, DUT_MSG_ERROR,
7836 "Failed to set ebtables rules, RULE-12");
7837 }
7838 return 1;
7839 }
7840
7841 val = get_param(cmd, "WLAN_TAG");
7842 if (val) {
7843 wlan_tag = atoi(val);
7844 if (wlan_tag != 1 && wlan_tag != 2) {
7845 send_resp(dut, conn, SIGMA_INVALID,
7846 "errorCode,Invalid WLAN_TAG");
7847 return 0;
7848 }
7849 }
7850
7851 if (wlan_tag == 2) {
7852 val = get_param(cmd, "PROXY_ARP");
7853 if (val)
7854 dut->ap2_proxy_arp = atoi(val);
7855 return 1;
7856 }
7857
7858 dest = get_param(cmd, "STA_MAC");
7859 if (dest) {
7860 /* This is a special/ugly way of using this command.
7861 * If "Dest" MAC is included, assume that this command
7862 * is being issued after ap_config_commit for dynamically
7863 * setting the QoS Map Set.
7864 */
7865 val = get_param(cmd, "QoS_MAP_SET");
7866 if (val) {
7867 dut->ap_qos_map_set = atoi(val);
7868 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
7869 dut->ap_qos_map_set);
7870 }
7871
7872 if (dut->ap_qos_map_set == 1)
7873 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_1);
7874 else if (dut->ap_qos_map_set == 2)
7875 run_hostapd_cli(dut, "set_qos_map_set " QOS_MAP_SET_2);
7876
7877 snprintf(buf, sizeof(buf), "send_qos_map_conf %s", dest);
7878 if (run_hostapd_cli(dut, buf) != 0)
7879 return -1;
7880 }
7881
7882 val = get_param(cmd, "DGAF_DISABLE");
7883 if (val)
7884 dut->ap_dgaf_disable = atoi(val);
7885
7886 dut->ap_interworking = 1;
7887
7888 val = get_param(cmd, "INTERWORKING");
7889 if (val == NULL)
7890 val = get_param(cmd, "INTERNETWORKING");
7891 if (val != NULL && atoi(val) == 0) {
7892 dut->ap_interworking = 0;
7893 dut->ap_hs2 = 0;
7894 return 1;
7895 }
7896
7897 val = get_param(cmd, "ACCS_NET_TYPE");
7898 if (val) {
7899 if (strcasecmp(val, "Chargeable_Public_Network") == 0 ||
7900 strcasecmp(val, "Chargable_Public_Network") == 0 ||
7901 strcasecmp(val, "Chargable Public Network") == 0)
7902 dut->ap_access_net_type = 2;
7903 else
7904 dut->ap_access_net_type = atoi(val);
7905 }
7906
7907 val = get_param(cmd, "INTERNET");
7908 if (val)
7909 dut->ap_internet = atoi(val);
7910
7911 val = get_param(cmd, "VENUE_GRP");
7912 if (val) {
7913 if (strcasecmp(val, "Business") == 0)
7914 dut->ap_venue_group = 2;
7915 else
7916 dut->ap_venue_group = atoi(val);
7917 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
7918 dut->ap_venue_name);
7919 }
7920
7921 val = get_param(cmd, "VENUE_TYPE");
7922 if (val) {
7923 if (strcasecmp(val, "R&D") == 0)
7924 dut->ap_venue_type = 8;
7925 else
7926 dut->ap_venue_type = atoi(val);
7927 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_type %d",
7928 dut->ap_venue_type);
7929 }
7930
7931 val = get_param(cmd, "HESSID");
7932 if (val) {
7933 if (strlen(val) >= sizeof(dut->ap_hessid)) {
7934 send_resp(dut, conn, SIGMA_ERROR,
7935 "errorCode,Invalid HESSID");
7936 return 0;
7937 }
7938 snprintf(dut->ap_hessid, sizeof(dut->ap_hessid), "%s", val);
7939 sigma_dut_print(dut, DUT_MSG_INFO, "ap_hessid %s",
7940 dut->ap_hessid);
7941 }
7942
7943 val = get_param(cmd, "ROAMING_CONS");
7944 if (val) {
7945 if (strlen(val) >= sizeof(dut->ap_roaming_cons)) {
7946 send_resp(dut, conn, SIGMA_ERROR,
7947 "errorCode,Invalid ROAMING_CONS");
7948 return 0;
7949 }
7950 if (strcasecmp(val, "Disabled") == 0) {
7951 dut->ap_roaming_cons[0] = '\0';
7952 } else {
7953 snprintf(dut->ap_roaming_cons,
7954 sizeof(dut->ap_roaming_cons), "%s", val);
7955 }
7956 sigma_dut_print(dut, DUT_MSG_INFO, "ap_roaming_cons %s",
7957 dut->ap_roaming_cons);
7958 }
7959
7960 val = get_param(cmd, "ANQP");
7961 if (val)
7962 dut->ap_anqpserver_on = atoi(val);
7963
7964 val = get_param(cmd, "NAI_REALM_LIST");
7965 if (val) {
7966 dut->ap_nai_realm_list = atoi(val);
7967 sigma_dut_print(dut, DUT_MSG_INFO, "ap_nai_realm_list %d",
7968 dut->ap_nai_realm_list);
7969 }
7970
7971 val = get_param(cmd, "3GPP_INFO");
7972 if (val) {
7973 /* What kind of encoding format is used?! */
7974 send_resp(dut, conn, SIGMA_ERROR, "errorCode,3GPP_INFO "
7975 "not yet supported (contents not fully defined)");
7976 return 0;
7977 }
7978
7979 val = get_param(cmd, "DOMAIN_LIST");
7980 if (val) {
7981 if (strlen(val) >= sizeof(dut->ap_domain_name_list)) {
7982 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Too long "
7983 "DOMAIN_LIST");
7984 return 0;
7985 }
7986 snprintf(dut->ap_domain_name_list,
7987 sizeof(dut->ap_domain_name_list), "%s", val);
7988 pos = dut->ap_domain_name_list;
7989 while (*pos) {
7990 if (*pos == ';')
7991 *pos = ',';
7992 pos++;
7993 }
7994 sigma_dut_print(dut, DUT_MSG_INFO, "ap_domain_name_list %s",
7995 dut->ap_domain_name_list);
7996 }
7997
7998 val = get_param(cmd, "OPER_NAME");
7999 if (val) {
8000 dut->ap_oper_name = atoi(val);
8001 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_name %d",
8002 dut->ap_oper_name);
8003 }
8004
8005 val = get_param(cmd, "VENUE_NAME");
8006 if (val) {
8007 dut->ap_venue_name = atoi(val);
8008 sigma_dut_print(dut, DUT_MSG_INFO, "ap_venue_name %d",
8009 dut->ap_venue_name);
8010 }
8011
8012 val = get_param(cmd, "GAS_CB_DELAY");
8013 if (val) {
8014 dut->ap_gas_cb_delay = atoi(val);
8015 sigma_dut_print(dut, DUT_MSG_INFO, "ap_gas_cb_delay %d",
8016 dut->ap_gas_cb_delay);
8017 }
8018
8019 val = get_param(cmd, "MIH");
8020 if (val && atoi(val) > 0) {
8021 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MIH not "
8022 "supported");
8023 return 0;
8024 }
8025
8026 val = get_param(cmd, "L2_TRAFFIC_INSPECT");
8027 if (val) {
8028 dut->ap_l2tif = atoi(val);
8029 sigma_dut_print(dut, DUT_MSG_INFO, "ap_l2tif %d",
8030 dut->ap_l2tif);
8031 }
8032
8033 val = get_param(cmd, "BCST_UNCST");
8034 if (val) {
8035 send_resp(dut, conn, SIGMA_ERROR,
8036 "errorCode,BCST_UNCST not yet supported");
8037 return 0;
8038 }
8039
8040 val = get_param(cmd, "PLMN_MCC");
8041 if (val) {
8042 char mcc[100], *start, *end;
8043 int i = 0;
8044 if (strlen(val) >= sizeof(mcc)) {
8045 send_resp(dut, conn, SIGMA_ERROR,
8046 "errorCode,PLMN_MCC too long");
8047 return 0;
8048 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07008049 strlcpy(mcc, val, sizeof(mcc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008050 start = mcc;
8051 while ((end = strchr(start, ';'))) {
8052 /* process all except the last */
8053 *end = '\0';
8054 if (strlen(start) != 3) {
8055 send_resp(dut, conn, SIGMA_ERROR,
8056 "errorCode,Invalid PLMN_MCC");
8057 return 0;
8058 }
8059 snprintf(dut->ap_plmn_mcc[i],
8060 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
8061 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
8062 dut->ap_plmn_mcc[i]);
8063 i++;
8064 start = end + 1;
8065 *end = ';';
8066 }
8067 if (strlen(start) != 3) {
8068 send_resp(dut, conn, SIGMA_ERROR,
8069 "errorCode,Invalid PLMN_MCC");
8070 return 0;
8071 }
8072 /* process last or only one */
8073 snprintf(dut->ap_plmn_mcc[i],
8074 sizeof(dut->ap_plmn_mcc[i]), "%s", start);
8075 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mcc %s",
8076 dut->ap_plmn_mcc[i]);
8077 }
8078
8079 val = get_param(cmd, "PLMN_MNC");
8080 if (val) {
8081 char mnc[100], *start, *end;
8082 int i = 0;
8083 if (strlen(val) >= sizeof(mnc)) {
8084 send_resp(dut, conn, SIGMA_ERROR,
8085 "errorCode,PLMN_MNC too long");
8086 return 0;
8087 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07008088 strlcpy(mnc, val, sizeof(mnc));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008089 start = mnc;
8090 while ((end = strchr(start, ';'))) {
8091 *end = '\0';
8092 if (strlen(start) != 2 && strlen(start) != 3) {
8093 send_resp(dut, conn, SIGMA_ERROR,
8094 "errorCode,Invalid PLMN_MNC");
8095 return 0;
8096 }
8097 snprintf(dut->ap_plmn_mnc[i],
8098 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
8099 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
8100 dut->ap_plmn_mnc[i]);
8101 i++;
8102 start = end + 1;
8103 *end = ';';
8104 }
8105 if (strlen(start) != 2 && strlen(start) != 3) {
8106 send_resp(dut, conn, SIGMA_ERROR,
8107 "errorCode,Invalid PLMN_MNC");
8108 return 0;
8109 }
8110 snprintf(dut->ap_plmn_mnc[i],
8111 sizeof(dut->ap_plmn_mnc[i]), "%s", start);
8112 sigma_dut_print(dut, DUT_MSG_INFO, "ap_plmn_mnc %s",
8113 dut->ap_plmn_mnc[i]);
8114 }
8115
8116 val = get_param(cmd, "PROXY_ARP");
8117 if (val) {
8118 dut->ap_proxy_arp = atoi(val);
8119 sigma_dut_print(dut, DUT_MSG_INFO, "ap_proxy_arp %d",
8120 dut->ap_proxy_arp);
8121 }
8122
8123 val = get_param(cmd, "WAN_METRICS");
8124 if (val) {
8125 dut->ap_wan_metrics = atoi(val);
8126 sigma_dut_print(dut, DUT_MSG_INFO, "ap_wan_metrics %d",
8127 dut->ap_wan_metrics);
8128 }
8129
8130 val = get_param(cmd, "CONN_CAP");
8131 if (val) {
8132 dut->ap_conn_capab = atoi(val);
8133 sigma_dut_print(dut, DUT_MSG_INFO, "ap_conn_capab %d",
8134 dut->ap_conn_capab);
8135 }
8136
8137 val = get_param(cmd, "IP_ADD_TYPE_AVAIL");
8138 if (val) {
8139 dut->ap_ip_addr_type_avail = atoi(val);
8140 sigma_dut_print(dut, DUT_MSG_INFO, "ap_ip_addr_type_avail %d",
8141 dut->ap_ip_addr_type_avail);
8142 }
8143
8144 val = get_param(cmd, "NET_AUTH_TYPE");
8145 if (val) {
8146 dut->ap_net_auth_type = atoi(val);
8147 sigma_dut_print(dut, DUT_MSG_INFO, "ap_net_auth_type %d",
8148 dut->ap_net_auth_type);
8149 }
8150
8151 val = get_param(cmd, "OP_CLASS");
8152 if (val == NULL)
8153 val = get_param(cmd, "OPER_CLASS");
8154 if (val) {
8155 dut->ap_oper_class = atoi(val);
8156 sigma_dut_print(dut, DUT_MSG_INFO, "ap_oper_class %d",
8157 dut->ap_oper_class);
8158 }
8159
8160 val = get_param(cmd, "OSU_PROVIDER_LIST");
8161 if (val) {
8162 dut->ap_osu_provider_list = atoi(val);
8163 sigma_dut_print(dut, DUT_MSG_INFO, "ap_osu_provider_list %d",
8164 dut->ap_osu_provider_list);
8165 }
8166
8167 val = get_param(cmd, "OSU_SERVER_URI");
8168 if (val) {
8169 i = 0;
8170 do {
8171 int len;
8172 const char *uri = val;
8173 val = strchr(val, ' ');
8174 len = val ? (val++ - uri) : (int) strlen(uri);
8175 if (len > 0 && len < 256) {
8176 memcpy(dut->ap_osu_server_uri[i], uri, len);
8177 dut->ap_osu_server_uri[i][len] = '\0';
8178 sigma_dut_print(dut, DUT_MSG_INFO,
8179 "ap_osu_server_uri[%d] %s", i,
8180 dut->ap_osu_server_uri[i]);
8181 }
8182 } while (val && ++i < 10);
8183 }
8184
8185 val = get_param(cmd, "OSU_METHOD");
8186 if (val) {
8187 i = 0;
8188 do {
8189 int len;
8190 const char *method = val;
8191 val = strchr(val, ' ');
8192 len = val ? (val++ - method) : (int) strlen(method);
8193 if (len > 0) {
8194 if (strncasecmp(method, "SOAP", len) == 0)
8195 dut->ap_osu_method[i] = 1;
8196 else if (strncasecmp(method, "OMADM", len) == 0)
8197 dut->ap_osu_method[i] = 0;
8198 else
8199 return -2;
8200 }
8201 } while (val && ++i < 10);
8202 }
8203
8204 val = get_param(cmd, "OSU_SSID");
8205 if (val) {
8206 if (strlen(val) > 0 && strlen(val) <= 32) {
Peng Xub8fc5cc2017-05-10 17:27:28 -07008207 strlcpy(dut->ap_osu_ssid, val,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008208 sizeof(dut->ap_osu_ssid));
8209 sigma_dut_print(dut, DUT_MSG_INFO,
8210 "ap_osu_ssid %s",
8211 dut->ap_osu_ssid);
8212 }
8213 }
8214
8215 val = get_param(cmd, "OSU_ICON_TAG");
8216 if (val)
8217 dut->ap_osu_icon_tag = atoi(val);
8218
8219 val = get_param(cmd, "QoS_MAP_SET");
8220 if (val) {
8221 dut->ap_qos_map_set = atoi(val);
8222 sigma_dut_print(dut, DUT_MSG_INFO, "ap_qos_map_set %d",
8223 dut->ap_qos_map_set);
8224 }
8225
8226 val = get_param(cmd, "BSS_LOAD");
8227 if (val) {
8228 dut->ap_bss_load = atoi(val);
8229 sigma_dut_print(dut, DUT_MSG_INFO, "ap_bss_load %d",
8230 dut->ap_bss_load);
8231 }
8232
8233 return 1;
8234}
8235
8236
8237void nfc_status(struct sigma_dut *dut, const char *state, const char *oper)
8238{
8239 char buf[100];
8240
8241 if (!file_exists("nfc-status"))
8242 return;
8243
8244 snprintf(buf, sizeof(buf), "./nfc-status %s %s", state, oper);
8245 run_system(dut, buf);
8246}
8247
8248
8249static int run_nfc_command(struct sigma_dut *dut, const char *cmd,
8250 const char *info)
8251{
8252 int res;
8253
8254 printf("\n\n\n=====[ NFC operation ]=========================\n\n");
8255 printf("%s\n\n", info);
8256
8257 nfc_status(dut, "START", info);
8258 res = run_system(dut, cmd);
8259 nfc_status(dut, res ? "FAIL" : "SUCCESS", info);
8260 if (res) {
8261 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to run '%s': %d",
8262 cmd, res);
8263 return res;
8264 }
8265
8266 return 0;
8267}
8268
8269
8270static int ap_nfc_write_config_token(struct sigma_dut *dut,
8271 struct sigma_conn *conn,
8272 struct sigma_cmd *cmd)
8273{
8274 int res;
8275 char buf[300];
8276
8277 run_system(dut, "killall wps-ap-nfc.py");
8278 unlink("nfc-success");
8279 snprintf(buf, sizeof(buf),
8280 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-config",
8281 dut->summary_log ? "--summary " : "",
8282 dut->summary_log ? dut->summary_log : "");
8283 res = run_nfc_command(dut, buf,
8284 "Touch NFC Tag to write WPS configuration token");
8285 if (res || !file_exists("nfc-success")) {
8286 send_resp(dut, conn, SIGMA_ERROR,
8287 "ErrorCode,Failed to write tag");
8288 return 0;
8289 }
8290
8291 return 1;
8292}
8293
8294
8295static int ap_nfc_wps_read_passwd(struct sigma_dut *dut,
8296 struct sigma_conn *conn,
8297 struct sigma_cmd *cmd)
8298{
8299 int res;
8300 char buf[300];
8301
8302 run_system(dut, "killall wps-ap-nfc.py");
8303
8304 unlink("nfc-success");
8305 snprintf(buf, sizeof(buf),
8306 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
8307 dut->summary_log ? "--summary " : "",
8308 dut->summary_log ? dut->summary_log : "");
8309 res = run_nfc_command(dut, buf, "Touch NFC Tag to read it");
8310 if (res || !file_exists("nfc-success")) {
8311 send_resp(dut, conn, SIGMA_ERROR,
8312 "ErrorCode,Failed to read tag");
8313 return 0;
8314 }
8315
8316 return 1;
8317}
8318
8319
8320static int ap_nfc_write_password_token(struct sigma_dut *dut,
8321 struct sigma_conn *conn,
8322 struct sigma_cmd *cmd)
8323{
8324 int res;
8325 char buf[300];
8326
8327 run_system(dut, "killall wps-ap-nfc.py");
8328 unlink("nfc-success");
8329 snprintf(buf, sizeof(buf),
8330 "./wps-ap-nfc.py --no-wait %s%s --success nfc-success write-password",
8331 dut->summary_log ? "--summary " : "",
8332 dut->summary_log ? dut->summary_log : "");
8333 res = run_nfc_command(dut, buf,
8334 "Touch NFC Tag to write WPS password token");
8335 if (res || !file_exists("nfc-success")) {
8336 send_resp(dut, conn, SIGMA_ERROR,
8337 "ErrorCode,Failed to write tag");
8338 return 0;
8339 }
8340
8341 if (run_hostapd_cli(dut, "wps_nfc_token enable") != 0) {
8342 send_resp(dut, conn, SIGMA_ERROR,
8343 "ErrorCode,Failed to enable NFC password token");
8344 return 0;
8345 }
8346
8347 return 1;
8348}
8349
8350
8351static int ap_nfc_wps_connection_handover(struct sigma_dut *dut,
8352 struct sigma_conn *conn,
8353 struct sigma_cmd *cmd)
8354{
8355 int res;
8356 char buf[300];
8357
8358 run_system(dut, "killall wps-ap-nfc.py");
8359 unlink("nfc-success");
8360 snprintf(buf, sizeof(buf),
8361 "./wps-ap-nfc.py -1 --no-wait %s%s --success nfc-success",
8362 dut->summary_log ? "--summary " : "",
8363 dut->summary_log ? dut->summary_log : "");
8364 res = run_nfc_command(dut, buf,
8365 "Touch NFC Device to respond to WPS connection handover");
8366 if (res) {
8367 send_resp(dut, conn, SIGMA_ERROR,
8368 "ErrorCode,Failed to enable NFC for connection "
8369 "handover");
8370 return 0;
8371 }
8372 if (!file_exists("nfc-success")) {
8373 send_resp(dut, conn, SIGMA_ERROR,
8374 "ErrorCode,Failed to complete NFC connection handover");
8375 return 0;
8376 }
8377
8378 return 1;
8379}
8380
8381
8382static int cmd_ap_nfc_action(struct sigma_dut *dut, struct sigma_conn *conn,
8383 struct sigma_cmd *cmd)
8384{
8385 /* const char *name = get_param(cmd, "Name"); */
8386 /* const char *intf = get_param(cmd, "Interface"); */
8387 const char *oper = get_param(cmd, "Operation");
8388
8389 if (oper == NULL)
8390 return -1;
8391
8392 if (strcasecmp(oper, "WRITE_CONFIG") == 0)
8393 return ap_nfc_write_config_token(dut, conn, cmd);
8394 if (strcasecmp(oper, "WRITE_PASSWD") == 0)
8395 return ap_nfc_write_password_token(dut, conn, cmd);
8396 if (strcasecmp(oper, "WPS_READ_PASSWD") == 0)
8397 return ap_nfc_wps_read_passwd(dut, conn, cmd);
8398 if (strcasecmp(oper, "WPS_CONN_HNDOVR") == 0)
8399 return ap_nfc_wps_connection_handover(dut, conn, cmd);
8400
8401 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported operation");
8402 return 0;
8403}
8404
8405
8406static int cmd_ap_wps_read_pin(struct sigma_dut *dut, struct sigma_conn *conn,
8407 struct sigma_cmd *cmd)
8408{
8409 char *pin = "12345670"; /* TODO: use random PIN */
8410 char resp[100];
8411
8412 snprintf(resp, sizeof(resp), "PIN,%s", pin);
8413 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8414
8415 return 0;
8416}
8417
8418
8419static int ath_vht_op_mode_notif(struct sigma_dut *dut, const char *ifname,
8420 const char *val)
8421{
8422 char *token, *result;
8423 int nss = 0, chwidth = 0;
8424 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308425 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008426
8427 /*
8428 * The following commands should be invoked to generate
8429 * VHT op mode notification
8430 */
8431
8432 /* Extract the NSS info */
8433 token = strdup(val);
8434 if (!token)
8435 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308436 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008437 if (result) {
8438 int count = atoi(result);
8439
8440 /* We do not support NSS > 3 */
8441 if (count < 0 || count > 3) {
8442 free(token);
8443 return -1;
8444 }
8445
8446 /* Convert nss to chainmask */
8447 while (count--)
8448 nss = (nss << 1) | 1;
8449
8450 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
8451 ifname, nss);
8452 if (system(buf) != 0) {
8453 sigma_dut_print(dut, DUT_MSG_ERROR,
8454 "iwpriv wifi1 rxchainmask failed!");
8455 }
8456 }
8457
8458 /* Extract the Channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308459 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008460 if (result) {
8461 switch (atoi(result)) {
8462 case 20:
8463 chwidth = 0;
8464 break;
8465 case 40:
8466 chwidth = 1;
8467 break;
8468 case 80:
8469 chwidth = 2;
8470 break;
8471 case 160:
8472 chwidth = 3;
8473 break;
8474 default:
8475 chwidth = 2;
8476 break;
8477 }
8478 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8479 ifname, chwidth);
8480 if (system(buf) != 0) {
8481 sigma_dut_print(dut, DUT_MSG_ERROR,
8482 "iwpriv chwidth failed!");
8483 }
8484 }
8485
8486 /* Send the opmode notification */
Sunil Dutt27ec7f62017-09-14 18:22:59 +03008487 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008488 if (system(buf) != 0) {
8489 sigma_dut_print(dut, DUT_MSG_ERROR,
8490 "iwpriv opmode_notify failed!");
8491 }
8492 free(token);
8493
8494 return 0;
8495}
8496
8497
8498static int ath_vht_nss_mcs(struct sigma_dut *dut, const char *ifname,
8499 const char *val)
8500{
8501 /* String (nss_operating_mode; mcs_operating_mode) */
8502 int nss, mcs;
8503 char *token, *result;
8504 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308505 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008506
8507 token = strdup(val);
8508 if (!token)
8509 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308510 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308511 if (!result) {
8512 sigma_dut_print(dut, DUT_MSG_ERROR,
8513 "VHT NSS not specified");
8514 goto end;
8515 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008516 if (strcasecmp(result, "def") != 0) {
8517 nss = atoi(result);
8518
8519 if (nss == 4)
8520 ath_disable_txbf(dut, ifname);
8521
8522 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", ifname, nss);
8523 if (system(buf) != 0) {
8524 sigma_dut_print(dut, DUT_MSG_ERROR,
8525 "iwpriv nss failed");
8526 }
8527 } else {
8528 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
8529 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", ifname);
8530 if (system(buf) != 0) {
8531 sigma_dut_print(dut, DUT_MSG_ERROR,
8532 "iwpriv nss failed");
8533 }
8534 }
8535 }
8536
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308537 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308538 if (!result) {
8539 sigma_dut_print(dut, DUT_MSG_ERROR,
8540 "VHT MCS not specified");
8541 goto end;
8542 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008543 if (strcasecmp(result, "def") == 0) {
8544 if (dut->device_type == AP_testbed && dut->ap_sgi80 == 1) {
8545 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs 7",
8546 ifname);
8547 if (system(buf) != 0) {
8548 sigma_dut_print(dut, DUT_MSG_ERROR,
8549 "iwpriv vhtmcs failed");
8550 }
8551 } else {
8552 snprintf(buf, sizeof(buf),
8553 "iwpriv %s set11NRates 0", ifname);
8554 if (system(buf) != 0) {
8555 sigma_dut_print(dut, DUT_MSG_ERROR,
8556 "iwpriv set11NRates failed");
8557 }
8558 }
8559 } else {
8560 mcs = atoi(result);
8561 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", ifname, mcs);
8562 if (system(buf) != 0) {
8563 sigma_dut_print(dut, DUT_MSG_ERROR,
8564 "iwpriv vhtmcs failed");
8565 }
8566 }
8567
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05308568end:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008569 free(token);
8570 return 0;
8571}
8572
8573
8574static int ath_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8575 const char *val)
8576{
8577 char *token, *result;
8578 int channel = 36;
8579 int chwidth = 80;
8580 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308581 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008582
8583 /* Extract the channel info */
8584 token = strdup(val);
8585 if (!token)
8586 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308587 result = strtok_r(token, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008588 if (result)
8589 channel = atoi(result);
8590
8591 /* Extract the channel width info */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308592 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008593 if (result)
8594 chwidth = atoi(result);
8595
8596 /* Issue the channel switch command */
8597 snprintf(buf, sizeof(buf), "iwpriv %s doth_ch_chwidth %d 10 %d",
8598 ifname, channel, chwidth);
8599 if (system(buf) != 0) {
8600 sigma_dut_print(dut, DUT_MSG_ERROR,
8601 "iwpriv doth_ch_chwidth failed!");
8602 }
8603
8604 free(token);
8605 return 0;
8606}
8607
8608
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008609static int ath_ndpa_stainfo_mac(struct sigma_dut *dut, const char *ifname,
8610 const char *val)
8611{
8612 char buf[80];
8613 unsigned char mac_addr[6];
8614
8615 if (parse_mac_address(dut, val, mac_addr) < 0)
8616 return -1;
8617
8618 snprintf(buf, sizeof(buf),
8619 "wifitool %s beeliner_fw_test 92 0x%02x%02x%02x%02x",
8620 ifname, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3]);
8621 run_system(dut, buf);
8622
8623 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 93 0x%02x%02x",
8624 ifname, mac_addr[4], mac_addr[5]);
8625 run_system(dut, buf);
8626
8627 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 94 1", ifname);
8628 run_system(dut, buf);
8629
8630 return 0;
8631}
8632
8633
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08008634void novap_reset(struct sigma_dut *dut, const char *ifname)
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08008635{
8636 char buf[60];
8637
8638 snprintf(buf, sizeof(buf), "iwpriv %s novap_reset 1", ifname);
8639 if (system(buf) != 0) {
8640 sigma_dut_print(dut, DUT_MSG_ERROR,
8641 "disabling novap reset failed");
8642 }
8643}
8644
8645
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008646struct mbo_pref_ap * mbo_find_nebor_ap_entry(struct sigma_dut *dut,
8647 const uint8_t *mac_addr)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008648{
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008649 int i;
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008650
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008651 for (i = 0; i < dut->mbo_pref_ap_cnt; i++) {
8652 if (memcmp(mac_addr, dut->mbo_pref_aps[i].mac_addr,
8653 ETH_ALEN) == 0)
8654 return &dut->mbo_pref_aps[i];
8655 }
8656 return NULL;
8657}
8658
8659
8660static void mbo_add_nebor_entry(struct sigma_dut *dut, const uint8_t *mac_addr,
8661 int ap_ne_class, int ap_ne_op_ch,
8662 int ap_ne_pref)
8663{
8664 struct mbo_pref_ap *entry;
8665 uint8_t self_mac[ETH_ALEN];
8666 char ifname[50];
8667
8668 get_if_name(dut, ifname, sizeof(ifname), 1);
8669 get_hwaddr(ifname, self_mac);
8670
8671 if (memcmp(mac_addr, self_mac, ETH_ALEN) == 0)
8672 entry = &dut->mbo_self_ap_tuple;
8673 else
8674 entry = mbo_find_nebor_ap_entry(dut, mac_addr);
8675
8676 if (!entry) {
8677 if (dut->mbo_pref_ap_cnt >= MBO_MAX_PREF_BSSIDS) {
8678 sigma_dut_print(dut, DUT_MSG_ERROR,
8679 "Nebor AP List is full. Not adding");
8680 return;
8681 }
8682 entry = &dut->mbo_pref_aps[dut->mbo_pref_ap_cnt];
8683 dut->mbo_pref_ap_cnt++;
8684 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
8685 entry->ap_ne_class = -1;
8686 entry->ap_ne_op_ch = -1;
8687 entry->ap_ne_pref = -1;
8688 }
8689 if (ap_ne_class != -1)
8690 entry->ap_ne_class = ap_ne_class;
8691 if (ap_ne_op_ch != -1)
8692 entry->ap_ne_op_ch = ap_ne_op_ch;
8693 if (ap_ne_pref != -1)
8694 entry->ap_ne_pref = ap_ne_pref;
8695}
8696
8697
8698static int ath_set_nebor_bssid(struct sigma_dut *dut, const char *ifname,
8699 struct sigma_cmd *cmd)
8700{
8701 unsigned char mac_addr[ETH_ALEN];
8702 const char *val;
8703 /*
8704 * -1 is invalid value for the following
8705 * to differentiate between unset and set values
8706 * -1 => implies not set by CAPI
8707 */
8708 int ap_ne_class = -1, ap_ne_op_ch = -1, ap_ne_pref = -1;
8709 int list_offset = dut->mbo_pref_ap_cnt;
8710
8711 if (list_offset >= MBO_MAX_PREF_BSSIDS) {
8712 sigma_dut_print(dut, DUT_MSG_ERROR,
8713 "AP Pref Entry list is full");
8714 return -1;
8715 }
8716
8717 val = get_param(cmd, "Nebor_Op_Class");
8718 if (val)
8719 ap_ne_class = atoi(val);
8720
8721 val = get_param(cmd, "Nebor_Op_Ch");
8722 if (val)
8723 ap_ne_op_ch = atoi(val);
8724
8725 val = get_param(cmd, "Nebor_Pref");
8726 if (val)
8727 ap_ne_pref = atoi(val);
8728
8729 val = get_param(cmd, "Nebor_BSSID");
8730 if (!val || parse_mac_address(dut, val, mac_addr) < 0)
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008731 return -1;
8732
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008733 mbo_add_nebor_entry(dut, mac_addr, ap_ne_class, ap_ne_op_ch,
8734 ap_ne_pref);
8735 apply_mbo_pref_ap_list(dut);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008736 return 0;
8737}
8738
8739
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008740static int ath_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8741 struct sigma_cmd *cmd)
8742{
8743 const char *val;
8744 char *ifname;
8745
8746 ifname = get_main_ifname();
8747
Priyadharshini Gowthaman39beafa2015-11-09 14:11:25 -08008748 /* Disable vap reset between the commands */
8749 novap_reset(dut, ifname);
8750
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008751 val = get_param(cmd, "Opt_md_notif_ie");
8752 if (val && ath_vht_op_mode_notif(dut, ifname, val) < 0)
8753 return -1;
8754
8755 /* TODO: Optional arguments */
8756
8757 val = get_param(cmd, "nss_mcs_opt");
8758 if (val && ath_vht_nss_mcs(dut, ifname, val) < 0)
8759 return -1;
8760
8761 val = get_param(cmd, "chnum_band");
8762 if (val && ath_vht_chnum_band(dut, ifname, val) < 0)
8763 return -1;
8764
8765 val = get_param(cmd, "RTS_FORCE");
8766 if (val)
8767 ath_config_rts_force(dut, ifname, val);
8768
8769 val = get_param(cmd, "DYN_BW_SGNL");
8770 if (val)
8771 ath_config_dyn_bw_sig(dut, ifname, val);
8772
8773 val = get_param(cmd, "CTS_WIDTH");
8774 if (val)
8775 ath_set_cts_width(dut, ifname, val);
8776
8777 val = get_param(cmd, "Ndpa_stainfo_mac");
8778 if (val && ath_ndpa_stainfo_mac(dut, ifname, val) < 0)
8779 return -1;
8780
8781 val = get_param(cmd, "txBandwidth");
8782 if (val && ath_set_width(dut, conn, ifname, val) < 0)
8783 return -1;
8784
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008785 val = get_param(cmd, "Assoc_Disallow");
8786 if (val)
8787 ath_set_assoc_disallow(dut, ifname, val);
8788
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008789
Adil Saeed Musthafa69063722017-04-10 23:13:40 -07008790 ath_set_nebor_bssid(dut, ifname, cmd);
priyadharshini gowthamanb4e05fc2016-10-13 15:02:35 -07008791 val = get_param(cmd, "BTMReq_DisAssoc_Imnt");
8792 if (val)
8793 dut->ap_btmreq_disassoc_imnt = atoi(val);
8794
8795 val = get_param(cmd, "BTMReq_Term_Bit");
8796 if (val)
8797 dut->ap_btmreq_term_bit = atoi(val);
8798
Adil Saeed Musthafa48c5ab92017-04-10 23:13:35 -07008799 val = get_param(cmd, "Assoc_Delay");
8800 if (val)
8801 run_system_wrapper(dut, "iwpriv %s mbo_asoc_ret %s",
8802 ifname, val);
8803
Adil Saeed Musthafa7d9ae382017-04-10 23:13:33 -07008804 val = get_param(cmd, "Disassoc_Timer");
8805 if (val)
8806 dut->ap_disassoc_timer = atoi(val);
8807
8808 val = get_param(cmd, "BSS_Term_Duration");
8809 if (val)
8810 dut->ap_btmreq_bss_term_dur = atoi(val);
8811
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008812 return 1;
8813}
8814
8815
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308816static int wcn_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8817 const char *val)
8818{
8819 char *token, *result;
8820 int channel = 36;
8821 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308822 char *saveptr;
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308823
8824 /* Extract the channel info */
8825 token = strdup(val);
8826 if (!token)
8827 return -1;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308828 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308829 if (result)
8830 channel = atoi(result);
8831
8832 /* Issue the channel switch command */
8833 snprintf(buf, sizeof(buf), "iwpriv %s setChanChange %d",
8834 ifname, channel);
8835 if (system(buf) != 0) {
8836 sigma_dut_print(dut, DUT_MSG_ERROR,
8837 "iwpriv setChanChange failed!");
8838 }
8839
8840 free(token);
8841 return 0;
8842}
8843
8844
8845static int wcn_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8846 struct sigma_cmd *cmd)
8847{
8848 const char *val;
8849 char *ifname;
8850
8851 ifname = get_main_ifname();
8852
8853 val = get_param(cmd, "chnum_band");
8854 if (val && wcn_vht_chnum_band(dut, ifname, val) < 0)
8855 return -1;
8856
8857 return 1;
8858}
8859
8860
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05308861static int mac80211_vht_chnum_band(struct sigma_dut *dut, const char *ifname,
8862 const char *val)
8863{
8864 char *token, *result;
8865 int channel = 36, chwidth = 80, center_freq_idx, center_freq,
8866 channel_freq;
8867 char buf[100];
8868 char *saveptr;
8869
8870 /* Extract the channel info */
8871 token = strdup(val);
8872 if (!token)
8873 return -1;
8874 result = strtok_r(token, ";", &saveptr);
8875 if (result)
8876 channel = atoi(result);
8877
8878 /* Extract the channel width info */
8879 result = strtok_r(NULL, ";", &saveptr);
8880 if (result)
8881 chwidth = atoi(result);
8882
8883 center_freq_idx = get_oper_centr_freq_seq_idx(chwidth, channel);
8884 if (center_freq_idx < 0) {
8885 free(token);
8886 return -1;
8887 }
8888
8889 center_freq = get_5g_channel_freq(center_freq_idx);
8890 channel_freq = get_5g_channel_freq(channel);
8891
8892 /* Issue the channel switch command */
8893 snprintf(buf, sizeof(buf),
8894 " -i %s chan_switch 10 %d sec_channel_offset=1 center_freq1=%d bandwidth=%d blocktx vht",
8895 ifname, channel_freq, center_freq, chwidth);
8896 if (run_hostapd_cli(dut,buf) != 0) {
8897 sigma_dut_print(dut, DUT_MSG_ERROR,
8898 "hostapd_cli chan_switch failed");
8899 }
8900
8901 free(token);
8902 return 0;
8903}
8904
8905
8906static int mac80211_ap_set_rfeature(struct sigma_dut *dut,
8907 struct sigma_conn *conn,
8908 struct sigma_cmd *cmd)
8909{
8910 const char *val;
8911 char *ifname;
8912
8913 ifname = get_main_ifname();
8914 val = get_param(cmd, "chnum_band");
8915 if (val && mac80211_vht_chnum_band(dut, ifname, val) < 0)
8916 return -1;
8917
8918 return 1;
8919}
8920
8921
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008922static int cmd_ap_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
8923 struct sigma_cmd *cmd)
8924{
8925 /* const char *name = get_param(cmd, "NAME"); */
8926 /* const char *type = get_param(cmd, "Type"); */
8927
8928 switch (get_driver_type()) {
8929 case DRIVER_ATHEROS:
8930 return ath_ap_set_rfeature(dut, conn, cmd);
8931 case DRIVER_OPENWRT:
8932 switch (get_openwrt_driver_type()) {
8933 case OPENWRT_DRIVER_ATHEROS:
8934 return ath_ap_set_rfeature(dut, conn, cmd);
8935 default:
8936 send_resp(dut, conn, SIGMA_ERROR,
8937 "errorCode,Unsupported ap_set_rfeature with the current openwrt driver");
8938 return 0;
8939 }
Sreelakshmi Konamki0e4fcf92016-04-26 19:55:01 +05308940 case DRIVER_LINUX_WCN:
Pradeep Reddy POTTETI88fd82c2016-03-14 12:20:18 +05308941 case DRIVER_WCN:
8942 return wcn_ap_set_rfeature(dut, conn, cmd);
Mohammed Shafi Shajakhanb53d8f92017-02-28 09:05:15 +05308943 case DRIVER_MAC80211:
8944 return mac80211_ap_set_rfeature(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008945 default:
8946 send_resp(dut, conn, SIGMA_ERROR,
8947 "errorCode,Unsupported ap_set_rfeature with the current driver");
8948 return 0;
8949 }
8950}
8951
8952
8953static int cmd_accesspoint(struct sigma_dut *dut, struct sigma_conn *conn,
8954 struct sigma_cmd *cmd)
8955{
8956 /* const char *name = get_param(cmd, "NAME"); */
8957 return 1;
8958}
8959
8960
8961void ap_register_cmds(void)
8962{
8963 sigma_dut_reg_cmd("ap_ca_version", NULL, cmd_ap_ca_version);
8964 sigma_dut_reg_cmd("ap_set_wireless", NULL, cmd_ap_set_wireless);
8965 sigma_dut_reg_cmd("ap_send_addba_req", NULL, cmd_ap_send_addba_req);
8966 sigma_dut_reg_cmd("ap_set_11n_wireless", NULL, cmd_ap_set_wireless);
8967 sigma_dut_reg_cmd("ap_set_11n", NULL, cmd_ap_set_wireless);
8968 sigma_dut_reg_cmd("ap_set_11d", NULL, cmd_ap_set_wireless);
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +05308969 sigma_dut_reg_cmd("ap_set_11h", NULL, cmd_ap_set_wireless);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008970 sigma_dut_reg_cmd("ap_set_security", NULL, cmd_ap_set_security);
8971 sigma_dut_reg_cmd("ap_set_apqos", NULL, cmd_ap_set_apqos);
8972 sigma_dut_reg_cmd("ap_set_staqos", NULL, cmd_ap_set_staqos);
8973 sigma_dut_reg_cmd("ap_set_radius", NULL, cmd_ap_set_radius);
8974 sigma_dut_reg_cmd("ap_reboot", NULL, cmd_ap_reboot);
8975 sigma_dut_reg_cmd("ap_config_commit", NULL, cmd_ap_config_commit);
8976 sigma_dut_reg_cmd("ap_reset_default", NULL, cmd_ap_reset_default);
8977 sigma_dut_reg_cmd("ap_get_info", NULL, cmd_ap_get_info);
8978 sigma_dut_reg_cmd("ap_deauth_sta", NULL, cmd_ap_deauth_sta);
8979 sigma_dut_reg_cmd("ap_send_frame", NULL, cmd_ap_send_frame);
8980 sigma_dut_reg_cmd("ap_get_mac_address", NULL, cmd_ap_get_mac_address);
8981 sigma_dut_reg_cmd("ap_set_pmf", NULL, cmd_ap_set_pmf);
8982 sigma_dut_reg_cmd("ap_set_hs2", NULL, cmd_ap_set_hs2);
8983 sigma_dut_reg_cmd("ap_set_rfeature", NULL, cmd_ap_set_rfeature);
8984 sigma_dut_reg_cmd("ap_nfc_action", NULL, cmd_ap_nfc_action);
8985 sigma_dut_reg_cmd("ap_wps_read_pin", NULL, cmd_ap_wps_read_pin);
8986 sigma_dut_reg_cmd("AccessPoint", NULL, cmd_accesspoint);
8987}